mirror of
https://github.com/phpbb/phpbb.git
synced 2025-07-31 14:00:31 +02:00
[ticket/17100] Move build_cfg_template parts to HTML-less function
PHPBB3-17100
This commit is contained in:
@@ -243,13 +243,20 @@ function h_radio($name, $input_ary, $input_default = false, $id = false, $key =
|
||||
}
|
||||
|
||||
/**
|
||||
* Build configuration template for acp configuration pages
|
||||
*/
|
||||
function build_cfg_template($tpl_type, $key, &$new_ary, $config_key, $vars)
|
||||
* HTML-less version of build_cfg_template
|
||||
*
|
||||
* @param array $tpl_type Template type
|
||||
* @param string $key Config key
|
||||
* @param $new_ary
|
||||
* @param $config_key
|
||||
* @param $vars
|
||||
* @return array
|
||||
*/
|
||||
function phpbb_build_cfg_template(array $tpl_type, string $key, &$new_ary, $config_key, $vars): array
|
||||
{
|
||||
global $user, $module, $phpbb_dispatcher;
|
||||
global $language;
|
||||
|
||||
$tpl = '';
|
||||
$tpl = [];
|
||||
$name = 'config[' . $config_key . ']';
|
||||
|
||||
// Make sure there is no notice printed out for non-existent config options (we simply set them)
|
||||
@@ -266,6 +273,8 @@ function build_cfg_template($tpl_type, $key, &$new_ary, $config_key, $vars)
|
||||
// replace passwords with asterixes
|
||||
$new_ary[$config_key] = '********';
|
||||
}
|
||||
// no break
|
||||
|
||||
case 'text':
|
||||
case 'url':
|
||||
case 'email':
|
||||
@@ -276,7 +285,15 @@ function build_cfg_template($tpl_type, $key, &$new_ary, $config_key, $vars)
|
||||
$size = (int) $tpl_type[1];
|
||||
$maxlength = (int) $tpl_type[2];
|
||||
|
||||
$tpl = '<input id="' . $key . '" type="' . $tpl_type[0] . '"' . (($size) ? ' size="' . $size . '"' : '') . ' maxlength="' . (($maxlength) ? $maxlength : 255) . '" name="' . $name . '" value="' . $new_ary[$config_key] . '"' . (($tpl_type[0] === 'password') ? ' autocomplete="off"' : '') . ' />';
|
||||
$tpl = [
|
||||
'tag' => 'input',
|
||||
'id' => $key,
|
||||
'type' => $tpl_type[0],
|
||||
'name' => $name,
|
||||
'size' => $size ?: '',
|
||||
'maxlength' => $maxlength ?: 255,
|
||||
'value' => $new_ary[$config_key],
|
||||
];
|
||||
break;
|
||||
|
||||
case 'color':
|
||||
@@ -284,7 +301,13 @@ function build_cfg_template($tpl_type, $key, &$new_ary, $config_key, $vars)
|
||||
case 'datetime-local':
|
||||
case 'month':
|
||||
case 'week':
|
||||
$tpl = '<input id="' . $key . '" type="' . $tpl_type[0] . '" name="' . $name . '" value="' . $new_ary[$config_key] . '" />';
|
||||
$tpl = [
|
||||
'tag' => 'input',
|
||||
'id' => $key,
|
||||
'type' => $tpl_type[0],
|
||||
'name' => $name,
|
||||
'value' => $new_ary[$config_key],
|
||||
];
|
||||
break;
|
||||
|
||||
case 'date':
|
||||
@@ -294,34 +317,125 @@ function build_cfg_template($tpl_type, $key, &$new_ary, $config_key, $vars)
|
||||
$min = isset($tpl_type[1]) ? (int) $tpl_type[1] : false;
|
||||
$max = isset($tpl_type[2]) ? (int) $tpl_type[2] : false;
|
||||
|
||||
$tpl = '<input id="' . $key . '" type="' . $tpl_type[0] . '"' . (( $min !== false ) ? ' min="' . $min . '"' : '') . (( $max !== false ) ? ' max="' . $max . '"' : '') . ' name="' . $name . '" value="' . $new_ary[$config_key] . '" />';
|
||||
$tpl = [
|
||||
'tag' => 'input',
|
||||
'id' => $key,
|
||||
'type' => $tpl_type[0],
|
||||
'name' => $name,
|
||||
'min' => $min !== false ? $min : '',
|
||||
'max' => $max !== false ? $max : '',
|
||||
'value' => $new_ary[$config_key],
|
||||
];
|
||||
break;
|
||||
|
||||
case 'dimension':
|
||||
$min = isset($tpl_type[1]) ? (int) $tpl_type[1] : false;
|
||||
$max = isset($tpl_type[2]) ? (int) $tpl_type[2] : false;
|
||||
|
||||
$tpl = '<input id="' . $key . '" type="number"' . (( $min !== false ) ? ' min="' . $min . '"' : '') . (( $max !== false ) ? ' max="' . $max . '"' : '') . ' name="config[' . $config_key . '_width]" value="' . $new_ary[$config_key . '_width'] . '" /> x <input type="number"' . (( $min !== '' ) ? ' min="' . $min . '"' : '') . (( $max != '' ) ? ' max="' . $max . '"' : '') . ' name="config[' . $config_key . '_height]" value="' . $new_ary[$config_key . '_height'] . '" />';
|
||||
$tpl = [
|
||||
'tag' => 'dimension',
|
||||
'width' => [
|
||||
'id' => $key,
|
||||
'type' => 'number',
|
||||
'name' => 'config[' . $config_key . '_width]',
|
||||
'min' => $min !== false ? $min : '',
|
||||
'max' => $max !== false ? $max : '',
|
||||
'value' => $new_ary[$config_key . '_width'],
|
||||
],
|
||||
'height' => [
|
||||
'type' => 'number',
|
||||
'name' => 'config[' . $config_key . '_height]',
|
||||
'min' => $min !== false ? $min : '',
|
||||
'max' => $max !== false ? $max : '',
|
||||
'value' => $new_ary[$config_key . '_height'],
|
||||
],
|
||||
];
|
||||
break;
|
||||
|
||||
case 'textarea':
|
||||
$rows = (int) $tpl_type[1];
|
||||
$cols = (int) $tpl_type[2];
|
||||
|
||||
$tpl = '<textarea id="' . $key . '" name="' . $name . '" rows="' . $rows . '" cols="' . $cols . '">' . $new_ary[$config_key] . '</textarea>';
|
||||
$tpl = [
|
||||
'tag' => 'textarea',
|
||||
'id' => $key,
|
||||
'name' => $name,
|
||||
'rows' => (int) $tpl_type[1],
|
||||
'cols' => (int) $tpl_type[2],
|
||||
'content' => $new_ary[$config_key],
|
||||
];
|
||||
break;
|
||||
|
||||
case 'radio':
|
||||
$key_yes = ($new_ary[$config_key]) ? ' checked="checked"' : '';
|
||||
$key_no = (!$new_ary[$config_key]) ? ' checked="checked"' : '';
|
||||
|
||||
$tpl_type_cond = explode('_', $tpl_type[1]);
|
||||
$type_no = ($tpl_type_cond[0] == 'disabled' || $tpl_type_cond[0] == 'enabled') ? false : true;
|
||||
$type_no = !(($tpl_type_cond[0] == 'disabled' || $tpl_type_cond[0] == 'enabled'));
|
||||
|
||||
$tpl_no = '<label><input type="radio" name="' . $name . '" value="0"' . $key_no . ' class="radio" /> ' . (($type_no) ? $user->lang['NO'] : $user->lang['DISABLED']) . '</label>';
|
||||
$tpl_yes = '<label><input type="radio" id="' . $key . '" name="' . $name . '" value="1"' . $key_yes . ' class="radio" /> ' . (($type_no) ? $user->lang['YES'] : $user->lang['ENABLED']) . '</label>';
|
||||
$no_button = [
|
||||
'type' => 'radio',
|
||||
'name' => $name,
|
||||
'value' => 0,
|
||||
'checked' => !$new_ary[$config_key],
|
||||
'label' => $type_no ? $language->lang('NO') : $language->lang('DISABLED'),
|
||||
];
|
||||
|
||||
$tpl = ($tpl_type_cond[0] == 'yes' || $tpl_type_cond[0] == 'enabled') ? $tpl_yes . $tpl_no : $tpl_no . $tpl_yes;
|
||||
$yes_button = [
|
||||
'id' => $key,
|
||||
'type' => 'radio',
|
||||
'name' => $name,
|
||||
'value' => 1,
|
||||
'checked' => $new_ary[$config_key],
|
||||
'label' => $type_no ? $language->lang('YES') : $language->lang('ENABLED'),
|
||||
];
|
||||
|
||||
$tpl = ['tag' => 'radio'];
|
||||
if ($tpl_type_cond[0] == 'yes' || $tpl_type_cond[0] == 'enabled')
|
||||
{
|
||||
$tpl['buttons'] = [$yes_button, $no_button];
|
||||
}
|
||||
else
|
||||
{
|
||||
$tpl['buttons'] = [$no_button, $yes_button];
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return $tpl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build configuration template for acp configuration pages
|
||||
*/
|
||||
function build_cfg_template($tpl_type, $key, &$new_ary, $config_key, $vars)
|
||||
{
|
||||
global $module, $phpbb_dispatcher;
|
||||
|
||||
$tpl = '';
|
||||
$name = 'config[' . $config_key . ']';
|
||||
|
||||
// Make sure there is no notice printed out for non-existent config options (we simply set them)
|
||||
if (!isset($new_ary[$config_key]))
|
||||
{
|
||||
$new_ary[$config_key] = '';
|
||||
}
|
||||
|
||||
switch ($tpl_type[0])
|
||||
{
|
||||
case 'password':
|
||||
case 'text':
|
||||
case 'url':
|
||||
case 'email':
|
||||
case 'tel':
|
||||
case 'search':
|
||||
case 'color':
|
||||
case 'datetime':
|
||||
case 'datetime-local':
|
||||
case 'month':
|
||||
case 'week':
|
||||
case 'date':
|
||||
case 'time':
|
||||
case 'number':
|
||||
case 'range':
|
||||
case 'dimension':
|
||||
case 'textarea':
|
||||
case 'radio':
|
||||
$tpl = phpbb_build_cfg_template($tpl_type, $key, $new_ary, $config_key, $vars);
|
||||
break;
|
||||
|
||||
case 'select':
|
||||
@@ -386,7 +500,14 @@ function build_cfg_template($tpl_type, $key, &$new_ary, $config_key, $vars)
|
||||
|
||||
if (isset($vars['append']))
|
||||
{
|
||||
$tpl .= $vars['append'];
|
||||
if (is_array($tpl))
|
||||
{
|
||||
$tpl['append'] = $vars['append'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$tpl .= $vars['append'];
|
||||
}
|
||||
}
|
||||
|
||||
$new = $new_ary;
|
||||
|
Reference in New Issue
Block a user