2014-05-26 02:30:46 +04:00
|
|
|
<?php
|
|
|
|
class DanbooruBridge extends BridgeAbstract{
|
|
|
|
|
2016-09-04 02:18:06 +03:00
|
|
|
const MAINTAINER = "mitsukarenai";
|
|
|
|
const NAME = "Danbooru";
|
|
|
|
const URI = "http://donmai.us/";
|
2016-09-25 18:04:28 +03:00
|
|
|
const CACHE_TIMEOUT = 1800; // 30min
|
2016-09-04 02:18:06 +03:00
|
|
|
const DESCRIPTION = "Returns images from given page";
|
|
|
|
|
|
|
|
const PARAMETERS = array(
|
|
|
|
'global'=>array(
|
|
|
|
'p'=>array(
|
|
|
|
'name'=>'page',
|
|
|
|
'defaultValue'=>1,
|
|
|
|
'type'=>'number'
|
|
|
|
),
|
|
|
|
't'=>array('name'=>'tags')
|
|
|
|
),
|
|
|
|
0=>array()
|
|
|
|
);
|
|
|
|
|
|
|
|
const PATHTODATA='article';
|
|
|
|
const IDATTRIBUTE='data-id';
|
|
|
|
|
|
|
|
protected function getFullURI(){
|
|
|
|
return $this->getURI().'posts?'
|
|
|
|
.'&page='.$this->getInput('p')
|
|
|
|
.'&tags='.urlencode($this->getInput('t'));
|
|
|
|
}
|
2014-05-26 02:30:46 +04:00
|
|
|
|
2016-09-04 02:18:06 +03:00
|
|
|
protected function getItemFromElement($element){
|
|
|
|
$item = array();
|
|
|
|
$item['uri'] = $this->getURI().$element->find('a', 0)->href;
|
|
|
|
$item['postid'] = (int)preg_replace("/[^0-9]/",'', $element->getAttribute(static::IDATTRIBUTE));
|
|
|
|
$item['timestamp'] = time();
|
|
|
|
$thumbnailUri = $this->getURI().$element->find('img', 0)->src;
|
|
|
|
$item['tags'] = $element->find('img', 0)->getAttribute('alt');
|
|
|
|
$item['title'] = $this->getName().' | '.$item['postid'];
|
|
|
|
$item['content'] = '<a href="' . $item['uri'] . '"><img src="' . $thumbnailUri . '" /></a><br>Tags: '.$item['tags'];
|
|
|
|
return $item;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function collectData(){
|
2016-09-26 00:22:33 +03:00
|
|
|
$html = getSimpleHTMLDOM($this->getFullURI())
|
|
|
|
or returnServerError('Could not request '.$this->getName());
|
2016-09-04 02:18:06 +03:00
|
|
|
|
|
|
|
foreach($html->find(static::PATHTODATA) as $element) {
|
|
|
|
$this->items[] = $this->getItemFromElement($element);
|
2014-05-26 02:30:46 +04:00
|
|
|
}
|
2016-09-04 02:18:06 +03:00
|
|
|
}
|
2014-05-26 02:30:46 +04:00
|
|
|
}
|