1
0

NumeramaBridge.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. /**
  3. * RssBridgeNumerama
  4. * Returns the 5 newest posts from http://www.numerama.com (full text)
  5. * 2014-05-25
  6. *
  7. * @name Numerama
  8. * @homepage http://www.numerama.com/
  9. * @description Returns the 5 newest posts from Numerama (full text)
  10. * @maintainer mitsukarenai
  11. */
  12. class NumeramaBridge extends BridgeAbstract{
  13. public function collectData(array $param){
  14. function NumeramaStripCDATA($string) {
  15. $string = str_replace('<![CDATA[', '', $string);
  16. $string = str_replace(']]>', '', $string);
  17. return $string;
  18. }
  19. function NumeramaExtractContent($url) {
  20. $html2 = file_get_html($url);
  21. $text = $html2->find('h2.intro', 0)->innertext;
  22. $text = $text.$html2->find('div.content', 0)->innertext;
  23. $text = strip_tags($text, '<p><b><a><blockquote><img><em><ul><ol>');
  24. return $text;
  25. }
  26. $html = file_get_html('http://www.numerama.com/rss/news.rss') or $this->returnError('Could not request Numerama.', 404);
  27. $limit = 0;
  28. foreach($html->find('item') as $element) {
  29. if($limit < 5) {
  30. $item = new \Item();
  31. $item->title = NumeramaStripCDATA($element->find('title', 0)->innertext);
  32. $item->uri = NumeramaStripCDATA($element->find('guid', 0)->plaintext);
  33. $item->timestamp = strtotime($element->find('pubDate', 0)->plaintext);
  34. $item->content = NumeramaExtractContent($item->uri);
  35. $this->items[] = $item;
  36. $limit++;
  37. }
  38. }
  39. }
  40. public function getName(){
  41. return 'Numerama';
  42. }
  43. public function getURI(){
  44. return 'http://www.numerama.com/';
  45. }
  46. public function getCacheDuration(){
  47. return 1800; // 30min
  48. }
  49. }