Ejemplo n.º 1
0
function automatic_dst_cache($timezone)
{
    if (is_numeric($timezone)) {
        // Time zone not yet converted, so lets temporarily do just that -  if there's no entry to convert to reset to GMT
        $timetable = automatic_dst_get_timetable();
        $timezone = number_format($timezone, 2);
        $timezone = $timetable[$timezone] ? $timetable[$timezone] : 'Europe/London';
        // It's important for the converter that this time zone is temporary, so lets tell it
        define('AUTOMATIC_DST_TEMP_TIMEZONE', TRUE);
    }
    if (version_compare(PHP_VERSION, '5.2.0', '>')) {
        date_default_timezone_set($timezone);
        $january = new DateTime(date('Y') . '-01-01 12:00:00');
        $july = new DateTime(date('Y') . '-07-01 12:00:00');
        $offset = $january->getOffset() < $july->getOffset() ? $january->getOffset() / 3600 : $july->getOffset() / 3600;
    } else {
        putenv('TZ=' . $timezone);
        $offset = date('Z', mktime(0, 0, 0, 01, 01)) < date('Z', mktime(0, 0, 0, 07, 01)) ? date('Z', mktime(0, 0, 0, 01, 01)) / 3600 : date('Z', mktime(0, 0, 0, 07, 01)) / 3600;
    }
    define('AUTOMATIC_DST_BOARD_TIMEZONE', $timezone);
    define('AUTOMATIC_DST_BOARD_ISDST', date('I'));
    // Return time zone offset
    return $offset;
}
Ejemplo n.º 2
0
*
*/
define('IN_PHPBB', true);
$phpbb_root_path = defined('PHPBB_ROOT_PATH') ? PHPBB_ROOT_PATH : './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include $phpbb_root_path . 'common.' . $phpEx;
// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup('mods/automatic_dst');
if (!$auth->acl_get('a_')) {
    trigger_error('NO_ADMIN');
}
if (defined('AUTOMATIC_DST_TEMP_TIMEZONE')) {
    trigger_error($user->lang['AUTOMATIC_DST_SETUP'], E_USER_WARNING);
}
$timetable = automatic_dst_get_timetable();
$sql = 'SELECT user_id, user_timezone
	FROM ' . USERS_TABLE;
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result)) {
    // Only convert entries that are actually stored in the old format
    if (array_key_exists($row['user_timezone'], $timetable)) {
        // If there's no entry to convert to use the board setting
        $timezone = $timetable[$row['user_timezone']] ? $timetable[$row['user_timezone']] : AUTOMATIC_DST_BOARD_TIMEZONE;
        $sql = 'UPDATE ' . USERS_TABLE . "\n\t\t\tSET user_timezone = '{$timezone}'\n\t\t\tWHERE user_id = " . $row['user_id'];
        $db->sql_query($sql);
    }
}
$db->sql_freeresult($result);
trigger_error($user->lang['AUTOMATIC_DST_INSTALLED']);