This repository has been archived on 2024-09-05. You can view files and clone it, but cannot push or open issues or pull requests.
shimmie2/ext/reverse_search_links/main.php
2024-08-31 17:06:39 +01:00

56 lines
1.3 KiB
PHP

<?php
declare(strict_types=1);
namespace Shimmie2;
abstract class ReverseSearchLinksConfig
{
public const ENABLED_SERVICES = "ext_reverse_search_links_enabled_services";
}
class ReverseSearchLinks extends Extension
{
/** @var ReverseSearchLinksTheme */
protected Themelet $theme;
/**
* Show the extension block when viewing an image
*/
public function onDisplayingImage(DisplayingImageEvent $event): void
{
global $page;
// only support image types
$supported_types = [MimeType::JPEG, MimeType::GIF, MimeType::PNG, MimeType::WEBP];
if (in_array($event->image->get_mime(), $supported_types)) {
$this->theme->reverse_search_block($page, $event->image);
}
}
/**
* Supported reverse search services
*
* @var string[]
*/
protected array $SERVICES = [
'SauceNAO',
'TinEye',
'trace.moe',
'ascii2d',
'Yandex'
];
/**
* Set default config values
*/
public function onInitExt(InitExtEvent $event): void
{
global $config;
$config->set_default_array(
ReverseSearchLinksConfig::ENABLED_SERVICES,
['SauceNAO', 'TinEye', 'trace.moe', 'ascii2d', 'Yandex']
);
}
}