1
1
Fork 0

improved browser language detect, set user language on login

This commit is contained in:
Friendika 2011-05-23 17:18:36 -07:00
parent 3ea145fae7
commit 3e6180183b
5 changed files with 65 additions and 19 deletions

View file

@ -4,7 +4,7 @@ set_time_limit(0);
ini_set('pcre.backtrack_limit', 250000);
define ( 'FRIENDIKA_VERSION', '2.2.988' );
define ( 'FRIENDIKA_VERSION', '2.2.989' );
define ( 'DFRN_PROTOCOL_VERSION', '2.21' );
define ( 'DB_UPDATE_VERSION', 1054 );
@ -2707,6 +2707,8 @@ function unamp($s) {
}}
if(! function_exists('lang_selector')) {
function lang_selector() {
global $lang;
@ -2748,4 +2750,5 @@ function is_site_admin() {
if(local_user() && x($a->user,'email') && x($a->config,'admin_email') && ($a->user['email'] === $a->config['admin_email']))
return true;
return false;
}}
}}

View file

@ -232,9 +232,11 @@ else {
$_SESSION['cid'] = $a->cid;
}
$l = get_language();
q("UPDATE `user` SET `login_date` = '%s' WHERE `uid` = %d LIMIT 1",
q("UPDATE `user` SET `login_date` = '%s', `language` = '%s' WHERE `uid` = %d LIMIT 1",
dbesc(datetime_convert()),
dbesc($l),
intval($_SESSION['uid'])
);

View file

@ -1,8 +1,59 @@
<?php
/**
* translation support
*/
/**
*
* Get the language setting directly from system variables, bypassing get_config()
* as database may not yet be configured.
*
* If possible, we use the value from the browser.
*
*/
if(! function_exists('get_language')) {
function get_language() {
if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
// break up string into pieces (languages and q factors)
preg_match_all('/([a-z]{1,8}(-[a-z]{1,8})?)\s*(;\s*q\s*=\s*(1|0\.[0-9]+))?/i',
$_SERVER['HTTP_ACCEPT_LANGUAGE'], $lang_parse);
if (count($lang_parse[1])) {
// create a list like "en" => 0.8
$langs = array_combine($lang_parse[1], $lang_parse[4]);
// set default to 1 for any without q factor
foreach ($langs as $lang => $val) {
if ($val === '') $langs[$lang] = 1;
}
// sort list based on value
arsort($langs, SORT_NUMERIC);
}
}
if(isset($langs) && count($langs)) {
foreach ($langs as $lang => $v) {
if(file_exists("view/$lang") && is_dir("view/$lang")) {
$preferred = $lang;
break;
}
}
}
if(isset($preferred))
return $preferred;
return ((isset($a->config['system']['language'])) ? $a->config['system']['language'] : 'en');
}}
// load string translation table for alternate language
if(! function_exists('load_translation_table')) {

View file

@ -29,22 +29,8 @@ $install = ((file_exists('.htconfig.php') && filesize('.htconfig.php')) ? false
@include(".htconfig.php");
/**
*
* Get the language setting directly from system variables, bypassing get_config()
* as database may not yet be configured.
*
* If possible, we use the value from the browser.
*
*/
if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
$langs = preg_split("/[,-]/",$_SERVER['HTTP_ACCEPT_LANGUAGE'],2);
$lang = $langs[0];
} else {
$lang = ((isset($a->config['system']['language'])) ? $a->config['system']['language'] : 'en');
}
$lang = get_language();
load_translation_table($lang);

View file

@ -103,11 +103,15 @@ function openid_content(&$a) {
$_SESSION['cid'] = $a->cid;
}
q("UPDATE `user` SET `login_date` = '%s' WHERE `uid` = %d LIMIT 1",
$l = get_language();
q("UPDATE `user` SET `login_date` = '%s', `language` = '%s' WHERE `uid` = %d LIMIT 1",
dbesc(datetime_convert()),
dbesc($l),
intval($_SESSION['uid'])
);
header('X-Account-Management-Status: active; name="' . $a->user['username'] . '"; id="' . $a->user['nickname'] .'"');
if(($a->module !== 'home') && isset($_SESSION['return_url']))
goaway($a->get_baseurl() . '/' . $_SESSION['return_url']);