PlanetLibreBridge.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  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. }
  9. private function PlanetLibreExtractContent($url){
  10. $html2 = $this->getSimpleHTMLDOM($url);
  11. $text = $html2->find('div[class="post-text"]', 0)->innertext;
  12. return $text;
  13. }
  14. public function collectData(array $param){
  15. $html = $this->getSimpleHTMLDOM('http://www.planet-libre.org/') or $this->returnServerError('Could not request PlanetLibre.');
  16. $limit = 0;
  17. foreach($html->find('div.post') as $element) {
  18. if($limit < 5) {
  19. $item = array();
  20. $item['title'] = $element->find('h1', 0)->plaintext;
  21. $item['uri'] = $element->find('a', 0)->href;
  22. $item['timestamp'] = strtotime(str_replace('/', '-', $element->find('div[class="post-date"]', 0)->plaintext));
  23. $item['content'] = $this->PlanetLibreExtractContent($item['uri']);
  24. $this->items[] = $item;
  25. $limit++;
  26. }
  27. }
  28. }
  29. public function getCacheDuration(){
  30. return 3600*2; // 1 hour
  31. }
  32. }