1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-02-24 20:13:22 +01:00

[ticket/12858] Generate timezone selects with template loop

PHPBB3-12858
This commit is contained in:
Marc Alexander 2014-09-17 14:15:16 +02:00
parent 20903c0a9b
commit 9ebee7de32
7 changed files with 38 additions and 19 deletions

View File

@ -904,9 +904,9 @@ class acp_board
*/
function timezone_select($value, $key)
{
global $user;
global $template, $user;
$timezone_select = phpbb_timezone_select($user, $value, true);
$timezone_select = phpbb_timezone_select($template, $user, $value, true);
$timezone_select['tz_select'];
return '<select name="config[' . $key . ']" id="' . $key . '">' . $timezone_select['tz_select'] . '</select>';

View File

@ -1661,7 +1661,7 @@ class acp_users
${'s_sort_' . $sort_option . '_dir'} .= '</select>';
}
$timezone_selects = phpbb_timezone_select($user, $data['tz'], true);
$timezone_selects = phpbb_timezone_select($template, $user, $data['tz'], true);
$user_prefs_data = array(
'S_PREFS' => true,
'S_JABBER_DISABLED' => ($config['jab_enable'] && $user_row['user_jabber'] && @extension_loaded('xml')) ? false : true,

View File

@ -1040,13 +1040,14 @@ 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 array Returns an array, also containing the options for the time selector.
* @return array Returns an array containing the options for the time selector.
*/
function phpbb_timezone_select($user, $default = '', $truncate = false)
function phpbb_timezone_select($template, $user, $default = '', $truncate = false)
{
static $timezones;
@ -1078,18 +1079,26 @@ function phpbb_timezone_select($user, $default = '', $truncate = false)
uksort($timezones, 'phpbb_tz_select_compare');
}
$tz_select = $tz_dates = $opt_group = '';
$tz_select = $opt_group = '';
foreach ($timezones as $timezone)
{
if ($opt_group != $timezone['offset'])
{
// Generate tz_select for backwards compatibility
$tz_select .= ($opt_group) ? '</optgroup>' : '';
$tz_select .= '<optgroup label="' . $timezone['offset'] . ' - ' . $timezone['current'] . '">';
$opt_group = $timezone['offset'];
$template->assign_block_vars('tz_select', array(
'LABEL' => $timezone['offset'] . ' - ' . $timezone['current'],
));
$selected = ($default_offset == $timezone['offset']) ? ' selected="selected"' : '';
$tz_dates .= '<option value="' . $timezone['offset'] . ' - ' . $timezone['current'] . '"' . $selected . '>' . $timezone['offset'] . ' - ' . $timezone['current'] . '</option>';
$template->assign_block_vars('tz_date', array(
'VALUE' => $timezone['offset'] . ' - ' . $timezone['current'],
'SELECTED' => $selected,
'TITLE' => $timezone['offset'] . ' - ' . $timezone['current'],
));
}
$label = $timezone['tz'];
@ -1104,14 +1113,20 @@ function phpbb_timezone_select($user, $default = '', $truncate = false)
$label = truncate_string($label, 50, 255, false, '...');
}
// Also generate tz_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('tz_select.tz_options', array(
'TITLE' => $title,
'VALUE' => $timezone['tz'],
'SELECTED' => $timezone['tz'] === $default,
'LABEL' => $label,
));
}
$tz_select .= '</optgroup>';
return array(
'tz_select' => $tz_select,
'tz_dates' => $tz_dates,
);
}

View File

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

View File

@ -154,7 +154,7 @@ class ucp_prefs
}
$dateformat_options .= '>' . $user->lang['CUSTOM_DATEFORMAT'] . '</option>';
$timezone_selects = phpbb_timezone_select($user, $data['tz'], true);
$timezone_selects = phpbb_timezone_select($template, $user, $data['tz'], true);
// check if there are any user-selectable languages
$sql = 'SELECT COUNT(lang_id) as languages_count
@ -208,8 +208,6 @@ class ucp_prefs
'S_LANG_OPTIONS' => language_select($data['lang']),
'S_STYLE_OPTIONS' => ($config['override_user_style']) ? '' : style_select($data['user_style']),
'S_TZ_OPTIONS' => $timezone_selects['tz_select'],
'S_TZ_DATE_OPTIONS' => $timezone_selects['tz_dates'],
'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

@ -452,7 +452,7 @@ class ucp_register
break;
}
$timezone_selects = phpbb_timezone_select($user, $data['tz'], true);
$timezone_selects = phpbb_timezone_select($template, $user, $data['tz'], true);
$template->assign_vars(array(
'ERROR' => (sizeof($error)) ? implode('<br />', $error) : '',
'USERNAME' => $data['username'],
@ -465,8 +465,6 @@ class ucp_register
'L_PASSWORD_EXPLAIN' => $user->lang($config['pass_complex'] . '_EXPLAIN', $user->lang('CHARACTERS', (int) $config['min_pass_chars']), $user->lang('CHARACTERS', (int) $config['max_pass_chars'])),
'S_LANG_OPTIONS' => language_select($data['lang']),
'S_TZ_OPTIONS' => $timezone_selects['tz_select'],
'S_TZ_DATE_OPTIONS' => $timezone_selects['tz_dates'],
'S_TZ_PRESELECT' => !$submit,
'S_CONFIRM_REFRESH' => ($config['enable_confirm'] && $config['confirm_refresh']) ? true : false,
'S_REGISTRATION' => true,

View File

@ -1,10 +1,12 @@
<dl>
<dt><label for="timezone">{L_BOARD_TIMEZONE}{L_COLON}</label></dt>
<!-- IF S_TZ_DATE_OPTIONS -->
<!-- IF .tz_date -->
<dd id="tz_select_date" style="display: none;">
<select name="tz_date" id="tz_date" class="autowidth tz_select">
<option value="">{L_SELECT_CURRENT_TIME}</option>
{S_TZ_DATE_OPTIONS}
<!-- BEGIN tz_date -->
<option value="{tz_date.VALUE}"<!-- IF tz_date.SELECTED --> selected="selected"<!-- ENDIF -->>{tz_date.TITLE}</option>
<!-- END tz_date -->
</select>
<input type="button" id="tz_select_date_suggest" class="button2" 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>
@ -12,7 +14,13 @@
<dd>
<select name="tz" id="timezone" class="autowidth tz_select">
<option value="">{L_SELECT_TIMEZONE}</option>
{S_TZ_OPTIONS}
<!-- BEGIN tz_select -->
<optgroup label="{tz_select.LABEL}">
<!-- BEGIN tz_options -->
<option title="{tz_select.tz_options.TITLE}" value="{tz_select.tz_options.VALUE}"<!-- IF tz_select.tz_options.SELECTED --> selected="selected"<!-- ENDIF -->>{tz_select.tz_options.LABEL}</option>
<!-- END tz_options -->
</optgroup>
<!-- END tz_select -->
</select>
<!-- INCLUDEJS timezone.js -->