Merge pull request #6470 from marc1706/ticket/17100

[ticket/17100] Introduce twig macros for commonly used form elements
This commit is contained in:
Marc Alexander 2023-05-23 20:46:31 +02:00 committed by GitHub
commit 73f9398ab0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
42 changed files with 1390 additions and 409 deletions

View file

@ -53,12 +53,19 @@ $module_id = $request->variable('i', '');
$mode = $request->variable('mode', ''); $mode = $request->variable('mode', '');
// Set custom style for admin area // Set custom style for admin area
$template->set_custom_style(array( /** @var \phpbb\template\base $template */
array( $template->set_custom_style(
'name' => 'adm', [
'ext_path' => 'adm/style/', [
), 'name' => 'adm',
), $phpbb_admin_path . 'style'); 'ext_path' => 'adm/style/',
]
],
[
$phpbb_admin_path . 'style',
$phpbb_root_path . 'styles/all/template/',
],
);
$template->assign_var('T_ASSETS_PATH', $phpbb_root_path . 'assets'); $template->assign_var('T_ASSETS_PATH', $phpbb_root_path . 'assets');
$template->assign_var('T_TEMPLATE_PATH', $phpbb_admin_path . 'style'); $template->assign_var('T_TEMPLATE_PATH', $phpbb_admin_path . 'style');

View file

@ -49,7 +49,13 @@
<dl> <dl>
<dt><label for="{options.KEY}">{options.TITLE}{L_COLON}</label><!-- IF options.S_EXPLAIN --><br /><span>{options.TITLE_EXPLAIN}</span><!-- ENDIF --></dt> <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 is iterable %}
{{ FormsBuildTemplate(options.CONTENT)}}
{% 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) %} {% 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> <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 %} {% endif %}
@ -175,8 +181,14 @@
<dd><input type="text" id="group_name" size="20" maxlength="100" name="group_name" value="{GROUP_NAME}" /></dd> <dd><input type="text" id="group_name" size="20" maxlength="100" name="group_name" value="{GROUP_NAME}" /></dd>
</dl> </dl>
<dl> <dl>
<dt><label for="category">{L_SPECIAL_CATEGORY}{L_COLON}</label><br /><span>{L_SPECIAL_CATEGORY_EXPLAIN}</span></dt> <dt><label for="{{ S_CATEGORY_SELECT.id }}">{L_SPECIAL_CATEGORY}{L_COLON}</label><br /><span>{L_SPECIAL_CATEGORY_EXPLAIN}</span></dt>
<dd>{S_CATEGORY_SELECT}</dd> <dd>
<select name="{{ S_CATEGORY_SELECT.name }}" id="{{ S_CATEGORY_SELECT.id }}">
{% for option in S_CATEGORY_SELECT.options %}
<option value="{{ option.value }}"{% if option.selected %} selected="selected"{% endif %}>{{ option.label }}</option>
{% endfor %}
</select>
</dd>
</dl> </dl>
<dl> <dl>
<dt><label for="allowed">{L_ALLOWED}{L_COLON}</label></dt> <dt><label for="allowed">{L_ALLOWED}{L_COLON}</label></dt>
@ -195,7 +207,10 @@
</dl> </dl>
<dl> <dl>
<dt><label for="extgroup_filesize">{L_MAX_EXTGROUP_FILESIZE}{L_COLON}</label></dt> <dt><label for="extgroup_filesize">{L_MAX_EXTGROUP_FILESIZE}{L_COLON}</label></dt>
<dd><input type="number" id="extgroup_filesize" min="0" max="999999999999999" step="any" name="max_filesize" value="{EXTGROUP_FILESIZE}" /> <select name="size_select">{S_EXT_GROUP_SIZE_OPTIONS}</select></dd> <dd>
<input type="number" id="extgroup_filesize" min="0" max="999999999999999" step="any" name="max_filesize" value="{EXTGROUP_FILESIZE}" />
{{ FormsSelect(EXT_GROUP_SIZE_OPTIONS) }}
</dd>
</dl> </dl>
<dl> <dl>
<dt><label for="assigned_extensions">{L_ASSIGNED_EXTENSIONS}{L_COLON}</label></dt> <dt><label for="assigned_extensions">{L_ASSIGNED_EXTENSIONS}{L_COLON}</label></dt>
@ -275,8 +290,14 @@
<dd><input type="text" id="add_extension" size="20" maxlength="100" name="add_extension" value="{ADD_EXTENSION}" /></dd> <dd><input type="text" id="add_extension" size="20" maxlength="100" name="add_extension" value="{ADD_EXTENSION}" /></dd>
</dl> </dl>
<dl> <dl>
<dt><label for="extension_group">{L_EXTENSION_GROUP}</label></dt> <dt><label for="{{ GROUP_SELECT_OPTIONS.id }}">{L_EXTENSION_GROUP}</label></dt>
<dd>{GROUP_SELECT_OPTIONS}</dd> <dd>
<select name="{{ GROUP_SELECT_OPTIONS.name }}" id="{{ GROUP_SELECT_OPTIONS.id }}">
{% for option in GROUP_SELECT_OPTIONS.options %}
<option value="{{ option.value }}"{% if option.selected %} selected="selected"{% endif %}>{{ option.label }}</option>
{% endfor %}
</select>
</dd>
</dl> </dl>
<p class="quick"> <p class="quick">
@ -309,7 +330,13 @@
<!-- ENDIF --> <!-- ENDIF -->
<tr> <tr>
<td><strong>{extensions.EXTENSION}</strong></td> <td><strong>{extensions.EXTENSION}</strong></td>
<td>{extensions.GROUP_OPTIONS}</td> <td>
<select name="{{ extensions.GROUP_OPTIONS.name }}" id="{{ extensions.GROUP_OPTIONS.id }}">
{% for option in extensions.GROUP_OPTIONS.options %}
<option value="{{ option.value }}"{% if option.selected %} selected="selected"{% endif %}>{{ option.label }}</option>
{% endfor %}
</select>
</td>
<td><input type="checkbox" class="radio" name="extension_id_list[]" value="{extensions.EXTENSION_ID}" /><input type="hidden" name="extension_change_list[]" value="{extensions.EXTENSION_ID}" /></td> <td><input type="checkbox" class="radio" name="extension_id_list[]" value="{extensions.EXTENSION_ID}" /><input type="hidden" name="extension_change_list[]" value="{extensions.EXTENSION_ID}" /></td>
</tr> </tr>
<!-- END extensions --> <!-- END extensions -->

View file

@ -27,7 +27,13 @@
<dl> <dl>
<dt><label for="{options.KEY}">{options.TITLE}{L_COLON}</label><!-- IF options.S_EXPLAIN --><br /><span>{options.TITLE_EXPLAIN}</span><!-- ENDIF --></dt> <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 is iterable %}
{{ FormsBuildTemplate(options.CONTENT)}}
{% else %}
{{ options.CONTENT }}
{% endif %}
</dd>
</dl> </dl>
<!-- ENDIF --> <!-- ENDIF -->

View file

@ -30,8 +30,10 @@
<dd><select id="bot_style" name="bot_style">{S_STYLE_OPTIONS}</select></dd> <dd><select id="bot_style" name="bot_style">{S_STYLE_OPTIONS}</select></dd>
</dl> </dl>
<dl> <dl>
<dt><label for="bot_lang">{L_BOT_LANG}{L_COLON}</label><br /><span>{L_BOT_LANG_EXPLAIN}</span></dt> <dt><label for="{{ LANG_OPTIONS.id }}">{L_BOT_LANG}{L_COLON}</label><br /><span>{L_BOT_LANG_EXPLAIN}</span></dt>
<dd><select id="bot_lang" name="bot_lang">{S_LANG_OPTIONS}</select></dd> <dd>
{{ FormsSelect(LANG_OPTIONS) }}
</dd>
</dl> </dl>
<dl> <dl>
<dt><label for="bot_active">{L_BOT_ACTIVE}{L_COLON}</label></dt> <dt><label for="bot_active">{L_BOT_ACTIVE}{L_COLON}</label></dt>

View file

@ -65,7 +65,7 @@
<!-- ENDIF --> <!-- ENDIF -->
<fieldset class="quick"> <fieldset class="quick">
<select name="action">{S_INACTIVE_OPTIONS}</select> {{ FormsSelect(INACTIVE_OPTIONS) }}
<input class="button2" type="submit" name="submit" value="{L_SUBMIT}" /> <input class="button2" type="submit" name="submit" value="{L_SUBMIT}" />
<p class="small"><a href="#" onclick="marklist('inactive', 'mark', true); return false;">{L_MARK_ALL}</a> &bull; <a href="#" onclick="marklist('inactive', 'mark', false); return false;">{L_UNMARK_ALL}</a></p> <p class="small"><a href="#" onclick="marklist('inactive', 'mark', true); return false;">{L_MARK_ALL}</a> &bull; <a href="#" onclick="marklist('inactive', 'mark', false); return false;">{L_UNMARK_ALL}</a></p>
{S_FORM_TOKEN} {S_FORM_TOKEN}

View file

@ -41,8 +41,10 @@
<label><input type="radio" class="radio" name="notifypm" value="0"<!-- IF not NOTIFY_PM --> id="notifypm" checked="checked"<!-- ENDIF --> /> {L_NO}</label></dd> <label><input type="radio" class="radio" name="notifypm" value="0"<!-- IF not NOTIFY_PM --> id="notifypm" checked="checked"<!-- ENDIF --> /> {L_NO}</label></dd>
</dl> </dl>
<dl> <dl>
<dt><label for="lang">{L_BOARD_LANGUAGE}{L_COLON}</label></dt> <dt><label for="{{ LANG_OPTIONS.id }}">{L_BOARD_LANGUAGE}{L_COLON}</label></dt>
<dd><select id="lang" name="lang">{S_LANG_OPTIONS}</select></dd> <dd>
{{ FormsSelect(LANG_OPTIONS) }}
</dd>
</dl> </dl>
<dl> <dl>
<dt><label for="style">{L_BOARD_STYLE}{L_COLON}</label></dt> <dt><label for="style">{L_BOARD_STYLE}{L_COLON}</label></dt>

View file

@ -340,6 +340,19 @@ $(function() {
}); });
} }
// Handle date option changes
const dateoptionSelect = document.getElementById('dateoptions');
if (dateoptionSelect) {
dateoptionSelect.addEventListener('change', function() {
const dateoptionInput = document.getElementById(this.getAttribute('data-dateoption'));
if (this.value === 'custom') {
dateoptionInput.value = this.getAttribute('data-dateoption-default');
} else {
dateoptionInput.value = this.value;
}
})
}
if ($('#acp_help_phpbb')) { if ($('#acp_help_phpbb')) {
phpbb.prepareSendStats(); phpbb.prepareSendStats();
} }

View file

@ -1,27 +1,15 @@
<dl> <dl>
<dt><label for="timezone">{L_BOARD_TIMEZONE}{L_COLON}</label></dt> <dt><label for="timezone">{{ lang('BOARD_TIMEZONE') ~ lang('COLON') }}</label></dt>
<!-- IF .timezone_date --> {% if TIMEZONE_OPTIONS %}
<dd id="tz_select_date" style="display: none;"> <dd id="tz_select_date hidden">
<select name="tz_date" id="tz_date" class="autowidth tz_select"> {% set tz_date_data = TIMEZONE_OPTIONS | merge({options: [{ value: "", label: lang('SELECT_CURRENT_TIME')}] | merge(TIMEZONE_OPTIONS.options) }) %}
<option value="">{L_SELECT_CURRENT_TIME}</option> {{ FormsSelect(tz_date_data | merge({class: 'autowidth tz_select', id: 'tz_date', name: 'tz_date', group_only: true})) }}
<!-- BEGIN timezone_date -->
<option value="{timezone_date.VALUE}"<!-- IF timezone_date.SELECTED --> selected="selected"<!-- ENDIF -->>{timezone_date.TITLE}</option>
<!-- END timezone_date -->
</select>
</dd> </dd>
<!-- ENDIF --> {% endif %}
<dd> <dd>
<select name="tz" id="timezone" class="autowidth tz_select"> {% set tz_select_data = TIMEZONE_OPTIONS | merge({ options: [{ value: "", label: lang('SELECT_TIMEZONE') }] | merge(TIMEZONE_OPTIONS.options) }) %}
<option value="">{L_SELECT_TIMEZONE}</option> {{ FormsSelect(tz_select_data | merge({class: 'autowidth tz_select', id: 'timezone'})) }}
<!-- BEGIN timezone_select -->
<optgroup label="{timezone_select.LABEL}" data-tz-value="{timezone_select.VALUE}">
<!-- BEGIN timezone_options -->
<option title="{timezone_select.timezone_options.TITLE}" value="{timezone_select.timezone_options.VALUE}"<!-- IF timezone_select.timezone_options.SELECTED --> selected="selected"<!-- ENDIF -->>{timezone_select.timezone_options.LABEL}</option>
<!-- END timezone_options -->
</optgroup>
<!-- END timezone_select -->
</select>
<!-- INCLUDEJS timezone.js --> {% INCLUDEJS('timezone.js') %}
</dd> </dd>
</dl> </dl>

