-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathmoderation.php
352 lines (299 loc) · 12 KB
/
moderation.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
<?php
////////////////////////////////////////////////////////////////////////////////
// //
// Copyright (C) 2016 Phorum Development Team //
// http://www.phorum.org //
// //
// This program is free software. You can redistribute it and/or modify //
// it under the terms of either the current Phorum License (viewable at //
// phorum.org) or the Phorum License that was distributed with this file //
// //
// 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. //
// //
// You should have received a copy of the Phorum License //
// along with this program. //
// //
////////////////////////////////////////////////////////////////////////////////
define('phorum_page','moderation');
require_once './common.php';
require_once PHORUM_PATH.'/include/api/thread.php';
require_once PHORUM_PATH.'/include/api/mail/message_notify.php';
// Check if the active user has read permission on the active forum.
if (!phorum_check_read_common()) {
return;
}
// CSRF protection: we do not accept posting to this script,
// when the browser does not include a Phorum signed token
// in the request.
phorum_api_request_check_token();
// Check if the active user has moderation permissions for the active forum.
$PHORUM["DATA"]["MODERATOR"] =
phorum_api_user_check_access(PHORUM_USER_ALLOW_MODERATE_MESSAGES);
// Retrieve the id of the thread or message on which to perform a
// moderation operation.
if (isset($_POST["thread"])) {
$msgthd_id = (int)$_POST["thread"];
} elseif(isset($PHORUM['args'][2])) {
$msgthd_id = (int)$PHORUM['args'][2];
} else {
$msgthd_id = 0;
}
// Retrieve the moderation step to perform.
if (isset($_POST["mod_step"])) {
$mod_step = (int)$_POST["mod_step"];
} elseif(isset($PHORUM['args'][1])) {
$mod_step = (int)$PHORUM['args'][1];
} else {
$mod_step = 0;
}
// When no thread or message id is provided or if the user isn't a moderator,
// then redirect the user back to the message list.
if (empty($msgthd_id) || !$PHORUM["DATA"]["MODERATOR"]) {
phorum_api_redirect(phorum_moderation_back_url());
}
// If the user is not fully logged in, send him to the login page.
// because moderation actions can vary so much, the only safe bet is to send
// them to the referrer if they are not fully logged in
if (!$PHORUM["DATA"]["FULLY_LOGGEDIN"]) {
phorum_api_redirect(
PHORUM_LOGIN_URL, "redir=".urlencode($_SERVER["HTTP_REFERER"]));
}
// If we gave the user a confirmation form and he clicked "No", send him back.
if (isset($_POST["confirmation"]) && empty($_POST["confirmation_yes"])) {
phorum_api_redirect(phorum_moderation_back_url());
}
// The user cancelled the moderation action.
if (isset($_POST['cancel'])) {
phorum_api_redirect(phorum_moderation_back_url());
}
// Build all our common URL's.
phorum_build_common_urls();
// The template to load at the end of this script.
$template = "message";
// Messages for which to invalidate the cache at the end of this script.
$invalidate_message_cache = array();
/*
* [hook]
* moderation
*
* [description]
* This hook can be used for logging moderator actions. You can
* use the <literal>$PHORUM</literal> array to retrieve additional info
* like the moderating user's id and similar.<sbr/>
* <sbr/>
* The moderation step id is the variable <literal>$mod_step</literal>
* that is used in <filename>moderation.php</filename>. Please read that
* script to see what moderation steps are available and for what moderation
* actions they stand.<sbr/>
* <sbr/>
* When checking the moderation step id for a certain step, always use
* the contstants that are defined for this in
* <filename>include/constants.php</filename>. The numerical value of this
* id can change between Phorum releases.
*
* [category]
* Moderation
*
* [when]
* At the start of <filename>moderation.php</filename>
*
* [input]
* The id of the moderation step which is run (read-only).
*
* [output]
* Same as input.
*
* [example]
* <hookcode>
* function phorum_mod_foo_moderation ($mod_step)
* {
* global $PHORUM;
*
* // Update the last timestamp for the moderation step
* $PHORUM["mod_foo"]["moderation_step_timestamps"][$mod_step] = time();
* $PHORUM['DB']->update_settings(array(
* "mod_foo" => $PHORUM["mod_foo"]
* ));
*
* return $mod_step;
* }
* </hookcode>
*/
if (isset($PHORUM["hooks"]["moderation"])) {
phorum_api_hook("moderation", $mod_step);
}
// Run the code for the requested moderation step.
switch ($mod_step)
{
case PHORUM_DELETE_MESSAGE: // this is a message delete
include PHORUM_PATH . '/include/moderation/delete_message.php';
break;
case PHORUM_DELETE_TREE: // this is a message delete
include PHORUM_PATH . '/include/moderation/delete_tree.php';
break;
case PHORUM_MOVE_THREAD: // this is the first step of a message move
include PHORUM_PATH . '/include/moderation/move_thread.php';
break;
case PHORUM_DO_THREAD_MOVE: // this is the last step of a message move
include PHORUM_PATH . '/include/moderation/do_thread_move.php';
break;
case PHORUM_CLOSE_THREAD: // we have to close a thread
include PHORUM_PATH . '/include/moderation/close_thread.php';
break;
case PHORUM_REOPEN_THREAD: // we have to reopen a thread
include PHORUM_PATH . '/include/moderation/reopen_thread.php';
break;
case PHORUM_APPROVE_MESSAGE: // approving a message
include PHORUM_PATH . '/include/moderation/approve_message.php';
break;
case PHORUM_APPROVE_MESSAGE_TREE: // approve a message and all replies to it
include PHORUM_PATH . '/include/moderation/approve_message_tree.php';
break;
case PHORUM_HIDE_POST: // hiding a message (and its replies)
include PHORUM_PATH . '/include/moderation/hide_post.php';
break;
case PHORUM_MERGE_THREAD: // this is the first step of a thread merge
include PHORUM_PATH . '/include/moderation/merge_thread.php';
break;
case PHORUM_DO_THREAD_MERGE: // this is the last step of a thread merge
include PHORUM_PATH . '/include/moderation/do_thread_merge.php';
break;
case PHORUM_SPLIT_THREAD: // this is the first step of a thread split
include PHORUM_PATH . '/include/moderation/split_thread.php';
break;
case PHORUM_DO_THREAD_SPLIT: // this is the last step of a thread split
include PHORUM_PATH . '/include/moderation/do_thread_split.php';
break;
case PHORUM_MAKE_STICKY: // make a thread sticky
include PHORUM_PATH . '/include/moderation/make_sticky.php';
break;
case PHORUM_MAKE_UNSTICKY: // make a thread unsticky
include PHORUM_PATH . '/include/moderation/make_unsticky.php';
break;
default:
phorum_api_redirect(phorum_moderation_back_url());
}
// Remove the affected messages from the cache if caching is enabled.
if ($PHORUM['cache_messages']) {
$invalidate_forums = array();
foreach($invalidate_message_cache as $message) {
phorum_api_cache_remove('message', $message['forum_id']."-".$message["message_id"]);
$invalidate_forums[$message['forum_id']]=$message['forum_id'];
}
if(is_array($invalidate_forums) && count($invalidate_forums)) {
// increment the cache version for all involved forums once
foreach($invalidate_forums as $forum_id) {
phorum_api_forums_increment_cache_version($forum_id);
}
}
}
if (!isset($PHORUM['DATA']['BACKMSG'])) {
$PHORUM['DATA']["BACKMSG"] = $PHORUM['DATA']["LANG"]["BacktoForum"];
}
phorum_api_output($template);
// ----------------------------------------------------------------------
// Functions
// ----------------------------------------------------------------------
/**
* Outputs a confirmation form.
*
* To maintain backwards compatibility with the templates,
* we generate a form in code and output it using stdblock.
*
* The function exits the script after displaying the form.
*
* @param string $message Message to display to users
* @param string $action The URI to post the form to
* @param array $args The hidden form values to be used in the form
* @return void
*
*/
function phorum_show_confirmation_form($message, $action, $args)
{
global $PHORUM;
ob_start();
?>
<div style="text-align: center;">
<strong><?php echo phorum_api_format_htmlspecialchars($message); ?></strong>
<br />
<br />
<form
action="<?php echo phorum_api_format_htmlspecialchars($action); ?>"
method="post">
<input type="hidden"
name="forum_id" value="<?php echo $PHORUM["forum_id"]; ?>" />
<input type="hidden" name="confirmation" value="1" />
<?php foreach ($args as $name => $value){ ?>
<input type="hidden"
name="<?php echo phorum_api_format_htmlspecialchars($name); ?>"
value="<?php echo phorum_api_format_htmlspecialchars($value); ?>" />
<?php } ?>
<?php echo $PHORUM["DATA"]["POST_VARS"]; ?>
<input type="submit"
name="confirmation_yes"
value="<?php echo $PHORUM["DATA"]["LANG"]["Yes"]; ?>" />
<input type="submit"
name="confirmation_no"
value="<?php echo $PHORUM["DATA"]["LANG"]["No"]; ?>" />
</form>
<br />
</div>
<?php
$PHORUM["DATA"]["BLOCK_CONTENT"] = ob_get_clean();
phorum_api_output("stdblock");
exit();
}
/**
* A utility function to determine a suitable URL to redirect back from
* the moderation code.
*
* @return string
*/
function phorum_moderation_back_url()
{
global $PHORUM;
// When the parameter "prepost" is available in the request, then
// the moderation action was initiated from the moderation interface
// in the user control center.
if (isset($_POST['prepost']) ||
isset($_GET['prepost']) ||
isset($PHORUM['args']['prepost']))
{
return phorum_api_url(
PHORUM_CONTROLCENTER_URL, "panel=" . PHORUM_CC_UNAPPROVED
);
}
// Find the id of the thread or message on which the moderation
// action has been performed.
if (isset($_POST["thread"])) {
$msgthd_id = (int)$_POST["thread"];
} elseif(isset($PHORUM['args'][2])) {
$msgthd_id = (int)$PHORUM['args'][2];
} else {
$msgthd_id = 0;
}
// If no id was found, then redirect back to the list page for
// the active forum or the index page if no active forum is available.
if (empty($msgthd_id))
{
if (empty($PHORUM["forum_id"])) {
return phorum_api_url(PHORUM_INDEX_URL);
} else {
return phorum_api_url(PHORUM_LIST_URL);
}
}
// Check if the message still exists. It might be gone after a
// moderation action. When the message no longer exists, redirect
// the user back to the list page for the active forum.
$message = $PHORUM['DB']->get_message($msgthd_id);
if (!$message) {
return phorum_api_url(PHORUM_LIST_URL);
}
// Redirect back to the message that we found.
return phorum_api_url(
PHORUM_READ_URL, $message['thread'], $message['message_id']
);
}
?>