NeuviemeArtBridge.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. } return $string;
  13. }
  14. protected function parseItem($item){
  15. $item = parent::parseItem($item);
  16. $article_html = getSimpleHTMLDOMCached($item['uri']);
  17. if(!$article_html){
  18. $item['content'] = 'Could not request 9eme Art: '.$item['uri'];
  19. return $item;
  20. }
  21. $article_image = '';
  22. foreach ($article_html->find('img.img_full') as $img){
  23. if ($img->alt == $item['title']){
  24. $article_image = self::URI.$img->src;
  25. break;
  26. }
  27. }
  28. $article_content='';
  29. if($article_image){
  30. $article_content = '<p><img src="'.$article_image.'" /></p>';
  31. }
  32. $article_content .= str_replace(
  33. 'src="/', 'src="'.self::URI,
  34. $article_html->find('div.newsGenerique_con', 0)->innertext
  35. );
  36. $article_content = $this->StripWithDelimiters($article_content, '<script', '</script>');
  37. $article_content = $this->StripWithDelimiters($article_content, '<style', '</style>');
  38. $article_content = $this->StripWithDelimiters($article_content, '<link', '>');
  39. $item['content'] = $article_content;
  40. return $item;
  41. }
  42. public function collectData(){
  43. $feedUrl = self::URI.'9emeart.rss';
  44. $this->collectExpandableDatas($feedUrl);
  45. }
  46. }