NiceMatinBridge.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. /**
  3. * RssBridgeNiceMatin
  4. * Returns the 10 newest posts from Nice Matin (full text)
  5. *
  6. * @name NiceMatin
  7. * @homepage http://www.nicematin.com/
  8. * @description Returns the 10 newest posts from NiceMatin (full text)
  9. * @maintainer pit-fgfjiudghdf
  10. * @update 2014-05-26
  11. */
  12. class NiceMatinBridge extends BridgeAbstract{
  13. public function collectData(array $param){
  14. function NiceMatinUrl($string) {
  15. $string = str_replace('</link>', '', $string);
  16. //$string = str_replace('.+', '', $string);
  17. $string = preg_replace('/html.*http.*/i','html',$string);
  18. $string = preg_replace('/.*http/i','http',$string);
  19. return $string;
  20. }
  21. function NiceMatinExtractContent($url) {
  22. $html2 = file_get_html($url);
  23. $text = $html2->find('figure[itemprop=associatedMedia]', 0)->innertext;
  24. $text .= $html2->find('div[id=content-article]', 0)->innertext;
  25. return $text;
  26. }
  27. $html = file_get_html('http://www.nicematin.com/derniere-minute/rss') or $this->returnError('Could not request NiceMatin.', 404);
  28. $limit = 0;
  29. foreach($html->find('item') as $element) {
  30. if($limit < 10) {
  31. $item = new \Item();
  32. //$item->title = NiceMatinStripCDATA($element->find('title', 0)->innertext);
  33. $item->title = $element->find('title', 0)->innertext;
  34. $item->uri = NiceMatinUrl($element->plaintext);
  35. $item->timestamp = strtotime($element->find('pubDate', 0)->plaintext);
  36. $item->content = NiceMatinExtractContent($item->uri);
  37. $this->items[] = $item;
  38. $limit++;
  39. }
  40. }
  41. }
  42. public function getName(){
  43. return 'NiceMatin';
  44. }
  45. public function getURI(){
  46. return 'http://www.nicematin.com/';
  47. }
  48. public function getCacheDuration(){
  49. return 3600; // 1 hour
  50. }
  51. }