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');
         }
     }
 }
Beispiel #2
0
 /**
  * Display the view.
  *
  * @param   string  $tpl  The name of the template file to parse.
  *
  * @return  void
  */
 public function display($tpl = null)
 {
     require_once JPATH_COMPONENT . '/helpers/multilangstatus.php';
     $this->homes = MultilangstatusHelper::getHomes();
     $this->language_filter = JLanguageMultilang::isEnabled();
     $this->switchers = MultilangstatusHelper::getLangswitchers();
     $this->listUsersError = MultilangstatusHelper::getContacts();
     $this->contentlangs = MultilangstatusHelper::getContentlangs();
     $this->site_langs = MultilangstatusHelper::getSitelangs();
     $this->statuses = MultilangstatusHelper::getStatus();
     $this->homepages = MultilangstatusHelper::getHomepages();
     parent::display($tpl);
 }
Beispiel #3
0
 /**
  * Display the view.
  *
  * @param   string  $tpl  The name of the template file to parse.
  *
  * @return  void
  */
 public function display($tpl = null)
 {
     JLoader::register('MultilangstatusHelper', JPATH_ADMINISTRATOR . '/components/com_languages/helpers/multilangstatus.php');
     $this->homes = MultilangstatusHelper::getHomes();
     $this->language_filter = JLanguageMultilang::isEnabled();
     $this->switchers = MultilangstatusHelper::getLangswitchers();
     $this->listUsersError = MultilangstatusHelper::getContacts();
     $this->contentlangs = MultilangstatusHelper::getContentlangs();
     $this->site_langs = JLanguageMultilang::getSiteLangs();
     $this->statuses = MultilangstatusHelper::getStatus();
     $this->homepages = JLanguageMultilang::getSiteHomePages();
     parent::display($tpl);
 }
 /**
  * Method to handle any login logic and report back to the subject.
  *
  * @param   array  $user     Holds the user data.
  * @param   array  $options  Array holding options (remember, autoregister, group).
  *
  * @return  boolean  True on success.
  *
  * @since   1.5
  */
 public function onUserLogin($user, $options = array())
 {
     $menu = $this->app->getMenu();
     if ($this->app->isSite() && $this->params->get('automatic_change', 1)) {
         // Load associations.
         $assoc = JLanguageAssociations::isEnabled();
         if ($assoc) {
             $active = $menu->getActive();
             if ($active) {
                 $associations = MenusHelper::getAssociations($active->id);
             }
         }
         $lang_code = $user['language'];
         if (empty($lang_code)) {
             $lang_code = $this->default_lang;
         }
         if ($lang_code != $this->default_lang) {
             // Change language.
             $this->default_lang = $lang_code;
             // Create a cookie.
             $cookie_domain = $this->app->get('cookie_domain', '');
             $cookie_path = $this->app->get('cookie_path', '/');
             setcookie(JApplicationHelper::getHash('language'), $lang_code, $this->getLangCookieTime(), $cookie_path, $cookie_domain);
             // Change the language code.
             JFactory::getLanguage()->setLanguage($lang_code);
             // Change the redirect (language has changed).
             if (isset($associations[$lang_code]) && $menu->getItem($associations[$lang_code])) {
                 $itemid = $associations[$lang_code];
                 $this->app->setUserState('users.login.form.return', 'index.php?&Itemid=' . $itemid);
             } else {
                 JLoader::register('MultilangstatusHelper', JPATH_ADMINISTRATOR . '/components/com_languages/helpers/multilangstatus.php');
                 $homes = MultilangstatusHelper::getHomepages();
                 $itemid = isset($homes[$lang_code]) ? $homes[$lang_code]->id : $homes['*']->id;
                 $this->app->setUserState('users.login.form.return', 'index.php?&Itemid=' . $itemid);
             }
         }
     }
 }
