*/ class Context { protected $defaultLocale = 'en'; protected $localeoverride = false; /** * sets the default system locale setting to the context * * @param mixed $locale * a locale setting */ public function setDefaultLocale($locale) { $this->defaultLocale = $locale; } public function getDefaultLocale() { return $this->defaultLocale; } /** * allows an additional locale with high priority from cookies or request params * * @param mixed $locale * a locale setting */ public function setLocaleOverride($locale) { $this->localeoverride = $locale; } public function getLocaleOverride() { return $this->localeoverride; } /** * * @return MMUser the current user of the request context */ public function getCurrentUser() { return \MCMS\System::getInstance()->getUserSvc()->getUser(); } public function findBestLocale(array $haystack) { $default = $this->getDefaultLocale(); $browserlocales = Locale::getLocaleList($_SERVER['HTTP_ACCEPT_LANGUAGE']); $user = $this->getCurrentUser(); if(!empty($user->locale)) $locales = array_merge(array('98.0' => $user->locale), $browserlocales, array( '0.0' => $default)); else $locales = array_merge($browserlocales, array('0.0' => $default)); if($this->localeoverride) $locales = array_merge(array('99.0' => $this->localeoverride), $locales); $lang = $default; foreach($locales as $l) { if(in_array($l, $haystack)) { $lang = $l; break; } } return $lang; } }