From adfd8f36e7bf5922de25a331c40c2a72fa5527c2 Mon Sep 17 00:00:00 2001 From: xiaomlove Date: Mon, 22 Aug 2022 21:39:20 +0800 Subject: [PATCH] remove get_user_info() + get_user_id() to global --- include/functions.php | 58 ----------------------------------- include/globalfunctions.php | 60 +++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 58 deletions(-) diff --git a/include/functions.php b/include/functions.php index 47b0851f..4c4be700 100644 --- a/include/functions.php +++ b/include/functions.php @@ -464,23 +464,6 @@ function highlight($search,$subject,$hlstart='',$hlend return $subject; } -function get_user_class() -{ - if (IN_NEXUS) { - global $CURUSER; - return $CURUSER["class"] ?? ''; - } - return auth()->user()->class; -} - -function get_user_id() -{ - if (IN_NEXUS) { - global $CURUSER; - return $CURUSER["id"] ?? 0; - } - return auth()->user()->id ?? 0; -} function get_user_class_name($class, $compact = false, $b_colored = false, $I18N = false, array $options = []) { @@ -1931,47 +1914,6 @@ function dbconn($autoclean = false, $doLogin = true) register_shutdown_function("autoclean"); } } -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'); - $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; - } - return null; - }); - -// if ($CURUSER && $id == $CURUSER['id']) { -// $row = array(); -// foreach($neededColumns as $column) { -// $row[$column] = $CURUSER[$column]; -// } -// if (!$curuserRowUpdated) { -// $Cache->cache_value('user_'.$CURUSER['id'].'_content', $row, 900); -// $curuserRowUpdated = true; -// } -// } elseif (!$row = $Cache->get_value('user_'.$id.'_content')){ -// $res = sql_query("SELECT ".implode(',', $neededColumns)." FROM users WHERE id = ".sqlesc($id)) or sqlerr(__FILE__,__LINE__); -// $row = mysql_fetch_array($res); -// $Cache->cache_value('user_'.$id.'_content', $row, 900); -// } - - if (!$row) - return false; - else return $row; -} function userlogin() { // do_log("COOKIE:" . json_encode($_COOKIE) . ", uid: " . (isset($_COOKIE['c_secure_uid']) ? base64($_COOKIE["c_secure_uid"],false) : '')); diff --git a/include/globalfunctions.php b/include/globalfunctions.php index 2d510155..0fd76268 100644 --- a/include/globalfunctions.php +++ b/include/globalfunctions.php @@ -701,6 +701,66 @@ function get_row_count($table, $suffix = "") return $a[0]; } +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'); + $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; + } + return null; + }); + +// if ($CURUSER && $id == $CURUSER['id']) { +// $row = array(); +// foreach($neededColumns as $column) { +// $row[$column] = $CURUSER[$column]; +// } +// if (!$curuserRowUpdated) { +// $Cache->cache_value('user_'.$CURUSER['id'].'_content', $row, 900); +// $curuserRowUpdated = true; +// } +// } elseif (!$row = $Cache->get_value('user_'.$id.'_content')){ +// $res = sql_query("SELECT ".implode(',', $neededColumns)." FROM users WHERE id = ".sqlesc($id)) or sqlerr(__FILE__,__LINE__); +// $row = mysql_fetch_array($res); +// $Cache->cache_value('user_'.$id.'_content', $row, 900); +// } + + if (!$row) + return false; + else return $row; +} + +function get_user_class() +{ + if (IN_NEXUS) { + global $CURUSER; + return $CURUSER["class"] ?? ''; + } + return auth()->user()->class; +} + +function get_user_id() +{ + if (IN_NEXUS) { + global $CURUSER; + return $CURUSER["id"] ?? 0; + } + return auth()->user()->id ?? 0; +} + function nexus() { return \Nexus\Nexus::instance();