OpenTheoryBridge.php 1.5 KB

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