Archived
1
0
Fork 0
This repository has been archived on 2020-07-31. You can view files and clone it, but cannot push or open issues or pull requests.
news-script/Source/Anivisual.php

83 lines
2.5 KiB
PHP

<?php
namespace Source;
use \Game;
class Anivisual extends Source {
public $title = "Anivisual";
protected $months = [
'Января' => 'January',
'Февраля' => 'February',
'Марта' => 'March',
'Апреля' => 'April',
'Мая' => 'May',
'Июня' => 'June',
'Июля' => 'July',
'Августа' => 'August',
'Сентября' => 'September',
'Октября' => 'October',
'Ноября' => 'November',
'Декабря' => 'December',
];
protected function parse() {
$text = $this->get_text('http://anivisual.net/stuff/1');
try {
$this->dom->loadStr($text, []);
} catch (\Exception $e) {
echo $e->getMessage();
echo $e->getTraceAsString();
return "";
}
unset($text);
$games = $this->dom->find('.entryBlock');
foreach ($games as $gameBlock) {
$date = trim($gameBlock->find('.icon-calendar')->innerHtml);
foreach ($this->months as $ruM => $enM) {
$date = str_replace($ruM, $enM, $date);
}
$date = \DateTime::createFromFormat('d F Y', $date);
$date = $date->format('U');
if ($date < $this->period) continue;
$game = new Game;
$link = $gameBlock->find('.novel-ttl a')[0];
$game->title = htmlspecialchars_decode($link->innerHtml);
$game->url = 'http://anivisual.net'.$link->getAttribute('href');
$game->description = $gameBlock->find('span')->first()->text;
$games[] = $game;
$this->output .= $game->print();
}
}
public function checkPage($url) {
return (strpos($url,'http://anivisual.net/stuff/') !== FALSE);
}
public function page($url) {
$text = $this->get_text($url);
try {
$this->dom->loadStr($text, []);
} catch (\Exception $e) {
echo $e->getMessage();
echo $e->getTraceAsString();
return "";
}
unset($text);
$game = new Game;
$game->url = $url;
$gameBlock = $this->dom->find('#casing-box');
try {
$date = trim($gameBlock->find('.icon-calendar')->first()->text);
foreach ($this->months as $ruM => $enM) {
$date = str_replace($ruM, $enM, $date);
}
$date = \DateTime::createFromFormat('d F Y', $date);
$date = $date->format('U');
$game->date = $date;
unset($date);
} catch (\Exception $e) {}
$game->title = htmlspecialchars_decode($gameBlock->find('h1.logo')->text);
// $game->description = $this->dom->find('#content > section > span')->text;
return $game;
}
}