SegfaultMintBridge.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. class SegfaultMintBridge extends BridgeAbstract{
  3. public function loadMetadatas() {
  4. $this->maintainer = "qwertygc";
  5. $this->name = "SegfaultMint";
  6. $this->uri = "http://segfault.linuxmint.com/";
  7. $this->description = "Returns the 5 newest posts from SegfaultMint (full text)";
  8. $this->update = "2014-07-05";
  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.post-bodycopy', 0)->innertext;
  19. $text = preg_replace('@<script[^>]*?>.*?</script>@si', '', $text);
  20. return $text;
  21. }
  22. $html = $this->file_get_html('http://segfault.linuxmint.com/feed/') or $this->returnError('Could not request segfault.', 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 'Segfault Mint';
  38. }
  39. public function getURI(){
  40. return 'http://segfault.linuxmint.com/feed/';
  41. }
  42. public function getCacheDuration(){
  43. return 3600*24; // 24 hours
  44. }
  45. }