NextInpactBridge.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. class NextInpactBridge extends BridgeAbstract {
  3. public function loadMetadatas() {
  4. $this->maintainer = "qwertygc";
  5. $this->name = "NextInpact Bridge";
  6. $this->uri = "http://www.nextinpact.com/";
  7. $this->description = "Returns the newest articles.";
  8. }
  9. private function StripCDATA($string) {
  10. $string = str_replace('<![CDATA[', '', $string);
  11. $string = str_replace(']]>', '', $string);
  12. return $string;
  13. }
  14. private function ExtractContent($url) {
  15. $html2 = $this->getSimpleHTMLDOM($url);
  16. $text = '<p><em>'.$html2->find('span.sub_title', 0)->innertext.'</em></p>'
  17. .'<p><img src="'.$html2->find('div.container_main_image_article', 0)->find('img.dedicated',0)->src.'" alt="-" /></p>'
  18. .'<div>'.$html2->find('div[itemprop=articleBody]', 0)->innertext.'</div>';
  19. $premium_article = $html2->find('h2.title_reserve_article', 0);
  20. if (is_object($premium_article))
  21. $text = $text.'<p><em>'.$premium_article->innertext.'</em></p>';
  22. return $text;
  23. }
  24. public function collectData(array $param) {
  25. $html = $this->getSimpleHTMLDOM('http://www.nextinpact.com/rss/news.xml') or $this->returnServerError('Could not request NextInpact.');
  26. $limit = 0;
  27. foreach($html->find('item') as $element) {
  28. if($limit < 3) {
  29. $item = array();
  30. $item['title'] = $this->StripCDATA($element->find('title', 0)->innertext);
  31. $item['uri'] = $this->StripCDATA($element->find('guid', 0)->plaintext);
  32. $item['author'] = $this->StripCDATA($element->find('creator', 0)->innertext);
  33. $item['timestamp'] = strtotime($element->find('pubDate', 0)->plaintext);
  34. $item['content'] = $this->ExtractContent($item['uri']);
  35. $this->items[] = $item;
  36. $limit++;
  37. }
  38. }
  39. }
  40. }