diff --git a/CHANGELOG.md b/CHANGELOG.md index e7a1a062b..21291ffb8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ - Fixed broken "Disable Board" function [\#1529](https://github.com/torrentpier/torrentpier/pull/1529) ([belomaxorka](https://github.com/belomaxorka)) - Fixed seed bonus accrual [\#1518](https://github.com/torrentpier/torrentpier/pull/1518) ([belomaxorka](https://github.com/belomaxorka)) - [BETA] Added emojis support 😄😁 [\#1514](https://github.com/torrentpier/torrentpier/pull/1514) ([belomaxorka](https://github.com/belomaxorka)) +- Datastore improvements [\#1538](https://github.com/torrentpier/torrentpier/pull/1538) ([belomaxorka](https://github.com/belomaxorka)) - Resize user/group avatar image if too large 🌆 [\#1512](https://github.com/torrentpier/torrentpier/pull/1512) ([belomaxorka](https://github.com/belomaxorka)) - Increased PASSWORD_MAX_LENGTH [\#1510](https://github.com/torrentpier/torrentpier/pull/1510) ([belomaxorka](https://github.com/belomaxorka)) - Some security improvements 🔑 [\#1503](https://github.com/torrentpier/torrentpier/pull/1503), [\#1505](https://github.com/torrentpier/torrentpier/pull/1505) ([belomaxorka](https://github.com/belomaxorka)) diff --git a/admin/admin_log.php b/admin/admin_log.php index 4fa8f7d2a..6993f02c0 100644 --- a/admin/admin_log.php +++ b/admin/admin_log.php @@ -59,7 +59,7 @@ $def_forums = $all_forums; $def_sort = $sort_desc; // Moderators data -if (!$mod = $datastore->get('moderators')) { +if (!$mod = $datastore->get('moderators') and !$datastore->has('moderators')) { $datastore->update('moderators'); $mod = $datastore->get('moderators'); } @@ -71,7 +71,7 @@ $users = array($lang['ACTS_LOG_ALL_ACTIONS'] => $all_users) + array_flip($mod['m unset($mod); // Forums data -if (!$forums = $datastore->get('cat_forums')) { +if (!$forums = $datastore->get('cat_forums') and !$datastore->has('cat_forums')) { $datastore->update('cat_forums'); $forums = $datastore->get('cat_forums'); } diff --git a/admin/admin_ug_auth.php b/admin/admin_ug_auth.php index 90c27f636..0fd19fff1 100644 --- a/admin/admin_ug_auth.php +++ b/admin/admin_ug_auth.php @@ -181,7 +181,7 @@ if ($mode == 'user' && (!empty($_POST['username']) || $user_id)) { bb_die($lang['NO_SUCH_USER']); } - if (!$forums = $datastore->get('cat_forums')) { + if (!$forums = $datastore->get('cat_forums') and !$datastore->has('cat_forums')) { $datastore->update('cat_forums'); $forums = $datastore->get('cat_forums'); } @@ -300,7 +300,7 @@ if ($mode == 'user' && (!empty($_POST['username']) || $user_id)) { bb_die($lang['GROUP_NOT_EXIST']); } - if (!$forums = $datastore->get('cat_forums')) { + if (!$forums = $datastore->get('cat_forums') and !$datastore->has('cat_forums')) { $datastore->update('cat_forums'); $forums = $datastore->get('cat_forums'); } diff --git a/admin/index.php b/admin/index.php index e91d7ef16..3461156f7 100644 --- a/admin/index.php +++ b/admin/index.php @@ -10,19 +10,19 @@ require __DIR__ . '/pagestart.php'; // Statistics -if (!$stats = $datastore->get('stats')) { +if (!$stats = $datastore->get('stats') and !$datastore->has('stats')) { $datastore->update('stats'); $stats = $datastore->get('stats'); } // Files integrity check -if (!$files_integrity_data = $datastore->get('files_integrity')) { +if (!$files_integrity_data = $datastore->get('files_integrity') and !$datastore->has('files_integrity')) { $datastore->update('files_integrity'); $files_integrity_data = $datastore->get('files_integrity'); } // Check for updates -if (!$update_data = $datastore->get('check_updates')) { +if (!$update_data = $datastore->get('check_updates') and !$datastore->has('check_updates')) { $datastore->update('check_updates'); $update_data = $datastore->get('check_updates'); } diff --git a/index.php b/index.php index 19a5c3a2f..7193dbc8c 100644 --- a/index.php +++ b/index.php @@ -65,13 +65,13 @@ $tracking_topics = get_tracks('topic'); $tracking_forums = get_tracks('forum'); // Statistics -if (!$stats = $datastore->get('stats')) { +if (!$stats = $datastore->get('stats') and !$datastore->has('stats')) { $datastore->update('stats'); $stats = $datastore->get('stats'); } // Forums data -if (!$forums = $datastore->get('cat_forums')) { +if (!$forums = $datastore->get('cat_forums') and !$datastore->has('cat_forums')) { $datastore->update('cat_forums'); $forums = $datastore->get('cat_forums'); } @@ -173,7 +173,7 @@ if (!$cat_forums = CACHE('bb_cache')->get($cache_name)) { // Obtain list of moderators $moderators = []; -if (!$mod = $datastore->get('moderators')) { +if (!$mod = $datastore->get('moderators') and !$datastore->has('moderators')) { $datastore->update('moderators'); $mod = $datastore->get('moderators'); } @@ -321,7 +321,7 @@ if ($bb_cfg['bt_show_dl_stat_on_index'] && !IS_GUEST) { // Latest news if ($bb_cfg['show_latest_news']) { - if (!$latest_news = $datastore->get('latest_news')) { + if (!$latest_news = $datastore->get('latest_news') and !$datastore->has('latest_news')) { $datastore->update('latest_news'); $latest_news = $datastore->get('latest_news'); } @@ -340,7 +340,7 @@ if ($bb_cfg['show_latest_news']) { // Network news if ($bb_cfg['show_network_news']) { - if (!$network_news = $datastore->get('network_news')) { + if (!$network_news = $datastore->get('network_news') and !$datastore->has('network_news')) { $datastore->update('network_news'); $network_news = $datastore->get('network_news'); } diff --git a/library/ajax/change_user_rank.php b/library/ajax/change_user_rank.php index 69b755a34..417000098 100644 --- a/library/ajax/change_user_rank.php +++ b/library/ajax/change_user_rank.php @@ -13,7 +13,7 @@ if (!defined('IN_AJAX')) { global $datastore, $lang; -if (!$ranks = $datastore->get('ranks')) { +if (!$ranks = $datastore->get('ranks') and !$datastore->has('ranks')) { $datastore->update('ranks'); $ranks = $datastore->get('ranks'); } diff --git a/library/ajax/index_data.php b/library/ajax/index_data.php index 193ac1de9..93850db51 100644 --- a/library/ajax/index_data.php +++ b/library/ajax/index_data.php @@ -17,13 +17,19 @@ if (!$mode = (string)$this->request['mode']) { $this->ajax_die('invalid mode (empty)'); } +$datastore->enqueue([ + 'stats', + 'moderators', + 'cat_forums' +]); + $html = ''; switch ($mode) { case 'birthday_week': - $stats = $datastore->get('stats'); - $datastore->enqueue([ - 'stats' - ]); + if (!$stats = $datastore->get('stats') and !$datastore->has('stats')) { + $datastore->update('stats'); + $stats = $datastore->get('stats'); + } $users = []; @@ -38,10 +44,10 @@ switch ($mode) { break; case 'birthday_today': - $stats = $datastore->get('stats'); - $datastore->enqueue([ - 'stats' - ]); + if (!$stats = $datastore->get('stats') and !$datastore->has('stats')) { + $datastore->update('stats'); + $stats = $datastore->get('stats'); + } $users = []; @@ -58,13 +64,12 @@ switch ($mode) { case 'get_forum_mods': $forum_id = (int)$this->request['forum_id']; - $datastore->enqueue([ - 'moderators', - 'cat_forums' - ]); + if (!$mod = $datastore->get('moderators') and !$datastore->has('moderators')) { + $datastore->update('moderators'); + $mod = $datastore->get('moderators'); + } $moderators = []; - $mod = $datastore->get('moderators'); if (isset($mod['mod_users'][$forum_id])) { foreach ($mod['mod_users'][$forum_id] as $user_id) { diff --git a/library/includes/bbcode.php b/library/includes/bbcode.php index 06a8fd809..1a592a022 100644 --- a/library/includes/bbcode.php +++ b/library/includes/bbcode.php @@ -116,7 +116,10 @@ function generate_smilies($mode) $user->session_start(); } - $data = $datastore->get('smile_replacements'); + if (!$data = $datastore->get('smile_replacements') and !$datastore->has('smile_replacements')) { + $datastore->update('smile_replacements'); + $data = $datastore->get('smile_replacements'); + } if ($sql = $data['smile']) { $num_smilies = 0; diff --git a/library/includes/functions.php b/library/includes/functions.php index 6cfc6b561..a916f408c 100644 --- a/library/includes/functions.php +++ b/library/includes/functions.php @@ -296,7 +296,7 @@ function auth($type, $forum_id, $ug_data, array $f_access = [], $group_perm = UG // If f_access has been passed, or auth is needed to return an array of forums // then we need to pull the auth information on the given forum (or all forums) if (empty($f_access)) { - if (!$forums = $datastore->get('cat_forums')) { + if (!$forums = $datastore->get('cat_forums') and !$datastore->has('cat_forums')) { $datastore->update('cat_forums'); $forums = $datastore->get('cat_forums'); } @@ -997,7 +997,7 @@ function make_jumpbox(): void return; } - if (!$jumpbox = $datastore->get('jumpbox')) { + if (!$jumpbox = $datastore->get('jumpbox') and !$datastore->has('jumpbox')) { $datastore->update('jumpbox'); $jumpbox = $datastore->get('jumpbox'); } @@ -1018,7 +1018,7 @@ function get_forum_select($mode = 'guest', $name = POST_FORUM_URL, $selected = n $max_length = HTML_SELECT_MAX_LENGTH; } $select = null === $all_forums_option ? [] : [$lang['ALL_AVAILABLE'] => $all_forums_option]; - if (!$forums = $datastore->get('cat_forums')) { + if (!$forums = $datastore->get('cat_forums') and !$datastore->has('cat_forums')) { $datastore->update('cat_forums'); $forums = $datastore->get('cat_forums'); } @@ -1893,7 +1893,7 @@ function profile_url(array $data, bool $target_blank = false, bool $no_link = fa { global $bb_cfg, $lang, $datastore; - if (!$ranks = $datastore->get('ranks')) { + if (!$ranks = $datastore->get('ranks') and !$datastore->has('ranks')) { $datastore->update('ranks'); $ranks = $datastore->get('ranks'); } @@ -2129,7 +2129,7 @@ function getBanInfo(int $userId = null): ?array global $datastore; // Get bans info from datastore - if (!$bans = $datastore->get('ban_list')) { + if (!$bans = $datastore->get('ban_list') and !$datastore->has('ban_list')) { $datastore->update('ban_list'); $bans = $datastore->get('ban_list'); } diff --git a/library/includes/ucp/viewprofile.php b/library/includes/ucp/viewprofile.php index ffe1fea0d..f3c0a1566 100644 --- a/library/includes/ucp/viewprofile.php +++ b/library/includes/ucp/viewprofile.php @@ -30,7 +30,7 @@ if (!$profiledata = get_userdata($_GET[POST_USERS_URL], profile_view: true)) { bb_die($lang['NO_USER_ID_SPECIFIED']); } -if (!$ranks = $datastore->get('ranks')) { +if (!$ranks = $datastore->get('ranks') and !$datastore->has('ranks')) { $datastore->update('ranks'); $ranks = $datastore->get('ranks'); } diff --git a/search.php b/search.php index 9dbea3532..029c3a622 100644 --- a/search.php +++ b/search.php @@ -104,7 +104,7 @@ $tracker_tbl = BB_BT_TRACKER . ' tr'; $users_tbl = BB_USERS . ' u'; // Cat/forum data -if (!$forums = $datastore->get('cat_forums')) { +if (!$forums = $datastore->get('cat_forums') and !$datastore->has('cat_forums')) { $datastore->update('cat_forums'); $forums = $datastore->get('cat_forums'); } diff --git a/src/Censor.php b/src/Censor.php index 676efcfd9..940337115 100644 --- a/src/Censor.php +++ b/src/Censor.php @@ -41,15 +41,11 @@ class Censor } // Get censored words - if (!$censoredWords = $datastore->get('censor')) { + if (!$censoredWords = $datastore->get('censor') and !$datastore->has('censor')) { $datastore->update('censor'); $censoredWords = $datastore->get('censor'); } - if (isset($censoredWords['no_words'])) { - return; - } - foreach ($censoredWords as $word) { $this->words[] = '#(?replacements[] = $word['replacement']; diff --git a/src/Legacy/BBCode.php b/src/Legacy/BBCode.php index 9f23d34cd..651a1703a 100644 --- a/src/Legacy/BBCode.php +++ b/src/Legacy/BBCode.php @@ -350,7 +350,10 @@ class BBCode global $datastore; if (null === $this->smilies) { - $this->smilies = $datastore->get('smile_replacements'); + if (!$this->smilies = $datastore->get('smile_replacements') and !$datastore->has('smile_replacements')) { + $datastore->update('smile_replacements'); + $this->smilies = $datastore->get('smile_replacements'); + } } if ($this->smilies) { diff --git a/src/Legacy/Common/User.php b/src/Legacy/Common/User.php index bdac28dd1..cb085a6a3 100644 --- a/src/Legacy/Common/User.php +++ b/src/Legacy/Common/User.php @@ -688,7 +688,7 @@ class User return ''; } - if (!$forums = $datastore->get('cat_forums')) { + if (!$forums = $datastore->get('cat_forums') and !$datastore->has('cat_forums')) { $datastore->update('cat_forums'); $forums = $datastore->get('cat_forums'); } @@ -751,7 +751,7 @@ class User if (bf($this->opt, 'user_opt', 'user_porn_forums')) { global $datastore; - if (!$forums = $datastore->get('cat_forums')) { + if (!$forums = $datastore->get('cat_forums') and !$datastore->has('cat_forums')) { $datastore->update('cat_forums'); $forums = $datastore->get('cat_forums'); } diff --git a/src/Legacy/Datastore/Common.php b/src/Legacy/Datastore/Common.php index 3ee9a4216..139ee15d7 100644 --- a/src/Legacy/Datastore/Common.php +++ b/src/Legacy/Datastore/Common.php @@ -77,6 +77,15 @@ class Common return $this->data[$title]; } + /** + * @param $title + * @return bool + */ + public function has($title): bool + { + return isset($this->data[$title]); + } + public function store($item_name, $item_data) { } diff --git a/src/Sitemap.php b/src/Sitemap.php index 271d3455d..7b7e7906d 100644 --- a/src/Sitemap.php +++ b/src/Sitemap.php @@ -31,7 +31,7 @@ class Sitemap $forumUrls = []; - if (!$forums = $datastore->get('cat_forums')) { + if (!$forums = $datastore->get('cat_forums') and !$datastore->has('cat_forums')) { $datastore->update('cat_forums'); $forums = $datastore->get('cat_forums'); } @@ -61,7 +61,7 @@ class Sitemap $topicUrls = []; - if (!$forums = $datastore->get('cat_forums')) { + if (!$forums = $datastore->get('cat_forums') and !$datastore->has('cat_forums')) { $datastore->update('cat_forums'); $forums = $datastore->get('cat_forums'); } diff --git a/tracker.php b/tracker.php index c9fa4494e..20bb1186e 100644 --- a/tracker.php +++ b/tracker.php @@ -333,7 +333,7 @@ if ($search_id) { } // Get allowed for searching forums list -if (!$forums = $datastore->get('cat_forums')) { +if (!$forums = $datastore->get('cat_forums') and !$datastore->has('cat_forums')) { $datastore->update('cat_forums'); $forums = $datastore->get('cat_forums'); } diff --git a/viewforum.php b/viewforum.php index a1b2c3689..12dd54e10 100644 --- a/viewforum.php +++ b/viewforum.php @@ -43,7 +43,7 @@ define('REQUESTED_PAGE', $req_page); caching_output(IS_GUEST, 'send', REQUESTED_PAGE . '_guest'); set_die_append_msg(); -if (!$forums = $datastore->get('cat_forums')) { +if (!$forums = $datastore->get('cat_forums') and !$datastore->has('cat_forums')) { $datastore->update('cat_forums'); $forums = $datastore->get('cat_forums'); } @@ -118,7 +118,7 @@ if ($mark_read && !IS_GUEST) { // Subforums $show_subforums = $bb_cfg['sf_on_first_page_only'] ? !$start : true; -if (!$forums = $datastore->get('cat_forums')) { +if (!$forums = $datastore->get('cat_forums') and !$datastore->has('cat_forums')) { $datastore->update('cat_forums'); $forums = $datastore->get('cat_forums'); } diff --git a/viewtopic.php b/viewtopic.php index e89557395..8e5a7cd8d 100644 --- a/viewtopic.php +++ b/viewtopic.php @@ -195,7 +195,7 @@ if ($is_auth['auth_mod']) { if ($moderation) { if (IS_ADMIN) { - if (!$forum_select = $datastore->get('viewtopic_forum_select')) { + if (!$forum_select = $datastore->get('viewtopic_forum_select') and !$datastore->has('viewtopic_forum_select')) { $datastore->update('viewtopic_forum_select'); $forum_select = $datastore->get('viewtopic_forum_select'); } @@ -207,7 +207,7 @@ if ($moderation) { $template->assign_vars(['S_FORUM_SELECT' => $forum_select_html]); } -if (!$forums = $datastore->get('cat_forums')) { +if (!$forums = $datastore->get('cat_forums') and !$datastore->has('cat_forums')) { $datastore->update('cat_forums'); $forums = $datastore->get('cat_forums'); } @@ -353,7 +353,7 @@ if ($postrow = DB()->fetch_rowset($sql)) { bb_die($lang['NO_POSTS_TOPIC']); } -if (!$ranks = $datastore->get('ranks')) { +if (!$ranks = $datastore->get('ranks') and !$datastore->has('ranks')) { $datastore->update('ranks'); $ranks = $datastore->get('ranks'); }