[GiphyBridge] code simplification

Signed-off-by: Pierre Mazière <pierre.maziere@gmx.com>
This commit is contained in:
Pierre Mazière 2016-08-28 20:36:00 +02:00
parent dc358dea9b
commit 7c840093db

View file

@ -9,7 +9,10 @@ class GiphyBridge extends BridgeAbstract{
public $description = "Bridge for giphy.com"; public $description = "Bridge for giphy.com";
public $parameters = array( array( public $parameters = array( array(
's'=>array('name'=>'search tag'), 's'=>array(
'name'=>'search tag',
'required'=>true
),
'n'=>array( 'n'=>array(
'name'=>'max number of returned items', 'name'=>'max number of returned items',
'type'=>'number' 'type'=>'number'
@ -19,16 +22,12 @@ class GiphyBridge extends BridgeAbstract{
public function collectData(){ public function collectData(){
$html = ''; $html = '';
$base_url = 'http://giphy.com'; $base_url = 'http://giphy.com';
if ($this->getInput('s')) { /* keyword search mode */ $html = $this->getSimpleHTMLDOM($this->uri.'/search/'.urlencode($this->getInput('s').'/'))
$html = $this->getSimpleHTMLDOM($base_url.'/search/'.urlencode($this->getInput('s').'/')) or $this->returnServerError('No results for this query.'); or $this->returnServerError('No results for this query.');
}
else {
$this->returnClientError('You must specify a search worf (?s=...).');
}
$max = GIPHY_LIMIT; $max = GIPHY_LIMIT;
if ($this->getInput('n')) { if ($this->getInput('n')) {
$max = (integer) $this->getInput('n'); $max = $this->getInput('n');
} }
$limit = 0; $limit = 0;
@ -38,7 +37,8 @@ class GiphyBridge extends BridgeAbstract{
$node = $entry->first_child(); $node = $entry->first_child();
$href = $node->getAttribute('href'); $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'); $figure = $html2->getElementByTagName('figure');
$img = $figure->firstChild(); $img = $figure->firstChild();
$caption = $figure->lastChild(); $caption = $figure->lastChild();