NiceMatinBridge.php 1.8 KB

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