From 0cb66e21943f193c1da121cbc1cf31c0364be3c1 Mon Sep 17 00:00:00 2001 From: logmanoriginal Date: Thu, 4 Aug 2016 12:11:10 +0200 Subject: [PATCH 1/3] [Reporterre] Change nested function to member function This fixes error "Using $this when not in object context" Nested functions are not part of the object and therefore don't have access to the object instance $this! --- bridges/ReporterreBridge.php | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/bridges/ReporterreBridge.php b/bridges/ReporterreBridge.php index 6990022..f88d6d2 100644 --- a/bridges/ReporterreBridge.php +++ b/bridges/ReporterreBridge.php @@ -7,22 +7,21 @@ class ReporterreBridge extends BridgeAbstract{ $this->name = "Reporterre Bridge"; $this->uri = "http://www.reporterre.net/"; $this->description = "Returns the newest articles."; - $this->update = "2015-04-07"; + $this->update = "2016-08-04"; } + function ExtractContentReporterre($url) { + $html2 = $this->file_get_html($url); + foreach($html2->find('div[style=text-align:justify]') as $e) { + $text = $e->outertext; + } + $html2->clear(); + unset ($html2); + return $text; + } + public function collectData(array $param){ - - function ExtractContentReporterre($url) { - $html2 = $this->file_get_html($url); - foreach($html2->find('div[style=text-align:justify]') as $e) { - $text = $e->outertext; - } - $html2->clear(); - unset ($html2); - return $text; - } - $html = $this->file_get_html('http://www.reporterre.net/spip.php?page=backend') or $this->returnError('Could not request Reporterre.', 404); $limit = 0; @@ -32,7 +31,7 @@ class ReporterreBridge extends BridgeAbstract{ $item->title = html_entity_decode($element->find('title', 0)->plaintext); $item->timestamp = strtotime($element->find('dc:date', 0)->plaintext); $item->uri = $element->find('guid', 0)->innertext; - $item->content = html_entity_decode(ExtractContentReporterre($item->uri)); + $item->content = html_entity_decode($this->ExtractContentReporterre($item->uri)); $this->items[] = $item; $limit++; } From d6ff40c527f03d3430785be9de1e39f1de54a9cb Mon Sep 17 00:00:00 2001 From: logmanoriginal Date: Thu, 4 Aug 2016 12:34:19 +0200 Subject: [PATCH 2/3] [Reporterre] Replace relative image paths with absolute URL Images from their own servers are linked relatively via 'local/...' we must replace this for images to point to the correct destination. Also use strip_tags to get rid of iframes --- bridges/ReporterreBridge.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/bridges/ReporterreBridge.php b/bridges/ReporterreBridge.php index f88d6d2..b0dfb30 100644 --- a/bridges/ReporterreBridge.php +++ b/bridges/ReporterreBridge.php @@ -18,6 +18,12 @@ class ReporterreBridge extends BridgeAbstract{ } $html2->clear(); unset ($html2); + + // Replace all relative urls with absolute ones + $text = preg_replace('/(href|src)(\=[\"\'])(?!http)([^"\']+)/ims', "$1$2" . $this->getURI() . "$3", $text); + + $text = strip_tags($text, '


'); + return $text; } From 6162164bd43fdf0d43b4a57a68e25262d39a9ee4 Mon Sep 17 00:00:00 2001 From: logmanoriginal Date: Thu, 4 Aug 2016 12:34:40 +0200 Subject: [PATCH 3/3] [Reporterre] Fix indentation and remove empty lines --- bridges/ReporterreBridge.php | 49 +++++++++++++++++------------------- 1 file changed, 23 insertions(+), 26 deletions(-) diff --git a/bridges/ReporterreBridge.php b/bridges/ReporterreBridge.php index b0dfb30..1f5d021 100644 --- a/bridges/ReporterreBridge.php +++ b/bridges/ReporterreBridge.php @@ -2,59 +2,56 @@ class ReporterreBridge extends BridgeAbstract{ public function loadMetadatas() { - $this->maintainer = "nyutag"; $this->name = "Reporterre Bridge"; $this->uri = "http://www.reporterre.net/"; $this->description = "Returns the newest articles."; $this->update = "2016-08-04"; - } function ExtractContentReporterre($url) { $html2 = $this->file_get_html($url); + foreach($html2->find('div[style=text-align:justify]') as $e) { $text = $e->outertext; } + $html2->clear(); unset ($html2); // Replace all relative urls with absolute ones $text = preg_replace('/(href|src)(\=[\"\'])(?!http)([^"\']+)/ims', "$1$2" . $this->getURI() . "$3", $text); - - $text = strip_tags($text, '


'); + $text = strip_tags($text, '


'); return $text; } - public function collectData(array $param){ + public function collectData(array $param){ $html = $this->file_get_html('http://www.reporterre.net/spip.php?page=backend') or $this->returnError('Could not request Reporterre.', 404); $limit = 0; foreach($html->find('item') as $element) { - if($limit < 5) { - $item = new \Item(); - $item->title = html_entity_decode($element->find('title', 0)->plaintext); - $item->timestamp = strtotime($element->find('dc:date', 0)->plaintext); - $item->uri = $element->find('guid', 0)->innertext; - $item->content = html_entity_decode($this->ExtractContentReporterre($item->uri)); - $this->items[] = $item; - $limit++; - } + if($limit < 5) { + $item = new \Item(); + $item->title = html_entity_decode($element->find('title', 0)->plaintext); + $item->timestamp = strtotime($element->find('dc:date', 0)->plaintext); + $item->uri = $element->find('guid', 0)->innertext; + $item->content = html_entity_decode($this->ExtractContentReporterre($item->uri)); + $this->items[] = $item; + $limit++; + } } - - } + } - public function getName(){ - return 'Reporterre Bridge'; - } + public function getName(){ + return 'Reporterre Bridge'; + } - public function getURI(){ - return 'http://www.reporterre.net/'; - } + public function getURI(){ + return 'http://www.reporterre.net/'; + } - public function getCacheDuration(){ - return 3600; // 1 hours -// return 0; - } + public function getCacheDuration(){ + return 3600; // 1 hours + } }