| // +---------------------------------------------------------------------------+ /** * Language switcher block. * * @package seagull * @subpackage block * @author Dmitri Lakachauskis */ class Default_Block_LangSwitcher2 { var $templatePath = 'default'; function init(&$output, $blockId, $aParams) { SGL::logMessage(null, PEAR_LOG_DEBUG); // only one language exists in minimal install if (SGL::isMinimalInstall()) { return false; } return $this->getBlockContent($output, $aParams); } function getBlockContent(&$output, $aParams) { SGL::logMessage(null, PEAR_LOG_DEBUG); if (empty($aParams)) { $aParams = array(); } $aDefaultParams = array( 'template' => 'blockLangSwitcher.html', 'extension' => 'png' ); // current params $aParams = array_merge($aDefaultParams, $aParams); // current theme $theme = isset($_SESSION['aPrefs']['theme']) ? $_SESSION['aPrefs']['theme'] : 'default'; $imageDir = isset($output->imagesDir) ? $output->imagesDir : SGL_BASE_URL . '/themes/' . $theme . '/image' ; $input = &SGL_Registry::singleton(); $conf = $input->getConfig(); $url = $input->getCurrentUrl(); $aLangs = SGL_Util::getLangsDescriptionMap(); $aLangsDef = $GLOBALS['_SGL']['LANGUAGE']; $aInstalledLangs = str_replace('_', '-', explode(',', $conf['translation']['installedLanguages'])); $aLangData = array(); foreach ($aLangs as $langKey => $langName) { if (!in_array($langKey, $aInstalledLangs)) { continue; } preg_match('/(.+) \(.+\)/', $langName, $matches); // main data $aLangData[$langKey]['name'] = $matches[1]; $aLangData[$langKey]['code'] = $aLangsDef[$langKey][2]; $aLangData[$langKey]['key'] = $langKey; if (SGL_Config::get('site.inputUrlHandlers') != 'Horde_Routes') { $url->aQueryData['lang'] = $langKey; $aQueryData = $url->getQueryData(true); $href = $this->_makeOldStyleUrl($aQueryData); } else { $switch = SGL_Config::get('translation.langInUrl') ? $aLangData[$langKey]['code'] : $langKey; $aQueryData = array('lang' => $switch); $href = $url->makeCurrentLink($aQueryData); } $imageFile = SGL_WEB_ROOT . '/themes/' . $theme . '/images/flags/' . $langKey . '.' . $aParams['extension']; // link $aLangData[$langKey]['url'] = $href; // is current? $aLangData[$langKey]['is_current'] = SGL::getCurrentLang() == $aLangData[$langKey]['code']; // image $aLangData[$langKey]['image'] = file_exists($imageFile) ? "$imageDir/flags/{$langKey}.{$aParams['extension']}" : false; } $blockOutput = & new SGL_Output(); $blockOutput->conf = $conf; $blockOutput->theme = $theme; $blockOutput->imagesDir = $imageDir; $blockOutput->masterTemplate = $aParams['template']; $blockOutput->aLangs = $aLangData; return $this->process($blockOutput); } function _makeOldStyleUrl($aQueryData = array()) { $action = ''; $params = ''; $cookie = SGL_Config::get('cookie.name'); if (isset($aQueryData['action'])) { $action = $aQueryData['action']; unset($aQueryData['action']); } foreach ($aQueryData as $key => $value) { if (empty($value) && !is_numeric($value) || false !== strpos($key, $cookie)) { continue; } $params[] = $key . '|' . $value; } if (!empty($params)) { $params = implode('||', $params); } return SGL_Output::makeUrl($action, '', '', array(), $params); } function process(&$output) { $output->moduleName = $this->templatePath; $view = & new SGL_HtmlSimpleView($output); return $view->render(); } } ?>