当前位置: 首页>>代码示例>>PHP>>正文


PHP phpbb_get_timezone_identifiers函数代码示例

本文整理汇总了PHP中phpbb_get_timezone_identifiers函数的典型用法代码示例。如果您正苦于以下问题:PHP phpbb_get_timezone_identifiers函数的具体用法?PHP phpbb_get_timezone_identifiers怎么用?PHP phpbb_get_timezone_identifiers使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了phpbb_get_timezone_identifiers函数的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: phpbb_timezone_select

/**
* 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 containing the options for the time selector.
*/
function phpbb_timezone_select($template, $user, $default = '', $truncate = false)
{
    static $timezones;
    $default_offset = '';
    if (!isset($timezones)) {
        $unsorted_timezones = phpbb_get_timezone_identifiers($default);
        $timezones = array();
        foreach ($unsorted_timezones as $timezone) {
            $tz = new DateTimeZone($timezone);
            $dt = $user->create_datetime('now', $tz);
            $offset = $dt->getOffset();
            $current_time = $dt->format($user->lang['DATETIME_FORMAT'], true);
            $offset_string = phpbb_format_timezone_offset($offset, true);
            $timezones['UTC' . $offset_string . ' - ' . $timezone] = array('tz' => $timezone, 'offset' => $offset_string, 'current' => $current_time);
            if ($timezone === $default) {
                $default_offset = 'UTC' . $offset_string;
            }
        }
        unset($unsorted_timezones);
        uksort($timezones, 'phpbb_tz_select_compare');
    }
    $tz_select = $opt_group = '';
    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']));
            $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'])));
        }
        $label = $timezone['tz'];
        if (isset($user->lang['timezones'][$label])) {
            $label = $user->lang['timezones'][$label];
        }
        $title = $user->lang(array('timezones', 'UTC_OFFSET_CURRENT'), $timezone['offset'], $label);
        if ($truncate) {
            $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('TITLE' => $title, 'VALUE' => $timezone['tz'], 'SELECTED' => !empty($selected), 'LABEL' => $label));
    }
    $tz_select .= '</optgroup>';
    return $tz_select;
}
开发者ID:WarriorMachines,项目名称:warriormachines-phpbb,代码行数:58,代码来源:functions.php

示例2: phpbb_validate_timezone

/**
* Validate Timezone Name
*
* Tests whether a timezone name is valid
*
* @param string $timezone	The timezone string to test
*
* @return bool|string		Either false if validation succeeded or
*							a string which will be used as the error message
*							(with the variable name appended)
*/
function phpbb_validate_timezone($timezone)
{
    return in_array($timezone, phpbb_get_timezone_identifiers($timezone)) ? false : 'TIMEZONE_INVALID';
}
开发者ID:Tarendai,项目名称:spring-website,代码行数:15,代码来源:functions_user.php


注:本文中的phpbb_get_timezone_identifiers函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。