aboutsummaryrefslogtreecommitdiff
path: root/bridges/VieDeMerdeBridge.php
blob: fae0b894806773fe12c3b8f6a905fa7af21716f7 (plain) (blame)
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
53
54
55
<?php
class VieDeMerdeBridge extends BridgeAbstract {

	const MAINTAINER = 'floviolleau';
	const NAME = 'VieDeMerde Bridge';
	const URI = 'https://viedemerde.fr';
	const DESCRIPTION = 'Returns latest quotes from VieDeMerde.';
	const CACHE_TIMEOUT = 7200;

	const PARAMETERS = array(array(
			'item_limit' => array(
			'name' => 'Limit number of returned items',
			'type' => 'number',
			'defaultValue' => 20
		)
	));

	public function collectData() {
		$limit = $this->getInput('item_limit');

		if ($limit < 1) {
			$limit = 20;
		}

		$html = getSimpleHTMLDOM(self::URI, array());

		$quotes = $html->find('article.article-panel');
		if(sizeof($quotes) === 0) {
			return;
		}

		foreach($quotes as $quote) {
			$item = array();
			$item['uri'] = self::URI . $quote->find('.article-contents a', 0)->href;
			$titleContent = $quote->find('.article-contents a h2.classic-title', 0);

			if($titleContent) {
				$item['title'] = html_entity_decode($titleContent->plaintext, ENT_QUOTES);
			} else {
				continue;
			}

			$quote->find('.article-contents a h2.classic-title', 0)->outertext = '';
			$item['content'] = $quote->find('.article-contents a', 0)->innertext;
			$item['author'] = $quote->find('.article-topbar', 0)->innertext;
			$item['uid'] = hash('sha256', $item['title']);

			$this->items[] = $item;

			if (count($this->items) >= $limit) {
				break;
			}
		}
	}
}