RaymondBridge.php 1.7 KB

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