/** * Returns a saved (or posted) locale. Posted locales are stored as a cookie. * * Sets the 'locale' option to the result (non-persistent) */ function getUserLocale() { global $_zp_current_admin_obj; if (DEBUG_LOCALE) { debugLogBackTrace("getUserLocale()"); } if (isset($_REQUEST['locale'])) { if (isset($_POST['locale'])) { $locale = validateLocale(sanitize($_POST['locale'], 0), 'POST'); } else { $locale = validateLocale(sanitize($_GET['locale'], 0), 'URI string'); } if ($locale) { zp_setCookie('dynamic_locale', $locale); } if (DEBUG_LOCALE) { debugLog("dynamic_locale from URL: " . sanitize($_REQUEST['locale'], 0) . "=>{$locale}"); } } else { $locale = false; } if (!$locale && is_object($_zp_current_admin_obj)) { $locale = $_zp_current_admin_obj->getLanguage(); if (DEBUG_LOCALE) { debugLog("locale from user: "******"locale from option: " . $localeOption . '; dynamic locale=' . $locale); } if (empty($localeOption) && empty($locale)) { // if one is not set, see if there is a match from 'HTTP_ACCEPT_LANGUAGE' $languageSupport = generateLanguageList(); $userLang = parseHttpAcceptLanguage(); foreach ($userLang as $lang) { $l = strtoupper($lang['fullcode']); $locale = validateLocale($l, 'HTTP Accept Language'); if ($locale) { break; } } } else { if (empty($locale)) { $locale = $localeOption; } } } if (empty($locale)) { // return "default" language, English if allowed, otherwise whatever is the "first" allowed language $languageSupport = generateLanguageList(); if (in_array('en_US', $languageSupport)) { $locale = 'en_US'; } else { $locale = array_shift($languageSupport); } } else { setOption('locale', $locale, false); } if (DEBUG_LOCALE) { debugLog("getUserLocale Returning locale: " . $locale); } return $locale; }
/** * Sets the locale, etc. to the zenphoto domain details. * Returns the result of setupCurrentLocale() * */ function setMainDomain() { global $_zp_current_admin_obj, $_zp_current_locale; if (DEBUG_LOCALE) { debugLogBackTrace("setMainDomain()"); } if (isset($_REQUEST['locale'])) { $_zp_current_locale = validateLocale(sanitize($_REQUEST['locale']), isset($_POST['locale']) ? 'POST' : 'URI string'); if ($_zp_current_locale) { zp_setCookie('dynamic_locale', $_zp_current_locale); } else { zp_clearCookie('dynamic_locale'); } if (DEBUG_LOCALE) { debugLog("dynamic_locale from URL: " . sanitize($_REQUEST['locale']) . "=>{$_zp_current_locale}"); } } else { $matches = explode('.', @$_SERVER['HTTP_HOST']); $_zp_current_locale = validateLocale($matches[0], 'HTTP_HOST'); if ($_zp_current_locale && zp_getCookie('dynamic_locale')) { zp_clearCookie('dynamic_locale'); } if (DEBUG_LOCALE) { debugLog("dynamic_locale from HTTP_HOST: " . sanitize($matches[0]) . "=>{$_zp_current_locale}"); } } if (!$_zp_current_locale && is_object($_zp_current_admin_obj)) { $_zp_current_locale = $_zp_current_admin_obj->getLanguage(); if (DEBUG_LOCALE) { debugLog("locale from user: "******"locale from option: " . $localeOption . '; dynamic locale=' . $_zp_current_locale); } if (empty($localeOption) && empty($_zp_current_locale)) { // if one is not set, see if there is a match from 'HTTP_ACCEPT_LANGUAGE' $languageSupport = generateLanguageList(); $userLang = parseHttpAcceptLanguage(); foreach ($userLang as $lang) { $l = strtoupper($lang['fullcode']); $_zp_current_locale = validateLocale($l, 'HTTP Accept Language'); if ($_zp_current_locale) { break; } } } else { if (empty($_zp_current_locale)) { $_zp_current_locale = $localeOption; } } } if (empty($_zp_current_locale)) { // return "default" language, English if allowed, otherwise whatever is the "first" allowed language $languageSupport = generateLanguageList(); if (defined('BASE_LOCALE')) { $loc = BASE_LOCALE; } else { $loc = 'en_US'; } if (empty($languageSupport) || in_array($loc, $languageSupport)) { $_zp_current_locale = $loc; } else { $_zp_current_locale = array_shift($languageSupport); } if (DEBUG_LOCALE) { debugLog("locale from language list: " . $_zp_current_locale); } } else { setOption('locale', $_zp_current_locale, false); } if (DEBUG_LOCALE) { debugLog("getUserLocale Returning locale: " . $_zp_current_locale); } return setupCurrentLocale($_zp_current_locale); }
/** * Returns a saved (or posted) locale. Posted locales are stored as a cookie. * * Sets the 'locale' option to the result (non-persistent) */ function getUserLocale() { if (DEBUG_LOCALE) { debugLogBackTrace("getUserLocale()"); } $cookiepath = WEBPATH; if (WEBPATH == '') { $cookiepath = '/'; } if (isset($_POST['dynamic-locale'])) { $locale = sanitize($_POST['dynamic-locale'], 0); zp_setCookie('dynamic_locale', $locale, time() + COOKIE_PESISTENCE, $cookiepath); if (DEBUG_LOCALE) { debugLog("dynamic_locale post: {$locale}"); } } else { $localeOption = getOption('locale'); $locale = zp_getCookie('dynamic_locale'); if (DEBUG_LOCALE) { debugLog("locale from option: " . $localeOption . '; dynamic locale=' . $locale); } if (empty($localeOption) && $locale === false) { // if one is not set, see if there is a match from 'HTTP_ACCEPT_LANGUAGE' $languageSupport = generateLanguageList(); $userLang = parseHttpAcceptLanguage(); foreach ($userLang as $lang) { $l = strtoupper($lang['fullcode']); foreach ($languageSupport as $key => $value) { if (strtoupper($value) == $l) { // we got a match $locale = $value; if (DEBUG_LOCALE) { debugLog("locale set from HTTP Accept Language: " . $locale); } break; } else { if (preg_match('/^' . $l . '/', strtoupper($value))) { // we got a partial match $locale = $value; if (DEBUG_LOCALE) { debugLog("locale set from HTTP Accept Language (partial match): " . $locale); } break; } } } if ($locale) { break; } } } } if ($locale !== false) { setOption('locale', $locale, false); } if (DEBUG_LOCALE) { debugLog("Returning locale: " . $locale); } return $locale; }