CommonDreamsBridge.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. $this->update = "2016-08-02";
  9. }
  10. function CommonDreamsExtractContent($url) {
  11. $html3 = $this->file_get_html($url);
  12. $text = $html3->find('div[class=field--type-text-with-summary]', 0)->innertext;
  13. $html3->clear();
  14. unset ($html3);
  15. return $text;
  16. }
  17. public function collectData(array $param){
  18. function CommonDreamsUrl($string) {
  19. $html2 = explode(" ", $string);
  20. $string = $html2[2] . "/node/" . $html2[0];
  21. return $string;
  22. }
  23. $html = $this->file_get_html('http://www.commondreams.org/rss.xml') or $this->returnError('Could not request CommonDreams.', 404);
  24. $limit = 0;
  25. foreach($html->find('item') as $element) {
  26. if($limit < 4) {
  27. $item = new \Item();
  28. $item->title = $element->find('title', 0)->innertext;
  29. $item->uri = CommonDreamsUrl($element->find('guid', 0)->innertext);
  30. $item->timestamp = strtotime($element->find('pubDate', 0)->plaintext);
  31. $item->content = $this->CommonDreamsExtractContent($item->uri);
  32. $this->items[] = $item;
  33. $limit++;
  34. }
  35. }
  36. }
  37. public function getName(){
  38. return 'CommonDreams Bridge';
  39. }
  40. public function getURI(){
  41. return 'http://www.commondreams.org/';
  42. }
  43. public function getCacheDuration(){
  44. return 3600; // 1 hours
  45. }
  46. }