From 1b0c20b9751eda0806b0b085d3989e0ea9c3798e Mon Sep 17 00:00:00 2001 From: Alexander Yakovlev Date: Sun, 25 Mar 2018 02:22:00 +0700 Subject: [PATCH] Anivisual and Apero updates --- Source/Anivisual.php | 7 +++---- Source/Apero.php | 29 ++++++++++++++--------------- 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/Source/Anivisual.php b/Source/Anivisual.php index 729c77e..69104de 100644 --- a/Source/Anivisual.php +++ b/Source/Anivisual.php @@ -23,15 +23,14 @@ class Anivisual extends Source { $text = $this->get_text('http://anivisual.net/stuff/1'); $this->loadStr($text); unset($text); - $games = $this->dom->filter('.entryBlock'); - foreach ($games as $gameBlock) { + $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) continue; + if ($date < $this->period) return; $game = new Game; $link = $gameBlock->filter('.novel-ttl a')->first(); $game->title = htmlspecialchars_decode($link->innerHtml); @@ -41,7 +40,7 @@ class Anivisual extends Source { $games[] = $game; $this->output .= $game->print(); - } + }); } public function checkPage($url) { return (strpos($url,'http://anivisual.net/stuff/') !== FALSE); diff --git a/Source/Apero.php b/Source/Apero.php index 797ca6a..b6823eb 100644 --- a/Source/Apero.php +++ b/Source/Apero.php @@ -12,27 +12,26 @@ class Apero extends Source { protected function parse() { $text = $this->get_text('http://apero.ru/Текстовые-игры/Песочница'); $text = mb_convert_encoding($text, 'UTF-8', 'auto'); - $this->dom->loadStr($text, []); - $this->parsePage(); + $this->loadStr($text); + $this->parseIndex(); $text = $this->get_text('http://apero.ru/Текстовые-игры'); $text = mb_convert_encoding($text, 'UTF-8', 'auto'); - $this->dom->loadStr($text, []); - $this->parsePage(); + $this->loadStr($text); + $this->parseIndex(); } - protected function parsePage() + protected function parseIndex() { - $formatter = new \IntlDateFormatter( 'ru', \IntlDateFormatter::LONG, \IntlDateFormatter::NONE ); - $games = $this->dom->find('.tabled-game-block'); - foreach ($games as $gameBlock) { - $date = trim($gameBlock->find('.game-updated-block')->innerHtml, "() \t\n\r\0\x0B"); + $this->dom->filter('.tabled-game-block')->each(function($gameBlock){ + $formatter = new \IntlDateFormatter( 'ru', \IntlDateFormatter::LONG, \IntlDateFormatter::NONE ); + $date = trim($gameBlock->filter('.game-updated-block')->text(), "() \t\n\r\0\x0B"); $date = $formatter->parse($date); - if ($date < $this->period) continue; + if ($date < $this->period) return; $game = new Game; - $game->author = trim($gameBlock->find('.game-author-block')[0]->find('a')->innerHtml); - $game->title = trim($gameBlock->find('h2')[0]->find('a')[0]->innerHtml); - $game->url = trim($gameBlock->find('h2')[0]->find('a')[0]->getAttribute('href')); - $game->description = trim($gameBlock->find('.game-desc-block')[0]->innerHtml); + $game->author = trim($gameBlock->filter('.game-author-block:first-child a')->text()); + $game->title = trim($gameBlock->find('h2:first-child a:first-child')->first()->text()); + $game->url = trim($gameBlock->find('h2:first-child a:first-child')->first()->getAttribute('href')); + $game->description = trim($gameBlock->find('.game-desc-block')->first()->text()); $this->output .= $game->print(); - } + }); } }