From 779a78a0f3f00630d7d048d8bd2db87860b2c8c4 Mon Sep 17 00:00:00 2001 From: Abhishek Pai Date: Mon, 23 Sep 2024 17:41:01 +0200 Subject: [PATCH] #943: Removed duplicated detect language code. --- composer.json | 2 +- htdocs/index.php | 3 +-- lib/detectbrowserlanguage.php | 37 ----------------------------------- 3 files changed, 2 insertions(+), 40 deletions(-) delete mode 100644 lib/detectbrowserlanguage.php diff --git a/composer.json b/composer.json index c3afe9e81..ae5998860 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "require": { - "ltb-project/ltb-common": "v0.2.1", + "ltb-project/ltb-common": "v0.3.0", "bjeavons/zxcvbn-php": "^1.0", "twbs/bootstrap": "v5.3.3", "defuse/php-encryption": "2.4.0", diff --git a/htdocs/index.php b/htdocs/index.php index 4c27538a1..6fa76632a 100644 --- a/htdocs/index.php +++ b/htdocs/index.php @@ -26,12 +26,11 @@ #============================================================================== # Language #============================================================================== -require_once("../lib/detectbrowserlanguage.php"); # Available languages $files = glob("../lang/*.php"); $languages = str_replace(".inc.php", "", $files); $languages = str_replace("../lang/", "", $languages); -$lang = detectLanguage($lang, $allowed_lang ? array_intersect($languages,$allowed_lang) : $languages); +$lang = \Ltb\Language::detect_language($lang, $allowed_lang ? array_intersect($languages,$allowed_lang) : $languages); require_once("../lang/$lang.inc.php"); # Remove default questions diff --git a/lib/detectbrowserlanguage.php b/lib/detectbrowserlanguage.php deleted file mode 100644 index 6d4111aa7..000000000 --- a/lib/detectbrowserlanguage.php +++ /dev/null @@ -1,37 +0,0 @@ - - * @license http://www.php.net/license/3_01.txt PHP license - */ - -/** - * split request header Accept-Language to determine the UserAgent's - * prefered language - * - * @param string $defaultLanguage preselected default language - * @return string returns the default language or a match from $availableLanguages - */ -function detectLanguage($defaultLanguage, $availableLanguages) -{ - $acceptedLanguages = filter_input(INPUT_SERVER, 'HTTP_ACCEPT_LANGUAGE', FILTER_SANITIZE_STRING); - $languageList = explode(',', $acceptedLanguages); - $choosenLanguage= $defaultLanguage; - foreach($languageList as $currentLanguage) { - $currentLanguage = explode(';', $currentLanguage); - if (preg_match('/(..)-?.*/', $currentLanguage[0], $reg)) { - foreach($reg as $checkLang) { - if ($match = preg_grep('/'.$checkLang.'/i', $availableLanguages)) { - $choosenLanguage= $match[key($match)]; - break 2; - } - } - } - } - return $choosenLanguage; -} - - /** - * vim: sts=4 ts=4 sw=4 cindent fdm=marker expandtab nu - */