BastaBridge.php 1.1 KB

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