SegfaultMintBridge.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. /**
  3. * @name SegfaultMint
  4. * @homepage http://segfault.linuxmint.com/
  5. * @description Returns the 5 newest posts from SegfaultMint (full text)
  6. * @maintainer qwertygc
  7. * @update 2014-07-05
  8. */
  9. class SegfaultMintBridge extends BridgeAbstract{
  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 = 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 = 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. }