From c3086fa20bc6021bc1c2b4ceeda6b976be730771 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre=20Mazi=C3=A8re?= Date: Sun, 28 Aug 2016 13:57:40 +0200 Subject: [PATCH] [DauphineLibereBridge] code simplification MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Pierre Mazière --- bridges/DauphineLibereBridge.php | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/bridges/DauphineLibereBridge.php b/bridges/DauphineLibereBridge.php index d4fa6b7..1084969 100644 --- a/bridges/DauphineLibereBridge.php +++ b/bridges/DauphineLibereBridge.php @@ -31,7 +31,7 @@ class DauphineLibereBridge extends BridgeAbstract { )); private function ExtractContent($url, $context) { - $html2 = $this->getSimpleHTMLDOM($url,false,$context); + $html2 = $this->getSimpleHTMLDOM($url); $text = $html2->find('div.column', 0)->innertext; $text = preg_replace('@]*?>.*?@si', '', $text); return $text; @@ -39,22 +39,14 @@ class DauphineLibereBridge extends BridgeAbstract { public function collectData(){ - // Simulate Mozilla user-agent to fix error 403 (Forbidden) - $opts = array('http' => - array( - 'method' => 'GET', - 'header' => 'User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36' - ) - ); - $context = stream_context_create($opts); - if (isset($this->getInput('u'))) { /* user timeline mode */ - $this->request = $this->getInput('u'); - $html = $this->getSimpleHTMLDOM('http://www.ledauphine.com/'.$this->request.'/rss',false,$context) or $this->returnServerError('Could not request DauphineLibere.'); - } - else { - $html = $this->getSimpleHTMLDOM('http://www.ledauphine.com/rss',false,$context) or $this->returnServerError('Could not request DauphineLibere.'); + if (empty($this->getInput('u'))) { + $html = $this->getSimpleHTMLDOM($this->uri.$this->getInput('u').'/rss') + or $this->returnServerError('Could not request DauphineLibere.'); + } else { + $html = $this->getSimpleHTMLDOM($this->uri.'rss') + or $this->returnServerError('Could not request DauphineLibere.'); } $limit = 0;