Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Auto-detect client language and timezone if desired by config/prefs

  • Loading branch information...
commit c8ae2497b7e4c7393210ed186acd672a0040389f 1 parent 7003206
Thomas B. authored
5  CHANGELOG
... ...
@@ -1,6 +1,11 @@
1 1
 CHANGELOG RoundCube Webmail
2 2
 ---------------------------
3 3
 
  4
+2008/09/03 (thomasb)
  5
+----------
  6
+- Allow to auto-detect client language if none set (#1484434)
  7
+- Auto-detect the client timezone (user configurable)
  8
+
4 9
 2008/09/03 (alec)
5 10
 ----------
6 11
 - Add RFC2231 header value continuations support for attachment
7  config/main.inc.php.dist
@@ -129,8 +129,9 @@ $rcmail_config['double_auth'] = false;
129 129
 // please provide a string of exactly 24 chars.
130 130
 $rcmail_config['des_key'] = 'rcmail-!24ByteDESkey*Str';
131 131
 
132  
-// the default locale setting
133  
-$rcmail_config['language'] = 'en_US';
  132
+// the default locale setting (leave empty for auto-detection)
  133
+// RFC1766 formatted language name like en_US, de_DE, de_CH, fr_FR, pt_BR
  134
+$rcmail_config['language'] = null;
134 135
 
135 136
 // use this format for short date display
136 137
 $rcmail_config['date_short'] = 'D H:i';
@@ -338,7 +339,7 @@ $rcmail_config['skin'] = 'default';
338 339
 $rcmail_config['pagesize'] = 40;
339 340
 
340 341
 // use this timezone to display date/time
341  
-$rcmail_config['timezone'] = intval(date('O'))/100 - date('I');
  342
+$rcmail_config['timezone'] = 'auto';
342 343
 
343 344
 // is daylight saving On?
344 345
 $rcmail_config['dst_active'] = (bool)date('I');
2  installer/config.php
@@ -453,7 +453,7 @@
453 453
 echo $input_locale->show($RCI->getprop('language'));
454 454
 
455 455
 ?>
456  
-<div>The default locale setting. This also defines the language of the login screen.</div>
  456
+<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>
457 457
 <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>
458 458
 </dd>
459 459
 
10  program/include/main.inc
@@ -706,9 +706,13 @@ function format_date($date, $format=NULL)
706 706
     return '';
707 707
    
708 708
   // get user's timezone
709  
-  $tz = $CONFIG['timezone'];
710  
-  if ($CONFIG['dst_active'])
711  
-    $tz++;
  709
+  if ($CONFIG['timezone'] == 'auto')
  710
+    $tz = isset($_SESSION['timezone']) ? $_SESSION['timezone'] : intval(date('O'))/100;
  711
+  else {
  712
+    $tz = $CONFIG['timezone'];
  713
+    if ($CONFIG['dst_active'])
  714
+      $tz++;
  715
+  }
712 716
 
713 717
   // convert time to user's timezone
714 718
   $timestamp = $ts - date('Z', $ts) + ($tz * 3600);
19  program/include/rcmail.php
@@ -15,7 +15,7 @@
15 15
  | Author: Thomas Bruederli <roundcube@gmail.com>                        |
16 16
  +-----------------------------------------------------------------------+
17 17
 
18  
- $Id: rcube_browser.php 328 2006-08-30 17:41:21Z thomasb $
  18
+ $Id: rcmail.php 328 2006-08-30 17:41:21Z thomasb $
19 19
 
20 20
 */
21 21
 
@@ -167,7 +167,7 @@ public function set_user($user)
167 167
       $this->config->merge((array)$this->user->get_prefs());
168 168
     }
169 169
     
170  
-    $_SESSION['language'] = $this->user->language = $this->language_prop($this->config->get('language'));
  170
+    $_SESSION['language'] = $this->user->language = $this->language_prop($this->config->get('language', $_SESSION['language']));
171 171
 
172 172
     // set localization
173 173
     setlocale(LC_ALL, $_SESSION['language'] . '.utf8');
