From 6ea946359cd83b4bb5d618e4b854c59333d4848b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre=20Mazi=C3=A8re?= Date: Sun, 28 Aug 2016 20:06:10 +0200 Subject: [PATCH] [FourChanBridge] fix + add pattern MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit the current url parameter must be modified to be validated more easily Signed-off-by: Pierre Mazière --- bridges/FourchanBridge.php | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/bridges/FourchanBridge.php b/bridges/FourchanBridge.php index f1954d7..eddfdde 100644 --- a/bridges/FourchanBridge.php +++ b/bridges/FourchanBridge.php @@ -7,23 +7,26 @@ class FourchanBridge extends BridgeAbstract{ public $description = "Returns posts from the specified thread"; public $parameters = array( array( - 't'=>array('name'=>'Thread URL') + 't'=>array( + 'name'=>'Thread URL', + 'pattern'=>'(https:\/\/)?boards\.4chan\.org\/.*thread\/.*', + 'required'=>true + ) )); public function collectData(){ - if (!$this->getInput('t')) - $this->returnClientError('You must specify the thread URL (?t=...)'); - - $thread = parse_url($this->getInput('t')) or $this->returnClientError('This URL seems malformed, please check it.'); + $thread = parse_url($this->getInput('t')) + or $this->returnClientError('This URL seems malformed, please check it.'); if($thread['host'] !== 'boards.4chan.org') $this->returnClientError('4chan thread URL only.'); if(strpos($thread['path'], 'thread/') === FALSE) $this->returnClientError('You must specify the thread URL.'); - $url = 'https://boards.4chan.org'.$thread['path'].''; - $html = $this->getSimpleHTMLDOM($url) or $this->returnServerError("Could not request 4chan, thread not found"); + $url = 'https://boards.4chan.org'.$thread['path']; + $html = $this->getSimpleHTMLDOM($url) + or $this->returnServerError("Could not request 4chan, thread not found"); foreach($html->find('div.postContainer') as $element) { $item = array();