summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorthomascube <thomas@roundcube.net>2008-09-03 16:03:19 +0000
committerthomascube <thomas@roundcube.net>2008-09-03 16:03:19 +0000
commitc8ae2497b7e4c7393210ed186acd672a0040389f (patch)
treeb21442a9fff2d15cee5809db3d532d8ef378da37
parent7003206d64c83534f29d1eb9dfc53edf993baf5b (diff)
Auto-detect client language and timezone if desired by config/prefs
-rw-r--r--CHANGELOG5
-rw-r--r--config/main.inc.php.dist7
-rw-r--r--installer/config.php2
-rw-r--r--program/include/main.inc10
-rw-r--r--program/include/rcmail.php19
-rw-r--r--program/include/rcube_config.php4
-rw-r--r--program/include/rcube_shared.inc56
-rwxr-xr-xprogram/include/rcube_template.php2
-rw-r--r--program/js/app.js8
-rw-r--r--program/localization/en_US/labels.inc1
-rw-r--r--program/steps/settings/func.inc7
-rw-r--r--program/steps/settings/save_prefs.inc2
12 files changed, 48 insertions, 75 deletions
diff --git a/CHANGELOG b/CHANGELOG
index 0e6d676cb..02289eb79 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,6 +1,11 @@
CHANGELOG RoundCube Webmail
---------------------------
+2008/09/03 (thomasb)
+----------
+- Allow to auto-detect client language if none set (#1484434)
+- Auto-detect the client timezone (user configurable)
+
2008/09/03 (alec)
----------
- Add RFC2231 header value continuations support for attachment
diff --git a/config/main.inc.php.dist b/config/main.inc.php.dist
index 09fad199c..fcf7e8fff 100644
--- a/config/main.inc.php.dist
+++ b/config/main.inc.php.dist
@@ -129,8 +129,9 @@ $rcmail_config['double_auth'] = false;
// please provide a string of exactly 24 chars.
$rcmail_config['des_key'] = 'rcmail-!24ByteDESkey*Str';
-// the default locale setting
-$rcmail_config['language'] = 'en_US';
+// the default locale setting (leave empty for auto-detection)
+// RFC1766 formatted language name like en_US, de_DE, de_CH, fr_FR, pt_BR
+$rcmail_config['language'] = null;
// use this format for short date display
$rcmail_config['date_short'] = 'D H:i';
@@ -338,7 +339,7 @@ $rcmail_config['skin'] = 'default';
$rcmail_config['pagesize'] = 40;
// use this timezone to display date/time
-$rcmail_config['timezone'] = intval(date('O'))/100 - date('I');
+$rcmail_config['timezone'] = 'auto';
// is daylight saving On?
$rcmail_config['dst_active'] = (bool)date('I');
diff --git a/installer/config.php b/installer/config.php
index fb5d93289..12af1c660 100644
--- a/installer/config.php
+++ b/installer/config.php
@@ -453,7 +453,7 @@ $input_locale = new html_inputfield(array('name' => '_language', 'size' => 6, 'i
echo $input_locale->show($RCI->getprop('language'));
?>
-<div>The default locale setting. This also defines the language of the login screen.</div>
+<div>The default locale setting. This also defines the language of the login screen.<br/>Leave it empty to auto-detect the user agent language.</div>
<p class="hint">Enter a <a href="http://www.faqs.org/rfcs/rfc1766">RFC1766</a> formatted language name. Examples: en_US, de_DE, de_CH, fr_FR, pt_BR</p>
</dd>
diff --git a/program/include/main.inc b/program/include/main.inc
index 83ed8c02e..469d8441c 100644
--- a/program/include/main.inc
+++ b/program/include/main.inc
@@ -706,9 +706,13 @@ function format_date($date, $format=NULL)
return '';
// get user's timezone
- $tz = $CONFIG['timezone'];
- if ($CONFIG['dst_active'])
- $tz++;
+ if ($CONFIG['timezone'] == 'auto')
+ $tz = isset($_SESSION['timezone']) ? $_SESSION['timezone'] : intval(date('O'))/100;
+ else {
+ $tz = $CONFIG['timezone'];
+ if ($CONFIG['dst_active'])
+ $tz++;
+ }
// convert time to user's timezone
$timestamp = $ts - date('Z', $ts) + ($tz * 3600);
diff --git a/program/include/rcmail.php b/program/include/rcmail.php
index 348a91675..243b6f835 100644
--- a/program/include/rcmail.php
+++ b/program/include/rcmail.php
@@ -15,7 +15,7 @@
| Author: Thomas Bruederli <roundcube@gmail.com> |
+-----------------------------------------------------------------------+
- $Id: rcube_browser.php 328 2006-08-30 17:41:21Z thomasb $
+ $Id: rcmail.php 328 2006-08-30 17:41:21Z thomasb $
*/
@@ -167,7 +167,7 @@ class rcmail
$this->config->merge((array)$this->user->get_prefs());
}
- $_SESSION['language'] = $this->user->language = $this->language_prop($this->config->get('language'));
+ $_SESSION['language'] = $this->user->language = $this->language_prop($this->config->get('language', $_SESSION['language']));
// set localization
setlocale(LC_ALL, $_SESSION['language'] . '.utf8');
@@ -183,7 +183,13 @@ class rcmail
private function language_prop($lang)
{
static $rcube_languages, $rcube_language_aliases;
-
+
+ // user HTTP_ACCEPT_LANGUAGE if no language is specified
+ if (empty($lang) || $lang == 'auto') {
+ $accept_langs = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
+ $lang = str_replace('-', '_', $accept_langs[0]);
+ }
+
if (empty($rcube_languages)) {
@include(INSTALL_PATH . 'program/localization/index.inc');
}
@@ -471,6 +477,9 @@ class rcmail
$_SESSION['imap_ssl'] = $imap_ssl;
$_SESSION['password'] = $this->encrypt_passwd($pass);
$_SESSION['login_time'] = mktime();
+
+ if ($_REQUEST['_timezone'] != '_default_')
+ $_SESSION['timezone'] = floatval($_REQUEST['_timezone']);
// force reloading complete list of subscribed mailboxes
$this->set_imap_prop();
@@ -641,7 +650,7 @@ class rcmail
*/
public function load_language($lang = null)
{
- $lang = $lang ? $this->language_prop($lang) : $_SESSION['language'];
+ $lang = $this->language_prop(($lang ? $lang : $_SESSION['language']));
// load localized texts
if (empty($this->texts) || $lang != $_SESSION['language']) {
@@ -748,7 +757,7 @@ class rcmail
$this->user->save_prefs(array('message_sort_col' => $_SESSION['sort_col'], 'message_sort_order' => $_SESSION['sort_order']));
}
- $_SESSION = array('language' => $USER->language, 'auth_time' => time(), 'temp' => true);
+ $_SESSION = array('language' => $this->user->language, 'auth_time' => time(), 'temp' => true);
setcookie('sessauth', '-del-', time() - 60);
$this->user->reset();
}
diff --git a/program/include/rcube_config.php b/program/include/rcube_config.php
index 43f735ba9..98e688d02 100644
--- a/program/include/rcube_config.php
+++ b/program/include/rcube_config.php
@@ -84,9 +84,9 @@ class rcube_config
ini_set('log_errors', 1);
if ($this->prop['log_driver'] == 'syslog') {
- ini_set('error_log', 'syslog');
+ ini_set('error_log', 'syslog');
} else {
- ini_set('error_log', $this->prop['log_dir'].'/errors');
+ ini_set('error_log', $this->prop['log_dir'].'/errors');
}
}
if ($this->prop['debug_level'] & 4) {
diff --git a/program/include/rcube_shared.inc b/program/include/rcube_shared.inc
index d82b1fef0..0dd661ec5 100644
--- a/program/include/rcube_shared.inc
+++ b/program/include/rcube_shared.inc
@@ -28,62 +28,6 @@
/**
- * Provide details about the client's browser
- *
- * @return array Key-value pairs of browser properties
- */
-function rcube_browser()
-{
- $HTTP_USER_AGENT = $_SERVER['HTTP_USER_AGENT'];
-
- $bw['ver'] = 0;
- $bw['win'] = stristr($HTTP_USER_AGENT, 'win');
- $bw['mac'] = stristr($HTTP_USER_AGENT, 'mac');
- $bw['linux'] = stristr($HTTP_USER_AGENT, 'linux');
- $bw['unix'] = stristr($HTTP_USER_AGENT, 'unix');
-
- $bw['ns4'] = stristr($HTTP_USER_AGENT, 'mozilla/4') && !stristr($HTTP_USER_AGENT, 'msie');
- $bw['ns'] = ($bw['ns4'] || stristr($HTTP_USER_AGENT, 'netscape'));
- $bw['ie'] = stristr($HTTP_USER_AGENT, 'msie');
- $bw['mz'] = stristr($HTTP_USER_AGENT, 'mozilla/5');
- $bw['opera'] = stristr($HTTP_USER_AGENT, 'opera');
- $bw['safari'] = stristr($HTTP_USER_AGENT, 'safari');
-
- if($bw['ns'])
- {
- $test = eregi("mozilla\/([0-9\.]+)", $HTTP_USER_AGENT, $regs);
- $bw['ver'] = $test ? (float)$regs[1] : 0;
- }
- if($bw['mz'])
- {
- $test = ereg("rv:([0-9\.]+)", $HTTP_USER_AGENT, $regs);
- $bw['ver'] = $test ? (float)$regs[1] : 0;
- }
- if($bw['ie'])
- {
- $test = eregi("msie ([0-9\.]+)", $HTTP_USER_AGENT, $regs);
- $bw['ver'] = $test ? (float)$regs[1] : 0;
- }
- if($bw['opera'])
- {
- $test = eregi("opera ([0-9\.]+)", $HTTP_USER_AGENT, $regs);
- $bw['ver'] = $test ? (float)$regs[1] : 0;
- }
-
- if(eregi(" ([a-z]{2})-([a-z]{2})", $HTTP_USER_AGENT, $regs))
- $bw['lang'] = $regs[1];
- else
- $bw['lang'] = 'en';
-
- $bw['dom'] = ($bw['mz'] || $bw['safari'] || ($bw['ie'] && $bw['ver']>=5) || ($bw['opera'] && $bw['ver']>=7));
- $bw['pngalpha'] = $bw['mz'] || $bw['safari'] || ($bw['ie'] && $bw['ver']>=5.5) ||
- ($bw['ie'] && $bw['ver']>=5 && $bw['mac']) || ($bw['opera'] && $bw['ver']>=7) ? TRUE : FALSE;
-
- return $bw;
-}
-
-
-/**
* Send HTTP headers to prevent caching this page
*/
function send_nocacheing_headers()
diff --git a/program/include/rcube_template.php b/program/include/rcube_template.php
index db2275ed4..847ea0df5 100755
--- a/program/include/rcube_template.php
+++ b/program/include/rcube_template.php
@@ -922,6 +922,7 @@ class rcube_template extends rcube_html_page
$input_user = new html_inputfield(array('name' => '_user', 'id' => 'rcmloginuser', 'size' => 30) + $attrib);
$input_pass = new html_passwordfield(array('name' => '_pass', 'id' => 'rcmloginpwd', 'size' => 30) + $attrib);
$input_action = new html_hiddenfield(array('name' => '_action', 'value' => 'login'));
+ $input_tzone = new html_hiddenfield(array('name' => '_timezone', 'id' => 'rcmlogintz', 'value' => '_default_'));
$input_host = null;
if (is_array($default_host)) {
@@ -960,6 +961,7 @@ class rcube_template extends rcube_html_page
}
$out = $input_action->show();
+ $out .= $input_tzone->show();
$out .= $table->show();
// surround html output with a form tag
diff --git a/program/js/app.js b/program/js/app.js
index ff6ff8cf3..7ba8572b3 100644
--- a/program/js/app.js
+++ b/program/js/app.js
@@ -318,13 +318,19 @@ function rcube_webmail()
case 'login':
var input_user = rcube_find_object('rcmloginuser');
var input_pass = rcube_find_object('rcmloginpwd');
+ var input_tz = rcube_find_object('rcmlogintz');
+
if (input_user)
input_user.onkeyup = function(e){ return rcmail.login_user_keyup(e); };
if (input_user && input_user.value=='')
input_user.focus();
else if (input_pass)
input_pass.focus();
-
+
+ // detect client timezone
+ if (input_tz)
+ input_tz.value = new Date().getTimezoneOffset() / -60;
+
this.enable_command('login', true);
break;
diff --git a/program/localization/en_US/labels.inc b/program/localization/en_US/labels.inc
index b628799b2..ac43c85f9 100644
--- a/program/localization/en_US/labels.inc
+++ b/program/localization/en_US/labels.inc
@@ -254,6 +254,7 @@ $labels['newitem'] = 'New item';
$labels['edititem'] = 'Edit item';
$labels['setdefault'] = 'Set default';
+$labels['autodetect'] = 'Auto';
$labels['language'] = 'Language';
$labels['timezone'] = 'Time zone';
$labels['pagesize'] = 'Rows per page';
diff --git a/program/steps/settings/func.inc b/program/steps/settings/func.inc
index 5b6e11308..ef3c24d26 100644
--- a/program/steps/settings/func.inc
+++ b/program/steps/settings/func.inc
@@ -49,14 +49,15 @@ function rcmail_user_prefs_form($attrib)
$select_lang->add(array_values($a_lang), array_keys($a_lang));
$table->add('title', html::label($field_id, Q(rcube_label('language'))));
- $table->add(null, $select_lang->show($_SESSION['language']));
+ $table->add(null, $select_lang->show($config['language']));
}
// show page size selection
if (!isset($no_override['timezone'])) {
$field_id = 'rcmfd_timezone';
- $select_timezone = new html_select(array('name' => '_timezone', 'id' => $field_id));
+ $select_timezone = new html_select(array('name' => '_timezone', 'id' => $field_id, 'onchange' => "document.getElementById('rcmfd_dst').disabled=this.selectedIndex==0"));
+ $select_timezone->add(rcube_label('autodetect'), 'auto');
$select_timezone->add('(GMT -11:00) Midway Island, Samoa', '-11');
$select_timezone->add('(GMT -10:00) Hawaii', '-10');
$select_timezone->add('(GMT -9:30) Marquesas Islands', '-9.5');
@@ -104,7 +105,7 @@ function rcmail_user_prefs_form($attrib)
// daylight savings
if (!isset($no_override['dst_active'])) {
$field_id = 'rcmfd_dst';
- $input_dst = new html_checkbox(array('name' => '_dst_active', 'id' => $field_id, 'value' => 1));
+ $input_dst = new html_checkbox(array('name' => '_dst_active', 'id' => $field_id, 'value' => 1, 'disabled' => ($config['timezone'] == 'auto')));
$table->add('title', html::label($field_id, Q(rcube_label('dstactive'))));
$table->add(null, $input_dst->show($config['dst_active']));
diff --git a/program/steps/settings/save_prefs.inc b/program/steps/settings/save_prefs.inc
index 3bccffae2..edd184a52 100644
--- a/program/steps/settings/save_prefs.inc
+++ b/program/steps/settings/save_prefs.inc
@@ -20,7 +20,7 @@
*/
$a_user_prefs = array(
- 'timezone' => isset($_POST['_timezone']) ? floatval($_POST['_timezone']) : $CONFIG['timezone'],
+ 'timezone' => isset($_POST['_timezone']) ? (is_numeric($_POST['_timezone']) ? floatval($_POST['_timezone']) : get_input_value('_timezone', RCUBE_INPUT_POST)) : $CONFIG['timezone'],
'dst_active' => isset($_POST['_dst_active']) ? TRUE : FALSE,
'pagesize' => is_numeric($_POST['_pagesize']) ? max(2, intval($_POST['_pagesize'])) : $CONFIG['pagesize'],
'prettydate' => isset($_POST['_pretty_date']) ? TRUE : FALSE,