From 0668f79704099243778e9302a16755b0db8a2322 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre=20Mazi=C3=A8re?= Date: Mon, 29 Aug 2016 12:42:34 +0200 Subject: [PATCH] [LeBonCoinBridge] code simplification MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Pierre Mazière --- bridges/LeBonCoinBridge.php | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/bridges/LeBonCoinBridge.php b/bridges/LeBonCoinBridge.php index 3779952..fab1a71 100755 --- a/bridges/LeBonCoinBridge.php +++ b/bridges/LeBonCoinBridge.php @@ -3,7 +3,7 @@ class LeBonCoinBridge extends BridgeAbstract{ public $maintainer = "16mhz"; public $name = "LeBonCoin"; - public $uri = "http://www.leboncoin.fr"; + public $uri = "http://www.leboncoin.fr/"; public $description = "Returns most recent results from LeBonCoin for a region, and optionally a category and a keyword ."; public $parameters = array( array( @@ -44,6 +44,7 @@ class LeBonCoinBridge extends BridgeAbstract{ 'name'=>'Catégorie', 'type'=>'list', 'values'=>array( + 'TOUS'=>'', 'EMPLOI'=>'_emploi_', 'VEHICULES'=>array( 'Tous'=>'_vehicules_', @@ -136,14 +137,16 @@ class LeBonCoinBridge extends BridgeAbstract{ public function collectData(){ - $html = ''; - if (empty($this->getInput('c'))) { - $link = 'http://www.leboncoin.fr/annonces/offres/' . $this->getInput('r') . '/?f=a&th=1&q=' . urlencode($this->getInput('k')); - } - else { - $link = 'http://www.leboncoin.fr/' . $this->getInput('c') . '/offres/' . $this->getInput('r') . '/?f=a&th=1&q=' . urlencode($this->getInput('k')); - } - $html = $this->getSimpleHTMLDOM($link) or $this->returnServerError('Could not request LeBonCoin.'); + $category=$this->getInput('c'); + if (empty($category)){ + $category='annonces'; + } + + $html = $this->getSimpleHTMLDOM( + $this->uri.$category.'/offres/' . $this->getInput('r') . '/?' + .'f=a&th=1&' + .'q=' . urlencode($this->getInput('k')) + ) or $this->returnServerError('Could not request LeBonCoin.'); $list = $html->find('.tabsContent', 0); if($list === NULL) {