qa-page-updates.php 3.34 KB
Newer Older
Gideon Greenspan committed
1 2 3 4 5 6 7
<?php

/*
	Question2Answer (c) Gideon Greenspan

	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-updates.php
	Version: See define()s at top of qa-include/qa-base.php
	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.
Scott Vivian committed
18

Gideon Greenspan committed
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
	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-format.php';
	require_once QA_INCLUDE_DIR.'qa-app-q-list.php';
Scott Vivian committed
35

Gideon Greenspan committed
36 37

//	Check that we're logged in
Scott Vivian committed
38

Gideon Greenspan committed
39
	$userid=qa_get_logged_in_userid();
Scott Vivian committed
40

Gideon Greenspan committed
41 42
	if (!isset($userid))
		qa_redirect('login');
Scott Vivian committed
43

Gideon Greenspan committed
44 45 46 47 48 49 50 51 52 53 54 55

//	Find out which updates to show

	$forfavorites=qa_get('show')!='content';
	$forcontent=qa_get('show')!='favorites';


//	Get lists of recent updates for this user

	$questions=qa_db_select_with_pending(
		qa_db_user_updates_selectspec($userid, $forfavorites, $forcontent)
	);
Scott Vivian committed
56

Gideon Greenspan committed
57 58 59 60 61 62 63 64 65
	if ($forfavorites) {
		if ($forcontent) {
			$sometitle=qa_lang_html('misc/recent_updates_title');
			$nonetitle=qa_lang_html('misc/no_recent_updates');

		} else {
			$sometitle=qa_lang_html('misc/recent_updates_favorites');
			$nonetitle=qa_lang_html('misc/no_updates_favorites');
		}
Scott Vivian committed
66

Gideon Greenspan committed
67 68 69 70 71
	} else {
		$sometitle=qa_lang_html('misc/recent_updates_content');
		$nonetitle=qa_lang_html('misc/no_updates_content');
	}

Scott Vivian committed
72

Gideon Greenspan committed
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
//	Prepare and return content for theme

	$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(
Gideon Greenspan committed
88 89
			'^1' => '<a href="'.qa_path_html('favorites').'">',
			'^2' => '</a>',
Gideon Greenspan committed
90 91
		)) : null // suggest what to do next
	);
Scott Vivian committed
92

Gideon Greenspan committed
93 94 95 96 97 98
	$qa_content['navigation']['sub']=array(
		'all' => array(
			'label' => qa_lang_html('misc/nav_all_my_updates'),
			'url' => qa_path_html('updates'),
			'selected' => $forfavorites && $forcontent,
		),
Scott Vivian committed
99

Gideon Greenspan committed
100 101 102 103 104
		'favorites' => array(
			'label' => qa_lang_html('misc/nav_my_favorites'),
			'url' => qa_path_html('updates', array('show' => 'favorites')),
			'selected' => $forfavorites && !$forcontent,
		),
Scott Vivian committed
105

Gideon Greenspan committed
106 107 108 109 110 111
		'myposts' => array(
			'label' => qa_lang_html('misc/nav_my_content'),
			'url' => qa_path_html('updates', array('show' => 'content')),
			'selected' => $forcontent && !$forfavorites,
		),
	);
Scott Vivian committed
112 113


Gideon Greenspan committed
114 115 116 117 118 119
	return $qa_content;


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