BastaBridge.php 1.1 KB

1234567891011121314151617181920212223242526272829303132
  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. Relative URLs always start with 'local/'!
  10. function ReplaceImageUrl($content){
  11. return preg_replace('/src=["\']{1}([^"\']+)/ims', 'src=\''.self::URI.'$1\'', $content);
  12. }
  13. $html = getSimpleHTMLDOM(self::URI.'spip.php?page=backend')
  14. or returnServerError('Could not request Bastamag.');
  15. $limit = 0;
  16. foreach($html->find('item') as $element) {
  17. if($limit < 10) {
  18. $item = array();
  19. $item['title'] = $element->find('title', 0)->innertext;
  20. $item['uri'] = $element->find('guid', 0)->plaintext;
  21. $item['timestamp'] = strtotime($element->find('dc:date', 0)->plaintext);
  22. $item['content'] = ReplaceImageUrl(getSimpleHTMLDOM($item['uri'])->find('div.texte', 0)->innertext);
  23. $this->items[] = $item;
  24. $limit++;
  25. }
  26. }
  27. }
  28. }
  29. ?>