[Openupload-svn-update] SF.net SVN: openupload:[27] trunk
Status: Beta
Brought to you by:
tsdogs
|
From: <ts...@us...> - 2008-10-16 18:45:16
|
Revision: 27
http://openupload.svn.sourceforge.net/openupload/?rev=27&view=rev
Author: tsdogs
Date: 2008-10-16 18:45:05 +0000 (Thu, 16 Oct 2008)
Log Message:
-----------
Add user language preference and browser language detection
Modified Paths:
--------------
trunk/lib/general.inc.php
trunk/lib/main.inc.php
trunk/lib/modules/db/mysql.inc.php
trunk/lib/modules/default/admin.inc.php
trunk/lib/modules/default/auth.inc.php
trunk/templates/default/modules/admin/useradd.tpl
trunk/templates/default/modules/admin/useredit.tpl
trunk/templates/default/modules/auth/profile.tpl
trunk/templates/default/modules/auth/profileedit.tpl
trunk/templates/default/modules/auth/registerForm.tpl
Modified: trunk/lib/general.inc.php
===================================================================
--- trunk/lib/general.inc.php 2008-10-16 17:46:16 UTC (rev 26)
+++ trunk/lib/general.inc.php 2008-10-16 18:45:05 UTC (rev 27)
@@ -46,7 +46,6 @@
return $result;
}
-
function translate($txt,$domain,$args) {
/* now we retrieve the translated message */
$txt = app()->tr->translate($txt,$domain);
Modified: trunk/lib/main.inc.php
===================================================================
--- trunk/lib/main.inc.php 2008-10-16 17:46:16 UTC (rev 26)
+++ trunk/lib/main.inc.php 2008-10-16 18:45:05 UTC (rev 27)
@@ -28,10 +28,6 @@
$this->tpl->caching = $this->config['site']['caching'];
$this->page['template']= $this->config['WWW_ROOT'].'/templates/'.$this->config['site']['template'];
- /* initialize the application components */
- if (!isset($_SESSIO['user']['lang'])) {
- $_SESSION['user']['lang']='en';
- }
/* include the class first */
$dbtype = $this->config['database']['type'];
@@ -49,10 +45,8 @@
require_once($this->config['INSTALL_ROOT'].'/lib/modules/auth/'.$authmname.'.inc.php');
$auth = $authmname.'Auth';
$this->auth = new $auth();
- $this->auth->init();
$this->user = new User();
- $this->user->init();
/* translation module */
if (isset($this->config['translator'])) {
@@ -63,7 +57,20 @@
require_once($this->config['INSTALL_ROOT'].'/lib/modules/tr/'.$trname.'.inc.php');
$tr = $trname.'Translator';
$this->tr = new $tr();
+
+ $this->langs = $this->db->loadTable('langs','','','id');
+
+ /* configure the language */
+ if ($this->user->userInfo('lang')=='') {
+ $lang = $this->getBrowserLang();
+ $user = $this->user->userInfo();
+ $user['lang']=$lang;
+ $this->user->setUserInfo($user);
+ }
+
$this->tr->init();
+ $this->auth->init();
+ $this->user->init();
$this->config['modules'][]='files';
$this->config['modules'][]='admin';
@@ -73,6 +80,31 @@
$this->initModules();
}
+ function getBrowserLang() {
+ global $_SERVER;
+
+ /* calculate preferred language */
+ $langs = str_replace(' ','',strtolower($_SERVER['HTTP_ACCEPT_LANGUAGE']));
+ $langs = explode(',',$langs);
+ foreach ($langs as $ls) {
+ $language = explode(';',$ls);
+ foreach ($language as $l) {
+ foreach ($this->langs as $ml) {
+ if (strpos(strtolower($ml['browser']),'['.$l.']')!==FALSE) {
+ return $ml['id'];
+ }
+ if (strpos($l,'-')) {
+ $x = explode('-',$l);
+ if (strpos(strtolower($ml['browser']),'['.$x[0].']')!==FALSE) {
+ return $ml['id'];
+ }
+ }
+ }
+ }
+ }
+ return $this->config['defaultlang'];
+ }
+
function fetch($tname) {
if (file_exists($this->tpl->template_dir.'/'.$this->config['site']['template'].'/'.$tname.'.tpl')) {
return $this->tpl->fetch($this->config['site']['template'].'/'.$tname.'.tpl');
@@ -261,7 +293,8 @@
$m->$fun();
/* now display the final page */
- $this->tpl->assign('user',$_SESSION['user']);
+ $this->tpl->assign('user',$this->user->userInfo());
+ $this->tpl->assign('langs',$this->langs);
unset($_SESSION['user']['messages']);
unset($_SESSION['user']['errors']);
$this->tpl->assign('plugins',$this->pluginHTML);
Modified: trunk/lib/modules/db/mysql.inc.php
===================================================================
--- trunk/lib/modules/db/mysql.inc.php 2008-10-16 17:46:16 UTC (rev 26)
+++ trunk/lib/modules/db/mysql.inc.php 2008-10-16 18:45:05 UTC (rev 27)
@@ -43,9 +43,9 @@
function addUser($user) {
$e = 'mysql_real_escape_string';
- $sql = 'insert into '.$this->prefix.'users (id,login,password,name,group_id,email,active) values
+ $sql = 'insert into '.$this->prefix.'users (id,login,password,name,group_id,email,lang,active) values
(NULL,"'.$e($user['login']).'","'.$e($user['password']).'","'.$e($user['name']).'","'.$e($user['group_id']).'","'
- .$e($user['email']).'","'.$e($user['active']).'")';
+ .$e($user['email']).'","'.$e($user['lang']).'","'.$e($user['active']).'")';
mysql_query($sql);
}
@@ -53,7 +53,7 @@
$e = 'mysql_real_escape_string';
$sql = 'update '.$this->prefix.'users set
password="'.$e($user['password']).'",group_id="'.$e($user['group_id']).'",name="'.$e($user['name']).
- '",email="'.$e($user['email']).'",active="'.$e($user['active']).'"'.
+ '",email="'.$e($user['email']).'",lang="'.$e($user['lang']).'",active="'.$e($user['active']).'"'.
'where login="'.$user['login'].'"';
mysql_query($sql);
}
Modified: trunk/lib/modules/default/admin.inc.php
===================================================================
--- trunk/lib/modules/default/admin.inc.php 2008-10-16 17:46:16 UTC (rev 26)
+++ trunk/lib/modules/default/admin.inc.php 2008-10-16 18:45:05 UTC (rev 27)
@@ -83,6 +83,7 @@
$user['group_id']=$_POST['addusergroup'];
$user['email']=$_POST['adduseremail'];
$user['active']=$_POST['adduseractive'];
+ $user['lang']=$_POST['adduserlang'];
$error = false;
if (strlen($_POST['adduserlogin'])<5) {
app()->error('login name must be at least 5 char long!');
@@ -147,6 +148,7 @@
$user['name']=$_POST['editusername'];
$user['group_id']=$_POST['editusergroup'];
$user['email']=$_POST['edituseremail'];
+ $user['lang']=$_POST['edituserlang'];
$user['active']=$_POST['edituseractive'];
$error = false;
if ($_POST['edituserpassword']!='') {
Modified: trunk/lib/modules/default/auth.inc.php
===================================================================
--- trunk/lib/modules/default/auth.inc.php 2008-10-16 17:46:16 UTC (rev 26)
+++ trunk/lib/modules/default/auth.inc.php 2008-10-16 18:45:05 UTC (rev 27)
@@ -122,6 +122,7 @@
$user['name'] = $_POST['registername'];
$user['password'] = $_POST['registerpassword'];
$user['email'] = $_POST['registeremail'];
+ $user['lang'] = $_POST['registerlang'];
$user['group_id'] = app()->config['register']['default_group'];
$user['active'] = 1;
$result = app()->pluginAction('registerConfirm',$user);
@@ -161,7 +162,6 @@
function profileedit() {
global $_POST;
$user = app()->user->userInfo();
-echo 'pwd:'.$user['password'];
if (isset($_POST['username'])) {
/* check for valid values*/
if ($_POST['username']=='') {
@@ -173,6 +173,7 @@
app()->error(tr('Please enter a valid e-mail address!'));
$error=true;
}
+ $user['lang']=$_POST['userlang'];
$user['email']=$_POST['useremail'];
if ($_POST['newpassword']!='') {
$error = false;
@@ -192,6 +193,7 @@
}
if (!$error) {
app()->db->updateUser($user);
+ app()->user->setUserInfo($user);
$this->nextStep(1);
}
}
Modified: trunk/templates/default/modules/admin/useradd.tpl
===================================================================
--- trunk/templates/default/modules/admin/useradd.tpl 2008-10-16 17:46:16 UTC (rev 26)
+++ trunk/templates/default/modules/admin/useradd.tpl 2008-10-16 18:45:05 UTC (rev 27)
@@ -14,6 +14,9 @@
<option value="{$g.name}" {if $g.name==$adduser.group_id} selected{/if}>{$g.description}</option>
{/foreach}
</select></td></tr>
+<tr><td>{tr}Preferred language{/tr}:</td><td> <select name="adduserlang">
+{foreach from=$langs item=l}<option value="{$l.id}" {if $adduser.lang==$l.id}selected{/if}>{$l.name}</option>{/foreach}
+</select></td></tr>
<tr><td>{tr}Active{/tr}:</td><td><input type="checkbox" name="adduseractive" value="1" {if $adduser.active==1}checked{/if}></td></tr>
<tr><td colspan="2" align=right><input type="submit" class="submit" value="{tr}Add{/tr}"></td></tr>
</table>
Modified: trunk/templates/default/modules/admin/useredit.tpl
===================================================================
--- trunk/templates/default/modules/admin/useredit.tpl 2008-10-16 17:46:16 UTC (rev 26)
+++ trunk/templates/default/modules/admin/useredit.tpl 2008-10-16 18:45:05 UTC (rev 27)
@@ -14,6 +14,9 @@
<option value="{$g.name}" {if $g.name==$edituser.group_id} selected{/if}>{$g.description}</option>
{/foreach}
</select></td></tr>
+<tr><td>{tr}Preferred language{/tr}:</td><td> <select name="edituserlang">
+{foreach from=$langs item=l}<option value="{$l.id}" {if $edituser.lang==$l.id}selected{/if}>{$l.name}</option>{/foreach}
+</select></td></tr>
<tr><td>{tr}Active{/tr}:</td><td><input type="checkbox" name="edituseractive" value="1" {if $edituser.active==1}checked{/if}></td></tr>
<tr><td colspan="2" align=right><input type="submit" class="submit" value="{tr}Confirm{/tr}"></td></tr>
</table>
Modified: trunk/templates/default/modules/auth/profile.tpl
===================================================================
--- trunk/templates/default/modules/auth/profile.tpl 2008-10-16 17:46:16 UTC (rev 26)
+++ trunk/templates/default/modules/auth/profile.tpl 2008-10-16 18:45:05 UTC (rev 27)
@@ -2,6 +2,7 @@
<tr><td>{tr}Login name{/tr}:</td><td>{$puser.login}</td></tr>
<tr><td>{tr}Full Name{/tr}:</td><td>{$puser.name}</td></tr>
<tr><td>{tr}e-mail{/tr}:</td><td>{$puser.email}</td></tr>
+<tr><td>{tr}Language{/tr}:</td><td>{$langs[$puser.lang].name}</td></tr>
<tr><td colspan="2"><hr></td></tr>
<tr><td colspan="2"><a href="{$script}?action={$action}&step={$nextstep}">{tr}Change{/tr}</td></tr>
</table>
\ No newline at end of file
Modified: trunk/templates/default/modules/auth/profileedit.tpl
===================================================================
--- trunk/templates/default/modules/auth/profileedit.tpl 2008-10-16 17:46:16 UTC (rev 26)
+++ trunk/templates/default/modules/auth/profileedit.tpl 2008-10-16 18:45:05 UTC (rev 27)
@@ -5,6 +5,9 @@
<tr><td>{tr}Login name{/tr}:</td><td>{$puser.login}</td></tr>
<tr><td>{tr}Full Name{/tr}:</td><td><input type="text" name="username" value="{$puser.name}"></td></tr>
<tr><td>{tr}e-mail{/tr}:</td><td><input type="text" name="useremail" value="{$puser.email}"></td></tr>
+<tr><td>{tr}Preferred language{/tr}:</td><td> <select name="userlang">
+{foreach from=$langs item=l}<option value="{$l.id}" {if $user.lang==$l.id}selected{/if}>{$l.name}</option>{/foreach}
+</select></td></tr>
<tr><td colspan="2"><hr></td></tr>
<tr><td>{tr}Old password{/tr}:</td><td><input type="password" name="oldpassword" value=""></td></tr>
<tr><td>{tr}New password{/tr}:</td><td><input type="password" name="newpassword" value=""></td></tr>
Modified: trunk/templates/default/modules/auth/registerForm.tpl
===================================================================
--- trunk/templates/default/modules/auth/registerForm.tpl 2008-10-16 17:46:16 UTC (rev 26)
+++ trunk/templates/default/modules/auth/registerForm.tpl 2008-10-16 18:45:05 UTC (rev 27)
@@ -7,7 +7,9 @@
<tr><td>{tr}Retype Password{/tr}:</td><td><input type="password" name="registerrepassword"></td></tr>
<tr><td>{tr}Full Name{/tr}:</td><td><input type="text" name="registername" value="{$register.name}"></td></tr>
<tr><td>{tr}e-mail{/tr}:</td><td><input type="text" name="registeremail" value="{$register.email}"></td></tr>
-<!--<tr><td>{tr}Preferred language{/tr}: <select name="registerlang"></select></td></tr>-->
+<tr><td>{tr}Preferred language{/tr}:</td><td> <select name="registerlang">
+{foreach from=$langs item=l}<option value="{$l.id}" {if $user.lang==$l.id}selected{/if}>{$l.name}</option>{/foreach}
+</select></td></tr>
{$plugins}
<tr><td colspan="2" align="right"><input type="submit" class="submit" value="Register"></td></tr>
</table>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|