Commit 4078a0aa by Scott

Add function qa_get_canonical to auto-generate canonical URL

Also add canonical tag to question lists and tag pages.
parent f51af14b
......@@ -828,3 +828,26 @@ function qa_get_state()
global $qa_state;
return $qa_state;
}
/**
* Generate a canonical URL for the current request. Preserves certain GET parameters.
* @return string The full canonical URL.
*/
function qa_get_canonical()
{
$params = array();
// variable assignment intentional here
if (($start = qa_get_start()) > 0) {
$params['start'] = $start;
}
if ($sort = qa_get('sort')) {
$params['sort'] = $sort;
}
if ($by = qa_get('by')) {
$params['by'] = $by;
}
return qa_path_html(qa_request(), $params, qa_opt('site_url'));
}
......@@ -124,6 +124,8 @@ function qa_q_list_page_content($questions, $pagesize, $start, $count, $sometitl
$qa_content['page_links'] = qa_html_page_links(qa_request(), $start, $pagesize, $count, qa_opt('pages_prev_next'), $pagelinkparams);
}
$qa_content['canonical'] = qa_get_canonical();
if (empty($qa_content['page_links'])) {
$qa_content['suggest_next'] = $suggest;
}
......
......@@ -79,6 +79,8 @@ foreach ($questions as $postid => $question) {
qa_post_html_fields($question, $userid, qa_cookie_get(), $usershtml, null, qa_post_html_options($question));
}
$qa_content['canonical'] = qa_get_canonical();
$qa_content['page_links'] = qa_html_page_links(qa_request(), $start, $pagesize, $tagword['tagcount'], qa_opt('pages_prev_next'));
if (empty($qa_content['page_links']))
......
......@@ -70,6 +70,8 @@ if (count($populartags)) {
} else
$qa_content['title'] = qa_lang_html('main/no_tags_found');
$qa_content['canonical'] = qa_get_canonical();
$qa_content['page_links'] = qa_html_page_links(qa_request(), $start, $pagesize, $tagcount, qa_opt('pages_prev_next'));
if (empty($qa_content['page_links']))
......
......@@ -83,8 +83,7 @@ if (!empty($users)) {
$qa_content['title'] = qa_lang_html('main/no_active_users');
}
// set the canonical url based on possible pagination
$qa_content['canonical'] = qa_path_html(qa_request(), ($start > 0 ? array('start' => $start) : null), qa_opt('site_url'));
$qa_content['canonical'] = qa_get_canonical();
$qa_content['page_links'] = qa_html_page_links(qa_request(), $start, $pageSize, $userCount, qa_opt('pages_prev_next'));
......
......@@ -74,9 +74,7 @@ if (count($users)) {
$qa_content['title'] = qa_lang_html('main/no_active_users');
}
// set the canonical url based on possible pagination
$qa_content['canonical'] = qa_path_html(qa_request(), ($start > 0 ? array('start' => $start) : null), qa_opt('site_url'));
$qa_content['canonical'] = qa_get_canonical();
$qa_content['page_links'] = qa_html_page_links(qa_request(), $start, $pagesize, $usercount, qa_opt('pages_prev_next'));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment