PlanetLibreBridge.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. class PlanetLibreBridge extends BridgeAbstract{
  3. public function loadMetadatas() {
  4. $this->maintainer = "pit-fgfjiudghdf";
  5. $this->name = "PlanetLibre";
  6. $this->uri = "http://www.planet-libre.org";
  7. $this->description = "Returns the 5 newest posts from PlanetLibre (full text)";
  8. $this->update = "2014-05-26";
  9. }
  10. public function collectData(array $param){
  11. function PlanetLibreExtractContent($url) {
  12. $html2 = $this->file_get_html($url);
  13. $text = $html2->find('div[class="post-text"]', 0)->innertext;
  14. return $text;
  15. }
  16. $html = $this->file_get_html('http://www.planet-libre.org/') or $this->returnError('Could not request PlanetLibre.', 404);
  17. $limit = 0;
  18. foreach($html->find('div.post') as $element) {
  19. if($limit < 5) {
  20. $item = new \Item();
  21. $item->title = $element->find('h1', 0)->plaintext;
  22. $item->uri = $element->find('a', 0)->href;
  23. $item->timestamp = strtotime(str_replace('/', '-', $element->find('div[class="post-date"]', 0)->plaintext));
  24. $item->content = PlanetLibreExtractContent($item->uri);
  25. $this->items[] = $item;
  26. $limit++;
  27. }
  28. }
  29. }
  30. public function getName(){
  31. return 'PlanetLibre';
  32. }
  33. public function getURI(){
  34. return 'http://www.planet-libre.org/';
  35. }
  36. public function getCacheDuration(){
  37. return 3600*2; // 1 hour
  38. }
  39. }