From 2555ebce4717f871922495e48cbca9e22da78bd5 Mon Sep 17 00:00:00 2001 From: Roman Kelesidis Date: Sun, 4 May 2025 11:55:28 +0300 Subject: [PATCH] feat: Added ability to hide peer country in peer list (#1891) * feat: Added ability to hide peer country in peer list * Update displaying_torrent.php * Update displaying_torrent.php * Updated * Update usercp_register.tpl * Update main.php * Update functions.php --- library/attach_mod/displaying_torrent.php | 13 ++++++++++++- library/includes/functions.php | 11 +++++++++-- library/includes/ucp/register.php | 1 + library/language/source/main.php | 1 + styles/templates/default/usercp_register.tpl | 7 +++++++ 5 files changed, 30 insertions(+), 3 deletions(-) diff --git a/library/attach_mod/displaying_torrent.php b/library/attach_mod/displaying_torrent.php index 84e9fa359..0a780e16d 100644 --- a/library/attach_mod/displaying_torrent.php +++ b/library/attach_mod/displaying_torrent.php @@ -462,11 +462,22 @@ if ($tor_reged && $tor_info) { } } + $peerCountry = $lang['UNKNOWN']; + if (IS_AM || $peer['user_id'] == $userdata['user_id'] || !bf($peer['user_opt'], 'user_opt', 'user_hide_peer_country')) { + if ($port !== false && $ip !== false) { + if ($infoByIP = infoByIP($ip, $port)) { + if (isset($infoByIP['countryCode'])) { + $peerCountry = render_flag($infoByIP['countryCode']); + } + } + } + } + $template->assign_block_vars("$x_full.$x_row", [ 'ROW_BGR' => $row_bgr, 'NAME' => ($peer['update_time']) ? $name : "$name", 'PEER_ID' => $peerTorrentClient, - 'COUNTRY' => render_flag(infoByIP((!empty($peer['ipv6']) ? $peer['ipv6'] : $peer['ip']), $peer['port'])['countryCode'], false), + 'COUNTRY' => $peerCountry, 'COMPL_PRC' => $compl_perc, 'UP_TOTAL' => ($max_up_id[$x] == $pid) ? "$up_tot" : $up_tot, 'DOWN_TOTAL' => ($max_down_id[$x] == $pid) ? "$down_tot" : $down_tot, diff --git a/library/includes/functions.php b/library/includes/functions.php index a383c00d3..efc0bee13 100644 --- a/library/includes/functions.php +++ b/library/includes/functions.php @@ -197,7 +197,8 @@ $bf['user_opt'] = [ 'dis_post_edit' => 13, // [PROHIBITIONS] Block editing own posts / topics 'user_dls' => 14, // [SETTINGS] Hide list of "Current downloads" in my profile 'user_retracker' => 15, // [SETTINGS] Add my retracker into downloaded torrent files - 'user_hide_torrent_client' => 16 // [SETTINGS] Option to hide user's torrent client in peer list + 'user_hide_torrent_client' => 16, // [SETTINGS] Option to hide user's torrent client in peer list + 'user_hide_peer_country' => 17 // [SETTINGS] Option to hide user's country name in peer list ]; function bit2dec($bit_num) @@ -602,7 +603,13 @@ function bt_show_ip($ip, $port = '') if (IS_AM) { $ip = \TorrentPier\Helpers\IPHelper::long2ip_extended($ip); - $ip .= ($port) ? ":$port" : ''; + + // Wrap IPv6 address in square brackets + if ($port && str_contains($ip, ':')) { + $ip = "[$ip]"; + } + $ip .= $port ? ":$port" : ''; + return $ip; } diff --git a/library/includes/ucp/register.php b/library/includes/ucp/register.php index 6abf55c1e..0e8cc2e34 100644 --- a/library/includes/ucp/register.php +++ b/library/includes/ucp/register.php @@ -366,6 +366,7 @@ foreach ($profile_fields as $field => $can_edit) { 'user_callseed' => $reg_mode ? true : true, 'user_retracker' => $reg_mode ? true : true, 'user_hide_torrent_client' => $reg_mode ? true : true, + 'user_hide_peer_country' => $reg_mode ? true : true, ]; foreach ($update_user_opt as $opt => $can_change_opt) { diff --git a/library/language/source/main.php b/library/language/source/main.php index c8ee2c495..3f8da2cdc 100644 --- a/library/language/source/main.php +++ b/library/language/source/main.php @@ -1880,6 +1880,7 @@ $lang['DL_STOPPED'] = 'stopped'; $lang['DL_UPD'] = 'upd: '; $lang['DL_INFO'] = 'shows data only for the current session'; $lang['HIDE_PEER_TORRENT_CLIENT'] = 'Hide my BitTorrent client name in peer list'; +$lang['HIDE_PEER_COUNTRY_NAME'] = 'Hide my country name in peer list'; // Post PIN $lang['POST_PIN'] = 'Pin first post'; diff --git a/styles/templates/default/usercp_register.tpl b/styles/templates/default/usercp_register.tpl index 9f3016280..d55a7a208 100644 --- a/styles/templates/default/usercp_register.tpl +++ b/styles/templates/default/usercp_register.tpl @@ -326,6 +326,13 @@ + + {L_HIDE_PEER_COUNTRY_NAME}: + +    + + + {L_AVATAR_PANEL}