コード例 #1
0
 public function __construct(&$subject, $config)
 {
     parent::__construct($subject, $config);
     // Ensure that constructor is called one time
     self::$cookie = SID == '';
     if (!self::$default_lang) {
         $app = JFactory::getApplication();
         $router = $app->getRouter();
         if (App::isSite()) {
             // setup language data
             self::$mode_sef = $router->getMode() == JROUTER_MODE_SEF ? true : false;
             self::$sefs = JLanguageHelper::getLanguages('sef');
             self::$lang_codes = JLanguageHelper::getLanguages('lang_code');
             self::$default_lang = Component::params('com_languages')->get('site', 'en-GB');
             self::$default_sef = self::$lang_codes[self::$default_lang]->sef;
             self::$homes = MultilangstatusHelper::getHomepages();
             $user = User::getRoot();
             $levels = $user->getAuthorisedViewLevels();
             foreach (self::$sefs as $sef => &$language) {
                 if (isset($language->access) && $language->access && !in_array($language->access, $levels)) {
                     unset(self::$sefs[$sef]);
                 }
             }
             App::forget('language.filter');
             App::set('language.filter', true);
             $uri = JFactory::getURI();
             if (self::$mode_sef) {
                 // Get the route path from the request.
                 $path = JString::substr($uri->toString(), JString::strlen($uri->base()));
                 // Apache mod_rewrite is Off
                 $path = Config::get('sef_rewrite') ? $path : JString::substr($path, 10);
                 // Trim any spaces or slashes from the ends of the path and explode into segments.
                 $path = JString::trim($path, '/ ');
                 $parts = explode('/', $path);
                 // The language segment is always at the beginning of the route path if it exists.
                 $sef = $uri->getVar('lang');
                 if (!empty($parts) && empty($sef)) {
                     $sef = reset($parts);
                 }
             } else {
                 $sef = $uri->getVar('lang');
             }
             if (isset(self::$sefs[$sef])) {
                 $lang_code = self::$sefs[$sef]->lang_code;
                 // Create a cookie
                 $cookie_domain = Config::get('cookie_domain', '');
                 $cookie_path = Config::get('cookie_path', '/');
                 setcookie(App::hash('language'), $lang_code, $this->getLangCookieTime(), $cookie_path, $cookie_domain);
                 // set the request var
                 Request::setVar('language', $lang_code);
             }
         }
         parent::__construct($subject, $config);
         // 	Detect browser feature
         if (App::isSite()) {
             $app->setDetectBrowser($this->params->get('detect_browser', '1') == '1');
         }
     }
 }
コード例 #2
0
 public function __construct(&$subject, $config)
 {
     // Ensure that constructor is called one time
     self::$cookie = SID == '';
     if (!self::$default_lang) {
         $app = JFactory::getApplication();
         $router = $app->getRouter();
         if ($app->isSite()) {
             // setup language data
             self::$mode_sef = $router->getMode() == JROUTER_MODE_SEF ? true : false;
             self::$sefs = JLanguageHelper::getLanguages('sef');
             self::$lang_codes = JLanguageHelper::getLanguages('lang_code');
             self::$default_lang = JComponentHelper::getParams('com_languages')->get('site', 'en-GB');
             self::$default_sef = self::$lang_codes[self::$default_lang]->sef;
             $app->setLanguageFilter(true);
             $uri = JFactory::getURI();
             if (self::$mode_sef) {
                 // Get the route path from the request.
                 $path = JString::substr($uri->toString(), JString::strlen($uri->base()));
                 // Apache mod_rewrite is Off
                 $path = JFactory::getConfig()->get('sef_rewrite') ? $path : JString::substr($path, 10);
                 // Trim any spaces or slashes from the ends of the path and explode into segments.
                 $path = JString::trim($path, '/ ');
                 $parts = explode('/', $path);
                 // The language segment is always at the beginning of the route path if it exists.
                 $sef = $uri->getVar('lang');
                 if (!empty($parts) && empty($sef)) {
                     $sef = reset($parts);
                 }
             } else {
                 $sef = $uri->getVar('lang');
             }
             if (isset(self::$sefs[$sef])) {
                 $lang_code = self::$sefs[$sef]->lang_code;
                 // Create a cookie
                 $conf = JFactory::getConfig();
                 $cookie_domain = $conf->get('config.cookie_domain', '');
                 $cookie_path = $conf->get('config.cookie_path', '/');
                 setcookie(JApplication::getHash('language'), $lang_code, time() + 365 * 86400, $cookie_path, $cookie_domain);
                 // set the request var
                 JRequest::setVar('language', $lang_code);
             }
         }
         parent::__construct($subject, $config);
         // 	Detect browser feature
         if ($app->isSite()) {
             $app->setDetectBrowser($this->params->get('detect_browser', '1') == '1');
         }
     }
 }