FrandroidBridge.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. /**
  3. * RssBridgeFrandroid
  4. * Returns the RSS feed from Frandroid (full text articles)
  5. *
  6. * @name Frandroid
  7. * @homepage http://www.frandroid.com/
  8. * @description Returns the RSS feed from Frandroid (full text articles)
  9. * @maintainer Daiyousei
  10. * @update 2015-03-05
  11. */
  12. class FrandroidBridge extends BridgeAbstract
  13. {
  14. public function collectData(array $param)
  15. {
  16. function FrandroidStripCDATA($string)
  17. {
  18. $string = str_replace('<![CDATA[', '', $string);
  19. $string = str_replace(']]>', '', $string);
  20. return $string;
  21. }
  22. function FrandroidExtractContent($url)
  23. {
  24. $html2 = file_get_html($url);
  25. $html3 = $html2->find('div.post-content', 0);
  26. $html3->find('div.no-sidebar-ad-top', 0)->outertext = '';
  27. $ret = $html3->find('div.shortcode-container');
  28. foreach ($ret as $value) {
  29. $value->outertext = '';
  30. }
  31. $html3->find('div#hrr-link', 0)->outertext = '';
  32. $text = $html3->innertext;
  33. $text = strip_tags($text, '<h1><span><h2><p><b><a><blockquote><img><em><ul><ol>');
  34. return $text;
  35. }
  36. $html = file_get_html('http://feeds.feedburner.com/Frandroid?format=xml') or $this->returnError('Could not request Frandroid.', 404);
  37. $limit = 0;
  38. foreach ($html->find('item') as $element) {
  39. if ($limit < 5) {
  40. $item = new \Item();
  41. $item->title = FrandroidStripCDATA($element->find('title', 0)->innertext);
  42. $item->uri = FrandroidStripCDATA($element->find('guid', 0)->plaintext);
  43. $item->timestamp = strtotime($element->find('pubDate', 0)->plaintext);
  44. $item->content = FrandroidExtractContent($item->uri);
  45. $this->items[] = $item;
  46. $limit++;
  47. }
  48. }
  49. }
  50. public function getName()
  51. {
  52. return 'Frandroid';
  53. }
  54. public function getURI()
  55. {
  56. return 'http://www.frandroid.com/';
  57. }
  58. public function getCacheDuration()
  59. {
  60. return 300; // 5min
  61. }
  62. }