Example #1
0
 /**
  * Get a language object
  *
  * Returns a reference to the global {@link JLanguage} object, only creating it
  * if it doesn't already exist.
  *
  * @access public
  * @return object JLanguage
  */
 function &getLanguage()
 {
     static $instance;
     if (!is_object($instance)) {
         //get the debug configuration setting
         $conf =& JFactory::getConfig();
         $debug = $conf->getValue('config.debug_lang');
         $instance = JFactory::_createLanguage();
         $instance->setDebug($debug);
     }
     return $instance;
 }
 /**
  * Grabs the params from the db if we are getting an article,
  * then gets the language tag from it. If there's a valid language
  * tag then we set it into the JDocument. That's all.
  * @access	public
  */
 function onAfterRoute()
 {
     $option = JRequest::getVar("option", '');
     if ($option == "com_content") {
         if (JRequest::getVar("view", null) == 'article') {
             $id = (int) JRequest::getVar('id');
             $db =& JFactory::getDBO();
             $query = 'SELECT attribs ' . ' FROM #__content' . ' WHERE id = ' . $id;
             $db->setQuery($query);
             $attribs = $db->loadResult();
             $aparams = explode("\n", $attribs);
             $html_lang_tag = $this->params->get('html_lang_tag', 1);
             foreach ($aparams as $param) {
                 $vart = strpos($param, "language");
                 if ($vart !== false) {
                     $langnow = $param;
                     $user = JFactory::getUser();
                     $langnow = explode("=", $langnow);
                     foreach ($langnow as $langnow) {
                         if ($langnow !== "language" && $langnow != '') {
                             if (!$html_lang_tag) {
                                 $doc =& JFactory::getDocument();
                                 $doc->setLanguage($langnow);
                             }
                             if ($html_lang_tag) {
                                 // do the whole page (also does the <html> tag stuff)
                                 $config =& JFactory::getConfig();
                                 $oldlang =& JFactory::getLanguage();
                                 if ($oldlang->getTag() != $langnow) {
                                     // this is slightly dodgy, in that the original language object was created
                                     // BEFORE all the routing was done.
                                     // $mainframe->route()   and  $mainframe->authorize()  are done with the
                                     // old language, before we get this chance to set the new one.
                                     // But neither of those seem to need anything to do with the old language
                                     // so we are almost certainly fine :-)
                                     $config->setValue('config.language', $langnow);
                                     $oldlang = JFactory::_createLanguage();
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
 }
Example #3
0
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;
}
Example #4
0
  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 .= "&amp;";
                              }
                              // 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 .= '&amp;' . $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 />&nbsp;<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;
              }
          }
      }
  }
Example #5
0
 /**
  * Get a language object
  *
  * Returns the global {@link JLanguage} object, only creating it
  * if it doesn't already exist.
  *
  * @return object JLanguage
  */
 public static function getLanguage()
 {
     if (!is_object(JFactory::$language)) {
         //get the debug configuration setting
         $conf =& JFactory::getConfig();
         $debug = $conf->getValue('config.debug_lang');
         JFactory::$language = JFactory::_createLanguage();
         JFactory::$language->setDebug($debug);
     }
     return JFactory::$language;
 }