1
0

NiceMatinBridge.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 = "2016-08-06";
  9. }
  10. private function NiceMatinExtractContent($url) {
  11. $html = $this->file_get_html($url);
  12. if(!$html)
  13. $this->returnError('Could not acquire content from url: ' . $url . '!', 404);
  14. $content = $html->find('article', 0);
  15. if(!$content)
  16. $this->returnError('Could not find \'section\'!', 404);
  17. $text = preg_replace('#<script(.*?)>(.*?)</script>#is', '', $content->innertext);
  18. $text = strip_tags($text, '<p><a><img>');
  19. return $text;
  20. }
  21. public function collectData(array $param){
  22. $html = $this->file_get_html('http://www.nicematin.com/derniere-minute/rss') or $this->returnError('Could not request NiceMatin.', 404);
  23. $limit = 0;
  24. foreach($html->find('item') as $element) {
  25. if($limit < 10) {
  26. // We need to fix the 'link' tag as simplehtmldom cannot parse it (just rename it and load back as dom)
  27. $element_text = $element->outertext;
  28. $element_text = str_replace('<link>', '<url>', $element_text);
  29. $element_text = str_replace('</link>', '</url>', $element_text);
  30. $element = str_get_html($element_text);
  31. $item = new \Item();
  32. $item->title = $element->find('title', 0)->innertext;
  33. $item->uri = $element->find('url', 0)->innertext;
  34. $item->timestamp = strtotime($element->find('pubDate', 0)->plaintext);
  35. $item->content = $this->NiceMatinExtractContent($item->uri);
  36. $this->items[] = $item;
  37. $limit++;
  38. }
  39. }
  40. }
  41. public function getName(){
  42. return 'NiceMatin';
  43. }
  44. public function getURI(){
  45. return 'http://www.nicematin.com/';
  46. }
  47. }