View file

@ -69,6 +69,13 @@ services:
template.twig.extensions.debug: template.twig.extensions.debug:
class: Twig\Extension\DebugExtension class: Twig\Extension\DebugExtension
template.twig.extensions.forms:
class: phpbb\template\twig\extension\forms
arguments:
- '@user'
tags:
- { name: twig.extension }
template: template:
class: phpbb\template\twig\twig class: phpbb\template\twig\twig
arguments: arguments:

View file

@ -452,11 +452,11 @@ class acp_attachments
$cache->destroy('_extensions'); $cache->destroy('_extensions');
} }
$template->assign_vars(array( $template->assign_vars([
'S_EXTENSIONS' => true, 'S_EXTENSIONS' => true,
'ADD_EXTENSION' => (isset($add_extension)) ? $add_extension : '', 'ADD_EXTENSION' => (isset($add_extension)) ? $add_extension : '',
'GROUP_SELECT_OPTIONS' => (isset($_POST['add_extension_check'])) ? $this->group_select('add_group_select', $add_extension_group, 'extension_group') : $this->group_select('add_group_select', false, 'extension_group')) 'GROUP_SELECT_OPTIONS' => $this->group_select('add_group_select', $request->is_set_post('add_extension_check') ? $add_extension_group : false, 'extension_group'),
); ]);
$sql = 'SELECT * $sql = 'SELECT *
FROM ' . EXTENSIONS_TABLE . ' FROM ' . EXTENSIONS_TABLE . '
@ -794,7 +794,10 @@ class acp_attachments
'ASSIGNED_EXTENSIONS' => $assigned_extensions, 'ASSIGNED_EXTENSIONS' => $assigned_extensions,
'S_CATEGORY_SELECT' => $this->category_select('special_category', $group_id, 'category'), 'S_CATEGORY_SELECT' => $this->category_select('special_category', $group_id, 'category'),
'S_EXT_GROUP_SIZE_OPTIONS' => size_select_options($size_format), 'EXT_GROUP_SIZE_OPTIONS' => [
'name' => 'size_select',
'options' => size_select_options($size_format),
],
'S_EXTENSION_OPTIONS' => $s_extension_options, 'S_EXTENSION_OPTIONS' => $s_extension_options,
'S_FILENAME_LIST' => $filename_list, 'S_FILENAME_LIST' => $filename_list,
'S_EDIT_GROUP' => true, 'S_EDIT_GROUP' => true,
@ -1445,16 +1448,21 @@ class acp_attachments
$cat_type = attachment_category::NONE; $cat_type = attachment_category::NONE;
} }
$group_select = '<select name="' . $select_name . '"' . (($key) ? ' id="' . $key . '"' : '') . '>'; $group_select = [
'name' => $select_name,
'id' => $key,
'options' => [],
];
foreach ($types as $type => $mode) foreach ($types as $type => $mode)
{ {
$selected = ($type == $cat_type) ? ' selected="selected"' : ''; $group_select['options'][] = [
$group_select .= '<option value="' . $type . '"' . $selected . '>' . $mode . '</option>'; 'value' => $type,
'selected' => $type == $cat_type,
'label' => $mode,
];
} }
$group_select .= '</select>';
return $group_select; return $group_select;
} }
@ -1465,8 +1473,6 @@ class acp_attachments
{ {
global $db, $user; global $db, $user;
$group_select = '<select name="' . $select_name . '"' . (($key) ? ' id="' . $key . '"' : '') . '>';
$sql = 'SELECT group_id, group_name $sql = 'SELECT group_id, group_name
FROM ' . EXTENSION_GROUPS_TABLE . ' FROM ' . EXTENSION_GROUPS_TABLE . '
ORDER BY group_name'; ORDER BY group_name';
@ -1484,22 +1490,30 @@ class acp_attachments
$row['group_name'] = $user->lang['NOT_ASSIGNED']; $row['group_name'] = $user->lang['NOT_ASSIGNED'];
$group_name[] = $row; $group_name[] = $row;
$group_select = [
'name' => $select_name,
'id' => $key,
'options' => [],
];
for ($i = 0, $groups_size = count($group_name); $i < $groups_size; $i++) for ($i = 0, $groups_size = count($group_name); $i < $groups_size; $i++)
{ {
if ($default_group === false) if ($default_group === false)
{ {
$selected = ($i == 0) ? ' selected="selected"' : ''; $selected = $i == 0;
} }
else else
{ {
$selected = ($group_name[$i]['group_id'] == $default_group) ? ' selected="selected"' : ''; $selected = $group_name[$i]['group_id'] == $default_group;
} }
$group_select .= '<option value="' . $group_name[$i]['group_id'] . '"' . $selected . '>' . $group_name[$i]['group_name'] . '</option>'; $group_select['options'][] = [
'value' => $group_name[$i]['group_id'],
'selected' => $selected,
'label' => $group_name[$i]['group_name'],
];
} }
$group_select .= '</select>';
return $group_select; return $group_select;
} }
@ -1712,8 +1726,23 @@ class acp_attachments
$size_var = $filesize['si_identifier']; $size_var = $filesize['si_identifier'];
$value = $filesize['value']; $value = $filesize['value'];
// size and maxlength must not be specified for input of type number return [
return '<input type="number" id="' . $key . '" min="0" max="999999999999999" step="any" name="config[' . $key . ']" value="' . $value . '" /> <select name="' . $key . '">' . size_select_options($size_var) . '</select>'; [
'tag' => 'input',
'id' => $key,
'type' => 'number',
'name' => 'config[' . $key . ']',
'min' => 0,
'max' => 999999999999999,
'step' => 'any',
'value' => $value,
],
[
'tag' => 'select',
'name' => $key,
'options' => size_select_options($size_var),
]
];
} }
/** /**

View file

@ -18,6 +18,11 @@
/** /**
* @ignore * @ignore
*/ */
use phpbb\config\config;
use phpbb\language\language;
use phpbb\user;
if (!defined('IN_PHPBB')) if (!defined('IN_PHPBB'))
{ {
exit; exit;
@ -28,16 +33,26 @@ class acp_board
var $u_action; var $u_action;
var $new_config; var $new_config;
/** @var config */
protected $config;
/** @var language */
protected $language;
/** @var user */
protected $user;
function main($id, $mode) function main($id, $mode)
{ {
global $user, $template, $request, $language; global $user, $template, $request, $language;
global $config, $phpbb_root_path, $phpEx; global $config, $phpbb_root_path, $phpEx;
global $cache, $phpbb_container, $phpbb_dispatcher, $phpbb_log; global $cache, $phpbb_container, $phpbb_dispatcher, $phpbb_log;
/** @var \phpbb\language\language $language Language object */ $this->config = $config;
$language = $phpbb_container->get('language'); $this->language = $language;
$this->user = $user;
$user->add_lang('acp/board'); $this->language->add_lang('acp/board');
$submit = (isset($_POST['submit']) || isset($_POST['allow_quick_reply_enable'])) ? true : false; $submit = (isset($_POST['submit']) || isset($_POST['allow_quick_reply_enable'])) ? true : false;
@ -64,7 +79,7 @@ class acp_board
'board_index_text' => array('lang' => 'BOARD_INDEX_TEXT', 'validate' => 'string', 'type' => 'text:40:255', 'explain' => true), 'board_index_text' => array('lang' => 'BOARD_INDEX_TEXT', 'validate' => 'string', 'type' => 'text:40:255', 'explain' => true),
'board_disable' => array('lang' => 'DISABLE_BOARD', 'validate' => 'bool', 'type' => 'custom', 'method' => 'board_disable', 'explain' => true), 'board_disable' => array('lang' => 'DISABLE_BOARD', 'validate' => 'bool', 'type' => 'custom', 'method' => 'board_disable', 'explain' => true),
'board_disable_msg' => false, 'board_disable_msg' => false,
'default_lang' => array('lang' => 'DEFAULT_LANGUAGE', 'validate' => 'lang', 'type' => 'select', 'function' => 'language_select', 'params' => array('{CONFIG_VALUE}'), 'explain' => false), 'default_lang' => array('lang' => 'DEFAULT_LANGUAGE', 'validate' => 'lang', 'type' => 'select', 'method' => 'language_select', 'params' => array('{CONFIG_VALUE}'), 'explain' => false),
'default_dateformat' => array('lang' => 'DEFAULT_DATE_FORMAT', 'validate' => 'string', 'type' => 'custom', 'method' => 'dateformat_select', 'explain' => true), 'default_dateformat' => array('lang' => 'DEFAULT_DATE_FORMAT', 'validate' => 'string', 'type' => 'custom', 'method' => 'dateformat_select', 'explain' => true),
'board_timezone' => array('lang' => 'SYSTEM_TIMEZONE', 'validate' => 'timezone', 'type' => 'custom', 'method' => 'timezone_select', 'explain' => true), 'board_timezone' => array('lang' => 'SYSTEM_TIMEZONE', 'validate' => 'timezone', 'type' => 'custom', 'method' => 'timezone_select', 'explain' => true),
@ -503,7 +518,7 @@ class acp_board
{ {
if (!preg_match('#^[a-z][a-z0-9+\\-.]*$#Di', $scheme)) if (!preg_match('#^[a-z][a-z0-9+\\-.]*$#Di', $scheme))
{ {
$error[] = $language->lang('URL_SCHEME_INVALID', $language->lang('ALLOWED_SCHEMES_LINKS'), $scheme); $error[] = $this->language->lang('URL_SCHEME_INVALID', $this->language->lang('ALLOWED_SCHEMES_LINKS'), $scheme);
} }
} }
} }
@ -976,19 +991,50 @@ class acp_board
/** /**
* Select bump interval * Select bump interval
*/ */
function bump_interval($value, $key) public function bump_interval($value, $key): array
{ {
global $user; $bump_type_options = [];
$s_bump_type = '';
$types = array('m' => 'MINUTES', 'h' => 'HOURS', 'd' => 'DAYS'); $types = array('m' => 'MINUTES', 'h' => 'HOURS', 'd' => 'DAYS');
foreach ($types as $type => $lang) foreach ($types as $type => $lang)
{ {
$selected = ($this->new_config['bump_type'] == $type) ? ' selected="selected"' : ''; $bump_type_options[] = [
$s_bump_type .= '<option value="' . $type . '"' . $selected . '>' . $user->lang[$lang] . '</option>'; 'value' => $type,
'selected' => $this->new_config['bump_type'] == $type,
'label' => $this->language->lang($lang),
];
} }
return '<input id="' . $key . '" type="text" size="3" maxlength="4" name="config[bump_interval]" value="' . $value . '" />&nbsp;<select name="config[bump_type]">' . $s_bump_type . '</select>'; return [
[
'tag' => 'input',
'id' => $key,
'type' => 'text',
'size' => 3,
'maxlength' => 4,
'name' => 'config[bump_interval]',
'value' => $value,
],
[
'tag' => 'select',
'name' => 'config[bump_type]',
'options' => $bump_type_options,
],
];
}
/**
* Wrapper function for phpbb_language_select()
*
* @param string $default
* @param array $langdata
*
* @return array
*/
public function language_select(string $default = '', array $langdata = []): array
{
global $db;
return phpbb_language_select($db, $default, $langdata);
} }
/** /**
@ -1019,11 +1065,13 @@ class acp_board
*/ */
function timezone_select($value, $key) function timezone_select($value, $key)
{ {
global $template, $user; $timezone_select = phpbb_timezone_select($this->user, $value, true);
$timezone_select = phpbb_timezone_select($template, $user, $value, true); return [
'tag' => 'select',
return '<select name="config[' . $key . ']" id="' . $key . '">' . $timezone_select . '</select>'; 'name' => 'config[' . $key . ']',
'options' => $timezone_select,
];
} }
/** /**
@ -1060,81 +1108,132 @@ class acp_board
} }
/** /**
* Select default dateformat * Create select for default date format
*/ *
function dateformat_select($value, $key) * @param string $value Current date format value
* @param string $key Date format key
*
* @return array Date format select data
*/
public function dateformat_select(string $value, string $key): array
{ {
global $user, $config;
// Let the format_date function operate with the acp values // Let the format_date function operate with the acp values
$old_tz = $user->timezone; $old_tz = $this->user->timezone;
try try
{ {
$user->timezone = new DateTimeZone($config['board_timezone']); $this->user->timezone = new DateTimeZone($this->config['board_timezone']);
} }
catch (\Exception $e) catch (\Exception $e)
{ {
// If the board timezone is invalid, we just use the users timezone. // If the board timezone is invalid, we just use the users timezone.
} }
$dateformat_options = ''; $dateformat_options = [];
foreach ($user->lang['dateformats'] as $format => $null) $dateformats = $this->language->lang_raw('dateformats');
if (!is_array($dateformats))
{ {
$dateformat_options .= '<option value="' . $format . '"' . (($format == $value) ? ' selected="selected"' : '') . '>'; $dateformats = [];
$dateformat_options .= $user->format_date(time(), $format, false) . ((strpos($format, '|') !== false) ? $user->lang['VARIANT_DATE_SEPARATOR'] . $user->format_date(time(), $format, true) : '');
$dateformat_options .= '</option>';
} }
$dateformat_options .= '<option value="custom"'; foreach ($dateformats as $format => $null)
if (!isset($user->lang['dateformats'][$value]))
{ {
$dateformat_options .= ' selected="selected"'; $dateformat_options[] = [
'value' => $format,
'selected' => $format == $value,
'label' => $this->user->format_date(time(), $format, false) . ((strpos($format, '|') !== false) ? $this->language->lang('VARIANT_DATE_SEPARATOR') . $this->user->format_date(time(), $format, true) : '')
];
} }
$dateformat_options .= '>' . $user->lang['CUSTOM_DATEFORMAT'] . '</option>';
// Add custom entry
$dateformat_options[] = [
'value' => 'custom',
'selected' => !isset($dateformats[$value]),
'label' => $this->language->lang('CUSTOM_DATEFORMAT'),
];
// Reset users date options // Reset users date options
$user->timezone = $old_tz; $this->user->timezone = $old_tz;
return "<select name=\"dateoptions\" id=\"dateoptions\" onchange=\"if (this.value == 'custom') { document.getElementById('" . addslashes($key) . "').value = '" . addslashes($value) . "'; } else { document.getElementById('" . addslashes($key) . "').value = this.value; }\">$dateformat_options</select> return [
<input type=\"text\" name=\"config[$key]\" id=\"$key\" value=\"$value\" maxlength=\"64\" />"; [
'tag' => 'select',
'name' => 'dateoptions',
'id' => 'dateoptions',
'options' => $dateformat_options,
'data' => [
'dateoption' => $key,
'dateoption-default' => $value,
]
],
[
'tag' => 'input',
'type' => 'text',
'name' => "config[$key]",
'id' => $key,
'value' => $value,
'maxlength' => 64,
]
];
} }
/** /**
* Select multiple forums * Select for multiple forums
*/ *
function select_news_forums($value, $key) * @param mixed $value Config value, unused
* @param string $key Config key
*
* @return array Forum select data
*/
public function select_news_forums($value, string $key)
{ {
$forum_list = make_forum_select(false, false, true, true, true, false, true); return $this->get_forum_select($key);
// Build forum options
$s_forum_options = '<select id="' . $key . '" name="' . $key . '[]" multiple="multiple">';
foreach ($forum_list as $f_id => $f_row)
{
$f_row['selected'] = phpbb_optionget(FORUM_OPTION_FEED_NEWS, $f_row['forum_options']);
$s_forum_options .= '<option value="' . $f_id . '"' . (($f_row['selected']) ? ' selected="selected"' : '') . (($f_row['disabled']) ? ' disabled="disabled" class="disabled-option"' : '') . '>' . $f_row['padding'] . $f_row['forum_name'] . '</option>';
}
$s_forum_options .= '</select>';
return $s_forum_options;
} }
function select_exclude_forums($value, $key) /**
* Select for multiple forums to exclude
*
* @param mixed $value Config value, unused
* @param string $key Config key
*
* @return array Forum select data
*/
public function select_exclude_forums($value, string $key): array
{
return $this->get_forum_select($key, FORUM_OPTION_FEED_EXCLUDE);
}
/**
* Get forum select data for specified key and option
*
* @param string $key Config key
* @param int $forum_option Forum option bit
*
* @return array Forum select data
*/
protected function get_forum_select(string $key, int $forum_option = FORUM_OPTION_FEED_NEWS): array
{ {
$forum_list = make_forum_select(false, false, true, true, true, false, true); $forum_list = make_forum_select(false, false, true, true, true, false, true);
// Build forum options // Build forum options
$s_forum_options = '<select id="' . $key . '" name="' . $key . '[]" multiple="multiple">'; $forum_options = [];
foreach ($forum_list as $f_id => $f_row) foreach ($forum_list as $f_id => $f_row)
{ {
$f_row['selected'] = phpbb_optionget(FORUM_OPTION_FEED_EXCLUDE, $f_row['forum_options']); $forum_options[] = [
'value' => $f_id,
$s_forum_options .= '<option value="' . $f_id . '"' . (($f_row['selected']) ? ' selected="selected"' : '') . (($f_row['disabled']) ? ' disabled="disabled" class="disabled-option"' : '') . '>' . $f_row['padding'] . $f_row['forum_name'] . '</option>'; 'selected' => phpbb_optionget($forum_option, $f_row['forum_options']),
'disabled' => $f_row['disabled'],
'label' => $f_row['padding'] . $f_row['forum_name'],
];
} }
$s_forum_options .= '</select>';
return $s_forum_options; return [
'tag' => 'select',
'id' => $key,
'name' => $key . '[]',
'multiple' => true,
'options' => $forum_options,
];
} }
function store_feed_forums($option, $key) function store_feed_forums($option, $key)

View file

@ -330,7 +330,7 @@ class acp_bots
} }
$style_select = style_select($bot_row['bot_style'], true); $style_select = style_select($bot_row['bot_style'], true);
$lang_select = language_select($bot_row['bot_lang']); $lang_options = phpbb_language_select($db, $bot_row['bot_lang']);
$l_title = ($action == 'edit') ? 'EDIT' : 'ADD'; $l_title = ($action == 'edit') ? 'EDIT' : 'ADD';
@ -347,10 +347,13 @@ class acp_bots
'S_EDIT_BOT' => true, 'S_EDIT_BOT' => true,
'S_ACTIVE_OPTIONS' => $s_active_options, 'S_ACTIVE_OPTIONS' => $s_active_options,
'S_STYLE_OPTIONS' => $style_select, 'S_STYLE_OPTIONS' => $style_select,
'S_LANG_OPTIONS' => $lang_select, 'LANG_OPTIONS' => [
'id' => 'bot_lang',
'name' => 'bot_lang',
'options' => $lang_options,
],
'S_ERROR' => (count($error)) ? true : false, 'S_ERROR' => (count($error)) ? true : false,
) ));
);
return; return;