@@ -183,7 +183,13 @@ public function set_user($user)
183 183
   private function language_prop($lang)
184 184
   {
185 185
     static $rcube_languages, $rcube_language_aliases;
186  
-
  186
+    
  187
+    // user HTTP_ACCEPT_LANGUAGE if no language is specified
  188
+    if (empty($lang) || $lang == 'auto') {
  189
+       $accept_langs = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
  190
+       $lang = str_replace('-', '_', $accept_langs[0]);
  191
+     }
  192
+     
187 193
     if (empty($rcube_languages)) {
188 194
       @include(INSTALL_PATH . 'program/localization/index.inc');
189 195
     }
@@ -471,6 +477,9 @@ function login($username, $pass, $host=NULL)
471 477
       $_SESSION['imap_ssl']  = $imap_ssl;
472 478
       $_SESSION['password']  = $this->encrypt_passwd($pass);
473 479
       $_SESSION['login_time'] = mktime();
  480
+      
  481
+      if ($_REQUEST['_timezone'] != '_default_')
  482
+        $_SESSION['timezone'] = floatval($_REQUEST['_timezone']);
474 483
 
475 484
       // force reloading complete list of subscribed mailboxes
476 485
       $this->set_imap_prop();
@@ -641,7 +650,7 @@ public function gettext($attrib)
641 650
    */
642 651
   public function load_language($lang = null)
643 652
   {
644  
-    $lang = $lang ? $this->language_prop($lang) : $_SESSION['language'];
  653
+    $lang = $this->language_prop(($lang ? $lang : $_SESSION['language']));
645 654
     
646 655
     // load localized texts
647 656
     if (empty($this->texts) || $lang != $_SESSION['language']) {
@@ -748,7 +757,7 @@ public function kill_session()
748 757
       $this->user->save_prefs(array('message_sort_col' => $_SESSION['sort_col'], 'message_sort_order' => $_SESSION['sort_order']));
749 758
     }
750 759
 
751  
-    $_SESSION = array('language' => $USER->language, 'auth_time' => time(), 'temp' => true);
  760
+    $_SESSION = array('language' => $this->user->language, 'auth_time' => time(), 'temp' => true);
752 761
     setcookie('sessauth', '-del-', time() - 60);
753 762
     $this->user->reset();
754 763
   }
4  program/include/rcube_config.php
@@ -84,9 +84,9 @@ private function load()
84 84
       ini_set('log_errors', 1);
85 85
 
86 86
       if ($this->prop['log_driver'] == 'syslog') {
87  
-	ini_set('error_log', 'syslog');
  87
+        ini_set('error_log', 'syslog');
88 88
       } else {
89  
-	ini_set('error_log', $this->prop['log_dir'].'/errors');
  89
+        ini_set('error_log', $this->prop['log_dir'].'/errors');
90 90
       }
91 91
     }
