FSBridge.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. /**
  3. * RssBridgeFS
  4. * Returns the 5 newest posts from http://www.futura-sciences.com (full text)
  5. *
  6. * @name Futurasciences
  7. * @description Returns the 5 newest posts from FS (full text)
  8. * @homepage http://www.futura-sciences.com
  9. *@maintainer qwertygc
  10. */
  11. class FSBridge extends BridgeAbstract{
  12. public function collectData(array $param){
  13. function FS_StripCDATA($string) {
  14. $string = str_replace('<![CDATA[', '', $string);
  15. $string = str_replace(']]>', '', $string);
  16. return $string;
  17. }
  18. function FS_ExtractContent($url) {
  19. $html2 = file_get_html($url);
  20. $text = $html2->find('div.fiche-actualite', 0)->innertext;
  21. $text = preg_replace('@<script[^>]*?>.*?</script>@si', '', $text);
  22. return $text;
  23. }
  24. $html = file_get_html('http://www.futura-sciences.com/rss/actualites.xml') or $this->returnError('Could not request Futura Sciences.', 404);
  25. $limit = 0;
  26. foreach($html->find('item') as $element) {
  27. if($limit < 5) {
  28. $item = new \Item();
  29. $item->title = FS_StripCDATA($element->find('title', 0)->innertext);
  30. $item->uri = FS_StripCDATA($element->find('guid', 0)->plaintext);
  31. $item->timestamp = strtotime($element->find('pubDate', 0)->plaintext);
  32. $item->content = FS_ExtractContent($item->uri);
  33. $this->items[] = $item;
  34. $limit++;
  35. }
  36. }
  37. }
  38. public function getName(){
  39. return 'Futura Sciences';
  40. }
  41. public function getURI(){
  42. return 'http://www.futura-sciences.com/';
  43. }
  44. public function getCacheDuration(){
  45. return 3600; // 1 hour
  46. // return 0; // 1 hour
  47. }
  48. }