2020-09-09 15:11:19 +03:00
|
|
|
<?php
|
|
|
|
|
2022-07-01 16:10:30 +03:00
|
|
|
class WorldCosplayBridge extends BridgeAbstract
|
|
|
|
{
|
|
|
|
const NAME = 'WorldCosplay Bridge';
|
|
|
|
const URI = 'https://worldcosplay.net/';
|
|
|
|
const DESCRIPTION = 'Returns WorldCosplay photos';
|
|
|
|
const MAINTAINER = 'AxorPL';
|
2020-09-09 15:11:19 +03:00
|
|
|
|
2022-07-01 16:10:30 +03:00
|
|
|
const API_CHARACTER = 'api/photo/list.json?character_id=%u&limit=%u';
|
|
|
|
const API_COSPLAYER = 'api/member/photos.json?member_id=%u&limit=%u';
|
|
|
|
const API_SERIES = 'api/photo/list.json?title_id=%u&limit=%u';
|
|
|
|
const API_TAG = 'api/tag/photo_list.json?id=%u&limit=%u';
|
2020-09-09 15:11:19 +03:00
|
|
|
|
2022-07-01 16:10:30 +03:00
|
|
|
const CONTENT_HTML
|
|
|
|
= '<a href="%s" target="_blank"><img src="%s" alt="%s" title="%s"></a>';
|
2020-09-09 15:11:19 +03:00
|
|
|
|
2022-07-01 16:10:30 +03:00
|
|
|
const ERR_CONTEXT = 'No context provided';
|
|
|
|
const ERR_QUERY = 'Unable to query: %s';
|
2020-09-09 15:11:19 +03:00
|
|
|
|
2022-07-01 16:10:30 +03:00
|
|
|
const LIMIT_MIN = 1;
|
|
|
|
const LIMIT_MAX = 24;
|
2020-09-09 15:11:19 +03:00
|
|
|
|
2022-07-01 16:10:30 +03:00
|
|
|
const PARAMETERS = [
|
|
|
|
'Character' => [
|
|
|
|
'cid' => [
|
|
|
|
'name' => 'Character ID',
|
|
|
|
'type' => 'number',
|
|
|
|
'required' => true,
|
|
|
|
'title' => 'WorldCosplay character ID',
|
|
|
|
'exampleValue' => 18204
|
|
|
|
]
|
|
|
|
],
|
|
|
|
'Cosplayer' => [
|
|
|
|
'uid' => [
|
|
|
|
'name' => 'Cosplayer ID',
|
|
|
|
'type' => 'number',
|
|
|
|
'required' => true,
|
|
|
|
'title' => 'Cosplayer\'s WorldCosplay profile ID',
|
|
|
|
'exampleValue' => 406782
|
|
|
|
]
|
|
|
|
],
|
|
|
|
'Series' => [
|
|
|
|
'sid' => [
|
|
|
|
'name' => 'Series ID',
|
|
|
|
'type' => 'number',
|
|
|
|
'required' => true,
|
|
|
|
'title' => 'WorldCosplay series ID',
|
|
|
|
'exampleValue' => 3139
|
|
|
|
]
|
|
|
|
],
|
|
|
|
'Tag' => [
|
|
|
|
'tid' => [
|
|
|
|
'name' => 'Tag ID',
|
|
|
|
'type' => 'number',
|
|
|
|
'required' => true,
|
|
|
|
'title' => 'WorldCosplay tag ID',
|
|
|
|
'exampleValue' => 33643
|
|
|
|
]
|
|
|
|
],
|
|
|
|
'global' => [
|
|
|
|
'limit' => [
|
|
|
|
'name' => 'Limit',
|
|
|
|
'type' => 'number',
|
|
|
|
'required' => false,
|
|
|
|
'title' => 'Maximum number of photos to return',
|
|
|
|
'exampleValue' => 5,
|
|
|
|
'defaultValue' => 5
|
|
|
|
]
|
|
|
|
]
|
|
|
|
];
|
2020-09-09 15:11:19 +03:00
|
|
|
|
2022-07-01 16:10:30 +03:00
|
|
|
public function collectData()
|
|
|
|
{
|
|
|
|
$limit = $this->getInput('limit');
|
|
|
|
$limit = min(self::LIMIT_MAX, max(self::LIMIT_MIN, $limit));
|
|
|
|
switch ($this->queriedContext) {
|
|
|
|
case 'Character':
|
|
|
|
$id = $this->getInput('cid');
|
|
|
|
$url = self::API_CHARACTER;
|
|
|
|
break;
|
|
|
|
case 'Cosplayer':
|
|
|
|
$id = $this->getInput('uid');
|
|
|
|
$url = self::API_COSPLAYER;
|
|
|
|
break;
|
|
|
|
case 'Series':
|
|
|
|
$id = $this->getInput('sid');
|
|
|
|
$url = self::API_SERIES;
|
|
|
|
break;
|
|
|
|
case 'Tag':
|
|
|
|
$id = $this->getInput('tid');
|
|
|
|
$url = self::API_TAG;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
returnClientError(self::ERR_CONTEXT);
|
|
|
|
}
|
|
|
|
$url = self::URI . sprintf($url, $id, $limit);
|
2020-09-09 15:11:19 +03:00
|
|
|
|
2022-07-01 16:10:30 +03:00
|
|
|
$json = json_decode(getContents($url));
|
|
|
|
if ($json->has_error) {
|
|
|
|
returnServerError($json->message);
|
|
|
|
}
|
|
|
|
$list = $json->list;
|
2020-09-09 15:11:19 +03:00
|
|
|
|
2022-07-01 16:10:30 +03:00
|
|
|
foreach ($list as $img) {
|
Fix coding style missed by phpbcf (#2901)
$ composer require --dev friendsofphp/php-cs-fixer
$ echo >.php-cs-fixer.dist.php "<?php
$finder = PhpCsFixer\Finder::create()
->in(__DIR__);
$rules = [
'@PSR12' => true,
// '@PSR12:risky' => true,
'@PHP74Migration' => true,
// '@PHP74Migration:risky' => true,
// buggy, duplicates existing comment sometimes
'no_break_comment' => false,
'array_syntax' => true,
'lowercase_static_reference' => true,
'visibility_required' => false,
// Too much noise
'binary_operator_spaces' => false,
'heredoc_indentation' => false,
'trailing_comma_in_multiline' => false,
];
$config = new PhpCsFixer\Config();
return $config
->setRules($rules)
// ->setRiskyAllowed(true)
->setFinder($finder);
"
$ vendor/bin/php-cs-fixer --version
PHP CS Fixer 3.8.0 BerSzcz against war! by Fabien Potencier and Dariusz Ruminski.
PHP runtime: 8.1.7
$ vendor/bin/php-cs-fixer fix
$ rm .php-cs-fixer.cache
$ vendor/bin/php-cs-fixer fix
2022-07-08 14:00:52 +03:00
|
|
|
$image = $img->photo ?? $img;
|
2022-07-01 16:10:30 +03:00
|
|
|
$item = [
|
|
|
|
'uri' => self::URI . substr($image->url, 1),
|
|
|
|
'title' => $image->subject,
|
|
|
|
'author' => $img->member->global_name,
|
|
|
|
'enclosures' => [$image->large_url],
|
|
|
|
'uid' => $image->id,
|
|
|
|
];
|
2022-09-09 21:18:50 +03:00
|
|
|
// Context cosplayer don't have created_at
|
|
|
|
if (isset($image->created_at)) {
|
|
|
|
$item['timestamp'] = $image->created_at;
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
$item['content'] = sprintf(
|
|
|
|
self::CONTENT_HTML,
|
|
|
|
$item['uri'],
|
|
|
|
$item['enclosures'][0],
|
|
|
|
$item['title'],
|
|
|
|
$item['title']
|
|
|
|
);
|
|
|
|
$this->items[] = $item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getName()
|
|
|
|
{
|
|
|
|
switch ($this->queriedContext) {
|
|
|
|
case 'Character':
|
|
|
|
$id = $this->getInput('cid');
|
|
|
|
break;
|
|
|
|
case 'Cosplayer':
|
|
|
|
$id = $this->getInput('uid');
|
|
|
|
break;
|
|
|
|
case 'Series':
|
|
|
|
$id = $this->getInput('sid');
|
|
|
|
break;
|
|
|
|
case 'Tag':
|
|
|
|
$id = $this->getInput('tid');
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return parent::getName();
|
|
|
|
}
|
|
|
|
return sprintf('%s %u - ', $this->queriedContext, $id) . self::NAME;
|
|
|
|
}
|
2020-09-09 15:11:19 +03:00
|
|
|
}
|