From 82174026430103c2fdc680d47b68e8ea1be620c1 Mon Sep 17 00:00:00 2001 From: xiaomlove Date: Tue, 23 Aug 2022 01:02:54 +0800 Subject: [PATCH] improve get_user_row() --- include/globalfunctions.php | 27 +++++++++++++++------------ public/announce.php | 4 +++- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/include/globalfunctions.php b/include/globalfunctions.php index 0fd76268..915f0be8 100644 --- a/include/globalfunctions.php +++ b/include/globalfunctions.php @@ -705,22 +705,25 @@ function get_user_row($id) { global $Cache, $CURUSER; static $curuserRowUpdated = false; - static $neededColumns = array('id', 'noad', 'class', 'enabled', 'privacy', 'avatar', 'signature', 'uploaded', 'downloaded', 'last_access', 'username', 'donor', 'donoruntil', 'leechwarn', 'warned', 'title'); + static $neededColumns = array( + 'id', 'noad', 'class', 'enabled', 'privacy', 'avatar', 'signature', 'uploaded', 'downloaded', 'last_access', 'username', 'donor', + 'donoruntil', 'leechwarn', 'warned', 'title', 'downloadpos', 'parked', 'clientselect', 'showclienterror', + ); $cacheKey = 'user_'.$id.'_content'; $row = \Nexus\Database\NexusDB::remember($cacheKey, 900, function () use ($id, $neededColumns) { $user = \App\Models\User::query()->with(['wearing_medals'])->find($id, $neededColumns); - if ($user) { - $userRep = new \App\Repositories\UserRepository(); - $metas = $userRep->listMetas($id, \App\Models\UserMeta::META_KEY_PERSONALIZED_USERNAME); - $arr = $user->toArray(); - if ($metas->isNotEmpty()) { - $arr['__is_rainbow'] = 1; - } else { - $arr['__is_rainbow'] = 0; - } - return $arr; + if (!$user) { + return null; } - return null; + $arr = $user->toArray(); + $userRep = new \App\Repositories\UserRepository(); + $metas = $userRep->listMetas($id, \App\Models\UserMeta::META_KEY_PERSONALIZED_USERNAME); + if ($metas->isNotEmpty()) { + $arr['__is_rainbow'] = 1; + } else { + $arr['__is_rainbow'] = 0; + } + return $arr; }); // if ($CURUSER && $id == $CURUSER['id']) { diff --git a/public/announce.php b/public/announce.php index 4701f8ea..db4a5ee3 100644 --- a/public/announce.php +++ b/public/announce.php @@ -172,7 +172,9 @@ if (!$torrent) { do_log("[TORRENT NOT EXISTS] infoHashUrlEncode: $infoHashUrlEncode", 'error'); err("torrent not registered with this tracker"); -} elseif (!user_can('seebanned', false, $userid)) { +} +//Do not use user_can(), some func user_can() used is not available IN_TRACKER +if ($az['class'] < $seebanned_class) { if ($torrent['banned'] == 'yes') { err("torrent banned"); } elseif ($torrent['approval_status'] != \App\Models\Torrent::APPROVAL_STATUS_ALLOW && get_setting('torrent.approval_status_none_visible') == 'no') {