. */ namespace Oreolek\Source; use \Oreolek\Game; use \Oreolek\Source; 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,'://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'); $dateBlock = $this->dom->filter('.icon-calendar'); $date = ''; if ($dateBlock->count() > 0) { $date = trim($dateBlock->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 = trim(htmlspecialchars_decode($title->text())); } $game->description = $this->dom->filter('#content > section > span')->first()->text(); $game->description = str_replace('(adsbygoogle = window.adsbygoogle || []).push({});', '', $game->description); $game->description = str_replace('Доп. ссылки: Доступно только для пользователей', '', $game->description); $game->description = trim($game->description); $sidebar = $gameBlock->filter('#sidebar')->first()->html(); $pos_start = mb_strpos($sidebar, 'Автор:'); $sidebar_search = trim(mb_substr($sidebar, $pos_start)); $pos_end = mb_strpos($sidebar_search, '
'); $sidebar_search = trim(mb_substr($sidebar_search, 0, $pos_end)); $sidebar_search = str_replace('Автор:', '', $sidebar_search); $game->author = trim(strip_tags($sidebar_search)); $matches = []; preg_match ('/Перевод:<\/b>\s+(.*)<\/a>
/', $sidebar, $matches); if (count($matches) > 0) { $game->author .= ', пер. '.strip_tags($matches[1]); } return $game; } }