mirror of
https://github.com/torrentpier/torrentpier
synced 2025-08-19 21:03:54 -07:00
Refactored Sessions class (#656)
This commit is contained in:
parent
4d496ba645
commit
58cc723e4b
15 changed files with 34 additions and 35 deletions
|
@ -38,6 +38,6 @@ switch ($mode) {
|
||||||
|
|
||||||
DB()->query("UPDATE " . BB_USERS . " SET avatar_ext_id = $new_ext_id WHERE user_id = $user_id");
|
DB()->query("UPDATE " . BB_USERS . " SET avatar_ext_id = $new_ext_id WHERE user_id = $user_id");
|
||||||
|
|
||||||
\TorrentPier\Legacy\Sessions::cache_rm_user_sessions($user_id);
|
\TorrentPier\Sessions::cache_rm_user_sessions($user_id);
|
||||||
|
|
||||||
$this->response['avatar_html'] = $response;
|
$this->response['avatar_html'] = $response;
|
||||||
|
|
|
@ -97,7 +97,7 @@ switch ($mode) {
|
||||||
}
|
}
|
||||||
|
|
||||||
send_pm($tor['poster_id'], $subject, $message, $userdata['user_id']);
|
send_pm($tor['poster_id'], $subject, $message, $userdata['user_id']);
|
||||||
\TorrentPier\Legacy\Sessions::cache_rm_user_sessions($tor['poster_id']);
|
\TorrentPier\Sessions::cache_rm_user_sessions($tor['poster_id']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -115,7 +115,7 @@ switch ($mode) {
|
||||||
}
|
}
|
||||||
|
|
||||||
send_pm($tor['checked_user_id'], $subject, $message, $userdata['user_id']);
|
send_pm($tor['checked_user_id'], $subject, $message, $userdata['user_id']);
|
||||||
\TorrentPier\Legacy\Sessions::cache_rm_user_sessions($tor['checked_user_id']);
|
\TorrentPier\Sessions::cache_rm_user_sessions($tor['checked_user_id']);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,6 +33,6 @@ foreach ($bf['user_opt'] as $opt_name => $opt_bit) {
|
||||||
DB()->query("UPDATE " . BB_USERS . " SET user_opt = {$u_data['user_opt']} WHERE user_id = $user_id");
|
DB()->query("UPDATE " . BB_USERS . " SET user_opt = {$u_data['user_opt']} WHERE user_id = $user_id");
|
||||||
|
|
||||||
// Удаляем данные из кеша
|
// Удаляем данные из кеша
|
||||||
\TorrentPier\Legacy\Sessions::cache_rm_user_sessions($user_id);
|
\TorrentPier\Sessions::cache_rm_user_sessions($user_id);
|
||||||
|
|
||||||
$this->response['resp_html'] = $lang['SAVED'];
|
$this->response['resp_html'] = $lang['SAVED'];
|
||||||
|
|
|
@ -26,7 +26,7 @@ if ($rank_id != 0 && !isset($ranks[$rank_id])) {
|
||||||
|
|
||||||
DB()->query("UPDATE " . BB_USERS . " SET user_rank = $rank_id WHERE user_id = $user_id");
|
DB()->query("UPDATE " . BB_USERS . " SET user_rank = $rank_id WHERE user_id = $user_id");
|
||||||
|
|
||||||
\TorrentPier\Legacy\Sessions::cache_rm_user_sessions($user_id);
|
\TorrentPier\Sessions::cache_rm_user_sessions($user_id);
|
||||||
|
|
||||||
$user_rank = ($rank_id) ? '<span class="' . $ranks[$rank_id]['rank_style'] . '">' . $ranks[$rank_id]['rank_title'] . '</span>' : '';
|
$user_rank = ($rank_id) ? '<span class="' . $ranks[$rank_id]['rank_style'] . '">' . $ranks[$rank_id]['rank_title'] . '</span>' : '';
|
||||||
|
|
||||||
|
|
|
@ -153,6 +153,6 @@ switch ($field) {
|
||||||
$value_sql = DB()->escape($value, true);
|
$value_sql = DB()->escape($value, true);
|
||||||
DB()->query("UPDATE $table SET $field = $value_sql WHERE user_id = $user_id");
|
DB()->query("UPDATE $table SET $field = $value_sql WHERE user_id = $user_id");
|
||||||
|
|
||||||
\TorrentPier\Legacy\Sessions::cache_rm_user_sessions($user_id);
|
\TorrentPier\Sessions::cache_rm_user_sessions($user_id);
|
||||||
|
|
||||||
$this->response['edit_id'] = $this->request['edit_id'];
|
$this->response['edit_id'] = $this->request['edit_id'];
|
||||||
|
|
|
@ -90,7 +90,7 @@ switch ($mode) {
|
||||||
// Set current user timezone
|
// Set current user timezone
|
||||||
DB()->query("UPDATE " . BB_USERS . " SET user_timezone = $tz WHERE user_id = " . $userdata['user_id']);
|
DB()->query("UPDATE " . BB_USERS . " SET user_timezone = $tz WHERE user_id = " . $userdata['user_id']);
|
||||||
$bb_cfg['board_timezone'] = $tz;
|
$bb_cfg['board_timezone'] = $tz;
|
||||||
\TorrentPier\Legacy\Sessions::cache_rm_user_sessions($userdata['user_id']);
|
\TorrentPier\Sessions::cache_rm_user_sessions($userdata['user_id']);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@ switch ($mode) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($user_id != BOT_UID) {
|
if ($user_id != BOT_UID) {
|
||||||
\TorrentPier\Legacy\Sessions::delete_user_sessions($user_id);
|
\TorrentPier\Sessions::delete_user_sessions($user_id);
|
||||||
\TorrentPier\Legacy\Admin\Common::user_delete($user_id);
|
\TorrentPier\Legacy\Admin\Common::user_delete($user_id);
|
||||||
|
|
||||||
$this->response['info'] = $lang['USER_DELETED'];
|
$this->response['info'] = $lang['USER_DELETED'];
|
||||||
|
@ -99,7 +99,7 @@ switch ($mode) {
|
||||||
}
|
}
|
||||||
|
|
||||||
DB()->query("UPDATE " . BB_USERS . " SET user_active = '0' WHERE user_id = " . $user_id);
|
DB()->query("UPDATE " . BB_USERS . " SET user_active = '0' WHERE user_id = " . $user_id);
|
||||||
\TorrentPier\Legacy\Sessions::delete_user_sessions($user_id);
|
\TorrentPier\Sessions::delete_user_sessions($user_id);
|
||||||
|
|
||||||
$this->response['info'] = $lang['USER_ACTIVATE_OFF'];
|
$this->response['info'] = $lang['USER_ACTIVATE_OFF'];
|
||||||
|
|
||||||
|
|
|
@ -43,7 +43,7 @@ if ($mc_type && $post['poster_id'] != $userdata['user_id']) {
|
||||||
$message = sprintf($lang['MC_COMMENT_PM_MSG'], get_username($post['poster_id']), make_url(POST_URL . "$post_id#$post_id"), $lang['MC_COMMENT'][$mc_type]['type'], $mc_text);
|
$message = sprintf($lang['MC_COMMENT_PM_MSG'], get_username($post['poster_id']), make_url(POST_URL . "$post_id#$post_id"), $lang['MC_COMMENT'][$mc_type]['type'], $mc_text);
|
||||||
|
|
||||||
send_pm($post['poster_id'], $subject, $message);
|
send_pm($post['poster_id'], $subject, $message);
|
||||||
\TorrentPier\Legacy\Sessions::cache_rm_user_sessions($post['poster_id']);
|
\TorrentPier\Sessions::cache_rm_user_sessions($post['poster_id']);
|
||||||
}
|
}
|
||||||
|
|
||||||
switch ($mc_type) {
|
switch ($mc_type) {
|
||||||
|
|
|
@ -1368,7 +1368,7 @@ function bb_die($msg_text)
|
||||||
|
|
||||||
// If empty session
|
// If empty session
|
||||||
if (empty($userdata)) {
|
if (empty($userdata)) {
|
||||||
$userdata = \TorrentPier\Legacy\Sessions::session_pagestart();
|
$userdata = \TorrentPier\Sessions::session_pagestart();
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the header hasn't been output then do it
|
// If the header hasn't been output then do it
|
||||||
|
|
|
@ -70,7 +70,7 @@ if ($logged_in && empty($gen_simple_header) && !defined('IN_ADMIN')) {
|
||||||
if ($userdata['user_last_privmsg'] > $userdata['user_lastvisit'] && defined('IN_PM')) {
|
if ($userdata['user_last_privmsg'] > $userdata['user_lastvisit'] && defined('IN_PM')) {
|
||||||
$userdata['user_last_privmsg'] = $userdata['user_lastvisit'];
|
$userdata['user_last_privmsg'] = $userdata['user_lastvisit'];
|
||||||
|
|
||||||
\TorrentPier\Legacy\Sessions::db_update_userdata($userdata, array(
|
\TorrentPier\Sessions::db_update_userdata($userdata, array(
|
||||||
'user_last_privmsg' => $userdata['user_lastvisit'],
|
'user_last_privmsg' => $userdata['user_lastvisit'],
|
||||||
));
|
));
|
||||||
|
|
||||||
|
@ -93,7 +93,7 @@ if ($logged_in && empty($gen_simple_header) && !defined('IN_ADMIN')) {
|
||||||
if ($userdata['user_unread_privmsg'] != $real_unread_pm_count) {
|
if ($userdata['user_unread_privmsg'] != $real_unread_pm_count) {
|
||||||
$userdata['user_unread_privmsg'] = $real_unread_pm_count;
|
$userdata['user_unread_privmsg'] = $real_unread_pm_count;
|
||||||
|
|
||||||
\TorrentPier\Legacy\Sessions::db_update_userdata($userdata, array(
|
\TorrentPier\Sessions::db_update_userdata($userdata, array(
|
||||||
'user_unread_privmsg' => $real_unread_pm_count,
|
'user_unread_privmsg' => $real_unread_pm_count,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,7 +46,7 @@ if (isset($_POST['bonus_id'])) {
|
||||||
AND u.user_id = bu.user_id
|
AND u.user_id = bu.user_id
|
||||||
");
|
");
|
||||||
|
|
||||||
\TorrentPier\Legacy\Sessions::cache_rm_user_sessions($user_id);
|
\TorrentPier\Sessions::cache_rm_user_sessions($user_id);
|
||||||
meta_refresh(BONUS_URL, 5);
|
meta_refresh(BONUS_URL, 5);
|
||||||
|
|
||||||
$message = sprintf($lang['BONUS_SUCCES'], humn_size($upload_row[$id] * 1024 * 1024 * 1024));
|
$message = sprintf($lang['BONUS_SUCCES'], humn_size($upload_row[$id] * 1024 * 1024 * 1024));
|
||||||
|
|
|
@ -628,7 +628,7 @@ if ($submit && !$errors) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
\TorrentPier\Legacy\Sessions::cache_rm_user_sessions($pr_data['user_id']);
|
\TorrentPier\Sessions::cache_rm_user_sessions($pr_data['user_id']);
|
||||||
|
|
||||||
if ($adm_edit) {
|
if ($adm_edit) {
|
||||||
bb_die($lang['PROFILE_USER'] . ' <b>' . profile_url($pr_data) . '</b> ' . $lang['GOOD_UPDATE']);
|
bb_die($lang['PROFILE_USER'] . ' <b>' . profile_url($pr_data) . '</b> ' . $lang['GOOD_UPDATE']);
|
||||||
|
|
|
@ -179,7 +179,7 @@ if ($mode == 'read') {
|
||||||
bb_die('Could not update private message read status for user');
|
bb_die('Could not update private message read status for user');
|
||||||
}
|
}
|
||||||
if (DB()->affected_rows()) {
|
if (DB()->affected_rows()) {
|
||||||
\TorrentPier\Legacy\Sessions::cache_rm_userdata($userdata);
|
\TorrentPier\Sessions::cache_rm_userdata($userdata);
|
||||||
}
|
}
|
||||||
|
|
||||||
$sql = "UPDATE " . BB_PRIVMSGS . "
|
$sql = "UPDATE " . BB_PRIVMSGS . "
|
||||||
|
@ -895,7 +895,7 @@ if ($mode == 'read') {
|
||||||
bb_die('Could not update private message new / read status for user');
|
bb_die('Could not update private message new / read status for user');
|
||||||
}
|
}
|
||||||
|
|
||||||
\TorrentPier\Legacy\Sessions::cache_rm_user_sessions($to_userdata['user_id']);
|
\TorrentPier\Sessions::cache_rm_user_sessions($to_userdata['user_id']);
|
||||||
|
|
||||||
if (bf($to_userdata['user_opt'], 'user_opt', 'user_notify_pm') && $to_userdata['user_active'] && $bb_cfg['pm_notify_enabled']) {
|
if (bf($to_userdata['user_opt'], 'user_opt', 'user_notify_pm') && $to_userdata['user_active'] && $bb_cfg['pm_notify_enabled']) {
|
||||||
// Sending email
|
// Sending email
|
||||||
|
@ -1146,7 +1146,7 @@ if ($mode == 'read') {
|
||||||
//
|
//
|
||||||
// Update unread status
|
// Update unread status
|
||||||
//
|
//
|
||||||
\TorrentPier\Legacy\Sessions::db_update_userdata($userdata, array(
|
\TorrentPier\Sessions::db_update_userdata($userdata, array(
|
||||||
'user_unread_privmsg' => 'user_unread_privmsg + user_new_privmsg',
|
'user_unread_privmsg' => 'user_unread_privmsg + user_new_privmsg',
|
||||||
'user_new_privmsg' => 0,
|
'user_new_privmsg' => 0,
|
||||||
'user_last_privmsg' => $userdata['session_start'],
|
'user_last_privmsg' => $userdata['session_start'],
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
namespace TorrentPier\Legacy\Common;
|
namespace TorrentPier\Legacy\Common;
|
||||||
|
|
||||||
use TorrentPier\Legacy\DateDelta;
|
use TorrentPier\Legacy\DateDelta;
|
||||||
use TorrentPier\Legacy\Sessions;
|
use TorrentPier\Sessions;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class User
|
* Class User
|
||||||
|
|
|
@ -7,11 +7,11 @@
|
||||||
* @license https://github.com/torrentpier/torrentpier/blob/master/LICENSE MIT License
|
* @license https://github.com/torrentpier/torrentpier/blob/master/LICENSE MIT License
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace TorrentPier\Legacy;
|
namespace TorrentPier;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class Sessions
|
* Class Sessions
|
||||||
* @package TorrentPier\Legacy
|
* @package TorrentPier
|
||||||
*/
|
*/
|
||||||
class Sessions
|
class Sessions
|
||||||
{
|
{
|
||||||
|
@ -20,19 +20,19 @@ class Sessions
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
private static function ignore_cached_userdata()
|
private static function ignore_cached_userdata(): bool
|
||||||
{
|
{
|
||||||
return \defined('IN_PM') ? true : false;
|
return defined('IN_PM');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get userdata from cache
|
* Get userdata from cache
|
||||||
*
|
*
|
||||||
* @param int $id
|
* @param string $id
|
||||||
*
|
*
|
||||||
* @return bool|array
|
* @return bool|array
|
||||||
*/
|
*/
|
||||||
public static function cache_get_userdata($id)
|
public static function cache_get_userdata(string $id)
|
||||||
{
|
{
|
||||||
if (self::ignore_cached_userdata()) {
|
if (self::ignore_cached_userdata()) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -49,7 +49,7 @@ class Sessions
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public static function cache_set_userdata($userdata, $force = false)
|
public static function cache_set_userdata(array $userdata, bool $force = false): bool
|
||||||
{
|
{
|
||||||
global $bb_cfg;
|
global $bb_cfg;
|
||||||
|
|
||||||
|
@ -68,7 +68,7 @@ class Sessions
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public static function cache_rm_userdata($userdata)
|
public static function cache_rm_userdata(array $userdata): bool
|
||||||
{
|
{
|
||||||
if (!$userdata) {
|
if (!$userdata) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -81,11 +81,11 @@ class Sessions
|
||||||
/**
|
/**
|
||||||
* Delete user sessions from cache
|
* Delete user sessions from cache
|
||||||
*
|
*
|
||||||
* @param array|string $user_id
|
* @param string|int $user_id
|
||||||
*/
|
*/
|
||||||
public static function cache_rm_user_sessions($user_id)
|
public static function cache_rm_user_sessions($user_id)
|
||||||
{
|
{
|
||||||
$user_id = get_id_csv($user_id);
|
$user_id = get_id_csv(explode(',', (string)$user_id));
|
||||||
|
|
||||||
$rowset = DB()->fetch_rowset("SELECT session_id FROM " . BB_SESSIONS . " WHERE session_user_id IN($user_id)");
|
$rowset = DB()->fetch_rowset("SELECT session_id FROM " . BB_SESSIONS . " WHERE session_user_id IN($user_id)");
|
||||||
|
|
||||||
|
@ -101,7 +101,7 @@ class Sessions
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public static function cache_update_userdata($userdata)
|
public static function cache_update_userdata(array $userdata): bool
|
||||||
{
|
{
|
||||||
return self::cache_set_userdata($userdata, true);
|
return self::cache_set_userdata($userdata, true);
|
||||||
}
|
}
|
||||||
|
@ -115,7 +115,7 @@ class Sessions
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public static function db_update_userdata($userdata, $sql_ary, $data_already_escaped = true)
|
public static function db_update_userdata(array $userdata, array $sql_ary, bool $data_already_escaped = true): bool
|
||||||
{
|
{
|
||||||
if (!$userdata) {
|
if (!$userdata) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -134,13 +134,13 @@ class Sessions
|
||||||
/**
|
/**
|
||||||
* Delete user sessions from cache and database
|
* Delete user sessions from cache and database
|
||||||
*
|
*
|
||||||
* @param array|string $user_id
|
* @param string|int $user_id
|
||||||
*/
|
*/
|
||||||
public static function delete_user_sessions($user_id)
|
public static function delete_user_sessions($user_id)
|
||||||
{
|
{
|
||||||
self::cache_rm_user_sessions($user_id);
|
self::cache_rm_user_sessions($user_id);
|
||||||
|
|
||||||
$user_id = get_id_csv($user_id);
|
$user_id = get_id_csv(explode(',', (string)$user_id));
|
||||||
DB()->query("DELETE FROM " . BB_SESSIONS . " WHERE session_user_id IN($user_id)");
|
DB()->query("DELETE FROM " . BB_SESSIONS . " WHERE session_user_id IN($user_id)");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -152,9 +152,8 @@ class Sessions
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
* @deprecated
|
* @deprecated
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public static function session_pagestart($user_ip = USER_IP, $page_id = 0, $req_login = false)
|
public static function session_pagestart($user_ip = USER_IP, $page_id = 0, bool $req_login = false): array
|
||||||
{
|
{
|
||||||
global $user;
|
global $user;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue