From 018dd69177b0d79dcb74ea4a5b5b08de625b7e6f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?C=C3=B8nstantine=20Kovalensky?=
<45331093+kovalensky@users.noreply.github.com>
Date: Sat, 4 Nov 2023 19:16:23 +0400
Subject: [PATCH] Magnet link tweaks (#1035)
---
library/includes/functions.php | 11 +++++++----
library/language/source/main.php | 1 +
src/Legacy/Torrent.php | 3 ++-
src/Legacy/TorrentFileList.php | 4 ++--
styles/images/magnet_v2.png | Bin 0 -> 2175 bytes
styles/templates/default/tpl_config.php | 1 +
6 files changed, 13 insertions(+), 7 deletions(-)
create mode 100644 styles/images/magnet_v2.png
diff --git a/library/includes/functions.php b/library/includes/functions.php
index 27d17ab62..4ba569caa 100644
--- a/library/includes/functions.php
+++ b/library/includes/functions.php
@@ -1861,20 +1861,23 @@ function create_magnet(string $infohash, string $infohash_v2, string $auth_key,
return false;
}
+ $v1_support = !empty($infohash);
+ $v2_support = !empty($infohash_v2);
+
$magnet = 'magnet:?';
- if (!empty($infohash)) {
+ if ($v1_support) {
$magnet .= 'xt=urn:btih:' . bin2hex($infohash);
}
- if (!empty($infohash_v2)) {
- if (!empty($infohash)) {
+ if ($v2_support) {
+ if ($v1_support) {
$magnet .= '&';
}
$magnet .= 'xt=urn:btmh:1220' . bin2hex($infohash_v2);
}
- return '
';
+ return '
';
}
function set_die_append_msg($forum_id = null, $topic_id = null, $group_id = null)
diff --git a/library/language/source/main.php b/library/language/source/main.php
index 302c7b735..ad06eb6c8 100644
--- a/library/language/source/main.php
+++ b/library/language/source/main.php
@@ -1084,6 +1084,7 @@ $lang['SEEDING'] = 'Seed';
$lang['LEECHING'] = 'Leech';
$lang['IS_REGISTERED'] = 'Registered';
$lang['MAGNET'] = 'Magnet-link';
+$lang['MAGNET_v2'] = 'Magnet-link (BitTorrent v2 supported)';
//torrent status mod
$lang['TOR_STATUS'] = 'Status';
diff --git a/src/Legacy/Torrent.php b/src/Legacy/Torrent.php
index f750727f6..971b78406 100644
--- a/src/Legacy/Torrent.php
+++ b/src/Legacy/Torrent.php
@@ -389,7 +389,8 @@ class Torrent
if (isset($info['length'])) {
$totallen = (float)$info['length'];
- } elseif (isset($bt_v1, $info['files']) && \is_array($info['files'])) {
+ }
+ elseif (isset($bt_v1, $info['files']) && \is_array($info['files'])) {
foreach ($info['files'] as $fn => $f) {
// Exclude padding files
if (($f['attr'] ?? null) !== 'p') {
diff --git a/src/Legacy/TorrentFileList.php b/src/Legacy/TorrentFileList.php
index 682b449df..648022cfe 100644
--- a/src/Legacy/TorrentFileList.php
+++ b/src/Legacy/TorrentFileList.php
@@ -42,7 +42,7 @@ class TorrentFileList
public function get_filelist()
{
global $html;
- if (($this->tor_decoded['info']['meta version'] ?? null) == 2) {
+ if (($this->tor_decoded['info']['meta version'] ?? 1) === 2) {
if (is_array($this->tor_decoded['info']['file tree'] ?? null)) {
return $this->fileTreeList($this->tor_decoded['info']['file tree']); //v2
}
@@ -87,7 +87,7 @@ class TorrentFileList
continue;
}
// Exclude padding files
- if (($f['attr'] ?? null) === 'p') {
+ if (isset($f['attr']) && $f['attr'] === 'p') {
continue;
}
array_deep($f['path'], 'clean_tor_dirname');
diff --git a/styles/images/magnet_v2.png b/styles/images/magnet_v2.png
new file mode 100644
index 0000000000000000000000000000000000000000..f587bf795266b646cec33971de99620ff3a5fae0
GIT binary patch
literal 2175
zcmV-_2!QvAP)(_`g8%^e{{R4h=l}px2mk>USO5SzmjD14Z`WEM
zkN^M(1xZ9fRCwB?S8I%2RTci$+WWljy)*aTnR{nir?d>y3QVC$r7egAEz%YODwL!M
zD2XBQ0a1y@poumnMEoHS5m2MS=pQ9f`~wLI5`!@`EftVjD5dY`Oy_y;oqOJUFMr&b
z>9oA#I$1f%$vOMmYpwl#YaM!Sa5>KPiu2y0>|KEmB~hiU^pnd1|9U3!L})H@fB+VN08*p^SIcT&
z+Ub
zmS!U(Fwq%{zheWm5L^(D>g{**pN~(E{kW5o_o%UhPGm*!{S{ZACx#%@Io(Pr!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