/** Standard constructor * * @param languageID ID of the associated language * @param elementTable Reference to the ContentElementTable object */ function ContentObject($languageID, &$contentElement, $id = -1) { $db = JFactory::getDBO(); if ($id > 0) { $this->id = $id; } $this->language_id = $languageID; // active languages are cached in FalangManager - use these if possible $jfManager = FalangManager::getInstance(); if (isset($jfManager) && $jfManager->activeLanguagesCacheByID && array_key_exists($languageID, $jfManager->activeLanguagesCacheByID)) { $lang = $jfManager->activeLanguagesCacheByID[$languageID]; } else { $lang = new TableJFLanguage($db); $lang->load($languageID); } $this->language = $lang->title; $this->_contentElement = $contentElement; }
function _determineLanguage($getLang = null, $redir = false, $useMainLang = false) { // set the language for JoomFish if (SEFTools::JoomFishInstalled()) { $sefConfig =& SEFConfig::getConfig(); $registry =& JFactory::getConfig(); // Check if the Jfrouter is enabled $jfrouterEnabled = JPluginHelper::isEnabled('system', 'jfrouter'); // save the default language of the site if needed if (!$jfrouterEnabled) { $locale = $registry->getValue('config.language'); $GLOBALS['mosConfig_defaultLang'] = $locale; $registry->setValue("config.defaultlang", $locale); } // get instance of JoomFishManager to obtain active language list and config values $jfm =& JoomFishManager::getInstance(); // Get language from request if (!empty($getLang)) { $lang = $getLang; } // Try to get language code from JF cookie if ($sefConfig->jfLangCookie) { $jfCookie = JRequest::getVar('jfcookie', null, 'COOKIE'); if (isset($jfCookie['lang'])) { $cookieCode = $jfCookie['lang']; } } // Try to find language from browser settings if ($sefConfig->jfBrowserLang && isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) && !empty($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { $active_iso = array(); $active_isocountry = array(); $active_code = array(); $activeLanguages = $jfm->getActiveLanguages(); if (count($activeLanguages) > 0) { foreach ($activeLanguages as $alang) { $active_iso[] = $alang->iso; if (preg_match('/[_-]/i', $alang->iso)) { $iso = str_replace('_', '-', $alang->iso); $isocountry = explode('-', $iso); $active_isocountry[] = $isocountry[0]; } $active_code[] = $alang->shortcode; } // figure out which language to use - browser languages are based on ISO codes $browserLang = explode(',', $_SERVER["HTTP_ACCEPT_LANGUAGE"]); foreach ($browserLang as $blang) { if (in_array($blang, $active_iso)) { $client_lang = $blang; break; } $shortLang = substr($blang, 0, 2); if (in_array($shortLang, $active_isocountry)) { $client_lang = $shortLang; break; } // compare with code if (in_array($shortLang, $active_code)) { $client_lang = $shortLang; break; } } if (!empty($client_lang)) { if (strlen($client_lang) == 2) { $browserCode = SEFTools::getLangLongCode($client_lang); } else { $browserCode = $client_lang; } } } } if (!$jfrouterEnabled && $redir && $sefConfig->langPlacement != _COM_SEF_LANG_DOMAIN && (isset($cookieCode) || isset($browserCode)) && $sefConfig->mainLanguage != '0') { if (isset($cookieCode)) { $sc = SEFTools::getLangCode($cookieCode); } else { $sc = SEFTools::getLangCode($browserCode); } // Check the referer to see if we should redirect $shouldRedir = false; if (isset($_SERVER['HTTP_REFERER'])) { $refUri = new JURI($_SERVER['HTTP_REFERER']); $uri = JURI::getInstance(); $refHost = $refUri->getHost(); $host = $uri->getHost(); if ($refHost != $host) { $shouldRedir = true; } } else { $shouldRedir = true; } if ($shouldRedir) { if (!empty($lang) && $sc != $lang || empty($lang) && $sc != $sefConfig->mainLanguage) { // Redirect to correct site $mainframe =& JFactory::getApplication(); $href = JRoute::_('index.php?lang=' . $sc, false); $mainframe->redirect($href); exit; } } } // Check if language is selected if (empty($lang) && !$jfrouterEnabled) { // If route and query string are empty, use the main language // note: removed && $redir - it was not possible to switch language to main language // on other page than homepage (let's see if it causes any other problem) // note: added $useMainLang - now it should work for both the VM checkout and using // main language with component's own router if ($useMainLang && (empty($code) || !JLanguage::exists($code))) { if ($sefConfig->mainLanguage != '0') { $code = SEFTools::GetLangLongCode($sefConfig->mainLanguage); } } // Try to get language code from JF cookie if (empty($code) || !JLanguage::exists($code)) { if (isset($cookieCode)) { $code = $cookieCode; } } // Try to get language from browser if needed if (empty($code) || !JLanguage::exists($code)) { if (isset($browserCode)) { $code = $browserCode; } } // Get language from configuration if needed if (empty($code) || !JLanguage::exists($code)) { if ($sefConfig->mainLanguage != '0') { $code = SEFTools::GetLangLongCode($sefConfig->mainLanguage); } } // Get default language if needed if (empty($code) || !JLanguage::exists($code)) { $code = $registry->getValue('config.language'); } } // get language long code if needed if (empty($code)) { if (empty($lang)) { return; } $code = SEFTools::getLangLongCode($lang); } if (!empty($code)) { $jfrparams = $registry->getValue('jfrouter.params'); // set the site language $resetLang = false; if ($code != SEFTools::getLangLongCode()) { if (!$jfrouterEnabled || $jfrouterEnabled && $jfrparams->get('sefordomain', 'sefprefix') == 'sefprefix') { $language =& JFactory::getLanguage(); $language->setLanguage($code); $language->load(); // set the backward compatible language $backLang = $language->getBackwardLang(); $GLOBALS['mosConfig_lang'] = $backLang; $registry->setValue("config.lang", $backLang); $resetLang = true; } } // set joomfish language if needed if ($resetLang || !$jfrouterEnabled) { $jfLang = TableJFLanguage::createByJoomla($code); $registry->setValue("joomfish.language", $jfLang); // set some more variables $mainframe =& JFactory::getApplication(); $registry->setValue("config.multilingual_support", true); $mainframe->setUserState('application.lang', $jfLang->code); $registry->setValue("config.jflang", $jfLang->code); $registry->setValue("config.lang_site", $jfLang->code); $registry->setValue("config.language", $jfLang->code); $registry->setValue("joomfish.language", $jfLang); // overwrite global config with values from $jfLang if set to in JoomFish $jfparams = JComponentHelper::getParams("com_joomfish"); $overwriteGlobalConfig = $jfparams->get('overwriteGlobalConfig', 0); if ($overwriteGlobalConfig) { // We should overwrite additional global variables based on the language parameter configuration $langParams = new JParameter($jfLang->params); $paramarray = $langParams->toArray(); foreach ($paramarray as $key => $val) { $registry->setValue("config." . $key, $val); if (defined("_JLEGACY")) { $name = 'mosConfig_' . $key; $GLOBALS[$name] = $val; } } } // set the cookie with language if (!$jfrouterEnabled && $sefConfig->jfLangCookie || $jfrouterEnabled && $jfrparams->get('enableCookie', 1)) { setcookie("lang", "", time() - 1800, "/"); setcookie("jfcookie", "", time() - 1800, "/"); setcookie("jfcookie[lang]", $code, time() + 24 * 3600, '/'); } } } } }
function saveTranslation() { $catid = $this->_catid; $select_language_id = $this->_select_language_id; $language_id = $this->_language_id; $id = JRequest::getVar('reference_id', null); $jfc_id = JRequest::getVar('jfc_id ', null); $actContentObject = null; if (isset($catid) && $catid != "") { $contentElement = $this->_joomfishManager->getContentElement($catid); JLoader::import('models.ContentObject', JOOMFISH_ADMINPATH); $actContentObject = new ContentObject($language_id, $contentElement); // get's the config settings on how to store original files $storeOriginalText = $this->_joomfishManager->getCfg('storageOfOriginal') == 'md5' ? false : true; $actContentObject->bind($_POST, '', '', true, $storeOriginalText); $actContentObject->store(); $this->view->message = JText::_('Translation saved'); // Clear Translation Cache $db =& JFactory::getDBO(); $lang = new TableJFLanguage($db); $lang->load($language_id); $cache =& $this->_joomfishManager->getCache($lang->code); $cache->clean(); } else { $this->view->message = JText::_('Cannot save - invalid catid'); } if ($this->task == "translate.apply") { $cid = $actContentObject->id . "|" . $id . "|" . $language_id; JRequest::setVar('cid', array($cid)); $this->editTranslation(); } else { // redirect to overview $this->showTranslate(); } }
function shSetJfLanguage($requestlang) { if (empty($requestlang)) { return; } // get instance of JoomFishManager to obtain active language list and config values $jfm =& JoomFishManager::getInstance(); $activeLanguages = $jfm->getActiveLanguages(); // get the name of the language file for joomla $jfLang = TableJFLanguage::createByShortcode($requestlang, true); // set Joomfish stuff // Get the global configuration object global $mainframe; $registry =& JFactory::getConfig(); $params = $registry->getValue("jfrouter.params"); $enableCookie = empty($params) ? 1 : $params->get('enableCookie', 1); if ($enableCookie) { setcookie("lang", "", time() - 1800, "/"); setcookie("jfcookie", "", time() - 1800, "/"); setcookie("jfcookie[lang]", $jfLang->shortcode, time() + 24 * 3600, '/'); } $GLOBALS['iso_client_lang'] = $jfLang->shortcode; $GLOBALS['mosConfig_lang'] = $jfLang->code; $mainframe->setUserState('application.lang', $jfLang->code); $registry->setValue("config.jflang", $jfLang->code); $registry->setValue("config.lang_site", $jfLang->code); $registry->setValue("config.language", $jfLang->code); $registry->setValue("joomfish.language", $jfLang); // Force factory static instance to be updated if necessary $lang =& JFactory::getLanguage(); if ($jfLang->code != $lang->getTag()) { $lang = JFactory::_createLanguage(); } $lang16 =& shjlang16Helper::getLanguage(); if ($jfLang->code != $lang16->getTag()) { $lang16 = Jlanguage16::createLanguage(); } // overwrite with the valued from $jfLang $params = new JParameter($jfLang->params); $paramarray = $params->toArray(); foreach ($paramarray as $key => $val) { $registry->setValue("config." . $key, $val); if (defined("_JLEGACY")) { $name = 'mosConfig_' . $key; $GLOBALS[$name] = $val; } } // set our own data $GLOBALS['shMosConfig_lang'] = $lang->get('backwardlang', 'english'); $GLOBALS['shMosConfig_locale'] = $jfLang->code; $GLOBALS['shMosConfig_shortcode'] = $jfLang->shortcode; }
/** * Loads the language by it's iso name * @param string $iso iso name of the language * @return any result from the database operation */ function createByISO($iso, $active = true) { $db = JFactory::getDBO(); if ($iso === null) { return false; } $lang = new TableJFLanguage($db); $jfm = JoomFishManager::getInstance(); $langdata = $jfm->getLanguageByCode($iso, $active); if (!$lang->bind($langdata)) { $lang = null; } return $lang; }
function _discoverJFLanguage() { static $discovered; if (isset($discovered) && $discovered) { return; } $discovered = true; $registry = JFactory::getConfig(); // Find language without loading strings $locale = $registry->getValue('config.language'); // Attention - we need to access the site default values // #12943 explains that a user might overwrite the orignial settings based on his own profile $langparams = JComponentHelper::getParams('com_languages'); $defLanguage = $langparams->get("site"); $registry->setValue("config.defaultlang", isset($defLanguage) && $defLanguage != '' ? $defLanguage : $locale); // get params from registry in case function called statically $params = $registry->getValue("jfrouter.params"); $determitLanguage = $params->get('determitLanguage', 1); $newVisitorAction = $params->get('newVisitorAction', 'browser'); $use302redirect = $params->get('use302redirect', 0); $enableCookie = $params->get('enableCookie', 1); // get instance of JoomFishManager to obtain active language list and config values $jfm = JoomFishManager::getInstance(); $client_lang = ''; $lang_known = false; $jfcookie = JRequest::getVar('jfcookie', null, "COOKIE"); if (isset($jfcookie["lang"]) && $jfcookie["lang"] != "") { $client_lang = $jfcookie["lang"]; $lang_known = true; } $uri = JURI::getInstance(); if ($requestlang = JRequest::getVar('lang', null, "REQUEST")) { if ($requestlang != '') { $client_lang = $requestlang; $lang_known = true; } } // no language choosen - Test plugin e.g. IP lookup tool if (!$lang_known) { // setup Joomfish pluginds $dispatcher = JDispatcher::getInstance(); $iplang = ""; JPluginHelper::importPlugin('joomfish'); $dispatcher->trigger('onDiscoverLanguage', array(&$iplang)); if ($iplang != "") { $client_lang = $iplang; $lang_known = true; } } if (!$lang_known && $determitLanguage && key_exists('HTTP_ACCEPT_LANGUAGE', $_SERVER) && !empty($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { switch ($newVisitorAction) { // usesing the first defined Joom!Fish language case 'joomfish': $activeLanguages = $jfm->getActiveLanguages(); reset($activeLanguages); $first = key($activeLanguages); $client_lang = $activeLanguages[$first]->getLanguageCode(); break; case 'site': // We accept that this default locale might be overwritten by user settings! $jfLang = TableJFLanguage::createByJoomla($locale); $client_lang = $jfLang->getLanguageCode(); break; // no language chooses - assume from browser configuration // no language chooses - assume from browser configuration case 'browser': default: // language negotiation by Kochin Chang, June 16, 2004 // retrieve active languages from database $active_iso = array(); $active_isocountry = array(); $active_code = array(); $activeLanguages = $jfm->getActiveLanguages(); if (count($activeLanguages) == 0) { return; } foreach ($activeLanguages as $alang) { $active_iso[] = $alang->iso; if (preg_match('/[_-]/i', $alang->iso)) { $isocountry = preg_split('[_-]', $alang->iso); $active_isocountry[] = $isocountry[0]; } $active_code[] = $alang->shortcode; } // figure out which language to use - browser languages are based on ISO codes $browserLang = explode(',', $_SERVER["HTTP_ACCEPT_LANGUAGE"]); foreach ($browserLang as $blang) { if (in_array($blang, $active_iso)) { $client_lang = $blang; break; } $shortLang = substr($blang, 0, 2); if (in_array($shortLang, $active_isocountry)) { $client_lang = $shortLang; break; } // compare with code if (in_array($shortLang, $active_code)) { $client_lang = $shortLang; break; } } break; } } // get the name of the language file for joomla $jfLang = TableJFLanguage::createByShortcode($client_lang, false); if ($jfLang === null && $client_lang != "") { $jfLang = TableJFLanguage::createByISO($client_lang, false); } else { if ($jfLang === null) { $jfLang = TableJFLanguage::createByJoomla($locale); } } if (!$lang_known && $use302redirect) { // using a 302 redirect means that we do not change the language on the fly the first time, but with a clean reload of the page $href = "index.php"; $hrefVars = ''; $queryString = JRequest::getVar('QUERY_STRING', null, "SERVER"); if (!empty($queryString)) { $vars = explode("&", $queryString); if (count($vars) > 0 && $queryString) { foreach ($vars as $var) { if (preg_match('/=/i', $var)) { list($key, $value) = explode("=", $var); if ($key != "lang") { if ($hrefVars != "") { $hrefVars .= "&"; } // ignore mosmsg to ensure it is visible in frontend if ($key != 'mosmsg') { $hrefVars .= "{$key}={$value}"; } } } } } } // Add the existing variables if ($hrefVars != "") { $href .= '?' . $hrefVars; } if ($jfLang->getLanguageCode() != null) { $ulang = 'lang=' . $jfLang->getLanguageCode(); } else { // it's important that we add at least the basic parameter - as of the sef is adding the actual otherwise! $ulang = 'lang='; } // if there are other vars we need to add a & otherwiese ? if ($hrefVars == '') { $href .= '?' . $ulang; } else { $href .= '&' . $ulang; } $registry->setValue("config.multilingual_support", true); global $mainframe; $mainframe->setUserState('application.lang', $jfLang->code); $registry->setValue("config.jflang", $jfLang->code); $registry->setValue("config.lang_site", $jfLang->code); $registry->setValue("config.language", $jfLang->code); $registry->setValue("joomfish.language", $jfLang); $href = JRoute::_($href, false); header('HTTP/1.1 303 See Other'); header("Location: " . $href); exit; } if (isset($jfLang) && $jfLang->code != "" && ($jfLang->active || $jfm->getCfg("frontEndPreview"))) { $locale = $jfLang->code; } else { $jfLang = TableJFLanguage::createByJoomla($locale); if (!$jfLang->active) { ?> <div style="background-color: #c00; color: #fff"> <p style="font-size: 1.5em; font-weight: bold; padding: 10px 0px 10px 0px; text-align: center; font-family: Arial, Helvetica, sans-serif;"> Joom!Fish config error: Default language is inactive!<br /> <br /> Please check configuration, try to use first active language</p> </div> <?php $activeLanguages = $jfm->getActiveLanguages(); if (count($activeLanguages) > 0) { $jfLang = $activeLanguages[0]; $locale = $jfLang->code; } else { // No active language defined - using system default is only alternative! } } $client_lang = $jfLang->shortcode != '' ? $jfLang->shortcode : $jfLang->iso; } // TODO set the cookie domain so that it works for all subdomains if ($enableCookie) { setcookie("lang", "", time() - 1800, "/"); setcookie("jfcookie", "", time() - 1800, "/"); setcookie("jfcookie[lang]", $client_lang, time() + 24 * 3600, '/'); } if (defined("_JLEGACY")) { $GLOBALS['iso_client_lang'] = $client_lang; $GLOBALS['mosConfig_lang'] = $jfLang->code; } $registry->setValue("config.multilingual_support", true); global $mainframe; $mainframe->setUserState('application.lang', $jfLang->code); $registry->setValue("config.jflang", $jfLang->code); $registry->setValue("config.lang_site", $jfLang->code); $registry->setValue("config.language", $jfLang->code); $registry->setValue("joomfish.language", $jfLang); // Force factory static instance to be updated if necessary $lang =& JFactory::getLanguage(); if ($jfLang->code != $lang->getTag()) { // Must not assign by reference in order to overwrite the existing reference to the static instance of the language $lang = JFactory::_createLanguage(); $lang->setDefault($jfLang->code); $lang->_metadata = array(); $lang->_metadata['tag'] = $jfLang->code; $lang->_metadata['rtl'] = false; } // no need to set locale for this ISO code its done by JLanguage // overwrite with the valued from $jfLang $jfparams = JComponentHelper::getParams("com_joomfish"); $overwriteGlobalConfig = $jfparams->get('overwriteGlobalConfig', 0); if ($overwriteGlobalConfig) { // We should overwrite additional global variables based on the language parameter configuration $params = new JParameter($jfLang->params); $paramarray = $params->toArray(); foreach ($paramarray as $key => $val) { if (trim($val) !== '') { $registry->setValue("config." . $key, $val); } if (defined("_JLEGACY")) { $name = 'mosConfig_' . $key; $GLOBALS[$name] = $val; } } } }
/** Creates an array with all languages for the JoomFish * * @param boolean indicates if those languages must be active or not * @return Array of languages */ function getLanguages($active = true) { $db = JFactory::getDBO(); $langActive = null; $sql = 'SELECT * FROM #__languages'; if ($active) { //sbou //$sql .= ' WHERE active=1'; $sql .= ' WHERE published=1'; //fin sbou } $sql .= ' ORDER BY ordering'; $db->setQuery($sql); //sbou $rows = $db->loadObjectList('lang_id'); //$rows = $db->loadObjectList('id'); //fin sbou // We will need this class defined to popuplate the table include_once FALANG_ADMINPATH . DS . 'tables' . DS . 'JFLanguage.php'; if ($rows) { foreach ($rows as $row) { $lang = new TableJFLanguage($db); $lang->bind($row); $langActive[] = $lang; } } return $langActive; }
function _parseSefRoute(&$uri) { $vars = array(); _log('_parseSefRoute, parsing _uri ' . $uri->_uri); _log('_parseSefRoute, parsing _host ' . $uri->_host); _log('_parseSefRoute, parsing _path ' . $uri->_path); include JPATH_ROOT . DS . 'components' . DS . 'com_sh404sef' . DS . 'sh404sef.inc.php'; if (shIsMultilingual() == 'joomfish') { $currentLangShortCode = $GLOBALS['shMosConfig_shortcode']; $conf =& JFactory::getConfig(); $configDefaultLanguage = $conf->getValue('config.language'); $tmp = explode('-', str_replace('_', '-', $configDefaultLanguage)); $defaultLangShortCode = $tmp[0]; } else { $currentLang = ''; } $jMenu = null; $shMenu = null; // set active menu if changed if (!empty($vars['Itemid'])) { $newItemid = intval($vars['Itemid']); if (!empty($newItemid)) { $jMenu =& JSite::getMenu(); $jMenu->setActive($newItemid); $shMenu =& shRouter::shGetMenu(); $shMenu->setActive($newItemid); } } //Set the variables $this->setVars($vars); // set language again, as Joomfish may have set it according to user cookie if (shIsMultilingual() == 'joomfish' && !empty($vars['lang']) && $vars['lang'] != $currentLangShortCode) { JRequest::setVar('lang', $vars['lang']); // we also need to fix the main menu, as joomfish has set it to the wrong language if (empty($shMenu) || empty($shMenu)) { $jMenu =& JSite::getMenu(); $shMenu =& shRouter::shGetMenu(); } $sefLang = TableJFLanguage::createByShortcode($vars['lang'], false); $jMenu->_items = shGetJFMenu($sefLang->code, false, $jMenu->_items); $shMenu->_items = shGetJFMenu($sefLang->code, false, $shMenu->_items); // and finally we can set new joomfish language shSetJfLanguage($vars['lang']); } // last fix is to remove the home flag if other than default language if (shIsMultilingual() == 'joomfish' && !empty($vars['lang']) && $vars['lang'] != $defaultLangShortCode) { if (empty($shMenu) || empty($shMenu)) { $jMenu =& JSite::getMenu(); $shMenu =& shRouter::shGetMenu(); } $jDefaultItem =& $jMenu->getDefault(); $jDefaultItem->home = 0; $shDefaultItem =& $shMenu->getDefault(); $shDefaultItem->home = 0; } // and finally we can set new joomfish language if (shIsMultilingual() == 'joomfish' && !empty($vars['lang']) && $vars['lang'] != $currentLangShortCode) { shSetJfLanguage($vars['lang']); } // real last fix is to fix the $uri object, which Joomfish broke as it intended the path to be // parsed by Joomla router, not ours if (shIsMultilingual() == 'joomfish') { $myUri =& JURI::getInstance(); // fix the path if (!empty($sefConfig->shRewriteMode)) { $rewriteBit = JString::rtrim($sefConfig->shRewriteStrings[$sefConfig->shRewriteMode], '/'); } else { $rewriteBit = ''; } $path = rtrim($shPageInfo->base, '/') . $rewriteBit . $shPageInfo->shCurrentPagePath; $myUri->setPath($path); // remove the lang query that JF added to $uri $myUri->delVar('lang'); } return $vars; }
/** Standard constructor * * @param languageID ID of the associated language * @param elementTable Reference to the ContentElementTable object */ function ContentObject($languageID, &$contentElement, $id = -1) { $db =& JFactory::getDBO(); if ($id > 0) { $this->id = $id; } $this->language_id = $languageID; // active languages are cached in $_JOOMFISH_MANAGER - use these if possible global $_JOOMFISH_MANAGER; if (isset($_JOOMFISH_MANAGER) && $_JOOMFISH_MANAGER->activeLanguagesCacheByID && array_key_exists($languageID, $_JOOMFISH_MANAGER->activeLanguagesCacheByID)) { $lang = $_JOOMFISH_MANAGER->activeLanguagesCacheByID[$languageID]; } else { $lang = new TableJFLanguage($db); $lang->load($languageID); } $this->language = $lang->name; $this->_contentElement = $contentElement; }
function _createHRef2($currenturl, $href, $code) { // Treat change of language specially because of problems if menu alias is translated $registry = JFactory::getConfig(); $language = $registry->getValue("joomfish.language", null); if ($language != null) { $jfLang = $language->getLanguageCode(); } else { $jfLang = null; } if (!is_null($code) && $code != $jfLang) { $registry = JFactory::getConfig(); $sefLang = TableJFLanguage::createByShortcode($code, false); $registry->setValue("joomfish.sef_lang", $sefLang->code); // Should really do this with classes and clones - this is a proof of concept $menu = JSite::getMenu(); $menu->_items = JFModuleHTML::getJFMenu($sefLang->code, false, $menu->_items); $url = JFModuleHTML::_route($href, $sefLang); $menu->_items = JFModuleHTML::getJFMenu($language->code, true); $registry->setValue("joomfish.sef_lang", false); /* $menu = JSite::getMenu(true); if (version_compare(phpversion(), '5.0') >= 0) { $keepmenu = clone($menu); } else { $keepmenu = $menu; } $menu = new JMenuSite(); $url = JRoute::_( $href ); $registry->setValue("joomfish.sef_lang", false); $menu = $keepmenu; return $url; */ } else { $url = JFModuleHTML::_route($href, $language); } return $url; }
function saveTranslation() { $catid = $this->_catid; $select_language_id = $this->_select_language_id; $language_id = $this->_language_id; $id = JRequest::getVar('reference_id', null); $jfc_id = JRequest::getVar('jfc_id ', null); $translationObject = null; if (isset($catid) && $catid != "") { $contentElement = $this->_joomfishManager->getContentElement($catid); $translationClass = $contentElement->getTranslationObjectClass(); $translationObject = new $translationClass($language_id, $contentElement); // get's the config settings on how to store original files $storeOriginalText = $this->_joomfishManager->getCfg('storageOfOriginal') == 'md5' ? false : true; $translationObject->bind($_POST, '', '', true, $storeOriginalText); $success = $translationObject->store(); if ($success) { JPluginHelper::importPlugin('joomfish'); $dispatcher = JDispatcher::getInstance(); $dispatcher->trigger('onAfterTranslationSave', array($_POST)); $this->view->message = JText::_('TRANSLATION_SAVED'); } else { $this->view->message = JText::_('ERROR_SAVING_TRANSLATION'); } // Clear Translation Cache $db = JFactory::getDBO(); $lang = new TableJFLanguage($db); $lang->load($language_id); $cache = $this->_joomfishManager->getCache($lang->code); $cache->clean(); } else { $this->view->message = JText::_('Cannot save - invalid catid'); } if ($this->task == "apply") { $cid = $translationObject->id . "|" . $id . "|" . $language_id; JRequest::setVar('cid', array($cid)); //$this->editTranslation(); $this->setRedirect("index.php?option=com_joomfish&task=translate.edit&cid[]={$cid}", $this->view->message); } else { // redirect to overview $this->setRedirect("index.php?option=com_joomfish&task=translate.overview", $this->view->message); } }
function saveTranslation() { $catid = $this->_catid; $select_language_id = $this->_select_language_id; $language_id = $this->_language_id; $app = JFactory::getApplication(); $id = $app->input->get('reference_id', null); $jfc_id = $app->input->get('jfc_id ', null); $actContentObject = null; if (isset($catid) && $catid != "") { $contentElement = $this->_falangManager->getContentElement($catid); JLoader::import('models.ContentObject', FALANG_ADMINPATH); $actContentObject = new ContentObject($language_id, $contentElement); // get's the config settings on how to store original files $storeOriginalText = $this->_falangManager->getCfg('storageOfOriginal') == 'md5' ? false : true; $actContentObject->bind($_POST, '', '', true, $storeOriginalText); if ($actContentObject->store() == null) { // JPluginHelper::importPlugin('falang'); $dispatcher = JDispatcher::getInstance(); $dispatcher->trigger('onAfterTranslationSave', array($_POST)); $this->view->message = JText::_('COM_FALANG_TRANSLATE_SAVED'); } else { $this->view->message = JText::_('COM_FALANG_TRANSLATE_SAVED_ERROR'); } // Clear Translation Cache $db = JFactory::getDBO(); $lang = new TableJFLanguage($db); $lang->load($language_id); $cache = $this->_falangManager->getCache($lang->code); //$cache->clean(); } else { $this->view->message = JText::_('COM_FALANG_TRANSLATE_SAVED_ERROR_CATID'); } if ($this->task == "apply") { $cid = $actContentObject->id . "|" . $id . "|" . $language_id; JRequest::setVar('cid', array($cid)); $this->editTranslation(); } else { // redirect to overview $this->showTranslate(); } }
function determineLanguage($get_lang = null) { // Set the language for JoomFish if (AcesefUtility::JoomFishInstalled()) { $registry = JFactory::getConfig(); // save the default language of the site if needed $locale = $registry->get('config.language'); $GLOBALS['mosConfig_defaultLang'] = $locale; $registry->set("config.defaultlang", $locale); // Get language from request if (!empty($get_lang)) { $lang = $get_lang; } // Try to get language code from JF cookie if ($this->AcesefConfig->joomfish_cookie) { $jf_cookie = JRequest::getVar('jfcookie', null, 'COOKIE'); if (isset($jf_cookie['lang'])) { $cookieCode = $jf_cookie['lang']; } } // Try to find language from browser settings if ($this->AcesefConfig->joomfish_browser && isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) && !empty($_SERVER['HTTP_ACCEPT_LANGUAGE']) && class_exists('JoomFishManager')) { $active_iso = array(); $active_isocountry = array(); $active_code = array(); $active_languages = JoomFishManager::getInstance()->getActiveLanguages(); if (count($active_languages) > 0) { foreach ($active_languages as $a_lang) { $active_iso[] = $a_lang->iso; if (preg_match('/[_-]/i', $a_lang->iso)) { $iso = str_replace('_', '-', $a_lang->iso); $isocountry = explode('-', $iso); $active_isocountry[] = $isocountry[0]; } $active_code[] = $a_lang->shortcode; } // figure out which language to use - browser languages are based on ISO codes $browser_lang = explode(',', $_SERVER["HTTP_ACCEPT_LANGUAGE"]); foreach ($browser_lang as $b_lang) { if (in_array($b_lang, $active_iso)) { $client_lang = $b_lang; break; } $short_lang = substr($b_lang, 0, 2); if (in_array($short_lang, $active_isocountry)) { $client_lang = $short_lang; break; } // compare with code if (in_array($short_lang, $active_code)) { $client_lang = $short_lang; break; } } if (!empty($client_lang)) { if (strlen($client_lang) == 2) { $browser_code = self::getLangLongCode($client_lang); } else { $browser_code = $client_lang; } } } } // Check if language is selected if (empty($lang)) { if (empty($code) || !JLanguage::exists($code)) { if ($this->AcesefConfig->joomfish_main_lang != '0') { $code = self::getLangLongCode($this->AcesefConfig->joomfish_main_lang); } } // Try to get language code from JF cookie if (empty($code) || !JLanguage::exists($code)) { if (isset($cookieCode)) { $code = $cookieCode; } } // Try to get language from browser if needed if (empty($code) || !JLanguage::exists($code)) { if (isset($browser_code)) { $code = $browser_code; } } // Get language from configuration if needed if (empty($code) || !JLanguage::exists($code)) { if ($this->AcesefConfig->joomfish_main_lang != '0') { $code = self::getLangLongCode($this->AcesefConfig->joomfish_main_lang); } } // Get default language if needed if (empty($code) || !JLanguage::exists($code)) { $code = $registry->get('config.language'); } } // get language long code if needed if (empty($code)) { if (empty($lang)) { return; } $code = self::getLangLongCode($lang); } if (!empty($code)) { // set the site language $reset_lang = false; if ($code != self::getLangLongCode()) { $language = JFactory::getLanguage(); $language->setLanguage($code); $language->load(); // set the backward compatible language $back_lang = $language->getBackwardLang(); $GLOBALS['mosConfig_lang'] = $back_lang; $registry->set("config.lang", $back_lang); $reset_lang = true; } // set joomfish language if needed if ($reset_lang) { $jf_lang = TableJFLanguage::createByJoomla($code); $registry->set("joomfish.language", $jf_lang); // set some more variables $mainframe = JFactory::getApplication(); $registry->set("config.multilingual_support", true); $mainframe->setUserState('application.lang', $jf_lang->code); $registry->set("config.jflang", $jf_lang->code); $registry->set("config.lang_site", $jf_lang->code); $registry->set("config.language", $jf_lang->code); $registry->set("joomfish.language", $jf_lang); // overwrite global config with values from $jf_lang if set to in JoomFish $jf_params = JComponentHelper::getParams("com_joomfish"); $overwriteGlobalConfig = $jf_params->get('overwriteGlobalConfig', 0); if ($overwriteGlobalConfig) { // We should overwrite additional global variables based on the language parameter configuration $lang_params = new JParameter($jf_lang->params); $param_array = $lang_params->toArray(); foreach ($param_array as $key => $val) { $registry->set("config." . $key, $val); if (defined("_JLEGACY")) { $name = 'mosConfig_' . $key; $GLOBALS[$name] = $val; } } } // set the cookie with language if ($this->AcesefConfig->joomfish_cookie) { setcookie("lang", "", time() - 1800, "/"); setcookie("jfcookie", "", time() - 1800, "/"); setcookie("jfcookie[lang]", $code, time() + 24 * 3600, '/'); } } } } }