Skip to content

Commit

Permalink
Revert "Do not add default or active Itemid to every link without own…
Browse files Browse the repository at this point in the history
… menu item (joomla#19099)"

This reverts commit d068868.
  • Loading branch information
Tomasz Narloch committed Jan 31, 2018
1 parent f2d4ae1 commit 335100c
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 50 deletions.
20 changes: 12 additions & 8 deletions libraries/src/Component/Router/Rules/MenuRules.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,16 +160,20 @@ public function preprocess(&$query)
}
}

// If there is no view and task in query then add the default item id
if (!isset($query['view']) && !isset($query['task']))
// Check if the active menuitem matches the requested language
if ($active && $active->component === 'com_' . $this->router->getName()
&& ($language === '*' || in_array($active->language, array('*', $language)) || !\JLanguageMultilang::isEnabled()))
{
// If not found, return language specific home link
$default = $this->router->menu->getDefault($language);
$query['Itemid'] = $active->id;
return;
}

if (!empty($default->id))
{
$query['Itemid'] = $default->id;
}
// If not found, return language specific home link
$default = $this->router->menu->getDefault($language);

if (!empty($default->id))
{
$query['Itemid'] = $default->id;
}
}

Expand Down
18 changes: 15 additions & 3 deletions libraries/src/Router/SiteRouter.php
Original file line number Diff line number Diff line change
Expand Up @@ -708,14 +708,26 @@ protected function createUri($url)

if ($itemid === null)
{
if (!$uri->getVar('option'))
if ($option = $uri->getVar('option'))
{
$option = $this->getVar('option');
$item = $this->menu->getItem($this->getVar('Itemid'));

if ($option)
if ($item !== null && $item->component === $option)
{
$uri->setVar('Itemid', $item->id);
}
}
else
{
if ($option = $this->getVar('option'))
{
$uri->setVar('option', $option);
}

if ($itemid = $this->getVar('Itemid'))
{
$uri->setVar('Itemid', $itemid);
}
}
}
else
Expand Down
4 changes: 3 additions & 1 deletion modules/mod_login/tmpl/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
JHtml::_('bootstrap.tooltip');

