PostModeration.php 21 KB

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