aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/includes
diff options
context:
space:
mode:
authorJosh Woody <a_jelly_doughnut@phpbb.com>2010-06-27 14:22:36 -0500
committerJoas Schilling <nickvergessen@gmx.de>2012-08-29 17:50:11 +0200
commitfb13ab83e476d2afbc7bb181f7ab90df98f996da (patch)
treea86bc9db9c4e65efb50857d6ca18633c87a5027c /phpBB/includes
parentc32d76080605f843bb23e9a608c368d4b5dc55d8 (diff)
downloadforums-fb13ab83e476d2afbc7bb181f7ab90df98f996da.tar
forums-fb13ab83e476d2afbc7bb181f7ab90df98f996da.tar.gz
forums-fb13ab83e476d2afbc7bb181f7ab90df98f996da.tar.bz2
forums-fb13ab83e476d2afbc7bb181f7ab90df98f996da.tar.xz
forums-fb13ab83e476d2afbc7bb181f7ab90df98f996da.zip
[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
Diffstat (limited to 'phpBB/includes')
-rw-r--r--phpBB/includes/class_visibility.php265
-rw-r--r--phpBB/includes/functions_posting.php112
-rw-r--r--phpBB/includes/mcp/info/mcp_queue.php1
-rw-r--r--phpBB/includes/mcp/mcp_queue.php152
4 files changed, 351 insertions, 179 deletions
diff --git a/phpBB/includes/class_visibility.php b/phpBB/includes/class_visibility.php
index 46f188d833..9798e938b1 100644
--- a/phpBB/includes/class_visibility.php
+++ b/phpBB/includes/class_visibility.php
@@ -125,7 +125,6 @@ class phpbb_visibility
// we are adjusting _all_ posts in that topic.
$status = self::set_post_visibility($visibility, false, $topic_id, $forum_id, true, true);
-
return $status;
}
@@ -172,5 +171,267 @@ class phpbb_visibility
update_post_information('forum', $forum_id, false);
}
}
+
+ /**
+ * Can the current logged-in user soft-delete posts?
+ * @param $forum_id - int - the forum ID whose permissions to check
+ * @param $poster_id - int - the poster ID of the post in question
+ * @param $post_locked - bool - is the post locked?
+ * @return bool
+ */
+ public function can_soft_delete($forum_id, $poster_id, $post_locked)
+ {
+ global $auth, $user;
+
+ if ($auth->acl_get('m_softdelete', $forum_id))
+ {
+ return true;
+ }
+ else if ($auth->acl_get('f_softdelete', $forum_id) && $poster_id == $user->data['poster_id'] && !$post_locked)
+ {
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Can the current logged-in user restore soft-deleted posts?
+ * @param $forum_id - int - the forum ID whose permissions to check
+ * @param $poster_id - int - the poster ID of the post in question
+ * @param $post_locked - bool - is the post locked?
+ * @return bool
+ */
+ public function can_restore($forum_id, $poster_id, $post_locked)
+ {
+ global $auth, $user;
+
+ if ($auth->acl_get('m_restore', $forum_id))
+ {
+ return true;
+ }
+ else if ($auth->acl_get('f_restore', $forum_id) && $poster_id == $user->data['user_id'] && !$post_locked)
+ {
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Do the required math to hide a complete topic (going from approved to
+ * unapproved or from approved to deleted)
+ * @param $topic_id - int - the topic to act on
+ * @param $forum_id - int - the forum where the topic resides
+ * @param $topic_row - array - data about the topic, may be empty at call time
+ * @param $sql_data - array - populated with the SQL changes, may be empty at call time
+ * @return void
+ */
+ public function hide_topic($topic_id, $forum_id, &$topic_row, &$sql_data)
+ {
+ global $auth, $config, $db;
+
+ // Do we need to grab some topic informations?
+ if (!sizeof($topic_row))
+ {
+ $sql = 'SELECT topic_type, topic_replies, topic_replies_real, topic_visibility
+ FROM ' . TOPICS_TABLE . '
+ WHERE topic_id = ' . $topic_id;
+ $result = $db->sql_query($sql);
+ $topic_row = $db->sql_fetchrow($result);
+ $db->sql_freeresult($result);
+ }
+
+ // If this is the only post remaining we do not need to decrement topic_replies.
+ // Also do not decrement if first post - then the topic_replies will not be adjusted if approving the topic again.
+
+ // If this is an edited topic or the first post the topic gets completely disapproved later on...
+ $sql_data[FORUMS_TABLE] = 'forum_topics = forum_topics - 1';
+ $sql_data[FORUMS_TABLE] = 'forum_posts = forum_posts - ' . ($topic_row['topic_replies'] + 1);
+
+ set_config_count('num_topics', -1, true);
+ set_config_count('num_posts', ($topic_row['topic_replies'] + 1) * (-1), true);
+
+ // Only decrement this post, since this is the one non-approved now
+ if ($auth->acl_get('f_postcount', $forum_id))
+ {
+ $sql_data[USERS_TABLE] = 'user_posts = user_posts - 1';
+ }
+ }
+
+ /**
+ * Do the required math to hide a single post (going from approved to
+ * unapproved or from approved to deleted)
+ * Notably, we do _not_ need the post ID to do this operation. We're only changing statistic caches
+ * @param $forum_id - int - the forum where the topic resides
+ * @param $current_time - int - passed for consistency instead of calling time() internally
+ * @param $sql_data - array - populated with the SQL changes, may be empty at call time
+ * @return void
+ */
+ public function hide_post($forum_id, $current_time, &$sql_data)
+ {
+ global $auth, $config, $db;
+
+ $sql_data[TOPICS_TABLE] = 'topic_replies = topic_replies - 1, topic_last_view_time = ' . $current_time;
+ $sql_data[FORUMS_TABLE] = 'forum_posts = forum_posts - 1';
+
+ set_config_count('num_posts', -1, true);
+
+ if ($auth->acl_get('f_postcount', $forum_id))
+ {
+ $sql_data[USERS_TABLE] = 'user_posts = user_posts - 1';
+ }
+ }
+
+ /**
+ * One function to rule them all ... and unhide posts and topics. This could
+ * reasonably be broken up, I straight copied this code from the mcp_queue.php
+ * file here for global access.
+ * @param $mode - string - member of the set {'approve', 'restore'}
+ * @param $post_info - array - Contains info from post U topics table about
+ * the posts/topics in question
+ * @param $post_id_list - array of ints - the set of posts being worked on
+ */
+ public function unhide_posts_topics($mode, $post_info, $post_id_list)
+ {
+ global $db, $config;
+
+ // If Topic -> total_topics = total_topics+1, total_posts = total_posts+1, forum_topics = forum_topics+1, forum_posts = forum_posts+1
+ // If Post -> total_posts = total_posts+1, forum_posts = forum_posts+1, topic_replies = topic_replies+1
+
+ $total_topics = $total_posts = 0;
+ $topic_approve_sql = $post_approve_sql = $topic_id_list = $forum_id_list = $approve_log = array();
+ $user_posts_sql = $post_approved_list = array();
+
+ foreach ($post_info as $post_id => $post_data)
+ {
+ if ($post_data['post_visibility'] == ITEM_APPROVED)
+ {
+ $post_approved_list[] = $post_id;
+ continue;
+ }
+
+ $topic_id_list[$post_data['topic_id']] = 1;
+
+ if ($post_data['forum_id'])
+ {
+ $forum_id_list[$post_data['forum_id']] = 1;
+ }
+
+ // User post update (we do not care about topic or post, since user posts are strictly connected to posts)
+ // But we care about forums where post counts get not increased. ;)
+ if ($post_data['post_postcount'])
+ {
+ $user_posts_sql[$post_data['poster_id']] = (empty($user_posts_sql[$post_data['poster_id']])) ? 1 : $user_posts_sql[$post_data['poster_id']] + 1;
+ }
+
+ // Topic or Post. ;)
+ if ($post_data['topic_first_post_id'] == $post_id)
+ {
+ if ($post_data['forum_id'])
+ {
+ $total_topics++;
+ }
+ $topic_approve_sql[] = $post_data['topic_id'];
+
+ $approve_log[] = array(
+ 'type' => 'topic',
+ 'post_subject' => $post_data['post_subject'],
+ 'forum_id' => $post_data['forum_id'],
+ 'topic_id' => $post_data['topic_id'],
+ );
+ }
+ else
+ {
+ $approve_log[] = array(
+ 'type' => 'post',
+ 'post_subject' => $post_data['post_subject'],
+ 'forum_id' => $post_data['forum_id'],
+ 'topic_id' => $post_data['topic_id'],
+ );
+ }
+
+ if ($post_data['forum_id'])
+ {
+ $total_posts++;
+
+ // Increment by topic_replies if we approve a topic...
+ // This works because we do not adjust the topic_replies when re-approving a topic after an edit.
+ if ($post_data['topic_first_post_id'] == $post_id && $post_data['topic_replies'])
+ {
+ $total_posts += $post_data['topic_replies'];
+ }
+ }
+
+ $post_approve_sql[] = $post_id;
+ }
+
+ $post_id_list = array_values(array_diff($post_id_list, $post_approved_list));
+ for ($i = 0, $size = sizeof($post_approved_list); $i < $size; $i++)
+ {
+ unset($post_info[$post_approved_list[$i]]);
+ }
+
+ if (sizeof($topic_approve_sql))
+ {
+ $sql = 'UPDATE ' . TOPICS_TABLE . '
+ SET topic_visibility = ' . ITEM_APPROVED . '
+ WHERE ' . $db->sql_in_set('topic_id', $topic_approve_sql);
+ $db->sql_query($sql);
+ }
+
+ if (sizeof($post_approve_sql))
+ {
+ $sql = 'UPDATE ' . POSTS_TABLE . '
+ SET post_visibility = ' . ITEM_APPROVED . '
+ WHERE ' . $db->sql_in_set('post_id', $post_approve_sql);
+ $db->sql_query($sql);
+ }
+
+ unset($topic_approve_sql, $post_approve_sql);
+
+ foreach ($approve_log as $log_data)
+ {
+ add_log('mod', $log_data['forum_id'], $log_data['topic_id'], ($log_data['type'] == 'topic') ? 'LOG_TOPIC_' . strtoupper($mode) . 'D' : 'LOG_POST_' . strtoupper($mode) . 'D', $log_data['post_subject']);
+ }
+
+ if (sizeof($user_posts_sql))
+ {
+ // Try to minimize the query count by merging users with the same post count additions
+ $user_posts_update = array();
+
+ foreach ($user_posts_sql as $user_id => $user_posts)
+ {
+ $user_posts_update[$user_posts][] = $user_id;
+ }
+
+ foreach ($user_posts_update as $user_posts => $user_id_ary)
+ {
+ $sql = 'UPDATE ' . USERS_TABLE . '
+ SET user_posts = user_posts + ' . $user_posts . '
+ WHERE ' . $db->sql_in_set('user_id', $user_id_ary);
+ $db->sql_query($sql);
+ }
+ }
+
+ if ($total_topics)
+ {
+ set_config_count('num_topics', $total_topics, true);
+ }
+
+ if ($total_posts)
+ {
+ set_config_count('num_posts', $total_posts, true);
+ }
+
+ if (!function_exists('sync'))
+ {
+ global $phpbb_root_path, $phpEx;
+ include ($phpbb_root_path . 'includes/functions_admin.'.$phpEx);
+ }
+
+ sync('topic', 'topic_id', array_keys($topic_id_list), true);
+ sync('forum', 'forum_id', array_keys($forum_id_list), true, true);
+ unset($topic_id_list, $forum_id_list);
+
+ return true;
+ }
}
-?>
diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php
index 12448ea0ce..b264e35a93 100644
--- a/phpBB/includes/functions_posting.php
+++ b/phpBB/includes/functions_posting.php
@@ -1411,7 +1411,7 @@ function user_notification($mode, $subject, $topic_title, $forum_name, $forum_id
/**
* Delete Post
*/
-function delete_post($forum_id, $topic_id, $post_id, &$data)
+function delete_post($forum_id, $topic_id, $post_id, &$data, $is_soft = false)
{
global $db, $user, $auth;
global $config, $phpEx, $phpbb_root_path;
@@ -1422,10 +1422,14 @@ function delete_post($forum_id, $topic_id, $post_id, &$data)
{
$post_mode = 'delete_topic';
}
- else if ($data['topic_first_post_id'] == $post_id)
+ else if ($data['topic_first_post_id'] == $post_id && !$is_soft)
{
$post_mode = 'delete_first_post';
}
+ else if ($data['topic_first_post_id'] == $post_id && $is_soft)
+ {
+ $post_mode = 'delete_topic';
+ }
else if ($data['topic_last_post_id'] == $post_id)
{
$post_mode = 'delete_last_post';
@@ -1460,14 +1464,22 @@ function delete_post($forum_id, $topic_id, $post_id, &$data)
$db->sql_freeresult($result);
}
- if (!delete_posts('post_id', array($post_id), false, false))
+ if ($is_soft)
+ {
+ phpbb_visibility::set_post_visibility(ITEM_DELETED, $post_id, $topic_id, $forum_id, ($data['topic_first_post_id'] == $post_id), ($data['topic_last_post_id'] == $post_id));
+ phpbb_visibility::hide_post($forum_id, time(), $sql_data);
+ }
+ else
{
- // Try to delete topic, we may had an previous error causing inconsistency
- if ($post_mode == 'delete_topic')
+ if (!delete_posts('post_id', array($post_id), false, false))
{
- delete_topics('topic_id', array($topic_id), false);
+ // Try to delete topic, we may had an previous error causing inconsistency
+ if ($post_mode == 'delete_topic')
+ {
+ delete_topics('topic_id', array($topic_id), false);
+ }
+ trigger_error('ALREADY_DELETED');
}
- trigger_error('ALREADY_DELETED');
}
$db->sql_transaction('commit');
@@ -1486,17 +1498,31 @@ function delete_post($forum_id, $topic_id, $post_id, &$data)
update_post_information('forum', $updated_forum);
}
- delete_topics('topic_id', array($topic_id), false);
+ if ($is_soft)
+ {
+ $topic_row = array();
+ phpbb_visibility::set_topic_visibility(POST_DELETED, $topic_id, $forum_id);
+ phpbb_visibility::hide_topic($topic_id, $forum_id, $topic_row, $sql_data);
+ }
+ else
+ {
+ delete_topics('topic_id', array($topic_id), false);
- $sql_data[FORUMS_TABLE] .= 'forum_topics_real = forum_topics_real - 1';
- $sql_data[FORUMS_TABLE] .= ($data['topic_visibility'] == ITEM_APPROVED) ? ', forum_posts = forum_posts - 1, forum_topics = forum_topics - 1' : '';
- $update_sql = update_post_information('forum', $forum_id, true);
- if (sizeof($update_sql))
- {
- $sql_data[FORUMS_TABLE] .= ($sql_data[FORUMS_TABLE]) ? ', ' : '';
- $sql_data[FORUMS_TABLE] .= implode(', ', $update_sql[$forum_id]);
+ if ($data['topic_type'] != POST_GLOBAL)
+ {
+ $sql_data[FORUMS_TABLE] .= 'forum_topics_real = forum_topics_real - 1';
+ $sql_data[FORUMS_TABLE] .= ($data['topic_visibility'] == ITEM_APPROVED) ? ', forum_posts = forum_posts - 1, forum_topics = forum_topics - 1' : '';
+ }
+
+ $update_sql = update_post_information('forum', $forum_id, true);
+ if (sizeof($update_sql))
+ {
+ $sql_data[FORUMS_TABLE] .= ($sql_data[FORUMS_TABLE]) ? ', ' : '';
+ $sql_data[FORUMS_TABLE] .= implode(', ', $update_sql[$forum_id]);
+ }
}
+
break;
case 'delete_first_post':
@@ -1520,19 +1546,27 @@ function delete_post($forum_id, $topic_id, $post_id, &$data)
break;
case 'delete_last_post':
- $sql_data[FORUMS_TABLE] = ($data['post_visibility'] == ITEM_APPROVED) ? 'forum_posts = forum_posts - 1' : '';
-
- $update_sql = update_post_information('forum', $forum_id, true);
- if (sizeof($update_sql))
+ if ($is_soft)
{
- $sql_data[FORUMS_TABLE] .= ($sql_data[FORUMS_TABLE]) ? ', ' : '';
- $sql_data[FORUMS_TABLE] .= implode(', ', $update_sql[$forum_id]);
+ phpbb_visibility::hide_post($forum_id, time(), $sql_data);
+ phpbb_visibility::set_post_visibility($post_id, $topic_id, $forum_id, false, true);
}
+ else
+ {
+ $sql_data[FORUMS_TABLE] = ($data['post_visibility'] == ITEM_APPROVED) ? 'forum_posts = forum_posts - 1' : '';
+
+ $update_sql = update_post_information('forum', $forum_id, true);
+ if (sizeof($update_sql))
+ {
+ $sql_data[FORUMS_TABLE] .= ($sql_data[FORUMS_TABLE]) ? ', ' : '';
+ $sql_data[FORUMS_TABLE] .= implode(', ', $update_sql[$forum_id]);
+ }
- $sql_data[TOPICS_TABLE] = 'topic_bumped = 0, topic_bumper = 0, topic_replies_real = topic_replies_real - 1' . (($data['post_visibility'] == ITEM_APPROVED) ? ', topic_replies = topic_replies - 1' : '');
+ $sql_data[TOPICS_TABLE] = 'topic_bumped = 0, topic_bumper = 0, topic_replies_real = topic_replies_real - 1' . (($data['post_visibility'] == ITEM_APPROVED) ? ', topic_replies = topic_replies - 1' : '');
+ }
$update_sql = update_post_information('topic', $topic_id, true);
- if (sizeof($update_sql))
+ if (sizeof($update_sql) && !$is_soft)
{
$sql_data[TOPICS_TABLE] .= ', ' . implode(', ', $update_sql[$topic_id]);
$next_post_id = (int) str_replace('topic_last_post_id = ', '', $update_sql[$topic_id][0]);
@@ -1702,7 +1736,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u
// Mods are able to force approved/unapproved posts. True means the post is approved, false the post is unapproved
if (isset($data['force_approved_state']))
{
- $post_approval = ($data['force_approved_state']) ? 1 : 0;
+ $post_approval = ($data['force_approved_state']) ? ITEM_APPROVED : ITEM_UNAPPROVED;
}
// Start the transaction here
@@ -1915,32 +1949,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u
// Correctly set back the topic replies and forum posts... only if the topic was approved before and now gets disapproved
if (!$post_approval && $data['topic_visibility'] == ITEM_APPROVED)
{
- // Do we need to grab some topic informations?
- if (!sizeof($topic_row))
- {
- $sql = 'SELECT topic_type, topic_replies, topic_replies_real, topic_visibility
- FROM ' . TOPICS_TABLE . '
- WHERE topic_id = ' . $data['topic_id'];
- $result = $db->sql_query($sql);
- $topic_row = $db->sql_fetchrow($result);
- $db->sql_freeresult($result);
- }
-
- // If this is the only post remaining we do not need to decrement topic_replies.
- // Also do not decrement if first post - then the topic_replies will not be adjusted if approving the topic again.
-
- // If this is an edited topic or the first post the topic gets completely disapproved later on...
- $sql_data[FORUMS_TABLE]['stat'][] = 'forum_topics = forum_topics - 1';
- $sql_data[FORUMS_TABLE]['stat'][] = 'forum_posts = forum_posts - ' . ($topic_row['topic_replies'] + 1);
-
- set_config_count('num_topics', -1, true);
- set_config_count('num_posts', ($topic_row['topic_replies'] + 1) * (-1), true);
-
- // Only decrement this post, since this is the one non-approved now
- if ($auth->acl_get('f_postcount', $data['forum_id']))
- {
- $sql_data[USERS_TABLE]['stat'][] = 'user_posts = user_posts - 1';
- }
+ phpbb_visibility::hide_topic($data['topic_id'], $data['forum_id'], $topic_row, $sql_data);
}
break;
@@ -1951,6 +1960,8 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u
// Correctly set back the topic replies and forum posts... but only if the post was approved before.
if (!$post_approval && $data['post_visibility'] == ITEM_APPROVED)
{
+ //phpbb_visibility::hide_post($forum_id, $current_time, $sql_data);
+ // ^^ hide_post SQL is identical, except that it does not include the ['stat'] sub-array
$sql_data[TOPICS_TABLE]['stat'][] = 'topic_replies = topic_replies - 1, topic_last_view_time = ' . $current_time;
$sql_data[FORUMS_TABLE]['stat'][] = 'forum_posts = forum_posts - 1';
@@ -1960,6 +1971,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u
{
$sql_data[USERS_TABLE]['stat'][] = 'user_posts = user_posts - 1';
}
+
}
break;
diff --git a/phpBB/includes/mcp/info/mcp_queue.php b/phpBB/includes/mcp/info/mcp_queue.php
index 7ad79f9781..31e9cc9af6 100644
--- a/phpBB/includes/mcp/info/mcp_queue.php
+++ b/phpBB/includes/mcp/info/mcp_queue.php
@@ -21,6 +21,7 @@ class mcp_queue_info
'modes' => array(
'unapproved_topics' => array('title' => 'MCP_QUEUE_UNAPPROVED_TOPICS', 'auth' => 'aclf_m_approve', 'cat' => array('MCP_QUEUE')),
'unapproved_posts' => array('title' => 'MCP_QUEUE_UNAPPROVED_POSTS', 'auth' => 'aclf_m_approve', 'cat' => array('MCP_QUEUE')),
+ 'deleted_posts' => array('title' => 'MCP_QUEUE_DELETED_POSTS', 'auth' => 'aclf_m_restore', 'cat' => array('MCP_QUEUE')),
'approve_details' => array('title' => 'MCP_QUEUE_APPROVE_DETAILS', 'auth' => 'acl_m_approve,$id || (!$id && aclf_m_approve)', 'cat' => array('MCP_QUEUE')),
),
);
diff --git a/phpBB/includes/mcp/mcp_queue.php b/phpBB/includes/mcp/mcp_queue.php
index 833f924efc..c19fb9b2b6 100644
--- a/phpBB/includes/mcp/mcp_queue.php
+++ b/phpBB/includes/mcp/mcp_queue.php
@@ -46,6 +46,7 @@ class mcp_queue
{
case 'approve':
case 'disapprove':
+ case 'restore':
include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx);
$post_id_list = request_var('post_id_list', array(0));
@@ -59,6 +60,10 @@ class mcp_queue
{
approve_post($post_id_list, 'queue', $mode);
}
+ else if ($action == 'restore')
+ {
+// do something
+ }
else
{
disapprove_post($post_id_list, 'queue', $mode);
@@ -224,6 +229,16 @@ class mcp_queue
case 'unapproved_topics':
case 'unapproved_posts':
+ case 'deleted_posts':
+ if ($mode == 'deleted_posts')
+ {
+ $m_perm = 'm_restore';
+ }
+ else
+ {
+ $m_perm = 'm_approve';
+ }
+
$user->add_lang(array('viewtopic', 'viewforum'));
$topic_id = request_var('t', 0);
@@ -242,7 +257,7 @@ class mcp_queue
$forum_id = $topic_info['forum_id'];
}
- $forum_list_approve = get_forum_list('m_approve', false, true);
+ $forum_list_approve = get_forum_list($m_perm, false, true);
$forum_list_read = array_flip(get_forum_list('f_read', true, true)); // Flipped so we can isset() the forum IDs
// Remove forums we cannot read
@@ -277,7 +292,7 @@ class mcp_queue
}
else
{
- $forum_info = get_forum_data(array($forum_id), 'm_approve');
+ $forum_info = get_forum_data(array($forum_id), $m_perm);
if (!sizeof($forum_info))
{
@@ -304,8 +319,10 @@ class mcp_queue
$forum_names = array();
- if ($mode == 'unapproved_posts')
+ if ($mode == 'unapproved_posts' || $mode == 'deleted_posts')
{
+ $visibility_const = ($mode == 'unapproved_posts') ? ITEM_UNAPPROVED : ITEM_DELETED;
+
$sql = 'SELECT p.post_id
FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . ' t' . (($sort_order_sql[0] == 'u') ? ', ' . USERS_TABLE . ' u' : '') . '
WHERE ' . $db->sql_in_set('p.forum_id', $forum_list) . '
@@ -425,13 +442,14 @@ class mcp_queue
// Now display the page
$template->assign_vars(array(
'L_DISPLAY_ITEMS' => ($mode == 'unapproved_posts') ? $user->lang['DISPLAY_POSTS'] : $user->lang['DISPLAY_TOPICS'],
- 'L_EXPLAIN' => ($mode == 'unapproved_posts') ? $user->lang['MCP_QUEUE_UNAPPROVED_POSTS_EXPLAIN'] : $user->lang['MCP_QUEUE_UNAPPROVED_TOPICS_EXPLAIN'],
- 'L_TITLE' => ($mode == 'unapproved_posts') ? $user->lang['MCP_QUEUE_UNAPPROVED_POSTS'] : $user->lang['MCP_QUEUE_UNAPPROVED_TOPICS'],
+ 'L_EXPLAIN' => $user->lang['MCP_QUEUE_' . strtoupper($mode) . '_EXPLAIN'],
+ 'L_TITLE' => $user->lang['MCP_QUEUE_' . strtoupper($mode)],
'L_ONLY_TOPIC' => ($topic_id) ? sprintf($user->lang['ONLY_TOPIC'], $topic_info['topic_title']) : '',
'S_FORUM_OPTIONS' => $forum_options,
'S_MCP_ACTION' => build_url(array('t', 'f', 'sd', 'st', 'sk')),
- 'S_TOPICS' => ($mode == 'unapproved_posts') ? false : true,
+ 'S_TOPICS' => ($mode == 'unapproved_topics') ? true : false,
+ 'S_RESTORE' => ($mode == 'deleted_posts') ? true : false,
'PAGE_NUMBER' => phpbb_on_page($template, $user, $base_url, $total, $config['topics_per_page'], $start),
'TOPIC_ID' => $topic_id,
@@ -475,127 +493,7 @@ function approve_post($post_id_list, $id, $mode)
{
$notify_poster = (isset($_REQUEST['notify_poster'])) ? true : false;
- // If Topic -> total_topics = total_topics+1, total_posts = total_posts+1, forum_topics = forum_topics+1, forum_posts = forum_posts+1
- // If Post -> total_posts = total_posts+1, forum_posts = forum_posts+1, topic_replies = topic_replies+1
-
- $total_topics = $total_posts = 0;
- $topic_approve_sql = $post_approve_sql = $topic_id_list = $forum_id_list = $approve_log = array();
- $user_posts_sql = $post_approved_list = array();
-
- foreach ($post_info as $post_id => $post_data)
- {
- if ($post_data['post_visibility'] == ITEM_APPROVED)
- {
- $post_approved_list[] = $post_id;
- continue;
- }
-
- $topic_id_list[$post_data['topic_id']] = 1;
- $forum_id_list[$post_data['forum_id']] = 1;
-
- // User post update (we do not care about topic or post, since user posts are strictly connected to posts)
- // But we care about forums where post counts get not increased. ;)
- if ($post_data['post_postcount'])
- {
- $user_posts_sql[$post_data['poster_id']] = (empty($user_posts_sql[$post_data['poster_id']])) ? 1 : $user_posts_sql[$post_data['poster_id']] + 1;
- }
-
- // Topic or Post. ;)
- if ($post_data['topic_first_post_id'] == $post_id)
- {
- $total_topics++;
- $topic_approve_sql[] = $post_data['topic_id'];
-
- $approve_log[] = array(
- 'type' => 'topic',
- 'post_subject' => $post_data['post_subject'],
- 'forum_id' => $post_data['forum_id'],
- 'topic_id' => $post_data['topic_id'],
- );
- }
- else
- {
- $approve_log[] = array(
- 'type' => 'post',
- 'post_subject' => $post_data['post_subject'],
- 'forum_id' => $post_data['forum_id'],
- 'topic_id' => $post_data['topic_id'],
- );
- }
-
- $total_posts++;
-
- // Increment by topic_replies if we approve a topic...
- // This works because we do not adjust the topic_replies when re-approving a topic after an edit.
- if ($post_data['topic_first_post_id'] == $post_id && $post_data['topic_replies'])
- {
- $total_posts += $post_data['topic_replies'];
- }
-
- $post_approve_sql[] = $post_id;
- }
-
- $post_id_list = array_values(array_diff($post_id_list, $post_approved_list));
- for ($i = 0, $size = sizeof($post_approved_list); $i < $size; $i++)
- {
- unset($post_info[$post_approved_list[$i]]);
- }
-
- if (sizeof($topic_approve_sql))
- {
- $sql = 'UPDATE ' . TOPICS_TABLE . '
- SET topic_visibility = ' . ITEM_APPROVED . '
- WHERE ' . $db->sql_in_set('topic_id', $topic_approve_sql);
- $db->sql_query($sql);
- }
-
- if (sizeof($post_approve_sql))
- {
- $sql = 'UPDATE ' . POSTS_TABLE . '
- SET post_visibility = ' . ITEM_APPROVED . '
- WHERE ' . $db->sql_in_set('post_id', $post_approve_sql);
- $db->sql_query($sql);
- }
-
- unset($topic_approve_sql, $post_approve_sql);
-
- foreach ($approve_log as $log_data)
- {
- add_log('mod', $log_data['forum_id'], $log_data['topic_id'], ($log_data['type'] == 'topic') ? 'LOG_TOPIC_APPROVED' : 'LOG_POST_APPROVED', $log_data['post_subject']);
- }
-
- if (sizeof($user_posts_sql))
- {
- // Try to minimize the query count by merging users with the same post count additions
- $user_posts_update = array();
-
- foreach ($user_posts_sql as $user_id => $user_posts)
- {
- $user_posts_update[$user_posts][] = $user_id;
- }
-
- foreach ($user_posts_update as $user_posts => $user_id_ary)
- {
- $sql = 'UPDATE ' . USERS_TABLE . '
- SET user_posts = user_posts + ' . $user_posts . '
- WHERE ' . $db->sql_in_set('user_id', $user_id_ary);
- $db->sql_query($sql);
- }
- }
-
- if ($total_topics)
- {
- set_config_count('num_topics', $total_topics, true);
- }
-
- if ($total_posts)
- {
- set_config_count('num_posts', $total_posts, true);
- }
-
- sync('topic', 'topic_id', array_keys($topic_id_list), true);
- sync('forum', 'forum_id', array_keys($forum_id_list), true, true);
- unset($topic_id_list, $forum_id_list);
+ phpbb_visibility::unhide_posts_topics('approve', $post_info, $post_id_list);
$messenger = new messenger();