refactor: replace $bb_cfg with config() in user control panel files

- Updated multiple user control panel 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:
- bonus.php
- email.php
- register.php
- sendpasswd.php
- topic_watch.php
- viewprofile.php
This commit is contained in:
Yury Pikhtarev 2025-06-17 23:58:28 +04:00
commit 85a67cbc60
6 changed files with 61 additions and 59 deletions

View file

@ -14,9 +14,9 @@ if (!defined('BB_ROOT')) {
$user_id = $userdata['user_id'];
$user_points = $userdata['user_points'];
if ($bb_cfg['seed_bonus_enabled'] && $bb_cfg['bonus_upload'] && $bb_cfg['bonus_upload_price']) {
$upload_row = unserialize($bb_cfg['bonus_upload']);
$price_row = unserialize($bb_cfg['bonus_upload_price']);
if (config()->get('seed_bonus_enabled') && config()->get('bonus_upload') && config()->get('bonus_upload_price')) {
$upload_row = unserialize(config()->get('bonus_upload'));
$price_row = unserialize(config()->get('bonus_upload_price'));
} else {
bb_die($lang['EXCHANGE_NOT']);
}

View file

@ -12,7 +12,7 @@ if (!defined('BB_ROOT')) {
}
// Is send through board enabled? No, return to index
if (!$bb_cfg['board_email_form']) {
if (!config()->get('board_email_form')) {
redirect('index.php');
}

View file

@ -16,7 +16,7 @@ array_deep($_POST, 'trim');
set_die_append_msg();
if (IS_ADMIN) {
$bb_cfg['reg_email_activation'] = false;
config()->set('reg_email_activation', false);
$new_user = (int)request_var('admin', '');
if ($new_user) {
@ -50,17 +50,17 @@ switch ($mode) {
if (!IS_ADMIN) {
// IP limit
if ($bb_cfg['unique_ip']) {
if (config()->get('unique_ip')) {
if ($users = DB()->fetch_row("SELECT user_id, username FROM " . BB_USERS . " WHERE user_reg_ip = '" . USER_IP . "' LIMIT 1")) {
bb_die(sprintf($lang['ALREADY_REG_IP'], '<a href="' . PROFILE_URL . $users['user_id'] . '"><b>' . $users['username'] . '</b></a>', $bb_cfg['tech_admin_email']));
bb_die(sprintf($lang['ALREADY_REG_IP'], '<a href="' . PROFILE_URL . $users['user_id'] . '"><b>' . $users['username'] . '</b></a>', config()->get('tech_admin_email')));
}
}
// Disabling registration
if ($bb_cfg['new_user_reg_disabled'] || ($bb_cfg['reg_email_activation'] && !$bb_cfg['emailer']['enabled'])) {
if (config()->get('new_user_reg_disabled') || (config()->get('reg_email_activation') && !config()->get('emailer.enabled'))) {
bb_die($lang['NEW_USER_REG_DISABLED']);
} // Time limit
elseif ($bb_cfg['new_user_reg_restricted']) {
if (in_array(date('G'), $bb_cfg['new_user_reg_interval'], true)) {
elseif (config()->get('new_user_reg_restricted')) {
if (in_array(date('G'), config()->get('new_user_reg_interval'), true)) {
bb_die($lang['REGISTERED_IN_TIME']);
}
}
@ -83,8 +83,8 @@ switch ($mode) {
'user_password' => '',
'user_email' => '',
'invite_code' => '',
'user_timezone' => $bb_cfg['board_timezone'],
'user_lang' => $bb_cfg['default_lang'],
'user_timezone' => config()->get('board_timezone'),
'user_lang' => config()->get('default_lang'),
'user_opt' => 0,
'avatar_ext_id' => 0
];
@ -101,13 +101,13 @@ switch ($mode) {
// field => can_edit
$profile_fields = [
'user_active' => IS_ADMIN,
'username' => (IS_ADMIN || $bb_cfg['allow_namechange']) && !IN_DEMO_MODE,
'username' => (IS_ADMIN || config()->get('allow_namechange')) && !IN_DEMO_MODE,
'user_password' => !IN_DEMO_MODE,
'user_email' => !IN_DEMO_MODE, // should be after user_password
'user_lang' => $bb_cfg['allow_change']['language'],
'user_gender' => $bb_cfg['gender'],
'user_birthday' => $bb_cfg['birthday_enabled'],
'user_timezone' => $bb_cfg['allow_change']['timezone'],
'user_lang' => config()->get('allow_change.language'),
'user_gender' => config()->get('gender'),
'user_birthday' => config()->get('birthday_enabled'),
'user_timezone' => config()->get('allow_change.timezone'),
'user_opt' => true,
'avatar_ext_id' => true,
'user_icq' => true,
@ -152,7 +152,7 @@ switch ($mode) {
}
// Captcha
$need_captcha = ($mode == 'register' && !IS_ADMIN && !$bb_cfg['captcha']['disabled']);
$need_captcha = ($mode == 'register' && !IS_ADMIN && !config()->get('captcha.disabled'));
if ($submit) {
if ($need_captcha && !bb_captcha('check')) {
@ -203,12 +203,13 @@ foreach ($profile_fields as $field => $can_edit) {
* Invite code (reg)
*/
case 'invite_code':
if ($bb_cfg['invites_system']['enabled']) {
if (config()->get('invites_system.enabled')) {
$invite_code = $_POST['invite_code'] ?? '';
if ($submit) {
if (isset($bb_cfg['invites_system']['codes'][$invite_code])) {
if ($bb_cfg['invites_system']['codes'][$invite_code] !== 'permanent') {
if (TIMENOW > strtotime($bb_cfg['invites_system']['codes'][$invite_code])) {
$inviteCodes = config()->get('invites_system.codes');
if (isset($inviteCodes[$invite_code])) {
if ($inviteCodes[$invite_code] !== 'permanent') {
if (TIMENOW > strtotime($inviteCodes[$invite_code])) {
$errors[] = $lang['INVITE_EXPIRED'];
}
}
@ -264,7 +265,7 @@ foreach ($profile_fields as $field => $can_edit) {
}
$db_data['user_email'] = $email;
} elseif ($email != $pr_data['user_email']) {
if ($bb_cfg['email_change_disabled'] && !$adm_edit && !IS_ADMIN) {
if (config()->get('email_change_disabled') && !$adm_edit && !IS_ADMIN) {
$errors[] = $lang['EMAIL_CHANGING_DISABLED'];
}
if (!$cur_pass_valid) {
@ -273,7 +274,7 @@ foreach ($profile_fields as $field => $can_edit) {
if (!$errors and $err = \TorrentPier\Validate::email($email)) {
$errors[] = $err;
}
if ($bb_cfg['reg_email_activation']) {
if (config()->get('reg_email_activation')) {
$pr_data['user_active'] = 0;
$db_data['user_active'] = 0;
}
@ -336,10 +337,10 @@ foreach ($profile_fields as $field => $can_edit) {
if (!empty($birthday_date['year'])) {
if (strtotime($user_birthday) >= TIMENOW) {
$errors[] = $lang['WRONG_BIRTHDAY_FORMAT'];
} elseif (bb_date(TIMENOW, 'Y', false) - $birthday_date['year'] > $bb_cfg['birthday_max_age']) {
$errors[] = sprintf($lang['BIRTHDAY_TO_HIGH'], $bb_cfg['birthday_max_age']);
} elseif (bb_date(TIMENOW, 'Y', false) - $birthday_date['year'] < $bb_cfg['birthday_min_age']) {
$errors[] = sprintf($lang['BIRTHDAY_TO_LOW'], $bb_cfg['birthday_min_age']);
} elseif (bb_date(TIMENOW, 'Y', false) - $birthday_date['year'] > config()->get('birthday_max_age')) {
$errors[] = sprintf($lang['BIRTHDAY_TO_HIGH'], config()->get('birthday_max_age'));
} elseif (bb_date(TIMENOW, 'Y', false) - $birthday_date['year'] < config()->get('birthday_min_age')) {
$errors[] = sprintf($lang['BIRTHDAY_TO_LOW'], config()->get('birthday_min_age'));
}
}
@ -357,16 +358,16 @@ foreach ($profile_fields as $field => $can_edit) {
$update_user_opt = [
# 'user_opt_name' => ($reg_mode) ? #reg_value : #in_login_change
'user_viewemail' => $reg_mode ? false : (IS_ADMIN || $bb_cfg['show_email_visibility_settings']),
'user_viewemail' => $reg_mode ? false : (IS_ADMIN || config()->get('show_email_visibility_settings')),
'user_viewonline' => $reg_mode ? false : true,
'user_notify' => $reg_mode ? true : true,
'user_notify_pm' => $reg_mode ? true : $bb_cfg['pm_notify_enabled'],
'user_notify_pm' => $reg_mode ? true : config()->get('pm_notify_enabled'),
'user_porn_forums' => $reg_mode ? false : true,
'user_dls' => $reg_mode ? false : true,
'user_callseed' => $reg_mode ? true : true,
'user_retracker' => $reg_mode ? true : true,
'user_hide_torrent_client' => $reg_mode ? true : true,
'user_hide_peer_country' => $reg_mode ? true : $bb_cfg['ip2country_settings']['enabled'],
'user_hide_peer_country' => $reg_mode ? true : config()->get('ip2country_settings.enabled'),
'user_hide_peer_username' => $reg_mode ? false : true,
];
@ -390,7 +391,7 @@ foreach ($profile_fields as $field => $can_edit) {
if ($submit && !bf($pr_data['user_opt'], 'user_opt', 'dis_avatar')) {
// Integration with MonsterID
if (empty($_FILES['avatar']['name']) && !isset($_POST['delete_avatar']) && isset($_POST['use_monster_avatar'])) {
$monsterAvatar = new Arokettu\MonsterID\Monster($pr_data['user_email'], $bb_cfg['avatars']['max_height']);
$monsterAvatar = new Arokettu\MonsterID\Monster($pr_data['user_email'], config()->get('avatars.max_height'));
$tempAvatar = tmpfile();
$tempAvatarPath = stream_get_meta_data($tempAvatar)['uri'];
$monsterAvatar->writeToStream($tempAvatar);
@ -412,10 +413,10 @@ foreach ($profile_fields as $field => $can_edit) {
delete_avatar($pr_data['user_id'], $pr_data['avatar_ext_id']);
$pr_data['avatar_ext_id'] = 0;
$db_data['avatar_ext_id'] = 0;
} elseif (!empty($_FILES['avatar']['name']) && $bb_cfg['avatars']['up_allowed']) {
} elseif (!empty($_FILES['avatar']['name']) && config()->get('avatars.up_allowed')) {
$upload = new TorrentPier\Legacy\Common\Upload();
if ($upload->init($bb_cfg['avatars'], $_FILES['avatar'], !isset($_POST['use_monster_avatar'])) and $upload->store('avatar', $pr_data)) {
if ($upload->init(config()->getSection('avatars'), $_FILES['avatar'], !isset($_POST['use_monster_avatar'])) and $upload->store('avatar', $pr_data)) {
$pr_data['avatar_ext_id'] = $upload->file_ext_id;
$db_data['avatar_ext_id'] = (int)$upload->file_ext_id;
} else {
@ -423,7 +424,7 @@ foreach ($profile_fields as $field => $can_edit) {
}
}
}
$tp_data['AVATARS_MAX_SIZE'] = humn_size($bb_cfg['avatars']['max_size']);
$tp_data['AVATARS_MAX_SIZE'] = humn_size(config()->get('avatars.max_size'));
break;
/**
@ -484,7 +485,7 @@ foreach ($profile_fields as $field => $can_edit) {
if ($submit && $sig != $pr_data['user_sig']) {
$sig = prepare_message($sig);
if (mb_strlen($sig, DEFAULT_CHARSET) > $bb_cfg['max_sig_chars']) {
if (mb_strlen($sig, DEFAULT_CHARSET) > config()->get('max_sig_chars')) {
$errors[] = $lang['SIGNATURE_TOO_LONG'];
} elseif (preg_match('#<(a|b|i|u|table|tr|td|img) #i', $sig) || preg_match('#(href|src|target|title)=#i', $sig)) {
$errors[] = $lang['SIGNATURE_ERROR_HTML'];
@ -559,9 +560,10 @@ foreach ($profile_fields as $field => $can_edit) {
$templates = isset($_POST['tpl_name']) ? (string)$_POST['tpl_name'] : $pr_data['tpl_name'];
$templates = htmlCHR($templates);
if ($submit && $templates != $pr_data['tpl_name']) {
$pr_data['tpl_name'] = $bb_cfg['tpl_name'];
$db_data['tpl_name'] = (string)$bb_cfg['tpl_name'];
foreach ($bb_cfg['templates'] as $folder => $name) {
$pr_data['tpl_name'] = config()->get('tpl_name');
$db_data['tpl_name'] = (string)config()->get('tpl_name');
$availableTemplates = config()->get('templates');
foreach ($availableTemplates as $folder => $name) {
if ($templates == $folder) {
$pr_data['tpl_name'] = $templates;
$db_data['tpl_name'] = (string)$templates;
@ -585,7 +587,7 @@ if ($submit && !$errors) {
* Создание нового профиля
*/
if ($mode == 'register') {
if ($bb_cfg['reg_email_activation']) {
if (config()->get('reg_email_activation')) {
$user_actkey = make_rand_str(ACTKEY_LENGTH);
$db_data['user_active'] = 0;
$db_data['user_actkey'] = $user_actkey;
@ -600,7 +602,7 @@ if ($submit && !$errors) {
}
if (!isset($db_data['tpl_name'])) {
$db_data['tpl_name'] = (string)$bb_cfg['tpl_name'];
$db_data['tpl_name'] = (string)config()->get('tpl_name');
}
$sql_args = DB()->build_array('INSERT', $db_data);
@ -622,13 +624,13 @@ if ($submit && !$errors) {
set_pr_die_append_msg($new_user_id);
$message = $lang['ACCOUNT_ADDED'];
} else {
if ($bb_cfg['reg_email_activation']) {
if (config()->get('reg_email_activation')) {
$message = $lang['ACCOUNT_INACTIVE'];
$email_subject = sprintf($lang['EMAILER_SUBJECT']['USER_WELCOME_INACTIVE'], $bb_cfg['sitename']);
$email_subject = sprintf($lang['EMAILER_SUBJECT']['USER_WELCOME_INACTIVE'], config()->get('sitename'));
$email_template = 'user_welcome_inactive';
} else {
$message = $lang['ACCOUNT_ADDED'];
$email_subject = sprintf($lang['EMAILER_SUBJECT']['USER_WELCOME'], $bb_cfg['sitename']);
$email_subject = sprintf($lang['EMAILER_SUBJECT']['USER_WELCOME'], config()->get('sitename'));
$email_template = 'user_welcome';
}
@ -640,7 +642,7 @@ if ($submit && !$errors) {
$emailer->set_template($email_template, $user_lang);
$emailer->assign_vars([
'WELCOME_MSG' => sprintf($lang['WELCOME_SUBJECT'], $bb_cfg['sitename']),
'WELCOME_MSG' => sprintf($lang['WELCOME_SUBJECT'], config()->get('sitename')),
'USERNAME' => html_entity_decode($username),
'PASSWORD' => $new_pass,
'U_ACTIVATE' => make_url('profile.php?mode=activate&' . POST_USERS_URL . '=' . $new_user_id . '&act_key=' . $db_data['user_actkey'])
@ -728,12 +730,12 @@ $template->assign_vars([
'LANGUAGE_SELECT' => \TorrentPier\Legacy\Common\Select::language($pr_data['user_lang'], 'user_lang'),
'TIMEZONE_SELECT' => \TorrentPier\Legacy\Common\Select::timezone($pr_data['user_timezone'], 'user_timezone'),
'AVATAR_EXPLAIN' => sprintf($lang['AVATAR_EXPLAIN'], $bb_cfg['avatars']['max_width'], $bb_cfg['avatars']['max_height'], humn_size($bb_cfg['avatars']['max_size'])),
'AVATAR_EXPLAIN' => sprintf($lang['AVATAR_EXPLAIN'], config()->get('avatars.max_width'), config()->get('avatars.max_height'), humn_size(config()->get('avatars.max_size'))),
'AVATAR_DISALLOWED' => bf($pr_data['user_opt'], 'user_opt', 'dis_avatar'),
'AVATAR_DIS_EXPLAIN' => sprintf($lang['AVATAR_DISABLE'], $bb_cfg['terms_and_conditions_url']),
'AVATAR_DIS_EXPLAIN' => sprintf($lang['AVATAR_DISABLE'], config()->get('terms_and_conditions_url')),
'AVATAR_IMG' => get_avatar($pr_data['user_id'], $pr_data['avatar_ext_id'], !bf($pr_data['user_opt'], 'user_opt', 'dis_avatar')),
'SIGNATURE_EXPLAIN' => sprintf($lang['SIGNATURE_EXPLAIN'], $bb_cfg['max_sig_chars']),
'SIGNATURE_EXPLAIN' => sprintf($lang['SIGNATURE_EXPLAIN'], config()->get('max_sig_chars')),
'SIG_DISALLOWED' => bf($pr_data['user_opt'], 'user_opt', 'dis_sig'),
'PR_USER_ID' => $pr_data['user_id'],

View file

@ -13,11 +13,11 @@ if (!defined('BB_ROOT')) {
set_die_append_msg();
if (!$bb_cfg['emailer']['enabled']) {
if (!config()->get('emailer.enabled')) {
bb_die($lang['EMAILER_DISABLED']);
}
$need_captcha = ($_GET['mode'] == 'sendpassword' && !IS_ADMIN && !$bb_cfg['captcha']['disabled']);
$need_captcha = ($_GET['mode'] == 'sendpassword' && !IS_ADMIN && !config()->get('captcha.disabled'));
if (isset($_POST['submit'])) {
if ($need_captcha && !bb_captcha('check')) {

View file

@ -11,7 +11,7 @@ if (!defined('BB_ROOT')) {
die(basename(__FILE__));
}
if (!$bb_cfg['topic_notify_enabled']) {
if (!config()->get('topic_notify_enabled')) {
bb_die($lang['DISABLED']);
}
@ -35,7 +35,7 @@ if (isset($_GET[POST_USERS_URL])) {
}
}
$start = isset($_GET['start']) ? abs((int)$_GET['start']) : 0;
$per_page = $bb_cfg['topics_per_page'];
$per_page = config()->get('topics_per_page');
if (isset($_POST['topic_id_list'])) {
$topic_ids = implode(",", $_POST['topic_id_list']);
@ -96,7 +96,7 @@ if ($watch_count > 0) {
'IS_UNREAD' => $is_unread,
'POLL' => (bool)$watch[$i]['topic_vote'],
'TOPIC_ICON' => get_topic_icon($watch[$i], $is_unread),
'PAGINATION' => ($watch[$i]['topic_status'] == TOPIC_MOVED) ? '' : build_topic_pagination(TOPIC_URL . $watch[$i]['topic_id'], $watch[$i]['topic_replies'], $bb_cfg['posts_per_page'])
'PAGINATION' => ($watch[$i]['topic_status'] == TOPIC_MOVED) ? '' : build_topic_pagination(TOPIC_URL . $watch[$i]['topic_id'], $watch[$i]['topic_replies'], config()->get('posts_per_page'))
]);
}

View file

@ -50,7 +50,7 @@ if (IS_ADMIN) {
}
if (bf($profiledata['user_opt'], 'user_opt', 'user_viewemail') || $profiledata['user_id'] == $userdata['user_id'] || IS_ADMIN) {
$email_uri = ($bb_cfg['board_email_form']) ? 'profile.php?mode=email&amp;' . POST_USERS_URL . '=' . $profiledata['user_id'] : 'mailto:' . $profiledata['user_email'];
$email_uri = (config()->get('board_email_form')) ? 'profile.php?mode=email&amp;' . POST_USERS_URL . '=' . $profiledata['user_id'] : 'mailto:' . $profiledata['user_email'];
$email = '<a class="editable" href="' . $email_uri . '">' . $profiledata['user_email'] . '</a>';
} else {
$email = '';
@ -62,7 +62,7 @@ if (bf($profiledata['user_opt'], 'user_opt', 'user_viewemail') || $profiledata['
$profile_user_id = ($profiledata['user_id'] == $userdata['user_id']);
$signature = ($bb_cfg['allow_sig'] && $profiledata['user_sig']) ? $profiledata['user_sig'] : '';
$signature = (config()->get('allow_sig') && $profiledata['user_sig']) ? $profiledata['user_sig'] : '';
if (bf($profiledata['user_opt'], 'user_opt', 'dis_sig')) {
if ($profile_user_id) {
@ -75,7 +75,7 @@ if (bf($profiledata['user_opt'], 'user_opt', 'dis_sig')) {
}
// Null ratio
if ($bb_cfg['ratio_null_enabled'] && $btu = get_bt_userdata($profiledata['user_id'])) {
if (config()->get('ratio_null_enabled') && $btu = get_bt_userdata($profiledata['user_id'])) {
$template->assign_vars(['NULLED_RATIO' => $btu['ratio_nulled']]);
}
@ -110,10 +110,10 @@ $template->assign_vars([
'SKYPE' => $profiledata['user_skype'],
'TWITTER' => $profiledata['user_twitter'],
'USER_POINTS' => $profiledata['user_points'],
'GENDER' => $bb_cfg['gender'] ? $lang['GENDER_SELECT'][$profiledata['user_gender']] : '',
'BIRTHDAY' => ($bb_cfg['birthday_enabled'] && !empty($profiledata['user_birthday']) && $profiledata['user_birthday'] != '1900-01-01') ? $profiledata['user_birthday'] : '',
'GENDER' => config()->get('gender') ? $lang['GENDER_SELECT'][$profiledata['user_gender']] : '',
'BIRTHDAY' => (config()->get('birthday_enabled') && !empty($profiledata['user_birthday']) && $profiledata['user_birthday'] != '1900-01-01') ? $profiledata['user_birthday'] : '',
'BIRTHDAY_ICON' => user_birthday_icon($profiledata['user_birthday'], $profiledata['user_id']),
'AGE' => ($bb_cfg['birthday_enabled'] && !empty($profiledata['user_birthday']) && $profiledata['user_birthday'] != '1900-01-01') ? birthday_age($profiledata['user_birthday']) : '',
'AGE' => (config()->get('birthday_enabled') && !empty($profiledata['user_birthday']) && $profiledata['user_birthday'] != '1900-01-01') ? birthday_age($profiledata['user_birthday']) : '',
'L_VIEWING_PROFILE' => sprintf($lang['VIEWING_USER_PROFILE'], $profiledata['username']),
'L_MY_PROFILE' => sprintf($lang['VIEWING_MY_PROFILE'], 'profile.php?mode=editprofile'),