052844f5e1
simplehtmldom 1.9 introduced new functions to recursively remove nodes from the DOM. This allows removing elements without the need to re-load the document by using $html->load($html->save()), which is very inefficient. Find more information about remove() at https://simplehtmldom.sourceforge.io/docs/1.9/api/simple_html_dom_node/remove/
52 lines
1.2 KiB
PHP
52 lines
1.2 KiB
PHP
<?php
|
|
class WorldOfTanksBridge extends FeedExpander {
|
|
|
|
const MAINTAINER = 'Riduidel';
|
|
const NAME = 'World of Tanks';
|
|
const URI = 'http://worldoftanks.eu/';
|
|
const DESCRIPTION = 'News about the tank slaughter game.';
|
|
|
|
const PARAMETERS = array( array(
|
|
'lang' => array(
|
|
'name' => 'Langue',
|
|
'type' => 'list',
|
|
'values' => array(
|
|
'Français' => 'fr',
|
|
'English' => 'en',
|
|
'Español' => 'es',
|
|
'Deutsch' => 'de',
|
|
'Čeština' => 'cs',
|
|
'Polski' => 'pl',
|
|
'Türkçe' => 'tr'
|
|
)
|
|
)
|
|
));
|
|
|
|
public function collectData() {
|
|
$this->collectExpandableDatas(sprintf('https://worldoftanks.eu/%s/rss/news/', $this->getInput('lang')));
|
|
}
|
|
|
|
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->remove();
|
|
}
|
|
|
|
return $content->innertext;
|
|
}
|
|
}
|