Skip to content

Commit b8e602b

Browse files
committed
Force redirect when input categories do not match stored categories in hot questions
1 parent 7d086f1 commit b8e602b

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

qa-include/pages/hot.php

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,45 +30,51 @@
3030

3131
// Get list of hottest questions, allow per-category if QA_ALLOW_UNINDEXED_QUERIES set in qa-config.php
3232

33-
$categoryslugs = QA_ALLOW_UNINDEXED_QUERIES ? qa_request_parts(1) : null;
34-
$countslugs = $categoryslugs === null ? null : count($categoryslugs);
33+
$categoryslugs = qa_request_parts(1);
34+
$hasSlugs = !empty($categoryslugs);
35+
if (!QA_ALLOW_UNINDEXED_QUERIES && $hasSlugs) {
36+
qa_redirect('hot');
37+
}
3538

3639
$start = qa_get_start();
3740
$userid = qa_get_logged_in_userid();
3841

3942
list($questions, $categories, $categoryid) = qa_db_select_with_pending(
4043
qa_db_qs_selectspec($userid, 'hotness', $start, $categoryslugs, null, false, false, qa_opt_if_loaded('page_size_hot_qs')),
4144
qa_db_category_nav_selectspec($categoryslugs, false, false, true),
42-
$countslugs ? qa_db_slugs_to_category_id_selectspec($categoryslugs) : null
45+
$hasSlugs ? qa_db_slugs_to_category_id_selectspec($categoryslugs) : null
4346
);
4447

45-
if ($countslugs) {
48+
if ($hasSlugs) {
4649
if (!isset($categoryid))
4750
return include QA_INCLUDE_DIR . 'qa-page-not-found.php';
4851

4952
$categorytitlehtml = qa_html($categories[$categoryid]['title']);
5053
$sometitle = qa_lang_html_sub('main/hot_qs_in_x', $categorytitlehtml);
5154
$nonetitle = qa_lang_html_sub('main/no_questions_in_x', $categorytitlehtml);
52-
5355
} else {
5456
$sometitle = qa_lang_html('main/hot_qs_title');
5557
$nonetitle = qa_lang_html('main/no_questions_found');
5658
}
5759

60+
if (isset($categoryid) && $categories[$categoryid]['backpath'] !== qa_db_slugs_to_backpath($categoryslugs)) {
61+
$expectedPathInUrl = implode('/', array_reverse(explode('/', $categories[$categoryid]['backpath'])));
62+
qa_redirect('hot/' . $expectedPathInUrl);
63+
}
5864

5965
// Prepare and return content for theme
6066

6167
return qa_q_list_page_content(
6268
$questions, // questions
6369
qa_opt('page_size_hot_qs'), // questions per page
6470
$start, // start offset
65-
$countslugs ? $categories[$categoryid]['qcount'] : qa_opt('cache_qcount'), // total count
71+
$hasSlugs ? $categories[$categoryid]['qcount'] : qa_opt('cache_qcount'), // total count
6672
$sometitle, // title if some questions
6773
$nonetitle, // title if no questions
68-
QA_ALLOW_UNINDEXED_QUERIES ? $categories : array(), // categories for navigation
74+
$categories, // categories for navigation
6975
$categoryid, // selected category id
7076
true, // show question counts in category navigation
71-
QA_ALLOW_UNINDEXED_QUERIES ? 'hot/' : null, // prefix for links in category navigation (null if no navigation)
77+
QA_ALLOW_UNINDEXED_QUERIES ? 'hot/' : null, // prefix for links in category navigation
7278
qa_opt('feed_for_hot') ? 'hot' : null, // prefix for RSS feed paths (null to hide)
7379
qa_html_suggest_ask() // suggest what to do next
7480
);

0 commit comments

Comments
 (0)