2014-05-26 02:30:46 +04:00
|
|
|
<?php
|
|
|
|
|
2022-03-29 23:42:09 +03:00
|
|
|
class GelbooruBridge extends BridgeAbstract
|
2022-07-01 16:10:30 +03:00
|
|
|
{
|
2017-02-11 18:16:56 +03:00
|
|
|
const MAINTAINER = 'mitsukarenai';
|
|
|
|
const NAME = 'Gelbooru';
|
2022-03-29 23:42:09 +03:00
|
|
|
const URI = 'https://gelbooru.com/';
|
2017-02-11 18:16:56 +03:00
|
|
|
const DESCRIPTION = 'Returns images from given page';
|
2015-11-05 18:50:18 +03:00
|
|
|
|
2022-03-29 23:42:09 +03:00
|
|
|
const PARAMETERS = [
|
|
|
|
'global' => [
|
|
|
|
'p' => [
|
|
|
|
'name' => 'page',
|
|
|
|
'defaultValue' => 0,
|
|
|
|
'type' => 'number'
|
|
|
|
],
|
|
|
|
't' => [
|
|
|
|
'name' => 'tags',
|
2022-04-12 17:52:34 +03:00
|
|
|
'exampleValue' => 'solo',
|
2022-03-29 23:42:09 +03:00
|
|
|
'title' => 'Tags to search for'
|
|
|
|
],
|
|
|
|
'l' => [
|
|
|
|
'name' => 'limit',
|
|
|
|
'exampleValue' => 100,
|
|
|
|
'title' => 'How many posts to retrieve (hard limit of 1000)'
|
2022-07-01 16:10:30 +03:00
|
|
|
]
|
2022-03-29 23:42:09 +03:00
|
|
|
],
|
|
|
|
0 => []
|
|
|
|
];
|
2014-05-26 02:30:46 +04:00
|
|
|
|
2017-02-11 18:16:56 +03:00
|
|
|
protected function getFullURI()
|
|
|
|
{
|
|
|
|
return $this->getURI()
|
2022-03-29 23:42:09 +03:00
|
|
|
. 'index.php?&page=dapi&s=post&q=index&json=1&pid=' . $this->getInput('p')
|
|
|
|
. '&limit=' . $this->getInput('l')
|
2017-02-11 18:16:56 +03:00
|
|
|
. '&tags=' . urlencode($this->getInput('t'));
|
|
|
|
}
|
2017-08-05 23:38:22 +03:00
|
|
|
|
2022-03-29 23:42:09 +03:00
|
|
|
/*
|
|
|
|
This function is superfluous for GelbooruBridge, but useful
|
|
|
|
for Bridges that inherit from it
|
|
|
|
*/
|
|
|
|
protected function buildThumbnailURI($element)
|
|
|
|
{
|
|
|
|
return $this->getURI() . 'thumbnails/' . $element->directory
|
|
|
|
. '/thumbnail_' . $element->md5 . '.jpg';
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getItemFromElement($element)
|
|
|
|
{
|
|
|
|
$item = [];
|
|
|
|
$item['uri'] = $this->getURI() . 'index.php?page=post&s=view&id='
|
|
|
|
. $element->id;
|
|
|
|
$item['postid'] = $element->id;
|
|
|
|
$item['author'] = $element->owner;
|
|
|
|
$item['timestamp'] = date('d F Y H:i:s', $element->change);
|
|
|
|
$item['tags'] = $element->tags;
|
|
|
|
$item['title'] = $this->getName() . ' | ' . $item['postid'];
|
2017-08-05 23:38:22 +03:00
|
|
|
|
2022-03-29 23:42:09 +03:00
|
|
|
if (isset($element->preview_url)) {
|
|
|
|
$thumbnailUri = $element->preview_url;
|
|
|
|
} else {
|
|
|
|
$thumbnailUri = $this->buildThumbnailURI($element);
|
2017-08-05 23:38:22 +03:00
|
|
|
}
|
|
|
|
|
2022-03-29 23:42:09 +03:00
|
|
|
$item['content'] = '<a href="' . $item['uri'] . '"><img src="'
|
2022-11-08 20:43:51 +03:00
|
|
|
. $thumbnailUri . '" /></a><br><br><b>Dimensions:</b> '
|
|
|
|
. strval($element->width) . ' x ' . strval($element->height) . '<br><br><b>Tags:</b> '
|
|
|
|
. $item['tags'];
|
2022-11-15 02:30:51 +03:00
|
|
|
if (isset($element->source)) {
|
2022-11-08 20:43:51 +03:00
|
|
|
$item['content'] .= '<br><br><b>Source: </b><a href="' . $element->source . '">' . $element->source . '</a>';
|
|
|
|
}
|
2022-03-29 23:42:09 +03:00
|
|
|
|
|
|
|
return $item;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function collectData()
|
|
|
|
{
|
|
|
|
$content = getContents($this->getFullURI());
|
2022-04-13 00:37:30 +03:00
|
|
|
// $content is empty string
|
2022-03-29 23:42:09 +03:00
|
|
|
|
|
|
|
// Most other Gelbooru-based boorus put their content in the root of
|
|
|
|
// the JSON. This check is here for Bridges that inherit from this one
|
|
|
|
$posts = json_decode($content);
|
|
|
|
if (isset($posts->post)) {
|
|
|
|
$posts = $posts->post;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_null($posts)) {
|
|
|
|
returnServerError('No posts found.');
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($posts as $post) {
|
|
|
|
$this->items[] = $this->getItemFromElement($post);
|
|
|
|
}
|
2017-08-05 23:38:22 +03:00
|
|
|
}
|
2014-05-26 02:30:46 +04:00
|
|
|
}
|