ReporterreBridge.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. }
  9. private function ExtractContentReporterre($url) {
  10. $html2 = $this->getSimpleHTMLDOM($url);
  11. foreach($html2->find('div[style=text-align:justify]') as $e) {
  12. $text = $e->outertext;
  13. }
  14. $html2->clear();
  15. unset ($html2);
  16. // Replace all relative urls with absolute ones
  17. $text = preg_replace('/(href|src)(\=[\"\'])(?!http)([^"\']+)/ims', "$1$2" . $this->uri . "$3", $text);
  18. $text = strip_tags($text, '<p><br><a><img>');
  19. return $text;
  20. }
  21. public function collectData(array $param){
  22. $html = $this->getSimpleHTMLDOM('http://www.reporterre.net/spip.php?page=backend') or $this->returnServerError('Could not request Reporterre.');
  23. $limit = 0;
  24. foreach($html->find('item') as $element) {
  25. if($limit < 5) {
  26. $item = array();
  27. $item['title'] = html_entity_decode($element->find('title', 0)->plaintext);
  28. $item['timestamp'] = strtotime($element->find('dc:date', 0)->plaintext);
  29. $item['uri'] = $element->find('guid', 0)->innertext;
  30. $item['content'] = html_entity_decode($this->ExtractContentReporterre($item['uri']));
  31. $this->items[] = $item;
  32. $limit++;
  33. }
  34. }
  35. }
  36. }