From 4eb11a17850522bd89f22e88621c8d84b50f5e11 Mon Sep 17 00:00:00 2001 From: Miraty Date: Mon, 12 Oct 2020 18:48:53 +0200 Subject: [PATCH] Add an option to force used locale in config.inc.php --- config.inc.php | 14 ++++++++++---- inc.php | 29 ++++++++++++++++------------- 2 files changed, 26 insertions(+), 17 deletions(-) diff --git a/config.inc.php b/config.inc.php index 9d73ace..e315db4 100755 --- a/config.inc.php +++ b/config.inc.php @@ -13,10 +13,16 @@ deleteOldQR(60 * 60 * 24 * 7); // FR : Nom du thème (doit être dans le dossier themes) $theme = "dark"; -// EN: Language used if those wanted by the user are not available +// EN: Language used if those requested by the user are not available // FR : Langue utilisée si celles demandées par l'utilisateurice ne sont pas disponibles -$locale = "fr"; // fr ou en +$locale = "en"; // en || fr -$fileNameLenght = 32; // Longueur du nom du fichier du code QR +// EN: Should the locales requested by the user be ignored? +// FR : Faut-il ignorer les langues demandées par l'utilisateurice ? +$forceLocale = false; -//$additionalText = "This LibreQR instance is hosted by foo."; +// EN: Lenght of the QR code filename +// FR : Longueur du nom du fichier du code QR +$fileNameLenght = 32; + +//$customText = "This LibreQR instance is hosted by foo."; diff --git a/inc.php b/inc.php index 04d911d..cfca77f 100644 --- a/inc.php +++ b/inc.php @@ -2,30 +2,33 @@ require "config.inc.php"; -// Defines locale used -$clientLocales = $_SERVER['HTTP_ACCEPT_LANGUAGE']; -$clientLocales = preg_replace("#[A-Z0-9]|q=|;|-|\.#", "", $clientLocales); -$clientLocales = explode(',', $clientLocales); -$availableLocales = array('fr', 'en', 'template'); -foreach ($clientLocales as $clientLocale) { - if (in_array($clientLocale, $availableLocales)) { - $locale = $clientLocale; - break; +// Defines the locale used +if ($forceLocale == false) { + $clientLocales = $_SERVER['HTTP_ACCEPT_LANGUAGE']; + $clientLocales = preg_replace("#[A-Z0-9]|q=|;|-|\.#", "", $clientLocales); + $clientLocales = explode(',', $clientLocales); + $availableLocales = array('fr', 'en', 'template'); + foreach ($clientLocales as $clientLocale) { + if (in_array($clientLocale, $availableLocales)) { + $locale = $clientLocale; + break; + } } } require "locales/" . $locale . ".php"; -// Defines root URL +// Defines the root URL if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') $protocol = "https"; else $protocol = "http"; -$instPath = $protocol . "://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; -$instPath = preg_replace('#\?.*$#', '', $instPath); -$instPath = preg_replace('#(manifest|opensearch|index).php$#i', '', $instPath); +$rootPath = $protocol . "://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; +$rootPath = preg_replace('#\?.*$#', '', $rootPath); +$rootPath = preg_replace('#(manifest|opensearch|index).php$#i', '', $rootPath); require "themes/" . $theme . "/theme.php"; // Load theme +// Used to generate the filename of the QR code function generateRandomString($length) { $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; $charactersLength = strlen($characters);