92 92
     if ($this->prop['debug_level'] & 4) {
56  program/include/rcube_shared.inc
@@ -28,62 +28,6 @@
28 28
 
29 29
 
30 30
 /**
31  
- * Provide details about the client's browser
32  
- *
33  
- * @return array Key-value pairs of browser properties
34  
- */
35  
-function rcube_browser()
36  
-{
37  
-  $HTTP_USER_AGENT = $_SERVER['HTTP_USER_AGENT'];
38  
-
39  
-  $bw['ver'] = 0;
40  
-  $bw['win'] = stristr($HTTP_USER_AGENT, 'win');
41  
-  $bw['mac'] = stristr($HTTP_USER_AGENT, 'mac');
42  
-  $bw['linux'] = stristr($HTTP_USER_AGENT, 'linux');
43  
-  $bw['unix']  = stristr($HTTP_USER_AGENT, 'unix');
44  
-
45  
-  $bw['ns4'] = stristr($HTTP_USER_AGENT, 'mozilla/4') && !stristr($HTTP_USER_AGENT, 'msie');
46  
-  $bw['ns']  = ($bw['ns4'] || stristr($HTTP_USER_AGENT, 'netscape'));
47  
-  $bw['ie']  = stristr($HTTP_USER_AGENT, 'msie');
48  
-  $bw['mz']  = stristr($HTTP_USER_AGENT, 'mozilla/5');
49  
-  $bw['opera'] = stristr($HTTP_USER_AGENT, 'opera');
50  
-  $bw['safari'] = stristr($HTTP_USER_AGENT, 'safari');
51  
-
52  
-  if($bw['ns'])
53  
-  {
54  
-    $test = eregi("mozilla\/([0-9\.]+)", $HTTP_USER_AGENT, $regs);
55  
-    $bw['ver'] = $test ? (float)$regs[1] : 0;
56  
-  }
57  
-  if($bw['mz'])
58  
-  {
59  
-    $test = ereg("rv:([0-9\.]+)", $HTTP_USER_AGENT, $regs);
60  
-    $bw['ver'] = $test ? (float)$regs[1] : 0;
61  
-  }
62  
-  if($bw['ie'])
63  
-  {
64  
-    $test = eregi("msie ([0-9\.]+)", $HTTP_USER_AGENT, $regs);
65  
-    $bw['ver'] = $test ? (float)$regs[1] : 0;
66  
-  }
67  
-  if($bw['opera'])
68  
-  {
69  
-    $test = eregi("opera ([0-9\.]+)", $HTTP_USER_AGENT, $regs);
70  
-    $bw['ver'] = $test ? (float)$regs[1] : 0;
71  
-  }
72  
-
73  
-  if(eregi(" ([a-z]{2})-([a-z]{2})", $HTTP_USER_AGENT, $regs))
74  
-    $bw['lang'] =  $regs[1];
75  
-  else
76  
-    $bw['lang'] =  'en';
77  
-
78  
-  $bw['dom'] = ($bw['mz'] || $bw['safari'] || ($bw['ie'] && $bw['ver']>=5) || ($bw['opera'] && $bw['ver']>=7));
79  
-  $bw['pngalpha'] = $bw['mz'] || $bw['safari'] || ($bw['ie'] && $bw['ver']>=5.5) ||
80  
-                    ($bw['ie'] && $bw['ver']>=5 && $bw['mac']) || ($bw['opera'] && $bw['ver']>=7) ? TRUE : FALSE;
81  
-
82  
-  return $bw;
83  
-}
84  
-
85  
-
86  
-/**
87 31
  * Send HTTP headers to prevent caching this page
88 32
  */
89 33
 function send_nocacheing_headers()
2  program/include/rcube_template.php
@@ -922,6 +922,7 @@ private function login_form($attrib)
922 922
         $input_user   = new html_inputfield(array('name' => '_user', 'id' => 'rcmloginuser', 'size' => 30) + $attrib);
923 923
         $input_pass   = new html_passwordfield(array('name' => '_pass', 'id' => 'rcmloginpwd', 'size' => 30) + $attrib);
924 924
         $input_action = new html_hiddenfield(array('name' => '_action', 'value' => 'login'));
  925
+        $input_tzone  = new html_hiddenfield(array('name' => '_timezone', 'id' => 'rcmlogintz', 'value' => '_default_'));
925 926
         $input_host   = null;
926 927
 
927 928
         if (is_array($default_host)) {
@@ -960,6 +961,7 @@ private function login_form($attrib)
960 961
         }
961 962
 
962 963
         $out = $input_action->show();
  964
+        $out .= $input_tzone->show();
963 965
         $out .= $table->show();
964 966
 
965 967
         // surround html output with a form tag
8  program/js/app.js
@@ -318,13 +318,19 @@ function rcube_webmail()
318 318
       case 'login':
319 319
         var input_user = rcube_find_object('rcmloginuser');
320 320
         var input_pass = rcube_find_object('rcmloginpwd');
  321
+        var input_tz = rcube_find_object('rcmlogintz');
  322
+
321 323
         if (input_user)
322 324
           input_user.onkeyup = function(e){ return rcmail.login_user_keyup(e); };
323 325
         if (input_user && input_user.value=='')
324 326
           input_user.focus();
325 327
         else if (input_pass)
326 328
           input_pass.focus();
327  
-          
  329
+
  330
+        // detect client timezone
  331
+        if (input_tz)
  332
+          input_tz.value = new Date().getTimezoneOffset() / -60;
  333
+
328 334
         this.enable_command('login', true);
329 335
         break;
330 336
       
1  program/localization/en_US/labels.inc
@@ -254,6 +254,7 @@ $labels['newitem']  = 'New item';
254 254
 $labels['edititem']  = 'Edit item';
255 255
 
256 256
 $labels['setdefault']  = 'Set default';
  257
+$labels['autodetect']  = 'Auto';
257 258
 $labels['language']  = 'Language';
258 259
 $labels['timezone']  = 'Time zone';
259 260
 $labels['pagesize']  = 'Rows per page';
7  program/steps/settings/func.inc
@@ -49,14 +49,15 @@ function rcmail_user_prefs_form($attrib)
49 49
     $select_lang->add(array_values($a_lang), array_keys($a_lang));
50 50
   
51 51
     $table->add('title', html::label($field_id, Q(rcube_label('language'))));
52  
-    $table->add(null, $select_lang->show($_SESSION['language']));
  52
+    $table->add(null, $select_lang->show($config['language']));
53 53
   }
