User definable timezones. Work in UTC internally and display per user/site default. http://laconi.ca/PITS/00011
darcs-hash:20080720141325-533db-87cb60501434c9dc0ac13716ba5d8b17754431f5.gz
This commit is contained in:
parent
060fecf5ec
commit
88717d8805
@ -88,6 +88,9 @@ class ProfilesettingsAction extends SettingsAction {
|
|||||||
} else if (!is_null($location) && strlen($location) > 255) {
|
} else if (!is_null($location) && strlen($location) > 255) {
|
||||||
$this->show_form(_('Location is too long (max 255 chars).'));
|
$this->show_form(_('Location is too long (max 255 chars).'));
|
||||||
return;
|
return;
|
||||||
|
} else if (is_null($timezone) || !in_array($timezone, DateTimeZone::listIdentifiers())) {
|
||||||
|
$this->show_form(_('Timezone not selected.'));
|
||||||
|
return;
|
||||||
} else if ($this->nickname_exists($nickname)) {
|
} else if ($this->nickname_exists($nickname)) {
|
||||||
$this->show_form(_('Nickname already in use. Try another one.'));
|
$this->show_form(_('Nickname already in use. Try another one.'));
|
||||||
return;
|
return;
|
||||||
@ -99,31 +102,22 @@ class ProfilesettingsAction extends SettingsAction {
|
|||||||
|
|
||||||
$user->query('BEGIN');
|
$user->query('BEGIN');
|
||||||
|
|
||||||
if ($user->nickname != $nickname) {
|
if ($user->nickname != $nickname ||
|
||||||
|
$user->language != $language ||
|
||||||
|
$user->timezone != $timezone) {
|
||||||
|
|
||||||
common_debug('Updating user nickname from ' . $user->nickname . ' to ' . $nickname,
|
common_debug('Updating user nickname from ' . $user->nickname . ' to ' . $nickname,
|
||||||
__FILE__);
|
__FILE__);
|
||||||
|
common_debug('Updating user language from ' . $user->language . ' to ' . $language,
|
||||||
|
__FILE__);
|
||||||
|
common_debug('Updating user timezone from ' . $user->timezone . ' to ' . $timezone,
|
||||||
|
__FILE__);
|
||||||
|
|
||||||
$original = clone($user);
|
$original = clone($user);
|
||||||
|
|
||||||
$user->nickname = $nickname;
|
$user->nickname = $nickname;
|
||||||
|
|
||||||
$result = $user->updateKeys($original);
|
|
||||||
|
|
||||||
if ($result === FALSE) {
|
|
||||||
common_log_db_error($user, 'UPDATE', __FILE__);
|
|
||||||
common_server_error(_('Couldn\'t update user.'));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ($user->language != $language) {
|
|
||||||
|
|
||||||
common_debug('Updating user language from ' . $user->language . ' to ' . $language,
|
|
||||||
__FILE__);
|
|
||||||
|
|
||||||
$original = clone($user);
|
|
||||||
|
|
||||||
$user->language = $language;
|
$user->language = $language;
|
||||||
|
$user->timezone = $timezone;
|
||||||
|
|
||||||
$result = $user->updateKeys($original);
|
$result = $user->updateKeys($original);
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ $config =
|
|||||||
'locale_path' => './locale',
|
'locale_path' => './locale',
|
||||||
'language' => 'en_US',
|
'language' => 'en_US',
|
||||||
'languages' => get_all_languages(),
|
'languages' => get_all_languages(),
|
||||||
'email' =>
|
'email' =>
|
||||||
array_key_exists('SERVER_ADMIN', $_SERVER) ? $_SERVER['SERVER_ADMIN'] : NULL,
|
array_key_exists('SERVER_ADMIN', $_SERVER) ? $_SERVER['SERVER_ADMIN'] : NULL,
|
||||||
'broughtby' => NULL,
|
'broughtby' => NULL,
|
||||||
'timezone' => 'UTC',
|
'timezone' => 'UTC',
|
||||||
@ -101,8 +101,9 @@ $config['db'] =
|
|||||||
|
|
||||||
require_once(INSTALLDIR.'/config.php');
|
require_once(INSTALLDIR.'/config.php');
|
||||||
|
|
||||||
if (function_exists('date_default_timezone_set') && $config['site']['timezone']) {
|
if (function_exists('date_default_timezone_set')) {
|
||||||
date_default_timezone_set($config['site']['timezone']);
|
/* Work internally in UTC */
|
||||||
|
date_default_timezone_set('UTC');
|
||||||
}
|
}
|
||||||
|
|
||||||
require_once(INSTALLDIR.'/lib/util.php');
|
require_once(INSTALLDIR.'/lib/util.php');
|
||||||
|
36
lib/util.php
36
lib/util.php
@ -435,6 +435,18 @@ function common_textarea($id, $label, $content=NULL, $instructions=NULL) {
|
|||||||
common_element_end('p');
|
common_element_end('p');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function common_timezone() {
|
||||||
|
if (common_logged_in()) {
|
||||||
|
$user = common_current_user();
|
||||||
|
if ($user->timezone) {
|
||||||
|
return $user->timezone;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
global $config;
|
||||||
|
return $config['site']['timezone'];
|
||||||
|
}
|
||||||
|
|
||||||
function common_language() {
|
function common_language() {
|
||||||
$httplang = isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? $_SERVER['HTTP_ACCEPT_LANGUAGE'] : NULL;
|
$httplang = isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? $_SERVER['HTTP_ACCEPT_LANGUAGE'] : NULL;
|
||||||
$language = array();
|
$language = array();
|
||||||
@ -920,23 +932,31 @@ function common_date_string($dt) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function common_exact_date($dt) {
|
function common_exact_date($dt) {
|
||||||
$t = strtotime($dt);
|
$dateStr = date('d F Y H:i:s', strtotime($dt));
|
||||||
return date(DATE_RFC850, $t);
|
$d = new DateTime($dateStr, new DateTimeZone('UTC'));
|
||||||
|
$d->setTimezone(new DateTimeZone(common_timezone()));
|
||||||
|
return $d->format(DATE_RFC850);
|
||||||
}
|
}
|
||||||
|
|
||||||
function common_date_w3dtf($dt) {
|
function common_date_w3dtf($dt) {
|
||||||
$t = strtotime($dt);
|
$dateStr = date('d F Y H:i:s', strtotime($dt));
|
||||||
return date(DATE_W3C, $t);
|
$d = new DateTime($dateStr, new DateTimeZone('UTC'));
|
||||||
|
$d->setTimezone(new DateTimeZone(common_timezone()));
|
||||||
|
return $d->format(DATE_W3C);
|
||||||
}
|
}
|
||||||
|
|
||||||
function common_date_rfc2822($dt) {
|
function common_date_rfc2822($dt) {
|
||||||
$t = strtotime($dt);
|
$dateStr = date('d F Y H:i:s', strtotime($dt));
|
||||||
return date("r", $t);
|
$d = new DateTime($dateStr, new DateTimeZone('UTC'));
|
||||||
|
$d->setTimezone(new DateTimeZone(common_timezone()));
|
||||||
|
return $d->format('r');
|
||||||
}
|
}
|
||||||
|
|
||||||
function common_date_iso8601($dt) {
|
function common_date_iso8601($dt) {
|
||||||
$t = strtotime($dt);
|
$dateStr = date('d F Y H:i:s', strtotime($dt));
|
||||||
return date("c", $t);
|
$d = new DateTime($dateStr, new DateTimeZone('UTC'));
|
||||||
|
$d->setTimezone(new DateTimeZone(common_timezone()));
|
||||||
|
return $d->format('c');
|
||||||
}
|
}
|
||||||
|
|
||||||
function common_redirect($url, $code=307) {
|
function common_redirect($url, $code=307) {
|
||||||
|
Loading…
Reference in New Issue
Block a user