From fa7cd4a7393c3fcde2f0138e24c031c2d34e8c31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre=20Mazi=C3=A8re?= Date: Sun, 28 Aug 2016 01:38:43 +0200 Subject: [PATCH] [AllocineFRBridge] fix and simplify code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Pierre Mazière --- bridges/AllocineFRBridge.php | 51 ++++++++++++++++++++++-------------- 1 file changed, 31 insertions(+), 20 deletions(-) diff --git a/bridges/AllocineFRBridge.php b/bridges/AllocineFRBridge.php index 3911955..f180f5d 100644 --- a/bridges/AllocineFRBridge.php +++ b/bridges/AllocineFRBridge.php @@ -16,34 +16,45 @@ class AllocineFRBridge extends BridgeAbstract{ 'values'=>array( 'Faux Raccord'=>'faux-raccord', 'Top 5'=>'top-5', - 'Tueurs En Serie'=>'tuers-en-serie' + 'Tueurs en Séries'=>'tueurs-en-serie' ) ) )); - public function collectData(){ - $category = ''; + public function getURI(){ switch($this->getInput('category')){ - case 'faux-raccord': - $this->uri = 'http://www.allocine.fr/video/programme-12284/saison-24580/'; - $category = 'Faux Raccord'; - break; - case 'top-5': - $this->uri = 'http://www.allocine.fr/video/programme-12299/saison-22542/'; - $category = 'Top 5'; - break; - case 'tuers-en-serie': - $this->uri = 'http://www.allocine.fr/video/programme-12286/saison-22938/'; - $category = 'Tueurs en Séries'; - break; - default: - $this->returnClientError('You must select a valid category!'); + case 'faux-raccord': + $uri = 'http://www.allocine.fr/video/programme-12284/saison-24580/'; + break; + case 'top-5': + $uri = 'http://www.allocine.fr/video/programme-12299/saison-22542/'; + break; + case 'tueurs-en-serie': + $uri = 'http://www.allocine.fr/video/programme-12286/saison-22938/'; + break; } - // Update bridge name to match selection - $this->name .= ' : ' . $category; + return $uri; + } + + public function getName(){ + return $this->name.' : ' + .array_search( + $this->getInput('category'), + $this->parameters[$this->queriedContext]['category']['values'] + ); + } + + public function collectData(){ + + $html = $this->getSimpleHTMLDOM($this->getURI()) + or $this->returnServerError("Could not request ".$this->getURI()." !"); + + $category=array_search( + $this->getInput('category'), + $this->parameters[$this->queriedContext]['category']['values'] + ); - $html = $this->getSimpleHTMLDOM($this->uri) or $this->returnServerError("Could not request {$this->uri}!"); foreach($html->find('figure.media-meta-fig') as $element) {