[FourChanBridge] fix + add pattern

the current url parameter must be modified to be validated
more easily

Signed-off-by: Pierre Mazière <pierre.maziere@gmx.com>
This commit is contained in:
Pierre Mazière 2016-08-28 20:06:10 +02:00
parent 0d9be1f510
commit 6ea946359c

View file

@ -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();