GizmodoFRBridge.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. $this->update = "2014-07-14";
  9. }
  10. public function collectData(array $param){
  11. function GizmodoFRExtractContent($url) {
  12. $articleHTMLContent = $this->file_get_html($url);
  13. $text = $articleHTMLContent->find('div.entry-thumbnail', 0)->innertext;
  14. $text = $text.$articleHTMLContent->find('div.entry-excerpt', 0)->innertext;
  15. $text = $text.$articleHTMLContent->find('div.entry-content', 0)->innertext;
  16. foreach($articleHTMLContent->find('pagespeed_iframe') as $element) {
  17. $text = $text.'<p>link to a iframe (could be a video): <a href="'.$element->src.'">'.$element->src.'</a></p><br>';
  18. }
  19. $text = strip_tags($text, '<p><b><a><blockquote><img><em>');
  20. return $text;
  21. }
  22. $rssFeed = $this->file_get_html('http://www.gizmodo.fr/feed') or $this->returnError('Could not request http://www.gizmodo.fr/feed', 404);
  23. $limit = 0;
  24. foreach($rssFeed->find('item') as $element) {
  25. if($limit < 15) {
  26. $item = new \Item();
  27. $item->title = $element->find('title', 0)->innertext;
  28. $item->uri = $element->find('guid', 0)->plaintext;
  29. $item->timestamp = strtotime($element->find('pubDate', 0)->plaintext);
  30. $item->content = GizmodoFRExtractContent($item->uri);
  31. $this->items[] = $item;
  32. $limit++;
  33. }
  34. }
  35. }
  36. public function getName(){
  37. return 'GizmodoFR';
  38. }
  39. public function getURI(){
  40. return 'http://www.gizmodo.fr/';
  41. }
  42. public function getCacheDuration(){
  43. return 1800; // 30min
  44. }
  45. }