mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-07 20:08:53 +00:00
[ticket/17100] Move build_cfg_template parts to HTML-less function
PHPBB3-17100
This commit is contained in:
parent
f64eb7dd04
commit
99368ab19a
4 changed files with 207 additions and 23 deletions
|
@ -37,6 +37,7 @@
|
|||
|
||||
<!-- IF S_ATTACHMENT_SETTINGS -->
|
||||
|
||||
{% import "form_macros.twig" as form_macros %}
|
||||
<form id="attachsettings" method="post" action="{U_ACTION}">
|
||||
<!-- BEGIN options -->
|
||||
<!-- IF options.S_LEGEND -->
|
||||
|
@ -49,7 +50,20 @@
|
|||
|
||||
<dl>
|
||||
<dt><label for="{options.KEY}">{options.TITLE}{L_COLON}</label><!-- IF options.S_EXPLAIN --><br /><span>{options.TITLE_EXPLAIN}</span><!-- ENDIF --></dt>
|
||||
<dd>{options.CONTENT}</dd>
|
||||
<dd>
|
||||
{% if options.CONTENT.tag %}
|
||||
{% if options.CONTENT.tag == 'input' %}
|
||||
{{ form_macros.input(options.CONTENT) }}
|
||||
{% elseif options.CONTENT.tag == 'dimension' %}
|
||||
{{ form_macros.dimension(options.CONTENT) }}
|
||||
{% elseif options.CONTENT.tag == 'radio' %}
|
||||
{{ form_macros.radio_buttons(options.CONTENT) }}
|
||||
{% endif %}
|
||||
{% if options.CONTENT.append %}{{ options.CONTENT.append }}{% endif %}
|
||||
{% else %}
|
||||
{options.CONTENT}
|
||||
{% endif %}
|
||||
</dd>
|
||||
{% if (options.KEY == 'allow_attachments' and S_EMPTY_POST_GROUPS) or (options.KEY == 'allow_pm_attach' and S_EMPTY_PM_GROUPS) %}
|
||||
<dd><span class="error">{{ lang(options.KEY == 'allow_attachments' ? 'NO_EXT_GROUP_ALLOWED_POST' : 'NO_EXT_GROUP_ALLOWED_PM', U_EXTENSION_GROUPS) }}</span></dd>
|
||||
{% endif %}
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
</div>
|
||||
<!-- ENDIF -->
|
||||
|
||||
{% import "form_macros.twig" as form_macros %}
|
||||
<form id="acp_board" method="post" action="{U_ACTION}">
|
||||
|
||||
<!-- BEGIN options -->
|
||||
|
@ -27,7 +28,20 @@
|
|||
|
||||
<dl>
|
||||
<dt><label for="{options.KEY}">{options.TITLE}{L_COLON}</label><!-- IF options.S_EXPLAIN --><br /><span>{options.TITLE_EXPLAIN}</span><!-- ENDIF --></dt>
|
||||
<dd>{options.CONTENT}</dd>
|
||||
<dd>
|
||||
{% if options.CONTENT.tag %}
|
||||
{% if options.CONTENT.tag == 'input' %}
|
||||
{{ form_macros.input(options.CONTENT) }}
|
||||
{% elseif options.CONTENT.tag == 'dimension' %}
|
||||
{{ form_macros.dimension(options.CONTENT) }}
|
||||
{% elseif options.CONTENT.tag == 'radio' %}
|
||||
{{ form_macros.radio_buttons(options.CONTENT) }}
|
||||
{% endif %}
|
||||
{% if options.CONTENT.append %}{{ options.CONTENT.append }}{% endif %}
|
||||
{% else %}
|
||||
{{ options.CONTENT }}
|
||||
{% endif %}
|
||||
</dd>
|
||||
</dl>
|
||||
|
||||
<!-- ENDIF -->
|
||||
|
|
35
phpBB/adm/style/form_macros.twig
Normal file
35
phpBB/adm/style/form_macros.twig
Normal file
|
@ -0,0 +1,35 @@
|
|||
{% macro input(form_data) %}
|
||||
<input
|
||||
{% if form_data.id %}id="{{ form_data.id }}"{% endif %}
|
||||
type="{{ form_data.type }}"
|
||||
name="{{ form_data.name }}"
|
||||
{% if form_data.size %}size="{{ form_data.size }}"{% endif %}
|
||||
{% if form_data.maxlength %}maxlength="{{ form_data.maxlength }}"{% endif %}
|
||||
{% if form_data.min %}min="{{ form_data.min }}"{% endif %}
|
||||
{% if form_data.max %}max="{{ form_data.max }}"{% endif %}
|
||||
{% if form_data.type == 'password' %}autocomplete="off"{% endif %}
|
||||
{% if form_data.checked %}checked="checked"{% endif %}
|
||||
{% if form_data.class %}class="{{ form_data.class }}"{% endif %}
|
||||
value="{{ form_data.value }}"
|
||||
>
|
||||
{% endmacro %}
|
||||
|
||||
{% macro dimension(form_data) %}
|
||||
{{ _self.input(form_data.width) }} x {{ _self.input(form_data.height) }}
|
||||
{% endmacro %}
|
||||
|
||||
{% macro textarea(form_data) %}
|
||||
<textarea
|
||||
id="{{ form_data.id }}"
|
||||
name="{{ form_data.name }}"
|
||||
rows="{{ form_data.rows }}"
|
||||
cols="{{ form_data.cols }}"
|
||||
>
|
||||
{{ form_data.content }}
|
||||
</textarea>
|
||||
{% endmacro %}
|
||||
|
||||
{% macro radio_buttons(form_data) %}
|
||||
<label>{{ _self.input(form_data.buttons[0]) ~ form_data.buttons[0].label }}</label>
|
||||
<label>{{ _self.input(form_data.buttons[1]) ~ form_data.buttons[1].label }}</label>
|
||||
{% endmacro %}
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Reference in a new issue