From 92e0bec9256ed9f42aee3882c313ea58349eb382 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre=20Mazi=C3=A8re?= Date: Mon, 29 Aug 2016 22:33:24 +0200 Subject: [PATCH] [SakugabooruBridge] code simplification MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Pierre Mazière --- bridges/SakugabooruBridge.php | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/bridges/SakugabooruBridge.php b/bridges/SakugabooruBridge.php index ab74d6d..c83eee5 100644 --- a/bridges/SakugabooruBridge.php +++ b/bridges/SakugabooruBridge.php @@ -9,20 +9,19 @@ class SakugabooruBridge extends BridgeAbstract{ public $parameters = array( array( 'p'=>array( 'name'=>'page', + 'defaultValue'=>1, 'type'=>'number' ), 't'=>array('name'=>'tags') )); public function collectData(){ - $page = 1;$tags=''; - if ($this->getInput('p')) { - $page = (int)preg_replace("/[^0-9]/",'', $this->getInput('p')); - } - if ($this->getInput('t')) { - $tags = urlencode($this->getInput('t')); - } - $html = $this->getSimpleHTMLDOM("http://sakuga.yshi.org/post?page=$page&tags=$tags") or $this->returnServerError('Could not request Sakugabooru.'); + $html = $this->getSimpleHTMLDOM( + $this->uri.'post?' + .'&page='.$this->getInput('p') + .'&tags='.urlencode($this->getInput('t')) + ) or $this->returnServerError('Could not request Sakugabooru.'); + $input_json = explode('Post.register(', $html); foreach($input_json as $element) $data[] = preg_replace('/}\)(.*)/', '}', $element); @@ -31,7 +30,7 @@ class SakugabooruBridge extends BridgeAbstract{ foreach($data as $datai) { $json = json_decode($datai, TRUE); $item = array(); - $item['uri'] = 'http://sakuga.yshi.org/post/show/'.$json['id']; + $item['uri'] = $this->uri.'/post/show/'.$json['id']; $item['postid'] = $json['id']; $item['timestamp'] = $json['created_at']; $item['imageUri'] = $json['file_url'];