ReporterreBridge.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. class ReporterreBridge extends BridgeAbstract{
  3. const MAINTAINER = "nyutag";
  4. const NAME = "Reporterre Bridge";
  5. const URI = "http://www.reporterre.net/";
  6. const DESCRIPTION = "Returns the newest articles.";
  7. private function ExtractContentReporterre($url) {
  8. $html2 = getSimpleHTMLDOM($url);
  9. foreach($html2->find('div[style=text-align:justify]') as $e) {
  10. $text = $e->outertext;
  11. }
  12. $html2->clear();
  13. unset ($html2);
  14. // Replace all relative urls with absolute ones
  15. $text = preg_replace('/(href|src)(\=[\"\'])(?!http)([^"\']+)/ims', "$1$2" . self::URI . "$3", $text);
  16. $text = strip_tags($text, '<p><br><a><img>');
  17. return $text;
  18. }
  19. public function collectData(){
  20. $html = getSimpleHTMLDOM(self::URI.'spip.php?page=backend') or returnServerError('Could not request Reporterre.');
  21. $limit = 0;
  22. foreach($html->find('item') as $element) {
  23. if($limit < 5) {
  24. $item = array();
  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($this->ExtractContentReporterre($item['uri']));
  29. $this->items[] = $item;
  30. $limit++;
  31. }
  32. }
  33. }
  34. }