From 7c840093db03f0bec86fe08d82402b685827f3d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre=20Mazi=C3=A8re?= Date: Sun, 28 Aug 2016 20:36:00 +0200 Subject: [PATCH] [GiphyBridge] code simplification MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Pierre Mazière --- bridges/GiphyBridge.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/bridges/GiphyBridge.php b/bridges/GiphyBridge.php index 79665189..95beea58 100644 --- a/bridges/GiphyBridge.php +++ b/bridges/GiphyBridge.php @@ -9,7 +9,10 @@ class GiphyBridge extends BridgeAbstract{ public $description = "Bridge for giphy.com"; public $parameters = array( array( - 's'=>array('name'=>'search tag'), + 's'=>array( + 'name'=>'search tag', + 'required'=>true + ), 'n'=>array( 'name'=>'max number of returned items', 'type'=>'number' @@ -19,16 +22,12 @@ class GiphyBridge extends BridgeAbstract{ public function collectData(){ $html = ''; $base_url = 'http://giphy.com'; - if ($this->getInput('s')) { /* keyword search mode */ - $html = $this->getSimpleHTMLDOM($base_url.'/search/'.urlencode($this->getInput('s').'/')) or $this->returnServerError('No results for this query.'); - } - else { - $this->returnClientError('You must specify a search worf (?s=...).'); - } + $html = $this->getSimpleHTMLDOM($this->uri.'/search/'.urlencode($this->getInput('s').'/')) + or $this->returnServerError('No results for this query.'); $max = GIPHY_LIMIT; if ($this->getInput('n')) { - $max = (integer) $this->getInput('n'); + $max = $this->getInput('n'); } $limit = 0; @@ -38,7 +37,8 @@ class GiphyBridge extends BridgeAbstract{ $node = $entry->first_child(); $href = $node->getAttribute('href'); - $html2 = $this->getSimpleHTMLDOM($base_url . $href) or $this->returnServerError('No results for this query.'); + $html2 = $this->getSimpleHTMLDOM($this->uri . $href) + or $this->returnServerError('No results for this query.'); $figure = $html2->getElementByTagName('figure'); $img = $figure->firstChild(); $caption = $figure->lastChild();