Beispiel #5
0
 /**
  * Method to add alternative meta tags for associated menu items.
  *
  * @return  void
  *
  * @since   1.7
  */
 public function onAfterDispatch()
 {
     $doc = JFactory::getDocument();
     if ($this->app->isSite() && $this->params->get('alternate_meta') && $doc->getType() == 'html') {
         $languages = $this->lang_codes;
         $homes = MultilangstatusHelper::getHomepages();
         $menu = $this->app->getMenu();
         $active = $menu->getActive();
         $levels = JFactory::getUser()->getAuthorisedViewLevels();
         $remove_default_prefix = $this->params->get('remove_default_prefix', 0);
         $server = JUri::getInstance()->toString(array('scheme', 'host', 'port'));
         $is_home = false;
         if ($active) {
             $active_link = JRoute::_($active->link . '&Itemid=' . $active->id, false);
             $current_link = JUri::getInstance()->toString(array('path', 'query'));
             // Load menu associations
             if ($active_link == $current_link) {
                 $associations = MenusHelper::getAssociations($active->id);
             }
             // Check if we are on the homepage
             $is_home = $active->home && ($active_link == $current_link || $active_link == $current_link . 'index.php' || $active_link . '/' == $current_link);
         }
         // Load component associations.
         $option = $this->app->input->get('option');
         $cName = JString::ucfirst(JString::str_ireplace('com_', '', $option)) . 'HelperAssociation';
         JLoader::register($cName, JPath::clean(JPATH_COMPONENT_SITE . '/helpers/association.php'));
         if (class_exists($cName) && is_callable(array($cName, 'getAssociations'))) {
             $cassociations = call_user_func(array($cName, 'getAssociations'));
         }
         // For each language...
         foreach ($languages as $i => &$language) {
             switch (true) {
                 // Language without frontend UI || Language without specific home menu || Language without authorized access level
                 case !array_key_exists($i, MultilangstatusHelper::getSitelangs()):
                 case !isset($homes[$i]):
                 case isset($language->access) && $language->access && !in_array($language->access, $levels):
                     unset($languages[$i]);
                     break;
                     // Home page
                 // Home page
                 case $is_home:
                     $language->link = JRoute::_('index.php?lang=' . $language->sef . '&Itemid=' . $homes[$i]->id);
                     break;
                     // Current language link
                 // Current language link
                 case $i == $this->current_lang:
                     $language->link = JUri::getInstance()->toString(array('path', 'query'));
                     break;
                     // Component association
                 // Component association
                 case isset($cassociations[$i]):
                     $language->link = JRoute::_($cassociations[$i] . '&lang=' . $language->sef);
                     break;
                     // Menu items association
                     // Heads up! "$item = $menu" here below is an assignment, *NOT* comparison
                 // Menu items association
                 // Heads up! "$item = $menu" here below is an assignment, *NOT* comparison
                 case isset($associations[$i]) && ($item = $menu->getItem($associations[$i])):
                     $language->link = JRoute::_($item->link . '&Itemid=' . $item->id . '&lang=' . $language->sef);
                     break;
                     // Too bad...
                 // Too bad...
                 default:
                     unset($languages[$i]);
             }
         }
         // If there are at least 2 of them, add the rel="alternate" links to the <head>
         if (count($languages) > 1) {
             // Remove the sef from the default language if "Remove URL Language Code" is on
             if (isset($languages[$this->default_lang]) && $remove_default_prefix) {
                 $languages[$this->default_lang]->link = preg_replace('|/' . $languages[$this->default_lang]->sef . '/|', '/', $languages[$this->default_lang]->link, 1);
             }
             foreach ($languages as $i => &$language) {
                 $doc->addHeadLink($server . $language->link, 'alternate', 'rel', array('hreflang' => $i));
             }
         }
     }
 }
Beispiel #6
0
 /**
  * Gets a list of available languages
  *
  * @param   \Joomla\Registry\Registry  &$params  module params
  *
  * @return  array
  */
 public static function getList(&$params)
 {
     $user = JFactory::getUser();
     $lang = JFactory::getLanguage();
     $languages = JLanguageHelper::getLanguages();
     $app = JFactory::getApplication();
     $menu = $app->getMenu();
     // Get menu home items
     $homes = array();
     $homes['*'] = $menu->getDefault('*');
     foreach ($languages as $item) {
         $default = $menu->getDefault($item->lang_code);
         if ($default && $default->language == $item->lang_code) {
             $homes[$item->lang_code] = $default;
         }
     }
     // Load associations
     $assoc = JLanguageAssociations::isEnabled();
     if ($assoc) {
         $active = $menu->getActive();
         if ($active) {
             $associations = MenusHelper::getAssociations($active->id);
         }
         // Load component associations
         $class = str_replace('com_', '', $app->input->get('option')) . 'HelperAssociation';
         JLoader::register($class, JPATH_COMPONENT_SITE . '/helpers/association.php');
         if (class_exists($class) && is_callable(array($class, 'getAssociations'))) {
             $cassociations = call_user_func(array($class, 'getAssociations'));
         }
     }
     $levels = $user->getAuthorisedViewLevels();
     // Filter allowed languages
     foreach ($languages as $i => &$language) {
         // Do not display language without frontend UI
         if (!array_key_exists($language->lang_code, MultilangstatusHelper::getSitelangs())) {
             unset($languages[$i]);
         } elseif (!isset($homes[$language->lang_code])) {
             unset($languages[$i]);
         } elseif (isset($language->access) && $language->access && !in_array($language->access, $levels)) {
             unset($languages[$i]);
         } else {
             $language->active = $language->lang_code == $lang->getTag();
             if (JLanguageMultilang::isEnabled()) {
                 if (isset($cassociations[$language->lang_code])) {
                     $language->link = JRoute::_($cassociations[$language->lang_code] . '&lang=' . $language->sef);
                 } elseif (isset($associations[$language->lang_code]) && $menu->getItem($associations[$language->lang_code])) {
                     $itemid = $associations[$language->lang_code];
                     $language->link = JRoute::_('index.php?lang=' . $language->sef . '&Itemid=' . $itemid);
                 } else {
                     if ($language->active) {
                         $language->link = JUri::getInstance()->toString(array('scheme', 'host', 'port', 'path', 'query'));
                     } else {
                         $itemid = isset($homes[$language->lang_code]) ? $homes[$language->lang_code]->id : $homes['*']->id;
                         $language->link = JRoute::_('index.php?lang=' . $language->sef . '&Itemid=' . $itemid);
                     }
                 }
             } else {
                 $language->link = JRoute::_('&Itemid=' . $homes['*']->id);
             }
         }
     }
     return $languages;
 }