Merge remote-tracking branch 'upstream/develop' into 1610-gcontact-type

This commit is contained in:
Michael Vogel 2016-10-04 03:52:22 +00:00
commit 8cde8b375b
4 changed files with 35 additions and 34 deletions

View file

@ -1,13 +1,7 @@
<?php <?php
require_once("include/dba.php");
/**
* translation support
*/
/** /**
* @brief translation support
* *
* Get the language setting directly from system variables, bypassing get_config() * Get the language setting directly from system variables, bypassing get_config()
* as database may not yet be configured. * as database may not yet be configured.
@ -16,8 +10,12 @@ require_once("include/dba.php");
* *
*/ */
require_once("include/dba.php");
if(! function_exists('get_browser_language')) { if(! function_exists('get_browser_language')) {
/**
* @brief get the prefered language from the HTTP_ACCEPT_LANGUAGE header
*/
function get_browser_language() { function get_browser_language() {
if (x($_SERVER,'HTTP_ACCEPT_LANGUAGE')) { if (x($_SERVER,'HTTP_ACCEPT_LANGUAGE')) {
@ -25,32 +23,34 @@ function get_browser_language() {
preg_match_all('/([a-z]{1,8}(-[a-z]{1,8})?)\s*(;\s*q\s*=\s*(1|0\.[0-9]+))?/i', 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); $_SERVER['HTTP_ACCEPT_LANGUAGE'], $lang_parse);
$lang_list = [];
if (count($lang_parse[1])) { if (count($lang_parse[1])) {
// create a list like "en" => 0.8 // go through the list of prefered languages and add a generic language
$langs = array_combine($lang_parse[1], $lang_parse[4]); // for sub-linguas (e.g. de-ch will add de) if not already in array
for ($i=0; $i<count($lang_parse[1]); $i++) {
// set default to 1 for any without q factor $lang_list[] = strtolower($lang_parse[1][$i]);
foreach ($langs as $lang => $val) { if ( strlen($lang_parse[1][$i])>3 ) {
if ($val === '') $langs[$lang] = 1; $dashpos = strpos($lang_parse[1][$i], '-');
} if (! in_array(substr($lang_parse[1][$i], 0, $dashpos), $lang_list ) ) {
$lang_list[] = strtolower(substr($lang_parse[1][$i], 0, $dashpos));
// sort list based on value }
arsort($langs, SORT_NUMERIC); }
}
}
if(isset($langs) && count($langs)) {
foreach ($langs as $lang => $v) {
if(file_exists("view/lang/$lang") && is_dir("view/lang/$lang")) {
$preferred = $lang;
break;
} }
} }
} }
// check if we have translations for the preferred languages and pick the 1st that has
for ($i=0; $i<count($lang_list); $i++) {
$lang = $lang_list[$i];
if(file_exists("view/lang/$lang") && is_dir("view/lang/$lang")) {
$preferred = $lang;
break;
}
}
if(isset($preferred)) if(isset($preferred))
return $preferred; return $preferred;
// in case none matches, get the system wide configured language, or fall back to English
$a = get_app(); $a = get_app();
return ((isset($a->config['system']['language'])) ? $a->config['system']['language'] : 'en'); return ((isset($a->config['system']['language'])) ? $a->config['system']['language'] : 'en');
}} }}

View file

@ -79,11 +79,9 @@ function authenticate_success($user_record, $login_initial = false, $interactive
header('X-Account-Management-Status: active; name="' . $a->user['username'] . '"; id="' . $a->user['nickname'] .'"'); header('X-Account-Management-Status: active; name="' . $a->user['username'] . '"; id="' . $a->user['nickname'] .'"');
if($login_initial || $login_refresh) { if($login_initial || $login_refresh) {
$l = get_browser_language();
q("UPDATE `user` SET `login_date` = '%s', `language` = '%s' WHERE `uid` = %d", q("UPDATE `user` SET `login_date` = '%s' WHERE `uid` = %d",
dbesc(datetime_convert()), dbesc(datetime_convert()),
dbesc($l),
intval($_SESSION['uid']) intval($_SESSION['uid'])
); );

View file

@ -1127,18 +1127,20 @@ function admin_page_dbsync(&$a) {
* @param App $a * @param App $a
*/ */
function admin_page_users_post(&$a){ function admin_page_users_post(&$a){
$pending = (x($_POST, 'pending') ? $_POST['pending'] : array()); $pending = (x($_POST, 'pending') ? $_POST['pending'] : array());
$users = (x($_POST, 'user') ? $_POST['user'] : array()); $users = (x($_POST, 'user') ? $_POST['user'] : array());
$nu_name = (x($_POST, 'new_user_name') ? $_POST['new_user_name'] : ''); $nu_name = (x($_POST, 'new_user_name') ? $_POST['new_user_name'] : '');
$nu_nickname = (x($_POST, 'new_user_nickname') ? $_POST['new_user_nickname'] : ''); $nu_nickname = (x($_POST, 'new_user_nickname') ? $_POST['new_user_nickname'] : '');
$nu_email = (x($_POST, 'new_user_email') ? $_POST['new_user_email'] : ''); $nu_email = (x($_POST, 'new_user_email') ? $_POST['new_user_email'] : '');
$nu_language = get_config('system', 'language');
check_form_security_token_redirectOnErr('/admin/users', 'admin_users'); check_form_security_token_redirectOnErr('/admin/users', 'admin_users');
if(!($nu_name==="") && !($nu_email==="") && !($nu_nickname==="")) { if(!($nu_name==="") && !($nu_email==="") && !($nu_nickname==="")) {
require_once('include/user.php'); require_once('include/user.php');
$result = create_user(array('username'=>$nu_name, 'email'=>$nu_email, 'nickname'=>$nu_nickname, 'verified'=>1)); $result = create_user(array('username'=>$nu_name, 'email'=>$nu_email,
'nickname'=>$nu_nickname, 'verified'=>1, 'language'=>$nu_language));
if(! $result['success']) { if(! $result['success']) {
notice($result['message']); notice($result['message']);
return; return;

View file

@ -52,6 +52,7 @@ function register_post(&$a) {
$arr['blocked'] = $blocked; $arr['blocked'] = $blocked;
$arr['verified'] = $verified; $arr['verified'] = $verified;
$arr['language'] = get_browser_language();
$result = create_user($arr); $result = create_user($arr);