BastaBridge.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. $this->update = "2016-08-02";
  9. }
  10. public function collectData(array $param){
  11. // Replaces all relative image URLs by absolute URLs. Relative URLs always start with 'local/'!
  12. function ReplaceImageUrl($content){
  13. return preg_replace('/src=["\']{1}([^"\']+)/ims', 'src=\'http://www.bastamag.net/$1\'', $content);
  14. }
  15. $html = $this->file_get_html('http://www.bastamag.net/spip.php?page=backend') or $this->returnError('Could not request Bastamag.', 404);
  16. $limit = 0;
  17. foreach($html->find('item') as $element) {
  18. if($limit < 10) {
  19. $item = new \Item();
  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($this->file_get_html($item->uri)->find('div.texte', 0)->innertext);
  24. $this->items[] = $item;
  25. $limit++;
  26. }
  27. }
  28. }
  29. public function getName(){
  30. return 'Bastamag Bridge';
  31. }
  32. public function getURI(){
  33. return 'http://bastamag.net/';
  34. }
  35. public function getCacheDuration(){
  36. return 3600*2; // 2 hours
  37. }
  38. }
  39. ?>