diff --git a/components/com_content/View/Article/HtmlView.php b/components/com_content/View/Article/HtmlView.php index de3e568cea3cc..414e96e358cd1 100644 --- a/components/com_content/View/Article/HtmlView.php +++ b/components/com_content/View/Article/HtmlView.php @@ -197,10 +197,13 @@ public function display($tpl = null) { if ($this->user->get('guest')) { - $return = base64_encode(Uri::getInstance()); - $login_url_with_return = Route::_('index.php?option=com_users&return=' . $return); + $uri = new Uri('index.php'); + $uri->setQuery($app->getRouter()->getVars()); + + $login_url_with_return = new Uri(Route::_('index.php?option=com_users&view=login', false)); + $login_url_with_return->setVar('return', base64_encode($uri->toString())); $app->enqueueMessage(Text::_('JERROR_ALERTNOAUTHOR'), 'notice'); - $app->redirect($login_url_with_return, 403); + $app->redirect($login_url_with_return->toString(), 403); } else { diff --git a/components/com_content/tmpl/article/default.php b/components/com_content/tmpl/article/default.php index 8cc0ae56fb56a..38841ee42e27e 100644 --- a/components/com_content/tmpl/article/default.php +++ b/components/com_content/tmpl/article/default.php @@ -141,11 +141,11 @@ item->introtext); ?> get('show_readmore') && $this->item->fulltext != null) : ?> - getMenu(); ?> - getActive(); ?> - id; ?> - - setVar('return', base64_encode(ContentHelperRoute::getArticleRoute($this->item->slug, $this->item->catid, $this->item->language))); ?> + + item->slug, $this->item->catid, $this->item->language)); ?> + getRouter(); ?> + buildComponentPreprocess($router, $uri); ?> + setVar('return', base64_encode($uri->toString())); ?>

item->attribs); ?> diff --git a/components/com_content/tmpl/category/blog_item.php b/components/com_content/tmpl/category/blog_item.php index 83406ea7adf96..fad79e5ed7d3c 100644 --- a/components/com_content/tmpl/category/blog_item.php +++ b/components/com_content/tmpl/category/blog_item.php @@ -72,11 +72,11 @@ if ($params->get('access-view')) : $link = Route::_(ContentHelperRoute::getArticleRoute($this->item->slug, $this->item->catid, $this->item->language)); else : - $menu = Factory::getApplication()->getMenu(); - $active = $menu->getActive(); - $itemId = $active->id; - $link = new Uri(Route::_('index.php?option=com_users&view=login&Itemid=' . $itemId, false)); - $link->setVar('return', base64_encode(ContentHelperRoute::getArticleRoute($this->item->slug, $this->item->catid, $this->item->language))); + $link = new Uri(Route::_('index.php?option=com_users&view=login', false)); + $uri = new Uri(ContentHelperRoute::getArticleRoute($this->item->slug, $this->item->catid, $this->item->language)); + $router = Factory::getApplication()->getRouter(); + $router->buildComponentPreprocess($router, $uri); + $link->setVar('return', base64_encode($uri->toString())); endif; ?> $this->item, 'params' => $params, 'link' => $link)); ?> diff --git a/components/com_content/tmpl/category/default_articles.php b/components/com_content/tmpl/category/default_articles.php index f5812d4006841..4253eaeca47c6 100644 --- a/components/com_content/tmpl/category/default_articles.php +++ b/components/com_content/tmpl/category/default_articles.php @@ -176,9 +176,11 @@ escape($article->title) . ' : '; - $itemId = Factory::getApplication()->getMenu()->getActive()->id; - $link = new Uri(Route::_('index.php?option=com_users&view=login&Itemid=' . $itemId, false)); - $link->setVar('return', base64_encode(ContentHelperRoute::getArticleRoute($article->slug, $article->catid, $article->language))); + $link = new Uri(Route::_('index.php?option=com_users&view=login', false)); + $uri = new Uri(ContentHelperRoute::getArticleRoute($article->slug, $article->catid, $article->language)); + $router = Factory::getApplication()->getRouter(); + $router->buildComponentPreprocess($router, $uri); + $link->setVar('return', base64_encode($uri->toString())); ?> diff --git a/components/com_content/tmpl/featured/default_item.php b/components/com_content/tmpl/featured/default_item.php index a5e6e2212f3fe..d6f22b738d2d5 100644 --- a/components/com_content/tmpl/featured/default_item.php +++ b/components/com_content/tmpl/featured/default_item.php @@ -92,11 +92,11 @@ if ($params->get('access-view')) : $link = Route::_(ContentHelperRoute::getArticleRoute($this->item->slug, $this->item->catid, $this->item->language)); else : - $menu = Factory::getApplication()->getMenu(); - $active = $menu->getActive(); - $itemId = $active->id; - $link = new Uri(Route::_('index.php?option=com_users&view=login&Itemid=' . $itemId, false)); - $link->setVar('return', base64_encode(ContentHelperRoute::getArticleRoute($this->item->slug, $this->item->catid, $this->item->language))); + $link = new Uri(Route::_('index.php?option=com_users&view=login', false)); + $uri = new Uri(ContentHelperRoute::getArticleRoute($this->item->slug, $this->item->catid, $this->item->language)); + $router = Factory::getApplication()->getRouter(); + $router->buildComponentPreprocess($router, $uri); + $link->setVar('return', base64_encode($uri->toString())); endif; ?> $this->item, 'params' => $params, 'link' => $link)); ?> diff --git a/components/com_users/Controller/UserController.php b/components/com_users/Controller/UserController.php index 643a92f61d39f..45f2c6d2cb52d 100644 --- a/components/com_users/Controller/UserController.php +++ b/components/com_users/Controller/UserController.php @@ -101,7 +101,13 @@ public function login() // Set the return URL if empty. if (empty($data['return'])) { - $data['return'] = 'index.php?option=com_users&view=profile'; + $uri = new Uri('index.php?option=com_users&view=profile'); + $router = Factory::getApplication()->getRouter(); + + // Add Itemid to link + $router->buildComponentPreprocess($router, $uri); + + $data['return'] = $uri->toString(); } // Set the return URL in the user state to allow modification by plugins diff --git a/components/com_users/tmpl/login/default_login.php b/components/com_users/tmpl/login/default_login.php index c63b7ea8d76c7..1dfc193cab4fb 100644 --- a/components/com_users/tmpl/login/default_login.php +++ b/components/com_users/tmpl/login/default_login.php @@ -46,7 +46,7 @@ -

