CoinDeskBridge.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. /**
  3. * RssBridgeCoinDesk
  4. * Returns the 5 newest posts from coindesk.com (full text)
  5. *
  6. * @name CoinDesk
  7. * @homepage http://www.coindesk.com/
  8. * @description Returns the 5 newest posts from CoinDesk (full text)
  9. * @maintainer mitsukarenai
  10. * @update 2014-05-30
  11. */
  12. class CoinDeskBridge extends BridgeAbstract{
  13. public function collectData(array $param){
  14. function CoinDeskStripCDATA($string) {
  15. $string = str_replace('<![CDATA[', '', $string);
  16. $string = str_replace(']]>', '', $string);
  17. return $string;
  18. }
  19. function CoinDeskExtractContent($url) {
  20. $html2 = file_get_html($url);
  21. $text = $html2->find('div.single-content', 0)->innertext;
  22. $text = strip_tags($text, '<p><a><img>');
  23. return $text;
  24. }
  25. $html = file_get_html('http://www.coindesk.com/feed/atom/') or $this->returnError('Could not request CoinDesk.', 404);
  26. $limit = 0;
  27. foreach($html->find('entry') as $element) {
  28. if($limit < 5) {
  29. $item = new \Item();
  30. $item->title = CoinDeskStripCDATA($element->find('title', 0)->innertext);
  31. $item->author = $element->find('author', 0)->plaintext;
  32. $item->uri = $element->find('link', 0)->href;
  33. $item->timestamp = strtotime($element->find('published', 0)->plaintext);
  34. $item->content = CoinDeskExtractContent($item->uri);
  35. $this->items[] = $item;
  36. $limit++;
  37. }
  38. }
  39. }
  40. public function getName(){
  41. return 'CoinDesk';
  42. }
  43. public function getURI(){
  44. return 'http://www.coindesk.com/';
  45. }
  46. public function getCacheDuration(){
  47. return 1800; // 30min
  48. }
  49. }