2018-04-14 18:19:35 +03:00
|
|
|
<?php
|
|
|
|
class PixivBridge extends BridgeAbstract {
|
|
|
|
|
2021-05-24 22:42:39 +03:00
|
|
|
const MAINTAINER = 'Yaman Qalieh';
|
2018-04-14 18:19:35 +03:00
|
|
|
const NAME = 'Pixiv Bridge';
|
|
|
|
const URI = 'https://www.pixiv.net/';
|
|
|
|
const DESCRIPTION = 'Returns the tag search from pixiv.net';
|
2021-05-24 22:42:39 +03:00
|
|
|
const CACHE_TIMEOUT = 21600; // 6h
|
2018-04-14 18:19:35 +03:00
|
|
|
|
|
|
|
|
|
|
|
const PARAMETERS = array( array(
|
2021-05-24 22:42:39 +03:00
|
|
|
'mode' => array(
|
|
|
|
'name' => 'Post Type',
|
|
|
|
'type' => 'list',
|
|
|
|
'values' => array('Illustration' => 'illustrations/',
|
|
|
|
'Manga' => 'manga/',
|
|
|
|
'Novel' => 'novels/')
|
|
|
|
),
|
2018-04-14 18:19:35 +03:00
|
|
|
'tag' => array(
|
2021-05-24 22:42:39 +03:00
|
|
|
'name' => 'Query to search',
|
|
|
|
'exampleValue' => '葬送のフリーレン',
|
2018-04-14 18:19:35 +03:00
|
|
|
'required' => true
|
|
|
|
),
|
2021-05-24 22:42:39 +03:00
|
|
|
'posts' => array(
|
|
|
|
'name' => 'Post Limit',
|
|
|
|
'type' => 'number',
|
|
|
|
'defaultValue' => '10'
|
|
|
|
),
|
|
|
|
'fullsize' => array(
|
|
|
|
'name' => 'Full-size Image',
|
|
|
|
'type' => 'checkbox'
|
|
|
|
)
|
2018-04-14 18:19:35 +03:00
|
|
|
));
|
|
|
|
|
2021-05-24 22:42:39 +03:00
|
|
|
const JSON_KEY_MAP = array(
|
|
|
|
'illustrations/' => 'illust',
|
|
|
|
'manga/' => 'manga',
|
|
|
|
'novels/' => 'novel'
|
|
|
|
);
|
|
|
|
const WORK_LINK_MAP = array(
|
|
|
|
'illustrations/' => 'artworks/',
|
|
|
|
'manga/' => 'artworks/',
|
|
|
|
'novels/' => 'novel/show.php?id='
|
|
|
|
);
|
|
|
|
|
|
|
|
public function collectData() {
|
|
|
|
$content = getContents($this->getSearchURI());
|
|
|
|
$content = json_decode($content, true);
|
|
|
|
|
|
|
|
$key = self::JSON_KEY_MAP[$this->getInput('mode')];
|
2018-04-14 18:19:35 +03:00
|
|
|
$count = 0;
|
2021-05-24 22:42:39 +03:00
|
|
|
foreach($content['body'][$key]['data'] as $result) {
|
2018-04-14 18:19:35 +03:00
|
|
|
$count++;
|
2021-05-24 22:42:39 +03:00
|
|
|
if ($count > $this->getInput('posts')) {
|
|
|
|
break;
|
|
|
|
}
|
2018-04-14 18:19:35 +03:00
|
|
|
|
|
|
|
$item = array();
|
2021-05-24 22:42:39 +03:00
|
|
|
$item['id'] = $result['id'];
|
|
|
|
$item['uri'] = static::URI . self::WORK_LINK_MAP[$this->getInput('mode')] . $result['id'];
|
|
|
|
$item['title'] = $result['title'];
|
2018-06-30 00:55:33 +03:00
|
|
|
$item['author'] = $result['userName'];
|
2021-05-24 22:42:39 +03:00
|
|
|
$item['timestamp'] = $result['updateDate'];
|
2018-06-30 00:55:33 +03:00
|
|
|
$item['content'] = "<img src='" . $this->cacheImage($result['url'], $item['id']) . "' />";
|
2021-05-24 22:42:39 +03:00
|
|
|
|
2018-04-14 18:19:35 +03:00
|
|
|
$this->items[] = $item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-24 22:42:39 +03:00
|
|
|
private function getSearchURI() {
|
|
|
|
$query = urlencode($this->getInput('tag'));
|
|
|
|
|
|
|
|
$uri = static::URI . 'ajax/search/' . $this->getInput('mode')
|
|
|
|
. $query . '?word=' . $query . '&order=date_d&mode=all&p=1';
|
|
|
|
|
|
|
|
return $uri;
|
|
|
|
}
|
|
|
|
|
2018-08-05 16:53:45 +03:00
|
|
|
private function cacheImage($url, $illustId) {
|
2021-05-24 22:42:39 +03:00
|
|
|
$illustId = preg_replace('/[^0-9]/', '', $illustId);
|
|
|
|
$thumbnailurl = $url;
|
2018-04-14 18:19:35 +03:00
|
|
|
|
2018-11-10 21:48:05 +03:00
|
|
|
$path = PATH_CACHE . 'pixiv_img/';
|
2018-04-14 18:19:35 +03:00
|
|
|
if(!is_dir($path))
|
|
|
|
mkdir($path, 0755, true);
|
|
|
|
|
2021-05-24 22:42:39 +03:00
|
|
|
$path .= $illustId;
|
|
|
|
if ($this->getInput('fullsize')) {
|
|
|
|
$path .= '_fullsize';
|
2018-04-14 18:19:35 +03:00
|
|
|
}
|
2021-05-24 22:42:39 +03:00
|
|
|
$path .= '.jpg';
|
2018-04-14 18:19:35 +03:00
|
|
|
|
2021-05-24 22:42:39 +03:00
|
|
|
if(!is_file($path)) {
|
|
|
|
|
|
|
|
// Get fullsize URL
|
|
|
|
if (!$this->getInput('mode') !== 'novels/' && $this->getInput('fullsize')) {
|
|
|
|
$ajax_uri = static::URI . 'ajax/illust/' . $illustId;
|
|
|
|
$imagejson = json_decode(getContents($ajax_uri), true);
|
|
|
|
$url = $imagejson['body']['urls']['original'];
|
|
|
|
}
|
|
|
|
|
|
|
|
$headers = array('Referer: ' . static::URI);
|
|
|
|
try {
|
|
|
|
$illust = getContents($url, $headers);
|
|
|
|
} catch (Exception $e) {
|
|
|
|
$illust = getContents($thumbnailurl, $headers); // Original thumbnail
|
|
|
|
}
|
|
|
|
file_put_contents($path, $illust);
|
|
|
|
}
|
2018-04-14 18:19:35 +03:00
|
|
|
|
2021-05-24 22:42:39 +03:00
|
|
|
return 'cache/pixiv_img/' . preg_replace('/.*\//', '', $path);
|
2018-04-14 18:19:35 +03:00
|
|
|
}
|
|
|
|
}
|