PostModeration.php 21 KB

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