From fefb6ff8f30dcef5edb74fb21bdd6d66567d9b43 Mon Sep 17 00:00:00 2001 From: xiaomlove Date: Sun, 24 Jul 2022 02:04:29 +0800 Subject: [PATCH] peer location relative to privacy --- app/Models/Torrent.php | 14 +------ public/userdetails.php | 6 ++- public/viewpeerlist.php | 91 ++++++++++++++++++++++++++--------------- 3 files changed, 63 insertions(+), 48 deletions(-) diff --git a/app/Models/Torrent.php b/app/Models/Torrent.php index 9e3dadce..88e1dc22 100644 --- a/app/Models/Torrent.php +++ b/app/Models/Torrent.php @@ -179,7 +179,7 @@ class Torrent extends NexusModel throw new \RuntimeException('no select sp_state field'); } $spState = $this->sp_state; - $global = self::getGlobalPromotionState(); + $global = get_global_sp_state(); $log = sprintf('torrent: %s sp_state: %s, global sp state: %s', $this->id, $spState, $global); if ($global != self::PROMOTION_NORMAL) { $spState = $global; @@ -214,18 +214,6 @@ class Torrent extends NexusModel ); } - public static function getGlobalPromotionState() - { - if (is_null(self::$globalPromotionState)) { - $result = TorrentState::query()->first(['global_sp_state']); - if (!$result) { - do_log("global sp state no value", 'error'); - } - self::$globalPromotionState = $result->global_sp_state ?? false; - } - return self::$globalPromotionState; - } - public static function getFieldsForList($appendTableName = false): array|bool { $fields = 'id, sp_state, promotion_time_type, promotion_until, banned, picktype, pos_state, category, source, medium, codec, standard, processing, team, audiocodec, leechers, seeders, name, small_descr, times_completed, size, added, comments,anonymous,owner,url,cache_stamp, pt_gen, hr, approval_status'; diff --git a/public/userdetails.php b/public/userdetails.php index 51a653d5..312e40f7 100644 --- a/public/userdetails.php +++ b/public/userdetails.php @@ -312,7 +312,11 @@ tr_small($lang_userdetails['row_forum_posts'], ($forumposts && ($user["id"] == $ if ($user["id"] == $CURUSER["id"] || get_user_class() >= $viewhistory_class) { if (\App\Models\HitAndRun::getIsEnabled()) { $hrStatus = (new \App\Repositories\HitAndRunRepository())->getStatusStats($user['id']); - tr_small('H&R', sprintf('%s', getSchemeAndHttpHost(), $user['id'], $hrStatus), 1); + tr_small('H&R', sprintf('%s', $user['id'], $hrStatus), 1); + } + if (\App\Models\Claim::getConfigIsEnabled()) { + $states = (new \App\Repositories\ClaimRepository())->getStats($user['id']); + tr_small($lang_functions['menu_claim'], sprintf('%s', $user['id'], $states), 1); } tr_small($lang_userdetails['row_karma_points'], number_format($user['seedbonus'], 1), 1); tr_small($lang_functions['text_seed_points'], number_format($user['seed_points'], 1), 1); diff --git a/public/viewpeerlist.php b/public/viewpeerlist.php index 8bf251f6..ba3127e4 100644 --- a/public/viewpeerlist.php +++ b/public/viewpeerlist.php @@ -11,6 +11,44 @@ header("Content-Type: text/xml; charset=utf-8"); $id = intval($_GET['id'] ?? 0); $seedBoxRep = new \App\Repositories\SeedBoxRepository(); + +function get_location_column($e, $isStrongPrivacy, $canView): string +{ + global $enablelocation_tweak, $seedBoxRep, $lang_functions, $lang_viewpeerlist; + if ($enablelocation_tweak == 'yes') { + $address = $ips = []; + if (!empty($e['ipv4'])) { + list($loc_pub, $loc_mod) = get_ip_location($e['ipv4']); + $seedBoxIcon = $seedBoxRep->renderIcon($e['ipv4'], $e['userid']); + $address[] = $loc_pub . $seedBoxIcon; + $ips[] = $e['ipv4']; + } + if (!empty($e['ipv6'])) { + list($loc_pub, $loc_mod) = get_ip_location($e['ipv6']); + $seedBoxIcon = $seedBoxRep->renderIcon($e['ipv6'], $e['userid']); + $address[] = $loc_pub . $seedBoxIcon; + $ips[] = $e['ipv6']; + } + $title = sprintf('%s%s%s', $lang_functions['text_user_ip'], ': ', implode(', ', $ips)); + $addressStr = implode('
', $address); + $location = "
" . $addressStr . "
"; + } else { + $location = implode(', ', array_filter([$e['ipv4'], $e['ipv6']])); + } + + if ($isStrongPrivacy) { + $result = '
'.$lang_viewpeerlist['text_anonymous'].'
'; + if ($canView) { + $result .= $location; + } + } else { + $result = $location; + } + + return "
" . $result . "
\n"; +} + + if(isset($CURUSER)) { function dltable($name, $arr, $torrent) @@ -20,12 +58,13 @@ function dltable($name, $arr, $torrent) global $lang_functions, $seedBoxRep; $s = "" . count($arr) . " $name\n"; + $showLocationColumn = $enablelocation_tweak == 'yes' || get_user_class() >= $userprofile_class; if (!count($arr)) return $s; $s .= "\n"; $s .= "\n"; $s .= "" . - ($enablelocation_tweak == 'yes' || get_user_class() >= $userprofile_class ? "" : ""). + ($showLocationColumn ? "" : ""). "". "". "" . @@ -40,46 +79,30 @@ function dltable($name, $arr, $torrent) $num = 0; $privacyData = \App\Models\User::query()->whereIn('id', array_column($arr, 'userid'))->get(['id', 'privacy'])->keyBy('id'); foreach ($arr as $e) { -// $privacy = get_single_value("users", "privacy","WHERE id=".sqlesc($e['userid'])); $privacy = $privacyData->get($e['userid'])->privacy ?? ''; ++$num; $highlight = $CURUSER["id"] == $e['userid'] ? " bgcolor=#BBAF9B" : ""; $s .= "\n"; - if($privacy == "strong" || ($torrent['anonymous'] == 'yes' && $e['userid'] == $torrent['owner'])) - { - if(get_user_class() >= $viewanonymous_class || $e['userid'] == $CURUSER['id']) - $s .= "\n"; - } - else - $s .= "\n"; + if ($showLocationColumn) { + $s .= get_location_column($e, true, false); + } } - if (!empty($e['ipv6'])) { - list($loc_pub, $loc_mod) = get_ip_location($e['ipv6']); - $seedBoxIcon = $seedBoxRep->renderIcon($e['ipv6'], $e['userid']); - $address[] = $loc_pub . $seedBoxIcon; - $ips[] = $e['ipv6']; + } else { + $s .= "\n"; - } - elseif (get_user_class() >= $userprofile_class){ - $location = implode(', ', array_filter([$e['ipv4'], $e['ipv6']])); - $s .= "\n"; - } + } $s .= "\n"; $s .= "\n";
".$lang_viewpeerlist['col_user_ip']."".$lang_viewpeerlist['col_location']."".$lang_viewpeerlist['col_location']."".$lang_viewpeerlist['col_connectable']."".$lang_viewpeerlist['col_uploaded']."".$lang_viewpeerlist['col_rate']."".$lang_viewpeerlist['text_anonymous']."
(" . get_username($e['userid']) . ")"; - else - $s .= "
".$lang_viewpeerlist['text_anonymous']."" . get_username($e['userid']); - - $secs = max(1, ($e["la"] - $e["st"])); - if ($enablelocation_tweak == 'yes'){ - $address = $ips = []; - if (!empty($e['ipv4'])) { - list($loc_pub, $loc_mod) = get_ip_location($e['ipv4']); - $seedBoxIcon = $seedBoxRep->renderIcon($e['ipv4'], $e['userid']); - $address[] = $loc_pub . $seedBoxIcon; - $ips[] = $e['ipv4']; + $secs = max(1, ($e["la"] - $e["st"])); + if ($privacy == "strong" || ($torrent['anonymous'] == 'yes' && $e['userid'] == $torrent['owner'])) { + if (get_user_class() >= $viewanonymous_class || $e['userid'] == $CURUSER['id']) { + $s .= "".$lang_viewpeerlist['text_anonymous']."
(" . get_username($e['userid']) . ")"; + if ($showLocationColumn) { + $s .= get_location_column($e, true, true); + } + } else { + $s .= "
".$lang_viewpeerlist['text_anonymous']."" . get_username($e['userid']); + if ($showLocationColumn) { + $s .= get_location_column($e, false, false); } - $title = sprintf('%s%s%s', $lang_functions['text_user_ip'], ': ', implode(', ', $ips)); - $addressStr = implode('
', $address); - $location = get_user_class() >= $userprofile_class ? "
" . $addressStr . "
" : $addressStr; - $s .= "
" . $location . "" . $location . "" . ($e['connectable'] == "yes" ? $lang_viewpeerlist['text_yes'] : "".$lang_viewpeerlist['text_no']."") . "" . mksize($e["uploaded"]) . "