Bludit Installer: timezone, language and locale autodetection
This commit is contained in:
parent
34fff17d03
commit
95e9835867
File diff suppressed because one or more lines are too long
44
install.php
44
install.php
|
@ -107,24 +107,32 @@ include(PATH_HELPERS.'log.class.php');
|
||||||
include(PATH_HELPERS.'date.class.php');
|
include(PATH_HELPERS.'date.class.php');
|
||||||
include(PATH_KERNEL.'dblanguage.class.php');
|
include(PATH_KERNEL.'dblanguage.class.php');
|
||||||
|
|
||||||
// --- LANGUAGE ---
|
// --- LANGUAGE and LOCALE ---
|
||||||
|
|
||||||
// Try to detect language from HTTP
|
|
||||||
$explode = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
|
|
||||||
$localeFromHTTP = empty($explode[0])?'en_US':str_replace('-', '_', $explode[0]);
|
|
||||||
|
|
||||||
|
// Language from the URI
|
||||||
if(isset($_GET['language'])) {
|
if(isset($_GET['language'])) {
|
||||||
$localeFromHTTP = Sanitize::html($_GET['language']);
|
$localeFromHTTP = Sanitize::html($_GET['language']);
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
// Try to detect the locale
|
||||||
|
if( function_exists('locale_accept_from_http') ) {
|
||||||
|
$localeFromHTTP = locale_accept_from_http($_SERVER['HTTP_ACCEPT_LANGUAGE']);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$explodeLocale = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
|
||||||
|
$localeFromHTTP = empty($explodeLocale[0])?'en_US':str_replace('-', '_', $explodeLocale[0]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if( !Sanitize::pathFile(PATH_LANGUAGES.$localeFromHTTP.'.json') ) {
|
// Check if the dictionary exists, otherwise the default language is English.
|
||||||
|
if( !file_exists(PATH_LANGUAGES.$localeFromHTTP.'.json') ) {
|
||||||
$localeFromHTTP = 'en_US';
|
$localeFromHTTP = 'en_US';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get language file
|
||||||
$Language = new dbLanguage($localeFromHTTP);
|
$Language = new dbLanguage($localeFromHTTP);
|
||||||
|
|
||||||
// --- LOCALE ---
|
// Set locale
|
||||||
|
|
||||||
setlocale(LC_ALL, $localeFromHTTP);
|
setlocale(LC_ALL, $localeFromHTTP);
|
||||||
|
|
||||||
// --- TIMEZONE ---
|
// --- TIMEZONE ---
|
||||||
|
@ -132,7 +140,7 @@ setlocale(LC_ALL, $localeFromHTTP);
|
||||||
// Check if timezone is defined in php.ini
|
// Check if timezone is defined in php.ini
|
||||||
$iniDate = ini_get('date.timezone');
|
$iniDate = ini_get('date.timezone');
|
||||||
if(empty($iniDate)) {
|
if(empty($iniDate)) {
|
||||||
// Timezone not defined in php.ini, then UTC as default.
|
// Timezone not defined in php.ini, then set UTC as default.
|
||||||
date_default_timezone_set('UTC');
|
date_default_timezone_set('UTC');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -229,15 +237,15 @@ function checkSystem()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Finish with the installation.
|
// Finish with the installation.
|
||||||
function install($adminPassword, $email, $timezoneOffset)
|
function install($adminPassword, $email, $timezone)
|
||||||
{
|
{
|
||||||
global $Language;
|
global $Language;
|
||||||
|
|
||||||
$stdOut = array();
|
$stdOut = array();
|
||||||
|
|
||||||
$timezone = timezone_name_from_abbr('', $timezoneOffset, 0);
|
if( date_default_timezone_set($timezone) ) {
|
||||||
if($timezone === false) { $timezone = timezone_name_from_abbr('', $timezoneOffset, 0); } // Workaround bug #44780
|
date_default_timezone_set('UTC');
|
||||||
date_default_timezone_set($timezone);
|
}
|
||||||
|
|
||||||
$currentDate = Date::current(DB_DATE_FORMAT);
|
$currentDate = Date::current(DB_DATE_FORMAT);
|
||||||
|
|
||||||
|
@ -580,6 +588,7 @@ if( $_SERVER['REQUEST_METHOD'] == 'POST' )
|
||||||
<!-- Javascript -->
|
<!-- Javascript -->
|
||||||
<script charset="utf-8" src="./js/jquery.min.js?version=<?php echo time() ?>"></script>
|
<script charset="utf-8" src="./js/jquery.min.js?version=<?php echo time() ?>"></script>
|
||||||
<script charset="utf-8" src="./js/uikit/uikit.min.js?version=<?php echo time() ?>"></script>
|
<script charset="utf-8" src="./js/uikit/uikit.min.js?version=<?php echo time() ?>"></script>
|
||||||
|
<script charset="utf-8" src="./js/jstz.min.js?version=<?php echo time() ?>"></script>
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
<body class="uk-height-1-1">
|
<body class="uk-height-1-1">
|
||||||
|
@ -673,15 +682,14 @@ if( $_SERVER['REQUEST_METHOD'] == 'POST' )
|
||||||
<script>
|
<script>
|
||||||
$(document).ready(function()
|
$(document).ready(function()
|
||||||
{
|
{
|
||||||
// Set timezone
|
|
||||||
var timezoneOffset = -(new Date().getTimezoneOffset() * 60);
|
// Timezone
|
||||||
$("#jstimezone").val(timezoneOffset);
|
var timezone = jstz.determine();
|
||||||
|
$("#jstimezone").val( timezone.name() );
|
||||||
|
|
||||||
// Proceed without email field.
|
// Proceed without email field.
|
||||||
$("#jscompleteEmail").on("click", function() {
|
$("#jscompleteEmail").on("click", function() {
|
||||||
|
|
||||||
console.log("Click proceed anyway");
|
|
||||||
|
|
||||||
$("#jsnoCheckEmail").val("1");
|
$("#jsnoCheckEmail").val("1");
|
||||||
|
|
||||||
$("#jsformInstaller").submit();
|
$("#jsformInstaller").submit();
|
||||||
|
|
Loading…
Reference in New Issue