user-answers.php 3.21 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 user page showing all user's answers


	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
require_once QA_INCLUDE_DIR . 'db/selects.php';
require_once QA_INCLUDE_DIR . 'app/format.php';
Scott committed
29 30


31
// $handle, $userhtml are already set by /qa-include/page/user.php - also $userid if using external user integration
Scott committed
32

33
$start = qa_get_start();
Scott committed
34 35


Scott committed
36
// Find the questions for this user
Scott committed
37

38 39
$loginuserid = qa_get_logged_in_userid();
$identifier = QA_FINAL_EXTERNAL_USERS ? $userid : $handle;
Scott committed
40

41 42 43 44 45
list($useraccount, $userpoints, $questions) = qa_db_select_with_pending(
	QA_FINAL_EXTERNAL_USERS ? null : qa_db_user_account_selectspec($handle, false),
	qa_db_user_points_selectspec($identifier),
	qa_db_user_recent_a_qs_selectspec($loginuserid, $identifier, qa_opt_if_loaded('page_size_activity'), $start)
);
Scott committed
46

47 48
if (!QA_FINAL_EXTERNAL_USERS && !is_array($useraccount)) // check the user exists
	return include QA_INCLUDE_DIR . 'qa-page-not-found.php';
Scott committed
49 50


Scott committed
51
// Get information on user questions
Scott committed
52

53 54 55 56
$pagesize = qa_opt('page_size_activity');
$count = (int)@$userpoints['aposts'];
$questions = array_slice($questions, 0, $pagesize);
$usershtml = qa_userids_handles_html($questions, false);
Scott committed
57 58


Scott committed
59
// Prepare content for theme
Scott committed
60

61
$qa_content = qa_content_prepare(true);
Scott committed
62

63 64 65 66
if (count($questions))
	$qa_content['title'] = qa_lang_html_sub('profile/answers_by_x', $userhtml);
else
	$qa_content['title'] = qa_lang_html_sub('profile/no_answers_by_x', $userhtml);
Scott committed
67 68


Scott committed
69
// Recent questions by this user
Scott committed
70

71 72
$qa_content['q_list']['form'] = array(
	'tags' => 'method="post" action="' . qa_self_html() . '"',
Scott committed
73

74 75 76 77
	'hidden' => array(
		'code' => qa_get_form_security_code('vote'),
	),
);
Scott committed
78

79
$qa_content['q_list']['qs'] = array();
Scott committed
80

81 82 83 84 85
$htmldefaults = qa_post_html_defaults('Q');
$htmldefaults['whoview'] = false;
$htmldefaults['avatarsize'] = 0;
$htmldefaults['ovoteview'] = true;
$htmldefaults['answersview'] = false;
Scott committed
86

87 88 89
foreach ($questions as $question) {
	$options = qa_post_html_options($question, $htmldefaults);
	$options['voteview'] = qa_get_vote_view('A', false, false);
Scott committed
90

91 92 93
	$qa_content['q_list']['qs'][] = qa_other_to_q_html_fields($question, $loginuserid, qa_cookie_get(),
		$usershtml, null, $options);
}
Scott committed
94

95
$qa_content['page_links'] = qa_html_page_links(qa_request(), $start, $pagesize, $count, qa_opt('pages_prev_next'));
Scott committed
96 97


Scott committed
98
// Sub menu for navigation in user pages
Scott committed
99

100 101
$ismyuser = isset($loginuserid) && $loginuserid == (QA_FINAL_EXTERNAL_USERS ? $userid : $useraccount['userid']);
$qa_content['navigation']['sub'] = qa_user_sub_navigation($handle, 'answers', $ismyuser);
Scott committed
102 103


104
return $qa_content;