NeuviemeArtBridge.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. class NeuviemeArtBridge extends BridgeAbstract {
  3. public function loadMetadatas() {
  4. $this->maintainer = "ORelio";
  5. $this->name = '9ème Art Bridge';
  6. $this->uri = "http://www.9emeart.fr/";
  7. $this->description = "Returns the newest articles.";
  8. }
  9. public function collectData(array $param) {
  10. function StripWithDelimiters($string, $start, $end) {
  11. while (strpos($string, $start) !== false) {
  12. $section_to_remove = substr($string, strpos($string, $start));
  13. $section_to_remove = substr($section_to_remove, 0, strpos($section_to_remove, $end) + strlen($end));
  14. $string = str_replace($section_to_remove, '', $string);
  15. } return $string;
  16. }
  17. $feedUrl = 'http://www.9emeart.fr/9emeart.rss';
  18. $html = $this->getSimpleHTMLDOM($feedUrl) or $this->returnServerError('Could not request 9eme Art: '.$feedUrl);
  19. $limit = 0;
  20. foreach ($html->find('item') as $element) {
  21. if ($limit < 5) {
  22. //Retrieve article Uri and get that page
  23. $article_uri = $element->find('guid', 0)->plaintext;
  24. $article_html = $this->getSimpleHTMLDOM($article_uri) or $this->returnServerError('Could not request 9eme Art: '.$article_uri);
  25. //Build article contents from corresponding elements
  26. $article_title = trim($element->find('title', 0)->plaintext);
  27. $article_image = $element->find('enclosure', 0)->url;
  28. foreach ($article_html->find('img.img_full') as $img)
  29. if ($img->alt == $article_title)
  30. $article_image = 'http://www.9emeart.fr'.$img->src;
  31. $article_content = '<p><img src="'.$article_image.'" /></p>'
  32. .str_replace('src="/', 'src="http://www.9emeart.fr/', $article_html->find('div.newsGenerique_con', 0)->innertext);
  33. $article_content = StripWithDelimiters($article_content, '<script', '</script>');
  34. $article_content = StripWithDelimiters($article_content, '<style', '</style>');
  35. $article_content = StripWithDelimiters($article_content, '<link', '>');
  36. //Build and add final item
  37. $item = array();
  38. $item['uri'] = $article_uri;
  39. $item['title'] = $article_title;
  40. $item['author'] = $article_html->find('a[class=upp transition_fast upp]', 0)->plaintext;
  41. $item['timestamp'] = strtotime($element->find('pubDate', 0)->plaintext);
  42. $item['content'] = $article_content;
  43. $this->items[] = $item;
  44. $limit++;
  45. }
  46. }
  47. }
  48. }