From e60b5ab1939380daeeab105bf8dabaf363cb3c22 Mon Sep 17 00:00:00 2001 From: Nicolas Delsaux Date: Sun, 22 Apr 2018 12:58:07 +0200 Subject: [PATCH] =?UTF-8?q?Mise=20=C3=A0=20jour=20du=20bridge=20pour=20Wor?= =?UTF-8?q?ldOfTanks=20(#527)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Mise à jour de l'un de mes bridges fétiches --- bridges/WorldOfTanksBridge.php | 70 ++++++++++++---------------------- 1 file changed, 25 insertions(+), 45 deletions(-) diff --git a/bridges/WorldOfTanksBridge.php b/bridges/WorldOfTanksBridge.php index f783e29..46dd588 100644 --- a/bridges/WorldOfTanksBridge.php +++ b/bridges/WorldOfTanksBridge.php @@ -1,16 +1,12 @@ array( - // TODO: should be a list - 'name' => 'nom de la catégorie' - ), 'lang' => array( 'name' => 'Langue', 'type' => 'list', @@ -26,47 +22,31 @@ class WorldOfTanksBridge extends BridgeAbstract { ) )); - private $title = ''; + public function collectData() { + $this->collectExpandableDatas(sprintf('https://worldoftanks.eu/%s/rss/news/', $this->getInput('lang'))); + } - public function getURI(){ - if(!is_null($this->getInput('lang'))) { - $lang = $this->getInput('lang'); - $uri = self::URI . $lang . '/news/'; - if(!empty($this->getInput('category'))) { - $uri .= 'pc-browser/' . $this->getInput('category') . '/'; - } - return $uri; + protected function parseItem($newsItem){ + $item = parent::parseItem($newsItem); + $item['content'] = $this->loadFullArticle($item['uri']); + return $item; + } + + /** + * Loads the full article and returns the contents + * @param $uri The article URI + * @return The article content + */ + private function loadFullArticle($uri){ + $html = getSimpleHTMLDOMCached($uri); + + $content = $html->find('article', 0); + + // Remove the scripts, please + foreach($content->find('script') as $script) { + $script->outertext = ''; } - return parent::getURI(); - } - - public function getName(){ - return $this->title ?: parent::getName(); - } - - public function collectData(){ - $html = getSimpleHTMLDOM($this->getURI()) - or returnServerError('Could not request ' . $this->getURI()); - debugMessage("loaded HTML from " . $this->getURI()); - // customize name - $this->title = $html->find('title', 0)->innertext; - foreach($html->find('.b-imgblock_ico') as $infoLink) { - $this->parseLine($infoLink); - } - } - - private function parseLine($infoLink){ - $item = array(); - $item['uri'] = self::URI . $infoLink->href; - // now load that uri from cache - debugMessage('loading page ' . $item['uri']); - $articlePage = getSimpleHTMLDOMCached($item['uri']); - $content = $articlePage->find('.l-content', 0); - defaultLinkTo($content, self::URI); - $item['title'] = $content->find('h1', 0)->innertext; - $item['content'] = $content->find('.b-content', 0)->innertext; - $item['timestamp'] = $content->find('.b-statistic_time', 0)->getAttribute("data-timestamp"); - $this->items[] = $item; + return $content->innertext; } }