54 54
 
55 55
 
56 56
   // show page size selection
57 57
   if (!isset($no_override['timezone'])) {
58 58
     $field_id = 'rcmfd_timezone';
59  
-    $select_timezone = new html_select(array('name' => '_timezone', 'id' => $field_id));
  59
+    $select_timezone = new html_select(array('name' => '_timezone', 'id' => $field_id, 'onchange' => "document.getElementById('rcmfd_dst').disabled=this.selectedIndex==0"));
  60
+    $select_timezone->add(rcube_label('autodetect'), 'auto');
60 61
     $select_timezone->add('(GMT -11:00) Midway Island, Samoa', '-11');
61 62
     $select_timezone->add('(GMT -10:00) Hawaii', '-10');
62 63
     $select_timezone->add('(GMT -9:30) Marquesas Islands', '-9.5');
@@ -104,7 +105,7 @@ function rcmail_user_prefs_form($attrib)
104 105
   // daylight savings
105 106
   if (!isset($no_override['dst_active'])) {
106 107
     $field_id = 'rcmfd_dst';
107  
-    $input_dst = new html_checkbox(array('name' => '_dst_active', 'id' => $field_id, 'value' => 1));
  108
+    $input_dst = new html_checkbox(array('name' => '_dst_active', 'id' => $field_id, 'value' => 1, 'disabled' => ($config['timezone'] == 'auto')));
108 109
     
109 110
     $table->add('title', html::label($field_id, Q(rcube_label('dstactive'))));
110 111
     $table->add(null, $input_dst->show($config['dst_active']));
2  program/steps/settings/save_prefs.inc
@@ -20,7 +20,7 @@
20 20
 */
21 21
 
22 22
 $a_user_prefs = array(
23  
-  'timezone'     => isset($_POST['_timezone']) ? floatval($_POST['_timezone']) : $CONFIG['timezone'],
  23
+  'timezone'     => isset($_POST['_timezone']) ? (is_numeric($_POST['_timezone']) ? floatval($_POST['_timezone']) : get_input_value('_timezone', RCUBE_INPUT_POST)) : $CONFIG['timezone'],
24 24
   'dst_active'   => isset($_POST['_dst_active']) ? TRUE : FALSE,
25 25
   'pagesize'     => is_numeric($_POST['_pagesize']) ? max(2, intval($_POST['_pagesize'])) : $CONFIG['pagesize'],
26 26
   'prettydate'   => isset($_POST['_pretty_date']) ? TRUE : FALSE,

0 notes on commit c8ae249

Please sign in to comment.
Something went wrong with that request. Please try again.