public function getUserLangs()
{
$userLangs = array();
// Highest priority: forced language
if ($this->forcedLang != NULL) {
$userLangs[] = $this->forcedLang;
}
// 2nd highest priority: GET parameter 'lang'
if (isset($_GET['lang']) && is_string($_GET['lang'])) {
$userLangs[] = $_GET['lang'];
}
// 3rd highest priority: SESSION parameter 'lang'
if (isset($_SESSION['lang']) && is_string($_SESSION['lang'])) {
$userLangs[] = $_SESSION['lang'];
}
// 4th highest priority: HTTP_ACCEPT_LANGUAGE
if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
foreach (explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']) as $part) {
$userLangs[] = strtolower(substr($part, 0, 2));
}
}
// Lowest priority: fallback
$userLangs[] = $this->fallbackLang;
// remove duplicate elements
$userLangs = array_unique($userLangs);
// remove illegal userLangs
$userLangs2 = array();
foreach ($userLangs as $key => $value) {
// only allow a-z, A-Z and 0-9 and _ and -
if (preg_match('/^[a-zA-Z0-9_-]*$/', $value) === 1) {
$userLangs2[$key] = $value;
}
}
return $userLangs2;
}