From bba6a0b5c2555b70809fb64011a5f460851d6dc2 Mon Sep 17 00:00:00 2001 From: ORelio Date: Sat, 13 Feb 2016 13:52:28 +0100 Subject: [PATCH] [9emeArt] Add NeuviemeArtBridge --- bridges/NeuviemeArtBridge.php | 70 +++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 bridges/NeuviemeArtBridge.php diff --git a/bridges/NeuviemeArtBridge.php b/bridges/NeuviemeArtBridge.php new file mode 100644 index 00000000..d558b2d3 --- /dev/null +++ b/bridges/NeuviemeArtBridge.php @@ -0,0 +1,70 @@ +maintainer = "ORelio"; + $this->name = "9ème Art"; + $this->uri = "http://www.9emeart.fr/"; + $this->description = "Returns the newest articles."; + $this->update = "2016-02-05"; + } + + public function collectData(array $param) { + + function StripWithDelimiters($string, $start, $end) { + while (strpos($string, $start) !== false) { + $section_to_remove = substr($string, strpos($string, $start)); + $section_to_remove = substr($section_to_remove, 0, strpos($section_to_remove, $end) + strlen($end)); + $string = str_replace($section_to_remove, '', $string); + } return $string; + } + + $feedUrl = 'http://www.9emeart.fr/9emeart.rss'; + $html = file_get_html($feedUrl) or $this->returnError('Could not request 9eme Art: '.$feedUrl, 500); + $limit = 0; + + foreach ($html->find('item') as $element) { + if ($limit < 5) { + + //Retrieve article Uri and get that page + $article_uri = $element->find('guid', 0)->plaintext; + $article_html = file_get_html($article_uri) or $this->returnError('Could not request 9eme Art: '.$article_uri, 500); + + //Build article contents from corresponding elements + $article_title = trim($element->find('title', 0)->plaintext); + $article_image = $element->find('enclosure', 0)->url; + foreach ($article_html->find('img.img_full') as $img) + if ($img->alt == $article_title) + $article_image = 'http://www.9emeart.fr'.$img->src; + $article_content = '

' + .str_replace('src="/', 'src="http://www.9emeart.fr/', $article_html->find('div.newsGenerique_con', 0)->innertext); + $article_content = StripWithDelimiters($article_content, ''); + $article_content = StripWithDelimiters($article_content, ''); + $article_content = StripWithDelimiters($article_content, ''); + + //Build and add final item + $item = new \Item(); + $item->uri = $article_uri; + $item->title = $article_title; + $item->thumbnailUri = $element->find('enclosure', 0)->url; + $item->author = $article_html->find('a[class=upp transition_fast upp]', 0)->plaintext; + $item->timestamp = strtotime($element->find('pubDate', 0)->plaintext); + $item->content = $article_content; + $this->items[] = $item; + $limit++; + } + } + } + + public function getName() { + return '9ème Art Bridge'; + } + + public function getURI() { + return 'http://www.9emeart.fr/'; + } + + public function getCacheDuration() { + return 3600; //1 hour + } +} \ No newline at end of file