1
0
Fork 0
forked from blallo/rss-bridge

[NovelUpdatesBridge] use 'name' parameter instead of full URI

This breaks compatibility with previous versions of NoveUpdatesBridge.
Bridges should never use full URIs as inputs since 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 <pierre.maziere@gmx.com>
This commit is contained in:
Pierre Mazière 2016-09-04 14:26:11 +02:00
parent d60220769e
commit 0c139941d9

View file

@ -7,23 +7,22 @@ class NovelUpdatesBridge extends BridgeAbstract{
const DESCRIPTION = "Returns releases from Novel Updates"; const DESCRIPTION = "Returns releases from Novel Updates";
const PARAMETERS = array( array( const PARAMETERS = array( array(
'n'=>array( 'n'=>array(
'name'=>'Novel URL', 'name'=>'Novel name as found in the url',
'patterns'=>'http:\/\/www.novelupdates.com\/.*', 'exampleValue'=>'spirit-realm',
'required'=>true 'required'=>true
) )
)); ));
private $seriesTitle=''; private $seriesTitle='';
public function getURI(){
return static::URI.'/series/'.$this->getInput('n').'/';
}
public function collectData(){ public function collectData(){
$thread = parse_url($this->getInput('n')) $fullhtml = $this->getSimpleHTMLDOM($this->getURI())
or $this->returnClientError('This URL seems malformed, please check it.'); or $this->returnServerError('Could not request NovelUpdates, novel "'.$this->getInput('n').'" not found');
if($thread['host'] !== 'www.novelupdates.com')
$this->returnClientError('NovelUpdates URL only.');
if(strpos($thread['path'], 'series/') === FALSE)
$this->returnClientError('You must specify the novel URL.');
$url = self::URI.$thread['path'].'';
$fullhtml = $this->getSimpleHTMLDOM($url) or $this->returnServerError("Could not request NovelUpdates, novel not found");
$this->seriesTitle = $fullhtml->find('h4.seriestitle', 0)->plaintext; $this->seriesTitle = $fullhtml->find('h4.seriestitle', 0)->plaintext;
// dirty fix for nasty simpledom bug: https://github.com/sebsauvage/rss-bridge/issues/259 // dirty fix for nasty simpledom bug: https://github.com/sebsauvage/rss-bridge/issues/259
// forcefully removes tbody // forcefully removes tbody
@ -37,13 +36,17 @@ class NovelUpdatesBridge extends BridgeAbstract{
$item['title'] = $element->find('td', 2)->find('a', 0)->plaintext; $item['title'] = $element->find('td', 2)->find('a', 0)->plaintext;
$item['team'] = $element->find('td', 1)->innertext; $item['team'] = $element->find('td', 1)->innertext;
$item['timestamp'] = strtotime($element->find('td', 0)->plaintext); $item['timestamp'] = strtotime($element->find('td', 0)->plaintext);
$item['content'] = '<a href="'.$item['uri'].'">'.$this->seriesTitle.' - '.$item['title'].'</a> by '.$item['team'].'<br><a href="'.$item['uri'].'">'.$fullhtml->find('div.seriesimg', 0)->innertext.'</a>'; $item['content'] =
'<a href="'.$item['uri'].'">'
.$this->seriesTitle.' - '.$item['title']
.'</a> by '.$item['team'].'<br>'
.'<a href="'.$item['uri'].'">'.$fullhtml->find('div.seriesimg', 0)->innertext.'</a>';
$this->items[] = $item; $this->items[] = $item;
} }
} }
public function getName(){ public function getName(){
return (!empty($this->seriesTitle) ? $this->seriesTitle.' - ' : '') .'Novel Updates'; return $this->seriesTitle. ' - ' . static::NAME;
} }
public function getCacheDuration(){ public function getCacheDuration(){