forked from blallo/rss-bridge
[KonachanBridge] code simplification
Signed-off-by: Pierre Mazière <pierre.maziere@gmx.com>
This commit is contained in:
parent
df80500c51
commit
7c03437c57
1 changed files with 8 additions and 9 deletions
|
@ -9,20 +9,19 @@ class KonachanBridge extends BridgeAbstract{
|
||||||
public $parameters = array( array(
|
public $parameters = array( array(
|
||||||
'p'=>array(
|
'p'=>array(
|
||||||
'name'=>'page',
|
'name'=>'page',
|
||||||
|
'defaultValue'=>1,
|
||||||
'type'=>'number'
|
'type'=>'number'
|
||||||
),
|
),
|
||||||
't'=>array('name'=>'tags')
|
't'=>array('name'=>'tags')
|
||||||
));
|
));
|
||||||
|
|
||||||
public function collectData(){
|
public function collectData(){
|
||||||
$page = 1;$tags='';
|
$html = $this->getSimpleHTMLDOM(
|
||||||
if ($this->getInput('p')) {
|
$this->uri.'/post?'
|
||||||
$page = (int)preg_replace("/[^0-9]/",'', $this->getInput('p'));
|
.'&page='.$this->getInput('p')
|
||||||
}
|
.'&tags='.urlencode($this->getInput('t'))
|
||||||
if ($this->getInput('t')) {
|
) or $this->returnServerError('Could not request Konachan.');
|
||||||
$tags = urlencode($this->getInput('t'));
|
|
||||||
}
|
|
||||||
$html = $this->getSimpleHTMLDOM("http://konachan.com/post?page=$page&tags=$tags") or $this->returnServerError('Could not request Konachan.');
|
|
||||||
$input_json = explode('Post.register(', $html);
|
$input_json = explode('Post.register(', $html);
|
||||||
foreach($input_json as $element)
|
foreach($input_json as $element)
|
||||||
$data[] = preg_replace('/}\)(.*)/', '}', $element);
|
$data[] = preg_replace('/}\)(.*)/', '}', $element);
|
||||||
|
@ -31,7 +30,7 @@ class KonachanBridge extends BridgeAbstract{
|
||||||
foreach($data as $datai) {
|
foreach($data as $datai) {
|
||||||
$json = json_decode($datai, TRUE);
|
$json = json_decode($datai, TRUE);
|
||||||
$item = array();
|
$item = array();
|
||||||
$item['uri'] = 'http://konachan.com/post/show/'.$json['id'];
|
$item['uri'] = $this->uri.'/post/show/'.$json['id'];
|
||||||
$item['postid'] = $json['id'];
|
$item['postid'] = $json['id'];
|
||||||
$item['timestamp'] = $json['created_at'];
|
$item['timestamp'] = $json['created_at'];
|
||||||
$item['imageUri'] = $json['file_url'];
|
$item['imageUri'] = $json['file_url'];
|
||||||
|
|
Loading…
Reference in a new issue