aboutsummaryrefslogtreecommitdiff
path: root/bridges/JornalDeNoticiasBridge.php
blob: e61a7a422c5b4d2c7daa0e7a0fe3fb763d18aa8f (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
<?php
class JornalDeNoticiasBridge extends BridgeAbstract {
	const NAME = 'Jornal de Notícias (PT)';
	const URI = 'https://jn.pt';
	const DESCRIPTION = 'Jornal de Notícias (JN.PT)';
	const MAINTAINER = 'somini';
	const PARAMETERS = array(
		'URL' => array(
			'url' => array(
				'name' => 'URL (relative)',
				'exampleValue' => 'opiniao/catia-domingues.html',
			)
		)
	);

	public function getIcon() {
		return 'https://static.globalnoticias.pt/jn/common/images/favicons/favicon-128.png';
	}

	public function getURI() {
		switch($this->queriedContext) {
		case 'URL':
			$url = self::URI . '/' . $this->getInput('url');
			break;
		default:
			$url = self::URI;
		}
		return $url;
	}

	public function collectData() {
		$archives = self::getURI();
		$html = getSimpleHTMLDOMCached($archives);

		foreach($html->find('article') as $element) {
			$item = array();

			$title = $element->find('h2 a', 0);
			$link = $element->find('h2 a', 0);
			$auth = $element->find('h3 a', 0);

			$item['title'] = $title->plaintext;
			$item['uri'] = self::URI . $link->href;
			$item['author'] = $auth->plaintext;

			$snippet = $element->find('h4 a', 0);
			if ($snippet) {
				$item['content'] = $snippet->plaintext;
			}

			$this->items[] = $item;
		}
	}
}