PostModeration.php 21 KB

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