View file

@ -306,7 +306,10 @@ class acp_inactive
$template->assign_vars(array( $template->assign_vars(array(
'S_INACTIVE_USERS' => true, 'S_INACTIVE_USERS' => true,
'S_INACTIVE_OPTIONS' => build_select($option_ary), 'INACTIVE_OPTIONS' => [
'name' => 'action',
'options' => build_select($option_ary),
],
'S_LIMIT_DAYS' => $s_limit_days, 'S_LIMIT_DAYS' => $s_limit_days,
'S_SORT_KEY' => $s_sort_key, 'S_SORT_KEY' => $s_sort_key,

View file

@ -626,16 +626,7 @@ class acp_main
)); ));
} }
$option_ary = array('activate' => 'ACTIVATE', 'delete' => 'DELETE'); $template->assign_var('S_INACTIVE_USERS', true);
if ($config['email_enable'])
{
$option_ary += array('remind' => 'REMIND');
}
$template->assign_vars(array(
'S_INACTIVE_USERS' => true,
'S_INACTIVE_OPTIONS' => build_select($option_ary))
);
} }
// Warn if install is still present // Warn if install is still present

View file

@ -1795,7 +1795,9 @@ class acp_users
${'s_sort_' . $sort_option . '_dir'} .= '</select>'; ${'s_sort_' . $sort_option . '_dir'} .= '</select>';
} }
phpbb_timezone_select($template, $user, $data['tz'], true); $timezone_select = phpbb_timezone_select($user, $data['tz'], true);
$lang_options = phpbb_language_select($db, $data['lang']);
$user_prefs_data = array( $user_prefs_data = array(
'S_PREFS' => true, 'S_PREFS' => true,
'S_JABBER_DISABLED' => ($config['jab_enable'] && $user_row['user_jabber'] && @extension_loaded('xml')) ? false : true, 'S_JABBER_DISABLED' => ($config['jab_enable'] && $user_row['user_jabber'] && @extension_loaded('xml')) ? false : true,
@ -1831,8 +1833,17 @@ class acp_users
'DEFAULT_DATEFORMAT' => $config['default_dateformat'], 'DEFAULT_DATEFORMAT' => $config['default_dateformat'],
'A_DEFAULT_DATEFORMAT' => addslashes($config['default_dateformat']), 'A_DEFAULT_DATEFORMAT' => addslashes($config['default_dateformat']),
'S_LANG_OPTIONS' => language_select($data['lang']), 'LANG_OPTIONS' => [
'id' => 'lang',
'name' => 'lang',
'options' => $lang_options,
],
'S_STYLE_OPTIONS' => style_select($data['style']), 'S_STYLE_OPTIONS' => style_select($data['style']),
'TIMEZONE_OPTIONS' => [
'tag' => 'select',
'name' => 'tz',
'options' => $timezone_select,
],
); );
/** /**

View file

@ -265,15 +265,12 @@ function phpbb_version_compare(string $version1, string $version2, string $opera
/** /**
* Pick a language, any language ... * Pick a language, any language ...
* *
* @param \phpbb\db\driver\driver_interface $db DBAL driver
* @param string $default Language ISO code to be selected by default in the dropdown list * @param string $default Language ISO code to be selected by default in the dropdown list
* @param array $langdata Language data in format of array(array('lang_iso' => string, lang_local_name => string), ...) * @param array $langdata Language data in format of array(array('lang_iso' => string, lang_local_name => string), ...)
*
* @return string HTML options for language selection dropdown list.
*/ */
function language_select($default = '', array $langdata = []) function phpbb_language_select(\phpbb\db\driver\driver_interface $db, string $default = '', array $langdata = []): array
{ {
global $db;
if (empty($langdata)) if (empty($langdata))
{ {
$sql = 'SELECT lang_iso, lang_local_name $sql = 'SELECT lang_iso, lang_local_name
@ -284,11 +281,14 @@ function language_select($default = '', array $langdata = [])
$db->sql_freeresult($result); $db->sql_freeresult($result);
} }
$lang_options = ''; $lang_options = [];
foreach ($langdata as $row) foreach ($langdata as $row)
{ {
$selected = ($row['lang_iso'] == $default) ? ' selected="selected"' : ''; $lang_options[] = [
$lang_options .= '<option value="' . $row['lang_iso'] . '"' . $selected . '>' . $row['lang_local_name'] . '</option>'; 'value' => $row['lang_iso'],
'label' => $row['lang_local_name'],
'selected' => $row['lang_iso'] === $default,
];
} }
return $lang_options; return $lang_options;
@ -442,14 +442,13 @@ function phpbb_get_timezone_identifiers($selected_timezone)
/** /**
* Options to pick a timezone and date/time * Options to pick a timezone and date/time
* *
* @param \phpbb\template\template $template phpBB template object
* @param \phpbb\user $user Object of the current user * @param \phpbb\user $user Object of the current user
* @param string $default A timezone to select * @param string $default A timezone to select
* @param boolean $truncate Shall we truncate the options text * @param boolean $truncate Shall we truncate the options text
* *
* @return string Returns an array containing the options for the time selector. * @return string Returns an array containing the options for the time selector.
*/ */
function phpbb_timezone_select($template, $user, $default = '', $truncate = false) function phpbb_timezone_select($user, $default = '', $truncate = false)
{ {
static $timezones; static $timezones;
@ -481,27 +480,22 @@ function phpbb_timezone_select($template, $user, $default = '', $truncate = fals
uksort($timezones, 'phpbb_tz_select_compare'); uksort($timezones, 'phpbb_tz_select_compare');
} }
$tz_select = $opt_group = ''; $opt_group = '';
$tz_data = [];
foreach ($timezones as $key => $timezone) foreach ($timezones as $key => $timezone)
{ {
if ($opt_group != $timezone['offset']) if ($opt_group != $timezone['offset'])
{ {
// Generate tz_select for backwards compatibility $tz_data[$timezone['offset']] = [
$tz_select .= ($opt_group) ? '</optgroup>' : ''; 'label' => $user->lang(array('timezones', 'UTC_OFFSET_CURRENT'), $timezone['offset'], $timezone['current']),
$tz_select .= '<optgroup label="' . $user->lang(array('timezones', 'UTC_OFFSET_CURRENT'), $timezone['offset'], $timezone['current']) . '">'; 'value' => $key . ' - ' . $timezone['current'],
$opt_group = $timezone['offset']; 'options' => [],
$template->assign_block_vars('timezone_select', array( 'selected' => !empty($default_offset) && strpos($key, $default_offset) !== false,
'LABEL' => $user->lang(array('timezones', 'UTC_OFFSET_CURRENT'), $timezone['offset'], $timezone['current']), 'data' => ['tz-value' => $key . ' - ' . $timezone['current']],
'VALUE' => $key . ' - ' . $timezone['current'], ];
));
$selected = (!empty($default_offset) && strpos($key, $default_offset) !== false) ? ' selected="selected"' : ''; $opt_group = $timezone['offset'];
$template->assign_block_vars('timezone_date', array(
'VALUE' => $key . ' - ' . $timezone['current'],
'SELECTED' => !empty($selected),
'TITLE' => $user->lang(array('timezones', 'UTC_OFFSET_CURRENT'), $timezone['offset'], $timezone['current']),
));
} }
$label = $timezone['tz']; $label = $timezone['tz'];
@ -516,19 +510,15 @@ function phpbb_timezone_select($template, $user, $default = '', $truncate = fals
$label = truncate_string($label, 50, 255, false, '...'); $label = truncate_string($label, 50, 255, false, '...');
} }
// Also generate timezone_select for backwards compatibility $tz_data[$timezone['offset']]['options'][] = [
$selected = ($timezone['tz'] === $default) ? ' selected="selected"' : '';
$tz_select .= '<option title="' . $title . '" value="' . $timezone['tz'] . '"' . $selected . '>' . $label . '</option>';
$template->assign_block_vars('timezone_select.timezone_options', array(
'TITLE' => $title, 'TITLE' => $title,
'VALUE' => $timezone['tz'], 'value' => $timezone['tz'],
'SELECTED' => !empty($selected), 'selected' => $timezone['tz'] === $default,
'LABEL' => $label, 'label' => $label,
)); ];
} }
$tz_select .= '</optgroup>';
return $tz_select; return $tz_data;
} }
// Functions handling topic/post tracking/marking // Functions handling topic/post tracking/marking

