CommonDreamsBridge.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. class CommonDreamsBridge extends BridgeAbstract{
  3. public function loadMetadatas() {
  4. $this->maintainer = "nyutag";
  5. $this->name = "CommonDreams Bridge";
  6. $this->uri = "http://www.commondreams.org/";
  7. $this->description = "Returns the newest articles.";
  8. }
  9. private function CommonDreamsExtractContent($url) {
  10. $html3 = $this->getSimpleHTMLDOM($url);
  11. $text = $html3->find('div[class=field--type-text-with-summary]', 0)->innertext;
  12. $html3->clear();
  13. unset ($html3);
  14. return $text;
  15. }
  16. public function collectData(array $param){
  17. function CommonDreamsUrl($string) {
  18. $html2 = explode(" ", $string);
  19. $string = $html2[2] . "/node/" . $html2[0];
  20. return $string;
  21. }
  22. $html = $this->getSimpleHTMLDOM('http://www.commondreams.org/rss.xml') or $this->returnServerError('Could not request CommonDreams.');
  23. $limit = 0;
  24. foreach($html->find('item') as $element) {
  25. if($limit < 4) {
  26. $item = array();
  27. $item['title'] = $element->find('title', 0)->innertext;
  28. $item['uri'] = CommonDreamsUrl($element->find('guid', 0)->innertext);
  29. $item['timestamp'] = strtotime($element->find('pubDate', 0)->plaintext);
  30. $item['content'] = $this->CommonDreamsExtractContent($item['uri']);
  31. $this->items[] = $item;
  32. $limit++;
  33. }
  34. }
  35. }
  36. }