qa-page-hot.php 2.95 KB
Newer Older
Gideon Greenspan committed
1 2 3
<?php

/*
Gideon Greenspan committed
4
	Question2Answer by Gideon Greenspan and contributors
Gideon Greenspan committed
5 6 7

	http://www.question2answer.org/

Scott Vivian committed
8

Gideon Greenspan committed
9 10 11 12 13 14 15 16 17
	File: qa-include/qa-page-hot.php
	Version: See define()s at top of qa-include/qa-base.php
	Description: Controller for page listing hot 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.
Scott Vivian committed
18

Gideon Greenspan committed
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
	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
*/

	if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
		header('Location: ../');
		exit;
	}

	require_once QA_INCLUDE_DIR.'qa-db-selects.php';
	require_once QA_INCLUDE_DIR.'qa-app-q-list.php';
Scott Vivian committed
34

Gideon Greenspan committed
35 36

//	Get list of hottest questions, allow per-category if QA_ALLOW_UNINDEXED_QUERIES set in qa-config.php
Scott Vivian committed
37

Gideon Greenspan committed
38 39
	$categoryslugs=QA_ALLOW_UNINDEXED_QUERIES ? qa_request_parts(1) : null;
	$countslugs=@count($categoryslugs);
Scott Vivian committed
40

Gideon Greenspan committed
41 42
	$start=qa_get_start();
	$userid=qa_get_logged_in_userid();
Scott Vivian committed
43

Gideon Greenspan committed
44
	list($questions, $categories, $categoryid)=qa_db_select_with_pending(
Gideon Greenspan committed
45 46 47 48 49 50 51 52
		qa_db_qs_selectspec($userid, 'hotness', $start, $categoryslugs, null, false, false, qa_opt_if_loaded('page_size_hot_qs')),
		qa_db_category_nav_selectspec($categoryslugs, false, false, true),
		$countslugs ? qa_db_slugs_to_category_id_selectspec($categoryslugs) : null
	);

	if ($countslugs) {
		if (!isset($categoryid))
			return include QA_INCLUDE_DIR.'qa-page-not-found.php';
Scott Vivian committed
53

Gideon Greenspan committed
54 55 56 57 58 59 60 61
		$categorytitlehtml=qa_html($categories[$categoryid]['title']);
		$sometitle=qa_lang_html_sub('main/hot_qs_in_x', $categorytitlehtml);
		$nonetitle=qa_lang_html_sub('main/no_questions_in_x', $categorytitlehtml);

	} else {
		$sometitle=qa_lang_html('main/hot_qs_title');
		$nonetitle=qa_lang_html('main/no_questions_found');
	}
Scott Vivian committed
62

Gideon Greenspan committed
63 64 65 66 67 68 69 70 71 72 73 74

//	Prepare and return content for theme

	return qa_q_list_page_content(
		$questions, // questions
		qa_opt('page_size_hot_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
		QA_ALLOW_UNINDEXED_QUERIES ? $categories : null, // categories for navigation
		$categoryid, // selected category id
Gideon Greenspan committed
75 76
		true, // show question counts in category navigation
		QA_ALLOW_UNINDEXED_QUERIES ? 'hot/' : null, // prefix for links in category navigation (null if no navigation)
Gideon Greenspan committed
77 78 79
		qa_opt('feed_for_hot') ? 'hot' : null, // prefix for RSS feed paths (null to hide)
		qa_html_suggest_ask() // suggest what to do next
	);
Scott Vivian committed
80

Gideon Greenspan committed
81 82 83 84

/*
	Omit PHP closing tag to help avoid accidental output
*/