PlanetLibreBridge.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. <?php
  2. class PlanetLibreBridge extends BridgeAbstract{
  3. const MAINTAINER = "pit-fgfjiudghdf";
  4. const NAME = "PlanetLibre";
  5. const URI = "http://www.planet-libre.org";
  6. const DESCRIPTION = "Returns the 5 newest posts from PlanetLibre (full text)";
  7. private function PlanetLibreExtractContent($url){
  8. $html2 = getSimpleHTMLDOM($url);
  9. $text = $html2->find('div[class="post-text"]', 0)->innertext;
  10. return $text;
  11. }
  12. public function collectData(){
  13. $html = getSimpleHTMLDOM(self::URI)
  14. or returnServerError('Could not request PlanetLibre.');
  15. $limit = 0;
  16. foreach($html->find('div.post') as $element) {
  17. if($limit < 5) {
  18. $item = array();
  19. $item['title'] = $element->find('h1', 0)->plaintext;
  20. $item['uri'] = $element->find('a', 0)->href;
  21. $item['timestamp'] = strtotime(str_replace('/', '-', $element->find('div[class="post-date"]', 0)->plaintext));
  22. $item['content'] = $this->PlanetLibreExtractContent($item['uri']);
  23. $this->items[] = $item;
  24. $limit++;
  25. }
  26. }
  27. }
  28. public function getCacheDuration(){
  29. return 3600*2; // 1 hour
  30. }
  31. }