2014-05-26 02:30:46 +04:00
|
|
|
<?php
|
2017-02-11 18:16:56 +03:00
|
|
|
|
2022-07-01 16:10:30 +03:00
|
|
|
class DanbooruBridge extends BridgeAbstract
|
|
|
|
{
|
|
|
|
const MAINTAINER = 'mitsukarenai, logmanoriginal';
|
|
|
|
const NAME = 'Danbooru';
|
|
|
|
const URI = 'http://donmai.us/';
|
|
|
|
const CACHE_TIMEOUT = 1800; // 30min
|
|
|
|
const DESCRIPTION = 'Returns images from given page';
|
2017-02-11 18:16:56 +03:00
|
|
|
|
2022-07-01 16:10:30 +03:00
|
|
|
const PARAMETERS = [
|
|
|
|
'global' => [
|
|
|
|
'p' => [
|
|
|
|
'name' => 'page',
|
|
|
|
'defaultValue' => 1,
|
|
|
|
'type' => 'number'
|
|
|
|
],
|
|
|
|
't' => [
|
|
|
|
'type' => 'text',
|
|
|
|
'name' => 'tags',
|
|
|
|
'exampleValue' => 'cosplay',
|
|
|
|
]
|
|
|
|
],
|
|
|
|
0 => []
|
|
|
|
];
|
2017-02-11 18:16:56 +03:00
|
|
|
|
2022-07-01 16:10:30 +03:00
|
|
|
const PATHTODATA = 'article';
|
|
|
|
const IDATTRIBUTE = 'data-id';
|
|
|
|
const TAGATTRIBUTE = 'alt';
|
2017-02-11 18:16:56 +03:00
|
|
|
|
2022-07-01 16:10:30 +03:00
|
|
|
protected function getFullURI()
|
|
|
|
{
|
|
|
|
return $this->getURI()
|
|
|
|
. 'posts?&page=' . $this->getInput('p')
|
|
|
|
. '&tags=' . urlencode($this->getInput('t'));
|
|
|
|
}
|
2017-02-11 18:16:56 +03:00
|
|
|
|
2022-07-01 16:10:30 +03:00
|
|
|
protected function getTags($element)
|
|
|
|
{
|
|
|
|
return $element->find('img', 0)->getAttribute(static::TAGATTRIBUTE);
|
|
|
|
}
|
2017-08-05 23:24:48 +03:00
|
|
|
|
2022-07-01 16:10:30 +03:00
|
|
|
protected function getItemFromElement($element)
|
|
|
|
{
|
|
|
|
// Fix links
|
|
|
|
defaultLinkTo($element, $this->getURI());
|
2017-07-25 15:40:34 +03:00
|
|
|
|
2022-07-01 16:10:30 +03:00
|
|
|
$item = [];
|
|
|
|
$item['uri'] = html_entity_decode($element->find('a', 0)->href);
|
|
|
|
$item['postid'] = (int)preg_replace('/[^0-9]/', '', $element->getAttribute(static::IDATTRIBUTE));
|
|
|
|
$item['timestamp'] = time();
|
|
|
|
$thumbnailUri = $element->find('img', 0)->src;
|
|
|
|
$item['categories'] = array_filter(explode(' ', $this->getTags($element)));
|
|
|
|
$item['title'] = $this->getName() . ' | ' . $item['postid'];
|
|
|
|
$item['content'] = '<a href="'
|
|
|
|
. $item['uri']
|
|
|
|
. '"><img src="'
|
|
|
|
. $thumbnailUri
|
|
|
|
. '" /></a><br>Tags: '
|
|
|
|
. $this->getTags($element);
|
2017-02-11 18:16:56 +03:00
|
|
|
|
2022-07-01 16:10:30 +03:00
|
|
|
return $item;
|
|
|
|
}
|
2017-02-11 18:16:56 +03:00
|
|
|
|
2022-07-01 16:10:30 +03:00
|
|
|
public function collectData()
|
|
|
|
{
|
|
|
|
$html = getSimpleHTMLDOMCached($this->getFullURI());
|
2018-08-09 22:55:43 +03:00
|
|
|
|
2022-07-01 16:10:30 +03:00
|
|
|
foreach ($html->find(static::PATHTODATA) as $element) {
|
|
|
|
$this->items[] = $this->getItemFromElement($element);
|
|
|
|
}
|
|
|
|
}
|
2014-05-26 02:30:46 +04:00
|
|
|
}
|