From b8c55291ed7ed86565be2bc651bf20eb1a9ed4dd Mon Sep 17 00:00:00 2001 From: Josh Woody Date: Thu, 17 Jun 2010 23:58:18 -0500 Subject: [feature/soft-delete] Lay the groundwork for a soft-delete feature So far, I've added no new functionality. The biggest change here is adjusting the DB column names to "visibility" rather than "approved". Some things here are pretty likely to change, for example the name and location of the topic_visibility class. Happy birthday phpBB :) PHPBB3-9657 --- phpBB/posting.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'phpBB/posting.php') diff --git a/phpBB/posting.php b/phpBB/posting.php index a17578e343..273499c1e4 100644 --- a/phpBB/posting.php +++ b/phpBB/posting.php @@ -86,8 +86,8 @@ switch ($mode) $sql = 'SELECT f.*, t.* FROM ' . TOPICS_TABLE . ' t, ' . FORUMS_TABLE . " f WHERE t.topic_id = $topic_id - AND f.forum_id = t.forum_id" . - (($auth->acl_get('m_approve', $forum_id)) ? '' : ' AND t.topic_approved = 1'); + AND f.forum_id = t.forum_id + AND " . topic_visibility::get_visibility_sql('topic', $forum_id, 't.'); break; case 'quote': @@ -114,8 +114,8 @@ switch ($mode) WHERE p.post_id = $post_id AND t.topic_id = p.topic_id AND u.user_id = p.poster_id - AND f.forum_id = t.forum_id" . - (($auth->acl_get('m_approve', $forum_id)) ? '' : ' AND p.post_approved = 1'); + AND f.forum_id = t.forum_id + AND " . topic_visibility::get_visibility_sql('topic', $forum_id, 't.'); break; case 'smilies': @@ -163,7 +163,7 @@ if (!$post_data) // Not able to reply to unapproved posts/topics // TODO: add more descriptive language key -if ($auth->acl_get('m_approve', $forum_id) && ((($mode == 'reply' || $mode == 'bump') && !$post_data['topic_approved']) || ($mode == 'quote' && !$post_data['post_approved']))) +if ($auth->acl_get('m_approve', $forum_id) && ((($mode == 'reply' || $mode == 'bump') && $post_data['topic_visibility'] == ITEM_UNAPPROVED) || ($mode == 'quote' && $post_data['post_visibility'] == ITEM_UNAPPROVED))) { trigger_error(($mode == 'reply' || $mode == 'bump') ? 'TOPIC_UNAPPROVED' : 'POST_UNAPPROVED'); } @@ -1063,8 +1063,8 @@ if ($submit || $preview || $refresh) 'attachment_data' => $message_parser->attachment_data, 'filename_data' => $message_parser->filename_data, - 'topic_approved' => (isset($post_data['topic_approved'])) ? $post_data['topic_approved'] : false, - 'post_approved' => (isset($post_data['post_approved'])) ? $post_data['post_approved'] : false, + 'topic_visibility' => (isset($post_data['topic_visibility'])) ? $post_data['topic_visibility'] : false, + 'post_visibility' => (isset($post_data['post_visibility'])) ? $post_data['post_visibility'] : false, ); if ($mode == 'edit') @@ -1514,9 +1514,9 @@ function handle_post_delete($forum_id, $topic_id, $post_id, &$post_data) 'topic_first_post_id' => $post_data['topic_first_post_id'], 'topic_last_post_id' => $post_data['topic_last_post_id'], 'topic_replies_real' => $post_data['topic_replies_real'], - 'topic_approved' => $post_data['topic_approved'], + 'topic_visibility' => $post_data['topic_visibility'], 'topic_type' => $post_data['topic_type'], - 'post_approved' => $post_data['post_approved'], + 'post_visibility' => $post_data['post_visibility'], 'post_reported' => $post_data['post_reported'], 'post_time' => $post_data['post_time'], 'poster_id' => $post_data['poster_id'], -- cgit v1.2.1 From c32d76080605f843bb23e9a608c368d4b5dc55d8 Mon Sep 17 00:00:00 2001 From: Josh Woody Date: Sun, 20 Jun 2010 15:01:26 -0500 Subject: [feature/soft-delete] I told you I was going to rename the class! Rename topic_visibility class to phpbb_visibility. Also a bit of work to the class itself, mostly cleanup and adding the comments that I'd previously written. PHPBB3-9657 --- phpBB/posting.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/posting.php') diff --git a/phpBB/posting.php b/phpBB/posting.php index 273499c1e4..30b897c068 100644 --- a/phpBB/posting.php +++ b/phpBB/posting.php @@ -87,7 +87,7 @@ switch ($mode) FROM ' . TOPICS_TABLE . ' t, ' . FORUMS_TABLE . " f WHERE t.topic_id = $topic_id AND f.forum_id = t.forum_id - AND " . topic_visibility::get_visibility_sql('topic', $forum_id, 't.'); + AND " . phpbb_visibility::get_visibility_sql('topic', $forum_id, 't.'); break; case 'quote': @@ -115,7 +115,7 @@ switch ($mode) AND t.topic_id = p.topic_id AND u.user_id = p.poster_id AND f.forum_id = t.forum_id - AND " . topic_visibility::get_visibility_sql('topic', $forum_id, 't.'); + AND " . phpbb_visibility::get_visibility_sql('topic', $forum_id, 't.'); break; case 'smilies': -- cgit v1.2.1 From fb13ab83e476d2afbc7bb181f7ab90df98f996da Mon Sep 17 00:00:00 2001 From: Josh Woody Date: Sun, 27 Jun 2010 14:22:36 -0500 Subject: [feature/soft-delete] Implement the ability to soft-delete and restore posts The soft delete feature seems to work. Tests are pending. A real icon is pending. Add the permissions and the interface to soft-delete posts. Also able to restore posts via the MCP queue PHPBB3-9657 --- phpBB/posting.php | 51 ++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 42 insertions(+), 9 deletions(-) (limited to 'phpBB/posting.php') diff --git a/phpBB/posting.php b/phpBB/posting.php index 30b897c068..221d469b4a 100644 --- a/phpBB/posting.php +++ b/phpBB/posting.php @@ -38,8 +38,20 @@ $load = (isset($_POST['load'])) ? true : false; $delete = (isset($_POST['delete'])) ? true : false; $cancel = (isset($_POST['cancel']) && !isset($_POST['save'])) ? true : false; -$refresh = (isset($_POST['add_file']) || isset($_POST['delete_file']) || isset($_POST['cancel_unglobalise']) || $save || $load || $preview) ? true : false; -$mode = ($delete && !$preview && !$refresh && $submit) ? 'delete' : request_var('mode', ''); +$refresh = (isset($_POST['add_file']) || isset($_POST['delete_file']) || isset($_POST['cancel_unglobalise']) || $save || $load || $preview); +$mode = request_var('mode', ''); + +if ($submit && !$refresh) +{ + if (isset($_POST['soft_delete'])) + { + $mode = 'soft_delete'; + } + else if (isset($_POST['delete'])) + { + $mode = 'delete'; + } +} $error = $post_data = array(); $current_time = time(); @@ -93,6 +105,7 @@ switch ($mode) case 'quote': case 'edit': case 'delete': + case 'soft_delete': if (!$post_id) { $user->setup('posting'); @@ -168,6 +181,13 @@ if ($auth->acl_get('m_approve', $forum_id) && ((($mode == 'reply' || $mode == 'b trigger_error(($mode == 'reply' || $mode == 'bump') ? 'TOPIC_UNAPPROVED' : 'POST_UNAPPROVED'); } +if ($mode == 'edit' && $post_data['post_visibility'] == ITEM_DELETED && !isset($_POST['soft_delete']) && phpbb_visibility::can_restore($forum_id, $post_data['poster_id'], $post_data['post_edit_locked'])) +{ + // don't feel that a confirm_box is needed for this + // do not return / trigger_error after this because the post content can also be changed + phpbb_visibility::unhide_posts_topics('restore', array($post_id => $post_data), array($post_id)); +} + if ($mode == 'popup') { upload_popup($post_data['forum_style']); @@ -259,6 +279,13 @@ switch ($mode) $is_authed = true; } break; + + case 'soft_delete': + if ($user->data['is_registered'] && $auth->acl_gets('f_softdelete', 'm_softdelete', $forum_id)) + { + $is_authed = true; + } + break; } if (!$is_authed) @@ -306,9 +333,9 @@ if ($mode == 'edit' && !$auth->acl_get('m_edit', $forum_id)) } // Handle delete mode... -if ($mode == 'delete') +if ($mode == 'delete' || $mode == 'soft_delete') { - handle_post_delete($forum_id, $topic_id, $post_id, $post_data); + handle_post_delete($forum_id, $topic_id, $post_id, $post_data, ($mode == 'soft_delete')); return; } @@ -1401,6 +1428,10 @@ $template->assign_vars(array( 'S_LOCK_TOPIC_CHECKED' => ($lock_topic_checked) ? ' checked="checked"' : '', 'S_LOCK_POST_ALLOWED' => ($mode == 'edit' && $auth->acl_get('m_edit', $forum_id)) ? true : false, 'S_LOCK_POST_CHECKED' => ($lock_post_checked) ? ' checked="checked"' : '', + 'S_SOFT_DELETE_CHECKED' => ($mode == 'edit' && $post_data['post_visibility'] == ITEM_DELETED) ? ' checked="checked"' : '', + 'S_SOFT_DELETE_ALLOWED' => (phpbb_visibility::can_soft_delete($forum_id, $post_data['poster_id'], $lock_post_checked)) ? true : false, + 'S_RESTORE_ALLOWED' => (phpbb_visibility::can_restore($forum_id, $post_data['poster_id'], $lock_post_checked)) ? true : false, + 'S_IS_DELETED' => ($post_data['post_visibility'] == POST_DELETED) ? true : false, 'S_LINKS_ALLOWED' => $url_status, 'S_MAGIC_URL_CHECKED' => ($urls_checked) ? ' checked="checked"' : '', 'S_TYPE_TOGGLE' => $topic_type_toggle, @@ -1494,19 +1525,21 @@ function upload_popup($forum_style = 0) /** * Do the various checks required for removing posts as well as removing it */ -function handle_post_delete($forum_id, $topic_id, $post_id, &$post_data) +function handle_post_delete($forum_id, $topic_id, $post_id, &$post_data, $is_soft) { global $user, $db, $auth, $config; global $phpbb_root_path, $phpEx; + $perm_check = ($is_soft) ? 'softdelete' : 'delete'; + // If moderator removing post or user itself removing post, present a confirmation screen - 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'] && !$post_data['post_edit_locked'] && ($post_data['post_time'] > time() - ($config['delete_time'] * 60) || !$config['delete_time']))) + if ($auth->acl_get("m_$perm_check", $forum_id) || ($post_data['poster_id'] == $user->data['user_id'] && $user->data['is_registered'] && $auth->acl_get("f_$perm_check", $forum_id) && $post_id == $post_data['topic_last_post_id'] && !$post_data['post_edit_locked'] && ($post_data['post_time'] > time() - ($config['delete_time'] * 60) || !$config['delete_time']))) { $s_hidden_fields = build_hidden_fields(array( 'p' => $post_id, 'f' => $forum_id, - 'mode' => 'delete') - ); + 'mode' => ($is_soft) ? 'soft_delete' : 'delete', + )); if (confirm_box(true)) { @@ -1523,7 +1556,7 @@ function handle_post_delete($forum_id, $topic_id, $post_id, &$post_data) 'post_postcount' => $post_data['post_postcount'] ); - $next_post_id = delete_post($forum_id, $topic_id, $post_id, $data); + $next_post_id = delete_post($forum_id, $topic_id, $post_id, $data, $is_soft); $post_username = ($post_data['poster_id'] == ANONYMOUS && !empty($post_data['post_username'])) ? $post_data['post_username'] : $post_data['username']; if ($next_post_id === false) -- cgit v1.2.1 From a80cfafdd91a384ba810a8ee0d43406bba955faa Mon Sep 17 00:00:00 2001 From: Josh Woody Date: Wed, 30 Jun 2010 13:38:49 -0500 Subject: [feature/soft-delete] Rename phpbb_visibility class to phpbb_content_visibility Rename the class to more accurately reflect what it does. PHPBB3-9657 --- phpBB/posting.php | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'phpBB/posting.php') diff --git a/phpBB/posting.php b/phpBB/posting.php index 221d469b4a..877ebc6404 100644 --- a/phpBB/posting.php +++ b/phpBB/posting.php @@ -99,7 +99,7 @@ switch ($mode) FROM ' . TOPICS_TABLE . ' t, ' . FORUMS_TABLE . " f WHERE t.topic_id = $topic_id AND f.forum_id = t.forum_id - AND " . phpbb_visibility::get_visibility_sql('topic', $forum_id, 't.'); + AND " . phpbb_content_visibility::get_visibility_sql('topic', $forum_id, 't.'); break; case 'quote': @@ -128,7 +128,7 @@ switch ($mode) AND t.topic_id = p.topic_id AND u.user_id = p.poster_id AND f.forum_id = t.forum_id - AND " . phpbb_visibility::get_visibility_sql('topic', $forum_id, 't.'); + AND " . phpbb_content_visibility::get_visibility_sql('topic', $forum_id, 't.'); break; case 'smilies': @@ -181,13 +181,6 @@ if ($auth->acl_get('m_approve', $forum_id) && ((($mode == 'reply' || $mode == 'b trigger_error(($mode == 'reply' || $mode == 'bump') ? 'TOPIC_UNAPPROVED' : 'POST_UNAPPROVED'); } -if ($mode == 'edit' && $post_data['post_visibility'] == ITEM_DELETED && !isset($_POST['soft_delete']) && phpbb_visibility::can_restore($forum_id, $post_data['poster_id'], $post_data['post_edit_locked'])) -{ - // don't feel that a confirm_box is needed for this - // do not return / trigger_error after this because the post content can also be changed - phpbb_visibility::unhide_posts_topics('restore', array($post_id => $post_data), array($post_id)); -} - if ($mode == 'popup') { upload_popup($post_data['forum_style']); @@ -891,6 +884,13 @@ if ($submit || $preview || $refresh) $error[] = $user->lang['FORM_INVALID']; } + if ($submit && $mode == 'edit' && $post_data['post_visibility'] == ITEM_DELETED && !isset($_POST['soft_delete']) && phpbb_content_visibility::can_restore($forum_id, $post_data['poster_id'], $post_data['post_edit_locked'])) + { + // don't feel that a confirm_box is needed for this + // do not return / trigger_error after this because the post content can also be changed + phpbb_content_visibility::unhide_posts_topics('restore', array($post_id => $post_data), array($post_id)); + } + // Parse subject if (!$preview && !$refresh && utf8_clean_string($post_data['post_subject']) === '' && ($mode == 'post' || ($mode == 'edit' && $post_data['topic_first_post_id'] == $post_id))) { @@ -1429,8 +1429,8 @@ $template->assign_vars(array( 'S_LOCK_POST_ALLOWED' => ($mode == 'edit' && $auth->acl_get('m_edit', $forum_id)) ? true : false, 'S_LOCK_POST_CHECKED' => ($lock_post_checked) ? ' checked="checked"' : '', 'S_SOFT_DELETE_CHECKED' => ($mode == 'edit' && $post_data['post_visibility'] == ITEM_DELETED) ? ' checked="checked"' : '', - 'S_SOFT_DELETE_ALLOWED' => (phpbb_visibility::can_soft_delete($forum_id, $post_data['poster_id'], $lock_post_checked)) ? true : false, - 'S_RESTORE_ALLOWED' => (phpbb_visibility::can_restore($forum_id, $post_data['poster_id'], $lock_post_checked)) ? true : false, + 'S_SOFT_DELETE_ALLOWED' => (phpbb_content_visibility::can_soft_delete($forum_id, $post_data['poster_id'], $lock_post_checked)) ? true : false, + 'S_RESTORE_ALLOWED' => (phpbb_content_visibility::can_restore($forum_id, $post_data['poster_id'], $lock_post_checked)) ? true : false, 'S_IS_DELETED' => ($post_data['post_visibility'] == POST_DELETED) ? true : false, 'S_LINKS_ALLOWED' => $url_status, 'S_MAGIC_URL_CHECKED' => ($urls_checked) ? ' checked="checked"' : '', -- cgit v1.2.1 From 1ab41f8dc6ec81f2aaf152229d5f0275de796c85 Mon Sep 17 00:00:00 2001 From: Josh Woody Date: Sat, 17 Jul 2010 14:34:36 -0500 Subject: [feature/soft-delete] Fix some small bugs To wit: using non-existing constant POST_DELETED in posting.php; first test post was initially unapproved; soft delete checkbox appeared at post time Links pointing to the wrong place. PHPBB3-9657 --- phpBB/posting.php | 50 +++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 47 insertions(+), 3 deletions(-) (limited to 'phpBB/posting.php') diff --git a/phpBB/posting.php b/phpBB/posting.php index 877ebc6404..095fc06a3f 100644 --- a/phpBB/posting.php +++ b/phpBB/posting.php @@ -886,9 +886,52 @@ if ($submit || $preview || $refresh) if ($submit && $mode == 'edit' && $post_data['post_visibility'] == ITEM_DELETED && !isset($_POST['soft_delete']) && phpbb_content_visibility::can_restore($forum_id, $post_data['poster_id'], $post_data['post_edit_locked'])) { + // if this is the first post of the topic, restore the whole topic + if ($post_id == $post_data['topic_first_post_id']) + { + // that means we need to gather data for all posts in the topic, not + // just the one being edited + $sql = 'SELECT post_id, poster_id, post_subject, post_postcount + FROM ' . POSTS_TABLE . ' + WHERE topic_id = ' . $post_data['topic_id'] . ' + AND post_visibility = ' . ITEM_DELETED; + $result = $db->sql_query($sql); + + $post_ids = array(); + + while ($row = $db->sql_fetchrow($result)) + { + $post_ids[] = $row['post_id']; + + $posts_data[$row['post_id']] = array( + // all posts are from the same topic and forum + // and are deleted because of the constraints to the query above + 'topic_id' => $post_data['topic_id'], + 'forum_id' => $post_data['forum_id'], + 'topic_replies' => $post_data['topic_replies'], + 'topic_first_post_id' => $post_data['topic_first_post_id'], + 'post_visibility' => ITEM_DELETED, + + 'poster_id' => $row['poster_id'], + 'post_subject' => $row['post_subject'], + 'post_postcount'=> $row['post_postcount'], + ); + } + + // No direct query is needed, just update the array + $post_data['post_visibility'] = $post_data['topic_visibility'] = ITEM_APPROVED; + } + else + { + $post_ids = array($post_id); + $posts_data = array($post_id => $post_data); + + $post_data['post_visibility'] = ITEM_APPROVED; + } + // don't feel that a confirm_box is needed for this // do not return / trigger_error after this because the post content can also be changed - phpbb_content_visibility::unhide_posts_topics('restore', array($post_id => $post_data), array($post_id)); + phpbb_content_visibility::unhide_posts_topics('restore', $posts_data, $post_ids); } // Parse subject @@ -1429,9 +1472,9 @@ $template->assign_vars(array( 'S_LOCK_POST_ALLOWED' => ($mode == 'edit' && $auth->acl_get('m_edit', $forum_id)) ? true : false, 'S_LOCK_POST_CHECKED' => ($lock_post_checked) ? ' checked="checked"' : '', 'S_SOFT_DELETE_CHECKED' => ($mode == 'edit' && $post_data['post_visibility'] == ITEM_DELETED) ? ' checked="checked"' : '', - 'S_SOFT_DELETE_ALLOWED' => (phpbb_content_visibility::can_soft_delete($forum_id, $post_data['poster_id'], $lock_post_checked)) ? true : false, + 'S_SOFT_DELETE_ALLOWED' => ($mode == 'edit' && phpbb_content_visibility::can_soft_delete($forum_id, $post_data['poster_id'], $lock_post_checked)) ? true : false, 'S_RESTORE_ALLOWED' => (phpbb_content_visibility::can_restore($forum_id, $post_data['poster_id'], $lock_post_checked)) ? true : false, - 'S_IS_DELETED' => ($post_data['post_visibility'] == POST_DELETED) ? true : false, + 'S_IS_DELETED' => ($mode == 'edit' && $post_data['post_visibility'] == ITEM_DELETED) ? true : false, 'S_LINKS_ALLOWED' => $url_status, 'S_MAGIC_URL_CHECKED' => ($urls_checked) ? ' checked="checked"' : '', 'S_TYPE_TOGGLE' => $topic_type_toggle, @@ -1547,6 +1590,7 @@ function handle_post_delete($forum_id, $topic_id, $post_id, &$post_data, $is_sof 'topic_first_post_id' => $post_data['topic_first_post_id'], 'topic_last_post_id' => $post_data['topic_last_post_id'], 'topic_replies_real' => $post_data['topic_replies_real'], + 'topic_replies' => $post_data['topic_replies'], 'topic_visibility' => $post_data['topic_visibility'], 'topic_type' => $post_data['topic_type'], 'post_visibility' => $post_data['post_visibility'], -- cgit v1.2.1 From 05f236675528b5af68ba5f0ff140eb8c51ab92b1 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 5 Oct 2012 14:42:11 +0200 Subject: [feature/soft-delete] Update docs of can_soft_delete and remove can_restore PHPBB3-9567 --- phpBB/posting.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'phpBB/posting.php') diff --git a/phpBB/posting.php b/phpBB/posting.php index 095fc06a3f..c09ddb91ff 100644 --- a/phpBB/posting.php +++ b/phpBB/posting.php @@ -884,8 +884,9 @@ if ($submit || $preview || $refresh) $error[] = $user->lang['FORM_INVALID']; } - if ($submit && $mode == 'edit' && $post_data['post_visibility'] == ITEM_DELETED && !isset($_POST['soft_delete']) && phpbb_content_visibility::can_restore($forum_id, $post_data['poster_id'], $post_data['post_edit_locked'])) + if ($submit && $mode == 'edit' && $post_data['post_visibility'] == ITEM_DELETED && !isset($_POST['soft_delete']) && $auth->acl_get('m_approve', $forum_id)) { + //@todo: REMOVE the magic! // if this is the first post of the topic, restore the whole topic if ($post_id == $post_data['topic_first_post_id']) { @@ -1471,10 +1472,10 @@ $template->assign_vars(array( 'S_LOCK_TOPIC_CHECKED' => ($lock_topic_checked) ? ' checked="checked"' : '', 'S_LOCK_POST_ALLOWED' => ($mode == 'edit' && $auth->acl_get('m_edit', $forum_id)) ? true : false, 'S_LOCK_POST_CHECKED' => ($lock_post_checked) ? ' checked="checked"' : '', - 'S_SOFT_DELETE_CHECKED' => ($mode == 'edit' && $post_data['post_visibility'] == ITEM_DELETED) ? ' checked="checked"' : '', - 'S_SOFT_DELETE_ALLOWED' => ($mode == 'edit' && phpbb_content_visibility::can_soft_delete($forum_id, $post_data['poster_id'], $lock_post_checked)) ? true : false, - 'S_RESTORE_ALLOWED' => (phpbb_content_visibility::can_restore($forum_id, $post_data['poster_id'], $lock_post_checked)) ? true : false, - 'S_IS_DELETED' => ($mode == 'edit' && $post_data['post_visibility'] == ITEM_DELETED) ? true : false, + 'S_SOFT_DELETE_CHECKED' => ($mode == 'edit' && $post_data['post_visibility'] == ITEM_DELETED) ? ' checked="checked"' : '', + 'S_SOFT_DELETE_ALLOWED' => ($mode == 'edit' && phpbb_content_visibility::can_soft_delete($forum_id, $post_data['poster_id'], $lock_post_checked)) ? true : false, + 'S_RESTORE_ALLOWED' => $auth->acl_get('m_approve', $forum_id), + 'S_IS_DELETED' => ($mode == 'edit' && $post_data['post_visibility'] == ITEM_DELETED) ? true : false, 'S_LINKS_ALLOWED' => $url_status, 'S_MAGIC_URL_CHECKED' => ($urls_checked) ? ' checked="checked"' : '', 'S_TYPE_TOGGLE' => $topic_type_toggle, -- cgit v1.2.1 From e447a0fa0797440688335bc0dc18c8a73b5586ec Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 8 Oct 2012 23:09:12 +0200 Subject: [feature/soft-delete] Fix restoring a post via editing PHPBB3-9567 --- phpBB/posting.php | 58 ++++++++++--------------------------------------------- 1 file changed, 10 insertions(+), 48 deletions(-) (limited to 'phpBB/posting.php') diff --git a/phpBB/posting.php b/phpBB/posting.php index c09ddb91ff..f4a6df3200 100644 --- a/phpBB/posting.php +++ b/phpBB/posting.php @@ -274,7 +274,7 @@ switch ($mode) break; case 'soft_delete': - if ($user->data['is_registered'] && $auth->acl_gets('f_softdelete', 'm_softdelete', $forum_id)) + if ($user->data['is_registered'] && phpbb_content_visibility::can_soft_delete($forum_id, $post_data['poster_id'], $post_data['post_edit_locked'])) { $is_authed = true; } @@ -886,53 +886,15 @@ if ($submit || $preview || $refresh) if ($submit && $mode == 'edit' && $post_data['post_visibility'] == ITEM_DELETED && !isset($_POST['soft_delete']) && $auth->acl_get('m_approve', $forum_id)) { - //@todo: REMOVE the magic! - // if this is the first post of the topic, restore the whole topic - if ($post_id == $post_data['topic_first_post_id']) - { - // that means we need to gather data for all posts in the topic, not - // just the one being edited - $sql = 'SELECT post_id, poster_id, post_subject, post_postcount - FROM ' . POSTS_TABLE . ' - WHERE topic_id = ' . $post_data['topic_id'] . ' - AND post_visibility = ' . ITEM_DELETED; - $result = $db->sql_query($sql); - - $post_ids = array(); - - while ($row = $db->sql_fetchrow($result)) - { - $post_ids[] = $row['post_id']; - - $posts_data[$row['post_id']] = array( - // all posts are from the same topic and forum - // and are deleted because of the constraints to the query above - 'topic_id' => $post_data['topic_id'], - 'forum_id' => $post_data['forum_id'], - 'topic_replies' => $post_data['topic_replies'], - 'topic_first_post_id' => $post_data['topic_first_post_id'], - 'post_visibility' => ITEM_DELETED, - - 'poster_id' => $row['poster_id'], - 'post_subject' => $row['post_subject'], - 'post_postcount'=> $row['post_postcount'], - ); - } + $is_first_post = ($post_id == $post_data['topic_first_post_id'] || !$post_data['topic_replies']); + $is_last_post = ($post_id == $post_data['topic_last_post_id'] || !$post_data['topic_replies']); + $updated_post_data = phpbb_content_visibility::set_post_visibility(ITEM_APPROVED, $post_id, $post_data['topic_id'], $post_data['forum_id'], $user->data['user_id'], time(), '', $is_first_post, $is_last_post); - // No direct query is needed, just update the array - $post_data['post_visibility'] = $post_data['topic_visibility'] = ITEM_APPROVED; - } - else + if (!empty($updated_post_data)) { - $post_ids = array($post_id); - $posts_data = array($post_id => $post_data); - - $post_data['post_visibility'] = ITEM_APPROVED; + // Update the post_data, so we don't need to refetch it. + $post_data = array_merge($post_data, $updated_post_data); } - - // don't feel that a confirm_box is needed for this - // do not return / trigger_error after this because the post content can also be changed - phpbb_content_visibility::unhide_posts_topics('restore', $posts_data, $post_ids); } // Parse subject @@ -1591,17 +1553,17 @@ function handle_post_delete($forum_id, $topic_id, $post_id, &$post_data, $is_sof 'topic_first_post_id' => $post_data['topic_first_post_id'], 'topic_last_post_id' => $post_data['topic_last_post_id'], 'topic_replies_real' => $post_data['topic_replies_real'], - 'topic_replies' => $post_data['topic_replies'], + 'topic_replies' => $post_data['topic_replies'], 'topic_visibility' => $post_data['topic_visibility'], 'topic_type' => $post_data['topic_type'], 'post_visibility' => $post_data['post_visibility'], 'post_reported' => $post_data['post_reported'], 'post_time' => $post_data['post_time'], 'poster_id' => $post_data['poster_id'], - 'post_postcount' => $post_data['post_postcount'] + 'post_postcount' => $post_data['post_postcount'], ); - $next_post_id = delete_post($forum_id, $topic_id, $post_id, $data, $is_soft); + $next_post_id = delete_post($forum_id, $topic_id, $post_id, $data, $is_soft);//@todo: $reason); $post_username = ($post_data['poster_id'] == ANONYMOUS && !empty($post_data['post_username'])) ? $post_data['post_username'] : $post_data['username']; if ($next_post_id === false) -- cgit v1.2.1 From 70fa983fa804c2a826a51af1c31ffc663cde48b3 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 9 Oct 2012 17:38:08 +0200 Subject: [feature/soft-delete] Do not allow users to reply to soft deleted topics We should discuss this in an RFC again, but for now, we just fix the old state. So moderators can only reply, when the topic is approved. Also fixes a bug in the visibility check. We need to check the posts visibility rather then the visibility of the topic. Because when the post is visible, the topic is as well, but not the other way round. PHPBB3-9567 --- phpBB/posting.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/posting.php') diff --git a/phpBB/posting.php b/phpBB/posting.php index f4a6df3200..9f0b0d2eb9 100644 --- a/phpBB/posting.php +++ b/phpBB/posting.php @@ -128,7 +128,7 @@ switch ($mode) AND t.topic_id = p.topic_id AND u.user_id = p.poster_id AND f.forum_id = t.forum_id - AND " . phpbb_content_visibility::get_visibility_sql('topic', $forum_id, 't.'); + AND " . phpbb_content_visibility::get_visibility_sql('post', $forum_id, 'p.'); break; case 'smilies': @@ -176,7 +176,7 @@ if (!$post_data) // Not able to reply to unapproved posts/topics // TODO: add more descriptive language key -if ($auth->acl_get('m_approve', $forum_id) && ((($mode == 'reply' || $mode == 'bump') && $post_data['topic_visibility'] == ITEM_UNAPPROVED) || ($mode == 'quote' && $post_data['post_visibility'] == ITEM_UNAPPROVED))) +if ($auth->acl_get('m_approve', $forum_id) && ((($mode == 'reply' || $mode == 'bump') && $post_data['topic_visibility'] != ITEM_APPROVED) || ($mode == 'quote' && $post_data['post_visibility'] != ITEM_APPROVED))) { trigger_error(($mode == 'reply' || $mode == 'bump') ? 'TOPIC_UNAPPROVED' : 'POST_UNAPPROVED'); } -- cgit v1.2.1 From 5925a17894cecb9fdf2d5c58dcdeb533fb80e8f7 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 22 Oct 2012 14:55:10 +0200 Subject: [feature/soft-delete] Fix some more uses of topic_replies_real PHPBB3-9567 --- phpBB/posting.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'phpBB/posting.php') diff --git a/phpBB/posting.php b/phpBB/posting.php index 9f0b0d2eb9..c7e96dd6c0 100644 --- a/phpBB/posting.php +++ b/phpBB/posting.php @@ -886,8 +886,8 @@ if ($submit || $preview || $refresh) if ($submit && $mode == 'edit' && $post_data['post_visibility'] == ITEM_DELETED && !isset($_POST['soft_delete']) && $auth->acl_get('m_approve', $forum_id)) { - $is_first_post = ($post_id == $post_data['topic_first_post_id'] || !$post_data['topic_replies']); - $is_last_post = ($post_id == $post_data['topic_last_post_id'] || !$post_data['topic_replies']); + $is_first_post = ($post_id == $post_data['topic_first_post_id'] || !$post_data['topic_posts']); + $is_last_post = ($post_id == $post_data['topic_last_post_id'] || !$post_data['topic_posts']); $updated_post_data = phpbb_content_visibility::set_post_visibility(ITEM_APPROVED, $post_id, $post_data['topic_id'], $post_data['forum_id'], $user->data['user_id'], time(), '', $is_first_post, $is_last_post); if (!empty($updated_post_data)) @@ -1102,8 +1102,9 @@ if ($submit || $preview || $refresh) if ($mode == 'edit') { - $data['topic_replies_real'] = $post_data['topic_replies_real']; - $data['topic_replies'] = $post_data['topic_replies']; + $data['topic_posts'] = $post_data['topic_posts']; + $data['topic_posts_unapproved'] = $post_data['topic_posts_unapproved']; + $data['topic_posts_softdeleted'] = $post_data['topic_posts_softdeleted']; } // The last parameter tells submit_post if search indexer has to be run @@ -1552,8 +1553,9 @@ function handle_post_delete($forum_id, $topic_id, $post_id, &$post_data, $is_sof $data = array( 'topic_first_post_id' => $post_data['topic_first_post_id'], 'topic_last_post_id' => $post_data['topic_last_post_id'], - 'topic_replies_real' => $post_data['topic_replies_real'], - 'topic_replies' => $post_data['topic_replies'], + 'topic_posts' => $post_data['topic_posts']; + 'topic_posts_unapproved' => $post_data['topic_posts_unapproved']; + 'topic_posts_softdeleted' => $post_data['topic_posts_softdeleted']; 'topic_visibility' => $post_data['topic_visibility'], 'topic_type' => $post_data['topic_type'], 'post_visibility' => $post_data['post_visibility'], -- cgit v1.2.1 From f21fd469bca3e5c3504a773a96d1a8fab6c374a7 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 24 Oct 2012 19:52:16 +0200 Subject: [feature/soft-delete] Handle soft deleting via Delete Icon PHPBB3-9567 --- phpBB/posting.php | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) (limited to 'phpBB/posting.php') diff --git a/phpBB/posting.php b/phpBB/posting.php index c7e96dd6c0..f82ae049dc 100644 --- a/phpBB/posting.php +++ b/phpBB/posting.php @@ -41,16 +41,10 @@ $cancel = (isset($_POST['cancel']) && !isset($_POST['save'])) ? true : false; $refresh = (isset($_POST['add_file']) || isset($_POST['delete_file']) || isset($_POST['cancel_unglobalise']) || $save || $load || $preview); $mode = request_var('mode', ''); -if ($submit && !$refresh) +// If the user is not allowed to delete the post, we try to soft delete it, so we overwrite the mode here. +if ($mode == 'delete' && (($auth->acl_get('m_softdelete', $forum_id) && $request->is_set_post('soft_delete')) || !$auth->acl_get('m_delete', $forum_id))) { - if (isset($_POST['soft_delete'])) - { - $mode = 'soft_delete'; - } - else if (isset($_POST['delete'])) - { - $mode = 'delete'; - } + $mode = 'soft_delete'; } $error = $post_data = array(); @@ -328,7 +322,8 @@ if ($mode == 'edit' && !$auth->acl_get('m_edit', $forum_id)) // Handle delete mode... if ($mode == 'delete' || $mode == 'soft_delete') { - handle_post_delete($forum_id, $topic_id, $post_id, $post_data, ($mode == 'soft_delete')); + $soft_delete_reason = ($mode == 'soft_delete' && $auth->acl_get('m_softdelete', $forum_id)) ? utf8_normalize_nfc(request_var('delete_reason', '', true)) : ''; + handle_post_delete($forum_id, $topic_id, $post_id, $post_data, ($mode == 'soft_delete'), $soft_delete_reason); return; } @@ -1532,7 +1527,7 @@ function upload_popup($forum_style = 0) /** * Do the various checks required for removing posts as well as removing it */ -function handle_post_delete($forum_id, $topic_id, $post_id, &$post_data, $is_soft) +function handle_post_delete($forum_id, $topic_id, $post_id, &$post_data, $is_soft = false, $soft_delete_reason = '') { global $user, $db, $auth, $config; global $phpbb_root_path, $phpEx; @@ -1553,9 +1548,9 @@ function handle_post_delete($forum_id, $topic_id, $post_id, &$post_data, $is_sof $data = array( 'topic_first_post_id' => $post_data['topic_first_post_id'], 'topic_last_post_id' => $post_data['topic_last_post_id'], - 'topic_posts' => $post_data['topic_posts']; - 'topic_posts_unapproved' => $post_data['topic_posts_unapproved']; - 'topic_posts_softdeleted' => $post_data['topic_posts_softdeleted']; + 'topic_posts' => $post_data['topic_posts'], + 'topic_posts_unapproved' => $post_data['topic_posts_unapproved'], + 'topic_posts_softdeleted' => $post_data['topic_posts_softdeleted'], 'topic_visibility' => $post_data['topic_visibility'], 'topic_type' => $post_data['topic_type'], 'post_visibility' => $post_data['post_visibility'], @@ -1565,7 +1560,7 @@ function handle_post_delete($forum_id, $topic_id, $post_id, &$post_data, $is_sof 'post_postcount' => $post_data['post_postcount'], ); - $next_post_id = delete_post($forum_id, $topic_id, $post_id, $data, $is_soft);//@todo: $reason); + $next_post_id = delete_post($forum_id, $topic_id, $post_id, $data, $is_soft, $soft_delete_reason); $post_username = ($post_data['poster_id'] == ANONYMOUS && !empty($post_data['post_username'])) ? $post_data['post_username'] : $post_data['username']; if ($next_post_id === false) @@ -1589,7 +1584,15 @@ function handle_post_delete($forum_id, $topic_id, $post_id, &$post_data, $is_sof } else { - confirm_box(false, 'DELETE_POST', $s_hidden_fields); + global $template; + + $template->assign_vars(array( + 'S_ALLOWED_DELETE' => $auth->acl_get('m_delete', $forum_id) || $auth->acl_get('f_delete', $forum_id), + 'S_ALLOWED_SOFTDELETE' => $auth->acl_get('m_softdelete', $forum_id) || $auth->acl_get('f_softdelete', $forum_id), + 'S_DELETE_REASON' => $auth->acl_get('m_softdelete', $forum_id), + )); + + confirm_box(false, 'DELETE_POST', $s_hidden_fields, 'posting_delete_post_body.html'); } } -- cgit v1.2.1 From 4a8d38aab13099fdb4fb7e2a7b72cff1c05fda9c Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 27 Oct 2012 17:12:34 +0200 Subject: [feature/soft-delete] Allow soft deleting/restoring topics via quickmoderation PHPBB3-9567 --- phpBB/posting.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/posting.php') diff --git a/phpBB/posting.php b/phpBB/posting.php index f82ae049dc..d1c48b38b0 100644 --- a/phpBB/posting.php +++ b/phpBB/posting.php @@ -1565,14 +1565,14 @@ function handle_post_delete($forum_id, $topic_id, $post_id, &$post_data, $is_sof if ($next_post_id === false) { - add_log('mod', $forum_id, $topic_id, 'LOG_DELETE_TOPIC', $post_data['topic_title'], $post_username); + add_log('mod', $forum_id, $topic_id, (($is_soft) ? 'LOG_SOFTDELETE_TOPIC' : 'LOG_DELETE_TOPIC'), $post_data['topic_title'], $post_username); $meta_info = append_sid("{$phpbb_root_path}viewforum.$phpEx", "f=$forum_id"); $message = $user->lang['POST_DELETED']; } else { - add_log('mod', $forum_id, $topic_id, 'LOG_DELETE_POST', $post_data['post_subject'], $post_username); + add_log('mod', $forum_id, $topic_id, (($is_soft) ? 'LOG_SOFTDELETE_POST' : 'LOG_DELETE_POST'), $post_data['post_subject'], $post_username); $meta_info = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&t=$topic_id&p=$next_post_id") . "#p$next_post_id"; $message = $user->lang['POST_DELETED'] . '

' . sprintf($user->lang['RETURN_TOPIC'], '', ''); -- cgit v1.2.1 From 8d05dad63471ffbc58feecd1f44cfa5703f0d5f1 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 31 Oct 2012 17:29:55 +0100 Subject: [feature/soft-delete] Display message when the posts are already soft deleted PHPBB3-9567 --- phpBB/posting.php | 1 + 1 file changed, 1 insertion(+) (limited to 'phpBB/posting.php') diff --git a/phpBB/posting.php b/phpBB/posting.php index d1c48b38b0..e0ab56f7b7 100644 --- a/phpBB/posting.php +++ b/phpBB/posting.php @@ -1587,6 +1587,7 @@ function handle_post_delete($forum_id, $topic_id, $post_id, &$post_data, $is_sof global $template; $template->assign_vars(array( + 'S_SOFTDELETED' => $post_data['post_visibility'] == ITEM_DELETED, 'S_ALLOWED_DELETE' => $auth->acl_get('m_delete', $forum_id) || $auth->acl_get('f_delete', $forum_id), 'S_ALLOWED_SOFTDELETE' => $auth->acl_get('m_softdelete', $forum_id) || $auth->acl_get('f_softdelete', $forum_id), 'S_DELETE_REASON' => $auth->acl_get('m_softdelete', $forum_id), -- cgit v1.2.1 From bed82bf2bd13ca04cc1572d454eee5ef3a9053a6 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 1 Nov 2012 22:23:35 +0100 Subject: [feature/soft-delete] Invert the logic on confirm box Permanent delete is now the checkbox rather then softdelete. PHPBB3-9567 --- phpBB/posting.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'phpBB/posting.php') diff --git a/phpBB/posting.php b/phpBB/posting.php index e0ab56f7b7..b0157376cf 100644 --- a/phpBB/posting.php +++ b/phpBB/posting.php @@ -1593,7 +1593,9 @@ function handle_post_delete($forum_id, $topic_id, $post_id, &$post_data, $is_sof 'S_DELETE_REASON' => $auth->acl_get('m_softdelete', $forum_id), )); - confirm_box(false, 'DELETE_POST', $s_hidden_fields, 'posting_delete_post_body.html'); + $l_confirm = 'DELETE_POST' . (($post_data['post_visibility'] == ITEM_DELETED) ? '_PERMANENTLY' : ''); + + confirm_box(false, $l_confirm, $s_hidden_fields, 'confirm_delete_body.html'); } } -- cgit v1.2.1 From 63e3baf0eb37d1d8f6f0b5b46df56a673eafa6fe Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 2 Nov 2012 12:40:10 +0100 Subject: [feature/soft-delete] Correctly manage softdeleting via posting.php PHPBB3-9567 --- phpBB/posting.php | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'phpBB/posting.php') diff --git a/phpBB/posting.php b/phpBB/posting.php index b0157376cf..96907ee790 100644 --- a/phpBB/posting.php +++ b/phpBB/posting.php @@ -35,14 +35,14 @@ $submit = (isset($_POST['post'])) ? true : false; $preview = (isset($_POST['preview'])) ? true : false; $save = (isset($_POST['save'])) ? true : false; $load = (isset($_POST['load'])) ? true : false; -$delete = (isset($_POST['delete'])) ? true : false; +$confirm = (isset($_POST['confirm'])) ? true : false; $cancel = (isset($_POST['cancel']) && !isset($_POST['save'])) ? true : false; $refresh = (isset($_POST['add_file']) || isset($_POST['delete_file']) || isset($_POST['cancel_unglobalise']) || $save || $load || $preview); $mode = request_var('mode', ''); // If the user is not allowed to delete the post, we try to soft delete it, so we overwrite the mode here. -if ($mode == 'delete' && (($auth->acl_get('m_softdelete', $forum_id) && $request->is_set_post('soft_delete')) || !$auth->acl_get('m_delete', $forum_id))) +if ($mode == 'delete' && (($confirm && !$request->is_set_post('delete_permanent')) || !$auth->acl_get('m_delete', $forum_id))) { $mode = 'soft_delete'; } @@ -1537,11 +1537,11 @@ function handle_post_delete($forum_id, $topic_id, $post_id, &$post_data, $is_sof // If moderator removing post or user itself removing post, present a confirmation screen if ($auth->acl_get("m_$perm_check", $forum_id) || ($post_data['poster_id'] == $user->data['user_id'] && $user->data['is_registered'] && $auth->acl_get("f_$perm_check", $forum_id) && $post_id == $post_data['topic_last_post_id'] && !$post_data['post_edit_locked'] && ($post_data['post_time'] > time() - ($config['delete_time'] * 60) || !$config['delete_time']))) { - $s_hidden_fields = build_hidden_fields(array( + $s_hidden_fields = array( 'p' => $post_id, 'f' => $forum_id, 'mode' => ($is_soft) ? 'soft_delete' : 'delete', - )); + ); if (confirm_box(true)) { @@ -1593,9 +1593,18 @@ function handle_post_delete($forum_id, $topic_id, $post_id, &$post_data, $is_sof 'S_DELETE_REASON' => $auth->acl_get('m_softdelete', $forum_id), )); - $l_confirm = 'DELETE_POST' . (($post_data['post_visibility'] == ITEM_DELETED) ? '_PERMANENTLY' : ''); + $l_confirm = 'DELETE_POST'; + if ($post_data['post_visibility'] == ITEM_DELETED) + { + $l_confirm .= '_PERMANENTLY'; + $s_hidden_fields['delete_permanent'] = '1'; + } + else if (!$auth->acl_get('m_softdelete', $forum_id) && !$auth->acl_get('f_softdelete', $forum_id)) + { + $s_hidden_fields['delete_permanent'] = '1'; + } - confirm_box(false, $l_confirm, $s_hidden_fields, 'confirm_delete_body.html'); + confirm_box(false, $l_confirm, build_hidden_fields($s_hidden_fields), 'confirm_delete_body.html'); } } -- cgit v1.2.1 From dfcfccf537658b83401b78afc851239f4842a4e5 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 3 Nov 2012 22:53:54 +0100 Subject: [feature/soft-delete] Fix deleting via post editing PHPBB3-9567 --- phpBB/posting.php | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'phpBB/posting.php') diff --git a/phpBB/posting.php b/phpBB/posting.php index 96907ee790..4c92d85a20 100644 --- a/phpBB/posting.php +++ b/phpBB/posting.php @@ -322,6 +322,12 @@ if ($mode == 'edit' && !$auth->acl_get('m_edit', $forum_id)) // Handle delete mode... if ($mode == 'delete' || $mode == 'soft_delete') { + if ($mode == 'soft_delete' && $post_data['post_visibility'] == ITEM_DELETED) + { + $user->setup('posting'); + trigger_error('NO_POST'); + } + $soft_delete_reason = ($mode == 'soft_delete' && $auth->acl_get('m_softdelete', $forum_id)) ? utf8_normalize_nfc(request_var('delete_reason', '', true)) : ''; handle_post_delete($forum_id, $topic_id, $post_id, $post_data, ($mode == 'soft_delete'), $soft_delete_reason); return; @@ -1110,6 +1116,14 @@ if ($submit || $preview || $refresh) $captcha->reset(); } + // Handle delete mode... + if ($request->is_set_post('delete') || $request->is_set_post('delete_permanent')) + { + $soft_delete_reason = (!$request->is_set_post('delete_permanent') && $auth->acl_get('m_softdelete', $forum_id)) ? utf8_normalize_nfc(request_var('delete_reason', '', true)) : ''; + handle_post_delete($forum_id, $topic_id, $post_id, $post_data, !$request->is_set_post('delete_permanent'), $soft_delete_reason); + return; + } + // Check the permissions for post approval. Moderators are not affected. if ((!$auth->acl_get('f_noapprove', $data['forum_id']) && !$auth->acl_get('m_approve', $data['forum_id']) && empty($data['force_approved_state'])) || (isset($data['force_approved_state']) && !$data['force_approved_state'])) { @@ -1430,8 +1444,9 @@ $template->assign_vars(array( 'S_LOCK_TOPIC_CHECKED' => ($lock_topic_checked) ? ' checked="checked"' : '', 'S_LOCK_POST_ALLOWED' => ($mode == 'edit' && $auth->acl_get('m_edit', $forum_id)) ? true : false, 'S_LOCK_POST_CHECKED' => ($lock_post_checked) ? ' checked="checked"' : '', - 'S_SOFT_DELETE_CHECKED' => ($mode == 'edit' && $post_data['post_visibility'] == ITEM_DELETED) ? ' checked="checked"' : '', - 'S_SOFT_DELETE_ALLOWED' => ($mode == 'edit' && phpbb_content_visibility::can_soft_delete($forum_id, $post_data['poster_id'], $lock_post_checked)) ? true : false, + 'S_SOFTDELETE_CHECKED' => ($mode == 'edit' && $post_data['post_visibility'] == ITEM_DELETED) ? ' checked="checked"' : '', + 'S_DELETE_REASON' => ($mode == 'edit' && $auth->acl_get('m_softdelete', $forum_id)) ? true : false, + 'S_SOFTDELETE_ALLOWED' => ($mode == 'edit' && phpbb_content_visibility::can_soft_delete($forum_id, $post_data['poster_id'], $lock_post_checked)) ? true : false, 'S_RESTORE_ALLOWED' => $auth->acl_get('m_approve', $forum_id), 'S_IS_DELETED' => ($mode == 'edit' && $post_data['post_visibility'] == ITEM_DELETED) ? true : false, 'S_LINKS_ALLOWED' => $url_status, @@ -1584,10 +1599,11 @@ function handle_post_delete($forum_id, $topic_id, $post_id, &$post_data, $is_sof } else { - global $template; + global $template, $request; $template->assign_vars(array( 'S_SOFTDELETED' => $post_data['post_visibility'] == ITEM_DELETED, + 'S_CHECKED_PERMANENT' => $request->is_set_post('delete_permanent') ? ' checked="checked"' : '', 'S_ALLOWED_DELETE' => $auth->acl_get('m_delete', $forum_id) || $auth->acl_get('f_delete', $forum_id), 'S_ALLOWED_SOFTDELETE' => $auth->acl_get('m_softdelete', $forum_id) || $auth->acl_get('f_softdelete', $forum_id), 'S_DELETE_REASON' => $auth->acl_get('m_softdelete', $forum_id), -- cgit v1.2.1 From 885e19e58a54dc5f06161dd56d7e1a2df34df95d Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 4 Nov 2012 01:17:22 +0100 Subject: [feature/soft-delete] Provide the options for permanent delete via AJAX AJAX confirm_box should be able to call the template file given. The confirm message is HTML so far, but generating the HTML in the php code is not, what we want. PHPBB3-9567 --- phpBB/posting.php | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'phpBB/posting.php') diff --git a/phpBB/posting.php b/phpBB/posting.php index 4c92d85a20..16dfad3b91 100644 --- a/phpBB/posting.php +++ b/phpBB/posting.php @@ -1604,8 +1604,8 @@ function handle_post_delete($forum_id, $topic_id, $post_id, &$post_data, $is_sof $template->assign_vars(array( 'S_SOFTDELETED' => $post_data['post_visibility'] == ITEM_DELETED, 'S_CHECKED_PERMANENT' => $request->is_set_post('delete_permanent') ? ' checked="checked"' : '', - 'S_ALLOWED_DELETE' => $auth->acl_get('m_delete', $forum_id) || $auth->acl_get('f_delete', $forum_id), - 'S_ALLOWED_SOFTDELETE' => $auth->acl_get('m_softdelete', $forum_id) || $auth->acl_get('f_softdelete', $forum_id), + 'S_ALLOWED_DELETE' => $auth->acl_gets('m_delete', 'f_delete', $forum_id), + 'S_ALLOWED_SOFTDELETE' => $auth->acl_gets('m_softdelete', 'f_softdelete', $forum_id), 'S_DELETE_REASON' => $auth->acl_get('m_softdelete', $forum_id), )); @@ -1620,7 +1620,24 @@ function handle_post_delete($forum_id, $topic_id, $post_id, &$post_data, $is_sof $s_hidden_fields['delete_permanent'] = '1'; } - confirm_box(false, $l_confirm, build_hidden_fields($s_hidden_fields), 'confirm_delete_body.html'); + // @todo: This needs fixing! AJAX confirm_box should be able to call template files! + if ($request->is_ajax()) + { + $l_confirm = (!isset($user->lang[$l_confirm . '_CONFIRM'])) ? $l_confirm : $user->lang[$l_confirm . '_CONFIRM']; + if ($auth->acl_gets('m_delete', 'f_delete', $forum_id) && $auth->acl_gets('m_softdelete', 'f_softdelete', $forum_id)) + { + $l_confirm .= '
' . $user->lang['DELETE_PERMANENTLY'] . ': '; + } + if ($auth->acl_get('m_softdelete', $forum_id)) + { + $l_confirm .= '
' . $user->lang['DELETE_REASON'] . ': '; + } + confirm_box(false, $l_confirm, build_hidden_fields($s_hidden_fields)); + } + else + { + confirm_box(false, $l_confirm, build_hidden_fields($s_hidden_fields), 'confirm_delete_body.html'); + } } } -- cgit v1.2.1 From fc110a7332a756891d5f8276d26f88a6e4113350 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 9 Nov 2012 12:09:46 +0100 Subject: [feature/soft-delete] Remove the current work around on ajax confirm problem PHPBB3-9567 --- phpBB/posting.php | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-) (limited to 'phpBB/posting.php') diff --git a/phpBB/posting.php b/phpBB/posting.php index 16dfad3b91..62c55d9ff4 100644 --- a/phpBB/posting.php +++ b/phpBB/posting.php @@ -1599,7 +1599,7 @@ function handle_post_delete($forum_id, $topic_id, $post_id, &$post_data, $is_sof } else { - global $template, $request; + global $user, $template, $request; $template->assign_vars(array( 'S_SOFTDELETED' => $post_data['post_visibility'] == ITEM_DELETED, @@ -1621,23 +1621,7 @@ function handle_post_delete($forum_id, $topic_id, $post_id, &$post_data, $is_sof } // @todo: This needs fixing! AJAX confirm_box should be able to call template files! - if ($request->is_ajax()) - { - $l_confirm = (!isset($user->lang[$l_confirm . '_CONFIRM'])) ? $l_confirm : $user->lang[$l_confirm . '_CONFIRM']; - if ($auth->acl_gets('m_delete', 'f_delete', $forum_id) && $auth->acl_gets('m_softdelete', 'f_softdelete', $forum_id)) - { - $l_confirm .= '
' . $user->lang['DELETE_PERMANENTLY'] . ': '; - } - if ($auth->acl_get('m_softdelete', $forum_id)) - { - $l_confirm .= '
' . $user->lang['DELETE_REASON'] . ': '; - } - confirm_box(false, $l_confirm, build_hidden_fields($s_hidden_fields)); - } - else - { - confirm_box(false, $l_confirm, build_hidden_fields($s_hidden_fields), 'confirm_delete_body.html'); - } + confirm_box(false, $l_confirm, build_hidden_fields($s_hidden_fields), 'confirm_delete_body.html'); } } -- cgit v1.2.1 From 8512543cf490e06e3b3ca95d0ae9be3ee8fb850d Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 9 Nov 2012 12:32:27 +0100 Subject: [feature/soft-delete] Use request object instead of direct access PHPBB3-9567 --- phpBB/posting.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'phpBB/posting.php') diff --git a/phpBB/posting.php b/phpBB/posting.php index 62c55d9ff4..0b22fa54c2 100644 --- a/phpBB/posting.php +++ b/phpBB/posting.php @@ -35,7 +35,7 @@ $submit = (isset($_POST['post'])) ? true : false; $preview = (isset($_POST['preview'])) ? true : false; $save = (isset($_POST['save'])) ? true : false; $load = (isset($_POST['load'])) ? true : false; -$confirm = (isset($_POST['confirm'])) ? true : false; +$confirm = $request->is_set_post('confirm'); $cancel = (isset($_POST['cancel']) && !isset($_POST['save'])) ? true : false; $refresh = (isset($_POST['add_file']) || isset($_POST['delete_file']) || isset($_POST['cancel_unglobalise']) || $save || $load || $preview); @@ -328,7 +328,7 @@ if ($mode == 'delete' || $mode == 'soft_delete') trigger_error('NO_POST'); } - $soft_delete_reason = ($mode == 'soft_delete' && $auth->acl_get('m_softdelete', $forum_id)) ? utf8_normalize_nfc(request_var('delete_reason', '', true)) : ''; + $soft_delete_reason = ($mode == 'soft_delete' && $auth->acl_get('m_softdelete', $forum_id)) ? $request->variable('delete_reason', '', true) : ''; handle_post_delete($forum_id, $topic_id, $post_id, $post_data, ($mode == 'soft_delete'), $soft_delete_reason); return; } @@ -1119,7 +1119,7 @@ if ($submit || $preview || $refresh) // Handle delete mode... if ($request->is_set_post('delete') || $request->is_set_post('delete_permanent')) { - $soft_delete_reason = (!$request->is_set_post('delete_permanent') && $auth->acl_get('m_softdelete', $forum_id)) ? utf8_normalize_nfc(request_var('delete_reason', '', true)) : ''; + $soft_delete_reason = (!$request->is_set_post('delete_permanent') && $auth->acl_get('m_softdelete', $forum_id)) ? $request->variable('delete_reason', '', true) : ''; handle_post_delete($forum_id, $topic_id, $post_id, $post_data, !$request->is_set_post('delete_permanent'), $soft_delete_reason); return; } -- cgit v1.2.1 From 9c2a58eff4c2bd164ee3bdb2ec66729d4562963d Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 9 Nov 2012 13:37:53 +0100 Subject: [feature/soft-delete] Append _approved to *_posts and *_topics column names PHPBB3-9567 --- phpBB/posting.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'phpBB/posting.php') diff --git a/phpBB/posting.php b/phpBB/posting.php index 0b22fa54c2..52ef424ace 100644 --- a/phpBB/posting.php +++ b/phpBB/posting.php @@ -887,8 +887,8 @@ if ($submit || $preview || $refresh) if ($submit && $mode == 'edit' && $post_data['post_visibility'] == ITEM_DELETED && !isset($_POST['soft_delete']) && $auth->acl_get('m_approve', $forum_id)) { - $is_first_post = ($post_id == $post_data['topic_first_post_id'] || !$post_data['topic_posts']); - $is_last_post = ($post_id == $post_data['topic_last_post_id'] || !$post_data['topic_posts']); + $is_first_post = ($post_id == $post_data['topic_first_post_id'] || !$post_data['topic_posts_approved']); + $is_last_post = ($post_id == $post_data['topic_last_post_id'] || !$post_data['topic_posts_approved']); $updated_post_data = phpbb_content_visibility::set_post_visibility(ITEM_APPROVED, $post_id, $post_data['topic_id'], $post_data['forum_id'], $user->data['user_id'], time(), '', $is_first_post, $is_last_post); if (!empty($updated_post_data)) @@ -1103,7 +1103,7 @@ if ($submit || $preview || $refresh) if ($mode == 'edit') { - $data['topic_posts'] = $post_data['topic_posts']; + $data['topic_posts_approved'] = $post_data['topic_posts_approved']; $data['topic_posts_unapproved'] = $post_data['topic_posts_unapproved']; $data['topic_posts_softdeleted'] = $post_data['topic_posts_softdeleted']; } @@ -1563,7 +1563,7 @@ function handle_post_delete($forum_id, $topic_id, $post_id, &$post_data, $is_sof $data = array( 'topic_first_post_id' => $post_data['topic_first_post_id'], 'topic_last_post_id' => $post_data['topic_last_post_id'], - 'topic_posts' => $post_data['topic_posts'], + 'topic_posts_approved' => $post_data['topic_posts_approved'], 'topic_posts_unapproved' => $post_data['topic_posts_unapproved'], 'topic_posts_softdeleted' => $post_data['topic_posts_softdeleted'], 'topic_visibility' => $post_data['topic_visibility'], -- cgit v1.2.1 From eb5a6cb006a3b65daca604996a154484bb318221 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 10 Mar 2013 22:07:38 +0100 Subject: [ticket/9657] Display reason field, when the user has both delete permissions PHPBB3-9657 --- phpBB/posting.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'phpBB/posting.php') diff --git a/phpBB/posting.php b/phpBB/posting.php index dd6c3556fc..40ffc0d98d 100644 --- a/phpBB/posting.php +++ b/phpBB/posting.php @@ -363,7 +363,8 @@ if ($mode == 'delete' || $mode == 'soft_delete') trigger_error('NO_POST'); } - $soft_delete_reason = ($mode == 'soft_delete' && $auth->acl_get('m_softdelete', $forum_id)) ? $request->variable('delete_reason', '', true) : ''; + $allow_reason = $auth->acl_get('m_softdelete', $forum_id) || ($auth->acl_gets('m_delete', 'f_delete', $forum_id) && $auth->acl_gets('m_softdelete', 'f_softdelete', $forum_id)); + $soft_delete_reason = ($mode == 'soft_delete' && $allow_reason) ? $request->variable('delete_reason', '', true) : ''; handle_post_delete($forum_id, $topic_id, $post_id, $post_data, ($mode == 'soft_delete'), $soft_delete_reason); return; } @@ -1154,7 +1155,8 @@ if ($submit || $preview || $refresh) // Handle delete mode... if ($request->is_set_post('delete') || $request->is_set_post('delete_permanent')) { - $soft_delete_reason = (!$request->is_set_post('delete_permanent') && $auth->acl_get('m_softdelete', $forum_id)) ? $request->variable('delete_reason', '', true) : ''; + $allow_reason = $auth->acl_get('m_softdelete', $forum_id) || ($auth->acl_gets('m_delete', 'f_delete', $forum_id) && $auth->acl_gets('m_softdelete', 'f_softdelete', $forum_id)); + $soft_delete_reason = (!$request->is_set_post('delete_permanent') && $allow_reason) ? $request->variable('delete_reason', '', true) : ''; handle_post_delete($forum_id, $topic_id, $post_id, $post_data, !$request->is_set_post('delete_permanent'), $soft_delete_reason); return; } @@ -1645,12 +1647,14 @@ function handle_post_delete($forum_id, $topic_id, $post_id, &$post_data, $is_sof { global $user, $template, $request; + $display_reason = $auth->acl_get('m_softdelete', $forum_id) || ($auth->acl_gets('m_delete', 'f_delete', $forum_id) && $auth->acl_gets('m_softdelete', 'f_softdelete', $forum_id)); + $template->assign_vars(array( 'S_SOFTDELETED' => $post_data['post_visibility'] == ITEM_DELETED, 'S_CHECKED_PERMANENT' => $request->is_set_post('delete_permanent') ? ' checked="checked"' : '', 'S_ALLOWED_DELETE' => $auth->acl_gets('m_delete', 'f_delete', $forum_id), 'S_ALLOWED_SOFTDELETE' => $auth->acl_gets('m_softdelete', 'f_softdelete', $forum_id), - 'S_DELETE_REASON' => $auth->acl_get('m_softdelete', $forum_id), + 'S_DELETE_REASON' => $display_reason, )); $l_confirm = 'DELETE_POST'; -- cgit v1.2.1 From d6d7acef0416287bf70c0582ae874bbca6caf2eb Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 10 Mar 2013 23:48:53 +0100 Subject: [ticket/9657] Remove already fixed todo PHPBB3-9657 --- phpBB/posting.php | 1 - 1 file changed, 1 deletion(-) (limited to 'phpBB/posting.php') diff --git a/phpBB/posting.php b/phpBB/posting.php index 40ffc0d98d..51cdc04abb 100644 --- a/phpBB/posting.php +++ b/phpBB/posting.php @@ -1668,7 +1668,6 @@ function handle_post_delete($forum_id, $topic_id, $post_id, &$post_data, $is_sof $s_hidden_fields['delete_permanent'] = '1'; } - // @todo: This needs fixing! AJAX confirm_box should be able to call template files! confirm_box(false, $l_confirm, build_hidden_fields($s_hidden_fields), 'confirm_delete_body.html'); } } -- cgit v1.2.1 From 74f4fd724e64eba4092b48cd114b2a1ee9e399b3 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 12 Mar 2013 12:39:00 +0100 Subject: [ticket/9657] Correctly determine the users permissions when deleting posts PHPBB3-9657 --- phpBB/posting.php | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'phpBB/posting.php') diff --git a/phpBB/posting.php b/phpBB/posting.php index 51cdc04abb..dbc569d844 100644 --- a/phpBB/posting.php +++ b/phpBB/posting.php @@ -296,7 +296,7 @@ switch ($mode) break; case 'delete': - if ($user->data['is_registered'] && $auth->acl_gets('f_delete', 'm_delete', $forum_id)) + if ($user->data['is_registered'] && ($auth->acl_get('m_delete', $forum_id) || ($post_data['poster_id'] == $user->data['user_id'] && $auth->acl_get('f_delete', $forum_id)))) { $is_authed = true; } @@ -307,6 +307,11 @@ switch ($mode) { $is_authed = true; } + else + { + // Display the same error message for softdelete we use for delete + $mode = 'delete'; + } break; } @@ -1647,13 +1652,15 @@ function handle_post_delete($forum_id, $topic_id, $post_id, &$post_data, $is_sof { global $user, $template, $request; - $display_reason = $auth->acl_get('m_softdelete', $forum_id) || ($auth->acl_gets('m_delete', 'f_delete', $forum_id) && $auth->acl_gets('m_softdelete', 'f_softdelete', $forum_id)); + $can_delete = $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)); + $can_softdelete = $auth->acl_get('m_softdelete', $forum_id) || ($post_data['poster_id'] == $user->data['user_id'] && $user->data['is_registered'] && $auth->acl_get('f_softdelete', $forum_id)); + $display_reason = $auth->acl_get('m_softdelete', $forum_id) || ($can_delete && $can_softdelete); $template->assign_vars(array( 'S_SOFTDELETED' => $post_data['post_visibility'] == ITEM_DELETED, 'S_CHECKED_PERMANENT' => $request->is_set_post('delete_permanent') ? ' checked="checked"' : '', - 'S_ALLOWED_DELETE' => $auth->acl_gets('m_delete', 'f_delete', $forum_id), - 'S_ALLOWED_SOFTDELETE' => $auth->acl_gets('m_softdelete', 'f_softdelete', $forum_id), + 'S_ALLOWED_DELETE' => $can_delete, + 'S_ALLOWED_SOFTDELETE' => $can_softdelete, 'S_DELETE_REASON' => $display_reason, )); @@ -1663,7 +1670,7 @@ function handle_post_delete($forum_id, $topic_id, $post_id, &$post_data, $is_sof $l_confirm .= '_PERMANENTLY'; $s_hidden_fields['delete_permanent'] = '1'; } - else if (!$auth->acl_get('m_softdelete', $forum_id) && !$auth->acl_get('f_softdelete', $forum_id)) + else if (!$can_softdelete) { $s_hidden_fields['delete_permanent'] = '1'; } -- cgit v1.2.1 From 9aed758c1397c31b979f4aca51249c73d21bd6f5 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 11 Jul 2013 14:24:07 +0200 Subject: [ticket/9657] Use the service instead of the static class PHPBB3-9657 --- phpBB/posting.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'phpBB/posting.php') diff --git a/phpBB/posting.php b/phpBB/posting.php index d5bb536753..ac459197b3 100644 --- a/phpBB/posting.php +++ b/phpBB/posting.php @@ -98,6 +98,8 @@ if (in_array($mode, array('post', 'reply', 'quote', 'edit', 'delete')) && !$foru trigger_error('NO_FORUM'); } +$phpbb_content_visibility = $phpbb_container->get('content.visibility'); + // We need to know some basic information in all cases before we do anything. switch ($mode) { @@ -128,7 +130,7 @@ switch ($mode) FROM ' . TOPICS_TABLE . ' t, ' . FORUMS_TABLE . " f WHERE t.topic_id = $topic_id AND f.forum_id = t.forum_id - AND " . phpbb_content_visibility::get_visibility_sql('topic', $forum_id, 't.'); + AND " . $phpbb_content_visibility->get_visibility_sql('topic', $forum_id, 't.'); break; case 'quote': @@ -157,7 +159,7 @@ switch ($mode) AND t.topic_id = p.topic_id AND u.user_id = p.poster_id AND f.forum_id = t.forum_id - AND " . phpbb_content_visibility::get_visibility_sql('post', $forum_id, 'p.'); + AND " . $phpbb_content_visibility->get_visibility_sql('post', $forum_id, 'p.'); break; case 'smilies': @@ -304,7 +306,7 @@ switch ($mode) break; case 'soft_delete': - if ($user->data['is_registered'] && phpbb_content_visibility::can_soft_delete($forum_id, $post_data['poster_id'], $post_data['post_edit_locked'])) + if ($user->data['is_registered'] && $phpbb_content_visibility->can_soft_delete($forum_id, $post_data['poster_id'], $post_data['post_edit_locked'])) { $is_authed = true; } @@ -931,7 +933,7 @@ if ($submit || $preview || $refresh) { $is_first_post = ($post_id == $post_data['topic_first_post_id'] || !$post_data['topic_posts_approved']); $is_last_post = ($post_id == $post_data['topic_last_post_id'] || !$post_data['topic_posts_approved']); - $updated_post_data = phpbb_content_visibility::set_post_visibility(ITEM_APPROVED, $post_id, $post_data['topic_id'], $post_data['forum_id'], $user->data['user_id'], time(), '', $is_first_post, $is_last_post); + $updated_post_data = $phpbb_content_visibility->set_post_visibility(ITEM_APPROVED, $post_id, $post_data['topic_id'], $post_data['forum_id'], $user->data['user_id'], time(), '', $is_first_post, $is_last_post); if (!empty($updated_post_data)) { @@ -1490,7 +1492,7 @@ $template->assign_vars(array( 'S_LOCK_POST_CHECKED' => ($lock_post_checked) ? ' checked="checked"' : '', 'S_SOFTDELETE_CHECKED' => ($mode == 'edit' && $post_data['post_visibility'] == ITEM_DELETED) ? ' checked="checked"' : '', 'S_DELETE_REASON' => ($mode == 'edit' && $auth->acl_get('m_softdelete', $forum_id)) ? true : false, - 'S_SOFTDELETE_ALLOWED' => ($mode == 'edit' && phpbb_content_visibility::can_soft_delete($forum_id, $post_data['poster_id'], $lock_post_checked)) ? true : false, + 'S_SOFTDELETE_ALLOWED' => ($mode == 'edit' && $phpbb_content_visibility->can_soft_delete($forum_id, $post_data['poster_id'], $lock_post_checked)) ? true : false, 'S_RESTORE_ALLOWED' => $auth->acl_get('m_approve', $forum_id), 'S_IS_DELETED' => ($mode == 'edit' && $post_data['post_visibility'] == ITEM_DELETED) ? true : false, 'S_LINKS_ALLOWED' => $url_status, -- cgit v1.2.1