NeuviemeArtBridge.php 3.0 KB

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