+
form->getFieldset('credentials') as $field) : ?> @@ -95,6 +95,7 @@ form->getValue('return', '', $this->params->get('login_redirect_url', $this->params->get('login_redirect_menuitem'))); ?> +
diff --git a/components/com_users/tmpl/login/default_logout.php b/components/com_users/tmpl/login/default_logout.php index c07e5ce3615bc..b93750e759334 100644 --- a/components/com_users/tmpl/login/default_logout.php +++ b/components/com_users/tmpl/login/default_logout.php @@ -39,7 +39,7 @@ - +
+ params->get('logout_redirect_url')) : ?> diff --git a/components/com_users/tmpl/profile/default.php b/components/com_users/tmpl/profile/default.php index 67e6ca96fc5a0..344fd5058e980 100644 --- a/components/com_users/tmpl/profile/default.php +++ b/components/com_users/tmpl/profile/default.php @@ -26,7 +26,7 @@ id == $this->data->id) : ?>
- diff --git a/plugins/system/languagefilter/languagefilter.php b/plugins/system/languagefilter/languagefilter.php index 5abeba991c16e..5c2009301d5de 100644 --- a/plugins/system/languagefilter/languagefilter.php +++ b/plugins/system/languagefilter/languagefilter.php @@ -628,20 +628,14 @@ public function onUserAfterSave($user, $isnew, $success, $msg) */ public function onUserLogin($user, $options = array()) { - $menu = $this->app->getMenu(); - if ($this->app->isClient('site')) { if ($this->params->get('automatic_change', 1)) { - $assoc = Associations::isEnabled(); $lang_code = $user['language']; // If no language is specified for this user, we set it to the site default language - if (empty($lang_code)) - { - $lang_code = $this->default_lang; - } + $lang_code = $lang_code ?? $this->default_lang; // The language has been deleted/disabled or the related content language does not exist/has been unpublished // or the related home page does not exist/has been unpublished @@ -652,85 +646,83 @@ public function onUserLogin($user, $options = array()) $lang_code = $this->current_lang; } - // Try to get association from the current active menu item - $active = $menu->getActive(); + if ($lang_code === $this->current_lang) + { + // The current page language is equal to user language + return; + } + + $menu = $this->app->getMenu(); + + $loginMenuItem = $menu->getActive(); $foundAssociation = false; /** * Looking for associations. * If the login menu item form contains an internal URL redirection, - * This will override the automatic change to the user preferred site language. + * this will override the automatic change to the user preferred site language. * In that case we use the redirect as defined in the menu item. - * Otherwise we redirect, when available, to the user preferred site language. + * Otherwise we redirect, when available, to the user preferred site language. */ - if ($active && !$active->params['login_redirect_url']) + if (!$loginMenuItem || !$loginMenuItem->params['login_redirect_url']) { - if ($assoc) + $return = $this->app->getUserState('users.login.form.return'); + + if ($return) { - $associations = MenusHelper::getAssociations($active->id); - } + // Retrieves the Itemid from a login form + $uri = new Uri($this->app->getUserState('users.login.form.return')); - // Retrieves the Itemid from a login form. - $uri = new Uri($this->app->getUserState('users.login.form.return')); + $Itemid = $uri->getVar('Itemid'); + } - if ($uri->getVar('Itemid')) + if ($Itemid) { - // The login form contains a menu item redirection. Try to get associations from that menu item. - // If any association set to the user preferred site language, redirect to that page. - if ($assoc) + if (Associations::isEnabled()) { - $associations = MenusHelper::getAssociations($uri->getVar('Itemid')); + // The login form contains a menu item redirection. Try to get associations from that menu item. + $assocs = MenusHelper::getAssociations($Itemid); + + // If any association set to the user preferred site language, redirect to that page. + if (isset($assocs[$lang_code]) && $menu->getItem($assocs[$lang_code])) + { + $this->app->setUserState('users.login.form.return', 'index.php?Itemid=' . $assocs[$lang_code]); + $foundAssociation = true; + } } - if (isset($associations[$lang_code]) && $menu->getItem($associations[$lang_code])) + // If there is no association + if (!$foundAssociation) { - $associationItemid = $associations[$lang_code]; - $this->app->setUserState('users.login.form.return', 'index.php?Itemid=' . $associationItemid); - $foundAssociation = true; + $returnItem = $menu->getItem($Itemid); + + // If the return URL points to the homepage + if ($returnItem && $returnItem->home) + { + // We are on a Home page, we redirect to the user preferred site language Home page. + $item = $menu->getDefault($lang_code); + + if ($item && $item->language !== $returnItem->language && $item->language !== '*') + { + $this->app->setUserState('users.login.form.return', 'index.php?Itemid=' . $item->id); + $foundAssociation = true; + } + } } - } - elseif (isset($associations[$lang_code]) && $menu->getItem($associations[$lang_code])) - { - /** - * The login form does not contain a menu item redirection. - * The active menu item has associations. - * We redirect to the user preferred site language associated page. - */ - $associationItemid = $associations[$lang_code]; - $this->app->setUserState('users.login.form.return', 'index.php?Itemid=' . $associationItemid); - $foundAssociation = true; - } - elseif ($active->home) - { - // We are on a Home page, we redirect to the user preferred site language Home page. - $item = $menu->getDefault($lang_code); - if ($item && $item->language !== $active->language && $item->language !== '*') + if ($foundAssociation) { - $this->app->setUserState('users.login.form.return', 'index.php?Itemid=' . $item->id); - $foundAssociation = true; - } - } - } + // Change language. + $this->current_lang = $lang_code; - if ($foundAssociation && $lang_code !== $this->current_lang) - { - // Change language. - $this->current_lang = $lang_code; - - // Create a cookie. - $this->setLanguageCookie($lang_code); + // Create a cookie. + $this->setLanguageCookie($lang_code); - // Change the language code. - Factory::getLanguage()->setLanguage($lang_code); - } - } - else - { - if ($this->app->getUserState('users.login.form.return')) - { - $this->app->setUserState('users.login.form.return', Route::_($this->app->getUserState('users.login.form.return'), false)); + // Change the language code. + Factory::getLanguage()->setLanguage($lang_code); + } + } } } } diff --git a/templates/cassiopeia/index.php b/templates/cassiopeia/index.php index 220b079fc9149..c8eda1eda09c7 100644 --- a/templates/cassiopeia/index.php +++ b/templates/cassiopeia/index.php @@ -28,7 +28,7 @@ $itemid = $app->input->getCmd('Itemid', ''); $sitename = $app->get('sitename'); $menu = $app->getMenu()->getActive(); -$pageclass = $menu->params->get('pageclass_sfx'); +$pageclass = $menu !== null ? $menu->params->get('pageclass_sfx') : null; // Enable assets $wa->enableAsset('template.cassiopeia.' . ($this->direction === 'rtl' ? 'rtl' : 'ltr')); diff --git a/templates/cassiopeia/offline.php b/templates/cassiopeia/offline.php index 1de1ee9c75c37..80267ce36e22d 100644 --- a/templates/cassiopeia/offline.php +++ b/templates/cassiopeia/offline.php @@ -93,7 +93,7 @@
- +
@@ -108,9 +108,10 @@ - - + + setQuery($app->getRouter()->getVars()); ?> +
diff --git a/templates/system/offline.php b/templates/system/offline.php index e5a47e473b2ee..27af45e6e4a84 100644 --- a/templates/system/offline.php +++ b/templates/system/offline.php @@ -9,6 +9,8 @@ defined('_JEXEC') or die; +use Joomla\CMS\Uri\Uri; + /** @var JDocumentHtml $this */ $app = JFactory::getApplication(); @@ -52,7 +54,7 @@

-
+

@@ -71,9 +73,10 @@

- - + + setQuery($app->getRouter()->getVars()); ?> +