Use MDAllowedValueSets for getting values of allowed values

phpcs-errors:226 phpunit-status:successful
This commit is contained in:
Joshua Ramon Enslin 2020-08-10 20:13:16 +02:00 committed by Stefan Rohde-Enslin
parent f75ecb08a4
commit df3e1580cf
7 changed files with 10 additions and 95 deletions

@ -1 +1 @@
Subproject commit a09eba6b843804c33eeff7205b8a376d4e46724b
Subproject commit 08c9582210be11ba211d012e8aea2838fd1e9909

View File

@ -24,7 +24,7 @@ if (isset($_GET['navlang'])) {
if (!in_array($_SESSION['lang'], $allowed_langs)) $_SESSION['lang'] = 'de';
}
else if (!isset($_SESSION['lang'])) {
$_SESSION['lang'] = lang_getfrombrowser($allowed_langs, 'en', "", false);
$_SESSION['lang'] = MD_STD::lang_getfrombrowser($allowed_langs, 'en', "", false);
}
$lang = $_SESSION['lang'];

View File

@ -77,7 +77,7 @@ function mdErrorHandler(int $errno, string $string, string $file, int $line):voi
$errorMsg = "*$errno (<a href='https://www.google.de/search?q=php+" . str_replace(" ", "+", $string) . "'>$string</a>) at $file: line_ $line _";
$errorMsg .= $userMsg;
$errorMsg .= " |-- Error generating page: <a href='$errorPageFull'>$errorPage</a>";
$errorMsg .= " |-- Used RAM / Peak RAM / Allowed: " . human_filesize((string)memory_get_usage()) . " / " . human_filesize((string)memory_get_peak_usage()) . " / " . ini_get("memory_limit");
$errorMsg .= " |-- Used RAM / Peak RAM / Allowed: " . MD_STD::human_filesize((string)memory_get_usage()) . " / " . MD_STD::human_filesize((string)memory_get_peak_usage()) . " / " . ini_get("memory_limit");
$errorMsg = str_replace(PHP_EOL, " ", $errorMsg);
@ -180,91 +180,6 @@ function mdExceptionHandler(Throwable $exception):void {
}
/**
* Function lang_getfrombrowser gets the browser language based on HTTP headers.
*
* @param array $allowed_languages Array containing all the languages for which
* there are translations.
* @param string $default_language Default language of the instance of MD.
* @param string $lang_variable Currently set language variable. Optional.
* @param boolean $strict_mode Whether to demand "de-de" (true) or "de" (false) Optional.
*
* @return string
*/
function lang_getfrombrowser(array $allowed_languages, string $default_language, string $lang_variable = "", bool $strict_mode = true):string {
// $_SERVER['HTTP_ACCEPT_LANGUAGE'] verwenden, wenn keine Sprachvariable mitgegeben wurde
if ($lang_variable === "") {
if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) $lang_variable = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
}
// wurde irgendwelche Information mitgeschickt?
if (empty($lang_variable)) {
// Nein? => Standardsprache zurückgeben
return $default_language;
}
// Den Header auftrennen
$accepted_languages = preg_split('/,\s*/', $lang_variable);
// Die Standardwerte einstellen
$current_lang = $default_language;
$current_q = 0;
// Nun alle mitgegebenen Sprachen abarbeiten
foreach ($accepted_languages as $accepted_language) {
// Alle Infos über diese Sprache rausholen
// phpcs:disable Generic.Strings.UnnecessaryStringConcat
$res = preg_match('/^([a-z]{1,8}(?:-[a-z]{1,8})*)(?:;\s*q=(0(?:\.[0-9]{1,3})?|1(?:\.0{1,3})?))?$/i', $accepted_language, $matches);
// phpcs:enable
// war die Syntax gültig?
if (!$res) {
// Nein? Dann ignorieren
continue;
}
// Sprachcode holen und dann sofort in die Einzelteile trennen
$lang_code = explode('-', $matches[1]);
// Wurde eine Qualität mitgegeben?
if (isset($matches[2])) {
// die Qualität benutzen
$lang_quality = (float)$matches[2];
} else {
// Kompabilitätsmodus: Qualität 1 annehmen
$lang_quality = 1.0;
}
// Bis der Sprachcode leer ist...
while (!empty($lang_code)) {
// mal sehen, ob der Sprachcode angeboten wird
if (in_array(strtolower(join('-', $lang_code)), $allowed_languages)) {
// Qualität anschauen
if ($lang_quality > $current_q) {
// diese Sprache verwenden
$current_lang = strtolower(join('-', $lang_code));
$current_q = $lang_quality;
// Hier die innere while-Schleife verlassen
break;
}
}
// Wenn wir im strengen Modus sind, die Sprache nicht versuchen zu minimalisieren
if ($strict_mode) {
// innere While-Schleife aufbrechen
break;
}
// den rechtesten Teil des Sprachcodes abschneiden
array_pop($lang_code);
}
}
// die gefundene Sprache zurückgeben
return $current_lang;
}
/**
* Function for generating the HTML head.
*

View File

@ -26,7 +26,7 @@ if (isset($_GET['navlang'])) {
if (!in_array($_SESSION['lang'], $allowed_langs)) $_SESSION['lang'] = 'de';
}
else if (!isset($_SESSION['lang'])) {
$_SESSION['lang'] = lang_getfrombrowser($allowed_langs, 'en', "", false);
$_SESSION['lang'] = MD_STD::lang_getfrombrowser($allowed_langs, 'en', "", false);
}
$lang = $_SESSION['lang'];

View File

@ -18,7 +18,7 @@ if (isset($_GET['navlang'])) {
if (!in_array($_SESSION['lang'], $allowed_langs)) $_SESSION['lang'] = 'de';
}
else if (!isset($_SESSION['lang'])) {
$_SESSION['lang'] = lang_getfrombrowser($allowed_langs, 'en', "", false);
$_SESSION['lang'] = MD_STD::lang_getfrombrowser($allowed_langs, 'en', "", false);
}
$lang = $_SESSION['lang'];

View File

@ -19,7 +19,7 @@ if (isset($_GET['navlang'])) {
if (!in_array($_SESSION['lang'], $allowed_langs)) $_SESSION['lang'] = 'de';
}
else if (!isset($_SESSION['lang'])) {
$_SESSION['lang'] = lang_getfrombrowser($allowed_langs, 'en', "", false);
$_SESSION['lang'] = MD_STD::lang_getfrombrowser($allowed_langs, 'en', "", false);
}
$lang = $_SESSION['lang'];

View File

@ -104,7 +104,7 @@ $availableFields = [
],
"object_other_title_kind_of" => [
"required" => false,
"allowedValues" => array_values($titelart),
"allowedValues" => array_values(MDTitleTypesSet::TITLE_TYPES),
"dependsOn" => ['object_other_title'],
"remark" => 'This field has to be used togehter with <i>object_other_title</i>',
"name_human_readable" => $searchvar[0][0] . ', in: ',
@ -423,7 +423,7 @@ $availableFields = [
],
"inclusion_kind_of" => [
"required" => false,
"allowedValues" => array_values($zugangsart),
"allowedValues" => array_values(MDEntryTypesSet::ENTRY_TYPES),
"remark" => '',
"name_human_readable" => "{$searchvar[19][0]}, {$object_add['as']}",
"explica" => "",
@ -1124,7 +1124,7 @@ for ($i = 1; $i <= 5 * $fieldNoMultiplicator; $i++) {
],
"image_rights{$i}" => [
"required" => false,
"allowedValues" => array_keys($availableLicenses),
"allowedValues" => array_keys(MDLicensesSet::AVAILABLE_LICENSES),
"dependsOn" => [
"image_name{$i}", "image_owner{$i}", "image_visible{$i}", "image_main{$i}"
],
@ -1242,7 +1242,7 @@ for ($i = 1; $i <= 5 * $fieldNoMultiplicator; $i++) {
],
"resource_rights{$i}" => [
"required" => false,
"allowedValues" => array_keys($availableLicenses),
"allowedValues" => array_keys(MDLicensesSet::AVAILABLE_LICENSES),
"dependsOn" => [
"resource_media_type{$i}", "resource_fileformat{$i}", "resource_location{$i}", "resource_name{$i}", "resource_owner{$i}", "resource_visible{$i}",
],