View file

@ -209,18 +209,21 @@ function adm_back_link($u_action)
/** /**
* Build select field options in acp pages * Build select field options in acp pages
*/ */
function build_select($option_ary, $option_default = false) function build_select($option_ary, $option_default = false): array
{ {
global $user; global $language;
$html = ''; $options = [];
foreach ($option_ary as $value => $title) foreach ($option_ary as $value => $title)
{ {
$selected = ($option_default !== false && $value == $option_default) ? ' selected="selected"' : ''; $options[] = [
$html .= '<option value="' . $value . '"' . $selected . '>' . $user->lang[$title] . '</option>'; 'value' => $value,
'selected' => $option_default !== false && $value == $option_default,
'label' => $language->lang($title),
];
} }
return $html; return $options;
} }
/** /**
@ -243,13 +246,20 @@ function h_radio($name, $input_ary, $input_default = false, $id = false, $key =
} }
/** /**
* Build configuration template for acp configuration pages * HTML-less version of build_cfg_template
*/ *
function build_cfg_template($tpl_type, $key, &$new_ary, $config_key, $vars) * @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 . ']'; $name = 'config[' . $config_key . ']';
// Make sure there is no notice printed out for non-existent config options (we simply set them) // Make sure there is no notice printed out for non-existent config options (we simply set them)
@ -266,6 +276,8 @@ function build_cfg_template($tpl_type, $key, &$new_ary, $config_key, $vars)
// replace passwords with asterixes // replace passwords with asterixes
$new_ary[$config_key] = '********'; $new_ary[$config_key] = '********';
} }
// no break
case 'text': case 'text':
case 'url': case 'url':
case 'email': case 'email':
@ -276,7 +288,15 @@ function build_cfg_template($tpl_type, $key, &$new_ary, $config_key, $vars)
$size = (int) $tpl_type[1]; $size = (int) $tpl_type[1];
$maxlength = (int) $tpl_type[2]; $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; break;
case 'color': case 'color':
@ -284,7 +304,13 @@ function build_cfg_template($tpl_type, $key, &$new_ary, $config_key, $vars)
case 'datetime-local': case 'datetime-local':
case 'month': case 'month':
case 'week': 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; break;
case 'date': case 'date':
@ -294,34 +320,125 @@ function build_cfg_template($tpl_type, $key, &$new_ary, $config_key, $vars)
$min = isset($tpl_type[1]) ? (int) $tpl_type[1] : false; $min = isset($tpl_type[1]) ? (int) $tpl_type[1] : false;
$max = isset($tpl_type[2]) ? (int) $tpl_type[2] : 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; break;
case 'dimension': case 'dimension':
$min = isset($tpl_type[1]) ? (int) $tpl_type[1] : false; $min = isset($tpl_type[1]) ? (int) $tpl_type[1] : false;
$max = isset($tpl_type[2]) ? (int) $tpl_type[2] : 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; break;
case 'textarea': case 'textarea':
$rows = (int) $tpl_type[1]; $tpl = [
$cols = (int) $tpl_type[2]; 'tag' => 'textarea',
'id' => $key,
$tpl = '<textarea id="' . $key . '" name="' . $name . '" rows="' . $rows . '" cols="' . $cols . '">' . $new_ary[$config_key] . '</textarea>'; 'name' => $name,
'rows' => (int) $tpl_type[1],
'cols' => (int) $tpl_type[2],
'content' => $new_ary[$config_key],
];
break; break;
case 'radio': 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]); $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>'; $no_button = [
$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>'; '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' => (bool) $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; break;
case 'select': case 'select':
@ -369,9 +486,29 @@ function build_cfg_template($tpl_type, $key, &$new_ary, $config_key, $vars)
if ($tpl_type[0] == 'select') if ($tpl_type[0] == 'select')
{ {
$size = (isset($tpl_type[1])) ? (int) $tpl_type[1] : 1; $size = (isset($tpl_type[1])) ? (int) $tpl_type[1] : 1;
$data_toggle = (!empty($tpl_type[2])) ? ' data-togglable-settings="true"' : '';
$tpl = '<select id="' . $key . '" name="' . $name . '"' . (($size > 1) ? ' size="' . $size . '"' : '') . $data_toggle . '>' . $return . '</select>'; if (is_string($return))
{
$data_toggle = (!empty($tpl_type[2])) ? ' data-togglable-settings="true"' : '';
$tpl = '<select id="' . $key . '" name="' . $name . '"' . (($size > 1) ? ' size="' . $size . '"' : '') . $data_toggle . '>' . $return . '</select>';
}
else
{
$tpl = [
'tag' => 'select',
'id' => $key,
'name' => $name,
'toggleable' => !empty($tpl_type[2]),
'options' => $return,
];
// Add size if it differs from default value of 1
if ($size != 1)
{
$tpl['size'] = $size;
}
}
} }
else else
{ {
@ -386,7 +523,14 @@ function build_cfg_template($tpl_type, $key, &$new_ary, $config_key, $vars)
if (isset($vars['append'])) if (isset($vars['append']))
{ {
$tpl .= $vars['append']; if (is_array($tpl))
{
$tpl['append'] = $vars['append'];
}
else
{
$tpl .= $vars['append'];
}
} }
$new = $new_ary; $new = $new_ary;

View file

@ -160,20 +160,23 @@ function make_forum_select($select_id = false, $ignore_id = false, $ignore_acl =
*/ */
function size_select_options($size_compare) function size_select_options($size_compare)
{ {
global $user; global $language;
$size_types_text = array($user->lang['BYTES'], $user->lang['KIB'], $user->lang['MIB']); $size_types_text = array($language->lang('BYTES'), $language->lang('KIB'), $language->lang('MIB'));
$size_types = array('b', 'kb', 'mb'); $size_types = array('b', 'kb', 'mb');
$s_size_options = ''; $size_options = [];
for ($i = 0, $size = count($size_types_text); $i < $size; $i++) for ($i = 0, $size = count($size_types_text); $i < $size; $i++)
{ {
$selected = ($size_compare == $size_types[$i]) ? ' selected="selected"' : ''; $size_options[] = [
$s_size_options .= '<option value="' . $size_types[$i] . '"' . $selected . '>' . $size_types_text[$i] . '</option>'; 'value' => $size_types[$i],
'selected' => $size_compare == $size_types[$i],
'label' => $size_types_text[$i],
];
} }
return $s_size_options; return $size_options;
} }
/** /**

View file

@ -111,9 +111,9 @@ function phpbb_clean_path($path)
*/ */
function tz_select($default = '', $truncate = false) function tz_select($default = '', $truncate = false)
{ {
global $template, $user; global $user;
return phpbb_timezone_select($template, $user, $default, $truncate); return phpbb_timezone_select($user, $default, $truncate);
} }
/** /**

View file

@ -156,7 +156,7 @@ class ucp_prefs
} }
$dateformat_options .= '>' . $user->lang['CUSTOM_DATEFORMAT'] . '</option>'; $dateformat_options .= '>' . $user->lang['CUSTOM_DATEFORMAT'] . '</option>';
phpbb_timezone_select($template, $user, $data['tz'], true); $timezone_select = phpbb_timezone_select($user, $data['tz'], true);
// check if there are any user-selectable languages // check if there are any user-selectable languages
$sql = 'SELECT lang_iso, lang_local_name $sql = 'SELECT lang_iso, lang_local_name
@ -177,6 +177,8 @@ class ucp_prefs
$db->sql_freeresult($result); $db->sql_freeresult($result);
$s_more_styles = count($styles_row) > 1; $s_more_styles = count($styles_row) > 1;
$lang_options = phpbb_language_select($db, $data['lang'], $lang_row);
$template->assign_vars(array( $template->assign_vars(array(
'ERROR' => (count($error)) ? implode('<br />', $error) : '', 'ERROR' => (count($error)) ? implode('<br />', $error) : '',
@ -198,8 +200,17 @@ class ucp_prefs
'S_MORE_LANGUAGES' => $s_more_languages, 'S_MORE_LANGUAGES' => $s_more_languages,
'S_MORE_STYLES' => $s_more_styles, 'S_MORE_STYLES' => $s_more_styles,
'S_LANG_OPTIONS' => language_select($data['lang'], $lang_row), 'LANG_OPTIONS' => [
'id' => 'lang',
'name' => 'lang',
'options' => $lang_options,
],
'S_STYLE_OPTIONS' => ($config['override_user_style']) ? '' : style_select($data['user_style'], false, $styles_row), 'S_STYLE_OPTIONS' => ($config['override_user_style']) ? '' : style_select($data['user_style'], false, $styles_row),
'TIMEZONE_OPTIONS' => [
'tag' => 'select',
'name' => 'tz',
'options' => $timezone_select,
],
'S_CAN_HIDE_ONLINE' => ($auth->acl_get('u_hideonline')) ? true : false, '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_SELECT_NOTIFY' => ($config['jab_enable'] && $user->data['user_jabber'] && @extension_loaded('xml')) ? true : false)
); );

View file

@ -157,6 +157,8 @@ class ucp_register
$lang_row = (array) $db->sql_fetchrowset($result); $lang_row = (array) $db->sql_fetchrowset($result);
$db->sql_freeresult($result); $db->sql_freeresult($result);
$lang_options = phpbb_language_select($db, $user_lang, $lang_row);
if ($coppa === false && $config['coppa_enable']) if ($coppa === false && $config['coppa_enable'])
{ {
$now = getdate(); $now = getdate();
@ -167,7 +169,11 @@ class ucp_register
unset($now); unset($now);
$template_vars = array( $template_vars = array(
'S_LANG_OPTIONS' => (count($lang_row) > 1) ? language_select($user_lang, $lang_row) : '', 'LANG_OPTIONS' => [
'id' => 'lang',
'name' => 'lang',
'options' => $lang_options,
],
'L_COPPA_NO' => $user->lang('UCP_COPPA_BEFORE', $coppa_birthday), 'L_COPPA_NO' => $user->lang('UCP_COPPA_BEFORE', $coppa_birthday),
'L_COPPA_YES' => $user->lang('UCP_COPPA_ON_AFTER', $coppa_birthday), 'L_COPPA_YES' => $user->lang('UCP_COPPA_ON_AFTER', $coppa_birthday),
@ -182,7 +188,11 @@ class ucp_register
else else
{ {
$template_vars = array( $template_vars = array(
'S_LANG_OPTIONS' => (count($lang_row) > 1) ? language_select($user_lang, $lang_row) : '', 'LANG_OPTIONS' => [
'id' => 'lang',
'name' => 'lang',
'options' => $lang_options,
],
'L_TERMS_OF_USE' => sprintf($user->lang['TERMS_OF_USE_CONTENT'], $config['sitename'], generate_board_url()), 'L_TERMS_OF_USE' => sprintf($user->lang['TERMS_OF_USE_CONTENT'], $config['sitename'], generate_board_url()),
'S_SHOW_COPPA' => false, 'S_SHOW_COPPA' => false,
@ -616,7 +626,7 @@ class ucp_register
} }
// Assign template vars for timezone select // Assign template vars for timezone select
phpbb_timezone_select($template, $user, $data['tz'], true); $timezone_select = phpbb_timezone_select($user, $data['tz'], true);
// Checking amount of available languages // Checking amount of available languages
$sql = 'SELECT lang_iso, lang_local_name $sql = 'SELECT lang_iso, lang_local_name
@ -626,6 +636,8 @@ class ucp_register
$lang_row = (array) $db->sql_fetchrowset($result); $lang_row = (array) $db->sql_fetchrowset($result);
$db->sql_freeresult($result); $db->sql_freeresult($result);
$lang_options = phpbb_language_select($db, $data['lang'], $lang_row);
$template_vars = array( $template_vars = array(
'USERNAME' => $data['username'], 'USERNAME' => $data['username'],
'PASSWORD' => $data['new_password'], 'PASSWORD' => $data['new_password'],
@ -636,7 +648,16 @@ class ucp_register
'L_USERNAME_EXPLAIN' => $user->lang($config['allow_name_chars'] . '_EXPLAIN', $user->lang('CHARACTERS', (int) $config['min_name_chars']), $user->lang('CHARACTERS', (int) $config['max_name_chars'])), 'L_USERNAME_EXPLAIN' => $user->lang($config['allow_name_chars'] . '_EXPLAIN', $user->lang('CHARACTERS', (int) $config['min_name_chars']), $user->lang('CHARACTERS', (int) $config['max_name_chars'])),
'L_PASSWORD_EXPLAIN' => $user->lang($config['pass_complex'] . '_EXPLAIN', $user->lang('CHARACTERS', (int) $config['min_pass_chars'])), 'L_PASSWORD_EXPLAIN' => $user->lang($config['pass_complex'] . '_EXPLAIN', $user->lang('CHARACTERS', (int) $config['min_pass_chars'])),
'S_LANG_OPTIONS' => (count($lang_row) > 1) ? language_select($data['lang'], $lang_row) : '', 'LANG_OPTIONS' => [
'id' => 'lang',
'name' => 'lang',
'options' => $lang_options,
],
'TIMEZONE_OPTIONS' => [
'tag' => 'select',
'name' => 'tz',
'options' => $timezone_select,
],
'S_TZ_PRESELECT' => !$submit, 'S_TZ_PRESELECT' => !$submit,
'S_CONFIRM_REFRESH' => ($config['enable_confirm'] && $config['confirm_refresh']) ? true : false, 'S_CONFIRM_REFRESH' => ($config['enable_confirm'] && $config['confirm_refresh']) ? true : false,
'S_REGISTRATION' => true, 'S_REGISTRATION' => true,

View file

@ -86,52 +86,10 @@ if (($mark_notification = $request->variable('mark_notification', 0)))
display_forums('', $config['load_moderators']); display_forums('', $config['load_moderators']);
$order_legend = ($config['legend_sort_groupname']) ? 'group_name' : 'group_legend';
// Grab group details for legend display
if ($auth->acl_gets('a_group', 'a_groupadd', 'a_groupdel'))
{
$sql = 'SELECT group_id, group_name, group_colour, group_type, group_legend
FROM ' . GROUPS_TABLE . '
WHERE group_legend > 0
ORDER BY ' . $order_legend . ' ASC';
}
else
{
$sql = 'SELECT g.group_id, g.group_name, g.group_colour, g.group_type, g.group_legend
FROM ' . GROUPS_TABLE . ' g
LEFT JOIN ' . USER_GROUP_TABLE . ' ug
ON (
g.group_id = ug.group_id
AND ug.user_id = ' . $user->data['user_id'] . '
AND ug.user_pending = 0
)
WHERE g.group_legend > 0
AND (g.group_type <> ' . GROUP_HIDDEN . ' OR ug.user_id = ' . $user->data['user_id'] . ')
ORDER BY g.' . $order_legend . ' ASC';
}
$result = $db->sql_query($sql);
/** @var \phpbb\group\helper $group_helper */ /** @var \phpbb\group\helper $group_helper */
$group_helper = $phpbb_container->get('group_helper'); $group_helper = $phpbb_container->get('group_helper');
$legend = array(); $group_helper->display_legend($db, $template);
while ($row = $db->sql_fetchrow($result))
{
$colour_text = ($row['group_colour']) ? ' style="color:#' . $row['group_colour'] . '"' : '';
$group_name = $group_helper->get_name($row['group_name']);
if ($row['group_name'] == 'BOTS' || ($user->data['user_id'] != ANONYMOUS && !$auth->acl_get('u_viewprofile')))
{
$legend[] = '<span' . $colour_text . '>' . $group_name . '</span>';
}
else
{
$legend[] = '<a' . $colour_text . ' href="' . append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=group&amp;g=' . $row['group_id']) . '">' . $group_name . '</a>';
}
}
$db->sql_freeresult($result);
$legend = implode($user->lang['COMMA_SEPARATOR'], $legend);
// Generate birthday list if required ... // Generate birthday list if required ...
$show_birthdays = ($config['load_birthdays'] && $config['allow_birthdays'] && $auth->acl_gets('u_viewprofile', 'a_user', 'a_useradd', 'a_userdel')); $show_birthdays = ($config['load_birthdays'] && $config['allow_birthdays'] && $auth->acl_gets('u_viewprofile', 'a_user', 'a_useradd', 'a_userdel'));
@ -219,7 +177,6 @@ $template->assign_vars(array(
'TOTAL_USERS' => $user->lang('TOTAL_USERS', (int) $config['num_users']), 'TOTAL_USERS' => $user->lang('TOTAL_USERS', (int) $config['num_users']),
'NEWEST_USER' => $user->lang('NEWEST_USER', get_username_string('full', $config['newest_user_id'], $config['newest_username'], $config['newest_user_colour'])), 'NEWEST_USER' => $user->lang('NEWEST_USER', get_username_string('full', $config['newest_user_id'], $config['newest_username'], $config['newest_user_colour'])),
'LEGEND' => $legend,
'BIRTHDAY_LIST' => (empty($birthday_list)) ? '' : implode($user->lang['COMMA_SEPARATOR'], $birthday_list), 'BIRTHDAY_LIST' => (empty($birthday_list)) ? '' : implode($user->lang['COMMA_SEPARATOR'], $birthday_list),
'S_LOGIN_ACTION' => append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=login'), 'S_LOGIN_ACTION' => append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=login'),

View file

@ -17,9 +17,11 @@ use phpbb\auth\auth;
use phpbb\avatar\helper as avatar_helper; use phpbb\avatar\helper as avatar_helper;
use phpbb\cache\service as cache; use phpbb\cache\service as cache;
use phpbb\config\config; use phpbb\config\config;
use phpbb\db\driver\driver_interface;
use phpbb\language\language; use phpbb\language\language;
use phpbb\event\dispatcher_interface; use phpbb\event\dispatcher_interface;
use phpbb\path_helper; use phpbb\path_helper;
use phpbb\template\template;
use phpbb\user; use phpbb\user;
class helper class helper
@ -294,8 +296,56 @@ class helper
* *
* @return array Avatar data * @return array Avatar data
*/ */
function get_avatar($group_row, $alt = 'GROUP_AVATAR', $ignore_config = false, $lazy = false) public function get_avatar($group_row, $alt = 'GROUP_AVATAR', $ignore_config = false, $lazy = false)
{ {
return $this->avatar_helper->get_group_avatar($group_row, $alt, $ignore_config, $lazy); return $this->avatar_helper->get_group_avatar($group_row, $alt, $ignore_config, $lazy);
} }
/**
* Display groups legend
*
* @param driver_interface $db
* @param template $template
* @return void
*/
public function display_legend(driver_interface $db, template $template): void
{
$order_legend = $this->config['legend_sort_groupname'] ? 'group_name' : 'group_legend';
// Grab group details for legend display
if ($this->auth->acl_gets('a_group', 'a_groupadd', 'a_groupdel'))
{
$sql = 'SELECT group_id, group_name, group_colour, group_type, group_legend
FROM ' . GROUPS_TABLE . '
WHERE group_legend > 0
ORDER BY ' . $order_legend . ' ASC';
}
else
{
$sql = 'SELECT g.group_id, g.group_name, g.group_colour, g.group_type, g.group_legend
FROM ' . GROUPS_TABLE . ' g
LEFT JOIN ' . USER_GROUP_TABLE . ' ug
ON (
g.group_id = ug.group_id
AND ug.user_id = ' . $this->user->data['user_id'] . '
AND ug.user_pending = 0
)
WHERE g.group_legend > 0
AND (g.group_type <> ' . GROUP_HIDDEN . ' OR ug.user_id = ' . $this->user->data['user_id'] . ')
ORDER BY g.' . $order_legend . ' ASC';
}
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result))
{
$show_group_url = $row['group_name'] != 'BOTS' && $this->auth->acl_get('u_viewprofile');
$template->assign_block_vars('LEGEND', [
'GROUP_COLOR' => $row['group_colour'] ?: '',
'GROUP_NAME' => $this->get_name($row['group_name']),
'GROUP_URL' => $show_group_url ? append_sid("{$this->path_helper->get_phpbb_root_path()}memberlist.{$this->path_helper->get_php_ext()}", 'mode=group&amp;g=' . $row['group_id']) : '',
]);
}
$db->sql_freeresult($result);
}
} }

