GizmodoFRBridge.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. class GizmodoFRBridge extends BridgeAbstract{
  3. public function loadMetadatas() {
  4. $this->maintainer = "polopollo";
  5. $this->name = "GizmodoFR";
  6. $this->uri = "http://www.gizmodo.fr/";
  7. $this->description = "Returns the 15 newest posts from GizmodoFR (full text).";
  8. }
  9. public function collectData(array $param){
  10. function GizmodoFRExtractContent($url) {
  11. $articleHTMLContent = $this->getSimpleHTMLDOM($url);
  12. $text = $articleHTMLContent->find('div.entry-thumbnail', 0)->innertext;
  13. $text = $text.$articleHTMLContent->find('div.entry-excerpt', 0)->innertext;
  14. $text = $text.$articleHTMLContent->find('div.entry-content', 0)->innertext;
  15. foreach($articleHTMLContent->find('pagespeed_iframe') as $element) {
  16. $text = $text.'<p>link to a iframe (could be a video): <a href="'.$element->src.'">'.$element->src.'</a></p><br>';
  17. }
  18. $text = strip_tags($text, '<p><b><a><blockquote><img><em>');
  19. return $text;
  20. }
  21. $rssFeed = $this->getSimpleHTMLDOM('http://www.gizmodo.fr/feed') or $this->returnServerError('Could not request http://www.gizmodo.fr/feed');
  22. $limit = 0;
  23. foreach($rssFeed->find('item') as $element) {
  24. if($limit < 15) {
  25. $item = array();
  26. $item['title'] = $element->find('title', 0)->innertext;
  27. $item['uri'] = $element->find('guid', 0)->plaintext;
  28. $item['timestamp'] = strtotime($element->find('pubDate', 0)->plaintext);
  29. $item['content'] = GizmodoFRExtractContent($item['uri']);
  30. $this->items[] = $item;
  31. $limit++;
  32. }
  33. }
  34. }
  35. public function getCacheDuration(){
  36. return 1800; // 30min
  37. }
  38. }