RaymondBridge.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. /**
  3. * RssBridgeRaymond
  4. * Returns the 3 newest posts from Raymond.cc (full text)
  5. *
  6. * @name Raymond
  7. * @homepage http://www.raymond.cc
  8. * @description Returns the 3 newest posts from Raymond.cc (full text)
  9. * @maintainer pit-fgfjiudghdf
  10. * @update 2014-05-26
  11. */
  12. class RaymondBridge extends BridgeAbstract{
  13. public function collectData(array $param){
  14. function raymondStripCDATA($string) {
  15. $string = str_replace('<![CDATA[', '', $string);
  16. $string = str_replace(']]>', '', $string);
  17. return $string;
  18. }
  19. function raymondExtractContent($url) {
  20. $html2 = file_get_html($url);
  21. $text = $html2->find('div.entry-content', 0)->innertext;
  22. $text = preg_replace('/class="ad".*/', '', $text);
  23. $text = strip_tags($text, '<p><a><i><strong><em><img>');
  24. $text = str_replace('(adsbygoogle = window.adsbygoogle || []).push({});', '', $text);
  25. return $text;
  26. }
  27. $html = file_get_html('http://www.raymond.cc/blog/feed') or $this->returnError('Could not request raymond.', 404);
  28. $limit = 0;
  29. foreach($html->find('item') as $element) {
  30. if($limit < 3) {
  31. $item = new \Item();
  32. $item->title = raymondStripCDATA($element->find('title', 0)->innertext);
  33. $item->uri = raymondStripCDATA($element->find('guid', 0)->plaintext);
  34. $item->timestamp = strtotime($element->find('pubDate', 0)->plaintext);
  35. $item->content = raymondExtractContent($item->uri);
  36. $this->items[] = $item;
  37. $limit++;
  38. }
  39. }
  40. }
  41. public function getName(){
  42. return 'raymond';
  43. }
  44. public function getURI(){
  45. return 'http://www.raymond.cc/blog';
  46. }
  47. public function getCacheDuration(){
  48. return 3600*12; // 12 hour
  49. }
  50. }