|
29 | 29 | require_once QA_INCLUDE_DIR . 'app/q-list.php';
|
30 | 30 |
|
31 | 31 | $categoryslugs = qa_request_parts(1);
|
32 |
| -$countslugs = count($categoryslugs); |
| 32 | +$hasSlugs = !empty($categoryslugs); |
| 33 | +$sort = qa_get('sort'); |
| 34 | + |
| 35 | +if (!QA_ALLOW_UNINDEXED_QUERIES && $hasSlugs) { |
| 36 | + $getParams = $sort === null ? [] : ['sort' => $sort]; |
| 37 | + qa_redirect('questions', $getParams); |
| 38 | +} |
33 | 39 |
|
34 |
| -$sort = ($countslugs && !QA_ALLOW_UNINDEXED_QUERIES) ? null : qa_get('sort'); |
35 | 40 | $start = qa_get_start();
|
36 | 41 | $userid = qa_get_logged_in_userid();
|
37 | 42 |
|
38 |
| - |
39 | 43 | // Get list of questions, plus category information
|
40 | 44 |
|
41 | 45 | switch ($sort) {
|
|
63 | 67 | list($questions, $categories, $categoryid) = qa_db_select_with_pending(
|
64 | 68 | qa_db_qs_selectspec($userid, $selectsort, $start, $categoryslugs, null, false, false, qa_opt_if_loaded('page_size_qs')),
|
65 | 69 | qa_db_category_nav_selectspec($categoryslugs, false, false, true),
|
66 |
| - $countslugs ? qa_db_slugs_to_category_id_selectspec($categoryslugs) : null |
| 70 | + $hasSlugs ? qa_db_slugs_to_category_id_selectspec($categoryslugs) : null |
67 | 71 | );
|
68 | 72 |
|
69 |
| -if ($countslugs) { |
| 73 | +if ($hasSlugs) { |
70 | 74 | if (!isset($categoryid)) {
|
71 | 75 | return include QA_INCLUDE_DIR . 'qa-page-not-found.php';
|
72 | 76 | }
|
73 | 77 |
|
| 78 | + if ($categories[$categoryid]['backpath'] !== qa_db_slugs_to_backpath($categoryslugs)) { |
| 79 | + $expectedPathInUrl = implode('/', array_reverse(explode('/', $categories[$categoryid]['backpath']))); |
| 80 | + $getParams = $sort === null ? [] : ['sort' => $sort]; |
| 81 | + qa_redirect('questions/' . $expectedPathInUrl, $getParams); |
| 82 | + } |
| 83 | + |
74 | 84 | $categorytitlehtml = qa_html($categories[$categoryid]['title']);
|
75 | 85 | $nonetitle = qa_lang_html_sub('main/no_questions_in_x', $categorytitlehtml);
|
76 |
| - |
77 | 86 | } else {
|
78 | 87 | $nonetitle = qa_lang_html('main/no_questions_found');
|
79 | 88 | }
|
80 | 89 |
|
81 |
| - |
82 | 90 | $categorypathprefix = QA_ALLOW_UNINDEXED_QUERIES ? 'questions/' : null; // this default is applied if sorted not by recent
|
83 | 91 | $feedpathprefix = null;
|
84 | 92 | $linkparams = array('sort' => $sort);
|
85 | 93 |
|
86 | 94 | switch ($sort) {
|
87 | 95 | case 'hot':
|
88 |
| - $sometitle = $countslugs ? qa_lang_html_sub('main/hot_qs_in_x', $categorytitlehtml) : qa_lang_html('main/hot_qs_title'); |
| 96 | + $sometitle = $hasSlugs ? qa_lang_html_sub('main/hot_qs_in_x', $categorytitlehtml) : qa_lang_html('main/hot_qs_title'); |
89 | 97 | $feedpathprefix = qa_opt('feed_for_hot') ? 'hot' : null;
|
90 | 98 | break;
|
91 | 99 |
|
92 | 100 | case 'votes':
|
93 |
| - $sometitle = $countslugs ? qa_lang_html_sub('main/voted_qs_in_x', $categorytitlehtml) : qa_lang_html('main/voted_qs_title'); |
| 101 | + $sometitle = $hasSlugs ? qa_lang_html_sub('main/voted_qs_in_x', $categorytitlehtml) : qa_lang_html('main/voted_qs_title'); |
94 | 102 | break;
|
95 | 103 |
|
96 | 104 | case 'answers':
|
97 |
| - $sometitle = $countslugs ? qa_lang_html_sub('main/answered_qs_in_x', $categorytitlehtml) : qa_lang_html('main/answered_qs_title'); |
| 105 | + $sometitle = $hasSlugs ? qa_lang_html_sub('main/answered_qs_in_x', $categorytitlehtml) : qa_lang_html('main/answered_qs_title'); |
98 | 106 | break;
|
99 | 107 |
|
100 | 108 | case 'views':
|
101 |
| - $sometitle = $countslugs ? qa_lang_html_sub('main/viewed_qs_in_x', $categorytitlehtml) : qa_lang_html('main/viewed_qs_title'); |
| 109 | + $sometitle = $hasSlugs ? qa_lang_html_sub('main/viewed_qs_in_x', $categorytitlehtml) : qa_lang_html('main/viewed_qs_title'); |
102 | 110 | break;
|
103 | 111 |
|
104 | 112 | default:
|
105 | 113 | $linkparams = array();
|
106 |
| - $sometitle = $countslugs ? qa_lang_html_sub('main/recent_qs_in_x', $categorytitlehtml) : qa_lang_html('main/recent_qs_title'); |
107 |
| - $categorypathprefix = 'questions/'; |
| 114 | + $sometitle = $hasSlugs ? qa_lang_html_sub('main/recent_qs_in_x', $categorytitlehtml) : qa_lang_html('main/recent_qs_title'); |
108 | 115 | $feedpathprefix = qa_opt('feed_for_questions') ? 'questions' : null;
|
109 | 116 | break;
|
110 | 117 | }
|
111 | 118 |
|
112 |
| - |
113 | 119 | // Prepare and return content for theme
|
114 | 120 |
|
115 | 121 | $qa_content = qa_q_list_page_content(
|
116 | 122 | $questions, // questions
|
117 | 123 | qa_opt('page_size_qs'), // questions per page
|
118 | 124 | $start, // start offset
|
119 |
| - $countslugs ? $categories[$categoryid]['qcount'] : qa_opt('cache_qcount'), // total count |
| 125 | + $hasSlugs ? $categories[$categoryid]['qcount'] : qa_opt('cache_qcount'), // total count |
120 | 126 | $sometitle, // title if some questions
|
121 | 127 | $nonetitle, // title if no questions
|
122 | 128 | $categories, // categories for navigation
|
123 | 129 | $categoryid, // selected category id
|
124 | 130 | true, // show question counts in category navigation
|
125 | 131 | $categorypathprefix, // prefix for links in category navigation
|
126 | 132 | $feedpathprefix, // prefix for RSS feed paths
|
127 |
| - $countslugs ? qa_html_suggest_qs_tags(qa_using_tags()) : qa_html_suggest_ask($categoryid), // suggest what to do next |
| 133 | + $hasSlugs ? qa_html_suggest_qs_tags(qa_using_tags()) : qa_html_suggest_ask($categoryid), // suggest what to do next |
128 | 134 | $linkparams, // extra parameters for page links
|
129 | 135 | $linkparams // category nav params
|
130 | 136 | );
|
131 | 137 |
|
132 |
| -if (QA_ALLOW_UNINDEXED_QUERIES || !$countslugs) { |
| 138 | +if (QA_ALLOW_UNINDEXED_QUERIES || !$hasSlugs) { |
133 | 139 | $qa_content['navigation']['sub'] = qa_qs_sub_navigation($sort, $categoryslugs);
|
134 | 140 | }
|
135 | 141 |
|
136 |
| - |
137 | 142 | return $qa_content;
|
0 commit comments