BastaBridge.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. <?php
  2. class BastaBridge extends BridgeAbstract {
  3. const MAINTAINER = 'qwertygc';
  4. const NAME = 'Bastamag Bridge';
  5. const URI = 'http://www.bastamag.net/';
  6. const CACHE_TIMEOUT = 7200; // 2h
  7. const DESCRIPTION = 'Returns the newest articles.';
  8. public function collectData(){
  9. // Replaces all relative image URLs by absolute URLs.
  10. // Relative URLs always start with 'local/'!
  11. function replaceImageUrl($content){
  12. return preg_replace('/src=["\']{1}([^"\']+)/ims', 'src=\'' . self::URI . '$1\'', $content);
  13. }
  14. $html = getSimpleHTMLDOM(self::URI . 'spip.php?page=backend')
  15. or returnServerError('Could not request Bastamag.');
  16. $limit = 0;
  17. foreach($html->find('item') as $element) {
  18. if($limit < 10) {
  19. $item = array();
  20. $item['title'] = $element->find('title', 0)->innertext;
  21. $item['uri'] = $element->find('guid', 0)->plaintext;
  22. $item['timestamp'] = strtotime($element->find('dc:date', 0)->plaintext);
  23. $item['content'] = replaceImageUrl(getSimpleHTMLDOM($item['uri'])->find('div.texte', 0)->innertext);
  24. $this->items[] = $item;
  25. $limit++;
  26. }
  27. }
  28. }
  29. }