GuruMedBridge.php 1.4 KB

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