1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-07-30 21:40:43 +02:00

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
42 changed files with 1390 additions and 409 deletions

View File

@@ -452,11 +452,11 @@ class acp_attachments
$cache->destroy('_extensions');
}
$template->assign_vars(array(
$template->assign_vars([
'S_EXTENSIONS' => true,
'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 *
FROM ' . EXTENSIONS_TABLE . '
@@ -794,7 +794,10 @@ class acp_attachments
'ASSIGNED_EXTENSIONS' => $assigned_extensions,
'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_FILENAME_LIST' => $filename_list,
'S_EDIT_GROUP' => true,
@@ -1445,16 +1448,21 @@ class acp_attachments
$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)
{
$selected = ($type == $cat_type) ? ' selected="selected"' : '';
$group_select .= '<option value="' . $type . '"' . $selected . '>' . $mode . '</option>';
$group_select['options'][] = [
'value' => $type,
'selected' => $type == $cat_type,
'label' => $mode,
];
}
$group_select .= '</select>';
return $group_select;
}
@@ -1465,8 +1473,6 @@ class acp_attachments
{
global $db, $user;
$group_select = '<select name="' . $select_name . '"' . (($key) ? ' id="' . $key . '"' : '') . '>';
$sql = 'SELECT group_id, group_name
FROM ' . EXTENSION_GROUPS_TABLE . '
ORDER BY group_name';
@@ -1484,22 +1490,30 @@ class acp_attachments
$row['group_name'] = $user->lang['NOT_ASSIGNED'];
$group_name[] = $row;
$group_select = [
'name' => $select_name,
'id' => $key,
'options' => [],
];
for ($i = 0, $groups_size = count($group_name); $i < $groups_size; $i++)
{
if ($default_group === false)
{
$selected = ($i == 0) ? ' selected="selected"' : '';
$selected = $i == 0;
}
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;
}
@@ -1712,8 +1726,23 @@ class acp_attachments
$size_var = $filesize['si_identifier'];
$value = $filesize['value'];
// size and maxlength must not be specified for input of type number
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>';
return [
[
'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
*/
use phpbb\config\config;
use phpbb\language\language;
use phpbb\user;
if (!defined('IN_PHPBB'))
{
exit;
@@ -28,16 +33,26 @@ class acp_board
var $u_action;
var $new_config;
/** @var config */
protected $config;
/** @var language */
protected $language;
/** @var user */
protected $user;
function main($id, $mode)
{
global $user, $template, $request, $language;
global $config, $phpbb_root_path, $phpEx;
global $cache, $phpbb_container, $phpbb_dispatcher, $phpbb_log;
/** @var \phpbb\language\language $language Language object */
$language = $phpbb_container->get('language');
$this->config = $config;
$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;
@@ -64,7 +79,7 @@ class acp_board
'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_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),
'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))
{
$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
*/
function bump_interval($value, $key)
public function bump_interval($value, $key): array
{
global $user;
$s_bump_type = '';
$bump_type_options = [];
$types = array('m' => 'MINUTES', 'h' => 'HOURS', 'd' => 'DAYS');
foreach ($types as $type => $lang)
{
$selected = ($this->new_config['bump_type'] == $type) ? ' selected="selected"' : '';
$s_bump_type .= '<option value="' . $type . '"' . $selected . '>' . $user->lang[$lang] . '</option>';
$bump_type_options[] = [
'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)
{
global $template, $user;
$timezone_select = phpbb_timezone_select($this->user, $value, true);
$timezone_select = phpbb_timezone_select($template, $user, $value, true);
return '<select name="config[' . $key . ']" id="' . $key . '">' . $timezone_select . '</select>';
return [
'tag' => 'select',
'name' => 'config[' . $key . ']',
'options' => $timezone_select,
];
}
/**
@@ -1060,81 +1108,132 @@ class acp_board
}
/**
* Select default dateformat
*/
function dateformat_select($value, $key)
* Create select for default date format
*
* @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
$old_tz = $user->timezone;
$old_tz = $this->user->timezone;
try
{
$user->timezone = new DateTimeZone($config['board_timezone']);
$this->user->timezone = new DateTimeZone($this->config['board_timezone']);
}
catch (\Exception $e)
{
// 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"' : '') . '>';
$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>';
$dateformats = [];
}
$dateformat_options .= '<option value="custom"';
if (!isset($user->lang['dateformats'][$value]))
foreach ($dateformats as $format => $null)
{
$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
$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>
<input type=\"text\" name=\"config[$key]\" id=\"$key\" value=\"$value\" maxlength=\"64\" />";
return [
[
'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
*/
function select_news_forums($value, $key)
* Select for multiple forums
*
* @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);
// 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;
return $this->get_forum_select($key);
}
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);
// Build forum options
$s_forum_options = '<select id="' . $key . '" name="' . $key . '[]" multiple="multiple">';
$forum_options = [];
foreach ($forum_list as $f_id => $f_row)
{
$f_row['selected'] = phpbb_optionget(FORUM_OPTION_FEED_EXCLUDE, $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>';
$forum_options[] = [
'value' => $f_id,
'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)

View File

@@ -330,7 +330,7 @@ class acp_bots
}
$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';
@@ -347,10 +347,13 @@ class acp_bots
'S_EDIT_BOT' => true,
'S_ACTIVE_OPTIONS' => $s_active_options,
'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,
)
);
));
return;

View File

@@ -306,7 +306,10 @@ class acp_inactive
$template->assign_vars(array(
'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_SORT_KEY' => $s_sort_key,

View File

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

View File

@@ -1795,7 +1795,9 @@ class acp_users
${'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(
'S_PREFS' => 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'],
'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']),
'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 ...
*
* @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 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))
{
$sql = 'SELECT lang_iso, lang_local_name
@@ -284,11 +281,14 @@ function language_select($default = '', array $langdata = [])
$db->sql_freeresult($result);
}
$lang_options = '';
$lang_options = [];
foreach ($langdata as $row)
{
$selected = ($row['lang_iso'] == $default) ? ' selected="selected"' : '';
$lang_options .= '<option value="' . $row['lang_iso'] . '"' . $selected . '>' . $row['lang_local_name'] . '</option>';
$lang_options[] = [
'value' => $row['lang_iso'],
'label' => $row['lang_local_name'],
'selected' => $row['lang_iso'] === $default,
];
}
return $lang_options;
@@ -442,14 +442,13 @@ function phpbb_get_timezone_identifiers($selected_timezone)
/**
* 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 string $default A timezone to select
* @param boolean $truncate Shall we truncate the options text
*
* @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;
@@ -481,27 +480,22 @@ function phpbb_timezone_select($template, $user, $default = '', $truncate = fals
uksort($timezones, 'phpbb_tz_select_compare');
}
$tz_select = $opt_group = '';
$opt_group = '';
$tz_data = [];
foreach ($timezones as $key => $timezone)
{
if ($opt_group != $timezone['offset'])
{
// Generate tz_select for backwards compatibility
$tz_select .= ($opt_group) ? '</optgroup>' : '';
$tz_select .= '<optgroup label="' . $user->lang(array('timezones', 'UTC_OFFSET_CURRENT'), $timezone['offset'], $timezone['current']) . '">';
$opt_group = $timezone['offset'];
$template->assign_block_vars('timezone_select', array(
'LABEL' => $user->lang(array('timezones', 'UTC_OFFSET_CURRENT'), $timezone['offset'], $timezone['current']),
'VALUE' => $key . ' - ' . $timezone['current'],
));
$tz_data[$timezone['offset']] = [
'label' => $user->lang(array('timezones', 'UTC_OFFSET_CURRENT'), $timezone['offset'], $timezone['current']),
'value' => $key . ' - ' . $timezone['current'],
'options' => [],
'selected' => !empty($default_offset) && strpos($key, $default_offset) !== false,
'data' => ['tz-value' => $key . ' - ' . $timezone['current']],
];
$selected = (!empty($default_offset) && strpos($key, $default_offset) !== false) ? ' selected="selected"' : '';
$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']),
));
$opt_group = $timezone['offset'];
}
$label = $timezone['tz'];
@@ -516,19 +510,15 @@ function phpbb_timezone_select($template, $user, $default = '', $truncate = fals
$label = truncate_string($label, 50, 255, false, '...');
}
// Also generate timezone_select for backwards compatibility
$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(
$tz_data[$timezone['offset']]['options'][] = [
'TITLE' => $title,
'VALUE' => $timezone['tz'],
'SELECTED' => !empty($selected),
'LABEL' => $label,
));
'value' => $timezone['tz'],
'selected' => $timezone['tz'] === $default,
'label' => $label,
];
}
$tz_select .= '</optgroup>';
return $tz_select;
return $tz_data;
}
// 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
*/
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)
{
$selected = ($option_default !== false && $value == $option_default) ? ' selected="selected"' : '';
$html .= '<option value="' . $value . '"' . $selected . '>' . $user->lang[$title] . '</option>';
$options[] = [
'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
*/
function build_cfg_template($tpl_type, $key, &$new_ary, $config_key, $vars)
* HTML-less version of build_cfg_template
*
* @param array $tpl_type Template type
* @param string $key Config key
* @param $new_ary
* @param $config_key
* @param $vars
* @return array
*/
function phpbb_build_cfg_template(array $tpl_type, string $key, &$new_ary, $config_key, $vars): array
{
global $user, $module, $phpbb_dispatcher;
global $language;
$tpl = '';
$tpl = [];
$name = 'config[' . $config_key . ']';
// Make sure there is no notice printed out for non-existent config options (we simply set them)
@@ -266,6 +276,8 @@ function build_cfg_template($tpl_type, $key, &$new_ary, $config_key, $vars)
// replace passwords with asterixes
$new_ary[$config_key] = '********';
}
// no break
case 'text':
case 'url':
case 'email':
@@ -276,7 +288,15 @@ function build_cfg_template($tpl_type, $key, &$new_ary, $config_key, $vars)
$size = (int) $tpl_type[1];
$maxlength = (int) $tpl_type[2];
$tpl = '<input id="' . $key . '" type="' . $tpl_type[0] . '"' . (($size) ? ' size="' . $size . '"' : '') . ' maxlength="' . (($maxlength) ? $maxlength : 255) . '" name="' . $name . '" value="' . $new_ary[$config_key] . '"' . (($tpl_type[0] === 'password') ? ' autocomplete="off"' : '') . ' />';
$tpl = [
'tag' => 'input',
'id' => $key,
'type' => $tpl_type[0],
'name' => $name,
'size' => $size ?: '',
'maxlength' => $maxlength ?: 255,
'value' => $new_ary[$config_key],
];
break;
case 'color':
@@ -284,7 +304,13 @@ function build_cfg_template($tpl_type, $key, &$new_ary, $config_key, $vars)
case 'datetime-local':
case 'month':
case 'week':
$tpl = '<input id="' . $key . '" type="' . $tpl_type[0] . '" name="' . $name . '" value="' . $new_ary[$config_key] . '" />';
$tpl = [
'tag' => 'input',
'id' => $key,
'type' => $tpl_type[0],
'name' => $name,
'value' => $new_ary[$config_key],
];
break;
case 'date':
@@ -294,34 +320,125 @@ function build_cfg_template($tpl_type, $key, &$new_ary, $config_key, $vars)
$min = isset($tpl_type[1]) ? (int) $tpl_type[1] : false;
$max = isset($tpl_type[2]) ? (int) $tpl_type[2] : false;
$tpl = '<input id="' . $key . '" type="' . $tpl_type[0] . '"' . (( $min !== false ) ? ' min="' . $min . '"' : '') . (( $max !== false ) ? ' max="' . $max . '"' : '') . ' name="' . $name . '" value="' . $new_ary[$config_key] . '" />';
$tpl = [
'tag' => 'input',
'id' => $key,
'type' => $tpl_type[0],
'name' => $name,
'min' => $min !== false ? $min : '',
'max' => $max !== false ? $max : '',
'value' => $new_ary[$config_key],
];
break;
case 'dimension':
$min = isset($tpl_type[1]) ? (int) $tpl_type[1] : false;
$max = isset($tpl_type[2]) ? (int) $tpl_type[2] : false;
$tpl = '<input id="' . $key . '" type="number"' . (( $min !== false ) ? ' min="' . $min . '"' : '') . (( $max !== false ) ? ' max="' . $max . '"' : '') . ' name="config[' . $config_key . '_width]" value="' . $new_ary[$config_key . '_width'] . '" /> x <input type="number"' . (( $min !== '' ) ? ' min="' . $min . '"' : '') . (( $max != '' ) ? ' max="' . $max . '"' : '') . ' name="config[' . $config_key . '_height]" value="' . $new_ary[$config_key . '_height'] . '" />';
$tpl = [
'tag' => 'dimension',
'width' => [
'id' => $key,
'type' => 'number',
'name' => 'config[' . $config_key . '_width]',
'min' => $min !== false ? $min : '',
'max' => $max !== false ? $max : '',
'value' => $new_ary[$config_key . '_width'],
],
'height' => [
'type' => 'number',
'name' => 'config[' . $config_key . '_height]',
'min' => $min !== false ? $min : '',
'max' => $max !== false ? $max : '',
'value' => $new_ary[$config_key . '_height'],
],
];
break;
case 'textarea':
$rows = (int) $tpl_type[1];
$cols = (int) $tpl_type[2];
$tpl = '<textarea id="' . $key . '" name="' . $name . '" rows="' . $rows . '" cols="' . $cols . '">' . $new_ary[$config_key] . '</textarea>';
$tpl = [
'tag' => 'textarea',
'id' => $key,
'name' => $name,
'rows' => (int) $tpl_type[1],
'cols' => (int) $tpl_type[2],
'content' => $new_ary[$config_key],
];
break;
case 'radio':
$key_yes = ($new_ary[$config_key]) ? ' checked="checked"' : '';
$key_no = (!$new_ary[$config_key]) ? ' checked="checked"' : '';
$tpl_type_cond = explode('_', $tpl_type[1]);
$type_no = ($tpl_type_cond[0] == 'disabled' || $tpl_type_cond[0] == 'enabled') ? false : true;
$type_no = $tpl_type_cond[0] != 'disabled' && $tpl_type_cond[0] != 'enabled';
$tpl_no = '<label><input type="radio" name="' . $name . '" value="0"' . $key_no . ' class="radio" /> ' . (($type_no) ? $user->lang['NO'] : $user->lang['DISABLED']) . '</label>';
$tpl_yes = '<label><input type="radio" id="' . $key . '" name="' . $name . '" value="1"' . $key_yes . ' class="radio" /> ' . (($type_no) ? $user->lang['YES'] : $user->lang['ENABLED']) . '</label>';
$no_button = [
'type' => 'radio',
'name' => $name,
'value' => 0,
'checked' => !$new_ary[$config_key],
'label' => $type_no ? $language->lang('NO') : $language->lang('DISABLED'),
];
$tpl = ($tpl_type_cond[0] == 'yes' || $tpl_type_cond[0] == 'enabled') ? $tpl_yes . $tpl_no : $tpl_no . $tpl_yes;
$yes_button = [
'id' => $key,
'type' => 'radio',
'name' => $name,
'value' => 1,
'checked' => (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;
case 'select':
@@ -369,9 +486,29 @@ function build_cfg_template($tpl_type, $key, &$new_ary, $config_key, $vars)
if ($tpl_type[0] == 'select')
{
$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
{
@@ -386,7 +523,14 @@ function build_cfg_template($tpl_type, $key, &$new_ary, $config_key, $vars)
if (isset($vars['append']))
{
$tpl .= $vars['append'];
if (is_array($tpl))
{
$tpl['append'] = $vars['append'];
}
else
{
$tpl .= $vars['append'];
}
}
$new = $new_ary;

View File

@@ -160,20 +160,23 @@ function make_forum_select($select_id = false, $ignore_id = false, $ignore_acl =
*/
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');
$s_size_options = '';
$size_options = [];
for ($i = 0, $size = count($size_types_text); $i < $size; $i++)
{
$selected = ($size_compare == $size_types[$i]) ? ' selected="selected"' : '';
$s_size_options .= '<option value="' . $size_types[$i] . '"' . $selected . '>' . $size_types_text[$i] . '</option>';
$size_options[] = [
'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)
{
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>';
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
$sql = 'SELECT lang_iso, lang_local_name
@@ -177,6 +177,8 @@ class ucp_prefs
$db->sql_freeresult($result);
$s_more_styles = count($styles_row) > 1;
$lang_options = phpbb_language_select($db, $data['lang'], $lang_row);
$template->assign_vars(array(
'ERROR' => (count($error)) ? implode('<br />', $error) : '',
@@ -198,8 +200,17 @@ class ucp_prefs
'S_MORE_LANGUAGES' => $s_more_languages,
'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),
'TIMEZONE_OPTIONS' => [
'tag' => 'select',
'name' => 'tz',
'options' => $timezone_select,
],
'S_CAN_HIDE_ONLINE' => ($auth->acl_get('u_hideonline')) ? true : false,
'S_SELECT_NOTIFY' => ($config['jab_enable'] && $user->data['user_jabber'] && @extension_loaded('xml')) ? true : false)
);

View File

@@ -157,6 +157,8 @@ class ucp_register
$lang_row = (array) $db->sql_fetchrowset($result);
$db->sql_freeresult($result);
$lang_options = phpbb_language_select($db, $user_lang, $lang_row);
if ($coppa === false && $config['coppa_enable'])
{
$now = getdate();
@@ -167,7 +169,11 @@ class ucp_register
unset($now);
$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_YES' => $user->lang('UCP_COPPA_ON_AFTER', $coppa_birthday),
@@ -182,7 +188,11 @@ class ucp_register
else
{
$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()),
'S_SHOW_COPPA' => false,
@@ -616,7 +626,7 @@ class ucp_register
}
// 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
$sql = 'SELECT lang_iso, lang_local_name
@@ -626,6 +636,8 @@ class ucp_register
$lang_row = (array) $db->sql_fetchrowset($result);
$db->sql_freeresult($result);
$lang_options = phpbb_language_select($db, $data['lang'], $lang_row);
$template_vars = array(
'USERNAME' => $data['username'],
'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_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_CONFIRM_REFRESH' => ($config['enable_confirm'] && $config['confirm_refresh']) ? true : false,
'S_REGISTRATION' => true,