aboutsummaryrefslogtreecommitdiff
path: root/bridges/Rue89Bridge.php
blob: ae407d3732ac06fa3a6f810bc5a0b16c60263421 (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
<?php
class Rue89Bridge extends BridgeAbstract{

	public function loadMetadatas() {

		$this->maintainer = "pit-fgfjiudghdf";
		$this->name = "Rue89";
		$this->uri = "http://rue89.nouvelobs.com/";
		$this->description = "Returns the 5 newest posts from Rue89 (full text)";
		$this->update = "2016-08-09";

	}

	private function rue89getDatas($url){

		$url = "http://api.rue89.nouvelobs.com/export/mobile2/node/" . str_replace(" ", "", substr($url, -8)) . "/full";
		$datas = json_decode(file_get_contents($url), true);

		return $datas["node"];

	}

    public function collectData(array $param){

        $html = $this->file_get_html('http://api.rue89.nouvelobs.com/feed') or $this->returnError('Could not request Rue89.', 404);

        $limit = 0;
        foreach($html->find('item') as $element) {

        	if($limit < 5) {

				$datas = $this->rue89getDatas(str_replace('#commentaires', '', ($element->find('comments', 0)->plaintext)));

				$item = new \Item();
				$item->title = $datas["title"];
				$item->author = $datas["author"][0]["name"];
				$item->timestamp = $datas["updated"];
				$item->content = $datas["body"];
				$item->uri = $datas["url"];

				$this->items[] = $item;

			}
        }

    }
}