2015-04-26 19:22:20 +02:00
|
|
|
<?php
|
|
|
|
class CommonDreamsBridge extends BridgeAbstract{
|
2015-11-03 23:28:44 +01:00
|
|
|
|
2016-08-02 14:43:59 +02:00
|
|
|
public function loadMetadatas() {
|
|
|
|
$this->maintainer = "nyutag";
|
|
|
|
$this->name = "CommonDreams Bridge";
|
|
|
|
$this->uri = "http://www.commondreams.org/";
|
|
|
|
$this->description = "Returns the newest articles.";
|
2016-08-06 16:00:56 +02:00
|
|
|
$this->update = "2016-08-06";
|
2016-08-02 14:43:59 +02:00
|
|
|
}
|
|
|
|
|
2016-08-06 16:00:56 +02:00
|
|
|
private function CommonDreamsExtractContent($url) {
|
2016-06-25 23:17:42 +02:00
|
|
|
$html3 = $this->file_get_html($url);
|
2015-04-26 19:22:20 +02:00
|
|
|
$text = $html3->find('div[class=field--type-text-with-summary]', 0)->innertext;
|
2015-05-05 20:30:26 +02:00
|
|
|
$html3->clear();
|
|
|
|
unset ($html3);
|
2015-04-26 19:22:20 +02:00
|
|
|
return $text;
|
2016-08-02 14:43:59 +02:00
|
|
|
}
|
2015-04-26 19:22:20 +02:00
|
|
|
|
2016-08-02 14:43:59 +02:00
|
|
|
public function collectData(array $param){
|
2016-08-02 14:41:54 +02:00
|
|
|
|
|
|
|
function CommonDreamsUrl($string) {
|
2016-08-02 14:43:59 +02:00
|
|
|
$html2 = explode(" ", $string);
|
|
|
|
$string = $html2[2] . "/node/" . $html2[0];
|
|
|
|
return $string;
|
2016-08-02 14:41:54 +02:00
|
|
|
}
|
|
|
|
|
2016-06-25 23:17:42 +02:00
|
|
|
$html = $this->file_get_html('http://www.commondreams.org/rss.xml') or $this->returnError('Could not request CommonDreams.', 404);
|
2015-04-26 19:22:20 +02:00
|
|
|
$limit = 0;
|
|
|
|
foreach($html->find('item') as $element) {
|
2016-08-02 14:43:59 +02:00
|
|
|
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++;
|
|
|
|
}
|
2015-04-26 19:22:20 +02:00
|
|
|
}
|
2016-08-02 14:43:59 +02:00
|
|
|
}
|
2015-04-26 19:22:20 +02:00
|
|
|
|
2016-08-02 14:43:59 +02:00
|
|
|
public function getName(){
|
|
|
|
return 'CommonDreams Bridge';
|
|
|
|
}
|
2015-04-26 19:22:20 +02:00
|
|
|
|
2016-08-02 14:43:59 +02:00
|
|
|
public function getURI(){
|
|
|
|
return 'http://www.commondreams.org/';
|
|
|
|
}
|
2015-04-26 19:22:20 +02:00
|
|
|
|
2016-08-02 14:43:59 +02:00
|
|
|
public function getCacheDuration(){
|
|
|
|
return 3600; // 1 hours
|
|
|
|
}
|
2015-04-26 19:22:20 +02:00
|
|
|
}
|