From 82b150baa8c9a2d1211e336404295f594197e96c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre=20Mazi=C3=A8re?= Date: Mon, 29 Aug 2016 22:53:38 +0200 Subject: [PATCH] [SensCritiqueBridge] code simplification MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Pierre Mazière --- bridges/SensCritiqueBridge.php | 84 ++++++++-------------------------- 1 file changed, 20 insertions(+), 64 deletions(-) diff --git a/bridges/SensCritiqueBridge.php b/bridges/SensCritiqueBridge.php index f3d1a2d..a202e0c 100644 --- a/bridges/SensCritiqueBridge.php +++ b/bridges/SensCritiqueBridge.php @@ -3,7 +3,7 @@ class SensCritiqueBridge extends BridgeAbstract { public $maintainer = "kranack"; public $name = "Sens Critique"; - public $uri = "http://www.senscritique.com"; + public $uri = "http://www.senscritique.com/"; public $description = "Sens Critique news"; public $parameters = array( array( @@ -34,71 +34,27 @@ class SensCritiqueBridge extends BridgeAbstract { )); public function collectData(){ - if (($this->getInput('m') && $this->getInput('m'))) { - $this->collectMoviesData(); - } else if (($this->getInput('s') && $this->getInput('s'))) { - $this->collectSeriesData(); - } else if (($this->getInput('g') && $this->getInput('g'))) { - $this->collectGamesData(); - } else if (($this->getInput('b') && $this->getInput('b'))) { - $this->collectBooksData(); - } else if (($this->getInput('bd') && $this->getInput('bd'))) { - $this->collectBDsData(); - } else if (($this->getInput('mu') && $this->getInput('mu'))) { - $this->collectMusicsData(); - } else { - $this->returnClientError('You must choose a category'); - } + $categories=array(); + foreach($this->parameters[$this->queriedContext] as $category=>$properties){ + if($this->getInput($category)){ + $uri=$this->uri; + switch($category){ + case 'm': $uri.='films/cette-semaine'; break; + case 's': $uri.='series/actualite'; break; + case 'g': $uri.='jeuxvideo/actualite'; break; + case 'b': $uri.='livres/actualite'; break; + case 'bd': $uri.='bd/actualite'; break; + case 'mu': $uri.='musique/actualite'; break; + } + $html = $this->getSimpleHTMLDOM($uri) + or $this->returnServerError('No results for this query.'); + $list = $html->find('ul.elpr-list', 0); + + $this->extractDataFromList($list); + } + } } - private function collectMoviesData() { - $html = ''; - $html = $this->getSimpleHTMLDOM('http://www.senscritique.com/films/cette-semaine') or $this->returnServerError('No results for this query.'); - $list = $html->find('ul.elpr-list', 0); - - $this->extractDataFromList($list); - } - - private function collectSeriesData() { - $html = ''; - $html = $this->getSimpleHTMLDOM('http://www.senscritique.com/series/actualite') or $this->returnServerError('No results for this query.'); - $list = $html->find('ul.elpr-list', 0); - - $this->extractDataFromList($list); - } - - private function collectGamesData() { - $html = ''; - $html = $this->getSimpleHTMLDOM('http://www.senscritique.com/jeuxvideo/actualite') or $this->returnServerError('No results for this query.'); - $list = $html->find('ul.elpr-list', 0); - - $this->extractDataFromList($list); - } - - private function collectBooksData() { - $html = ''; - $html = $this->getSimpleHTMLDOM('http://www.senscritique.com/livres/actualite') or $this->returnServerError('No results for this query.'); - $list = $html->find('ul.elpr-list', 0); - - $this->extractDataFromList($list); - } - - private function collectBDsData() { - $html = ''; - $html = $this->getSimpleHTMLDOM('http://www.senscritique.com/bd/actualite') or $this->returnServerError('No results for this query.'); - $list = $html->find('ul.elpr-list', 0); - - $this->extractDataFromList($list); - } - - private function collectMusicsData() { - $html = ''; - $html = $this->getSimpleHTMLDOM('http://www.senscritique.com/musique/actualite') or $this->returnServerError('No results for this query.'); - $list = $html->find('ul.elpr-list', 0); - - $this->extractDataFromList($list); - } - private function extractDataFromList($list) { if ($list === null) { $this->returnClientError('Cannot extract data from list');