. */ 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'); $this->loadStr($text); unset($text); $this->dom->filter('.entryBlock')->each(function($gameBlock) { $date = trim($gameBlock->filter('.icon-calendar')->text()); 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) return; $link = $gameBlock->filter('.novel-ttl a')->first(); $link = 'http://anivisual.net'.$link->attr('href'); $game = $this->page($link); //$game = new Game; //$game->title = htmlspecialchars_decode($link->html()); //$game->url = 'http://anivisual.net'.$link->attr('href'); //$game->description = $gameBlock->filter('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); $this->loadStr($text); unset($text); $game = new Game; $game->url = $url; $gameBlock = $this->dom->filter('#casing-box'); $date = trim($gameBlock->filter('.icon-calendar')->first()->text()); if (!empty($date)) { foreach ($this->months as $ruM => $enM) { $date = str_replace($ruM, $enM, $date); } $game->date = \DateTime::createFromFormat('d F Y', $date); unset($date); } $title = $this->dom->filter('h1.logo')->first(); if ($title->count() > 0) { $game->title = htmlspecialchars_decode($title->text()); } $game->description = $gameBlock->filter('#content > section > span')->first()->text(); $game->description = str_replace('(adsbygoogle = window.adsbygoogle || []).push({});', '', $game->description); $game->description = trim($game->description); $sidebar = $gameBlock->filter('#sidebar')->first()->html(); preg_match ('/Автор:<\/b>\s+(.*)(<\/a>)?
/', $sidebar, $matches); if (count($matches) > 0) { $game->author = strip_tags($matches[1]); preg_match('/(.*)Теги:/', $game->author, $matches); $game->author = $matches[1]; } $matches = []; preg_match ('/Перевод:<\/b>\s+(.*)<\/a>
/', $sidebar, $matches); if (count($matches) > 0) { $game->author .= ', пер. '.strip_tags($matches[1]); } return $game; } }