Changed language detection code, added some small features
This commit is contained in:
@@ -7,52 +7,6 @@ Copyright (C) 2011-2023 Thomas Hooge
|
||||
SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*****************************************************************************/
|
||||
|
||||
function strip_mac($mac, $caps=true) {
|
||||
// strip mac address to 12 char string
|
||||
// strip chars we don't need
|
||||
$mac = preg_replace('/[^a-fA-F0-9]/', '', $mac);
|
||||
if ($caps) {
|
||||
$mac = strtoupper($mac);
|
||||
} else {
|
||||
$mac = strtolower($mac);
|
||||
}
|
||||
return $mac;
|
||||
}
|
||||
|
||||
function write_mac($mac, $user_mac='xx:xx:xx:xx:xx:xx') {
|
||||
// rebuild mac address using user supplied format
|
||||
|
||||
if (strlen($mac) != 12) {
|
||||
// if the MAC is empty, or for whatever reason incorrect, just return
|
||||
return $mac;
|
||||
}
|
||||
|
||||
// check format of user mac: count upper or lower char
|
||||
$chars = count_chars($user_mac, 1);
|
||||
if (array_key_exists(88, $chars) and $chars[88] == 12) {
|
||||
$pattern = '/X/';
|
||||
$mac = strtoupper($mac);
|
||||
} elseif (array_key_exists(120, $chars) and $chars[120] == 12) {
|
||||
$pattern = '/x/';
|
||||
$mac = strtolower($mac);
|
||||
} else {
|
||||
// invalid format
|
||||
return $mac;
|
||||
}
|
||||
|
||||
for($i=0; $i<12; $i++) {
|
||||
$user_mac = preg_replace($pattern, $mac[$i], $user_mac, 1);
|
||||
}
|
||||
|
||||
return $user_mac;
|
||||
}
|
||||
|
||||
function header_location($location) {
|
||||
// redirect page
|
||||
header('location:' . $location);
|
||||
exit;
|
||||
}
|
||||
|
||||
// sanitize input
|
||||
function sanitize($input) {
|
||||
global $dblink;
|
||||
@@ -76,49 +30,13 @@ function sanitize($input) {
|
||||
return $input;
|
||||
}
|
||||
|
||||
function lang_getfrombrowser ($allowed_languages, $default_language, $lang_variable = null, $strict_mode = true) {
|
||||
if ($lang_variable === null) {
|
||||
$lang_variable = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
|
||||
}
|
||||
if (empty($lang_variable)) {
|
||||
return $default_language;
|
||||
}
|
||||
$accepted_languages = preg_split('/,\s*/', $lang_variable);
|
||||
$current_lang = $default_language;
|
||||
$current_q = 0;
|
||||
foreach ($accepted_languages as $accepted_language) {
|
||||
$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);
|
||||
if (!$res) {
|
||||
continue;
|
||||
}
|
||||
$lang_code = explode ('-', $matches[1]);
|
||||
if (isset($matches[2])) {
|
||||
$lang_quality = (float)$matches[2];
|
||||
} else {
|
||||
$lang_quality = 1.0;
|
||||
}
|
||||
while (count ($lang_code)) {
|
||||
if (in_array (strtolower (join ('-', $lang_code)), $allowed_languages)) {
|
||||
if ($lang_quality > $current_q) {
|
||||
$current_lang = strtolower (join ('-', $lang_code));
|
||||
$current_q = $lang_quality;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ($strict_mode) {
|
||||
break;
|
||||
}
|
||||
array_pop ($lang_code);
|
||||
}
|
||||
}
|
||||
return $current_lang;
|
||||
}
|
||||
|
||||
function print_tree_rec($tree, $level) {
|
||||
$output = '<ul class="treelvl' . $level. '">' . "\n";
|
||||
foreach ($tree as $node) {
|
||||
$output .= '<li><a href="' . $node['href'] . '">' . $node['value'] . '</a>';
|
||||
if ($node['info']) {
|
||||
$output .= ' - ' . $node['info'];
|
||||
}
|
||||
if ($node['children']) {
|
||||
$output .= "\n" . print_tree_rec($node['children'], $level+1);
|
||||
}
|
||||
@@ -141,9 +59,3 @@ function print_tree($params, Smarty_Internal_Template $template) {
|
||||
}
|
||||
}
|
||||
|
||||
function msgout(array $parameters, Smarty_Internal_Template $smarty) {
|
||||
// This is just a quick hack around missing {php} in Smarty3
|
||||
$GLOBALS['g_error']->PrintOut();
|
||||
$GLOBALS['g_warning']->PrintOut();
|
||||
$GLOBALS['g_message']->PrintOut();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user