2015-04-26 20:22:20 +03:00
|
|
|
<?php
|
|
|
|
class CommonDreamsBridge extends BridgeAbstract{
|
2015-11-04 01:28:44 +03:00
|
|
|
|
2016-08-27 22:03:26 +03:00
|
|
|
public $maintainer = "nyutag";
|
|
|
|
public $name = "CommonDreams Bridge";
|
|
|
|
public $uri = "http://www.commondreams.org/";
|
|
|
|
public $description = "Returns the newest articles.";
|
2016-08-02 15:43:59 +03:00
|
|
|
|
2016-08-06 17:00:56 +03:00
|
|
|
private function CommonDreamsExtractContent($url) {
|
2016-07-08 20:06:35 +03:00
|
|
|
$html3 = $this->getSimpleHTMLDOM($url);
|
2015-04-26 20:22:20 +03:00
|
|
|
$text = $html3->find('div[class=field--type-text-with-summary]', 0)->innertext;
|
2015-05-05 21:30:26 +03:00
|
|
|
$html3->clear();
|
|
|
|
unset ($html3);
|
2015-04-26 20:22:20 +03:00
|
|
|
return $text;
|
2016-08-02 15:43:59 +03:00
|
|
|
}
|
2015-04-26 20:22:20 +03:00
|
|
|
|
2016-08-25 02:24:53 +03:00
|
|
|
public function collectData(){
|
2016-08-02 15:41:54 +03:00
|
|
|
|
|
|
|
function CommonDreamsUrl($string) {
|
2016-08-02 15:43:59 +03:00
|
|
|
$html2 = explode(" ", $string);
|
|
|
|
$string = $html2[2] . "/node/" . $html2[0];
|
|
|
|
return $string;
|
2016-08-02 15:41:54 +03:00
|
|
|
}
|
|
|
|
|
2016-07-08 20:06:35 +03:00
|
|
|
$html = $this->getSimpleHTMLDOM('http://www.commondreams.org/rss.xml') or $this->returnServerError('Could not request CommonDreams.');
|
2015-04-26 20:22:20 +03:00
|
|
|
$limit = 0;
|
|
|
|
foreach($html->find('item') as $element) {
|
2016-08-02 15:43:59 +03:00
|
|
|
if($limit < 4) {
|
2016-08-22 19:55:59 +03:00
|
|
|
$item = array();
|
|
|
|
$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']);
|
2016-08-02 15:43:59 +03:00
|
|
|
$this->items[] = $item;
|
|
|
|
$limit++;
|
|
|
|
}
|
2015-04-26 20:22:20 +03:00
|
|
|
}
|
2016-08-02 15:43:59 +03:00
|
|
|
}
|
2015-04-26 20:22:20 +03:00
|
|
|
}
|