PageRenderTime 53ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 1ms

/forum/includes/prime_trash_bin_b.php

https://github.com/GreyTeardrop/socionicasys-forum
PHP | 1215 lines | 910 code | 139 blank | 166 comment | 175 complexity | b8e76bef74361abe3b18e9bf88daa995 MD5 | raw file
Possible License(s): AGPL-1.0, LGPL-3.0, MPL-2.0-no-copyleft-exception
  1. <?php
  2. /**
  3. *
  4. * @package phpBB3
  5. * @version $Id: prime_trash_bin_b.php,v 1.1.0 2010/01/03 03:00:00 PST primehalo Exp $
  6. * @copyright (c) 2007-2010 Ken Innes IV
  7. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  8. *
  9. */
  10. /**
  11. * @ignore
  12. */
  13. if (!defined('IN_PHPBB'))
  14. {
  15. exit;
  16. }
  17. /**
  18. * Check to see if this file has already been included.
  19. */
  20. if (!defined('INCLUDES_PRIME_TRASH_BIN_B_PHP'))
  21. {
  22. define('INCLUDES_PRIME_TRASH_BIN_B_PHP', true);
  23. include ($phpbb_root_path . 'includes/prime_trash_bin_a.' . $phpEx);
  24. //=======================================================================//
  25. // Administration Functions //
  26. //=======================================================================//
  27. /**
  28. */
  29. function make_fake_delete_select($select_id = 0)
  30. {
  31. global $config;
  32. if (!isset($config['topic_delete_mode']))
  33. {
  34. set_config('topic_delete_mode', 0);
  35. }
  36. $options = build_select(array(
  37. 0 => 'PRIME_FAKE_DELETE_DISABLE',
  38. 1 => 'PRIME_FAKE_DELETE_ENABLE',
  39. 2 => 'PRIME_FAKE_DELETE_AUTO_TRASH',
  40. 3 => 'PRIME_FAKE_DELETE_SHADOW_ON',
  41. 4 => 'PRIME_FAKE_DELETE_SHADOW_OFF',
  42. ), $select_id);
  43. return($options);
  44. }
  45. /**
  46. */
  47. function make_trash_select($select_id = false)
  48. {
  49. global $config, $user;
  50. if (!isset($config['trash_forum']))
  51. {
  52. set_config('trash_forum', 0);
  53. }
  54. $options = '<option value="0">' . $user->lang['PRIME_TRASH_FORUM_DISABLE'] . '</option>';
  55. $options .= '<option disabled="disabled" class="disabled-option" value="0">' . $user->lang['PRIME_TRASH_FORUM_DIVIDER'] . '</option>';
  56. return($options . make_forum_select($select_id, false, false, true, true, true, false));
  57. }
  58. /**
  59. */
  60. function validate_fake_delete_options($cfg_array, &$error)
  61. {
  62. $delete_mode = isset($cfg_array['topic_delete_mode']) ? $cfg_array['topic_delete_mode'] : 0;
  63. $msg[2] = 'PRIME_FAKE_DELETE_AUTO_TRASH';
  64. $msg[3] = 'PRIME_FAKE_DELETE_SHADOW_ON';
  65. $msg[4] = 'PRIME_FAKE_DELETE_SHADOW_OFF';
  66. if (empty($cfg_array['trash_forum']) && isset($msg[$delete_mode]))
  67. {
  68. global $user;
  69. $user->add_lang('mods/prime_trash_bin_b');
  70. $error[] = sprintf($user->lang['PRIME_NO_TRASH_FORUM_ERROR'], $user->lang[$msg[$delete_mode]]);
  71. }
  72. }
  73. /**
  74. * Alter the forum ID from which topics and posts were stifled (such as when the forum is being deleted).
  75. */
  76. function update_stifled_from($old_forum_id, $new_forum_id)
  77. {
  78. global $db;
  79. $sql = 'UPDATE ' . TOPICS_TABLE . ' SET topic_deleted_from = ' . (int)$new_forum_id . ' WHERE topic_deleted_from = ' . (int)$old_forum_id;
  80. $db->sql_query($sql);
  81. $sql = 'UPDATE ' . POSTS_TABLE . ' SET post_deleted_from = ' . (int)$new_forum_id . ' WHERE post_deleted_from = ' . (int)$old_forum_id;
  82. $db->sql_query($sql);
  83. }
  84. //=======================================================================//
  85. // Moderation Functions //
  86. //=======================================================================//
  87. /**
  88. * $data - key: user_id, value: post count to subtract
  89. */
  90. function stifle_update_post_counts($data)
  91. {
  92. if (!empty($data))
  93. {
  94. global $db;
  95. // Get the post counts for the users who need updating, and adjust them accordingly.
  96. // If we tried to do it directly with an UPDATE, they could wind up with a negative post count.
  97. $post_count = array();
  98. $sql = 'SELECT user_id, user_posts'
  99. . ' FROM ' . USERS_TABLE
  100. . ' WHERE ' . $db->sql_in_set('user_id', array_keys($data));
  101. $result = $db->sql_query($sql);
  102. while ($row = $db->sql_fetchrow($result))
  103. {
  104. if ($data[$row['user_id']])
  105. {
  106. $post_count[$row['user_id']] = ($row['user_posts'] - $data[$row['user_id']]) > 0 ? ($row['user_posts'] - $data[$row['user_id']]) : 0;
  107. }
  108. }
  109. $db->sql_freeresult($result);
  110. // Now that we have the correct post counts for each user, we can update the DB.
  111. foreach($post_count as $poster_id => $count)
  112. {
  113. $sql = 'UPDATE ' . USERS_TABLE
  114. . ' SET user_posts = ' . (int)$count
  115. . ' WHERE user_id = ' . (int)$poster_id;
  116. $db->sql_query($sql);
  117. }
  118. }
  119. }
  120. /**
  121. * $data - key: user_id, value: post count to subtract
  122. */
  123. function unstifle_update_post_counts($data)
  124. {
  125. if (!empty($data))
  126. {
  127. global $db;
  128. foreach ($data as $poster_id => $count)
  129. {
  130. $sql = 'UPDATE ' . USERS_TABLE
  131. . ' SET user_posts = user_posts + ' . (int)$count
  132. . ' WHERE user_id = ' . (int)$poster_id;
  133. $db->sql_query($sql);
  134. }
  135. }
  136. }
  137. /* Functions for topics
  138. ------------------------------------------------------------------------ */
  139. /**
  140. * @return mixed If all are mock-deleted: true
  141. * Otherwise: the number of mock-deleted topics
  142. */
  143. function are_topics_stifled($topic_ids)
  144. {
  145. global $db;
  146. $topic_ids = !is_array($topic_ids) ? array($topic_ids) : $topic_ids;
  147. $sql = 'SELECT topic_id'
  148. . ' FROM ' . TOPICS_TABLE
  149. . ' WHERE topic_deleted_time > 0'
  150. . ' AND ' . $db->sql_in_set('topic_id', $topic_ids);
  151. $result = $db->sql_query($sql);
  152. $stifled_count = $db->sql_affectedrows();
  153. $db->sql_freeresult($result);
  154. return(($stifled_count === count($topic_ids)) ? true : $stifled_count);
  155. }
  156. /**
  157. * The parameter $delete_post indicates that a user is deleting the only post
  158. * in a topic, and they are a moderator who has already been validated.
  159. */
  160. function mcp_stifle_topic($topic_ids, $delete_post = false)
  161. {
  162. global $db, $user, $auth, $template, $phpEx, $phpbb_root_path;
  163. if (!stifle_topics_enabled())
  164. {
  165. return(false);
  166. }
  167. if (empty($topic_ids))
  168. {
  169. trigger_error($user->lang['NO_TOPICS_SELECTED']);
  170. }
  171. $forum_id = request_var('f', 0);
  172. $user->add_lang('mcp');
  173. $topic_ids = is_array($topic_ids) ? $topic_ids : array($topic_ids);
  174. // If this is a shadow topic, then present the page for a normal, permanent deletion.
  175. if (count($topic_ids) == 1 && !empty($topic_ids[0]))
  176. {
  177. $sql = 'SELECT topic_status FROM ' . TOPICS_TABLE . ' WHERE topic_id = ' . (int)$topic_ids[0];
  178. $result = $db->sql_query($sql);
  179. $shadow_topic = (($row = $db->sql_fetchrow($result)) && $row['topic_status'] == ITEM_MOVED) ? true : false;
  180. $db->sql_freeresult($result);
  181. if ($shadow_topic)
  182. {
  183. return false;
  184. }
  185. }
  186. //If topics are supposed to be permanently deleted, we have to check for permission.
  187. $delete_forever = (request_var('delete_forever', false) && auth_fake_delete('delete', $forum_id));
  188. if (/*is_trash_forum($forum_id) ||*/ $delete_forever || ($already_stifled = are_topics_stifled($topic_ids)) === true)
  189. {
  190. if (!auth_fake_delete('delete', $forum_id)/* && (!$delete_post && !check_ids($topic_ids, TOPICS_TABLE, 'topic_id', array('m_delete_forever')))*/)
  191. {
  192. trigger_error($user->lang['NO_AUTH_OPERATION']);
  193. }
  194. return(false); // Return to allow normal, permanent deletion
  195. }
  196. if (!$delete_post && !check_ids($topic_ids, TOPICS_TABLE, 'topic_id', array('m_delete')))
  197. {
  198. trigger_error($user->lang['NO_AUTH_OPERATION']);
  199. }
  200. $user->add_lang('mods/prime_trash_bin_b');
  201. $redirect = request_var('redirect', build_url(array('_f_', 'action', 'quickmod')));
  202. $message = '';
  203. if (confirm_box(true))
  204. {
  205. $move_to_trash = (trash_enabled() && request_var('move_to_trash', false)) || trash_required();
  206. $view_trash = $auth->acl_get('f_list', get_trash_forum()) && $move_to_trash;
  207. $message = stifle_topics($topic_ids, true);
  208. }
  209. else
  210. {
  211. $s_hidden_fields = build_hidden_fields(array(
  212. 'topic_id_list' => $topic_ids,
  213. 'f' => $forum_id,
  214. 'action' => 'delete_topic',
  215. 'redirect' => $redirect,
  216. ));
  217. if ($already_stifled)
  218. {
  219. $template->assign_var('ADDITIONAL_MSG', $user->lang['PRIME_DELETE_TOPIC_MIX_NOTICE']);
  220. }
  221. if (get_trash_forum() && !is_trash_forum($forum_id))
  222. {
  223. $template->assign_var('S_CAN_USE_TRASH_BIN', !trash_required() ? true : false);
  224. $template->assign_var('S_SHADOW_DEFAULT_DISABLED', !trash_required() ? true : false); // Disable the shadow option when the trash bin option is not checked.
  225. $template->assign_var('S_CAN_LEAVE_SHADOW', !trash_shadow_required() && !trash_shadow_disabled());
  226. }
  227. if (auth_fake_delete('delete', $forum_id))
  228. {
  229. $template->assign_vars(array('S_CAN_DELETE_FOREVER' => true, 'L_PRIME_DELETE_FOREVER' => ($user->lang[sizeof($topic_ids) == 1 ? 'PRIME_DELETE_TOPIC_FOREVER' : 'PRIME_DELETE_TOPICS_FOREVER'])));
  230. }
  231. $template->assign_var('L_PRIME_DELETE_REASON', $user->lang['PRIME_DELETE_TOPIC_REASON']);
  232. confirm_box(false, (sizeof($topic_ids) == 1) ? 'DELETE_TOPIC' : 'DELETE_TOPICS', $s_hidden_fields, 'prime_delete_confirm.html');
  233. }
  234. if (!$message)
  235. {
  236. $redirect = request_var('redirect', "index.$phpEx");
  237. $redirect = reapply_sid($redirect);
  238. redirect($redirect);
  239. }
  240. else
  241. {
  242. $prev_page = preg_match('/mode=delete/i', $redirect) ? '' : reapply_sid($redirect);
  243. if (!$prev_page && $topic_ids[0])
  244. {
  245. $prev_page = append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $forum_id . '&amp;t=' . $topic_ids[0]);
  246. }
  247. $redirect = append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id);
  248. meta_refresh(3, $redirect);
  249. $message = $user->lang[$message];
  250. $message .= '<br /><br />' . sprintf($user->lang['RETURN_FORUM'], '<a href="' . $redirect . '">', '</a>');
  251. $message .= ($prev_page && ($view_trash || !$move_to_trash)) ? '<br /><br />' . sprintf($user->lang['RETURN_PAGE'], '<a href="' . $prev_page . '">', '</a>') : '';
  252. $message .= ($view_trash) ? '<br /><br />' . sprintf($user->lang['PRIME_GO_TO_TRASH_BIN'], '<a href="' . append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . get_trash_forum()) . '">', '</a>') : '';
  253. trigger_error($message);
  254. }
  255. }
  256. /**
  257. */
  258. function stifle_topics($topic_ids, $log = false)
  259. {
  260. global $db, $user, $phpbb_root_path, $phpEx;
  261. if (empty($topic_ids))
  262. {
  263. return('NO_TOPICS_SELECTED');
  264. }
  265. $sync = array();
  266. $topic_ids = is_array($topic_ids) ? $topic_ids : array($topic_ids);
  267. $trash_it = (request_var('move_to_trash', false) || trash_required()) ? (boolean)get_trash_forum() : false;
  268. $del_info['topic_deleted_user'] = $user->data['user_id'];
  269. $del_info['topic_deleted_time'] = time();
  270. $del_info['topic_deleted_reason'] = utf8_normalize_nfc(request_var('delete_reason', '', true));
  271. $post_count = array();
  272. // Check to see if this topic has yet to be marked for deletion (and get the forum id).
  273. $sql = 'SELECT topic_id, forum_id, topic_title'
  274. . ' FROM ' . TOPICS_TABLE
  275. . ' WHERE topic_deleted_time < 1'
  276. . ' AND ' . $db->sql_in_set('topic_id', $topic_ids);
  277. $result = $db->sql_query($sql);
  278. while ($row = $db->sql_fetchrow($result))
  279. {
  280. $sync[] = $row['forum_id'];
  281. $del_info['topic_deleted_from'] = $row['forum_id'];
  282. $sql = 'UPDATE ' . TOPICS_TABLE
  283. . ' SET ' . $db->sql_build_array('UPDATE', $del_info)
  284. . ' WHERE topic_id = ' . (int)$row['topic_id'];
  285. $db->sql_query($sql);
  286. if ($log)
  287. {
  288. add_log('mod', $row['forum_id'], $row['topic_id'], ($trash_it ? 'LOG_TOPIC_TRASHED' : 'LOG_TOPIC_STIFLED'), $row['topic_title'], $del_info['topic_deleted_reason']);
  289. }
  290. // Get info for updating user post counts
  291. $sql = 'SELECT poster_id'
  292. . ' FROM ' . POSTS_TABLE
  293. . ' WHERE (topic_id = ' . (int)$row['topic_id']
  294. . ' AND post_postcount > 0'
  295. . ' AND post_deleted_time = 0)';
  296. $result2 = $db->sql_query($sql);
  297. while ($row2 = $db->sql_fetchrow($result2))
  298. {
  299. $post_count[$row2['poster_id']] = empty($post_count[$row2['poster_id']]) ? 1 : $post_count[$row2['poster_id']] + 1;
  300. }
  301. $db->sql_freeresult($result2);
  302. }
  303. $db->sql_freeresult($result);
  304. // Update user post counts.
  305. stifle_update_post_counts($post_count);
  306. if ($trash_it)
  307. {
  308. return(move_to_trash($topic_ids));
  309. }
  310. if (!function_exists('sync'))
  311. {
  312. include($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
  313. }
  314. sync('forum', 'forum_id', $sync);
  315. return(sizeof($topic_ids) == 1 ? 'PRIME_DELETED_TOPIC_SUCCESS' : 'PRIME_DELETED_TOPICS_SUCCESS');
  316. }
  317. /**
  318. * Moves topics to the Trash Bin forum. There is no need to check for permissions,
  319. * as we want to move these to the trash regardless of the user's permissions.
  320. */
  321. function move_to_trash($topic_ids, $log = false)
  322. {
  323. global $db, $phpbb_root_path, $phpEx;
  324. $to_forum_id = (integer)get_trash_forum();
  325. if (empty($topic_ids) || empty($to_forum_id))
  326. {
  327. return(empty($topic_ids) ? 'NO_TOPICS_SELECTED' : 'FORUM_NOT_EXIST');
  328. }
  329. if(empty($to_forum_id)) //if (!sizeof($forum_data = get_forum_data($to_forum_id, false)))
  330. {
  331. return('FORUM_NOT_EXIST');
  332. }
  333. //$forum_id = check_ids($topic_ids, TOPICS_TABLE, 'topic_id', array('m_move'), true);
  334. $leave_shadow = (isset($_POST['move_leave_shadow']) || trash_shadow_required()) && !trash_shadow_disabled();
  335. $topics_moved = sizeof($topic_ids);
  336. $topics_authed_moved = 0;
  337. // Grab the topic data for the given topic IDs
  338. $sql_array = array(
  339. 'SELECT' => 't.*, f.forum_name',
  340. 'FROM' => array(TOPICS_TABLE => 't'),
  341. 'LEFT_JOIN' => array(array(
  342. 'FROM' => array(FORUMS_TABLE => 'f'),
  343. 'ON' => 'f.forum_id = t.forum_id')),
  344. 'WHERE' => $db->sql_in_set('t.topic_id', $topic_ids)
  345. );
  346. $sql = $db->sql_build_query('SELECT', $sql_array);
  347. $result = $db->sql_query($sql);
  348. while ($row = $db->sql_fetchrow($result))
  349. {
  350. $row['forum_id'] = (!$row['forum_id']) ? request_var('f', 0) : $row['forum_id'];
  351. $topic_data[$row['topic_id']] = $row;
  352. }
  353. $db->sql_freeresult($result);
  354. // All this sync code is taken straight from mcp_move_topic(), including
  355. // this $forum_sync_data which doesn't ever seemed to be used... ever.
  356. //$forum_sync_data = array();
  357. //$forum_sync_data[$forum_id] = current($topic_data);
  358. //$forum_sync_data[$to_forum_id] = $forum_data;
  359. foreach ($topic_data as $topic_id => $topic_info)
  360. {
  361. if ($topic_info['topic_approved'] == '1')
  362. {
  363. $topics_authed_moved++;
  364. }
  365. }
  366. $db->sql_transaction('begin');
  367. $sql = 'SELECT SUM(t.topic_replies + t.topic_approved) as topic_posts
  368. FROM ' . TOPICS_TABLE . ' t
  369. WHERE ' . $db->sql_in_set('t.topic_id', $topic_ids);
  370. $result = $db->sql_query($sql);
  371. $row_data = $db->sql_fetchrow($result);
  372. $db->sql_freeresult($result);
  373. $sync_sql = array();
  374. if ($row_data['topic_posts'])
  375. {
  376. // Move this line down inside the loop so $row['forum_id'] can replace $forum_id
  377. //$sync_sql[$forum_id][] = 'forum_posts = forum_posts - ' . (int) $row_data['topic_posts'];
  378. $sync_sql[$to_forum_id][] = 'forum_posts = forum_posts + ' . (int) $row_data['topic_posts'];
  379. }
  380. if ($topics_authed_moved)
  381. {
  382. $sync_sql[$to_forum_id][] = 'forum_topics = forum_topics + ' . (int) $topics_authed_moved;
  383. }
  384. $sync_sql[$to_forum_id][] = 'forum_topics_real = forum_topics_real + ' . (int) $topics_moved;
  385. // Move topics, but do not resync yet
  386. if (!function_exists('move_topics'))
  387. {
  388. include($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
  389. }
  390. move_topics($topic_ids, $to_forum_id, false);
  391. $forum_ids = array($to_forum_id);
  392. foreach ($topic_data as $topic_id => $row)
  393. {
  394. // Get the list of forums to resync, add a log entry
  395. $forum_ids[] = $row['forum_id'];
  396. if ($log)
  397. {
  398. add_log('mod', $to_forum_id, $topic_id, 'LOG_MOVE', $row['forum_name']);
  399. }
  400. // If we have moved a global announcement, we need to correct the topic type
  401. if ($row['topic_type'] == POST_GLOBAL)
  402. {
  403. $sql = 'UPDATE ' . TOPICS_TABLE . '
  404. SET topic_type = ' . POST_ANNOUNCE . '
  405. WHERE topic_id = ' . (int)$row['topic_id'];
  406. $db->sql_query($sql);
  407. }
  408. // Leave a redirection if required and only if the topic is visible to users
  409. if ($leave_shadow && $row['topic_approved'] && $row['topic_type'] != POST_GLOBAL)
  410. {
  411. $shadow = $row;
  412. unset($shadow['forum_name']);
  413. unset($shadow['topic_id']);
  414. $shadow['topic_approved'] = 1;
  415. $shadow['topic_status'] = ITEM_MOVED;
  416. $shadow['topic_type'] = POST_NORMAL;
  417. $shadow['topic_moved_id'] = (int) $row['topic_id'];
  418. $db->sql_query('INSERT INTO ' . TOPICS_TABLE . $db->sql_build_array('INSERT', $shadow));
  419. $topics_authed_moved--;
  420. $topics_moved--;
  421. }
  422. // I moved this code here inside the loop so $row['forum_id'] can replace $forum_id
  423. if ($row_data['topic_posts'] && !isset($sync_sql[$row['forum_id']]['forum_posts']))
  424. {
  425. $sync_sql[$row['forum_id']]['forum_posts'] = 'forum_posts = forum_posts - ' . (int) $row_data['topic_posts'];
  426. }
  427. if (!isset($sync_sql[$row['forum_id']]['forum_topics_real']))
  428. {
  429. $sync_sql[$row['forum_id']]['forum_topics_real'] = 'forum_topics_real = forum_topics_real - ' . (int) $topics_moved;
  430. }
  431. if ($topics_authed_moved && !isset($sync_sql[$row['forum_id']]['forum_topics']))
  432. {
  433. $sync_sql[$row['forum_id']]['forum_topics'] = 'forum_topics = forum_topics - ' . (int) $topics_authed_moved;
  434. }
  435. }
  436. unset($topic_data);
  437. // I moved this code up inside the loop so $row['forum_id'] can replace $forum_id
  438. //$sync_sql[$forum_id][] = 'forum_topics_real = forum_topics_real - ' . (int) $topics_moved;
  439. //if ($topics_authed_moved)
  440. //{
  441. // $sync_sql[$forum_id][] = 'forum_topics = forum_topics - ' . (int) $topics_authed_moved;
  442. //}
  443. foreach ($sync_sql as $forum_id_key => $array)
  444. {
  445. $sql = 'UPDATE ' . FORUMS_TABLE . '
  446. SET ' . implode(', ', $array) . '
  447. WHERE forum_id = ' . (int)$forum_id_key;
  448. $db->sql_query($sql);
  449. }
  450. $db->sql_transaction('commit');
  451. sync('forum', 'forum_id', $forum_ids);
  452. return((sizeof($topic_ids) == 1 ? 'PRIME_TRASHED_TOPIC_SUCCESS' : 'PRIME_TRASHED_TOPICS_SUCCESS'));
  453. }
  454. /**
  455. */
  456. function mcp_unstifle_topic($topic_ids)
  457. {
  458. global $user, $template, $phpEx, $phpbb_root_path;
  459. $user->add_lang('mcp');
  460. $user->add_lang('mods/prime_trash_bin_b');
  461. if (empty($topic_ids))
  462. {
  463. trigger_error($user->lang['NO_TOPICS_SELECTED']);
  464. }
  465. $topic_ids = is_array($topic_ids) ? $topic_ids : array($topic_ids);
  466. if (!check_ids($topic_ids, TOPICS_TABLE, 'topic_id', array('a_', 'm_undelete')))
  467. {
  468. trigger_error($user->lang['NO_AUTH_OPERATION']);
  469. }
  470. if (!are_topics_stifled($topic_ids))
  471. {
  472. trigger_error($user->lang['PRIME_UNDELETE_TOPICS_UNNEEDED']);
  473. }
  474. $redirect = request_var('redirect', build_url(array('_f_', 'action', 'quickmod')));
  475. $forum_id = request_var('f', 0);
  476. $message = '';
  477. if (confirm_box(true))
  478. {
  479. $message = unstifle_topics($topic_ids, true);
  480. }
  481. else
  482. {
  483. $s_hidden_fields = build_hidden_fields(array(
  484. 'topic_id_list' => $topic_ids,
  485. 'f' => $forum_id,
  486. 'action' => 'undelete_topic',
  487. 'redirect' => $redirect,
  488. ));
  489. $template->assign_var('L_PRIME_DELETE_REASON', $user->lang['PRIME_UNDELETE_TOPIC_REASON']);
  490. confirm_box(false, (sizeof($topic_ids) == 1) ? 'PRIME_UNDELETE_TOPIC' : 'PRIME_UNDELETE_TOPICS', $s_hidden_fields, 'prime_delete_confirm.html');
  491. }
  492. $redirect = reapply_sid($redirect);
  493. if (!$message)
  494. {
  495. redirect($redirect);
  496. }
  497. else
  498. {
  499. meta_refresh(3, $redirect);
  500. $message = $user->lang[$message];
  501. $message .= '<br /><br />' . sprintf($user->lang['RETURN_PAGE'], '<a href="' . $redirect . '">', '</a>');
  502. $message .= '<br /><br />' . sprintf($user->lang['RETURN_FORUM'], '<a href="' . append_sid("{$phpbb_root_path}viewforum.$phpEx", "f=$forum_id") . '">', '</a>');
  503. trigger_error($message);
  504. }
  505. }
  506. /**
  507. */
  508. function unstifle_topics($topic_ids, $log = false)
  509. {
  510. global $db, $phpbb_root_path, $phpEx;
  511. if (empty($topic_ids))
  512. {
  513. return('NO_TOPIC_SELECTED');
  514. }
  515. if (!is_array($topic_ids))
  516. {
  517. $topic_ids = array($topic_ids);
  518. }
  519. $sync = array();
  520. $move = array();
  521. $updated_info['topic_deleted_from'] = 0;
  522. $updated_info['topic_deleted_user'] = 0;
  523. $updated_info['topic_deleted_time'] = 0;
  524. $updated_info['topic_deleted_reason'] = utf8_normalize_nfc(request_var('delete_reason', '', true));
  525. $post_count = array();
  526. $sql = 'SELECT topic_id, forum_id, topic_deleted_from, topic_title, topic_type'
  527. . ' FROM ' . TOPICS_TABLE
  528. . ' WHERE topic_deleted_time > 0'
  529. . ' AND ' . $db->sql_in_set('topic_id', $topic_ids);
  530. $result = $db->sql_query($sql);
  531. while ($row = $db->sql_fetchrow($result))
  532. {
  533. if (auth_fake_delete('undelete', $row['forum_id']))
  534. {
  535. // If the topic used to be a global announcement, we must again make it so.
  536. if ($row['topic_deleted_from'] == 0 && $row['topic_type'] == POST_ANNOUNCE)
  537. {
  538. $updated_info['topic_type'] = POST_GLOBAL;
  539. }
  540. $sql = 'UPDATE ' . TOPICS_TABLE
  541. . ' SET ' . $db->sql_build_array('UPDATE', $updated_info)
  542. . ' WHERE topic_id = ' . (int)$row['topic_id'];
  543. $db->sql_query($sql);
  544. if (is_trash_forum($row['forum_id']))
  545. {
  546. $move[$row['topic_deleted_from']][] = $row['topic_id'];
  547. }
  548. $sync[] = $row['forum_id'];
  549. $sync[] = $row['topic_deleted_from'];
  550. $success = (empty($success) ? '' : ',') . $row['topic_id'];
  551. if ($log)
  552. {
  553. add_log('mod', $row['forum_id'], $row['topic_id'], 'LOG_TOPIC_UNSTIFLED', $row['topic_title'], $updated_info['topic_deleted_reason']);
  554. }
  555. // Get info for updating user post counts
  556. $sql = 'SELECT poster_id'
  557. . ' FROM ' . POSTS_TABLE
  558. . ' WHERE (topic_id = ' . (int)$row['topic_id']
  559. . ' AND post_postcount > 0'
  560. . ' AND post_deleted_time = 0)';
  561. $result2 = $db->sql_query($sql);
  562. while ($row2 = $db->sql_fetchrow($result2))
  563. {
  564. $post_count[$row2['poster_id']] = empty($post_count[$row2['poster_id']]) ? 1 : $post_count[$row2['poster_id']] + 1;
  565. }
  566. $db->sql_freeresult($result2);
  567. }
  568. }
  569. $db->sql_freeresult($result);
  570. // Update user post counts
  571. unstifle_update_post_counts($post_count);
  572. // Get out of here if nothing happened.
  573. if (empty($success))
  574. {
  575. return('NO_AUTH_OPERATION');
  576. }
  577. if (!function_exists('sync') || !function_exists('move_topics'))
  578. {
  579. include($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
  580. }
  581. // Move topics back to their pre-deletion forums
  582. foreach ($move as $forum_id => $topic_ids)
  583. {
  584. move_topics($topic_ids, $forum_id);
  585. }
  586. sync('forum', 'forum_id', $sync);
  587. return((sizeof($topic_ids) == 1) ? 'PRIME_UNDELETED_TOPIC_SUCCESS' : 'PRIME_UNDELETED_TOPICS_SUCCESS');
  588. }
  589. /* Functions for posts
  590. ------------------------------------------------------------------------ */
  591. /**
  592. * Determines how many posts are mock-deleted.
  593. * Returns true if all are mock-deleted, otherwise
  594. * returns the number of posts that are be mock-deleted.
  595. */
  596. function are_posts_stifled($post_ids)
  597. {
  598. global $db;
  599. $post_ids = !is_array($post_ids) ? array($post_ids) : $post_ids;
  600. $sql = 'SELECT post_id'
  601. . ' FROM ' . POSTS_TABLE
  602. . ' WHERE post_deleted_time > 0'
  603. . ' AND ' . $db->sql_in_set('post_id', $post_ids);
  604. $result = $db->sql_query($sql);
  605. $stifled_count = $db->sql_affectedrows();
  606. $db->sql_freeresult($result);
  607. return(($stifled_count === count($post_ids)) ? true : $stifled_count);
  608. }
  609. /**
  610. * Determines how many posts can be mock-deleted.
  611. * Returns true if all can be mock deleted, otherwise
  612. * returns the number of posts that can be mock deleted.
  613. */
  614. function can_posts_be_stifled($post_ids)
  615. {
  616. global $db;
  617. if (empty($post_ids))
  618. {
  619. return 0;
  620. }
  621. $post_ids = !is_array($post_ids) ? array($post_ids) : $post_ids;
  622. $sql = 'SELECT post_id'
  623. . ' FROM ' . POSTS_TABLE
  624. . ' WHERE (post_deleted_time = 0 AND post_approved > 0)'
  625. . ' AND ' . $db->sql_in_set('post_id', $post_ids);
  626. $result = $db->sql_query($sql);
  627. $safe_deletable_count = $db->sql_affectedrows();
  628. $db->sql_freeresult($result);
  629. return(($safe_deletable_count === count($post_ids)) ? true : $safe_deletable_count);
  630. }
  631. function stifle_users_posts($user_id, $username, $adm_link_back)
  632. {
  633. global $user;
  634. $delete_forever = (request_var('delete_forever', false) && auth_fake_delete('delete')) ? true : false;
  635. if (stifle_posts_enabled() && !$delete_forever)
  636. {
  637. $message = stifle_posts($user_id, 'poster_id');
  638. add_log('admin', 'LOG_USER_DEL_POSTS', $username);
  639. trigger_error($user->lang[$message] . $adm_link_back);
  640. }
  641. }
  642. /**
  643. * Marks posts as deleted.
  644. */
  645. function stifle_posts($ids, $where_type = 'post_id', $log = false)
  646. {
  647. global $db, $user;
  648. if (empty($ids))
  649. {
  650. return('NO_POST_SELECTED');
  651. }
  652. if (is_bool($where_type))
  653. {
  654. $log = $where_type;
  655. $where_type = 'post_id';
  656. }
  657. $ids = is_array($ids) ? $ids : array($ids);
  658. $return = '';
  659. // Only grab posts that have yet to be marked for deletion.
  660. $sql = 'SELECT post_deleted_time, post_deleted_user, post_deleted_reason, post_id, topic_id, forum_id, post_subject, poster_id, post_postcount'
  661. . ' FROM ' . POSTS_TABLE
  662. . ' WHERE (post_deleted_time = 0 AND post_approved > 0)'
  663. . ' AND ' . $db->sql_in_set($where_type, $ids);
  664. $result = $db->sql_query($sql);
  665. $del_info['post_deleted_time'] = time();
  666. $del_info['post_deleted_user'] = $user->data['user_id'];
  667. $del_info['post_deleted_reason'] = utf8_normalize_nfc(request_var('delete_reason', '', true));
  668. $post_count = array();
  669. $delete_topics = array();
  670. $sync_topics = array();
  671. $sync_forums = array();
  672. while ($row = $db->sql_fetchrow($result))
  673. {
  674. $sync_topics[] = $row['topic_id'];
  675. $sync_forums[] = $row['forum_id'];
  676. // We've already determined that the whole topic will be deleted.
  677. //if (isset($delete_topics[$row['topic_id']]))
  678. //{
  679. // continue;
  680. //}
  681. // Check if we should just mock-delete the entire topic.
  682. if (stifle_topics_enabled() && !is_trash_forum($row['forum_id']) && !isset($delete_topics[$row['topic_id']]))
  683. {
  684. $sql = 'SELECT topic_deleted_time, topic_first_post_id, topic_last_post_id'
  685. . ' FROM ' . TOPICS_TABLE
  686. . ' WHERE topic_id = ' . (int)$row['topic_id']
  687. ;
  688. $topic_result = $db->sql_query($sql);
  689. $topic_data = $db->sql_fetchrow($topic_result);
  690. $db->sql_freeresult($topic_result);
  691. // The post is the only one in the topic, so mock-delete this topic
  692. // unless the topic is already marked as deleted.
  693. if ($topic_data['topic_first_post_id'] == $topic_data['topic_last_post_id'] && empty($topic_data['topic_deleted_time']))
  694. {
  695. // Double-check just to be sure
  696. $sql = 'SELECT COUNT(post_id) AS posts_in_topic FROM ' . POSTS_TABLE . ' WHERE topic_id = ' . (int)$row['topic_id'] . ' AND post_approved = 1 AND post_deleted_time = 0';
  697. $result = $db->sql_query($sql);
  698. $posts_in_topic = (int) $db->sql_fetchfield('posts_in_topic');
  699. $db->sql_freeresult($result);
  700. if ($posts_in_topic <= 1)
  701. {
  702. $delete_topics[$row['topic_id']] = $row['topic_id'];
  703. continue;
  704. }
  705. }
  706. }
  707. // Keep track of user post counts so we can update them
  708. if ($row['post_postcount'])
  709. {
  710. $post_count[$row['poster_id']] = empty($post_count[$row['poster_id']]) ? 1 : $post_count[$row['poster_id']] + 1;
  711. }
  712. // Mark the post as deleted
  713. $sql = 'UPDATE ' . POSTS_TABLE
  714. . ' SET ' . $db->sql_build_array('UPDATE', $del_info)
  715. . ' WHERE post_id = ' . (int)$row['post_id'];
  716. $db->sql_query($sql);
  717. // Add a log entry if required
  718. if ($log)
  719. {
  720. add_log('mod', $row['forum_id'], $row['topic_id'], 'LOG_POST_STIFLED', $row['post_subject'], $del_info['post_deleted_reason']);
  721. }
  722. $return = !$return ? 'PRIME_DELETED_POST_SUCCESS' : 'PRIME_DELETED_POSTS_SUCCESS';
  723. }
  724. $db->sql_freeresult($result);
  725. // Update user post counts.
  726. stifle_update_post_counts($post_count);
  727. // Time to delete the topics, if need be.
  728. if (!empty($delete_topics))
  729. {
  730. $topic_msg = stifle_topics($delete_topics, $log);
  731. $return = $return . ($return ? '|' : '') . $topic_msg;
  732. }
  733. $return = empty($return) ? 'PRIME_DELETED_POST_FAILURE' : $return;
  734. // Update the last post information for the topics and forums
  735. if (count($sync_topics))
  736. {
  737. global $phpbb_root_path, $phpEx;
  738. if (!function_exists('sync') || !function_exists('move_posts'))
  739. {
  740. include($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
  741. }
  742. sync('topic', 'topic_id', $sync_topics);
  743. sync('forum', 'forum_id', $sync_forums);
  744. }
  745. return($return);
  746. }
  747. /**
  748. */
  749. function mcp_stifle_post($post_ids)
  750. {
  751. global $auth, $user, $db, $template, $phpEx, $phpbb_root_path;
  752. if (!stifle_posts_enabled())
  753. {
  754. return(false);
  755. }
  756. if (empty($post_ids))
  757. {
  758. trigger_error($user->lang['NO_POST_SELECTED']);
  759. }
  760. $user->add_lang('mcp');
  761. $post_ids = is_array($post_ids) ? $post_ids : array($post_ids);
  762. $post_ids_temp = $post_ids; // the check_ids() function will alter the passed in array of ids
  763. $can_full_delete = check_ids($post_ids_temp, POSTS_TABLE, 'post_id', array('a_', 'm_delete_forever'));
  764. // Check if posts are already marked as deleted or if the delete forever checkbox was selected.
  765. if (!($can_be_stifled = can_posts_be_stifled($post_ids)) || request_var('delete_forever', false))
  766. {
  767. if (!$can_full_delete)
  768. {
  769. trigger_error($user->lang['NO_AUTH_OPERATION']);
  770. }
  771. return(false); // Return to allow normal, permanent deletion
  772. }
  773. if (!check_ids($post_ids, POSTS_TABLE, 'post_id', array('m_delete')))
  774. {
  775. trigger_error($user->lang['NO_AUTH_OPERATION']);
  776. }
  777. $user->add_lang('mods/prime_trash_bin_b');
  778. $redirect = request_var('redirect', build_url(array('_f_', 'action', 'quickmod')));
  779. $forum_id = request_var('f', 0);
  780. $topic_id = request_var('t', 0);
  781. if (confirm_box(true))
  782. {
  783. $result_msg = stifle_posts($post_ids, 'post_id', true);
  784. if (strpos($result_msg, 'TOPIC') !== false)
  785. {
  786. $return_link[] = sprintf($user->lang['RETURN_TOPIC'], '<a href="' . append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&amp;t=$topic_id") . '">', '</a>');
  787. $result_msg .= '|' . 'EMPTY_TOPICS_REMOVED_WARNING';
  788. }
  789. if (strpos($result_msg, 'SUCCESS') !== false)
  790. {
  791. meta_refresh(3, $redirect);
  792. }
  793. $return_link[] = sprintf($user->lang['RETURN_FORUM'], '<a href="' . append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id) . '">', '</a>');
  794. $message = '';
  795. foreach(explode('|', $result_msg) as $msg)
  796. {
  797. $message .= ($message ? '<br /><br />' : '') . (isset($user->lang[$msg]) ? $user->lang[$msg] : $msg);
  798. }
  799. trigger_error($message . '<br /><br />' . sprintf($user->lang['RETURN_PAGE'], '<a href="' . $redirect . '">', '</a>') . '<br /><br />' . implode('<br /><br />', $return_link));
  800. }
  801. else
  802. {
  803. $s_hidden_fields = build_hidden_fields(array(
  804. 'post_id_list' => $post_ids,
  805. 'f' => $forum_id,
  806. 'action' => 'delete_post',
  807. 'redirect' => $redirect)
  808. );
  809. if ($can_be_stifled !== true)
  810. {
  811. $template->assign_var('ADDITIONAL_MSG', $user->lang['PRIME_DELETE_POST_MIX_NOTICE']);
  812. }
  813. if ($can_full_delete)
  814. {
  815. $template->assign_vars(array('S_CAN_DELETE_FOREVER' => true, 'L_PRIME_DELETE_FOREVER' => ($user->lang[sizeof($post_ids) == 1 ? 'PRIME_DELETE_POST_FOREVER' : 'PRIME_DELETE_POSTS_FOREVER'])));
  816. }
  817. $template->assign_var('L_PRIME_DELETE_REASON', $user->lang['PRIME_DELETE_POST_REASON']);
  818. confirm_box(false, (sizeof($post_ids) == 1) ? 'DELETE_POST' : 'DELETE_POSTS', $s_hidden_fields, 'prime_delete_confirm.html');
  819. }
  820. }
  821. /**
  822. */
  823. function unstifle_posts($post_ids, $log = false)
  824. {
  825. global $db, $phpbb_root_path, $phpEx;
  826. if (empty($post_ids))
  827. {
  828. return('NO_POST_SELECTED');
  829. }
  830. $post_ids = is_array($post_ids) ? $post_ids : array($post_ids);
  831. $sync_topics = array();
  832. $sync_forums = array();
  833. $move = array();
  834. $updated_info['post_deleted_from'] = 0;
  835. $updated_info['post_deleted_user'] = 0;
  836. $updated_info['post_deleted_time'] = 0;
  837. $updated_info['post_deleted_reason'] = utf8_normalize_nfc(request_var('delete_reason', '', true));
  838. $post_count = array();
  839. $sql = 'SELECT post_id, topic_id, forum_id, post_deleted_from, post_subject, poster_id, post_postcount'
  840. . ' FROM ' . POSTS_TABLE
  841. . ' WHERE post_deleted_time > 0'
  842. . ' AND ' . $db->sql_in_set('post_id', $post_ids);
  843. $result = $db->sql_query($sql);
  844. while ($row = $db->sql_fetchrow($result))
  845. {
  846. if (auth_fake_delete('undelete', $row['forum_id']))
  847. {
  848. if ($row['post_postcount'])
  849. {
  850. $post_count[$row['poster_id']] = empty($post_count[$row['poster_id']]) ? 1 : $post_count[$row['poster_id']] + 1;
  851. }
  852. $sql = 'UPDATE ' . POSTS_TABLE
  853. . ' SET ' . $db->sql_build_array('UPDATE', $updated_info)
  854. . ' WHERE post_id = ' . (int)$row['post_id'];
  855. $db->sql_query($sql);
  856. //if (is_trash_forum($row['forum_id']))
  857. //{
  858. // $move[$row['topic_deleted_from']][] = $row['topic_id'];
  859. //}
  860. $sync_topics[] = $row['topic_id'];
  861. $sync_forums[] = $row['forum_id'];
  862. $sync_forums[] = $row['post_deleted_from'];
  863. $success = true;
  864. if ($log)
  865. {
  866. add_log('mod', $row['forum_id'], $row['topic_id'], 'LOG_POST_UNSTIFLED', $row['post_subject'], $updated_info['post_deleted_reason']);
  867. }
  868. }
  869. }
  870. $db->sql_freeresult($result);
  871. // Update user post counts.
  872. unstifle_update_post_counts($post_count);
  873. // Get out of here if nothing happened.
  874. if (empty($success))
  875. {
  876. return(sizeof($post_ids) == 1 ? 'PRIME_UNDELETED_POST_FAILURE' : 'PRIME_UNDELETED_POSTS_FAILURE');
  877. }
  878. // Update the last post information for the topics and forums
  879. if (count($sync_topics))
  880. {
  881. if (!function_exists('sync') || !function_exists('move_posts'))
  882. {
  883. include($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
  884. }
  885. // Move posts back to their pre-deletion topics
  886. //foreach ($move as $forum_id => $topic_ids)
  887. //{
  888. // move_topics($topic_ids, $forum_id);
  889. //}
  890. sync('topic', 'topic_id', $sync_topics);
  891. sync('forum', 'forum_id', $sync_forums);
  892. }
  893. return((sizeof($post_ids) == 1) ? 'PRIME_UNDELETED_POST_SUCCESS' : 'PRIME_UNDELETED_POST_SUCCESS');
  894. }
  895. /**
  896. */
  897. function mcp_unstifle_post($post_ids, $forum_id = 0)
  898. {
  899. global $user, $template, $phpEx, $phpbb_root_path;
  900. $user->add_lang('mcp');
  901. $user->add_lang('mods/prime_trash_bin_b');
  902. if (empty($post_ids))
  903. {
  904. trigger_error($user->lang['NO_POST_SELECTED']);
  905. }
  906. $post_ids = is_array($post_ids) ? $post_ids : array($post_ids);
  907. $forum_id = request_var('f', 0);
  908. if (function_exists('check_ids') && !check_ids($post_ids, POSTS_TABLE, 'post_id', array('a_', 'm_undelete')))
  909. {
  910. trigger_error($user->lang['NO_AUTH_OPERATION']);
  911. }
  912. if(!auth_fake_delete('undelete', $forum_id))
  913. {
  914. trigger_error($user->lang['NO_AUTH_OPERATION']);
  915. }
  916. if (!are_posts_stifled($post_ids))
  917. {
  918. trigger_error($user->lang['PRIME_UNDELETE_POSTS_UNNEEDED']);
  919. }
  920. $redirect = request_var('redirect', build_url(array('_f_', 'action', 'quickmod')));
  921. $topic_id = request_var('t', 0);
  922. $message = '';
  923. if (confirm_box(true))
  924. {
  925. $message = unstifle_posts($post_ids, true);
  926. }
  927. else
  928. {
  929. $s_hidden_fields = build_hidden_fields(array(
  930. 'post_id_list' => $post_ids,
  931. 'f' => $forum_id,
  932. 't' => $topic_id,
  933. 'action' => 'undelete_post',
  934. 'redirect' => $redirect,
  935. ));
  936. $template->assign_var('L_PRIME_DELETE_REASON', $user->lang['PRIME_UNDELETE_POST_REASON']);
  937. confirm_box(false, (sizeof($post_ids) == 1) ? 'PRIME_UNDELETE_POST' : 'PRIME_UNDELETE_POSTS', $s_hidden_fields, 'prime_delete_confirm.html');
  938. }
  939. $redirect = reapply_sid($redirect);
  940. if (!$message)
  941. {
  942. redirect($redirect);
  943. }
  944. else
  945. {
  946. meta_refresh(3, $redirect);
  947. $message = $user->lang[$message];
  948. $message .= '<br /><br />' . sprintf($user->lang['RETURN_PAGE'], '<a href="' . $redirect . '">', '</a>');
  949. $message .= empty($topic_id) ? '' : '<br /><br />' . sprintf($user->lang['RETURN_TOPIC'], '<a href="' . append_sid("{$phpbb_root_path}viewtopic.$phpEx", "t=$topic_id") . '">', '</a>');
  950. $message .= empty($forum_id) ? '' : '<br /><br />' . sprintf($user->lang['RETURN_FORUM'], '<a href="' . append_sid("{$phpbb_root_path}viewforum.$phpEx", "f=$forum_id") . '">', '</a>');
  951. trigger_error($message);
  952. }
  953. }
  954. /**
  955. */
  956. function stifle_post($forum_id, $topic_id, $post_id, &$data, $log = false)
  957. {
  958. global $user;
  959. //$post_mode = ($data['topic_first_post_id'] == $data['topic_last_post_id']) ? 'delete_topic' : (($data['topic_first_post_id'] == $post_id) ? 'delete_first_post' : (($data['topic_last_post_id'] == $post_id) ? 'delete_last_post' : 'delete'));
  960. $next_post_id = $post_id;
  961. $result_msg = stifle_posts($post_id, 'post_id', $log);
  962. //switch ($post_mode)
  963. //{
  964. // case 'delete_topic':
  965. // break;
  966. //
  967. // case 'delete_first_post':
  968. // break;
  969. //
  970. // case 'delete_last_post':
  971. // break;
  972. //
  973. // case 'delete':
  974. // break;
  975. //}
  976. return($next_post_id);
  977. }
  978. /**
  979. */
  980. function handle_post_stifle($forum_id, $topic_id, $post_id, &$post_data)
  981. {
  982. global $user, $db, $auth, $phpbb_root_path, $phpEx, $template;
  983. $delete_forever = (request_var('delete_forever', false) && auth_fake_delete('delete', $forum_id));
  984. if (!stifle_posts_enabled() || $delete_forever)
  985. {
  986. return(false);
  987. }
  988. $user->add_lang('mods/prime_trash_bin_b');
  989. // The post can only be permanently deleted, so check for permission
  990. if (!can_stifle_post($post_data))
  991. {
  992. // If user can permanent delete then move on like we were never here.
  993. if (auth_fake_delete('delete', $forum_id))
  994. {
  995. return(false);
  996. }
  997. trigger_error($user->lang['PRIME_DELETE_POST_FOREVER_DENIED']);
  998. }
  999. // This is the only post in the topic AND the user is a moderator
  1000. // so lets do a topic deletion instead.
  1001. if($auth->acl_get('m_delete', $forum_id) && !empty($post_data['topic_first_post_id']) && !empty($post_data['topic_last_post_id']) && $post_data['topic_first_post_id'] == $post_data['topic_last_post_id'])
  1002. {
  1003. $sql = 'SELECT COUNT(post_id) AS posts_in_topic FROM ' . POSTS_TABLE . ' WHERE topic_id = ' . (int)$topic_id . ' AND post_approved = 1 AND post_deleted_time = 0';
  1004. $result = $db->sql_query($sql);
  1005. $posts_in_topic = (int) $db->sql_fetchfield('posts_in_topic');
  1006. $db->sql_freeresult($result);
  1007. if ($posts_in_topic <= 1)
  1008. {
  1009. mcp_stifle_topic($topic_id, true);
  1010. return(true);
  1011. }
  1012. }
  1013. // If moderator removing post or user itself removing post, present a confirmation screen
  1014. // These are normal delete permissions, since we're not permanent deleting.
  1015. if ($auth->acl_get('m_delete', $forum_id) || ($post_data['poster_id'] == $user->data['user_id'] && $user->data['is_registered'] && $auth->acl_get('f_delete', $forum_id) && $post_id == $post_data['topic_last_post_id']))
  1016. {
  1017. if (confirm_box(true))
  1018. {
  1019. $data = array(
  1020. 'user_id' => $user->data['user_id'],
  1021. 'topic_first_post_id' => $post_data['topic_first_post_id'],
  1022. 'topic_last_post_id' => $post_data['topic_last_post_id'],
  1023. 'topic_approved' => $post_data['topic_approved'],
  1024. 'topic_type' => $post_data['topic_type'],
  1025. 'post_approved' => $post_data['post_approved'],
  1026. 'post_reported' => $post_data['post_reported'],
  1027. 'post_time' => $post_data['post_time'],
  1028. 'poster_id' => $post_data['poster_id'],
  1029. 'post_postcount' => $post_data['post_postcount']
  1030. );
  1031. $next_post_id = stifle_post($forum_id, $topic_id, $post_id, $data, true);
  1032. if ($post_data['topic_first_post_id'] == $post_data['topic_last_post_id'])
  1033. {
  1034. //add_log('mod', $forum_id, $topic_id, (stifle_topics_enabled() ? 'LOG_TOPIC_STIFLED' : 'LOG_DELETE_TOPIC'), $post_data['topic_title']);
  1035. $meta_info = append_sid("{$phpbb_root_path}viewforum.$phpEx", "f=$forum_id");
  1036. $message = $user->lang['PRIME_DELETED_POST_SUCCESS'];
  1037. }
  1038. else
  1039. {
  1040. //add_log('mod', $forum_id, $topic_id, 'LOG_POST_STIFLED', $post_data['post_subject']);
  1041. $meta_info = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&amp;t=$topic_id&amp;p=$next_post_id") . "#p$next_post_id";
  1042. $message = $user->lang['PRIME_DELETED_POST_SUCCESS'] . '<br /><br />' . sprintf($user->lang['RETURN_TOPIC'], '<a href="' . $meta_info . '">', '</a>');
  1043. }
  1044. meta_refresh(3, $meta_info);
  1045. $message .= '<br /><br />' . sprintf($user->lang['RETURN_FORUM'], '<a href="' . append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id) . '">', '</a>');
  1046. trigger_error($message);
  1047. }
  1048. else
  1049. {
  1050. $s_hidden_fields = build_hidden_fields(array(
  1051. 'p' => $post_id,
  1052. 'f' => $forum_id,
  1053. 'mode' => 'delete',
  1054. ));
  1055. if (auth_fake_delete('delete', $forum_id))
  1056. {
  1057. global $template;
  1058. $template->assign_vars(array('S_CAN_DELETE_FOREVER' => true, 'L_PRIME_DELETE_FOREVER' => $user->lang['PRIME_DELETE_POST_FOREVER']));
  1059. }
  1060. $template->assign_var('L_PRIME_DELETE_REASON', $user->lang['PRIME_DELETE_POST_REASON']);
  1061. confirm_box(false, 'DELETE_MESSAGE', $s_hidden_fields, 'prime_delete_confirm.html');
  1062. }
  1063. }
  1064. // If we are here the user is not able to delete - present the correct error message
  1065. if ($post_data['poster_id'] != $user->data['user_id'] && $auth->acl_get('f_delete', $forum_id))
  1066. {
  1067. trigger_error('DELETE_OWN_POSTS');
  1068. }
  1069. if ($post_data['poster_id'] == $user->data['user_id'] && $auth->acl_get('f_delete', $forum_id) && $post_id != $post_data['topic_last_post_id'])
  1070. {
  1071. trigger_error('CANNOT_DELETE_REPLIED');
  1072. }
  1073. trigger_error('USER_CANNOT_DELETE');
  1074. }
  1075. }
  1076. ?>