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

	public function loadMetadatas() {
		$this->maintainer = "nyutag";
		$this->name = "CommonDreams Bridge";
		$this->uri = "http://www.commondreams.org/";
		$this->description = "Returns the newest articles.";
		$this->update = "2016-08-09";
	}

	private function CommonDreamsExtractContent($url) {
		$html3 = $this->file_get_html($url);
		$text = $html3->find('div[class=field--type-text-with-summary]', 0)->innertext;
		$html3->clear();
		unset ($html3);
		return $text;
	}

	public function collectData(array $param){

		function CommonDreamsUrl($string) {
			$html2 = explode(" ", $string);
			$string = $html2[2] . "/node/" . $html2[0];
			return $string;
		}

		$html = $this->file_get_html('http://www.commondreams.org/rss.xml') or $this->returnError('Could not request CommonDreams.', 404);
		$limit = 0;
		foreach($html->find('item') as $element) {
			if($limit < 4) {
				$item = new \Item();
				$item->title = $element->find('title', 0)->innertext;
				$item->uri = CommonDreamsUrl($element->find('guid', 0)->innertext);
				$item->timestamp = strtotime($element->find('pubDate', 0)->plaintext);
				$item->content = $this->CommonDreamsExtractContent($item->uri);
				$this->items[] = $item;
				$limit++;
			}
		}
	}
}