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/theme.php

35 lines
1.4 KiB
PHP
Raw Normal View History

<?php
declare(strict_types=1);
namespace Shimmie2;
class ReverseSearchLinksTheme extends Themelet
{
public function reverse_search_block(Page $page, Image $image): void
{
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 = "";
2024-08-31 16:05:18 +00:00
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' class='reverse_image_link' rel='nofollow'><img title='Search with $name' src='$icon_link' alt='$name icon'></a>";
}
}
$page->add_block(new Block("Reverse Image Search", $html, "main", 20));
}
}