Skip to content

Commit

Permalink
some logic fixes
Browse files Browse the repository at this point in the history
- strips trailing slash
- checks if query string exists
  • Loading branch information
slylth committed Jan 2, 2014
1 parent 193b3c7 commit e02cc48
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
13 changes: 11 additions & 2 deletions reason_4.0/lib/core/classes/canonicalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,17 @@ public function get_canonical_url()
// logic goes here
if ($this->num_canonical_mods == 1) //follow left side of pdf
{
// echo $canonical_module->get_canonical_url();
return $canonical_module->get_canonical_url();
$canonical_url = $canonical_module->get_canonical_url();
if ($canonical_url == get_current_url())
{
return;
}
else
{
$canonical_url = trim_slashes($canonical_url);
return $canonical_url;
}
// return $canonical_module->get_canonical_url();
// return '/foo/bar/';
}
else //follow right side
Expand Down
18 changes: 14 additions & 4 deletions reason_4.0/lib/core/minisite_templates/modules/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,14 @@ function get_canonical_url()

if (!empty($non_cans_array))
{
parse_str($parsed_url['query'], $qs_arrray);
if (array_key_exists('query', $parsed_url))
{
parse_str($parsed_url['query'], $qs_arrray);
}
else
{
$qs_arrray = array();
}
$canonicalized_qs = array_diff_key($qs_arrray, $non_cans_array);
$canonicalized_qs = http_build_query($canonicalized_qs);
$canonicalized_url = $parsed_url['scheme'];
Expand All @@ -575,9 +582,12 @@ function get_canonical_url()
{
$canonicalized_url .= $parsed_url['port'];
}
$canonicalized_url .= $parsed_url['path'];
$canonicalized_url .= '?';
$canonicalized_url .= $canonicalized_qs;
$canonicalized_url .= $parsed_url['path'];
if (!empty($canonicalized_qs))
{
$canonicalized_url .= '?';
$canonicalized_url .= $canonicalized_qs;
}
}
else
{
Expand Down

0 comments on commit e02cc48

Please sign in to comment.