diff --git a/admin/admin_user_ban.php b/admin/admin_user_ban.php
index 6ab668d43..3053536e1 100644
--- a/admin/admin_user_ban.php
+++ b/admin/admin_user_ban.php
@@ -67,6 +67,7 @@ if (isset($_POST['submit'])) {
}
}
+ $datastore->update('ban_list');
bb_die($lang['BAN_UPDATE_SUCESSFUL'] . '
' . sprintf($lang['CLICK_RETURN_BANADMIN'], '', '') . '
' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', ''));
} else {
$template->assign_vars(['S_BANLIST_ACTION' => 'admin_user_ban.php']);
diff --git a/library/includes/datastore/build_bans.php b/library/includes/datastore/build_bans.php
new file mode 100644
index 000000000..85d73cda6
--- /dev/null
+++ b/library/includes/datastore/build_bans.php
@@ -0,0 +1,21 @@
+fetch_rowset($sql) as $row) {
+ $bans[$row['ban_userid']] = $row;
+}
+
+$this->store('ban_list', $bans);
diff --git a/library/includes/datastore/build_ranks.php b/library/includes/datastore/build_ranks.php
index 3a522add0..1c2d286f7 100644
--- a/library/includes/datastore/build_ranks.php
+++ b/library/includes/datastore/build_ranks.php
@@ -11,9 +11,8 @@ if (!defined('BB_ROOT')) {
die(basename(__FILE__));
}
-$ranks = [];
-
$sql = "SELECT * FROM " . BB_RANKS;
+$ranks = [];
foreach (DB()->fetch_rowset($sql) as $row) {
$ranks[$row['rank_id']] = $row;
diff --git a/library/includes/functions.php b/library/includes/functions.php
index 786f1d8fa..f07cb8c99 100644
--- a/library/includes/functions.php
+++ b/library/includes/functions.php
@@ -2183,15 +2183,13 @@ function user_birthday_icon($user_birthday, $user_id): string
*/
function getUserBanInfo(int $userId): ?array
{
- return DB()->fetch_row("SELECT * FROM " . BB_BANLIST . " WHERE ban_userid = $userId LIMIT 1");
-}
+ global $datastore;
-/**
- * Returns information about all bans
- *
- * @return array|null
- */
-function getAllBans(): ?array
-{
- return DB()->fetch_rowset("SELECT * FROM " . BB_BANLIST);
+ // Get bans info from datastore
+ if (!$bans = $datastore->get('ban_list')) {
+ $datastore->update('ban_list');
+ $bans = $datastore->get('ban_list');
+ }
+
+ return $bans[$userId] ?? [];
}
diff --git a/library/includes/init_bb.php b/library/includes/init_bb.php
index 0130cff9d..005b65671 100644
--- a/library/includes/init_bb.php
+++ b/library/includes/init_bb.php
@@ -394,20 +394,6 @@ $user = new TorrentPier\Legacy\Common\User();
$userdata =& $user->data;
-/**
- * Initial ban check
- */
-if ($banInfo = getUserBanInfo((int)$user->id)) {
- if (!IS_GUEST) {
- $user->session_end();
- }
- if (!empty($banInfo['ban_reason'])) {
- bb_die($lang['YOU_BEEN_BANNED'] . '
' . $banInfo['ban_reason']);
- } else {
- bb_die($lang['YOU_BEEN_BANNED']);
- }
-}
-
/**
* Cron
*/
diff --git a/src/Legacy/Common/User.php b/src/Legacy/Common/User.php
index 31b7ba132..a8e47817e 100644
--- a/src/Legacy/Common/User.php
+++ b/src/Legacy/Common/User.php
@@ -108,7 +108,7 @@ class User
*/
public function session_start(array $cfg = [])
{
- global $bb_cfg;
+ global $bb_cfg, $lang;
$update_sessions_table = false;
$this->cfg = array_merge($this->cfg, $cfg);
@@ -217,26 +217,35 @@ class User
$this->init_userprefs();
+ // Initial ban check
+ if ($banInfo = getUserBanInfo((int)$this->id)) {
+ if (!empty($banInfo['ban_reason'])) {
+ bb_die($lang['YOU_BEEN_BANNED'] . '
' . $banInfo['ban_reason']);
+ } else {
+ bb_die($lang['YOU_BEEN_BANNED']);
+ }
+ $this->session_end();
+ }
+
return $this->data;
}
/**
* Create new session for the given user
*
- * @param $userdata
+ * @param array $userdata
* @param bool $auto_created
*
* @return array
*/
- public function session_create($userdata, bool $auto_created = false): array
+ public function session_create(array $userdata, bool $auto_created = false): array
{
- global $bb_cfg, $lang;
+ global $bb_cfg;
$this->data = $userdata;
$session_id = $this->sessiondata['sid'];
$login = ((int)$this->data['user_id'] !== GUEST_UID);
- $is_user = ((int)$this->data['user_level'] !== ADMIN);
$user_id = (int)$this->data['user_id'];
$mod_admin_session = ((int)$this->data['user_level'] === ADMIN || (int)$this->data['user_level'] === MOD);
diff --git a/src/Legacy/Datastore/Common.php b/src/Legacy/Datastore/Common.php
index aad004059..9e3b81fc2 100644
--- a/src/Legacy/Datastore/Common.php
+++ b/src/Legacy/Datastore/Common.php
@@ -47,6 +47,7 @@ class Common
'moderators' => 'build_moderators.php',
'stats' => 'build_stats.php',
'ranks' => 'build_ranks.php',
+ 'ban_list' => 'build_bans.php',
'attach_extensions' => 'build_attach_extensions.php',
'smile_replacements' => 'build_smilies.php',
];