user-wall.php 4.79 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 22
<?php
/*
	Question2Answer by Gideon Greenspan and contributors
	http://www.question2answer.org/

	File: qa-include/qa-page-user-wall.php
	Description: Controller for user page showing all user wall posts


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

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

28 29
require_once QA_INCLUDE_DIR . 'db/selects.php';
require_once QA_INCLUDE_DIR . 'app/messages.php';
Scott committed
30 31


Scott committed
32
// Check we're not using single-sign on integration, which doesn't allow walls
Scott committed
33

34 35
if (QA_FINAL_EXTERNAL_USERS)
	qa_fatal_error('User accounts are handled by external code');
Scott committed
36 37


Scott committed
38
// $handle, $userhtml are already set by qa-page-user.php
Scott committed
39

40
$start = qa_get_start();
Scott committed
41 42


Scott committed
43
// Find the questions for this user
Scott committed
44

45 46 47 48
list($useraccount, $usermessages) = qa_db_select_with_pending(
	qa_db_user_account_selectspec($handle, false),
	qa_db_recent_messages_selectspec(null, null, $handle, false, qa_opt_if_loaded('page_size_wall'), $start)
);
Scott committed
49

50 51
if (!is_array($useraccount)) // check the user exists
	return include QA_INCLUDE_DIR . 'qa-page-not-found.php';
Scott committed
52 53


Scott committed
54
// Perform pagination
Scott committed
55

56 57 58
$pagesize = qa_opt('page_size_wall');
$count = $useraccount['wallposts'];
$loginuserid = qa_get_logged_in_userid();
Scott committed
59

60 61
$usermessages = array_slice($usermessages, 0, $pagesize);
$usermessages = qa_wall_posts_add_rules($usermessages, $start);
Scott committed
62 63


Scott committed
64
// Process deleting or adding a wall post (similar but not identical code to qq-page-user-profile.php)
Scott committed
65

66
$errors = array();
Scott committed
67

68
$wallposterrorhtml = qa_wall_error_html($loginuserid, $useraccount['userid'], $useraccount['flags']);
Scott committed
69

70 71 72 73 74 75 76
foreach ($usermessages as $message) {
	if ($message['deleteable'] && qa_clicked('m' . $message['messageid'] . '_dodelete')) {
		if (!qa_check_form_security_code('wall-' . $useraccount['handle'], qa_post_text('code'))) {
			$errors['page'] = qa_lang_html('misc/form_security_again');
		} else {
			qa_wall_delete_post($loginuserid, qa_get_logged_in_handle(), qa_cookie_get(), $message);
			qa_redirect(qa_request(), $_GET);
Scott committed
77 78
		}
	}
79 80 81 82 83 84 85 86 87 88 89 90
}

if (qa_clicked('dowallpost')) {
	$inmessage = qa_post_text('message');

	if (!strlen($inmessage)) {
		$errors['message'] = qa_lang('profile/post_wall_empty');
	} elseif (!qa_check_form_security_code('wall-' . $useraccount['handle'], qa_post_text('code'))) {
		$errors['message'] = qa_lang_html('misc/form_security_again');
	} elseif (!$wallposterrorhtml) {
		qa_wall_add_post($loginuserid, qa_get_logged_in_handle(), qa_cookie_get(), $useraccount['userid'], $useraccount['handle'], $inmessage, '');
		qa_redirect(qa_request());
Scott committed
91
	}
92
}
Scott committed
93 94


Scott committed
95
// Prepare content for theme
Scott committed
96

97
$qa_content = qa_content_prepare();
Scott committed
98

99 100
$qa_content['title'] = qa_lang_html_sub('profile/wall_for_x', $userhtml);
$qa_content['error'] = @$errors['page'];
Scott committed
101

102 103
$qa_content['message_list'] = array(
	'tags' => 'id="wallmessages"',
Scott committed
104

105 106 107 108 109 110 111 112
	'form' => array(
		'tags' => 'name="wallpost" method="post" action="' . qa_self_html() . '"',
		'style' => 'tall',
		'hidden' => array(
			'qa_click' => '', // for simulating clicks in Javascript
			'handle' => qa_html($useraccount['handle']),
			'start' => qa_html($start),
			'code' => qa_get_form_security_code('wall-' . $useraccount['handle']),
Scott committed
113
		),
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
	),

	'messages' => array(),
);

if ($start == 0) { // only allow posting on first page
	if ($wallposterrorhtml) {
		$qa_content['message_list']['error'] = $wallposterrorhtml; // an error that means we are not allowed to post
	} else {
		$qa_content['message_list']['form']['fields'] = array(
			'message' => array(
				'tags' => 'name="message" id="message"',
				'value' => qa_html(@$inmessage, false),
				'rows' => 2,
				'error' => qa_html(@$errors['message']),
			),
		);
Scott committed
131

132 133 134 135 136 137
		$qa_content['message_list']['form']['buttons'] = array(
			'post' => array(
				'tags' => 'name="dowallpost" onclick="return qa_submit_wall_post(this, false);"',
				'label' => qa_lang_html('profile/post_wall_button'),
			),
		);
Scott committed
138
	}
139
}
Scott committed
140

141 142 143
foreach ($usermessages as $message) {
	$qa_content['message_list']['messages'][] = qa_wall_post_view($message);
}
Scott committed
144

145
$qa_content['page_links'] = qa_html_page_links(qa_request(), $start, $pagesize, $count, qa_opt('pages_prev_next'));
Scott committed
146 147


Scott committed
148
// Sub menu for navigation in user pages
Scott committed
149

150 151
$ismyuser = isset($loginuserid) && $loginuserid == (QA_FINAL_EXTERNAL_USERS ? $userid : $useraccount['userid']);
$qa_content['navigation']['sub'] = qa_user_sub_navigation($handle, 'wall', $ismyuser);
Scott committed
152 153


154
return $qa_content;