From 072b5a074ff6ba39ca5a2570cfc8ca7017db40c4 Mon Sep 17 00:00:00 2001 From: Roman Kelesidis Date: Sun, 27 Aug 2023 21:13:36 +0700 Subject: [PATCH] =?UTF-8?q?WIP:=20Added=20search=20by=20info=5Fhash=20v2?= =?UTF-8?q?=20=F0=9F=90=AF=20(#869)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Added search by info_hash v2 * Update functions.php * Update functions.php --- library/includes/functions.php | 16 +++++++++++++--- styles/templates/default/tracker.tpl | 2 +- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/library/includes/functions.php b/library/includes/functions.php index fec7ce425..03c7b3bcb 100644 --- a/library/includes/functions.php +++ b/library/includes/functions.php @@ -1949,14 +1949,24 @@ function hash_search($hash) global $lang; $hash = htmlCHR(trim($hash)); + $info_hash_where = null; - if (!isset($hash) || mb_strlen($hash, 'UTF-8') != 40) { + if (!isset($hash)) { bb_die(sprintf($lang['HASH_INVALID'], $hash)); } - $info_hash = DB()->escape(pack("H*", $hash)); + $info_hash = DB()->escape(pack('H*', $hash)); - if ($row = DB()->fetch_row("SELECT topic_id FROM " . BB_BT_TORRENTS . " WHERE info_hash = '$info_hash'")) { + // Check info_hash version + if (mb_strlen($hash, 'UTF-8') == 40) { + $info_hash_where = "WHERE info_hash = '$info_hash'"; + } elseif (mb_strlen($hash, 'UTF-8') == 64) { + $info_hash_where = "WHERE info_hash_v2 = '$info_hash'"; + } else { + bb_die(sprintf($lang['HASH_INVALID'], $hash)); + } + + if ($row = DB()->fetch_row("SELECT topic_id FROM " . BB_BT_TORRENTS . " $info_hash_where")) { redirect(TOPIC_URL . $row['topic_id']); } else { bb_die(sprintf($lang['HASH_NOT_FOUND'], $hash)); diff --git a/styles/templates/default/tracker.tpl b/styles/templates/default/tracker.tpl index f6dc5164e..1bd3b1e24 100644 --- a/styles/templates/default/tracker.tpl +++ b/styles/templates/default/tracker.tpl @@ -283,7 +283,7 @@ $(function(){
- {L_TITLE_MATCH} · {L_HASH_S} + {L_TITLE_MATCH} · {L_HASH_S}