Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert routing changes in 3.8.4 #19512

Merged
merged 4 commits into from
Feb 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion components/com_content/views/archive/tmpl/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
</h1>
</div>
<?php endif; ?>
<form id="adminForm" action="<?php echo JRoute::_('index.php?option=com_content&view=archive'); ?>" method="post" class="form-inline">
<form id="adminForm" action="<?php echo JRoute::_('index.php'); ?>" method="post" class="form-inline">
<fieldset class="filters">
<div class="filter-search">
<?php if ($this->params->get('filter_field') !== 'hide') : ?>
Expand All @@ -34,6 +34,8 @@
<?php echo $this->form->limitField; ?>

<button type="submit" class="btn btn-primary" style="vertical-align: top;"><?php echo JText::_('JGLOBAL_FILTER_BUTTON'); ?></button>
<input type="hidden" name="view" value="archive" />
<input type="hidden" name="option" value="com_content" />
<input type="hidden" name="limitstart" value="0" />
</div>
<br />
Expand Down
3 changes: 1 addition & 2 deletions components/com_users/views/login/tmpl/default_login.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<?php if (($this->params->get('logindescription_show') == 1 && str_replace(' ', '', $this->params->get('login_description')) != '') || $this->params->get('login_image') != '') : ?>
</div>
<?php endif; ?>
<form action="<?php echo JRoute::_('index.php?option=com_users&view=login'); ?>" method="post" class="form-validate form-horizontal well">
<form action="<?php echo JRoute::_('index.php?option=com_users&task=user.login'); ?>" method="post" class="form-validate form-horizontal well">
<fieldset>
<?php foreach ($this->form->getFieldset('credentials') as $field) : ?>
<?php if (!$field->hidden) : ?>
Expand Down Expand Up @@ -76,7 +76,6 @@
</button>
</div>
</div>
<input type="hidden" name="task" value="user.login" />
<?php $return = $this->form->getValue('return', '', $this->params->get('login_redirect_url', $this->params->get('login_redirect_menuitem'))); ?>
<input type="hidden" name="return" value="<?php echo base64_encode($return); ?>" />
<?php echo JHtml::_('form.token'); ?>
Expand Down
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
17 changes: 11 additions & 6 deletions libraries/src/Router/SiteRouter.php
Original file line number Diff line number Diff line change
Expand Up @@ -708,18 +708,23 @@ 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);
}

$itemid = $this->getVar('Itemid');

if ($itemid)
if ($itemid = $this->getVar('Itemid'))
{
$uri->setVar('Itemid', $itemid);
}
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
59 changes: 26 additions & 33 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 Down Expand Up @@ -624,56 +625,48 @@ public function onUserLogin($user, $options = array())
/**
* 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 ($active && !$active->params['login_redirect_url'])
{
if (JLanguageAssociations::isEnabled())
if ($assoc)
{
// Retrieves the Itemid from a login form.
$uri = new JUri($this->app->getUserState('users.login.form.return'));
$associations = MenusHelper::getAssociations($active->id);
}

$Itemid = $uri->getVar('Itemid');
// Retrieves the Itemid from a login form.
$uri = new JUri($this->app->getUserState('users.login.form.return'));

if (!$Itemid && $this->mode_sef)
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)
{
// Workaround to not use current active item id
$activeId = $this->app->input->get('Itemid');
$this->app->input->set('Itemid', null);

// Get Itemid from SEF or home page
$query = $this->app->getRouter()->parse($uri);
$Itemid = isset($query['Itemid']) ? $query['Itemid'] : null;

// Restore active item id
$this->app->input->set('Itemid', $activeId);
$associations = MenusHelper::getAssociations($uri->getVar('Itemid'));
}

if ($Itemid)
if (isset($associations[$lang_code]) && $menu->getItem($associations[$lang_code]))
{
// Assign the active item from previous page to check for home page below
$active = $menu->getItem($Itemid);

// The login form contains a menu item redirection. Try to get associations from that menu item.
$associations = MenusHelper::getAssociations($Itemid);
}
else
{
// Return URL does not have any Itemid
$active = null;
$associationItemid = $associations[$lang_code];
$this->app->setUserState('users.login.form.return', 'index.php?Itemid=' . $associationItemid);
$foundAssociation = true;
}
}

// If any association set to the user preferred site language, redirect to that page.
if (isset($associations[$lang_code]) && $menu->getItem($associations[$lang_code]))
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 && $active->home)
elseif ($active->home)
{
// We are on a Home page, we redirect to the user preferred site language Home page.
$item = $menu->getDefault($lang_code);
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
14 changes: 10 additions & 4 deletions tests/unit/suites/libraries/cms/router/JRouterSiteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1271,11 +1271,17 @@ public function casesCreateUri()
'preset' => array('Itemid' => '42'),
'expected' => 'index.php?var1=value1&Itemid=42'
),
// Check if a URL with no Itemid and no option, but with an option and a global Itemid available, which fits the option of the menu item gets the Itemid and option appended
// 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=value1',
'preset' => array('Itemid' => '42', 'option' => 'com_test'),
'expected' => 'index.php?var1=value1&option=com_test&Itemid=42'
'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