Skip to content

Commit

Permalink
Do not add unnecessary parameters in the archive link (#19447)
Browse files Browse the repository at this point in the history
* Do not add unnecessary parameters in the archive link

* Remove php notice

* Unset parameter month=0 when year is not set
  • Loading branch information
csthomas authored and Michael Babker committed Jan 27, 2018
1 parent fab5637 commit 0155f35
Showing 1 changed file with 40 additions and 22 deletions.
62 changes: 40 additions & 22 deletions components/com_content/helpers/legacyrouter.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,25 +225,34 @@ public function build(&$query, &$segments)
if (!$menuItemGiven)
{
$segments[] = $view;
unset($query['view']);
}

if (isset($query['year']))
unset($query['view']);

// If there is no year segment then do not add month segment
if (isset($query['year']) && $menuItemGiven)
{
if ($menuItemGiven)
if ($query['year'])
{
$segments[] = $query['year'];
unset($query['year']);

if (isset($query['month']))
{
if ($query['month'])
{
$segments[] = $query['month'];
}

unset($query['month']);
}
}

unset($query['year']);
}

if (isset($query['month']))
if (isset($query['month']) && empty($query['month']))
{
if ($menuItemGiven)
{
$segments[] = $query['month'];
unset($query['month']);
}
unset($query['month']);
}
}

Expand Down Expand Up @@ -320,14 +329,33 @@ public function parse(&$segments, &$vars)
* Standard routing for articles. If we don't pick up an Itemid then we get the view from the segments
* the first segment is the view and the last segment is the id of the article or category.
*/
if (!isset($item))
if ($item === null)
{
$vars['view'] = $segments[0];
$vars['id'] = $segments[$count - 1];

return;
}

// Manage the archive view
if ($item->query['view'] === 'archive')
{
$vars['view'] = 'archive';

if ($count >= 2)
{
$vars['year'] = $segments[$count - 2];
$vars['month'] = $segments[$count - 1];
}
else
{
$vars['year'] = $segments[$count - 1];
$vars['month'] = null;
}

return;
}

/*
* If there is only one segment, then it points to either an article or a category.
* We test it first to see if it is a category. If the id and alias match a category,
Expand Down Expand Up @@ -384,7 +412,7 @@ public function parse(&$segments, &$vars)
* because the first segment will have the target category id prepended to it. If the
* last segment has a number prepended, it is an article, otherwise, it is a category.
*/
if ((!$advanced) && ($item->query['view'] !== 'archive'))
if ((!$advanced))
{
$cat_id = (int) $segments[0];

Expand All @@ -405,16 +433,6 @@ public function parse(&$segments, &$vars)
return;
}

// Manage the archive view
if ($item->query['view'] == 'archive' && $count !== 1)
{
$vars['year'] = $count >= 2 ? $segments[$count - 2] : null;
$vars['month'] = $segments[$count - 1];
$vars['view'] = 'archive';

return;
}

// We get the category id from the menu item and search from there
$id = $item->query['id'];
$category = JCategories::getInstance('Content')->get($id);
Expand Down

0 comments on commit 0155f35

Please sign in to comment.