qa-page-user-wall.php 5.18 KB
Newer Older
Gideon Greenspan committed
1
<?php
Scott Vivian committed
2

Gideon Greenspan committed
3 4 5 6 7
/*
	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-user-wall.php
	Version: See define()s at top of qa-include/qa-base.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.
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-messages.php';
Scott Vivian committed
34

Gideon Greenspan committed
35 36

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

Gideon Greenspan committed
38 39 40 41 42 43
	if (QA_FINAL_EXTERNAL_USERS)
		qa_fatal_error('User accounts are handled by external code');


//	$handle, $userhtml are already set by qa-page-user.php

Scott committed
44
	$start = qa_get_start();
Scott Vivian committed
45 46


Gideon Greenspan committed
47
//	Find the questions for this user
Scott Vivian committed
48

Scott committed
49
	list($useraccount, $usermessages) = qa_db_select_with_pending(
Gideon Greenspan committed
50 51 52
		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 Vivian committed
53

Gideon Greenspan committed
54 55 56 57 58 59
	if (!is_array($useraccount)) // check the user exists
		return include QA_INCLUDE_DIR.'qa-page-not-found.php';


//	Perform pagination

Scott committed
60 61 62
	$pagesize = qa_opt('page_size_wall');
	$count = $useraccount['wallposts'];
	$loginuserid = qa_get_logged_in_userid();
Scott Vivian committed
63

Scott committed
64 65
	$usermessages = array_slice($usermessages, 0, $pagesize);
	$usermessages = qa_wall_posts_add_rules($usermessages, $start);
Gideon Greenspan committed
66 67 68


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

Scott committed
70
	$errors = array();
Scott Vivian committed
71

Scott committed
72
	$wallposterrorhtml = qa_wall_error_html($loginuserid, $useraccount['userid'], $useraccount['flags']);
Scott Vivian committed
73

74
	foreach ($usermessages as $message) {
Gideon Greenspan committed
75 76
		if ($message['deleteable'] && qa_clicked('m'.$message['messageid'].'_dodelete')) {
			if (!qa_check_form_security_code('wall-'.$useraccount['handle'], qa_post_text('code')))
Scott committed
77
				$errors['page'] = qa_lang_html('misc/form_security_again');
Scott Vivian committed
78

Gideon Greenspan committed
79 80
			else {
				qa_wall_delete_post($loginuserid, qa_get_logged_in_handle(), qa_cookie_get(), $message);
Gideon Greenspan committed
81
				qa_redirect(qa_request(), $_GET);
Gideon Greenspan committed
82 83
			}
		}
84
	}
Gideon Greenspan committed
85 86

	if (qa_clicked('dowallpost')) {
Scott committed
87
		$inmessage = qa_post_text('message');
Scott Vivian committed
88

Gideon Greenspan committed
89
		if (!strlen($inmessage))
Scott committed
90
			$errors['message'] = qa_lang('profile/post_wall_empty');
Scott Vivian committed
91

Gideon Greenspan committed
92
		elseif (!qa_check_form_security_code('wall-'.$useraccount['handle'], qa_post_text('code')))
Scott committed
93
			$errors['message'] = qa_lang_html('misc/form_security_again');
Scott Vivian committed
94

Gideon Greenspan committed
95 96 97 98 99
		elseif (!$wallposterrorhtml) {
			qa_wall_add_post($loginuserid, qa_get_logged_in_handle(), qa_cookie_get(), $useraccount['userid'], $useraccount['handle'], $inmessage, '');
			qa_redirect(qa_request());
		}
	}
Gideon Greenspan committed
100

Scott Vivian committed
101

Gideon Greenspan committed
102
//	Prepare content for theme
Scott Vivian committed
103

Scott committed
104
	$qa_content = qa_content_prepare();
Scott Vivian committed
105

Scott committed
106 107
	$qa_content['title'] = qa_lang_html_sub('profile/wall_for_x', $userhtml);
	$qa_content['error'] = @$errors['page'];
Scott Vivian committed
108

Scott committed
109
	$qa_content['script_rel'][] = 'qa-content/qa-user.js?'.QA_VERSION;
Gideon Greenspan committed
110

Scott committed
111
	$qa_content['message_list'] = array(
Gideon Greenspan committed
112
		'tags' => 'id="wallmessages"',
Scott Vivian committed
113

Gideon Greenspan committed
114 115 116 117 118
		'form' => array(
			'tags' => 'name="wallpost" method="post" action="'.qa_self_html().'"',
			'style' => 'tall',
			'hidden' => array(
				'qa_click' => '', // for simulating clicks in Javascript
Gideon Greenspan committed
119 120 121
				'handle' => qa_html($useraccount['handle']),
				'start' => qa_html($start),
				'code' => qa_get_form_security_code('wall-'.$useraccount['handle']),
Gideon Greenspan committed
122 123
			),
		),
Scott Vivian committed
124

Gideon Greenspan committed
125 126
		'messages' => array(),
	);
Scott Vivian committed
127

128
	if ($start == 0) { // only allow posting on first page
Gideon Greenspan committed
129
		if ($wallposterrorhtml)
Scott committed
130
			$qa_content['message_list']['error'] = $wallposterrorhtml; // an error that means we are not allowed to post
Scott Vivian committed
131

Gideon Greenspan committed
132
		else {
Scott committed
133
			$qa_content['message_list']['form']['fields'] = array(
Gideon Greenspan committed
134 135 136 137 138 139 140
				'message' => array(
					'tags' => 'name="message" id="message"',
					'value' => qa_html(@$inmessage, false),
					'rows' => 2,
					'error' => qa_html(@$errors['message']),
				),
			);
Scott Vivian committed
141

Scott committed
142
			$qa_content['message_list']['form']['buttons'] = array(
Gideon Greenspan committed
143 144 145 146 147 148 149 150
				'post' => array(
					'tags' => 'name="dowallpost" onclick="return qa_submit_wall_post(this, false);"',
					'label' => qa_lang_html('profile/post_wall_button'),
				),
			);
		}
	}

Gideon Greenspan committed
151
	foreach ($usermessages as $message)
Scott committed
152
		$qa_content['message_list']['messages'][] = qa_wall_post_view($message);
Scott Vivian committed
153

Scott committed
154
	$qa_content['page_links'] = qa_html_page_links(qa_request(), $start, $pagesize, $count, qa_opt('pages_prev_next'));
Gideon Greenspan committed
155 156 157 158


//	Sub menu for navigation in user pages

159 160
	$ismyuser = isset($loginuserid) && $loginuserid == (QA_FINAL_EXTERNAL_USERS ? $userid : $useraccount['userid']);
	$qa_content['navigation']['sub'] = qa_user_sub_navigation($handle, 'wall', $ismyuser);
Gideon Greenspan committed
161 162 163 164 165 166 167 168


	return $qa_content;


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