OpenTheoryBridge.php 1.5 KB

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