// script url define('TTPDS_DIR', $_SERVER['DOCUMENT_ROOT'] . $parentpath); // script directory include TTPDS_DIR . '/config.php'; include TTPDS_DIR . '/inc/lang.php'; include TTPDS_DIR . '/inc/files.php'; include TTPDS_DIR . '/inc/browserargs.php'; // Parsing arguments manually as $_GET is not working due to htaccess redirect $uri_parts = explode('?', $_SERVER['REQUEST_URI'], 2); $page_redirected_from = 'http://' . TTPDS_URL . substr($uri_parts[0], strlen($parentpath)); parse_str(isset($uri_parts[1]) ? $uri_parts[1] : "", $output_get); $acc = filter_url(getargfrom('acc', $output_get)); $lang = filter_url(getargfrom('lang', $output_get)); asort($TTPDS_langs); if ($lang == "" || !in_array($lang, $TTPDS_langs)) { $lang = prefered_language($TTPDS_langs); } switch ($lang) { case 'de': include TTPDS_DIR . '/lang/de.php'; break; case 'en': include TTPDS_DIR . '/lang/en.php'; break; default: // 'en' include TTPDS_DIR . '/lang/en.php'; $lang = 'en'; } # Get error code switch (getenv("REDIRECT_STATUS")) {
$language = $langprefix; } $qvalue = 1.0; if (!empty($arr[5])) { $qvalue = floatval($arr[5]); } // find q-maximal language if (in_array($language, $languages) && $qvalue > $bestqval) { $bestlang = $language; $bestqval = $qvalue; } else { if (in_array($languageprefix, $languages) && $qvalue * 0.9 > $bestqval) { $bestlang = $languageprefix; $bestqval = $qvalue * 0.9; } } } return $bestlang; } $languages = array_merge(array('en-us'), array_map(function ($f) { return str_replace('_', '-', strtolower(basename($f))); }, glob('locale/*', GLOB_ONLYDIR))); $prefered_language = prefered_language($languages, $_SERVER['HTTP_ACCEPT_LANGUAGE']); $prefered_language = explode('-', $prefered_language); $prefered_language = $prefered_language[0] . '_' . strtoupper($prefered_language[1]); if ($prefered_language != 'en_US') { setlocale(LC_ALL, $prefered_language . '.UTF-8'); bind_textdomain_codeset('messages', 'UTF-8'); bindtextdomain('messages', 'locale/'); textdomain('messages'); }
// default language (in case of no hits) is the first in the array $bestlang = $available_languages[0]; $bestqval = 0; foreach ($hits as $arr) { // read data from the array of this hit $langprefix = strtolower($arr[1]); if (!empty($arr[3])) { $langrange = strtolower($arr[3]); $language = $langprefix . "-" . $langrange; } else { $language = $langprefix; } $qvalue = 1.0; if (!empty($arr[5])) { $qvalue = floatval($arr[5]); } // find q-maximal language if (in_array($language, $available_languages) && $qvalue > $bestqval) { $bestlang = $language; $bestqval = $qvalue; } else { if (in_array($langprefix, $available_languages) && $qvalue * 0.9 > $bestqval) { $bestlang = $langprefix; $bestqval = $qvalue * 0.9; } } } return $bestlang; } header("Location: index" . $Destination[prefered_language(array_keys($Destination))] . ".html"); exit;