From 99368ab19abf9b7fbffe199a9db1bb28585a06f4 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Mon, 18 Apr 2022 11:31:23 +0200 Subject: [PATCH] [ticket/17100] Move build_cfg_template parts to HTML-less function PHPBB3-17100 --- phpBB/adm/style/acp_attachments.html | 16 ++- phpBB/adm/style/acp_board.html | 16 ++- phpBB/adm/style/form_macros.twig | 35 ++++++ phpBB/includes/functions_acp.php | 163 +++++++++++++++++++++++---- 4 files changed, 207 insertions(+), 23 deletions(-) create mode 100644 phpBB/adm/style/form_macros.twig diff --git a/phpBB/adm/style/acp_attachments.html b/phpBB/adm/style/acp_attachments.html index 529bdb7126..77a89ff571 100644 --- a/phpBB/adm/style/acp_attachments.html +++ b/phpBB/adm/style/acp_attachments.html @@ -37,6 +37,7 @@ + {% import "form_macros.twig" as form_macros %}
@@ -49,7 +50,20 @@

{options.TITLE_EXPLAIN}
-
{options.CONTENT}
+
+ {% 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 %} +
{% if (options.KEY == 'allow_attachments' and S_EMPTY_POST_GROUPS) or (options.KEY == 'allow_pm_attach' and S_EMPTY_PM_GROUPS) %}
{{ lang(options.KEY == 'allow_attachments' ? 'NO_EXT_GROUP_ALLOWED_POST' : 'NO_EXT_GROUP_ALLOWED_PM', U_EXTENSION_GROUPS) }}
{% endif %} diff --git a/phpBB/adm/style/acp_board.html b/phpBB/adm/style/acp_board.html index fe3e250099..3cc5d2dea2 100644 --- a/phpBB/adm/style/acp_board.html +++ b/phpBB/adm/style/acp_board.html @@ -13,6 +13,7 @@ +{% import "form_macros.twig" as form_macros %} @@ -27,7 +28,20 @@

{options.TITLE_EXPLAIN}
-
{options.CONTENT}
+
+ {% 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 %} +
diff --git a/phpBB/adm/style/form_macros.twig b/phpBB/adm/style/form_macros.twig new file mode 100644 index 0000000000..847b8b5f07 --- /dev/null +++ b/phpBB/adm/style/form_macros.twig @@ -0,0 +1,35 @@ +{% macro input(form_data) %} + +{% endmacro %} + +{% macro dimension(form_data) %} + {{ _self.input(form_data.width) }} x {{ _self.input(form_data.height) }} +{% endmacro %} + +{% macro textarea(form_data) %} + +{% endmacro %} + +{% macro radio_buttons(form_data) %} + + +{% endmacro %} diff --git a/phpBB/includes/functions_acp.php b/phpBB/includes/functions_acp.php index 9a1d4b6a70..ff7673155c 100644 --- a/phpBB/includes/functions_acp.php +++ b/phpBB/includes/functions_acp.php @@ -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 = ''; + $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 = ''; + $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 = ''; + $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 = ' x '; + $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 = ''; + $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 = ''; - $tpl_yes = ''; + $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;