updates.php 3.06 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 updates for a user


	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
*/

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

Scott committed
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


Scott committed
32
// Check that we're logged in
Scott committed
33

Scott committed
34
$userid = qa_get_logged_in_userid();
Scott committed
35

Scott committed
36 37
if (!isset($userid))
	qa_redirect('login');
Scott committed
38 39


Scott committed
40
// Find out which updates to show
Scott committed
41

Scott committed
42 43
$forfavorites = qa_get('show') != 'content';
$forcontent = qa_get('show') != 'favorites';
Scott committed
44 45


Scott committed
46
// Get lists of recent updates for this user
Scott committed
47

Scott committed
48 49 50
$questions = qa_db_select_with_pending(
	qa_db_user_updates_selectspec($userid, $forfavorites, $forcontent)
);
Scott committed
51

Scott committed
52 53 54 55
if ($forfavorites) {
	if ($forcontent) {
		$sometitle = qa_lang_html('misc/recent_updates_title');
		$nonetitle = qa_lang_html('misc/no_recent_updates');
Scott committed
56 57

	} else {
Scott committed
58 59
		$sometitle = qa_lang_html('misc/recent_updates_favorites');
		$nonetitle = qa_lang_html('misc/no_updates_favorites');
Scott committed
60 61
	}

Scott committed
62 63 64 65
} else {
	$sometitle = qa_lang_html('misc/recent_updates_content');
	$nonetitle = qa_lang_html('misc/no_updates_content');
}
Scott committed
66 67


Scott committed
68
// Prepare and return content for theme
Scott committed
69

Scott committed
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
$qa_content = qa_q_list_page_content(
	qa_any_sort_and_dedupe($questions),
	null, // questions per page
	0, // start offset
	null, // total count (null to hide page links)
	$sometitle, // title if some questions
	$nonetitle, // title if no questions
	null, // categories for navigation
	null, // selected category id
	null, // show question counts in category navigation
	null, // prefix for links in category navigation
	null, // prefix for RSS feed paths (null to hide)
	$forfavorites ? strtr(qa_lang_html('misc/suggest_update_favorites'), array(
		'^1' => '<a href="' . qa_path_html('favorites') . '">',
		'^2' => '</a>',
	)) : null // suggest what to do next
);

$qa_content['navigation']['sub'] = array(
	'all' => array(
		'label' => qa_lang_html('misc/nav_all_my_updates'),
		'url' => qa_path_html('updates'),
		'selected' => $forfavorites && $forcontent,
	),

	'favorites' => array(
		'label' => qa_lang_html('misc/nav_my_favorites'),
		'url' => qa_path_html('updates', array('show' => 'favorites')),
		'selected' => $forfavorites && !$forcontent,
	),

	'myposts' => array(
		'label' => qa_lang_html('misc/nav_my_content'),
		'url' => qa_path_html('updates', array('show' => 'content')),
		'selected' => $forcontent && !$forfavorites,
	),
);


return $qa_content;