Bludit Installer: timezone, language and locale autodetection
This commit is contained in:
parent
34fff17d03
commit
95e9835867
2
bl-kernel/admin/themes/default/js/jstz.min.js
vendored
Normal file
2
bl-kernel/admin/themes/default/js/jstz.min.js
vendored
Normal file
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_KERNEL.'dblanguage.class.php');
|
||||
|
||||
// --- LANGUAGE ---
|
||||
|
||||
// Try to detect language from HTTP
|
||||
$explode = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
|
||||
$localeFromHTTP = empty($explode[0])?'en_US':str_replace('-', '_', $explode[0]);
|
||||
// --- LANGUAGE and LOCALE ---
|
||||
|
||||
// Language from the URI
|
||||
if(isset($_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';
|
||||
}
|
||||
|
||||
// Get language file
|
||||
$Language = new dbLanguage($localeFromHTTP);
|
||||
|
||||
// --- LOCALE ---
|
||||
|
||||
// Set locale
|
||||
setlocale(LC_ALL, $localeFromHTTP);
|
||||
|
||||
// --- TIMEZONE ---
|
||||
@ -132,7 +140,7 @@ setlocale(LC_ALL, $localeFromHTTP);
|
||||
// Check if timezone is defined in php.ini
|
||||
$iniDate = ini_get('date.timezone');
|
||||
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');
|
||||
}
|
||||
|
||||
@ -229,15 +237,15 @@ function checkSystem()
|
||||
}
|
||||
|
||||
// Finish with the installation.
|
||||
function install($adminPassword, $email, $timezoneOffset)
|
||||
function install($adminPassword, $email, $timezone)
|
||||
{
|
||||
global $Language;
|
||||
|
||||
$stdOut = array();
|
||||
|
||||
$timezone = timezone_name_from_abbr('', $timezoneOffset, 0);
|
||||
if($timezone === false) { $timezone = timezone_name_from_abbr('', $timezoneOffset, 0); } // Workaround bug #44780
|
||||
date_default_timezone_set($timezone);
|
||||
if( date_default_timezone_set($timezone) ) {
|
||||
date_default_timezone_set('UTC');
|
||||
}
|
||||
|
||||
$currentDate = Date::current(DB_DATE_FORMAT);
|
||||
|
||||
@ -580,6 +588,7 @@ if( $_SERVER['REQUEST_METHOD'] == 'POST' )
|
||||
<!-- Javascript -->
|
||||
<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/jstz.min.js?version=<?php echo time() ?>"></script>
|
||||
|
||||
</head>
|
||||
<body class="uk-height-1-1">
|
||||
@ -673,15 +682,14 @@ if( $_SERVER['REQUEST_METHOD'] == 'POST' )
|
||||
<script>
|
||||
$(document).ready(function()
|
||||
{
|
||||
// Set timezone
|
||||
var timezoneOffset = -(new Date().getTimezoneOffset() * 60);
|
||||
$("#jstimezone").val(timezoneOffset);
|
||||
|
||||
// Timezone
|
||||
var timezone = jstz.determine();
|
||||
$("#jstimezone").val( timezone.name() );
|
||||
|
||||
// Proceed without email field.
|
||||
$("#jscompleteEmail").on("click", function() {
|
||||
|
||||
console.log("Click proceed anyway");
|
||||
|
||||
$("#jsnoCheckEmail").val("1");
|
||||
|
||||
$("#jsformInstaller").submit();
|
||||
|
Loading…
Reference in New Issue
Block a user