1
0
Fork 0
forked from blallo/rss-bridge

Merge pull request #274 from teromene/rue89

Fix Rue89Bridge
This commit is contained in:
Mitsu 2016-06-25 13:27:37 +02:00 committed by GitHub
commit 040f4da73d

View file

@ -11,41 +11,35 @@ class Rue89Bridge extends BridgeAbstract{
} }
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"];
}
public function collectData(array $param){ public function collectData(array $param){
function Rue89StripCDATA($string) {
$string = str_replace('<![CDATA[', '', $string);
$string = str_replace(']]>', '', $string);
return $string;
}
function Rue89ExtractContent($url) {
$html2 = file_get_html($url);
//$text = $html2->find('div[class=text]', 0)->innertext;
foreach($html2->find('img') as $image) { $html = file_get_html('http://api.rue89.nouvelobs.com/feed') or $this->returnError('Could not request Rue89.', 404);
$src = $image->getAttribute('data-src');
if($src) $image->src = $src;
}
$text = $html2->find('div.content', 0)->innertext;
$text = str_replace('href="/', 'href="http://rue89.nouvelobs.com/', $text);
$text = str_replace('src="/', 'src="http://rue89.nouvelobs.com/', $text);
$text = preg_replace('@<script[^>]*?>.*?</script>@si', '', $text);
$text = strip_tags($text, '<h1><h2><strong><p><b><a><blockquote><img><em><ul><ol>');
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; $limit = 0;
foreach($html->find('item') as $element) { foreach($html->find('item') as $element) {
if($limit < 5) { if($limit < 5) {
$datas = $this->rue89getDatas(str_replace('#commentaires', '', ($element->find('comments', 0)->plaintext)));
$item = new \Item(); $item = new \Item();
$item->title = Rue89StripCDATA($element->find('title', 0)->innertext); $item->title = $datas["title"];
$item->name = Rue89StripCDATA($element->find('dc:creator', 0)->innertext); $item->author = $datas["author"][0]["name"];
$item->uri = str_replace('#commentaires', '', Rue89StripCDATA($element->find('comments', 0)->plaintext)); $item->timestamp = $datas["updated"];
$item->timestamp = strtotime($element->find('pubDate', 0)->plaintext); $item->content = $datas["body"];
$item->content = Rue89ExtractContent($item->uri); $item->uri = $datas["url"];
$this->items[] = $item; $this->items[] = $item;
$limit++;
} }
} }