rss-bridge/bridges/CommonDreamsBridge.php

40 lines
1.2 KiB
PHP
Raw Normal View History

2015-04-26 20:22:20 +03:00
<?php
class CommonDreamsBridge extends BridgeAbstract{
const MAINTAINER = "nyutag";
const NAME = "CommonDreams Bridge";
const URI = "http://www.commondreams.org/";
const DESCRIPTION = "Returns the newest articles.";
private function CommonDreamsExtractContent($url) {
$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;
}
2015-04-26 20:22:20 +03:00
public function collectData(){
function CommonDreamsUrl($string) {
$html2 = explode(" ", $string);
$string = $html2[2] . "/node/" . $html2[0];
return $string;
}
$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) {
if($limit < 4) {
$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']);
$this->items[] = $item;
$limit++;
}
2015-04-26 20:22:20 +03:00
}
}
2015-04-26 20:22:20 +03:00
}