1
0

CommonDreamsBridge.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. /**
  3. * RssBridgeCommonDreams
  4. * Returns the newest articles
  5. * 2015-04-03
  6. *
  7. * @name CommonDreams Bridge
  8. * @homepage http://www.commondreams.org/
  9. * @description Returns the newest articles.
  10. * @maintainer nyutag
  11. */
  12. class CommonDreamsBridge extends BridgeAbstract{
  13. public function collectData(array $param){
  14. function CommonDreamsUrl($string) {
  15. $html2 = explode(" ", $string);
  16. $string = $html2[2] . "/node/" . $html2[0];
  17. return $string;
  18. }
  19. function CommonDreamsExtractContent($url) {
  20. $html3 = file_get_html($url);
  21. $text = $html3->find('div[class=field--type-text-with-summary]', 0)->innertext;
  22. return $text;
  23. }
  24. $html = file_get_html('http://www.commondreams.org/rss.xml') or $this->returnError('Could not request CommonDreams.', 404);
  25. $limit = 0;
  26. foreach($html->find('item') as $element) {
  27. if($limit < 2) {
  28. $item = new \Item();
  29. $item->title = $element->find('title', 0)->innertext;
  30. $item->uri = CommonDreamsUrl($element->find('guid', 0)->innertext);
  31. $item->timestamp = strtotime($element->find('pubDate', 0)->plaintext);
  32. $item->content = CommonDreamsExtractContent($item->uri);
  33. $this->items[] = $item;
  34. $limit++;
  35. }
  36. }
  37. }
  38. public function getName(){
  39. return 'CommonDreams Bridge';
  40. }
  41. public function getURI(){
  42. return 'http://www.commondreams.org/';
  43. }
  44. public function getCacheDuration(){
  45. // return 3600*2; // 2 hours
  46. return 0;
  47. }
  48. }