* @version Subversion $Id: language.php 1433 2009-12-07 18:35:05Z benoitg $ * @link http://www.wifidog.org/ */ /** * Load required files */ require_once 'classes/WifidogLocale.php'; if (!empty($_REQUEST['wifidog_language'])) { $session = Session::getObject(); //echo "Setting to $_REQUEST[wifidog_language]<br/>"; $AVAIL_LOCALE_ARRAY = LocaleList::getAvailableLanguageArray(); /* Try to guess the lang */ if (!empty($AVAIL_LOCALE_ARRAY[$_REQUEST['wifidog_language']])) { $session->set(SESS_LANGUAGE_VAR, $_REQUEST['wifidog_language']); } else { throw new Exception(htmlspecialchars($_REQUEST['wifidog_language']) . " is not a valid locale"); } } $locale = WifidogLocale::getCurrentLocale(); WifidogLocale::setCurrentLocale($locale); $locale_id = $locale->getId(); if (isset($smarty)) { $smarty->assign("lang_id", $locale_id); } /* * Local variables: * tab-width: 4 * c-basic-offset: 4 * c-hanging-comment-ender-p: nil * End: */
/** * Returns the first available string in the user's language, faling that in the * same major language (first part of the locale), failing that the first available * string * @param bool verbose : Should the function be verbose when a string is empty ? * @return UTF-8 string */ public function getString($verbose = true) { // Init values $retval = null; $row = null; $_useCache = false; $_cachedData = null; // Create new cache objects $_cacheLanguage = new Cache('langstrings_' . $this->id . '_substring_' . substr(WifidogLocale::getCurrentLocale()->getId(), 0, 2) . '_string', $this->id); $_cache = new Cache('langstrings_' . $this->id . '_substring__string', $this->id); // Check if caching has been enabled. if ($_cacheLanguage->isCachingEnabled) { $_cachedData = $_cacheLanguage->getCachedData(); if ($_cachedData) { // Return cached data. $_useCache = true; $retval = $_cachedData; } else { // Language specific cached data has not been found. // Try to get language independent cached data. if ($_cachedData = $_cache->getCachedData()) { // Return cached data. $_useCache = true; $retval = $_cachedData; } } } if (!$_useCache) { //Get user's prefered language $sql = "SELECT value, locales_id, \n"; $sql .= WifidogLocale::getSqlCaseStringSelect(WifidogLocale::getCurrentLocale()->getId()); $sql .= " as score FROM content_langstring_entries WHERE content_langstring_entries.langstrings_id = '{$this->id}' AND value!='' ORDER BY score LIMIT 1"; $this->mBd->execSqlUniqueRes($sql, $row, false); if ($row == null) { if ($verbose == true) { $retval = sprintf(_("(Empty %s)"), get_class($this)); } else { $retval = ""; } } else { $retval = $row['value']; // Check if caching has been enabled. if ($_cache->isCachingEnabled) { // Save data into cache, because it wasn't saved into cache before. $_cache->saveCachedData($retval); } } } return $retval; }
/** * Get the content to be displayed in the tool pane * * @return string HTML markup * * @access private */ private function getToolContent() { $session = Session::getObject(); $AVAIL_LOCALE_ARRAY = LocaleList::getAvailableLanguageArray(); // Init values $html = ""; $_gwId = null; $_gwAddress = null; $_gwPort = null; $_mac = null; $_selected = ""; $_languageChooser = array(); // Init ALL smarty SWITCH values $this->smarty->assign('sectionSTART', false); $this->smarty->assign('sectionLOGIN', false); // Set section of Smarty template $this->smarty->assign('sectionSTART', true); // Get information about user $_currentUser = User::getCurrentUser(); $_currentUser ? $this->smarty->assign('userListUI', $_currentUser->getListUI()) : $this->smarty->assign('userListUI', ""); $this->smarty->assign('logoutParameters', ""); $this->smarty->assign('loginParameters', ""); $this->smarty->assign('formAction', ""); $this->smarty->assign('toolContent', ""); $this->smarty->assign('accountInformation', ""); $this->smarty->assign('techSupportInformation', ""); $this->smarty->assign('shrinkLeftArea', $this->_shrinkLeftArea); /* * Provide Smarty information about the user's login/logout status */ if ($_currentUser != null) { // User is logged in // Detect gateway information $_gwId = $session->get(SESS_GW_ID_VAR); $_gwAddress = $session->get(SESS_GW_ADDRESS_VAR); $_gwPort = $session->get(SESS_GW_PORT_VAR); $_mac = $session->get(SESS_USER_MAC_VAR); // If gateway information could be detected tell them to Smarty if ($_gwId && $_gwAddress && $_gwPort) { $this->smarty->assign('logoutParameters', "&gw_id=" . $_gwId . "&gw_address=" . $_gwAddress . "&gw_port=" . $_gwPort . ($_mac ? "&mac=" . $_mac : "")); } } else { } /* * Provide Smarty information for the language chooser */ // Assign the action URL for the form $this->smarty->assign('formAction', htmlspecialchars($_SERVER['REQUEST_URI'])); foreach ($AVAIL_LOCALE_ARRAY as $_langIds => $_langNames) { if (WifidogLocale::getCurrentLocale()->getId() == $_langIds) { $_selected = ' selected="selected"'; } else { $_selected = ""; } $langName = "{$_langNames[0]}"; $_languageChooser[] = '<option value="' . $_langIds . '"' . $_selected . '>' . $langName . '</option>'; } // Provide Smarty all available languages $this->smarty->assign('languageChooser', $_languageChooser); // Compile HTML code $html = $this->smarty->fetch("templates/classes/MainUI_ToolContent.tpl"); return $html; }