summaryrefslogtreecommitdiff
path: root/bridges/WorldOfTanksBridge.php
blob: 46dd588dd30f0ebd54e77fecae333ab3bce0d44d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?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->outertext = '';
		}

		return $content->innertext;
	}
}