ReporterreBridge.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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 extractContent($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(
  16. '/(href|src)(\=[\"\'])(?!http)([^"\']+)/ims',
  17. '$1$2' . self::URI . '$3',
  18. $text
  19. );
  20. $text = strip_tags($text, '<p><br><a><img>');
  21. return $text;
  22. }
  23. public function collectData(){
  24. $html = getSimpleHTMLDOM(self::URI . 'spip.php?page=backend')
  25. or returnServerError('Could not request Reporterre.');
  26. $limit = 0;
  27. foreach($html->find('item') as $element) {
  28. if($limit < 5) {
  29. $item = array();
  30. $item['title'] = html_entity_decode($element->find('title', 0)->plaintext);
  31. $item['timestamp'] = strtotime($element->find('dc:date', 0)->plaintext);
  32. $item['uri'] = $element->find('guid', 0)->innertext;
  33. $item['content'] = html_entity_decode($this->extractContent($item['uri']));
  34. $this->items[] = $item;
  35. $limit++;
  36. }
  37. }
  38. }
  39. }