?>
<form action="<?php echo JRoute::_('index.php?option=com_users&task=user.login', true, $params->get('usesecure')); ?>" method="post" id="login-form" class="form-inline">
<form action="<?php echo JRoute::_('index.php', true, $params->get('usesecure')); ?>" method="post" id="login-form" class="form-inline">
<?php if ($params->get('pretext')) : ?>
<div class="pretext">
<p><?php echo $params->get('pretext'); ?></p>
Expand Down Expand Up @@ -111,6 +111,8 @@
<?php echo JText::_('MOD_LOGIN_FORGOT_YOUR_PASSWORD'); ?></a>
</li>
</ul>
<input type="hidden" name="option" value="com_users" />
<input type="hidden" name="task" value="user.login" />
<input type="hidden" name="return" value="<?php echo $return; ?>" />
<?php echo JHtml::_('form.token'); ?>
</div>
Expand Down
55 changes: 24 additions & 31 deletions plugins/system/languagefilter/languagefilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,7 @@ public function onUserLogin($user, $options = array())
{
if ($this->params->get('automatic_change', 1))
{
$assoc = JLanguageAssociations::isEnabled();
$lang_code = $user['language'];

// If no language is specified for this user, we set it to the site default language
Expand All @@ -616,53 +617,45 @@ public function onUserLogin($user, $options = array())
$lang_code = $this->current_lang;
}

$foundAssociation = false;

$assoc = JLanguageAssociations::isEnabled();

// If association is enabled
if ($assoc)
{
// Retrieves the Itemid from a login form.
$uri = new JUri($this->app->getUserState('users.login.form.return'));

// Get Itemid from SEF or home page
$query = $this->app::getRouter()->parse($uri);

// Check, if the login form contains a menu item redirection.
if (!empty($query['Itemid']))
{
// Try to get associations from that menu item.
$associations = MenusHelper::getAssociations($query['Itemid']);

// If any association set to the user preferred site language, redirect to that page.
if (isset($associations[$lang_code]) && $menu->getItem($associations[$lang_code]))
{
$associationItemid = $associations[$lang_code];
$this->app->setUserState('users.login.form.return', 'index.php?Itemid=' . $associationItemid);
$foundAssociation = true;
}
}
}

// Try to get association from the current active menu item
$active = $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.
* In that case we use the redirect as defined in the menu item.
* Otherwise we redirect, when available, to the user preferred site language.
*/
if (!$foundAssociation && $active && !$active->params['login_redirect_url'])
if ($active && !$active->params['login_redirect_url'])
{
if ($assoc)
{
$associations = MenusHelper::getAssociations($active->id);
}

if (isset($associations[$lang_code]) && $menu->getItem($associations[$lang_code]))
// Retrieves the Itemid from a login form.
$uri = new JUri($this->app->getUserState('users.login.form.return'));

if ($uri->getVar('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)
{
$associations = MenusHelper::getAssociations($uri->getVar('Itemid'));
}

if (isset($associations[$lang_code]) && $menu->getItem($associations[$lang_code]))
{
$associationItemid = $associations[$lang_code];
$this->app->setUserState('users.login.form.return', 'index.php?Itemid=' . $associationItemid);
$foundAssociation = true;
}
}
elseif (isset($associations[$lang_code]) && $menu->getItem($associations[$lang_code]))
{
/**
* The login form does not contain a menu item redirection.
Expand Down
4 changes: 3 additions & 1 deletion templates/beez3/html/mod_login/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

JHtml::_('behavior.keepalive');
?>
<form action="<?php echo JRoute::_('index.php?option=com_users&task=user.login', true, $params->get('usesecure')); ?>" method="post" id="login-form" >
<form action="<?php echo JRoute::_('index.php', true, $params->get('usesecure')); ?>" method="post" id="login-form" >
<?php if ($params->get('pretext')) : ?>
<div class="pretext">
<p><?php echo $params->get('pretext'); ?></p>
Expand Down Expand Up @@ -49,6 +49,8 @@
</p>
<?php endif; ?>
<input type="submit" name="Submit" class="button" value="<?php echo JText::_('JLOGIN') ?>" />
<input type="hidden" name="option" value="com_users" />
<input type="hidden" name="task" value="user.login" />
<input type="hidden" name="return" value="<?php echo $return; ?>" />
<?php echo JHtml::_('form.token'); ?>
<ul>
Expand Down
4 changes: 3 additions & 1 deletion templates/protostar/offline.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
<?php endif; ?>
</div>
<jdoc:include type="message" />
<form action="<?php echo JRoute::_('index.php?option=com_users&task=user.login'); ?>" method="post" id="form-login">
<form action="<?php echo JRoute::_('index.php', true); ?>" method="post" id="form-login">
<fieldset>
<label for="username"><?php echo JText::_('JGLOBAL_USERNAME'); ?></label>
<input name="username" id="username" type="text" title="<?php echo JText::_('JGLOBAL_USERNAME'); ?>" />
Expand All @@ -131,6 +131,8 @@

<input type="submit" name="Submit" class="btn btn-primary" value="<?php echo JText::_('JLOGIN'); ?>" />

<input type="hidden" name="option" value="com_users" />
<input type="hidden" name="task" value="user.login" />
<input type="hidden" name="return" value="<?php echo base64_encode(JUri::base()); ?>" />
<?php echo JHtml::_('form.token'); ?>
</fieldset>
Expand Down
4 changes: 3 additions & 1 deletion templates/system/offline.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
<?php echo JText::_('JOFFLINE_MESSAGE'); ?>
</p>
<?php endif; ?>
<form action="<?php echo JRoute::_('index.php?option=com_users&task=user.login'); ?>" method="post" id="form-login">
<form action="<?php echo JRoute::_('index.php', true); ?>" method="post" id="form-login">
<fieldset class="input">
<p id="form-login-username">
<label for="username"><?php echo JText::_('JGLOBAL_USERNAME'); ?></label>
Expand All @@ -77,6 +77,8 @@
<p id="submit-buton">
<input type="submit" name="Submit" class="button login" value="<?php echo JText::_('JLOGIN'); ?>" />
</p>
<input type="hidden" name="option" value="com_users" />
<input type="hidden" name="task" value="user.login" />
<input type="hidden" name="return" value="<?php echo base64_encode(JUri::base()); ?>" />
<?php echo JHtml::_('form.token'); ?>
</fieldset>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,13 @@ public function casesPreprocess()
$cases[] = array(array('option' => 'com_content', 'view' => 'article', 'id' => '42', 'catid' => '22', 'lang' => 'en-GB'),
array('option' => 'com_content', 'view' => 'article', 'id' => '42', 'catid' => '22', 'lang' => 'en-GB', 'Itemid' => '49'));

// Check non-existing menu link with a key
// Check non-existing menu link
$cases[] = array(array('option' => 'com_content', 'view' => 'categories', 'id' => '42'),
array('option' => 'com_content', 'view' => 'categories', 'id' => '42'));
array('option' => 'com_content', 'view' => 'categories', 'id' => '42', 'Itemid' => '49'));

// Check non-existing menu link with a key and language
// Check indirect link to a single view behind a nested view with a key and language
$cases[] = array(array('option' => 'com_content', 'view' => 'categories', 'id' => '42', 'lang' => 'en-GB'),
array('option' => 'com_content', 'view' => 'categories', 'id' => '42', 'lang' => 'en-GB'));
array('option' => 'com_content', 'view' => 'categories', 'id' => '42', 'lang' => 'en-GB', 'Itemid' => '49'));

// Check if a query with existing Itemid that is not the current active menu-item is not touched
$cases[] = array(array('option' => 'com_content', 'view' => 'categories', 'id' => '42', 'Itemid' => '99'),
Expand Down
18 changes: 18 additions & 0 deletions tests/unit/suites/libraries/cms/router/JRouterSiteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1265,6 +1265,24 @@ public function casesCreateUri()
'preset' => array('option' => 'com_test'),
'expected' => 'index.php?var1=value1&option=com_test'
),
// Check if a URL with no Itemid and no option, but globally set Itemid is added the Itemid
array(
'url' => 'index.php?var1=value1',
'preset' => array('Itemid' => '42'),
'expected' => 'index.php?var1=value1&Itemid=42'
),
// Check if a URL without an Itemid, but with an option set and a global Itemid available, which fits the option of the menu item gets the Itemid appended
array(
'url' => 'index.php?var1=value&option=com_test',
'preset' => array('Itemid' => '42'),
'expected' => 'index.php?var1=value&option=com_test&Itemid=42'
),
// Check if a URL without an Itemid, but with an option set and a global Itemid available, which does not fit the option of the menu item gets returned identically
array(
'url' => 'index.php?var1=value&option=com_test3',
'preset' => array('Itemid' => '42'),
'expected' => 'index.php?var1=value&option=com_test3'
),
);
}

Expand Down

0 comments on commit 335100c

Please sign in to comment.