public function lang() { $config = services::getService('config'); $params = services::getService('pageParams'); global $lang_de; global $lang_es; global $lang_en; $this->msg = array("de" => $lang_de, "en" => $lang_en, "es" => $lang_es); // if there's a lang_cookie, the cookie-language is chosen if ($_GET['lang']) { $this->lang = $_GET['lang']; } else { if ($_COOKIE['language']) { $this->lang = $_COOKIE['language']; } else { if (is_array(parseHttpAcceptLanguage())) { $blang = parseHttpAcceptLanguage(); $this->lang = $blang[0]['code']; } else { $this->lang = $config->getSetting('language'); } } } if (!in_array($this->lang, $this->languages)) { $this->lang = $config->getSetting('language'); } }
public function page() { $page_params = services::getService('pageParams'); $config = services::getService('config'); $login = $page_params->getParam('login'); $password = $page_params->getParam('password'); $this->act_page = $page_params->getParam('page'); $this->act_get = $this->getActGet(); if ($login != "" && $password != "") { $user = new user($login, crypt($password, 'dl')); if ($user->find(true)) { $this->user = $user; } } // set interface-language // if lang is in get, a cookie is set, lang in get is set, is written in db // else if lang is in db, a cookie is set // else if lang is in cookie, lang in cookie is set, is written in db // else if lang is in browser, a cookie is set etc., is written in db // else if lang is in config.ini, cookie, set, written in db if ($_GET['lang']) { setcookie('language', $_GET['lang'], time() + 60 * 60 * 24 * 365); if (is_object($user)) { $this->user->language = $_GET['lang']; $this->user->update(); } } else { if ($this->user->language) { if ($_COOKIE['language'] != $this->user->language) { setcookie('language', $this->user->language, time() + 60 * 60 * 24 * 365); } } else { if ($_COOKIE['language']) { if (is_object($user)) { $this->user->language = $_COOKIE['language']; $this->user->update(); } } else { if (is_array(parseHttpAcceptLanguage())) { $blang = parseHttpAcceptLanguage(); setcookie('language', $blang[0]['code'], time() + 60 * 60 * 24 * 365); if (is_object($user)) { $this->user->language = $blang[0]['code']; $this->user->update(); } } else { setcookie('language', $config->getSetting('language'), time() + 60 * 60 * 24 * 365); if (is_object($user)) { $this->user->language = $config->getSetting('language'); $this->user->update(); } } } } } $this->addMsg($page_params->getParam('msg')); $this->assignAll(); }
/** * Generates an editable list of language strings * * @param string $dbstring either a serialized languag string array or a single string * @param string $name the prefix for the label, id, and name tags * @param bool $textbox set to true for a textbox rather than a text field * @param string $locale optional locale of the translation desired * @param string $edit optional class * @param int $wide column size. true or false for the standard or short sizes. Or pass a column size * @param string $ulclass set to the class for the UL element * @param int $rows set to the number of rows to show. */ function print_language_string_list($dbstring, $name, $textbox = false, $locale = NULL, $edit = '', $wide = TEXT_INPUT_SIZE, $ulclass = 'language_string_list', $rows = 6) { global $_zp_active_languages, $_zp_current_locale, $_lsInstance; $dbstring = zpFunctions::unTagURLs($dbstring); if (!empty($edit)) { $edit = ' class="' . $edit . '"'; } if (is_null($locale)) { $locale = getUserLocale(); } $strings = getSerializedArray($dbstring); if (count($strings) == 1) { $keys = array_keys($strings); $lang = array_shift($keys); if (!is_string($lang)) { $strings = array($locale => array_shift($strings)); } } $activelang = generateLanguageList(); $allLang = array_flip(generateLanguageList('all')); foreach ($strings as $lang => $v) { if (!array_key_exists($lang, $activelang)) { $activelang[$allLang[$lang]] = $lang; } } echo '<div id="ls_' . ++$_lsInstance . '">' . "\n"; if ($multi = getOption('multi_lingual') && !empty($activelang)) { if ($textbox) { if (strpos($wide, '%') === false) { $width = ' cols="' . $wide . '"'; } else { $width = ' style="width:' . ((int) $wide - 1) . '%;"'; } } else { if (strpos($wide, '%') === false) { $width = ' size="' . $wide . '"'; } else { $width = ' style="width:' . ((int) $wide - 2) . '%;"'; } } // put the language list in perferred order $preferred = array(); if ($_zp_current_locale) { $preferred[] = $_zp_current_locale; } foreach (parseHttpAcceptLanguage() as $lang) { $preferred[] = str_replace('-', '_', $lang['fullcode']); } $preferred = array_unique($preferred); $emptylang = array(); foreach ($preferred as $lang) { foreach ($activelang as $key => $active) { if ($active == $lang) { $emptylang[$active] = $key; unset($activelang[$key]); continue 2; } } if (strlen($lang) == 2) { // "wild card language" foreach ($activelang as $key => $active) { if (substr($active, 0, 2) == $lang) { $emptylang[$active] = $key; } } } } foreach ($activelang as $key => $active) { $emptylang[$active] = $key; } if ($textbox) { $class = 'box'; } else { $class = ''; } echo '<ul id="ul_' . $_lsInstance . '" class="' . $ulclass . $class . '"' . ">\n"; $empty = true; foreach ($emptylang as $key => $lang) { if (isset($strings[$key])) { $string = $strings[$key]; if (!empty($string)) { unset($emptylang[$key]); $empty = false; ?> <li> <label for="<?php echo $name . '_' . $key; ?> "><?php echo $lang; ?> </label> <?php if ($textbox) { echo "\n" . '<textarea name="' . $name . '_' . $key . '"' . $edit . $width . ' rows="' . $rows . '">' . html_encode($string) . '</textarea>'; } else { echo '<br /><input id="' . $name . '_' . $key . '" name="' . $name . '_' . $key . '"' . $edit . ' type="text" value="' . html_encode($string) . '"' . $width . ' />'; } ?> </li> <?php } } } foreach ($emptylang as $key => $lang) { ?> <li> <label for="<?php echo $name . '_' . $key; ?> "><?php echo $lang; ?> </label> <?php if ($textbox) { echo "\n" . '<textarea name="' . $name . '_' . $key . '"' . $edit . $width . ' rows="' . $rows . '"></textarea>'; } else { echo '<br /><input id="' . $name . '_' . $key . '" name="' . $name . '_' . $key . '"' . $edit . ' type="text" value=""' . $width . ' />'; } ?> </li> <?php } echo "</ul>\n"; } else { if ($textbox) { if (strpos($wide, '%') === false) { $width = ' cols="' . $wide . '"'; } else { $width = ' style="width:' . $wide . ';"'; } } else { if (strpos($wide, '%') === false) { $width = ' size="' . $wide . '"'; } else { $width = ' style="width:' . $wide . ';"'; } } if (empty($locale)) { $locale = 'en_US'; } if (isset($strings[$locale])) { $dbstring = $strings[$locale]; unset($strings[$locale]); } else { $dbstring = array_shift($strings); } if ($textbox) { echo '<textarea name="' . $name . '_' . $locale . '"' . $edit . $width . ' rows="' . $rows . '">' . html_encode($dbstring) . '</textarea>'; } else { echo '<input name="' . $name . '_' . $locale . '"' . $edit . ' type="text" value="' . html_encode($dbstring) . '"' . $width . ' />'; } foreach ($strings as $key => $dbstring) { if (!empty($dbstring)) { ?> <input type="hidden" name="<?php echo $name . '_' . $key; ?> " value="<?php echo html_encode($dbstring); ?> " /> <?php } } } echo "</div>\n"; if ($multi) { ?> <script type="text/javascript"> $(function () { $('#ls_<?php echo $_lsInstance; ?> ').resizable({ minHeight: 60, resize: function (event, ui) { $(this).css("width", ''); $('#ul_<?php echo $_lsInstance; ?> ').height($('#ls_<?php echo $_lsInstance; ?> ').height()); } }); });</script> <?php } }
/** * 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() { 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; }
// lang code complement $morecode = array_key_exists(3, $found) ? $found[3] : false; // full lang code $fullcode = $morecode ? $code . '_' . $morecode : $code; // coefficient (preference value, will be used in sorting the list) $coef = sprintf('%3.1f', array_key_exists(5, $found) ? $found[5] : '1'); // for sorting by coefficient $accepted[$coef . '-' . $code] = array('code' => $code, 'coef' => $coef, 'morecode' => $morecode, 'fullcode' => $fullcode); } } // sorting the list by coefficient desc krsort($accepted); return $accepted; } $locales = list_system_locales(); $httpaccept = parseHttpAcceptLanguage(); if (count($httpaccept) > 0) { $accept = $httpaccept; $accept = array_shift($accept); ?> <strong>Http Accept Languages:</strong> <br /> <table> <tr> <th width = 100 align="left">Key</th> <?php foreach ($accept as $key => $value) { ?> <th width = 100 align="left"><?php echo $key; ?>
/** * Generates an editable list of language strings * * @param string $dbstring either a serialized languag string array or a single string * @param string $name the prefix for the label, id, and name tags * @param bool $textbox set to true for a textbox rather than a text field * @param string $locale optional locale of the translation desired * @param string $edit optional class * @param int $wide column size. true or false for the standard or short sizes. Or pass a column size * @param string $ulclass set to the class for the UL element * @param int $rows set to the number of rows to show. */ function print_language_string_list($dbstring, $name, $textbox = false, $locale = NULL, $edit = '', $wide = TEXT_INPUT_SIZE, $ulclass = 'language_string_list', $rows = 6) { global $_zp_active_languages, $_zp_current_locale; $dbstring = zpFunctions::unTagURLs($dbstring); if (!empty($edit)) { $edit = ' class="' . $edit . '"'; } if (is_null($locale)) { $locale = getUserLocale(); } $strings = getSerializedArray($dbstring); if (count($strings) == 1) { $keys = array_keys($strings); $lang = array_shift($keys); if (!is_string($lang)) { $strings = array($locale => array_shift($strings)); } } $activelang = generateLanguageList(); if (getOption('multi_lingual') && !empty($activelang)) { if ($textbox) { if (strpos($wide, '%') === false) { $width = ' cols="' . $wide . '"'; } else { $width = ' style="width:' . ((int) $wide - 1) . '%;"'; } } else { if (strpos($wide, '%') === false) { $width = ' size="' . $wide . '"'; } else { $width = ' style="width:' . ((int) $wide - 2) . '%;"'; } } // put the language list in perferred order $preferred = array($_zp_current_locale); foreach (parseHttpAcceptLanguage() as $lang) { $preferred[] = str_replace('-', '_', $lang['fullcode']); } $preferred = array_unique($preferred); $emptylang = array(); foreach ($preferred as $lang) { foreach ($activelang as $key => $active) { if ($active == $lang) { $emptylang[$active] = $key; unset($activelang[$key]); continue 2; } } if (strlen($lang) == 2) { // "wild card language" foreach ($activelang as $key => $active) { if (substr($active, 0, 2) == $lang) { $emptylang[$active] = $key; } } } } foreach ($activelang as $key => $active) { $emptylang[$active] = $key; } if ($textbox) { $class = 'box'; } else { $class = ''; } echo '<ul class="' . $ulclass . $class . '"' . ">\n"; $empty = true; foreach ($emptylang as $key => $lang) { if (isset($strings[$key])) { $string = $strings[$key]; if (!empty($string)) { unset($emptylang[$key]); $empty = false; ?> <li> <label for="<?php echo $name . '_' . $key; ?> "><?php echo $lang; ?> </label> <?php if ($textbox) { echo "\n" . '<textarea name="' . $name . '_' . $key . '"' . $edit . $width . ' rows="' . $rows . '">' . html_encode($string) . '</textarea>'; } else { echo '<br /><input id="' . $name . '_' . $key . '" name="' . $name . '_' . $key . '"' . $edit . ' type="text" value="' . html_encode($string) . '"' . $width . ' />'; } ?> </li> <?php } } } foreach ($emptylang as $key => $lang) { ?> <li> <label for="<?php echo $name . '_' . $key; ?> "><?php echo $lang; ?> </label> <?php if ($textbox) { echo "\n" . '<textarea name="' . $name . '_' . $key . '"' . $edit . $width . ' rows="' . $rows . '"></textarea>'; } else { echo '<br /><input id="' . $name . '_' . $key . '" name="' . $name . '_' . $key . '"' . $edit . ' type="text" value=""' . $width . ' />'; } ?> </li> <?php } echo "</ul>\n"; } else { if ($textbox) { if (strpos($wide, '%') === false) { $width = ' cols="' . $wide . '"'; } else { $width = ' style="width:' . $wide . ';"'; } } else { if (strpos($wide, '%') === false) { $width = ' size="' . $wide . '"'; } else { $width = ' style="width:' . $wide . ';"'; } } if (empty($locale)) { $locale = 'en_US'; } if (isset($strings[$locale])) { $dbstring = $strings[$locale]; } else { $dbstring = array_shift($strings); } if ($textbox) { echo '<textarea name="' . $name . '_' . $locale . '"' . $edit . $width . ' rows="' . $rows . '">' . html_encode($dbstring) . '</textarea>'; } else { echo '<input name="' . $name . '_' . $locale . '"' . $edit . ' type="text" value="' . html_encode($dbstring) . '"' . $width . ' />'; } } }
/** * 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; }