Skip to content

Commit

Permalink
canonicalization working for feature module
Browse files Browse the repository at this point in the history
moved most the work to the defaultMinisiteModule class
  • Loading branch information
slylth committed Dec 20, 2013
1 parent a7300a4 commit 193b3c7
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 14 deletions.
13 changes: 7 additions & 6 deletions reason_4.0/lib/core/classes/canonicalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,28 @@ public function register($module)
}
public function get_canonical_url()
{
$full_request_keys = array_keys($_GET);
foreach($this->modules as $key=>$module)
{
$this->data[$key]['non_canonical'] = $module->get_noncanonical_request_keys();
$this->data[$key]['all'] = array_keys($module->get_cleanup_rules());
$this->data[$key]['canonical'] = array_diff($non_canonical, $all);
if (!empty($this->data[$key]['canonical']))
// $this->data[$key]['canonical'] = array_diff($non_canonical, $all);
$this->data[$key]['canonical'] = array_diff($this->data[$key]['non_canonical'], $this->data[$key]['all']);
if (!empty($this->data[$key]['non_canonical']))
{
$num_canonical_mods++;
$this->num_canonical_mods++;
$canonical_module = $module;
}

}
// logic goes here
if ($num_canonical_mods == 1) //follow left side of pdf
if ($this->num_canonical_mods == 1) //follow left side of pdf
{
// echo $canonical_module->get_canonical_url();
return $canonical_module->get_canonical_url();
// return '/foo/bar/';
}
else //follow right side
{
$params_string = array();
$non_cans = $this->has_non_canonical_url_params(); // Any non-canonical QSPs?
if (!empty($non_cans))
{
Expand Down
2 changes: 1 addition & 1 deletion reason_4.0/lib/core/minisite_templates/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -853,7 +853,7 @@ function load_modules() // {{{
if($canonical_url = $canonicalizer->get_canonical_url())
{
// add link rel=canonical to the head items
$head_items->add_head_item('link',array('rel'=>'canonical','href'=>$canonical_url ), '');
$this->head_items->add_head_item('link',array('rel'=>'canonical','href'=>$canonical_url ), '');
}
}
} // }}}
Expand Down
44 changes: 39 additions & 5 deletions reason_4.0/lib/core/minisite_templates/modules/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,16 @@ class DefaultMinisiteModule
* @var array
*/
var $params;



/**
* noncanonical_request_keys with values as values
*
* ?????
*
*/
var $noncanonical_request_keys = array();

/**
* see if arguments have been parsed
* @var boolean
Expand Down Expand Up @@ -544,15 +553,40 @@ function get_cleanup_rules() // {{{
*/
function get_noncanonical_request_keys()
{
return array();
return $this->noncanonical_request_keys;
}
function get_canonical_url()
{
return NULL;
$canonicalized_url = NULL;
$non_cans_array = $this->get_noncanonical_request_keys();
$curr_url = get_current_url();
$parsed_url = parse_url($curr_url);
$non_cans_array = array_flip($non_cans_array);

if (!empty($non_cans_array))
{
parse_str($parsed_url['query'], $qs_arrray);
$canonicalized_qs = array_diff_key($qs_arrray, $non_cans_array);
$canonicalized_qs = http_build_query($canonicalized_qs);
$canonicalized_url = $parsed_url['scheme'];
$canonicalized_url .= '://';
$canonicalized_url .= $parsed_url['host'];
if (isset($parsed_url['port']))
{
$canonicalized_url .= $parsed_url['port'];
}
$canonicalized_url .= $parsed_url['path'];
$canonicalized_url .= '?';
$canonicalized_url .= $canonicalized_qs;
}
else
{
$canonicalized_url = $curr_url;
}
return $canonicalized_url;
}
/**
* the basic run function to display this module.
*
*
* this is called when the template is in non-editing mode
*/
function run() // {{{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class FeatureModule extends DefaultMinisiteModule
var $cleanup_rules = array('feature'=>'turn_into_int');
var $features_view_params;
var $current_feature_id = 0;
var $noncanonical_request_keys = array('feature');

private $_view;
private $_view_data;
Expand All @@ -76,8 +77,6 @@ function init( $args = array() )
$head_items =& $this->get_head_items();
$head_items->add_javascript(JQUERY_URL, true);

$canonical_url = get_current_url();
$head_items->add_head_item('link',array('rel'=>'canonical','href'=>$canonical_url ), '');
//create the view layer
$view = $this->get_view();
$view_data = $this->_view_data;
Expand Down

0 comments on commit 193b3c7

Please sign in to comment.