[feature/soft-delete] Allow to soft delete posts in the MCP quick moderation

PHPBB3-9567
This commit is contained in:
Joas Schilling 2012-10-30 21:46:04 +01:00
parent ed602857e6
commit f0e2d21f8c
3 changed files with 90 additions and 7 deletions

View file

@ -125,14 +125,18 @@ class mcp_main
case 'delete_post': case 'delete_post':
$user->add_lang('posting'); $user->add_lang('posting');
// f parameter is not reliable for permission usage, however we just use it to decide
// which permission we will check later on. So if it is manipulated, we will still catch it later on.
$forum_id = request_var('f', 0);
$post_ids = (!$quickmod) ? request_var('post_id_list', array(0)) : array(request_var('p', 0)); $post_ids = (!$quickmod) ? request_var('post_id_list', array(0)) : array(request_var('p', 0));
$soft_delete = (($auth->acl_get('m_softdelete', $forum_id) && $request->is_set_post('soft_delete')) || !$auth->acl_get('m_delete', $forum_id)) ? true : false;
if (!sizeof($post_ids)) if (!sizeof($post_ids))
{ {
trigger_error('NO_POST_SELECTED'); trigger_error('NO_POST_SELECTED');
} }
mcp_delete_post($post_ids); mcp_delete_post($post_ids, $soft_delete, ($soft_delete) ? request_var('delete_reason', '', true) : '');
break; break;
case 'restore_topic': case 'restore_topic':
@ -823,11 +827,11 @@ function mcp_delete_topic($topic_ids, $is_soft = false, $soft_delete_reason = ''
/** /**
* Delete Posts * Delete Posts
*/ */
function mcp_delete_post($post_ids) function mcp_delete_post($post_ids, $is_soft = false, $soft_delete_reason = '')
{ {
global $auth, $user, $db, $phpEx, $phpbb_root_path; global $auth, $user, $db, $phpEx, $phpbb_root_path;
if (!check_ids($post_ids, POSTS_TABLE, 'post_id', array('m_delete'))) if (!check_ids($post_ids, POSTS_TABLE, 'post_id', array('m_softdelete')))
{ {
return; return;
} }
@ -843,7 +847,72 @@ function mcp_delete_post($post_ids)
); );
$success_msg = ''; $success_msg = '';
if (confirm_box(true)) if (confirm_box(true) && $is_soft)
{
$post_info = get_post_data($post_ids);
$topic_info = $approve_log = array();
// Group the posts by topic_id
foreach ($post_info as $post_id => $post_data)
{
if ($post_data['post_visibility'] != ITEM_APPROVED)
{
continue;
}
$topic_id = (int) $post_data['topic_id'];
$topic_info[$topic_id]['posts'][] = (int) $post_id;
$topic_info[$topic_id]['forum_id'] = (int) $post_data['forum_id'];
if ($post_id == $post_data['topic_first_post_id'])
{
$topic_info[$topic_id]['first_post'] = true;
}
if ($post_id == $post_data['topic_last_post_id'])
{
$topic_info[$topic_id]['last_post'] = true;
}
$approve_log[] = array(
'forum_id' => $post_data['forum_id'],
'topic_id' => $post_data['topic_id'],
'post_subject' => $post_data['post_subject'],
'poster_id' => $post_data['poster_id'],
'post_username' => $post_data['post_username'],
'username' => $post_data['username'],
);
}
foreach ($topic_info as $topic_id => $topic_data)
{
phpbb_content_visibility::set_post_visibility(ITEM_DELETED, $topic_data['posts'], $topic_id, $topic_data['forum_id'], $user->data['user_id'], time(), $soft_delete_reason, isset($topic_data['first_post']), isset($topic_data['last_post']));
}
$affected_topics = sizeof($topic_info);
// None of the topics is really deleted, so a redirect won't hurt much.
$deleted_topics = 0;
$success_msg = (sizeof($post_info) == 1) ? 'POST_DELETED_SUCCESS' : 'POSTS_DELETED_SUCCESS';
foreach ($approve_log as $row)
{
$post_username = ($row['poster_id'] == ANONYMOUS && !empty($row['post_username'])) ? $row['post_username'] : $row['username'];
add_log('mod', $row['forum_id'], $row['topic_id'], 'LOG_SOFTDELETE_POST', $row['post_subject'], $post_username);
}
$topic_id = request_var('t', 0);
// Return links
$return_link = array();
if ($affected_topics == 1 && $topic_id)
{
$return_link[] = sprintf($user->lang['RETURN_TOPIC'], '<a href="' . append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&amp;t=$topic_id") . '">', '</a>');
}
$return_link[] = sprintf($user->lang['RETURN_FORUM'], '<a href="' . append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id) . '">', '</a>');
}
else if (confirm_box(true))
{ {
if (!function_exists('delete_posts')) if (!function_exists('delete_posts'))
{ {
@ -924,7 +993,18 @@ function mcp_delete_post($post_ids)
} }
else else
{ {
confirm_box(false, (sizeof($post_ids) == 1) ? 'DELETE_POST' : 'DELETE_POSTS', $s_hidden_fields); global $template;
$user->add_lang('posting');
$template->assign_vars(array(
'S_TOPIC_MODE' => true,
'S_ALLOWED_DELETE' => $auth->acl_get('m_delete', $forum_id),
'S_ALLOWED_SOFTDELETE' => $auth->acl_get('m_softdelete', $forum_id),
'S_DELETE_REASON' => $auth->acl_get('m_softdelete', $forum_id),
));
confirm_box(false, (sizeof($post_ids) == 1) ? 'DELETE_POST' : 'DELETE_POSTS', $s_hidden_fields, 'posting_delete_post_body.html');
} }
$redirect = request_var('redirect', "index.$phpEx"); $redirect = request_var('redirect', "index.$phpEx");

View file

@ -242,7 +242,8 @@ function mcp_topic_view($id, $mode, $action)
'MINI_POST_IMG' => ($post_unread) ? $user->img('icon_post_target_unread', 'UNREAD_POST') : $user->img('icon_post_target', 'POST'), 'MINI_POST_IMG' => ($post_unread) ? $user->img('icon_post_target_unread', 'UNREAD_POST') : $user->img('icon_post_target', 'POST'),
'S_POST_REPORTED' => ($row['post_reported'] && $auth->acl_get('m_report', $topic_info['forum_id'])), 'S_POST_REPORTED' => ($row['post_reported'] && $auth->acl_get('m_report', $topic_info['forum_id'])),
'S_POST_UNAPPROVED' => ($row['post_visibility'] != ITEM_APPROVED && $auth->acl_get('m_approve', $topic_info['forum_id'])), 'S_POST_UNAPPROVED' => ($row['post_visibility'] == ITEM_UNAPPROVED && $auth->acl_get('m_approve', $topic_info['forum_id'])),
'S_POST_DELETED' => ($row['post_visibility'] == ITEM_DELETED && $auth->acl_get('m_approve', $topic_info['forum_id'])),
'S_CHECKED' => (($submitted_id_list && !in_array(intval($row['post_id']), $submitted_id_list)) || in_array(intval($row['post_id']), $checked_ids)) ? true : false, 'S_CHECKED' => (($submitted_id_list && !in_array(intval($row['post_id']), $submitted_id_list)) || in_array(intval($row['post_id']), $checked_ids)) ? true : false,
'S_HAS_ATTACHMENTS' => (!empty($attachments[$row['post_id']])) ? true : false, 'S_HAS_ATTACHMENTS' => (!empty($attachments[$row['post_id']])) ? true : false,
@ -318,6 +319,7 @@ function mcp_topic_view($id, $mode, $action)
'REPORTED_IMG' => $user->img('icon_topic_reported', 'POST_REPORTED'), 'REPORTED_IMG' => $user->img('icon_topic_reported', 'POST_REPORTED'),
'UNAPPROVED_IMG' => $user->img('icon_topic_unapproved', 'POST_UNAPPROVED'), 'UNAPPROVED_IMG' => $user->img('icon_topic_unapproved', 'POST_UNAPPROVED'),
'DELETED_IMG' => $user->img('icon_topic_deleted', 'POST_DELETED'),
'INFO_IMG' => $user->img('icon_post_info', 'VIEW_INFO'), 'INFO_IMG' => $user->img('icon_post_info', 'VIEW_INFO'),
'S_MCP_ACTION' => "$url&amp;i=$id&amp;mode=$mode&amp;action=$action&amp;start=$start", 'S_MCP_ACTION' => "$url&amp;i=$id&amp;mode=$mode&amp;action=$action&amp;start=$start",

View file

@ -110,9 +110,10 @@ onload_functions.push('subPanels()');
<h3><a href="{postrow.U_POST_DETAILS}">{postrow.POST_SUBJECT}</a></h3> <h3><a href="{postrow.U_POST_DETAILS}">{postrow.POST_SUBJECT}</a></h3>
<p class="author"><a href="#pr{postrow.POST_ID}">{postrow.MINI_POST_IMG}</a> {L_POSTED} {postrow.POST_DATE} {L_POST_BY_AUTHOR} <strong>{postrow.POST_AUTHOR_FULL}</strong><!-- IF postrow.U_MCP_DETAILS --> [ <a href="{postrow.U_MCP_DETAILS}">{L_POST_DETAILS}</a> ]<!-- ENDIF --></p> <p class="author"><a href="#pr{postrow.POST_ID}">{postrow.MINI_POST_IMG}</a> {L_POSTED} {postrow.POST_DATE} {L_POST_BY_AUTHOR} <strong>{postrow.POST_AUTHOR_FULL}</strong><!-- IF postrow.U_MCP_DETAILS --> [ <a href="{postrow.U_MCP_DETAILS}">{L_POST_DETAILS}</a> ]<!-- ENDIF --></p>
<!-- IF postrow.S_POST_UNAPPROVED or postrow.S_POST_REPORTED --> <!-- IF postrow.S_POST_UNAPPROVED or postrow.S_POST_DELETED or postrow.S_POST_REPORTED -->
<p class="rules"> <p class="rules">
<!-- IF postrow.S_POST_UNAPPROVED -->{UNAPPROVED_IMG} <a href="{postrow.U_MCP_APPROVE}"><strong>{L_POST_UNAPPROVED}</strong></a><br /><!-- ENDIF --> <!-- IF postrow.S_POST_UNAPPROVED -->{UNAPPROVED_IMG} <a href="{postrow.U_MCP_APPROVE}"><strong>{L_POST_UNAPPROVED}</strong></a><br /><!-- ENDIF -->
<!-- IF postrow.S_POST_DELETED -->{DELETED_IMG} <a href="{postrow.U_MCP_APPROVE}"><strong>{L_POST_DELETED}</strong></a><br /><!-- ENDIF -->
<!-- IF postrow.S_POST_REPORTED -->{REPORTED_IMG} <a href="{postrow.U_MCP_REPORT}"><strong>{L_POST_REPORTED}</strong></a><!-- ENDIF --> <!-- IF postrow.S_POST_REPORTED -->{REPORTED_IMG} <a href="{postrow.U_MCP_REPORT}"><strong>{L_POST_REPORTED}</strong></a><!-- ENDIF -->
</p> </p>
<!-- ENDIF --> <!-- ENDIF -->