ReporterreBridge.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. class ReporterreBridge extends BridgeAbstract{
  3. public function loadMetadatas() {
  4. $this->maintainer = "nyutag";
  5. $this->name = "Reporterre Bridge";
  6. $this->uri = "http://www.reporterre.net/";
  7. $this->description = "Returns the newest articles.";
  8. $this->update = "2015-04-07";
  9. }
  10. public function collectData(array $param){
  11. function ExtractContentReporterre($url) {
  12. $html2 = $this->file_get_html($url);
  13. foreach($html2->find('div[style=text-align:justify]') as $e) {
  14. $text = $e->outertext;
  15. }
  16. $html2->clear();
  17. unset ($html2);
  18. return $text;
  19. }
  20. $html = $this->file_get_html('http://www.reporterre.net/spip.php?page=backend') or $this->returnError('Could not request Reporterre.', 404);
  21. $limit = 0;
  22. foreach($html->find('item') as $element) {
  23. if($limit < 5) {
  24. $item = new \Item();
  25. $item->title = html_entity_decode($element->find('title', 0)->plaintext);
  26. $item->timestamp = strtotime($element->find('dc:date', 0)->plaintext);
  27. $item->uri = $element->find('guid', 0)->innertext;
  28. $item->content = html_entity_decode(ExtractContentReporterre($item->uri));
  29. $this->items[] = $item;
  30. $limit++;
  31. }
  32. }
  33. }
  34. public function getName(){
  35. return 'Reporterre Bridge';
  36. }
  37. public function getURI(){
  38. return 'http://www.reporterre.net/';
  39. }
  40. public function getCacheDuration(){
  41. return 3600; // 1 hours
  42. // return 0;
  43. }
  44. }