MemoLinuxBridge.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. class MemoLinuxBridge extends BridgeAbstract{
  3. public function loadMetadatas() {
  4. $this->maintainer = "qwertygc";
  5. $this->name = "MemoLinux";
  6. $this->uri = "http://memo-linux.com/";
  7. $this->description = "Returns the 10 newest posts from MemoLinux (full text)";
  8. $this->update = "2015-01-30";
  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. $text = preg_replace('@<div[^>]*?>.*?</div>@si', '', $text);
  21. $text = preg_replace("/<h1.*/", '', $text);
  22. return $text;
  23. }
  24. $html = $this->file_get_html('http://memo-linux.com/feed/') or $this->returnError('Could not request MemoLinux.', 404);
  25. $limit = 0;
  26. foreach($html->find('item') as $element) {
  27. if($limit < 10) {
  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 'MemoLinux';
  40. }
  41. public function getURI(){
  42. return 'http://memo-linux.com/feed/';
  43. }
  44. public function getCacheDuration(){
  45. return 3600*12; // 12 hours
  46. }
  47. }