PlanetLibreBridge.php 1015 B

1234567891011121314151617181920212223242526272829303132333435363738
  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 extractContent($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(
  22. str_replace(
  23. '/',
  24. '-',
  25. $element->find('div[class="post-date"]', 0)->plaintext
  26. )
  27. );
  28. $item['content'] = $this->extractContent($item['uri']);
  29. $this->items[] = $item;
  30. $limit++;
  31. }
  32. }
  33. }
  34. }