Magnet link tweaks (#1035)

This commit is contained in:
Cønstantine Kovalensky 2023-11-04 19:16:23 +04:00 committed by GitHub
commit 018dd69177
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 13 additions and 7 deletions

View file

@ -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 '<a title="' . $lang['MAGNET'] . '" href="' . $magnet . '&tr=' . urlencode($bb_cfg['bt_announce_url'] . "?{$bb_cfg['passkey_key']}=$auth_key") . '&dn=' . urlencode($name) . '"><img src="' . $images['icon_magnet'] . '" width="12" height="12" border="0" /></a>';
return '<a title="' . ($v2_support ? $lang['MAGNET_v2'] : $lang['MAGNET']) . '" href="' . $magnet . '&tr=' . urlencode($bb_cfg['bt_announce_url'] . "?{$bb_cfg['passkey_key']}=$auth_key") . '&dn=' . urlencode($name) . '"><img src="' . ($v2_support ? $images['icon_magnet_v2'] : $images['icon_magnet']) . '" width="12" height="12" border="0" /></a>';
}
function set_die_append_msg($forum_id = null, $topic_id = null, $group_id = null)

View file

@ -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';

View file

@ -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') {

View file

@ -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');

BIN
styles/images/magnet_v2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

View file

@ -72,6 +72,7 @@ $images['folder_dl_hot_new'] = $_main . 'folder_dl_hot_new.gif';
$images['icon_clip'] = $_img . 'icon_clip.gif';
$images['icon_dn'] = $_img . 'icon_dn.gif';
$images['icon_magnet'] = $_img . 'magnet.png';
$images['icon_magnet_v2'] = $_img . 'magnet_v2.png';
// posting_icons
$images['post_new'] = $_lang . 'post.gif';