From fec864e0104ffef9f0cd95a1bc2963c92a5776b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre=20Mazi=C3=A8re?= Date: Sun, 4 Sep 2016 14:07:58 +0200 Subject: [PATCH] [FourchanBridge] use 'category' and 'thread' parameters instead of full URI MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This breaks compatibility with previous versions of FourChanBridge. Bridges should never use full URIs as inputs as their validation will always be more complicated, hence prone to security issues, than rebuilding a clean URI from simple validated inputs. Signed-off-by: Pierre Mazière --- bridges/FourchanBridge.php | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/bridges/FourchanBridge.php b/bridges/FourchanBridge.php index f17f38a2..90a746b4 100644 --- a/bridges/FourchanBridge.php +++ b/bridges/FourchanBridge.php @@ -3,35 +3,35 @@ class FourchanBridge extends BridgeAbstract{ const MAINTAINER = "mitsukarenai"; const NAME = "4chan"; - const URI = "https://www.4chan.org/"; + const URI = "https://boards.4chan.org/"; const DESCRIPTION = "Returns posts from the specified thread"; const PARAMETERS = array( array( - 't'=>array( - 'name'=>'Thread URL', - 'pattern'=>'(https:\/\/)?boards\.4chan\.org\/.*thread\/.*', + 'c'=>array( + 'name'=>'Thread category', 'required'=>true - ) + ), + 't'=>array( + 'name'=>'Thread number', + 'type'=>'number', + 'required'=>true + ) )); + public function getURI(){ + return static::URI.$this->getInput('c').'/thread/'.$this->getInput('t'); + + } + public function collectData(){ - $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"); + $html = $this->getSimpleHTMLDOM($this->getURI()) + or $this->returnServerError("Could not request 4chan, thread not found"); foreach($html->find('div.postContainer') as $element) { $item = array(); $item['id'] = $element->find('.post', 0)->getAttribute('id'); - $item['uri'] = $url.'#'.$item['id']; + $item['uri'] = $this->getURI().'#'.$item['id']; $item['timestamp'] = $element->find('span.dateTime', 0)->getAttribute('data-utc'); $item['author'] = $element->find('span.name', 0)->plaintext;