diff --git a/phpBB/includes/acp/acp_attachments.php b/phpBB/includes/acp/acp_attachments.php index 3e7d5ab544..0d66dfde4f 100644 --- a/phpBB/includes/acp/acp_attachments.php +++ b/phpBB/includes/acp/acp_attachments.php @@ -180,12 +180,12 @@ class acp_attachments 'allow_pm_attach' => array('lang' => 'ALLOW_PM_ATTACHMENTS', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => false), 'max_attachments' => array('lang' => 'MAX_ATTACHMENTS', 'validate' => 'int:0:999', 'type' => 'number:0:999', 'explain' => false), 'max_attachments_pm' => array('lang' => 'MAX_ATTACHMENTS_PM', 'validate' => 'int:0:999', 'type' => 'number:0:999', 'explain' => false), - 'display_order' => array('lang' => 'DISPLAY_ORDER', 'validate' => 'bool', 'type' => 'radio', 'function' => 'build_radio', 'params' => ['{CONFIG_VALUE}', '{KEY}', ['DESCENDING', 'ASCENDING']], 'explain' => true), + 'display_order' => array('lang' => 'DISPLAY_ORDER', 'validate' => 'bool', 'type' => 'radio', 'function' => 'phpbb_build_radio', 'params' => ['{CONFIG_VALUE}', '{KEY}', ['DESCENDING', 'ASCENDING']], 'explain' => true), 'attachment_quota' => array('lang' => 'ATTACH_QUOTA', 'validate' => 'string', 'type' => 'custom', 'method' => 'max_filesize', 'explain' => true), 'max_filesize' => array('lang' => 'ATTACH_MAX_FILESIZE', 'validate' => 'string', 'type' => 'custom', 'method' => 'max_filesize', 'explain' => true), 'max_filesize_pm' => array('lang' => 'ATTACH_MAX_PM_FILESIZE','validate' => 'string', 'type' => 'custom', 'method' => 'max_filesize', 'explain' => true), 'secure_downloads' => array('lang' => 'SECURE_DOWNLOADS', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), - 'secure_allow_deny' => array('lang' => 'SECURE_ALLOW_DENY', 'validate' => 'int', 'type' => 'radio', 'function' => 'build_radio', 'params' => ['{CONFIG_VALUE}', '{KEY}', [1 => 'ORDER_ALLOW_DENY', 0 => 'ORDER_DENY_ALLOW']], 'explain' => true), + 'secure_allow_deny' => array('lang' => 'SECURE_ALLOW_DENY', 'validate' => 'int', 'type' => 'radio', 'function' => 'phpbb_build_radio', 'params' => ['{CONFIG_VALUE}', '{KEY}', [1 => 'ORDER_ALLOW_DENY', 0 => 'ORDER_DENY_ALLOW']], 'explain' => true), 'secure_allow_empty_referer' => array('lang' => 'SECURE_EMPTY_REFERRER', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), 'check_attachment_content' => array('lang' => 'CHECK_CONTENT', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), @@ -331,7 +331,7 @@ class acp_attachments $l_explain = (isset($user->lang[$vars['lang'] . '_EXPLAIN'])) ? $user->lang[$vars['lang'] . '_EXPLAIN'] : ''; } - $content = build_cfg_template($type, $config_key, $this->new_config, $config_key, $vars); + $content = phpbb_build_cfg_template($type, $config_key, $this->new_config, $config_key, $vars); if (empty($content)) { continue; diff --git a/phpBB/includes/acp/acp_board.php b/phpBB/includes/acp/acp_board.php index 5f1a7e736b..d5203514e1 100644 --- a/phpBB/includes/acp/acp_board.php +++ b/phpBB/includes/acp/acp_board.php @@ -86,8 +86,8 @@ class acp_board 'board_timezone' => array('lang' => 'SYSTEM_TIMEZONE', 'validate' => 'timezone', 'type' => 'custom', 'method' => 'timezone_select', 'explain' => true), 'legend2' => 'BOARD_STYLE', - 'default_style' => array('lang' => 'DEFAULT_STYLE', 'validate' => 'int', 'type' => 'select', 'method' => 'style_select', 'params' => array('{CONFIG_VALUE}', false), 'explain' => true), - 'guest_style' => array('lang' => 'GUEST_STYLE', 'validate' => 'int', 'type' => 'select', 'method' => 'style_select', 'params' => array($this->guest_style_get(), false), 'explain' => true), + 'default_style' => array('lang' => 'DEFAULT_STYLE', 'validate' => 'int', 'type' => 'select', 'method' => 'phpbb_style_select', 'params' => array('{CONFIG_VALUE}', false), 'explain' => true), + 'guest_style' => array('lang' => 'GUEST_STYLE', 'validate' => 'int', 'type' => 'select', 'method' => 'phpbb_style_select', 'params' => array($this->guest_style_get(), false), 'explain' => true), 'override_user_style' => array('lang' => 'OVERRIDE_STYLE', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), 'legend3' => 'WARNINGS', @@ -432,10 +432,10 @@ class acp_board 'allow_autologin' => array('lang' => 'ALLOW_AUTOLOGIN', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), 'allow_password_reset' => array('lang' => 'ALLOW_PASSWORD_RESET', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), 'max_autologin_time' => array('lang' => 'AUTOLOGIN_LENGTH', 'validate' => 'int:0:99999', 'type' => 'number:0:99999', 'explain' => true, 'append' => ' ' . $user->lang['DAYS']), - 'ip_check' => array('lang' => 'IP_VALID', 'validate' => 'int', 'type' => 'radio', 'function' => 'build_radio', 'params' => ['{CONFIG_VALUE}', '{KEY}', [4 => 'ALL', 3 => 'CLASS_C', 2 => 'CLASS_B', 0 => 'NO_IP_VALIDATION']], 'explain' => true), + 'ip_check' => array('lang' => 'IP_VALID', 'validate' => 'int', 'type' => 'radio', 'function' => 'phpbb_build_radio', 'params' => ['{CONFIG_VALUE}', '{KEY}', [4 => 'ALL', 3 => 'CLASS_C', 2 => 'CLASS_B', 0 => 'NO_IP_VALIDATION']], 'explain' => true), 'browser_check' => array('lang' => 'BROWSER_VALID', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), 'forwarded_for_check' => array('lang' => 'FORWARDED_FOR_VALID', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), - 'referer_validation' => array('lang' => 'REFERRER_VALID', 'validate' => 'int:0:3','type' => 'radio', 'function' => 'build_radio', 'params' => ['{CONFIG_VALUE}', '{KEY}', [REFERER_VALIDATE_PATH => 'REF_PATH', REFERER_VALIDATE_HOST => 'REF_HOST', REFERER_VALIDATE_NONE => 'NO_REF_VALIDATION']], 'explain' => true), + 'referer_validation' => array('lang' => 'REFERRER_VALID', 'validate' => 'int:0:3','type' => 'radio', 'function' => 'phpbb_build_radio', 'params' => ['{CONFIG_VALUE}', '{KEY}', [REFERER_VALIDATE_PATH => 'REF_PATH', REFERER_VALIDATE_HOST => 'REF_HOST', REFERER_VALIDATE_NONE => 'NO_REF_VALIDATION']], 'explain' => true), 'check_dnsbl' => array('lang' => 'CHECK_DNSBL', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), 'email_check_mx' => array('lang' => 'EMAIL_CHECK_MX', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), 'min_pass_chars' => array('lang' => 'PASSWORD_LENGTH', 'validate' => 'int:1', 'type' => 'custom', 'method' => 'password_length', 'explain' => true), @@ -798,7 +798,7 @@ class acp_board $l_explain = (isset($user->lang[$vars['lang'] . '_EXPLAIN'])) ? $user->lang[$vars['lang'] . '_EXPLAIN'] : ''; } - $content = build_cfg_template($type, $config_key, $this->new_config, $config_key, $vars); + $content = phpbb_build_cfg_template($type, $config_key, $this->new_config, $config_key, $vars); if (empty($content)) { @@ -1110,12 +1110,12 @@ class acp_board /** * Wrapper function for style_select() * - * @param string $default Style ID to be selected in the dropdown list - * @param bool $all Flag indicating if all styles data including inactive should be fetched + * @param int|string $default Style ID to be selected in the dropdown list + * @param bool $all Flag indicating if all styles data including inactive should be fetched * * @return array */ - public function style_select($default, $all): array + public function phpbb_style_select(int|string $default, bool $all): array { global $db; @@ -1127,7 +1127,7 @@ class acp_board */ function board_disable($value, $key) { - $options = build_radio($value, $key, [1 => 'YES', 0 => 'NO']); + $options = phpbb_build_radio($value, $key, [1 => 'YES', 0 => 'NO']); return [ array_merge(['tag' => 'radio'], $options), @@ -1178,7 +1178,7 @@ class acp_board { global $language; - $options = build_radio($value, $key, [1 => 'YES', 0 => 'NO']); + $options = phpbb_build_radio($value, $key, [1 => 'YES', 0 => 'NO']); return [ array_merge(['tag' => 'radio', 'append' => '

'], $options), @@ -1436,7 +1436,7 @@ class acp_board $value = ($mod_rewrite === false) ? 0 : $value; $message = $mod_rewrite === null ? 'MOD_REWRITE_INFORMATION_UNAVAILABLE' : ($mod_rewrite === false ? 'MOD_REWRITE_DISABLED' : false); - $options = build_radio($value, $key, [1 => 'YES', 0 => 'NO']); + $options = phpbb_build_radio($value, $key, [1 => 'YES', 0 => 'NO']); foreach ($options['buttons'] as $i => $button) { $options['buttons'][$i]['disabled'] = $message === 'MOD_REWRITE_DISABLED'; diff --git a/phpBB/includes/functions_acp.php b/phpBB/includes/functions_acp.php index 0e0c6c94d3..d2cc39aec8 100644 --- a/phpBB/includes/functions_acp.php +++ b/phpBB/includes/functions_acp.php @@ -208,14 +208,19 @@ function adm_back_link($u_action) } /** -* Build select field options in acp pages -*/ -function build_select($option_ary, $option_default = false): array + * Build select field options in acp pages + * + * @param array $options_ary Configuration options data + * @param int|string|bool $option_default Configuration option selected value + * + * @return array + */ +function build_select(array $options_ary, int|string|bool $option_default = false): array { global $language; $options = []; - foreach ($option_ary as $value => $title) + foreach ($options_ary as $value => $title) { $options[] = [ 'value' => $value, @@ -228,21 +233,28 @@ function build_select($option_ary, $option_default = false): array } /** -* Build radio fields in acp pages -*/ -function build_radio($value, $key, $options) + * Build radio fields in acp pages + * + * @param int|string $value Configuration option value + * @param string $key Configuration option key name + * @param array $options Configuration options data + * representing array of [values => language_keys] + * + * @return array + */ +function phpbb_build_radio(int|string $value, string $key, array $options): array { global $language; $buttons = []; - foreach ($options as $val => $option) + foreach ($options as $val => $title) { $buttons[] = [ 'type' => 'radio', 'value' => $val, 'name' => 'config[' . $key . ']', 'checked' => $val == $value, - 'label' => $language->lang($option), + 'label' => $language->lang($title), ]; } @@ -254,15 +266,15 @@ function build_radio($value, $key, $options) /** * Build configuration data arrays or templates for configuration settings * - * @param array $tpl_type Configuration setting type data - * @param string $key Configuration option name - * @param array $new_ary Updated configuration data - * @param string $config_key Configuration option name - * @param Array $vars Configuration setting data + * @param array $tpl_type Configuration setting type data + * @param string $key Configuration option name + * @param array|object $new_ary Updated configuration data + * @param string $config_key Configuration option name + * @param array $vars Configuration setting data * * @return array|string */ -function build_cfg_template($tpl_type, $key, &$new_ary, $config_key, $vars) +function phpbb_build_cfg_template(array $tpl_type, string $key, array|object &$new_ary, string $config_key, array $vars): array|string { global $language, $module, $phpbb_dispatcher; @@ -380,7 +392,7 @@ function build_cfg_template($tpl_type, $key, &$new_ary, $config_key, $vars) { $options = array_reverse(explode('_', strtoupper($tpl_type[1]))); krsort($options); - $tpl_type = array_merge ($tpl_type, build_radio($new_ary[$config_key], $config_key, $options)); + $tpl_type = array_merge ($tpl_type, phpbb_build_radio($new_ary[$config_key], $config_key, $options)); } } case 'button': diff --git a/phpBB/includes/ucp/ucp_prefs.php b/phpBB/includes/ucp/ucp_prefs.php index 103f647ab0..8c682cebc0 100644 --- a/phpBB/includes/ucp/ucp_prefs.php +++ b/phpBB/includes/ucp/ucp_prefs.php @@ -179,7 +179,7 @@ class ucp_prefs $lang_options = phpbb_language_select($db, $data['lang'], $lang_row); - $template->assign_vars(array( + $template->assign_vars([ 'ERROR' => (count($error)) ? implode('
', $error) : '', 'S_NOTIFY_EMAIL' => ($data['notifymethod'] == NOTIFY_EMAIL) ? true : false, @@ -215,9 +215,9 @@ class ucp_prefs 'name' => 'tz', 'options' => $timezone_select, ], - 'S_CAN_HIDE_ONLINE' => ($auth->acl_get('u_hideonline')) ? true : false, - 'S_SELECT_NOTIFY' => ($config['jab_enable'] && $user->data['user_jabber'] && @extension_loaded('xml')) ? true : false) - ); + 'S_CAN_HIDE_ONLINE' => (bool) $auth->acl_get('u_hideonline'), + 'S_SELECT_NOTIFY' => (bool) ($config['jab_enable'] && $user->data['user_jabber'] && @extension_loaded('xml')), + ]); break; diff --git a/tests/functional/fixtures/ext/foo/bar/acp/main_module.php b/tests/functional/fixtures/ext/foo/bar/acp/main_module.php index 147ca2df2b..ec9e8d0145 100644 --- a/tests/functional/fixtures/ext/foo/bar/acp/main_module.php +++ b/tests/functional/fixtures/ext/foo/bar/acp/main_module.php @@ -41,15 +41,15 @@ class main_module 'setting_0_height' => ['lang' => 'SETTING_0', 'validate' => 'int:0', 'type' => false, 'method' => false, 'explain' => false], 'setting_0' => ['lang' => 'SETTING_0', 'validate' => 'int:0:16', 'type' => 'dimension:0:999', 'explain' => true, 'append' => ' ' . $language->lang('PIXEL')], 'setting_1' => ['lang' => 'SETTING_1', 'validate' => 'bool', 'type' => 'custom', 'method' => 'submit_button', 'lang_explain' => 'CUSTOM_LANG_EXPLAIN', 'explain' => true], - 'setting_2' => ['lang' => 'SETTING_2', 'validate' => 'bool', 'type' => 'radio', 'function' => 'build_radio', 'params' => ['{CONFIG_VALUE}', '{KEY}', [1 => 'YES', 0 => 'NO']]], + 'setting_2' => ['lang' => 'SETTING_2', 'validate' => 'bool', 'type' => 'radio', 'function' => 'phpbb_build_radio', 'params' => ['{CONFIG_VALUE}', '{KEY}', [1 => 'YES', 0 => 'NO']]], 'setting_3' => ['lang' => 'SETTING_3', 'validate' => 'int:0:99999','type' => 'number:0:99999', 'explain' => true], 'setting_4' => ['lang' => 'SETTING_4', 'validate' => 'string', 'type' => 'select', 'method' => 'create_select', 'explain' => true], 'setting_5' => ['lang' => 'SETTING_5', 'validate' => 'string', 'type' => 'text:25:255', 'explain' => true], 'setting_6' => ['lang' => 'SETTING_6', 'validate' => 'string', 'type' => 'password:25:255', 'explain' => true], 'setting_7' => ['lang' => 'SETTING_7', 'validate' => 'email', 'type' => 'email:0:100', 'explain' => true], 'setting_8' => ['lang' => 'SETTING_8', 'validate' => 'string', 'type' => 'textarea:5:30', 'explain' => true], - 'setting_9' => ['lang' => 'SETTING_9', 'validate' => 'bool', 'type' => 'radio', 'function' => 'build_radio', 'params' => ['{CONFIG_VALUE}', '{KEY}', [1 => 'ENABLED', 0 => 'DISABLED']], 'explain' => true], - 'setting_10'=> ['lang' => 'SETTING_10', 'validate' => 'int', 'type' => 'radio', 'function' => 'build_radio', 'params' => ['{CONFIG_VALUE}', '{KEY}', [1 => 'LABEL_1', 3 => 'LABEL_3', 2 => 'LABEL_2']], 'explain' => true], + 'setting_9' => ['lang' => 'SETTING_9', 'validate' => 'bool', 'type' => 'radio', 'function' => 'phpbb_build_radio', 'params' => ['{CONFIG_VALUE}', '{KEY}', [1 => 'ENABLED', 0 => 'DISABLED']], 'explain' => true], + 'setting_10'=> ['lang' => 'SETTING_10', 'validate' => 'int', 'type' => 'radio', 'function' => 'phpbb_build_radio', 'params' => ['{CONFIG_VALUE}', '{KEY}', [1 => 'LABEL_1', 3 => 'LABEL_3', 2 => 'LABEL_2']], 'explain' => true], 'setting_11'=> ['lang' => 'SETTING_11', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true], 'setting_12'=> ['lang' => 'SETTING_12', 'validate' => 'bool', 'type' => 'radio:enabled_disabled', 'explain' => true], ] @@ -125,7 +125,7 @@ class main_module $l_explain = $language->lang($vars['lang_explain'] ?: $vars['lang'] . '_EXPLAIN'); } - $content = build_cfg_template($type, $config_key, $this->new_config, $config_key, $vars); + $content = phpbb_build_cfg_template($type, $config_key, $this->new_config, $config_key, $vars); if (empty($content)) { diff --git a/tests/functions_acp/build_cfg_template_test.php b/tests/functions_acp/build_cfg_template_test.php index 9c60cc716f..bdb2bb36e4 100644 --- a/tests/functions_acp/build_cfg_template_test.php +++ b/tests/functions_acp/build_cfg_template_test.php @@ -81,7 +81,7 @@ class phpbb_functions_acp_build_cfg_template_test extends phpbb_test_case $language = new phpbb_mock_lang(); $user->lang = $language; - $this->assertEquals($expected, build_cfg_template($tpl_type, $key, $new, $config_key, $vars)); + $this->assertEquals($expected, phpbb_build_cfg_template($tpl_type, $key, $new, $config_key, $vars)); } public function build_cfg_template_dimension_data() @@ -151,7 +151,7 @@ class phpbb_functions_acp_build_cfg_template_test extends phpbb_test_case $user = new phpbb_mock_user(); $user->lang = new phpbb_mock_lang(); - $this->assertEquals($expected, build_cfg_template($tpl_type, $key, $new, $config_key, $vars)); + $this->assertEquals($expected, phpbb_build_cfg_template($tpl_type, $key, $new, $config_key, $vars)); } public function build_cfg_template_number_data() @@ -219,7 +219,7 @@ class phpbb_functions_acp_build_cfg_template_test extends phpbb_test_case $user = new phpbb_mock_user(); $user->lang = new phpbb_mock_lang(); - $this->assertEquals($expected, build_cfg_template($tpl_type, $key, $new, $config_key, $vars)); + $this->assertEquals($expected, phpbb_build_cfg_template($tpl_type, $key, $new, $config_key, $vars)); } public function build_cfg_template_textarea_data() @@ -254,7 +254,7 @@ class phpbb_functions_acp_build_cfg_template_test extends phpbb_test_case $user = new phpbb_mock_user(); $user->lang = new phpbb_mock_lang(); - $this->assertEquals($expected, build_cfg_template($tpl_type, $key, $new, $config_key, $vars)); + $this->assertEquals($expected, phpbb_build_cfg_template($tpl_type, $key, $new, $config_key, $vars)); } public function build_cfg_template_radio_data() @@ -292,7 +292,7 @@ class phpbb_functions_acp_build_cfg_template_test extends phpbb_test_case 'key_name', ['config_key_name' => '0'], 'config_key_name', - ['function' => 'build_radio', 'params' => ['{CONFIG_VALUE}', '{KEY}', [1 => 'ENABLED', 0 => 'DISABLED']]], + ['function' => 'phpbb_build_radio', 'params' => ['{CONFIG_VALUE}', '{KEY}', [1 => 'ENABLED', 0 => 'DISABLED']]], [ 'tag' => 'radio', 'buttons' => [ @@ -346,7 +346,7 @@ class phpbb_functions_acp_build_cfg_template_test extends phpbb_test_case 'key_name', ['config_key_name' => '1'], 'config_key_name', - ['function' => 'build_radio', 'params' => ['{CONFIG_VALUE}', '{KEY}', [1 => 'ENABLED', 0 => 'DISABLED']]], + ['function' => 'phpbb_build_radio', 'params' => ['{CONFIG_VALUE}', '{KEY}', [1 => 'ENABLED', 0 => 'DISABLED']]], [ 'tag' => 'radio', 'buttons' => [ @@ -400,7 +400,7 @@ class phpbb_functions_acp_build_cfg_template_test extends phpbb_test_case 'key_name', ['config_key_name' => '0'], 'config_key_name', - ['function' => 'build_radio', 'params' => ['{CONFIG_VALUE}', '{KEY}', [1 => 'YES', 0 => 'NO']]], + ['function' => 'phpbb_build_radio', 'params' => ['{CONFIG_VALUE}', '{KEY}', [1 => 'YES', 0 => 'NO']]], [ 'tag' => 'radio', 'buttons' => [ @@ -454,7 +454,7 @@ class phpbb_functions_acp_build_cfg_template_test extends phpbb_test_case 'key_name', ['config_key_name' => '1'], 'config_key_name', - ['function' => 'build_radio', 'params' => ['{CONFIG_VALUE}', '{KEY}', [1 => 'YES', 0 => 'NO']]], + ['function' => 'phpbb_build_radio', 'params' => ['{CONFIG_VALUE}', '{KEY}', [1 => 'YES', 0 => 'NO']]], [ 'tag' => 'radio', 'buttons' => [ @@ -489,7 +489,7 @@ class phpbb_functions_acp_build_cfg_template_test extends phpbb_test_case $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); $language = new \phpbb_mock_lang(); - $this->assertEquals($expected, build_cfg_template($tpl_type, $key, $new, $config_key, $vars)); + $this->assertEquals($expected, phpbb_build_cfg_template($tpl_type, $key, $new, $config_key, $vars)); } public function build_cfg_template_append_data() @@ -525,7 +525,7 @@ class phpbb_functions_acp_build_cfg_template_test extends phpbb_test_case $user = new phpbb_mock_user(); $user->lang = new phpbb_mock_lang(); - $this->assertEquals($expected, build_cfg_template($tpl_type, $key, $new, $config_key, $vars)); + $this->assertEquals($expected, phpbb_build_cfg_template($tpl_type, $key, $new, $config_key, $vars)); } public function build_cfg_template_select_data() @@ -618,7 +618,7 @@ class phpbb_functions_acp_build_cfg_template_test extends phpbb_test_case $user->module = $this; $module = $user; - $this->assertEquals($expected, build_cfg_template($tpl_type, $key, $new, $config_key, $vars)); + $this->assertEquals($expected, phpbb_build_cfg_template($tpl_type, $key, $new, $config_key, $vars)); } public function select_helper()