NextInpactBridge.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. $this->update = "2015-10-23";
  9. }
  10. public function collectData(array $param) {
  11. function StripCDATA($string) {
  12. $string = str_replace('<![CDATA[', '', $string);
  13. $string = str_replace(']]>', '', $string);
  14. return $string;
  15. }
  16. function ExtractContent($url) {
  17. $html2 = $this->file_get_html($url);
  18. $text = '<p><em>'.$html2->find('span.sub_title', 0)->innertext.'</em></p>'
  19. .'<p><img src="'.$html2->find('div.container_main_image_article', 0)->find('img.dedicated',0)->src.'" alt="-" /></p>'
  20. .'<div>'.$html2->find('div[itemprop=articleBody]', 0)->innertext.'</div>';
  21. $premium_article = $html2->find('h2.title_reserve_article', 0);
  22. if (is_object($premium_article))
  23. $text = $text.'<p><em>'.$premium_article->innertext.'</em></p>';
  24. return $text;
  25. }
  26. $html = $this->file_get_html('http://www.nextinpact.com/rss/news.xml') or $this->returnError('Could not request NextInpact.', 404);
  27. $limit = 0;
  28. foreach($html->find('item') as $element) {
  29. if($limit < 3) {
  30. $item = new \Item();
  31. $item->title = StripCDATA($element->find('title', 0)->innertext);
  32. $item->uri = StripCDATA($element->find('guid', 0)->plaintext);
  33. $item->thumbnailUri = StripCDATA($element->find('enclosure', 0)->url);
  34. $item->author = StripCDATA($element->find('author', 0)->innertext);
  35. $item->timestamp = strtotime($element->find('pubDate', 0)->plaintext);
  36. $item->content = ExtractContent($item->uri);
  37. $this->items[] = $item;
  38. $limit++;
  39. }
  40. }
  41. }
  42. public function getName() {
  43. return 'Nextinpact Bridge';
  44. }
  45. public function getURI() {
  46. return 'http://www.nextinpact.com/';
  47. }
  48. public function getCacheDuration() {
  49. return 3600; // 1 hour
  50. // return 0;
  51. }
  52. }