refactor: replace $bb_cfg with config() in various legacy files

- Updated multiple legacy files to utilize the new Config class for configuration access.
- Replaced instances of $bb_cfg with config()->get() for improved maintainability and consistency.
- Ensured backward compatibility while transitioning to the new configuration system.

Files modified:
- sidebar2.html
- BBCode.php
- LogAction.php
- Post.php
- Template.php
- Torrent.php
- Common/User.php
- Common/Select.php
- Common/Upload.php
- Admin/Common.php
- tpl_config.php
This commit is contained in:
Yury Pikhtarev 2025-06-18 00:30:42 +04:00
commit 0c6deb2369
No known key found for this signature in database
11 changed files with 61 additions and 69 deletions

View file

@ -7,5 +7,5 @@
<li>style/templates/default/page_footer.tpl</li>
</ul>
<br />
To disable this sidebar, set the variable $bb_cfg['page']['show_sidebar2'] in file config.php to false.
To disable this sidebar, set the variable page.show_sidebar2 in file config.php to false.
</div>

View file

@ -217,7 +217,7 @@ class Common
*/
public static function topic_delete($mode_or_topic_id, $forum_id = null, $prune_time = 0, $prune_all = false)
{
global $bb_cfg, $lang, $log_action;
global $lang, $log_action;
$topic_csv = [];
$prune = ($mode_or_topic_id === 'prune');
@ -348,7 +348,7 @@ class Common
@unlink("$attach_dir/" . THUMB_DIR . '/t_' . $filename);
}
// TorrServer integration
if ($bb_cfg['torr_server']['enabled']) {
if (config()->get('torr_server.enabled')) {
$torrServer = new \TorrentPier\TorrServerAPI();
$torrServer->removeM3U($row['attach_id']);
}
@ -699,7 +699,7 @@ class Common
*/
public static function user_delete($user_id, $delete_posts = false)
{
global $bb_cfg, $log_action;
global $log_action;
if (!$user_csv = get_id_csv($user_id)) {
return false;
@ -779,7 +779,7 @@ class Common
// Delete user feed
foreach (explode(',', $user_csv) as $user_id) {
$file_path = $bb_cfg['atom']['path'] . '/u/' . floor($user_id / 5000) . '/' . ($user_id % 100) . '/' . $user_id . '.atom';
$file_path = config()->get('atom.path') . '/u/' . floor($user_id / 5000) . '/' . ($user_id % 100) . '/' . $user_id . '.atom';
@unlink($file_path);
}
}

View file

@ -157,15 +157,13 @@ class BBCode
*/
public function bbcode2html(string $text): string
{
global $bb_cfg;
$text = self::clean_up($text);
$text = $this->parse($text);
$text = $this->make_clickable($text);
$text = $this->smilies_pass($text);
$text = $this->new_line2html($text);
if ($bb_cfg['tidy_post']) {
if (config()->get('tidy_post')) {
$text = $this->tidy($text);
}
@ -395,9 +393,7 @@ class BBCode
*/
private function nofollow_url(string $href, string $name): string
{
global $bb_cfg;
if (\in_array(parse_url($href, PHP_URL_HOST), $bb_cfg['nofollow']['allowed_url']) || $bb_cfg['nofollow']['disabled']) {
if (\in_array(parse_url($href, PHP_URL_HOST), config()->get('nofollow.allowed_url')) || config()->get('nofollow.disabled')) {
$link = "<a href=\"$href\" class=\"postLink\">$name</a>";
} else {
$link = "<a href=\"$href\" class=\"postLink\" rel=\"nofollow\">$name</a>";

View file

@ -25,11 +25,9 @@ class Select
*/
public static function language(string $default_lang, string $select_name = 'language'): mixed
{
global $bb_cfg;
$lang_select = '<select name="' . $select_name . '">';
$x = 0;
foreach ($bb_cfg['lang'] as $key => $data) {
foreach (config()->get('lang') as $key => $data) {
$selected = '';
if ($key == $default_lang) {
$selected = ' selected';
@ -38,7 +36,8 @@ class Select
$x++;
}
$lang_select .= '</select>';
return ($x > 1) ? $lang_select : reset($bb_cfg['lang']);
$languages = config()->get('lang');
return ($x > 1) ? $lang_select : reset($languages);
}
/**
@ -77,11 +76,9 @@ class Select
*/
public static function template(string $default_style, string $select_name = 'tpl_name'): mixed
{
global $bb_cfg;
$templates_select = '<select name="' . $select_name . '">';
$x = 0;
foreach ($bb_cfg['templates'] as $folder => $name) {
foreach (config()->get('templates') as $folder => $name) {
$selected = '';
if ($folder == $default_style) {
$selected = ' selected';
@ -90,6 +87,7 @@ class Select
$x++;
}
$templates_select .= '</select>';
return ($x > 1) ? $templates_select : reset($bb_cfg['templates']);
$templates = config()->get('templates');
return ($x > 1) ? $templates_select : reset($templates);
}
}

View file

@ -103,7 +103,7 @@ class Upload
*/
public function init(array $cfg = [], array $post_params = [], bool $uploaded_only = true): bool
{
global $bb_cfg, $lang;
global $lang;
$this->cfg = array_merge($this->cfg, $cfg);
$this->file = $post_params;
@ -150,7 +150,7 @@ class Upload
$file_name_ary = explode('.', $this->file['name']);
$this->file_ext = strtolower(end($file_name_ary));
$this->ext_ids = array_flip($bb_cfg['file_id_ext']);
$this->ext_ids = array_flip(config()->get('file_id_ext'));
// Actions for images [E.g. Change avatar]
if ($this->cfg['max_width'] || $this->cfg['max_height']) {

View file

@ -243,8 +243,6 @@ class User
*/
public function session_create(array $userdata, bool $auto_created = false): array
{
global $bb_cfg;
$this->data = $userdata;
$session_id = $this->sessiondata['sid'];
@ -281,8 +279,8 @@ class User
if (!$session_time = $this->data['user_session_time']) {
$last_visit = TIMENOW;
define('FIRST_LOGON', true);
} elseif ($session_time < (TIMENOW - $bb_cfg['last_visit_update_intrv'])) {
$last_visit = max($session_time, (TIMENOW - 86400 * $bb_cfg['max_last_visit_days']));
} elseif ($session_time < (TIMENOW - config()->get('last_visit_update_intrv'))) {
$last_visit = max($session_time, (TIMENOW - 86400 * config()->get('max_last_visit_days')));
}
if ($last_visit != $this->data['user_lastvisit']) {
@ -463,7 +461,6 @@ class User
*/
public function set_session_cookies($user_id)
{
global $bb_cfg;
$debug_cookies = [
COOKIE_DBG,

View file

@ -44,7 +44,7 @@ class LogAction
*/
public function init()
{
global $lang, $bb_cfg;
global $lang;
foreach ($lang['LOG_ACTION']['LOG_TYPE'] as $log_type => $log_desc) {
$this->log_type_select[strip_tags($log_desc)] = $this->log_type[$log_type];

View file

@ -31,7 +31,7 @@ class Post
*/
public static function prepare_post(&$mode, &$post_data, &$error_msg, &$username, &$subject, &$message)
{
global $bb_cfg, $user, $userdata, $lang;
global $user, $userdata, $lang;
// Check username
if (!empty($username)) {
@ -60,15 +60,15 @@ class Post
}
// Check smilies limit
if ($bb_cfg['max_smilies']) {
$count_smilies = substr_count(bbcode2html($message), '<img class="smile" src="' . $bb_cfg['smilies_path']);
if ($count_smilies > $bb_cfg['max_smilies']) {
$to_many_smilies = sprintf($lang['MAX_SMILIES_PER_POST'], $bb_cfg['max_smilies']);
if (config()->get('max_smilies')) {
$count_smilies = substr_count(bbcode2html($message), '<img class="smile" src="' . config()->get('smilies_path'));
if ($count_smilies > config()->get('max_smilies')) {
$to_many_smilies = sprintf($lang['MAX_SMILIES_PER_POST'], config()->get('max_smilies'));
$error_msg .= (!empty($error_msg)) ? '<br />' . $to_many_smilies : $to_many_smilies;
}
}
if (IS_GUEST && !$bb_cfg['captcha']['disabled'] && !bb_captcha('check')) {
if (IS_GUEST && !config()->get('captcha.disabled') && !bb_captcha('check')) {
$error_msg .= (!empty($error_msg)) ? '<br />' . $lang['CAPTCHA_WRONG'] : $lang['CAPTCHA_WRONG'];
}
}
@ -96,7 +96,7 @@ class Post
*/
public static function submit_post($mode, &$post_data, &$message, &$meta, &$forum_id, &$topic_id, &$post_id, &$topic_type, $post_username, $post_subject, $post_message, $update_post_time, $poster_rg_id, $attach_rg_sig, $robots_indexing)
{
global $userdata, $post_info, $is_auth, $bb_cfg, $lang, $datastore;
global $userdata, $post_info, $is_auth, $lang, $datastore;
$current_time = TIMENOW;
@ -108,7 +108,7 @@ class Post
$sql = "SELECT MAX(p.post_time) AS last_post_time FROM " . BB_POSTS . " p WHERE $where_sql";
if ($row = DB()->fetch_row($sql) and $row['last_post_time']) {
if ($userdata['user_level'] == USER) {
if ((TIMENOW - $row['last_post_time']) < $bb_cfg['flood_interval']) {
if ((TIMENOW - $row['last_post_time']) < config()->get('flood_interval')) {
bb_die($lang['FLOOD_ERROR']);
}
}
@ -200,9 +200,9 @@ class Post
update_post_html(['post_id' => $post_id, 'post_text' => $post_message]);
// Updating news cache on index page
if ($bb_cfg['show_latest_news']) {
$news_forums = array_flip(explode(',', $bb_cfg['latest_news_forum_id']));
if (isset($news_forums[$forum_id]) && $bb_cfg['show_latest_news'] && $mode == 'newtopic') {
if (config()->get('show_latest_news')) {
$news_forums = array_flip(explode(',', config()->get('latest_news_forum_id')));
if (isset($news_forums[$forum_id]) && config()->get('show_latest_news') && $mode == 'newtopic') {
$datastore->enqueue([
'latest_news'
]);
@ -210,9 +210,9 @@ class Post
}
}
if ($bb_cfg['show_network_news']) {
$net_forums = array_flip(explode(',', $bb_cfg['network_news_forum_id']));
if (isset($net_forums[$forum_id]) && $bb_cfg['show_network_news'] && $mode == 'newtopic') {
if (config()->get('show_network_news')) {
$net_forums = array_flip(explode(',', config()->get('network_news_forum_id')));
if (isset($net_forums[$forum_id]) && config()->get('show_network_news') && $mode == 'newtopic') {
$datastore->enqueue([
'network_news'
]);
@ -341,9 +341,9 @@ class Post
*/
public static function user_notification($mode, &$post_data, &$topic_title, &$forum_id, &$topic_id, &$notify_user)
{
global $bb_cfg, $lang, $userdata, $wordCensor;
global $lang, $userdata, $wordCensor;
if (!$bb_cfg['topic_notify_enabled']) {
if (!config()->get('topic_notify_enabled')) {
return;
}
@ -378,7 +378,7 @@ class Post
$emailer->set_template('topic_notify', $row['user_lang']);
$emailer->assign_vars([
'TOPIC_TITLE' => html_entity_decode($topic_title),
'SITENAME' => $bb_cfg['sitename'],
'SITENAME' => config()->get('sitename'),
'USERNAME' => $row['username'],
'U_TOPIC' => $u_topic,
'U_STOP_WATCHING_TOPIC' => $unwatch_topic,
@ -500,7 +500,7 @@ class Post
*/
public static function topic_review($topic_id)
{
global $bb_cfg, $template;
global $template;
// Fetch posts data
$review_posts = DB()->fetch_rowset("
@ -513,7 +513,7 @@ class Post
LEFT JOIN " . BB_POSTS_HTML . " h ON(h.post_id = p.post_id)
WHERE p.topic_id = " . (int)$topic_id . "
ORDER BY p.post_time DESC
LIMIT " . $bb_cfg['posts_per_page'] . "
LIMIT " . config()->get('posts_per_page') . "
");
// Topic posts block
@ -523,7 +523,7 @@ class Post
'POSTER' => profile_url($post),
'POSTER_NAME_JS' => addslashes($post['username']),
'POST_ID' => $post['post_id'],
'POST_DATE' => bb_date($post['post_time'], $bb_cfg['post_date_format']),
'POST_DATE' => bb_date($post['post_time'], config()->get('post_date_format')),
'IS_UNREAD' => is_unread($post['post_time'], $topic_id, $post['forum_id']),
'MESSAGE' => get_parsed_post($post),
]);

View file

@ -228,6 +228,7 @@ class Template
{
$this->cur_tpl = $filename;
// bb_cfg deprecated, but kept for compatibility with non-adapted themes
global $lang, $source_lang, $bb_cfg, $user;
$L =& $lang;

View file

@ -277,7 +277,7 @@ class Torrent
*/
public static function tracker_register($attach_id, $mode = '', $tor_status = TOR_NOT_APPROVED, $reg_time = TIMENOW)
{
global $bb_cfg, $lang, $reg_mode;
global $lang, $reg_mode;
$attach_id = (int)$attach_id;
$reg_mode = $mode;
@ -505,7 +505,7 @@ class Torrent
$attach_id = $attachment['attach_id'];
if (!$passkey_key = config()->get('passkey_key')) {
bb_die('Could not add passkey (wrong config $bb_cfg[\'passkey_key\'])');
bb_die('Could not add passkey (wrong config passkey_key)');
}
// Get $post_id & $poster_id

View file

@ -7,14 +7,14 @@
* @license https://github.com/torrentpier/torrentpier/blob/master/LICENSE MIT License
*/
global $bb_cfg, $page_cfg, $template, $images, $lang;
global $page_cfg, $template, $images, $lang;
$width = $height = [];
$template_name = basename(__DIR__);
$_img = BB_ROOT . 'styles/images/';
$_main = BB_ROOT . 'styles/' . basename(TEMPLATES_DIR) . '/' . $template_name . '/images/';
$_lang = $_main . 'lang/' . basename($bb_cfg['default_lang']) . '/';
$_lang = $_main . 'lang/' . basename(config()->get('default_lang')) . '/';
// post_buttons
$images['icon_code'] = $_lang . 'icon_code.gif';
@ -117,13 +117,13 @@ $images['progress_bar_full'] = $_main . 'progress_bar_full.gif';
$template->assign_vars([
'IMG' => $_main,
'TEXT_BUTTONS' => $bb_cfg['text_buttons'],
'POST_BTN_SPACER' => $bb_cfg['text_buttons'] ? '&nbsp;' : '',
'TEXT_BUTTONS' => config()->get('text_buttons'),
'POST_BTN_SPACER' => config()->get('text_buttons') ? '&nbsp;' : '',
'TOPIC_ATTACH_ICON' => '<img src="' . $_img . 'icon_clip.gif" alt="" />',
'OPEN_MENU_IMG_ALT' => '<img src="' . $_main . 'menu_open_1.gif" class="menu-alt1" alt="" />',
'TOPIC_LEFT_COL_SPACER_WITDH' => $bb_cfg['topic_left_column_witdh'] - 8, // 8px padding
'POST_IMG_WIDTH_DECR_JS' => $bb_cfg['topic_left_column_witdh'] + $bb_cfg['post_img_width_decr'],
'ATTACH_IMG_WIDTH_DECR_JS' => $bb_cfg['topic_left_column_witdh'] + $bb_cfg['attach_img_width_decr'],
'TOPIC_LEFT_COL_SPACER_WITDH' => config()->get('topic_left_column_witdh') - 8, // 8px padding
'POST_IMG_WIDTH_DECR_JS' => config()->get('topic_left_column_witdh') + config()->get('post_img_width_decr'),
'ATTACH_IMG_WIDTH_DECR_JS' => config()->get('topic_left_column_witdh') + config()->get('attach_img_width_decr'),
'FEED_IMG' => '<img src="' . $_main . 'feed.png" class="feed-small" alt="' . $lang['ATOM_FEED'] . '" />',
]);
@ -131,25 +131,25 @@ $template->assign_vars([
if (!empty($page_cfg['load_tpl_vars']) and $vars = array_flip($page_cfg['load_tpl_vars'])) {
if (isset($vars['post_buttons'])) {
$template->assign_vars([
'CODE_IMG' => $bb_cfg['text_buttons'] ? $lang['CODE_TOPIC_TXTB'] : '<img src="' . $images['icon_code'] . '" alt="' . $lang['CODE_TOPIC_TXTB'] . '" title="' . $lang['CODE'] . '" />',
'QUOTE_IMG' => $bb_cfg['text_buttons'] ? $lang['REPLY_WITH_QUOTE_TXTB'] : '<img src="' . $images['icon_quote'] . '" alt="' . $lang['REPLY_WITH_QUOTE_TXTB'] . '" title="' . $lang['REPLY_WITH_QUOTE'] . '" />',
'EDIT_POST_IMG' => $bb_cfg['text_buttons'] ? $lang['EDIT_DELETE_POST_TXTB'] : '<img src="' . $images['icon_edit'] . '" alt="' . $lang['EDIT_DELETE_POST_TXTB'] . '" title="' . $lang['EDIT_POST'] . '" />',
'DELETE_POST_IMG' => $bb_cfg['text_buttons'] ? $lang['DELETE_POST_TXTB'] : '<img src="' . $images['icon_delpost'] . '" alt="' . $lang['DELETE_POST_TXTB'] . '" title="' . $lang['DELETE_POST'] . '" />',
'IP_POST_IMG' => $bb_cfg['text_buttons'] ? $lang['VIEW_IP_TXTB'] : '<img src="' . $images['icon_ip'] . '" alt="' . $lang['VIEW_IP_TXTB'] . '" title="' . $lang['VIEW_IP'] . '" />',
'MOD_POST_IMG' => $bb_cfg['text_buttons'] ? $lang['MODERATE_POST_TXTB'] : '<img src="' . $images['icon_mod'] . '" alt="' . $lang['MODERATE_POST_TXTB'] . '" title="' . $lang['MODERATE_POST'] . '" />',
'MC_IMG' => $bb_cfg['text_buttons'] ? '[' . $lang['COMMENT'] . ']' : '<img src="' . $images['icon_mc'] . '" alt="[' . $lang['COMMENT'] . ']" title="' . $lang['COMMENT'] . '" />',
'POLL_IMG' => $bb_cfg['text_buttons'] ? $lang['TOPIC_POLL'] : '<img src="' . $images['icon_poll'] . '" alt="' . $lang['TOPIC_POLL'] . '" title="' . $lang['ADD_POLL'] . '" />',
'CODE_IMG' => config()->get('text_buttons') ? $lang['CODE_TOPIC_TXTB'] : '<img src="' . $images['icon_code'] . '" alt="' . $lang['CODE_TOPIC_TXTB'] . '" title="' . $lang['CODE'] . '" />',
'QUOTE_IMG' => config()->get('text_buttons') ? $lang['REPLY_WITH_QUOTE_TXTB'] : '<img src="' . $images['icon_quote'] . '" alt="' . $lang['REPLY_WITH_QUOTE_TXTB'] . '" title="' . $lang['REPLY_WITH_QUOTE'] . '" />',
'EDIT_POST_IMG' => config()->get('text_buttons') ? $lang['EDIT_DELETE_POST_TXTB'] : '<img src="' . $images['icon_edit'] . '" alt="' . $lang['EDIT_DELETE_POST_TXTB'] . '" title="' . $lang['EDIT_POST'] . '" />',
'DELETE_POST_IMG' => config()->get('text_buttons') ? $lang['DELETE_POST_TXTB'] : '<img src="' . $images['icon_delpost'] . '" alt="' . $lang['DELETE_POST_TXTB'] . '" title="' . $lang['DELETE_POST'] . '" />',
'IP_POST_IMG' => config()->get('text_buttons') ? $lang['VIEW_IP_TXTB'] : '<img src="' . $images['icon_ip'] . '" alt="' . $lang['VIEW_IP_TXTB'] . '" title="' . $lang['VIEW_IP'] . '" />',
'MOD_POST_IMG' => config()->get('text_buttons') ? $lang['MODERATE_POST_TXTB'] : '<img src="' . $images['icon_mod'] . '" alt="' . $lang['MODERATE_POST_TXTB'] . '" title="' . $lang['MODERATE_POST'] . '" />',
'MC_IMG' => config()->get('text_buttons') ? '[' . $lang['COMMENT'] . ']' : '<img src="' . $images['icon_mc'] . '" alt="[' . $lang['COMMENT'] . ']" title="' . $lang['COMMENT'] . '" />',
'POLL_IMG' => config()->get('text_buttons') ? $lang['TOPIC_POLL'] : '<img src="' . $images['icon_poll'] . '" alt="' . $lang['TOPIC_POLL'] . '" title="' . $lang['ADD_POLL'] . '" />',
'QUOTE_URL' => BB_ROOT . POSTING_URL . '?mode=quote&amp;' . POST_POST_URL . '=',
'EDIT_POST_URL' => BB_ROOT . POSTING_URL . '?mode=editpost&amp;' . POST_POST_URL . '=',
'DELETE_POST_URL' => BB_ROOT . POSTING_URL . '?mode=delete&amp;' . POST_POST_URL . '=',
'IP_POST_URL' => BB_ROOT . 'modcp.php?mode=ip&amp;' . POST_POST_URL . '=',
'PROFILE_IMG' => $bb_cfg['text_buttons'] ? $lang['READ_PROFILE_TXTB'] : '<img src="' . $images['icon_profile'] . '" alt="' . $lang['READ_PROFILE_TXTB'] . '" title="' . $lang['READ_PROFILE'] . '" />',
'PM_IMG' => $bb_cfg['text_buttons'] ? $lang['SEND_PM_TXTB'] : '<img src="' . $images['icon_pm'] . '" alt="' . $lang['SEND_PM_TXTB'] . '" title="' . $lang['SEND_PRIVATE_MESSAGE'] . '" />',
'EMAIL_IMG' => $bb_cfg['text_buttons'] ? $lang['SEND_EMAIL_TXTB'] : '<img src="' . $images['icon_email'] . '" alt="' . $lang['SEND_EMAIL_TXTB'] . '" title="' . $lang['SEND_EMAIL'] . '" />',
'WWW_IMG' => $bb_cfg['text_buttons'] ? $lang['VISIT_WEBSITE_TXTB'] : '<img src="' . $images['icon_www'] . '" alt="' . $lang['VISIT_WEBSITE_TXTB'] . '" title="' . $lang['VISIT_WEBSITE'] . '" />',
'ICQ_IMG' => $bb_cfg['text_buttons'] ? $lang['ICQ_TXTB'] : '<img src="' . $images['icon_icq'] . '" alt="' . $lang['ICQ_TXTB'] . '" title="' . $lang['ICQ'] . '" />',
'PROFILE_IMG' => config()->get('text_buttons') ? $lang['READ_PROFILE_TXTB'] : '<img src="' . $images['icon_profile'] . '" alt="' . $lang['READ_PROFILE_TXTB'] . '" title="' . $lang['READ_PROFILE'] . '" />',
'PM_IMG' => config()->get('text_buttons') ? $lang['SEND_PM_TXTB'] : '<img src="' . $images['icon_pm'] . '" alt="' . $lang['SEND_PM_TXTB'] . '" title="' . $lang['SEND_PRIVATE_MESSAGE'] . '" />',
'EMAIL_IMG' => config()->get('text_buttons') ? $lang['SEND_EMAIL_TXTB'] : '<img src="' . $images['icon_email'] . '" alt="' . $lang['SEND_EMAIL_TXTB'] . '" title="' . $lang['SEND_EMAIL'] . '" />',
'WWW_IMG' => config()->get('text_buttons') ? $lang['VISIT_WEBSITE_TXTB'] : '<img src="' . $images['icon_www'] . '" alt="' . $lang['VISIT_WEBSITE_TXTB'] . '" title="' . $lang['VISIT_WEBSITE'] . '" />',
'ICQ_IMG' => config()->get('text_buttons') ? $lang['ICQ_TXTB'] : '<img src="' . $images['icon_icq'] . '" alt="' . $lang['ICQ_TXTB'] . '" title="' . $lang['ICQ'] . '" />',
'EMAIL_URL' => BB_ROOT . 'profile.php?mode=email&amp;' . POST_USERS_URL . '=',
'FORUM_URL' => BB_ROOT . FORUM_URL,