From 7fcb4078dd6bc58f7ba9d87ab2e16089db7f068d Mon Sep 17 00:00:00 2001 From: Joe Date: Sat, 19 Aug 2023 15:12:11 -0500 Subject: [PATCH] add reverse image search links extension --- ext/reverse_search_links/icons/ascii2d.ico | Bin 0 -> 1334 bytes ext/reverse_search_links/icons/saucenao.ico | Bin 0 -> 822 bytes ext/reverse_search_links/icons/tineye.ico | Bin 0 -> 894 bytes ext/reverse_search_links/icons/trace.moe.ico | Bin 0 -> 1150 bytes ext/reverse_search_links/icons/yandex.ico | Bin 0 -> 1150 bytes ext/reverse_search_links/info.php | 18 ++++ ext/reverse_search_links/main.php | 85 +++++++++++++++++++ ext/reverse_search_links/style.css | 4 + ext/reverse_search_links/theme.php | 37 ++++++++ 9 files changed, 144 insertions(+) create mode 100644 ext/reverse_search_links/icons/ascii2d.ico create mode 100644 ext/reverse_search_links/icons/saucenao.ico create mode 100644 ext/reverse_search_links/icons/tineye.ico create mode 100644 ext/reverse_search_links/icons/trace.moe.ico create mode 100644 ext/reverse_search_links/icons/yandex.ico create mode 100644 ext/reverse_search_links/info.php create mode 100644 ext/reverse_search_links/main.php create mode 100644 ext/reverse_search_links/style.css create mode 100644 ext/reverse_search_links/theme.php diff --git a/ext/reverse_search_links/icons/ascii2d.ico b/ext/reverse_search_links/icons/ascii2d.ico new file mode 100644 index 0000000000000000000000000000000000000000..29e6fd1208c8c23e2d2cfd12b68141c7bbf8d292 GIT binary patch literal 1334 zcmZ?rHDhG}12Yx|1`Qxf0E!tII3N;0@-QC+GcW=)h7JF>Zr%ES$BrHU_wV2T|K!P&|8L&B z`TyCoXaC>4dGj9xK<16&(J&ZI14APX2$Kr9*x5PxAV5%vUs#x%ot>2#444=hSV%RE b81+CK*m;093P2U}va_>+EaV_YGa)qq8~-$e literal 0 HcmV?d00001 diff --git a/ext/reverse_search_links/icons/saucenao.ico b/ext/reverse_search_links/icons/saucenao.ico new file mode 100644 index 0000000000000000000000000000000000000000..128dde6444fb0cd83f4c385c9ab0bf7b30a27b59 GIT binary patch literal 822 zcmbV`(G7qw2t;fAH-0*T6LbLo-P*mB^vs3Og2W~eI38S&v(BZxDtVV!-Lq)whL9B~VZA-!n~83Jw4O literal 0 HcmV?d00001 diff --git a/ext/reverse_search_links/icons/tineye.ico b/ext/reverse_search_links/icons/tineye.ico new file mode 100644 index 0000000000000000000000000000000000000000..184b8793ead4703f51b88328cc8125d45fbe57d8 GIT binary patch literal 894 zcmZQzU<5(|0R|u`!H~hsz#zuJz@P!dKp_SNAO?x!0>;YxOY#l3R+|w-KxIJ1i}DNz zs)Q@Rs(4eS>AEtLHKoQt1Y`iYaP?Rj8!Akf78uUW)(0XW1IWdy3?jIz#rZ!HSXb>p z(0riApWi%ng4{T+^b+w6BY+ih>K-dbn*>)R)| z`9Svo(H2;MAMSI5qy62kJKCJKw>tg${^{qpPfN?KHrCl}sI}fuW4W!~dPjrR_Bso= zVj$!C&i<>rXRfKW1DX$1zof$Y@~#thh&7195pV+FR7{Z)nQdM;Tnpwu z-cF9cjD-Kwsc9OeQYK}y70P5Pl*^SV7JJyMM?U{flZj3JKGAq=Q#}5-SN*}kA@zD= z8Vrc)^^d)3)qg~z_cR>Z6bPLCsy>lOP^na+a5yaWe1~MxbZSGPkmRgWJ(TZsI<(nr zh;6-IQ=w4!rr~(CT1n2jZnx|3YPCwXZA+$>#bQAok4I{JJ|A)HHrCf_HOZ&bsT;{X z_lQIylIyze+|4bV&1RA}8jYR)%jJ^%e!t}GId&WO=Q{QNX0s{Z&6@dqPL^dkj5Vfd z$~<%aAJ(f{GnlvA?H{>1=YRRM0i5eV@fCO~0ymd{Q3mup@Nxy@ X(|{%7;H}74fVT^gyA%6op-p`PqdU!> literal 0 HcmV?d00001 diff --git a/ext/reverse_search_links/icons/yandex.ico b/ext/reverse_search_links/icons/yandex.ico new file mode 100644 index 0000000000000000000000000000000000000000..984e71c075e0381723d136012a50220a7225bdf9 GIT binary patch literal 1150 zcma)*Pe_w-9L9fA_6LKFB1Z&sh==}qD2oLV8KF{#C=W#tUK-lPLterl!b_Kkzy{I5 zOCxsJK^OzsXd;Y!Wd+NmS`8d4Bl_nSvNd1#K0V*}?YFu}`;O0^eV^z1z}O$9n)qgc6Jt;M8bel^EQ){M%|Y@nN0rhdc9ZKadTG!=VCgYhGu&DIlJ#|qR|(1 zU+1AvD9+Ad?n>bFXEGURQmL2hF4;^?&DVXMiv|LLo9uP)we-&|EG$4{7_Zqa+9VQh z>b}lJ=jP@#%r}#>*=!b?iHQQcRhzM~Pjz4CTEpS+6L$BJzCxh@OmzS5Ne~O$e zm&*`t-!ZYH4Hy|Uk$qP|Ydf(2sD-cJoLt|D8iw(h-41fRTCHMbrHZazzUMCBS$Y-X zT^g*}`@M&2_AZ`KEEYd_Jf3cLHxa*SnutxWq4NyTGXTggM4vjI{{pb|+4005A0HoN zZx>%v)R9`PhLO7#j$HvBMJ&iJlq)s#4#DECEea+!j zZuR>K4m(?UuLRECN~Kaj0~3qIuJhi*Q+~q^+; '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.
+ Options for which services to show and the position and priority of the block are available for admins on the config page."; +} diff --git a/ext/reverse_search_links/main.php b/ext/reverse_search_links/main.php new file mode 100644 index 00000000..9c68bb64 --- /dev/null +++ b/ext/reverse_search_links/main.php @@ -0,0 +1,85 @@ +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"], "
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'] + ); + } +} diff --git a/ext/reverse_search_links/style.css b/ext/reverse_search_links/style.css new file mode 100644 index 00000000..5ad622c0 --- /dev/null +++ b/ext/reverse_search_links/style.css @@ -0,0 +1,4 @@ +#Reverse_Image_Searchmain a, +#Reverse_Image_Searchleft a { + padding: 0 5px; +} diff --git a/ext/reverse_search_links/theme.php b/ext/reverse_search_links/theme.php new file mode 100644 index 00000000..592d07cf --- /dev/null +++ b/ext/reverse_search_links/theme.php @@ -0,0 +1,37 @@ + '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 .= "$name icon"; + } + } + + $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)); + } +}