View file

@ -153,10 +153,17 @@ class topic_form extends form
parent::render($template); parent::render($template);
$this->user->add_lang('viewtopic'); $this->user->add_lang('viewtopic');
$lang_options = phpbb_language_select($this->db, $this->recipient_lang);
$template->assign_vars(array( $template->assign_vars(array(
'EMAIL' => $this->recipient_address, 'EMAIL' => $this->recipient_address,
'NAME' => $this->recipient_name, 'NAME' => $this->recipient_name,
'S_LANG_OPTIONS' => language_select($this->recipient_lang), 'LANG_OPTIONS' => [
'id' => 'lang',
'name' => 'lang',
'options' => $lang_options,
],
'MESSAGE' => $this->body, 'MESSAGE' => $this->body,
'L_EMAIL_BODY_EXPLAIN' => $this->user->lang['EMAIL_TOPIC_EXPLAIN'], 'L_EMAIL_BODY_EXPLAIN' => $this->user->lang['EMAIL_TOPIC_EXPLAIN'],

View file

@ -0,0 +1,221 @@
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
namespace phpbb\template\twig\extension;
use phpbb\template\twig\environment;
use phpbb\user;
use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;
class forms extends AbstractExtension
{
/** @var user */
protected $user;
/**
* Constructor.
*
* @param user $user User object
*/
public function __construct(user $user)
{
$this->user = $user;
}
/**
* Returns the name of this extension.
*
* @return string The extension name
*/
public function getName()
{
return 'forms';
}
/**
* Returns a list of functions to add to the existing list.
*
* @return TwigFunction[] Array of twig functions
*/
public function getFunctions(): array
{
return [
new TwigFunction('FormsBuildTemplate', [$this, 'build_template'], ['needs_environment' => true]),
new TwigFunction('FormsDimension', [$this, 'dimension'], ['needs_environment' => true]),
new TwigFunction('FormsInput', [$this, 'input'], ['needs_environment' => true]),
new TwigFunction('FormsRadioButtons', [$this, 'radio_buttons'], ['needs_environment' => true]),
new TwigFunction('FormsSelect', [$this, 'select'], ['needs_environment' => true]),
new TwigFunction('FormsTextarea', [$this, 'textarea'], ['needs_environment' => true]),
];
}
/**
* Renders a form template
*
* @param environment $environment
* @param array $form_data
*
* @return string Rendered form template
*/
public function build_template(environment $environment, array $form_data): string
{
try
{
return $environment->render('macros/forms/build_template.twig', [
'form_data' => $form_data ?? [],
]);
}
catch (\Twig\Error\Error $e)
{
return '';
}
}
/**
* Renders form dimension fields
*
* @param environment $environment The twig environment
* @param array $form_data The form data
*
* @return string Form dimension fields
*/
public function dimension(environment $environment, array $form_data): string
{
try
{
return $environment->render('macros/forms/dimension.twig', [
'WIDTH' => $form_data['width'],
'HEIGHT' => $form_data['height'],
]);
}
catch (\Twig\Error\Error $e)
{
return '';
}
}
/**
* Renders a form input field
*
* @param environment $environment The twig environment
* @param array $form_data The form data
*
* @return string Form input field
*/
public function input(environment $environment, array $form_data): string
{
try
{
return $environment->render('macros/forms/input.twig', [
'ID' => (string) ($form_data['id'] ?? ''),
'TYPE' => (string) $form_data['type'],
'NAME' => (string) $form_data['name'],
'SIZE' => (int) ($form_data['size'] ?? 0),
'MAXLENGTH' => (int) ($form_data['maxlength'] ?? 0),
'MIN' => (int) ($form_data['min'] ?? 0),
'MAX' => (int) ($form_data['max'] ?? 0),
'STEP' => (int) ($form_data['step'] ?? 0),
'CHECKED' => (bool) ($form_data['checked'] ?? false),
'CLASS' => (string) ($form_data['class'] ?? ''),
'VALUE' => (string) ($form_data['value']),
'DATA' => $form_data['data'] ?? [],
]);
}
catch (\Twig\Error\Error $e)
{
return '';
}
}
/**
* Renders form radio buttons
*
* @param environment $environment The twig environment
* @param array $form_data The form data
*
* @return string Form radio buttons
*/
public function radio_buttons(environment $environment, array $form_data): string
{
try
{
return $environment->render('macros/forms/radio_buttons.twig', [
'FIRST_BUTTON' => $form_data['buttons'][0],
'FIRST_BUTTON_LABEL' => $form_data['buttons'][0]['label'],
'SECOND_BUTTON' => $form_data['buttons'][1],
'SECOND_BUTTON_LABEL' => $form_data['buttons'][1]['label'],
]);
}
catch (\Twig\Error\Error $e)
{
return '';
}
}
/**
* Renders a form select field
*
* @param environment $environment The twig environment
* @param array $form_data The form data
*
* @return string Form select field
*/
public function select(environment $environment, array $form_data): string
{
try
{
return $environment->render('macros/forms/select.twig', [
'ID' => (string) ($form_data['id'] ?? ''),
'CLASS' => (string) ($form_data['class'] ?? ''),
'NAME' => (string) $form_data['name'],
'TOGGLEABLE' => (bool) ($form_data['toggleable'] ?? false),
'OPTIONS' => $form_data['options'] ?? [],
'GROUP_ONLY' => (bool) ($form_data['group_only'] ?? false),
'DATA' => $form_data['data'] ?? [],
'SIZE' => (int) ($form_data['size'] ?? 0),
'MULTIPLE' => (bool) ($form_data['multiple'] ?? false),
]);
}
catch (\Twig\Error\Error $e)
{
return '';
}
}
/**
* Renders a form textarea field
*
* @param environment $environment
* @param array $form_data
*
* @return string Form textarea field
*/
public function textarea(environment $environment, array $form_data): string
{
try
{
return $environment->render('macros/forms/textarea.twig', [
'ID' => (string) $form_data['id'],
'NAME' => (string) $form_data['name'],
'ROWS' => (int) $form_data['rows'],
'COLS' => (int) $form_data['cols'],
'CONTENT' => (string) $form_data['content'],
]);
}
catch (\Twig\Error\Error $e)
{
return '';
}
}
}

View file

@ -0,0 +1,16 @@
{% if form_data.tag == 'input' %}
{{ FormsInput(form_data) }}
{% elseif form_data.tag == 'dimension' %}
{{ FormsDimension(form_data) }}
{% elseif form_data.tag == 'radio' %}
{{ FormsRadioButtons(form_data) }}
{% elseif form_data.tag == 'select' %}
{{ FormsSelect(form_data) }}
{% elseif form_data.tag == 'textarea' %}
{{ FormsTextarea(form_data) }}
{% elseif form_data[0] %}
{% for element in form_data %}
{{ FormsBuildTemplate(element) }}
{% endfor %}
{% endif %}
{% if form_data.append %}{{ form_data.append }}{% endif %}

View file

@ -0,0 +1 @@
{{ FormsInput(WIDTH) }} x {{ FormsInput(HEIGHT) }}

View file

@ -0,0 +1,18 @@
{% apply replace({"\n": ' ', "\t": ''}) %}
<input
{% if ID %}id="{{ ID }}" {% endif %}
type="{{ TYPE }}"
name="{{ NAME }}"
{% if SIZE %}size="{{ SIZE }}" {% endif %}
{% if MAXLENGTH %}maxlength="{{ MAXLENGTH }}" {% endif %}
{% if MIN %}min="{{ MIN }}" {% endif %}
{% if MAX %}max="{{ MAX }}" {% endif %}
{% if STEP %}step="{{ STEP }}" {% endif %}
{% if TYPE == 'password' %}autocomplete="off" {% endif %}
{% if CHECKED %}checked="checked" {% endif %}
{% if CLASS %}class="{{ CLASS }}" {% endif %}
{% for attribute, attribute_value in DATA %}
data-{{ attribute|e }}="{{ attribute_value|e('html_attr') }}"
{% endfor %}
value="{{ VALUE }}">
{% endapply %}

View file

@ -0,0 +1,2 @@
<label>{{ FormsInput(FIRST_BUTTON) ~ FIRST_BUTTON_LABEL }}</label>
<label>{{ FormsInput(SECOND_BUTTON) ~ SECOND_BUTTON_LABEL }}</label>

View file

@ -0,0 +1,30 @@
{% apply replace({"\n": ' ', "\t": ''}) %}
<select
{% if ID %}id="{{ ID }}" {% endif %}
{% if CLASS %}class="{{ CLASS }}" {% endif %}
name="{{ NAME }}"
{% if TOGGLEABLE %}data-togglable-settings="true" {% endif %}
{% for attribute, attribute_value in DATA %}
data-{{ attribute|e }}="{{ attribute_value|e('html_attr') }}"
{% endfor %}
{% if MULTIPLE %}multiple="multiple" {% endif %}
{% if SIZE %}size="{{ SIZE }}" {% endif %}>
{% endapply %}
{% for element in OPTIONS %}
{% if not GROUP_ONLY and element.options %}
{% apply replace({"\n": ' ', '\t': ''}) %}
<optgroup
label="{{ element.label }}"
{% for key, value in element.data %}
data-{{ key }}="{{ value }}"
{% endfor %}>
{% endapply %}
{% for option in element.options %}
<option value="{{ option.value }}"{% if option.selected %} selected="selected"{% endif %}{% if option.disabled %} disabled="disabled" class="disabled-option"{% endif %}>{{ option.label }}</option>
{% endfor %}
</optgroup>
{% else %}
<option value="{{ element.value }}"{% if element.selected %} selected="selected"{% endif %}{% if element.disabled %} disabled="disabled" class="disabled-option"{% endif %}>{{ element.label }}</option>
{% endif %}
{% endfor %}
</select>

View file

@ -0,0 +1,9 @@
{% apply replace({"\n": ' ', '\t': ''}) %}
<textarea
id="{{ ID }}"
name="{{ NAME }}"
rows="{{ ROWS }}"
cols="{{ COLS }}">
{{ CONTENT }}
</textarea>
{% endapply %}

View file

@ -44,7 +44,21 @@
{TOTAL_USERS_ONLINE} ({L_ONLINE_EXPLAIN})<br />{RECORD_USERS}<br /> {TOTAL_USERS_ONLINE} ({L_ONLINE_EXPLAIN})<br />{RECORD_USERS}<br />
<!-- IF U_VIEWONLINE --> <!-- IF U_VIEWONLINE -->
<br />{LOGGED_IN_USER_LIST} <br />{LOGGED_IN_USER_LIST}
<!-- IF LEGEND --><br /><em>{L_LEGEND}{L_COLON} {LEGEND}</em><!-- ENDIF --> {% if LEGEND|length > 0 %}
{% apply spaceless %}
<br>
<em>
{{ lang('LEGEND') ~ lang('COLON') }}
{% for group in LEGEND %}
{% if group.GROUP_URL %}
<a style="color:#{{ group.GROUP_COLOR }}" href="{{ group.GROUP_URL }}" alt="{{ group.GROUP_NAME }}">{{ group.GROUP_NAME }}</a>{% if not loop.last %}, {% endif %}
{% else %}
<span style="color:#{{ group.GROUP_COLOR }}">{{ group.GROUP_NAME }}</span>{% if not loop.last %}, {% endif %}
{% endif %}
{% endfor %}
</em>
{% endapply %}
{% endif %}
<!-- ENDIF --> <!-- ENDIF -->
<!-- EVENT index_body_block_online_append --> <!-- EVENT index_body_block_online_append -->
</p> </p>

View file

@ -71,7 +71,13 @@
<dl> <dl>
<dt><label for="lang">{L_DEST_LANG}{L_COLON}</label><br /> <dt><label for="lang">{L_DEST_LANG}{L_COLON}</label><br />
<span>{L_DEST_LANG_EXPLAIN}</span></dt> <span>{L_DEST_LANG_EXPLAIN}</span></dt>
<dd><select name="lang" id="lang">{S_LANG_OPTIONS}</select></dd> <dd>
<select name="lang" id="lang">
{% for option in lang_options %}
<option value="{{ option.LANG_ISO }}"{% if option.SELECTED %} selected="selected"{% endif %}>{{ option.LANG_LOCAL_NAME }}</option>
{% endfor %}
</select>
</dd>
</dl> </dl>
<!-- ENDIF --> <!-- ENDIF -->
<dl> <dl>

View file

@ -1,28 +1,16 @@
<dl> <dl>
<dt><label for="timezone">{L_BOARD_TIMEZONE}{L_COLON}</label></dt> <dt><label for="timezone">{{ lang('BOARD_TIMEZONE') ~ lang('COLON') }}</label></dt>
<!-- IF .timezone_date --> {% if TIMEZONE_OPTIONS %}
<dd id="tz_select_date" style="display: none;"> <dd id="tz_select_date hidden">
<select name="tz_date" id="tz_date" class="autowidth tz_select"> {% set tz_date_data = TIMEZONE_OPTIONS | merge({ options: [{ value: "", label: lang('SELECT_CURRENT_TIME') }] | merge(TIMEZONE_OPTIONS.options) }) %}
<option value="">{L_SELECT_CURRENT_TIME}</option> {{ FormsSelect(tz_date_data | merge({class: 'autowidth tz_select', id: 'tz_date', name: 'tz_date', group_only: true})) }}
<!-- BEGIN timezone_date -->
<option value="{timezone_date.VALUE}"<!-- IF timezone_date.SELECTED --> selected="selected"<!-- ENDIF -->>{timezone_date.TITLE}</option>
<!-- END timezone_date -->
</select>
<input type="button" id="tz_select_date_suggest" class="button1 button button-form-bold" style="display: none;" timezone-preselect="<!-- IF S_TZ_PRESELECT -->true<!-- ELSE -->false<!-- ENDIF -->" data-l-suggestion="{L_TIMEZONE_DATE_SUGGESTION}" value="{L_TIMEZONE_DATE_SUGGESTION}" /> <input type="button" id="tz_select_date_suggest" class="button1 button button-form-bold" style="display: none;" timezone-preselect="<!-- IF S_TZ_PRESELECT -->true<!-- ELSE -->false<!-- ENDIF -->" data-l-suggestion="{L_TIMEZONE_DATE_SUGGESTION}" value="{L_TIMEZONE_DATE_SUGGESTION}" />
</dd> </dd>
<!-- ENDIF --> {% endif %}
<dd> <dd>
<select name="tz" id="timezone" class="autowidth tz_select timezone"> {% set tz_select_data = TIMEZONE_OPTIONS | merge({ options: [{ value: "", label: lang('SELECT_TIMEZONE') }] | merge(TIMEZONE_OPTIONS.options) }) %}
<option value="">{L_SELECT_TIMEZONE}</option> {{ FormsSelect(tz_select_data | merge({class: 'autowidth tz_select', id: 'timezone'})) }}
<!-- BEGIN timezone_select -->
<optgroup label="{timezone_select.LABEL}" data-tz-value="{timezone_select.VALUE}">
<!-- BEGIN timezone_options -->
<option title="{timezone_select.timezone_options.TITLE}" value="{timezone_select.timezone_options.VALUE}"<!-- IF timezone_select.timezone_options.SELECTED --> selected="selected"<!-- ENDIF -->>{timezone_select.timezone_options.LABEL}</option>
<!-- END timezone_options -->
</optgroup>
<!-- END timezone_select -->
</select>
<!-- INCLUDEJS timezone.js --> {% INCLUDEJS('timezone.js') %}
</dd> </dd>
</dl> </dl>

View file

@ -2,29 +2,29 @@
<!-- IF S_SHOW_COPPA or S_REGISTRATION --> <!-- IF S_SHOW_COPPA or S_REGISTRATION -->
<!-- IF S_LANG_OPTIONS --> {% if LANG_OPTIONS %}
<script>
/**
* Change language
*/
function change_language(lang_iso)
{
document.cookie = '{COOKIE_NAME}_lang=' + lang_iso + '; path={COOKIE_PATH}';
document.forms['register'].change_lang.value = lang_iso;
document.forms['register'].submit();
}
</script>
<form method="post" action="{S_UCP_ACTION}" id="register"> <form method="post" action="{S_UCP_ACTION}" id="register">
<p class="rightside"> <p class="rightside">
<label for="lang">{L_LANGUAGE}{L_COLON}</label><select name="lang" id="lang" onchange="change_language(this.value); return false;" title="{L_LANGUAGE}">{S_LANG_OPTIONS}</select> <label for="{{ LANG_OPTIONS.id }}">{{ lang('LANGUAGE') ~ lang('COLON') }}</label>
{{ FormsSelect(LANG_OPTIONS) }}
{S_HIDDEN_FIELDS} {S_HIDDEN_FIELDS}
</p> </p>
</form> </form>
<div class="clear"></div> <div class="clear"></div>
<!-- ENDIF --> <script>
/**
* Change language on change
*/
document.querySelector("{{ '#' ~ LANG_OPTIONS.id }}").addEventListener('change', (event) => {
const langIso = event.target.value;
document.cookie = '{{ COOKIE_NAME }}_lang=' + langIso + '; path={{ COOKIE_PATH }}';
document.forms['register'].change_lang.value = langIso;
document.forms['register'].submit();
});
</script>
{% endif %}
<form method="post" action="{S_UCP_ACTION}" id="agreement"> <form method="post" action="{S_UCP_ACTION}" id="agreement">

View file

@ -52,8 +52,10 @@
<!-- ENDIF --> <!-- ENDIF -->
<!-- IF S_MORE_LANGUAGES --> <!-- IF S_MORE_LANGUAGES -->
<dl> <dl>
<dt><label for="lang">{L_BOARD_LANGUAGE}{L_COLON}</label></dt> <dt><label for="{{ LANG_OPTIONS.id }}">{L_BOARD_LANGUAGE}{L_COLON}</label></dt>
<dd><select name="lang" id="lang">{S_LANG_OPTIONS}</select></dd> <dd>
{{ FormsSelect(LANG_OPTIONS) }}
</dd>
</dl> </dl>
<!-- ENDIF --> <!-- ENDIF -->
<!-- IF S_STYLE_OPTIONS and S_MORE_STYLES --> <!-- IF S_STYLE_OPTIONS and S_MORE_STYLES -->

View file

@ -57,11 +57,22 @@
<hr /> <hr />
<!-- EVENT ucp_register_options_before --> <!-- EVENT ucp_register_options_before -->
{% if S_LANG_OPTIONS %} {% if LANG_OPTIONS %}
<dl> <dl>
<dt><label for="lang">{{ lang('LANGUAGE') ~ lang('COLON') }}</label></dt> <dt><label for="{{ LANG_OPTIONS.id }}">{{ lang('LANGUAGE') ~ lang('COLON') }}</label></dt>
<dd><select name="lang" id="lang" onchange="change_language(this.value); return false;" tabindex="6" title="{{ lang('LANGUAGE') }}">{{ S_LANG_OPTIONS }}</select></dd> <dd>
{{ FormsSelect(LANG_OPTIONS) }}
</dd>
</dl> </dl>
<script>
/**
* Change language on change
*/
document.querySelector("{{ '#' ~ LANG_OPTIONS.id }}").addEventListener('change', (event) => {
change_language(event.target.value);
return false;
});
</script>
{% endif %} {% endif %}
<!-- INCLUDE timezone_option.html --> <!-- INCLUDE timezone_option.html -->

View file

@ -47,7 +47,22 @@
</div> </div>
</div> </div>
<!-- IF LEGEND --><p><em>{L_LEGEND}{L_COLON} {LEGEND}</em></p><!-- ENDIF --> {% if LEGEND|length > 0 %}
{% apply spaceless %}
<p>
<em>
{{ lang('LEGEND') ~ lang('COLON') }}
{% for group in LEGEND %}
{% if group.GROUP_URL %}
<a style="color:#{{ group.GROUP_COLOR }}" href="{{ group.GROUP_URL }}" alt="{{ group.GROUP_NAME }}">{{ group.GROUP_NAME }}</a>{% if not loop.last %}, {% endif %}
{% else %}
<span style="color:#{{ group.GROUP_COLOR }}">{{ group.GROUP_NAME }}</span>{% if not loop.last %}, {% endif %}
{% endif %}
{% endfor %}
</em>
</p>
{% endapply %}
{% endif %}
<div class="action-bar bar-bottom"> <div class="action-bar bar-bottom">
<div class="pagination"> <div class="pagination">

View file

@ -441,44 +441,7 @@ while ($row = $db->sql_fetchrow($result))
$db->sql_freeresult($result); $db->sql_freeresult($result);
unset($prev_id, $prev_ip); unset($prev_id, $prev_ip);
$order_legend = ($config['legend_sort_groupname']) ? 'group_name' : 'group_legend'; $group_helper->display_legend($db, $template);
// Grab group details for legend display
if ($auth->acl_gets('a_group', 'a_groupadd', 'a_groupdel'))
{
$sql = 'SELECT group_id, group_name, group_colour, group_type, group_legend
FROM ' . GROUPS_TABLE . '
WHERE group_legend > 0
ORDER BY ' . $order_legend . ' ASC';
}
else
{
$sql = 'SELECT g.group_id, g.group_name, g.group_colour, g.group_type, g.group_legend
FROM ' . GROUPS_TABLE . ' g
LEFT JOIN ' . USER_GROUP_TABLE . ' ug
ON (
g.group_id = ug.group_id
AND ug.user_id = ' . $user->data['user_id'] . '
AND ug.user_pending = 0
)
WHERE g.group_legend > 0
AND (g.group_type <> ' . GROUP_HIDDEN . ' OR ug.user_id = ' . $user->data['user_id'] . ')
ORDER BY g.' . $order_legend . ' ASC';
}
$result = $db->sql_query($sql);
$legend = '';
while ($row = $db->sql_fetchrow($result))
{
if ($row['group_name'] == 'BOTS')
{
$legend .= (($legend != '') ? ', ' : '') . '<span style="color:#' . $row['group_colour'] . '">' . $user->lang['G_BOTS'] . '</span>';
}
else
{
$legend .= (($legend != '') ? ', ' : '') . '<a style="color:#' . $row['group_colour'] . '" href="' . append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=group&amp;g=' . $row['group_id']) . '">' . $group_helper->get_name($row['group_name']) . '</a>';
}
}
$db->sql_freeresult($result);
// Refreshing the page every 60 seconds... // Refreshing the page every 60 seconds...
meta_refresh(60, append_sid("{$phpbb_root_path}viewonline.$phpEx", "sg=$show_guests&amp;sk=$sort_key&amp;sd=$sort_dir&amp;start=$start")); meta_refresh(60, append_sid("{$phpbb_root_path}viewonline.$phpEx", "sg=$show_guests&amp;sk=$sort_key&amp;sd=$sort_dir&amp;start=$start"));

View file

@ -20,12 +20,68 @@ class phpbb_functions_language_select_test extends phpbb_database_test_case
public static function language_select_data() public static function language_select_data()
{ {
return array( return [
array('', '<option value="cs">Čeština</option><option value="en">English</option>'), [
array('en', '<option value="cs">Čeština</option><option value="en" selected="selected">English</option>'), '',
array('cs', '<option value="cs" selected="selected">Čeština</option><option value="en">English</option>'), [
array('de', '<option value="cs">Čeština</option><option value="en">English</option>'), [
); 'selected' => false,
'value' => 'cs',
'label' => 'Čeština',
],
[
'selected' => false,
'value' => 'en',
'label' => 'English',
],
]
],
[
'en',
[
[
'selected' => false,
'value' => 'cs',
'label' => 'Čeština',
],
[
'selected' => true,
'value' => 'en',
'label' => 'English',
],
]
],
[
'cs',
[
[
'selected' => true,
'value' => 'cs',
'label' => 'Čeština',
],
[
'selected' => false,
'value' => 'en',
'label' => 'English',
],
]
],
[
'de',
[
[
'selected' => false,
'value' => 'cs',
'label' => 'Čeština',
],
[
'selected' => false,
'value' => 'en',
'label' => 'English',
],
]
],
];
} }
/** /**
@ -36,6 +92,8 @@ class phpbb_functions_language_select_test extends phpbb_database_test_case
global $db; global $db;
$db = $this->new_dbal(); $db = $this->new_dbal();
$this->assertEquals($expected, language_select($default)); $lang_options = phpbb_language_select($db, $default);
$this->assertEquals($expected, $lang_options);
} }
} }

View file

@ -24,7 +24,15 @@ class phpbb_functions_acp_build_cfg_template_test extends phpbb_test_case
array('config_key_name' => '1'), array('config_key_name' => '1'),
'config_key_name', 'config_key_name',
array(), array(),
'<input id="key_name" type="text" size="20" maxlength="255" name="config[config_key_name]" value="1" />', [
'tag' => 'input',
'id' => 'key_name',
'type' => 'text',
'name' => 'config[config_key_name]',
'size' => 20,
'maxlength' => 255,
'value' => '1',
],
), ),
array( array(
array('password', 20, 128), array('password', 20, 128),
@ -32,7 +40,15 @@ class phpbb_functions_acp_build_cfg_template_test extends phpbb_test_case
array('config_key_name' => '2'), array('config_key_name' => '2'),
'config_key_name', 'config_key_name',
array(), array(),
'<input id="key_name" type="password" size="20" maxlength="128" name="config[config_key_name]" value="********" autocomplete="off" />', [
'tag' => 'input',
'id' => 'key_name',
'type' => 'password',
'name' => 'config[config_key_name]',
'size' => 20,
'maxlength' => 128,
'value' => '********',
],
), ),
array( array(
array('text', 0, 255), array('text', 0, 255),
@ -40,7 +56,15 @@ class phpbb_functions_acp_build_cfg_template_test extends phpbb_test_case
array('config_key_name' => '3'), array('config_key_name' => '3'),
'config_key_name', 'config_key_name',
array(), array(),
'<input id="key_name" type="text" maxlength="255" name="config[config_key_name]" value="3" />', [
'tag' => 'input',
'id' => 'key_name',
'type' => 'text',
'name' => 'config[config_key_name]',
'maxlength' => 255,
'value' => '3',
'size' => '',
],
), ),
); );
} }
@ -50,11 +74,12 @@ class phpbb_functions_acp_build_cfg_template_test extends phpbb_test_case
*/ */
public function test_build_cfg_template_text($tpl_type, $key, $new, $config_key, $vars, $expected) public function test_build_cfg_template_text($tpl_type, $key, $new, $config_key, $vars, $expected)
{ {
global $user, $phpbb_dispatcher; global $user, $phpbb_dispatcher, $language;
$phpbb_dispatcher = new phpbb_mock_event_dispatcher(); $phpbb_dispatcher = new phpbb_mock_event_dispatcher();
$user = new phpbb_mock_user(); $user = new phpbb_mock_user();
$user->lang = new phpbb_mock_lang(); $language = new phpbb_mock_lang();
$user->lang = $language;
$this->assertEquals($expected, build_cfg_template($tpl_type, $key, $new, $config_key, $vars)); $this->assertEquals($expected, build_cfg_template($tpl_type, $key, $new, $config_key, $vars));
} }
@ -68,7 +93,24 @@ class phpbb_functions_acp_build_cfg_template_test extends phpbb_test_case
array('config_key_name_width' => 10, 'config_key_name_height' => 20), array('config_key_name_width' => 10, 'config_key_name_height' => 20),
'config_key_name', 'config_key_name',
array(), array(),
'<input id="number_key_name" type="number" min="5" max="15" name="config[config_key_name_width]" value="10" /> x <input type="number" min="5" max="15" name="config[config_key_name_height]" value="20" />', [
'tag' => 'dimension',
'width' => [
'id' => 'number_key_name',
'type' => 'number',
'name' => 'config[config_key_name_width]',
'min' => 5,
'max' => 15,
'value' => 10,
],
'height' => [
'type' => 'number',
'name' => 'config[config_key_name_height]',
'min' => 5,
'max' => 15,
'value' => 20,
],
],
), ),
array( array(
array('dimension', 0, 15), array('dimension', 0, 15),
@ -76,7 +118,24 @@ class phpbb_functions_acp_build_cfg_template_test extends phpbb_test_case
array('config_key_name_width' => 10, 'config_key_name_height' => 20), array('config_key_name_width' => 10, 'config_key_name_height' => 20),
'config_key_name', 'config_key_name',
array(), array(),
'<input id="number_key_name" type="number" min="0" max="15" name="config[config_key_name_width]" value="10" /> x <input type="number" min="0" max="15" name="config[config_key_name_height]" value="20" />', [
'tag' => 'dimension',
'width' => [
'id' => 'number_key_name',
'type' => 'number',
'name' => 'config[config_key_name_width]',
'min' => 0,
'max' => 15,
'value' => 10,
],
'height' => [
'type' => 'number',
'name' => 'config[config_key_name_height]',
'min' => 0,
'max' => 15,
'value' => 20,
],
],
), ),
); );
} }
@ -104,7 +163,15 @@ class phpbb_functions_acp_build_cfg_template_test extends phpbb_test_case
array('config_key_name' => 10), array('config_key_name' => 10),
'config_key_name', 'config_key_name',
array(), array(),
'<input id="number_key_name" type="number" min="5" max="15" name="config[config_key_name]" value="10" />', [
'tag' => 'input',
'id' => 'number_key_name',
'type' => 'number',
'name' => 'config[config_key_name]',
'min' => 5,
'max' => 15,
'value' => 10,
],
), ),
array( array(
array('number', -1, 9999), array('number', -1, 9999),
@ -112,7 +179,15 @@ class phpbb_functions_acp_build_cfg_template_test extends phpbb_test_case
array('config_key_name' => 10), array('config_key_name' => 10),
'config_key_name', 'config_key_name',
array(), array(),
'<input id="number_key_name" type="number" min="-1" max="9999" name="config[config_key_name]" value="10" />', [
'tag' => 'input',
'id' => 'number_key_name',
'type' => 'number',
'name' => 'config[config_key_name]',
'min' => -1,
'max' => 9999,
'value' => 10,
],
), ),
array( array(
array('number', 0, 9999), array('number', 0, 9999),
@ -120,7 +195,15 @@ class phpbb_functions_acp_build_cfg_template_test extends phpbb_test_case
array('config_key_name' => 10), array('config_key_name' => 10),
'config_key_name', 'config_key_name',
array(), array(),
'<input id="number_key_name" type="number" min="0" max="9999" name="config[config_key_name]" value="10" />', [
'tag' => 'input',
'id' => 'number_key_name',
'type' => 'number',
'name' => 'config[config_key_name]',
'min' => 0,
'max' => 9999,
'value' => 10,
],
), ),
); );
} }
@ -148,7 +231,14 @@ class phpbb_functions_acp_build_cfg_template_test extends phpbb_test_case
array('config_key_name' => 'phpBB'), array('config_key_name' => 'phpBB'),
'config_key_name', 'config_key_name',
array(), array(),
'<textarea id="key_name" name="config[config_key_name]" rows="5" cols="30">phpBB</textarea>', [
'tag' => 'textarea',
'id' => 'key_name',
'name' => 'config[config_key_name]',
'rows' => 5,
'cols' => 30,
'content' => 'phpBB',
]
), ),
); );
} }
@ -176,7 +266,26 @@ class phpbb_functions_acp_build_cfg_template_test extends phpbb_test_case
array('config_key_name' => '0'), array('config_key_name' => '0'),
'config_key_name', 'config_key_name',
array(), array(),
'<label><input type="radio" id="key_name" name="config[config_key_name]" value="1" class="radio" /> ENABLED</label><label><input type="radio" name="config[config_key_name]" value="0" checked="checked" class="radio" /> DISABLED</label>', [
'tag' => 'radio',
'buttons' => [
[
'id' => 'key_name',
'type' => 'radio',
'value' => 1,
'name' => 'config[config_key_name]',
'label' => 'ENABLED',
'checked' => false,
],
[
'type' => 'radio',
'value' => 0,
'checked' => true,
'name' => 'config[config_key_name]',
'label' => 'DISABLED',
],
],
],
), ),
array( array(
array('radio', 'enabled_disabled'), array('radio', 'enabled_disabled'),
@ -184,7 +293,26 @@ class phpbb_functions_acp_build_cfg_template_test extends phpbb_test_case
array('config_key_name' => '1'), array('config_key_name' => '1'),
'config_key_name', 'config_key_name',
array(), array(),
'<label><input type="radio" id="key_name" name="config[config_key_name]" value="1" checked="checked" class="radio" /> ENABLED</label><label><input type="radio" name="config[config_key_name]" value="0" class="radio" /> DISABLED</label>', [
'tag' => 'radio',
'buttons' => [
[
'id' => 'key_name',
'type' => 'radio',
'value' => 1,
'name' => 'config[config_key_name]',
'label' => 'ENABLED',
'checked' => true,
],
[
'type' => 'radio',
'value' => 0,
'checked' => false,
'name' => 'config[config_key_name]',
'label' => 'DISABLED',
],
],
],
), ),
array( array(
array('radio', 'yes_no'), array('radio', 'yes_no'),
@ -192,7 +320,26 @@ class phpbb_functions_acp_build_cfg_template_test extends phpbb_test_case
array('config_key_name' => '0'), array('config_key_name' => '0'),
'config_key_name', 'config_key_name',
array(), array(),
'<label><input type="radio" id="key_name" name="config[config_key_name]" value="1" class="radio" /> YES</label><label><input type="radio" name="config[config_key_name]" value="0" checked="checked" class="radio" /> NO</label>', [
'tag' => 'radio',
'buttons' => [
[
'id' => 'key_name',
'type' => 'radio',
'value' => 1,
'name' => 'config[config_key_name]',
'label' => 'YES',
'checked' => false,
],
[
'type' => 'radio',
'value' => 0,
'checked' => true,
'name' => 'config[config_key_name]',
'label' => 'NO',
],
],
],
), ),
array( array(
array('radio', 'yes_no'), array('radio', 'yes_no'),
@ -200,7 +347,26 @@ class phpbb_functions_acp_build_cfg_template_test extends phpbb_test_case
array('config_key_name' => '1'), array('config_key_name' => '1'),
'config_key_name', 'config_key_name',
array(), array(),
'<label><input type="radio" id="key_name" name="config[config_key_name]" value="1" checked="checked" class="radio" /> YES</label><label><input type="radio" name="config[config_key_name]" value="0" class="radio" /> NO</label>', [
'tag' => 'radio',
'buttons' => [
[
'id' => 'key_name',
'type' => 'radio',
'value' => 1,
'name' => 'config[config_key_name]',
'label' => 'YES',
'checked' => true,
],
[
'type' => 'radio',
'value' => 0,
'checked' => false,
'name' => 'config[config_key_name]',
'label' => 'NO',
],
],
],
), ),
); );
} }
@ -210,11 +376,10 @@ class phpbb_functions_acp_build_cfg_template_test extends phpbb_test_case
*/ */
public function test_build_cfg_template_radio($tpl_type, $key, $new, $config_key, $vars, $expected) public function test_build_cfg_template_radio($tpl_type, $key, $new, $config_key, $vars, $expected)
{ {
global $user, $phpbb_dispatcher; global $language, $phpbb_dispatcher;
$phpbb_dispatcher = new phpbb_mock_event_dispatcher(); $phpbb_dispatcher = new phpbb_mock_event_dispatcher();
$user = new phpbb_mock_user(); $language = new \phpbb_mock_lang();
$user->lang = new phpbb_mock_lang();
$this->assertEquals($expected, build_cfg_template($tpl_type, $key, $new, $config_key, $vars)); $this->assertEquals($expected, build_cfg_template($tpl_type, $key, $new, $config_key, $vars));
} }
@ -228,7 +393,15 @@ class phpbb_functions_acp_build_cfg_template_test extends phpbb_test_case
array('config_key_name' => 'phpBB'), array('config_key_name' => 'phpBB'),
'config_key_name', 'config_key_name',
array('append' => 'Bertie is cool!'), array('append' => 'Bertie is cool!'),
'<textarea id="key_name" name="config[config_key_name]" rows="5" cols="30">phpBB</textarea>Bertie is cool!', [
'tag' => 'textarea',
'id' => 'key_name',
'name' => 'config[config_key_name]',
'rows' => 5,
'cols' => 30,
'content' => 'phpBB',
'append' => 'Bertie is cool!',
]
), ),
); );
} }
@ -249,24 +422,69 @@ class phpbb_functions_acp_build_cfg_template_test extends phpbb_test_case
public function build_cfg_template_select_data() public function build_cfg_template_select_data()
{ {
return array( return [
array( [
array('select'), ['select'],
'key_name', 'key_name',
array('config_key_name' => '0'), ['config_key_name' => '0'],
'config_key_name', 'config_key_name',
array('method' => 'select_helper'), ['method' => 'select_helper'],
'<select id="key_name" name="config[config_key_name]"><option value="1">First_Option</option><option value="2" selected="selected">Second_Option</option><option value="3">Third_Option</option></select>', [
), 'tag' => 'select',
array( 'id' => 'key_name',
array('select', 8), 'name' => 'config[config_key_name]',
'options' => [
[
'value' => 1,
'label' => 'First_Option',
'selected' => false,
],
[
'value' => 2,
'label' => 'Second_Option',
'selected' => true,
],
[
'value' => 3,
'label' => 'Third_Option',
'selected' => false,
]
],
'toggleable' => false,
],
],
[
['select', 8],
'key_name', 'key_name',
array('config_key_name' => '1'), ['config_key_name' => '1'],
'config_key_name', 'config_key_name',
array('method' => 'select_helper'), ['method' => 'select_helper'],
'<select id="key_name" name="config[config_key_name]" size="8"><option value="1">First_Option</option><option value="2" selected="selected">Second_Option</option><option value="3">Third_Option</option></select>', [
), 'tag' => 'select',
); 'id' => 'key_name',
'name' => 'config[config_key_name]',
'size' => 8,
'options' => [
[
'value' => 1,
'label' => 'First_Option',
'selected' => false,
],
[
'value' => 2,
'label' => 'Second_Option',
'selected' => true,
],
[
'value' => 3,
'label' => 'Third_Option',
'selected' => false,
]
],
'toggleable' => false,
],
],
];
} }
/** /**
@ -274,11 +492,12 @@ class phpbb_functions_acp_build_cfg_template_test extends phpbb_test_case
*/ */
public function test_build_cfg_template_select($tpl_type, $key, $new, $config_key, $vars, $expected) public function test_build_cfg_template_select($tpl_type, $key, $new, $config_key, $vars, $expected)
{ {
global $module, $user, $phpbb_dispatcher; global $module, $user, $phpbb_dispatcher, $language;
$phpbb_dispatcher = new phpbb_mock_event_dispatcher(); $phpbb_dispatcher = new phpbb_mock_event_dispatcher();
$user = new phpbb_mock_user(); $user = new phpbb_mock_user();
$user->lang = new phpbb_mock_lang(); $language = new phpbb_mock_lang();
$user->lang = $language;
$user->module = $this; $user->module = $this;
$module = $user; $module = $user;

View file

@ -34,7 +34,18 @@ class phpbb_functions_acp_built_select_test extends phpbb_test_case
'second' => 'SEC_OPTION', 'second' => 'SEC_OPTION',
), ),
false, false,
'<option value="test">TEST</option><option value="second">SEC_OPTION</option>', [
[
'value' => 'test',
'label' => 'TEST',
'selected' => false,
],
[
'value' => 'second',
'label' => 'SEC_OPTION',
'selected' => false,
],
],
), ),
array( array(
array( array(
@ -42,7 +53,18 @@ class phpbb_functions_acp_built_select_test extends phpbb_test_case
'second' => 'SEC_OPTION', 'second' => 'SEC_OPTION',
), ),
'test', 'test',
'<option value="test" selected="selected">TEST</option><option value="second">SEC_OPTION</option>', [
[
'value' => 'test',
'label' => 'TEST',
'selected' => true,
],
[
'value' => 'second',
'label' => 'SEC_OPTION',
'selected' => false,
],
],
), ),
array( array(
array( array(
@ -50,7 +72,18 @@ class phpbb_functions_acp_built_select_test extends phpbb_test_case
'second' => 'SEC_OPTION', 'second' => 'SEC_OPTION',
), ),
'second', 'second',
'<option value="test">TEST</option><option value="second" selected="selected">SEC_OPTION</option>', [
[
'value' => 'test',
'label' => 'TEST',
'selected' => false,
],
[
'value' => 'second',
'label' => 'SEC_OPTION',
'selected' => true,
],
],
), ),
); );
} }
@ -60,6 +93,10 @@ class phpbb_functions_acp_built_select_test extends phpbb_test_case
*/ */
public function test_build_select($option_ary, $option_default, $expected) public function test_build_select($option_ary, $option_default, $expected)
{ {
global $language;
$language = new phpbb_mock_lang();
$this->assertEquals($expected, build_select($option_ary, $option_default)); $this->assertEquals($expected, build_select($option_ary, $option_default));
} }
} }