Mercurial > hg > vamp-website
comparison forum/Sources/PostModeration.php @ 76:e3e11437ecea website
Add forum code
author | Chris Cannam |
---|---|
date | Sun, 07 Jul 2013 11:25:48 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
75:72f59aa7e503 | 76:e3e11437ecea |
---|---|
1 <?php | |
2 | |
3 /** | |
4 * Simple Machines Forum (SMF) | |
5 * | |
6 * @package SMF | |
7 * @author Simple Machines http://www.simplemachines.org | |
8 * @copyright 2011 Simple Machines | |
9 * @license http://www.simplemachines.org/about/smf/license.php BSD | |
10 * | |
11 * @version 2.0 | |
12 */ | |
13 | |
14 if (!defined('SMF')) | |
15 die('Hacking attempt...'); | |
16 | |
17 /* | |
18 //!!! | |
19 */ | |
20 | |
21 // This is a handling function for all things post moderation... | |
22 function PostModerationMain() | |
23 { | |
24 global $sourcedir; | |
25 | |
26 //!!! We'll shift these later bud. | |
27 loadLanguage('ModerationCenter'); | |
28 loadTemplate('ModerationCenter'); | |
29 | |
30 // Probably need this... | |
31 require_once($sourcedir . '/ModerationCenter.php'); | |
32 | |
33 // Allowed sub-actions, you know the drill by now! | |
34 $subactions = array( | |
35 'approve' => 'ApproveMessage', | |
36 'attachments' => 'UnapprovedAttachments', | |
37 'replies' => 'UnapprovedPosts', | |
38 'topics' => 'UnapprovedPosts', | |
39 ); | |
40 | |
41 // Pick something valid... | |
42 if (!isset($_REQUEST['sa']) || !isset($subactions[$_REQUEST['sa']])) | |
43 $_REQUEST['sa'] = 'replies'; | |
44 | |
45 $subactions[$_REQUEST['sa']](); | |
46 } | |
47 | |
48 // View all unapproved posts. | |
49 function UnapprovedPosts() | |
50 { | |
51 global $txt, $scripturl, $context, $user_info, $sourcedir, $smcFunc; | |
52 | |
53 $context['current_view'] = isset($_GET['sa']) && $_GET['sa'] == 'topics' ? 'topics' : 'replies'; | |
54 $context['page_title'] = $txt['mc_unapproved_posts']; | |
55 | |
56 // Work out what boards we can work in! | |
57 $approve_boards = boardsAllowedTo('approve_posts'); | |
58 | |
59 // If we filtered by board remove ones outside of this board. | |
60 //!!! Put a message saying we're filtered? | |
61 if (isset($_REQUEST['brd'])) | |
62 { | |
63 $filter_board = array((int) $_REQUEST['brd']); | |
64 $approve_boards = $approve_boards == array(0) ? $filter_board : array_intersect($approve_boards, $filter_board); | |
65 } | |
66 | |
67 if ($approve_boards == array(0)) | |
68 $approve_query = ''; | |
69 elseif (!empty($approve_boards)) | |
70 $approve_query = ' AND m.id_board IN (' . implode(',', $approve_boards) . ')'; | |
71 // Nada, zip, etc... | |
72 else | |
73 $approve_query = ' AND 0'; | |
74 | |
75 // We also need to know where we can delete topics and/or replies to. | |
76 if ($context['current_view'] == 'topics') | |
77 { | |
78 $delete_own_boards = boardsAllowedTo('remove_own'); | |
79 $delete_any_boards = boardsAllowedTo('remove_any'); | |
80 $delete_own_replies = array(); | |
81 } | |
82 else | |
83 { | |
84 $delete_own_boards = boardsAllowedTo('delete_own'); | |
85 $delete_any_boards = boardsAllowedTo('delete_any'); | |
86 $delete_own_replies = boardsAllowedTo('delete_own_replies'); | |
87 } | |
88 | |
89 $toAction = array(); | |
90 // Check if we have something to do? | |
91 if (isset($_GET['approve'])) | |
92 $toAction[] = (int) $_GET['approve']; | |
93 // Just a deletion? | |
94 elseif (isset($_GET['delete'])) | |
95 $toAction[] = (int) $_GET['delete']; | |
96 // Lots of approvals? | |
97 elseif (isset($_POST['item'])) | |
98 foreach ($_POST['item'] as $item) | |
99 $toAction[] = (int) $item; | |
100 | |
101 // What are we actually doing. | |
102 if (isset($_GET['approve']) || (isset($_POST['do']) && $_POST['do'] == 'approve')) | |
103 $curAction = 'approve'; | |
104 elseif (isset($_GET['delete']) || (isset($_POST['do']) && $_POST['do'] == 'delete')) | |
105 $curAction = 'delete'; | |
106 | |
107 // Right, so we have something to do? | |
108 if (!empty($toAction) && isset($curAction)) | |
109 { | |
110 checkSession('request'); | |
111 | |
112 // Handy shortcut. | |
113 $any_array = $curAction == 'approve' ? $approve_boards : $delete_any_boards; | |
114 | |
115 // Now for each message work out whether it's actually a topic, and what board it's on. | |
116 $request = $smcFunc['db_query']('', ' | |
117 SELECT m.id_msg, m.id_member, m.id_board, m.subject, t.id_topic, t.id_first_msg, t.id_member_started | |
118 FROM {db_prefix}messages AS m | |
119 INNER JOIN {db_prefix}topics AS t ON (t.id_topic = m.id_topic) | |
120 LEFT JOIN {db_prefix}boards AS b ON (t.id_board = b.id_board) | |
121 WHERE m.id_msg IN ({array_int:message_list}) | |
122 AND m.approved = {int:not_approved} | |
123 AND {query_see_board}', | |
124 array( | |
125 'message_list' => $toAction, | |
126 'not_approved' => 0, | |
127 ) | |
128 ); | |
129 $toAction = array(); | |
130 $details = array(); | |
131 while ($row = $smcFunc['db_fetch_assoc']($request)) | |
132 { | |
133 // If it's not within what our view is ignore it... | |
134 if (($row['id_msg'] == $row['id_first_msg'] && $context['current_view'] != 'topics') || ($row['id_msg'] != $row['id_first_msg'] && $context['current_view'] != 'replies')) | |
135 continue; | |
136 | |
137 $can_add = false; | |
138 // If we're approving this is simple. | |
139 if ($curAction == 'approve' && ($any_array == array(0) || in_array($row['id_board'], $any_array))) | |
140 { | |
141 $can_add = true; | |
142 } | |
143 // Delete requires more permission checks... | |
144 elseif ($curAction == 'delete') | |
145 { | |
146 // Own post is easy! | |
147 if ($row['id_member'] == $user_info['id'] && ($delete_own_boards == array(0) || in_array($row['id_board'], $delete_own_boards))) | |
148 $can_add = true; | |
149 // Is it a reply to their own topic? | |
150 elseif ($row['id_member'] == $row['id_member_started'] && $row['id_msg'] != $row['id_first_msg'] && ($delete_own_replies == array(0) || in_array($row['id_board'], $delete_own_replies))) | |
151 $can_add = true; | |
152 // Someone elses? | |
153 elseif ($row['id_member'] != $user_info['id'] && ($delete_any_boards == array(0) || in_array($row['id_board'], $delete_any_boards))) | |
154 $can_add = true; | |
155 } | |
156 | |
157 if ($can_add) | |
158 $anItem = $context['current_view'] == 'topics' ? $row['id_topic'] : $row['id_msg']; | |
159 $toAction[] = $anItem; | |
160 | |
161 // All clear. What have we got now, what, what? | |
162 $details[$anItem] = array(); | |
163 $details[$anItem]["subject"] = $row['subject']; | |
164 $details[$anItem]["topic"] = $row['id_topic']; | |
165 $details[$anItem]["member"] = ($context['current_view'] == 'topics') ? $row['id_member_started'] : $row['id_member']; | |
166 $details[$anItem]["board"] = $row['id_board']; | |
167 } | |
168 $smcFunc['db_free_result']($request); | |
169 | |
170 // If we have anything left we can actually do the approving (etc). | |
171 if (!empty($toAction)) | |
172 { | |
173 if ($curAction == 'approve') | |
174 { | |
175 approveMessages ($toAction, $details, $context['current_view']); | |
176 } | |
177 else | |
178 { | |
179 removeMessages ($toAction, $details, $context['current_view']); | |
180 } | |
181 } | |
182 } | |
183 | |
184 // How many unapproved posts are there? | |
185 $request = $smcFunc['db_query']('', ' | |
186 SELECT COUNT(*) | |
187 FROM {db_prefix}messages AS m | |
188 INNER JOIN {db_prefix}topics AS t ON (t.id_topic = m.id_topic AND t.id_first_msg != m.id_msg) | |
189 INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board) | |
190 WHERE m.approved = {int:not_approved} | |
191 AND {query_see_board} | |
192 ' . $approve_query, | |
193 array( | |
194 'not_approved' => 0, | |
195 ) | |
196 ); | |
197 list ($context['total_unapproved_posts']) = $smcFunc['db_fetch_row']($request); | |
198 $smcFunc['db_free_result']($request); | |
199 | |
200 // What about topics? Normally we'd use the table alias t for topics but lets use m so we don't have to redo our approve query. | |
201 $request = $smcFunc['db_query']('', ' | |
202 SELECT COUNT(m.id_topic) | |
203 FROM {db_prefix}topics AS m | |
204 INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board) | |
205 WHERE m.approved = {int:not_approved} | |
206 AND {query_see_board} | |
207 ' . $approve_query, | |
208 array( | |
209 'not_approved' => 0, | |
210 ) | |
211 ); | |
212 list ($context['total_unapproved_topics']) = $smcFunc['db_fetch_row']($request); | |
213 $smcFunc['db_free_result']($request); | |
214 | |
215 $context['page_index'] = constructPageIndex($scripturl . '?action=moderate;area=postmod;sa=' . $context['current_view'] . (isset($_REQUEST['brd']) ? ';brd=' . (int) $_REQUEST['brd'] : ''), $_GET['start'], $context['current_view'] == 'topics' ? $context['total_unapproved_topics'] : $context['total_unapproved_posts'], 10); | |
216 $context['start'] = $_GET['start']; | |
217 | |
218 // We have enough to make some pretty tabs! | |
219 $context[$context['moderation_menu_name']]['tab_data'] = array( | |
220 'title' => $txt['mc_unapproved_posts'], | |
221 'help' => 'postmod', | |
222 'description' => $txt['mc_unapproved_posts_desc'], | |
223 ); | |
224 | |
225 // Update the tabs with the correct number of posts. | |
226 $context['menu_data_' . $context['moderation_menu_id']]['sections']['posts']['areas']['postmod']['subsections']['posts']['label'] .= ' (' . $context['total_unapproved_posts'] . ')'; | |
227 $context['menu_data_' . $context['moderation_menu_id']]['sections']['posts']['areas']['postmod']['subsections']['topics']['label'] .= ' (' . $context['total_unapproved_topics'] . ')'; | |
228 | |
229 // If we are filtering some boards out then make sure to send that along with the links. | |
230 if (isset($_REQUEST['brd'])) | |
231 { | |
232 $context['menu_data_' . $context['moderation_menu_id']]['sections']['posts']['areas']['postmod']['subsections']['posts']['add_params'] = ';brd=' . (int) $_REQUEST['brd']; | |
233 $context['menu_data_' . $context['moderation_menu_id']]['sections']['posts']['areas']['postmod']['subsections']['topics']['add_params'] = ';brd=' . (int) $_REQUEST['brd']; | |
234 } | |
235 | |
236 // Get all unapproved posts. | |
237 $request = $smcFunc['db_query']('', ' | |
238 SELECT m.id_msg, m.id_topic, m.id_board, m.subject, m.body, m.id_member, | |
239 IFNULL(mem.real_name, m.poster_name) AS poster_name, m.poster_time, m.smileys_enabled, | |
240 t.id_member_started, t.id_first_msg, b.name AS board_name, c.id_cat, c.name AS cat_name | |
241 FROM {db_prefix}messages AS m | |
242 INNER JOIN {db_prefix}topics AS t ON (t.id_topic = m.id_topic) | |
243 INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board) | |
244 LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member) | |
245 LEFT JOIN {db_prefix}categories AS c ON (c.id_cat = b.id_cat) | |
246 WHERE m.approved = {int:not_approved} | |
247 AND t.id_first_msg ' . ($context['current_view'] == 'topics' ? '=' : '!=') . ' m.id_msg | |
248 AND {query_see_board} | |
249 ' . $approve_query . ' | |
250 LIMIT ' . $context['start'] . ', 10', | |
251 array( | |
252 'not_approved' => 0, | |
253 ) | |
254 ); | |
255 $context['unapproved_items'] = array(); | |
256 for ($i = 1; $row = $smcFunc['db_fetch_assoc']($request); $i++) | |
257 { | |
258 // Can delete is complicated, let's solve it first... is it their own post? | |
259 if ($row['id_member'] == $user_info['id'] && ($delete_own_boards == array(0) || in_array($row['id_board'], $delete_own_boards))) | |
260 $can_delete = true; | |
261 // Is it a reply to their own topic? | |
262 elseif ($row['id_member'] == $row['id_member_started'] && $row['id_msg'] != $row['id_first_msg'] && ($delete_own_replies == array(0) || in_array($row['id_board'], $delete_own_replies))) | |
263 $can_delete = true; | |
264 // Someone elses? | |
265 elseif ($row['id_member'] != $user_info['id'] && ($delete_any_boards == array(0) || in_array($row['id_board'], $delete_any_boards))) | |
266 $can_delete = true; | |
267 else | |
268 $can_delete = false; | |
269 | |
270 $context['unapproved_items'][] = array( | |
271 'id' => $row['id_msg'], | |
272 'alternate' => $i % 2, | |
273 'counter' => $context['start'] + $i, | |
274 'href' => $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . '#msg' . $row['id_msg'], | |
275 'subject' => $row['subject'], | |
276 'body' => parse_bbc($row['body'], $row['smileys_enabled'], $row['id_msg']), | |
277 'time' => timeformat($row['poster_time']), | |
278 'poster' => array( | |
279 'id' => $row['id_member'], | |
280 'name' => $row['poster_name'], | |
281 'link' => $row['id_member'] ? '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['poster_name'] . '</a>' : $row['poster_name'], | |
282 'href' => $scripturl . '?action=profile;u=' . $row['id_member'], | |
283 ), | |
284 'topic' => array( | |
285 'id' => $row['id_topic'], | |
286 ), | |
287 'board' => array( | |
288 'id' => $row['id_board'], | |
289 'name' => $row['board_name'], | |
290 ), | |
291 'category' => array( | |
292 'id' => $row['id_cat'], | |
293 'name' => $row['cat_name'], | |
294 ), | |
295 'can_delete' => $can_delete, | |
296 ); | |
297 } | |
298 $smcFunc['db_free_result']($request); | |
299 | |
300 $context['sub_template'] = 'unapproved_posts'; | |
301 } | |
302 | |
303 // View all unapproved attachments. | |
304 function UnapprovedAttachments() | |
305 { | |
306 global $txt, $scripturl, $context, $user_info, $sourcedir, $smcFunc; | |
307 | |
308 $context['page_title'] = $txt['mc_unapproved_attachments']; | |
309 | |
310 // Once again, permissions are king! | |
311 $approve_boards = boardsAllowedTo('approve_posts'); | |
312 | |
313 if ($approve_boards == array(0)) | |
314 $approve_query = ''; | |
315 elseif (!empty($approve_boards)) | |
316 $approve_query = ' AND m.id_board IN (' . implode(',', $approve_boards) . ')'; | |
317 else | |
318 $approve_query = ' AND 0'; | |
319 | |
320 // Get together the array of things to act on, if any. | |
321 $attachments = array(); | |
322 if (isset($_GET['approve'])) | |
323 $attachments[] = (int) $_GET['approve']; | |
324 elseif (isset($_GET['delete'])) | |
325 $attachments[] = (int) $_GET['delete']; | |
326 elseif (isset($_POST['item'])) | |
327 foreach ($_POST['item'] as $item) | |
328 $attachments[] = (int) $item; | |
329 | |
330 // Are we approving or deleting? | |
331 if (isset($_GET['approve']) || (isset($_POST['do']) && $_POST['do'] == 'approve')) | |
332 $curAction = 'approve'; | |
333 elseif (isset($_GET['delete']) || (isset($_POST['do']) && $_POST['do'] == 'delete')) | |
334 $curAction = 'delete'; | |
335 | |
336 // Something to do, let's do it! | |
337 if (!empty($attachments) && isset($curAction)) | |
338 { | |
339 checkSession('request'); | |
340 | |
341 // This will be handy. | |
342 require_once($sourcedir . '/ManageAttachments.php'); | |
343 | |
344 // Confirm the attachments are eligible for changing! | |
345 $request = $smcFunc['db_query']('', ' | |
346 SELECT a.id_attach | |
347 FROM {db_prefix}attachments AS a | |
348 INNER JOIN {db_prefix}messages AS m ON (m.id_msg = a.id_msg) | |
349 LEFT JOIN {db_prefix}boards AS b ON (m.id_board = b.id_board) | |
350 WHERE a.id_attach IN ({array_int:attachments}) | |
351 AND a.approved = {int:not_approved} | |
352 AND a.attachment_type = {int:attachment_type} | |
353 AND {query_see_board} | |
354 ' . $approve_query, | |
355 array( | |
356 'attachments' => $attachments, | |
357 'not_approved' => 0, | |
358 'attachment_type' => 0, | |
359 ) | |
360 ); | |
361 $attachments = array(); | |
362 while ($row = $smcFunc['db_fetch_assoc']($request)) | |
363 $attachments[] = $row['id_attach']; | |
364 $smcFunc['db_free_result']($request); | |
365 | |
366 // Assuming it wasn't all like, proper illegal, we can do the approving. | |
367 if (!empty($attachments)) | |
368 { | |
369 if ($curAction == 'approve') | |
370 ApproveAttachments($attachments); | |
371 else | |
372 removeAttachments(array('id_attach' => $attachments)); | |
373 } | |
374 } | |
375 | |
376 // How many unapproved attachments in total? | |
377 $request = $smcFunc['db_query']('', ' | |
378 SELECT COUNT(*) | |
379 FROM {db_prefix}attachments AS a | |
380 INNER JOIN {db_prefix}messages AS m ON (m.id_msg = a.id_msg) | |
381 INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board) | |
382 WHERE a.approved = {int:not_approved} | |
383 AND a.attachment_type = {int:attachment_type} | |
384 AND {query_see_board} | |
385 ' . $approve_query, | |
386 array( | |
387 'not_approved' => 0, | |
388 'attachment_type' => 0, | |
389 ) | |
390 ); | |
391 list ($context['total_unapproved_attachments']) = $smcFunc['db_fetch_row']($request); | |
392 $smcFunc['db_free_result']($request); | |
393 | |
394 $context['page_index'] = constructPageIndex($scripturl . '?action=moderate;area=attachmod;sa=attachments', $_GET['start'], $context['total_unapproved_attachments'], 10); | |
395 $context['start'] = $_GET['start']; | |
396 | |
397 // Get all unapproved attachments. | |
398 $request = $smcFunc['db_query']('', ' | |
399 SELECT a.id_attach, a.filename, a.size, m.id_msg, m.id_topic, m.id_board, m.subject, m.body, m.id_member, | |
400 IFNULL(mem.real_name, m.poster_name) AS poster_name, m.poster_time, | |
401 t.id_member_started, t.id_first_msg, b.name AS board_name, c.id_cat, c.name AS cat_name | |
402 FROM {db_prefix}attachments AS a | |
403 INNER JOIN {db_prefix}messages AS m ON (m.id_msg = a.id_msg) | |
404 INNER JOIN {db_prefix}topics AS t ON (t.id_topic = m.id_topic) | |
405 INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board) | |
406 LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member) | |
407 LEFT JOIN {db_prefix}categories AS c ON (c.id_cat = b.id_cat) | |
408 WHERE a.approved = {int:not_approved} | |
409 AND a.attachment_type = {int:attachment_type} | |
410 AND {query_see_board} | |
411 ' . $approve_query . ' | |
412 LIMIT ' . $context['start'] . ', 10', | |
413 array( | |
414 'not_approved' => 0, | |
415 'attachment_type' => 0, | |
416 ) | |
417 ); | |
418 $context['unapproved_items'] = array(); | |
419 for ($i = 1; $row = $smcFunc['db_fetch_assoc']($request); $i++) | |
420 { | |
421 $context['unapproved_items'][] = array( | |
422 'id' => $row['id_attach'], | |
423 'alternate' => $i % 2, | |
424 'filename' => $row['filename'], | |
425 'size' => round($row['size'] / 1024, 2), | |
426 'time' => timeformat($row['poster_time']), | |
427 'poster' => array( | |
428 'id' => $row['id_member'], | |
429 'name' => $row['poster_name'], | |
430 'link' => $row['id_member'] ? '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['poster_name'] . '</a>' : $row['poster_name'], | |
431 'href' => $scripturl . '?action=profile;u=' . $row['id_member'], | |
432 ), | |
433 'message' => array( | |
434 'id' => $row['id_msg'], | |
435 'subject' => $row['subject'], | |
436 'body' => parse_bbc($row['body']), | |
437 'time' => timeformat($row['poster_time']), | |
438 'href' => $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . '#msg' . $row['id_msg'], | |
439 ), | |
440 'topic' => array( | |
441 'id' => $row['id_topic'], | |
442 ), | |
443 'board' => array( | |
444 'id' => $row['id_board'], | |
445 'name' => $row['board_name'], | |
446 ), | |
447 'category' => array( | |
448 'id' => $row['id_cat'], | |
449 'name' => $row['cat_name'], | |
450 ), | |
451 ); | |
452 } | |
453 $smcFunc['db_free_result']($request); | |
454 | |
455 $context['sub_template'] = 'unapproved_attachments'; | |
456 } | |
457 | |
458 // Approve a post, just the one. | |
459 function ApproveMessage() | |
460 { | |
461 global $user_info, $topic, $board, $sourcedir, $smcFunc; | |
462 | |
463 checkSession('get'); | |
464 | |
465 $_REQUEST['msg'] = (int) $_REQUEST['msg']; | |
466 | |
467 require_once($sourcedir . '/Subs-Post.php'); | |
468 | |
469 isAllowedTo('approve_posts'); | |
470 | |
471 $request = $smcFunc['db_query']('', ' | |
472 SELECT t.id_member_started, t.id_first_msg, m.id_member, m.subject, m.approved | |
473 FROM {db_prefix}messages AS m | |
474 INNER JOIN {db_prefix}topics AS t ON (t.id_topic = {int:current_topic}) | |
475 WHERE m.id_msg = {int:id_msg} | |
476 AND m.id_topic = {int:current_topic} | |
477 LIMIT 1', | |
478 array( | |
479 'current_topic' => $topic, | |
480 'id_msg' => $_REQUEST['msg'], | |
481 ) | |
482 ); | |
483 list ($starter, $first_msg, $poster, $subject, $approved) = $smcFunc['db_fetch_row']($request); | |
484 $smcFunc['db_free_result']($request); | |
485 | |
486 // If it's the first in a topic then the whole topic gets approved! | |
487 if ($first_msg == $_REQUEST['msg']) | |
488 { | |
489 approveTopics($topic, !$approved); | |
490 | |
491 if ($starter != $user_info['id']) | |
492 logAction('approve_topic', array('topic' => $topic, 'subject' => $subject, 'member' => $starter, 'board' => $board)); | |
493 } | |
494 else | |
495 { | |
496 approvePosts($_REQUEST['msg'], !$approved); | |
497 | |
498 if ($poster != $user_info['id']) | |
499 logAction('approve', array('topic' => $topic, 'subject' => $subject, 'member' => $poster, 'board' => $board)); | |
500 } | |
501 | |
502 redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg']. '#msg' . $_REQUEST['msg']); | |
503 } | |
504 | |
505 // Approve a batch of posts (or topics in their own right) | |
506 function approveMessages($messages, $messageDetails, $current_view = 'replies') | |
507 { | |
508 global $sourcedir; | |
509 | |
510 require_once($sourcedir . '/Subs-Post.php'); | |
511 if ($current_view == 'topics') | |
512 { | |
513 approveTopics($messages); | |
514 // and tell the world about it | |
515 foreach ($messages as $topic) | |
516 { | |
517 logAction('approve_topic', array('topic' => $topic, 'subject' => $messageDetails[$topic]['subject'], 'member' => $messageDetails[$topic]['member'], 'board' => $messageDetails[$topic]['board'])); | |
518 } | |
519 } | |
520 else | |
521 { | |
522 approvePosts($messages); | |
523 // and tell the world about it again | |
524 foreach ($messages as $post) | |
525 { | |
526 logAction('approve', array('topic' => $messageDetails[$post]['topic'], 'subject' => $messageDetails[$post]['subject'], 'member' => $messageDetails[$post]['member'], 'board' => $messageDetails[$post]['board'])); | |
527 } | |
528 } | |
529 } | |
530 | |
531 // This is a helper function - basically approve everything! | |
532 function approveAllData() | |
533 { | |
534 global $smcFunc, $sourcedir; | |
535 | |
536 // Start with messages and topics. | |
537 $request = $smcFunc['db_query']('', ' | |
538 SELECT id_msg | |
539 FROM {db_prefix}messages | |
540 WHERE approved = {int:not_approved}', | |
541 array( | |
542 'not_approved' => 0, | |
543 ) | |
544 ); | |
545 $msgs = array(); | |
546 while ($row = $smcFunc['db_fetch_row']($request)) | |
547 $msgs[] = $row[0]; | |
548 $smcFunc['db_free_result']($request); | |
549 | |
550 if (!empty($msgs)) | |
551 { | |
552 require_once($sourcedir . '/Subs-Post.php'); | |
553 approvePosts($msgs); | |
554 } | |
555 | |
556 // Now do attachments | |
557 $request = $smcFunc['db_query']('', ' | |
558 SELECT id_attach | |
559 FROM {db_prefix}attachments | |
560 WHERE approved = {int:not_approved}', | |
561 array( | |
562 'not_approved' => 0, | |
563 ) | |
564 ); | |
565 $attaches = array(); | |
566 while ($row = $smcFunc['db_fetch_row']($request)) | |
567 $attaches[] = $row[0]; | |
568 $smcFunc['db_free_result']($request); | |
569 | |
570 if (!empty($attaches)) | |
571 { | |
572 require_once($sourcedir . '/ManageAttachments.php'); | |
573 ApproveAttachments($attaches); | |
574 } | |
575 } | |
576 | |
577 // remove a batch of messages (or topics) | |
578 function removeMessages($messages, $messageDetails, $current_view = 'replies') | |
579 { | |
580 global $sourcedir, $modSettings; | |
581 require_once($sourcedir . '/RemoveTopic.php'); | |
582 if ($current_view == 'topics') | |
583 { | |
584 removeTopics($messages); | |
585 // and tell the world about it | |
586 foreach ($messages as $topic) | |
587 // Note, only log topic ID in native form if it's not gone forever. | |
588 logAction('remove', array( | |
589 (empty($modSettings['recycle_enable']) || $modSettings['recycle_board'] != $messageDetails[$topic]['board'] ? 'topic' : 'old_topic_id') => $topic, 'subject' => $messageDetails[$topic]['subject'], 'member' => $messageDetails[$topic]['member'], 'board' => $messageDetails[$topic]['board'])); | |
590 } | |
591 else | |
592 { | |
593 foreach ($messages as $post) | |
594 { | |
595 removeMessage($post); | |
596 logAction('delete', array( | |
597 (empty($modSettings['recycle_enable']) || $modSettings['recycle_board'] != $messageDetails[$post]['board'] ? 'topic' : 'old_topic_id') => $messageDetails[$post]['topic'], 'subject' => $messageDetails[$post]['subject'], 'member' => $messageDetails[$post]['member'], 'board' => $messageDetails[$post]['board'])); | |
598 } | |
599 } | |
600 } | |
601 ?> |