NeuviemeArtBridge.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. class NeuviemeArtBridge extends FeedExpander {
  3. const MAINTAINER = 'ORelio';
  4. const NAME = '9ème Art Bridge';
  5. const URI = 'http://www.9emeart.fr/';
  6. const DESCRIPTION = 'Returns the newest articles.';
  7. private function stripWithDelimiters($string, $start, $end){
  8. while(strpos($string, $start) !== false) {
  9. $section_to_remove = substr($string, strpos($string, $start));
  10. $section_to_remove = substr($section_to_remove, 0, strpos($section_to_remove, $end) + strlen($end));
  11. $string = str_replace($section_to_remove, '', $string);
  12. }
  13. return $string;
  14. }
  15. protected function parseItem($item){
  16. $item = parent::parseItem($item);
  17. $article_html = getSimpleHTMLDOMCached($item['uri']);
  18. if(!$article_html) {
  19. $item['content'] = 'Could not request 9eme Art: ' . $item['uri'];
  20. return $item;
  21. }
  22. $article_image = '';
  23. foreach ($article_html->find('img.img_full') as $img) {
  24. if ($img->alt == $item['title']) {
  25. $article_image = self::URI . $img->src;
  26. break;
  27. }
  28. }
  29. $article_content = '';
  30. if($article_image) {
  31. $article_content = '<p><img src="' . $article_image . '" /></p>';
  32. }
  33. $article_content .= str_replace(
  34. 'src="/', 'src="' . self::URI,
  35. $article_html->find('div.newsGenerique_con', 0)->innertext
  36. );
  37. $article_content = $this->stripWithDelimiters($article_content, '<script', '</script>');
  38. $article_content = $this->stripWithDelimiters($article_content, '<style', '</style>');
  39. $article_content = $this->stripWithDelimiters($article_content, '<link', '>');
  40. $item['content'] = $article_content;
  41. return $item;
  42. }
  43. public function collectData(){
  44. $feedUrl = self::URI . '9emeart.rss';
  45. $this->collectExpandableDatas($feedUrl);
  46. }
  47. }