NiceMatinBridge.php 1.6 KB

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