From 7c62bf070b29769bc2e8a7d06ba5b0d70e2d3e91 Mon Sep 17 00:00:00 2001 From: Teromene Date: Tue, 21 Jun 2016 22:33:51 +0100 Subject: [PATCH] Fix Rue89Bridge --- bridges/Rue89Bridge.php | 54 ++++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 30 deletions(-) diff --git a/bridges/Rue89Bridge.php b/bridges/Rue89Bridge.php index cdd7780..d68b6ec 100644 --- a/bridges/Rue89Bridge.php +++ b/bridges/Rue89Bridge.php @@ -11,42 +11,36 @@ class Rue89Bridge extends BridgeAbstract{ } - public function collectData(array $param){ - function Rue89StripCDATA($string) { - $string = str_replace('', '', $string); - return $string; - } - function Rue89ExtractContent($url) { - $html2 = file_get_html($url); - //$text = $html2->find('div[class=text]', 0)->innertext; + private function rue89getDatas($url){ + + $url = "http://api.rue89.nouvelobs.com/export/mobile2/node/" . str_replace(" ", "", substr($url, -8)) . "/full"; + $datas = json_decode(file_get_contents($url), true); + + return $datas["node"]; - foreach($html2->find('img') as $image) { - $src = $image->getAttribute('data-src'); - if($src) $image->src = $src; } - $text = $html2->find('div.content', 0)->innertext; + public function collectData(array $param){ + + $html = file_get_html('http://api.rue89.nouvelobs.com/feed') or $this->returnError('Could not request Rue89.', 404); - $text = str_replace('href="/', 'href="http://rue89.nouvelobs.com/', $text); - $text = str_replace('src="/', 'src="http://rue89.nouvelobs.com/', $text); - $text = preg_replace('@]*?>.*?@si', '', $text); - $text = strip_tags($text, '

      '); - return $text; - } - $html = file_get_html('http://rue89.feedsportal.com/c/33822/f/608948/index.rss') or $this->returnError('Could not request Rue89.', 404); $limit = 0; foreach($html->find('item') as $element) { - if($limit < 5) { - $item = new \Item(); - $item->title = Rue89StripCDATA($element->find('title', 0)->innertext); - $item->name = Rue89StripCDATA($element->find('dc:creator', 0)->innertext); - $item->uri = str_replace('#commentaires', '', Rue89StripCDATA($element->find('comments', 0)->plaintext)); - $item->timestamp = strtotime($element->find('pubDate', 0)->plaintext); - $item->content = Rue89ExtractContent($item->uri); - $this->items[] = $item; - $limit++; - } + + if($limit < 5) { + + $datas = $this->rue89getDatas(str_replace('#commentaires', '', ($element->find('comments', 0)->plaintext))); + + $item = new \Item(); + $item->title = $datas["title"]; + $item->author = $datas["author"][0]["name"]; + $item->timestamp = $datas["updated"]; + $item->content = $datas["body"]; + $item->uri = $datas["url"]; + + $this->items[] = $item; + + } } }