add reverse image search links extension
This commit is contained in:
parent
945c358ab6
commit
7fcb4078dd
9 changed files with 144 additions and 0 deletions
BIN
ext/reverse_search_links/icons/ascii2d.ico
Normal file
BIN
ext/reverse_search_links/icons/ascii2d.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.3 KiB |
BIN
ext/reverse_search_links/icons/saucenao.ico
Normal file
BIN
ext/reverse_search_links/icons/saucenao.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 822 B |
BIN
ext/reverse_search_links/icons/tineye.ico
Normal file
BIN
ext/reverse_search_links/icons/tineye.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 894 B |
BIN
ext/reverse_search_links/icons/trace.moe.ico
Normal file
BIN
ext/reverse_search_links/icons/trace.moe.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.1 KiB |
BIN
ext/reverse_search_links/icons/yandex.ico
Normal file
BIN
ext/reverse_search_links/icons/yandex.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.1 KiB |
18
ext/reverse_search_links/info.php
Normal file
18
ext/reverse_search_links/info.php
Normal file
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Shimmie2;
|
||||
|
||||
class ReverseSearchLinksInfo extends ExtensionInfo
|
||||
{
|
||||
public const KEY = "reverse_search_links";
|
||||
|
||||
public string $key = self::KEY;
|
||||
public string $name = "Reverse Search Links";
|
||||
public array $authors = ['joe' => 'joe@thisisjoes.site'];
|
||||
public string $license = self::LICENSE_GPLV2;
|
||||
public string $description = "Provides reverse search links for images.";
|
||||
public ?string $documentation = "Click on an icon in the 'Reverse Image Search' block to search for the image using the corresponding service. This may be useful to find the original source or author of an image.<br/>
|
||||
Options for which services to show and the position and priority of the block are available for admins on the config page.";
|
||||
}
|
85
ext/reverse_search_links/main.php
Normal file
85
ext/reverse_search_links/main.php
Normal file
|
@ -0,0 +1,85 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Shimmie2;
|
||||
|
||||
abstract class ReverseSearchLinksConfig
|
||||
{
|
||||
public const PRIORITY = "ext_reverse_search_links_priority";
|
||||
public const POSITION = "ext_reverse_search_links_position";
|
||||
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)
|
||||
{
|
||||
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
|
||||
*/
|
||||
protected array $SERVICES = [
|
||||
'SauceNAO',
|
||||
'IQDB',
|
||||
'TinEye',
|
||||
'trace.moe',
|
||||
'ascii2d',
|
||||
'Yandex'
|
||||
];
|
||||
|
||||
private function get_options(): array
|
||||
{
|
||||
global $config;
|
||||
|
||||
$output = [];
|
||||
$services = $this->SERVICES;
|
||||
foreach ($services as $service) {
|
||||
$output[$service] = $service;
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the settings block
|
||||
*/
|
||||
public function onSetupBuilding(SetupBuildingEvent $event)
|
||||
{
|
||||
$sb = $event->panel->create_new_block("Reverse Search Links");
|
||||
$sb->start_table();
|
||||
$sb->add_int_option("ext_reverse_search_links_priority", "Priority:");
|
||||
$sb->add_choice_option("ext_reverse_search_links_position", ["Main page" => "main", "In navigation bar" => "left"], "<br>Position: ");
|
||||
$sb->add_multichoice_option("ext_reverse_search_links_enabled_services", $this->get_options(), "Enabled Services", true);
|
||||
$sb->end_table();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set default config values
|
||||
*/
|
||||
public function onInitExt(InitExtEvent $event)
|
||||
{
|
||||
global $config;
|
||||
$config->set_default_int(ReverseSearchLinksConfig::PRIORITY, 20);
|
||||
$config->set_default_string(ReverseSearchLinksConfig::POSITION, "main");
|
||||
$config->set_default_array(
|
||||
ReverseSearchLinksConfig::ENABLED_SERVICES,
|
||||
['SauceNAO', 'IQDB', 'TinEye', 'trace.moe', 'ascii2d', 'Yandex']
|
||||
);
|
||||
}
|
||||
}
|
4
ext/reverse_search_links/style.css
Normal file
4
ext/reverse_search_links/style.css
Normal file
|
@ -0,0 +1,4 @@
|
|||
#Reverse_Image_Searchmain a,
|
||||
#Reverse_Image_Searchleft a {
|
||||
padding: 0 5px;
|
||||
}
|
37
ext/reverse_search_links/theme.php
Normal file
37
ext/reverse_search_links/theme.php
Normal file
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Shimmie2;
|
||||
|
||||
class ReverseSearchLinksTheme extends Themelet
|
||||
{
|
||||
public function reverse_search_block(Page $page, Image $image)
|
||||
{
|
||||
global $config;
|
||||
|
||||
$links = [
|
||||
'SauceNAO' => 'https://saucenao.com/search.php?url=' . url_escape(make_http($image->get_thumb_link())),
|
||||
'TinEye' => 'https://www.tineye.com/search/?url=' . url_escape(make_http($image->get_thumb_link())),
|
||||
'trace.moe' => 'https://trace.moe/?auto&url=' . url_escape(make_http($image->get_thumb_link())),
|
||||
'ascii2d' => 'https://ascii2d.net/search/url/' . url_escape(make_http($image->get_thumb_link())),
|
||||
'Yandex' => 'https://yandex.com/images/search?rpt=imageview&url=' . url_escape(make_http($image->get_thumb_link()))
|
||||
];
|
||||
|
||||
// only generate links for enabled reverse search services
|
||||
$enabled_services = $config->get_array(ReverseSearchLinksConfig::ENABLED_SERVICES);
|
||||
|
||||
$html = "";
|
||||
foreach($links as $name => $link) {
|
||||
if (in_array($name, $enabled_services)) {
|
||||
$icon_link = make_link("/ext/reverse_search_links/icons/" . strtolower($name) . ".ico");
|
||||
$html .= "<a href='$link' rel='nofollow'><img title='Search with $name' src='$icon_link' alt='$name icon'></a>";
|
||||
}
|
||||
}
|
||||
|
||||
$position = $config->get_string(ReverseSearchLinksConfig::POSITION) ?? "main";
|
||||
$priority = $config->get_int(ReverseSearchLinksConfig::PRIORITY) ?? 20;
|
||||
|
||||
$page->add_block(new Block("Reverse Image Search", $html, $position, $priority));
|
||||
}
|
||||
}
|
Reference in a new issue