BastaBridge.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. class BastaBridge extends BridgeAbstract{
  3. public function loadMetadatas() {
  4. $this->maintainer = "qwertygc";
  5. $this->name = "Bastamag Bridge";
  6. $this->uri = "http://www.bastamag.net/";
  7. $this->description = "Returns the newest articles.";
  8. }
  9. public function collectData(array $param){
  10. // Replaces all relative image URLs by absolute URLs. Relative URLs always start with 'local/'!
  11. function ReplaceImageUrl($content){
  12. return preg_replace('/src=["\']{1}([^"\']+)/ims', 'src=\'http://www.bastamag.net/$1\'', $content);
  13. }
  14. $html = $this->getSimpleHTMLDOM('http://www.bastamag.net/spip.php?page=backend') or $this->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($this->getSimpleHTMLDOM($item['uri'])->find('div.texte', 0)->innertext);
  23. $this->items[] = $item;
  24. $limit++;
  25. }
  26. }
  27. }
  28. public function getCacheDuration(){
  29. return 3600*2; // 2 hours
  30. }
  31. }
  32. ?>