questions.php 4.24 KB
Newer Older
Scott committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
<?php
/*
	Question2Answer by Gideon Greenspan and contributors
	http://www.question2answer.org/

	Description: Controller for page listing recent questions


	This program is free software; you can redistribute it and/or
	modify it under the terms of the GNU General Public License
	as published by the Free Software Foundation; either version 2
	of the License, or (at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	More about this license: http://www.question2answer.org/license.php
*/

22
if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
23
	header('Location: ../../');
24 25
	exit;
}
Scott committed
26

27 28 29
require_once QA_INCLUDE_DIR . 'db/selects.php';
require_once QA_INCLUDE_DIR . 'app/format.php';
require_once QA_INCLUDE_DIR . 'app/q-list.php';
Scott committed
30

31 32
$categoryslugs = qa_request_parts(1);
$countslugs = count($categoryslugs);
Scott committed
33

34 35 36
$sort = ($countslugs && !QA_ALLOW_UNINDEXED_QUERIES) ? null : qa_get('sort');
$start = qa_get_start();
$userid = qa_get_logged_in_userid();
Scott committed
37 38


Scott committed
39
// Get list of questions, plus category information
Scott committed
40

41
switch ($sort) {
Félicie committed
42 43 44
	// case 'hot':
	// 	$selectsort = 'hotness';
	// 	break;
Scott committed
45

46 47 48
	case 'votes':
		$selectsort = 'netvotes';
		break;
Scott committed
49

50 51 52
	case 'answers':
		$selectsort = 'acount';
		break;
Scott committed
53

54 55 56
	case 'views':
		$selectsort = 'views';
		break;
Scott committed
57

58 59 60 61
	default:
		$selectsort = 'created';
		break;
}
Scott committed
62

63 64 65 66 67
list($questions, $categories, $categoryid) = qa_db_select_with_pending(
	qa_db_qs_selectspec($userid, $selectsort, $start, $categoryslugs, null, false, false, qa_opt_if_loaded('page_size_qs')),
	qa_db_category_nav_selectspec($categoryslugs, false, false, true),
	$countslugs ? qa_db_slugs_to_category_id_selectspec($categoryslugs) : null
);
Scott committed
68

69
if ($countslugs) {
Scott committed
70
	if (!isset($categoryid)) {
71
		return include QA_INCLUDE_DIR . 'qa-page-not-found.php';
Scott committed
72
	}
Scott committed
73

74 75
	$categorytitlehtml = qa_html($categories[$categoryid]['title']);
	$nonetitle = qa_lang_html_sub('main/no_questions_in_x', $categorytitlehtml);
Scott committed
76

77 78 79
} else {
	$nonetitle = qa_lang_html('main/no_questions_found');
}
Scott committed
80 81


82 83 84
$categorypathprefix = QA_ALLOW_UNINDEXED_QUERIES ? 'questions/' : null; // this default is applied if sorted not by recent
$feedpathprefix = null;
$linkparams = array('sort' => $sort);
Scott committed
85

86
switch ($sort) {
Félicie committed
87 88 89 90
	// case 'hot':
	// 	$sometitle = $countslugs ? qa_lang_html_sub('main/hot_qs_in_x', $categorytitlehtml) : qa_lang_html('main/hot_qs_title');
	// 	$feedpathprefix = qa_opt('feed_for_hot') ? 'hot' : null;
	// 	break;
Scott committed
91

92 93 94
	case 'votes':
		$sometitle = $countslugs ? qa_lang_html_sub('main/voted_qs_in_x', $categorytitlehtml) : qa_lang_html('main/voted_qs_title');
		break;
Scott committed
95

96 97 98
	case 'answers':
		$sometitle = $countslugs ? qa_lang_html_sub('main/answered_qs_in_x', $categorytitlehtml) : qa_lang_html('main/answered_qs_title');
		break;
Scott committed
99

100 101 102
	case 'views':
		$sometitle = $countslugs ? qa_lang_html_sub('main/viewed_qs_in_x', $categorytitlehtml) : qa_lang_html('main/viewed_qs_title');
		break;
Scott committed
103

104 105 106 107 108 109 110
	default:
		$linkparams = array();
		$sometitle = $countslugs ? qa_lang_html_sub('main/recent_qs_in_x', $categorytitlehtml) : qa_lang_html('main/recent_qs_title');
		$categorypathprefix = 'questions/';
		$feedpathprefix = qa_opt('feed_for_questions') ? 'questions' : null;
		break;
}
Scott committed
111 112


Scott committed
113
// Prepare and return content for theme
Scott committed
114

115 116 117 118 119 120 121 122 123 124 125 126
$qa_content = qa_q_list_page_content(
	$questions, // questions
	qa_opt('page_size_qs'), // questions per page
	$start, // start offset
	$countslugs ? $categories[$categoryid]['qcount'] : qa_opt('cache_qcount'), // total count
	$sometitle, // title if some questions
	$nonetitle, // title if no questions
	$categories, // categories for navigation
	$categoryid, // selected category id
	true, // show question counts in category navigation
	$categorypathprefix, // prefix for links in category navigation
	$feedpathprefix, // prefix for RSS feed paths
Félicie committed
127
	// $countslugs ? qa_html_suggest_qs_tags(qa_using_tags()) : qa_html_suggest_ask($categoryid), // suggest what to do next
128 129 130 131 132 133 134 135 136 137
	$linkparams, // extra parameters for page links
	$linkparams // category nav params
);

if (QA_ALLOW_UNINDEXED_QUERIES || !$countslugs) {
	$qa_content['navigation']['sub'] = qa_qs_sub_navigation($sort, $categoryslugs);
}


return $qa_content;