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/includes/acp/acp_forums.php | 8 ++-- phpBB/includes/acp/acp_main.php | 6 +-- phpBB/includes/acp/acp_users.php | 4 +- phpBB/includes/constants.php | 4 ++ phpBB/includes/functions_admin.php | 77 +++++++++++++++++-------------- phpBB/includes/functions_convert.php | 6 +-- phpBB/includes/functions_posting.php | 64 ++++++++++++------------- phpBB/includes/mcp/mcp_forum.php | 10 ++-- phpBB/includes/mcp/mcp_front.php | 4 +- phpBB/includes/mcp/mcp_main.php | 12 ++--- phpBB/includes/mcp/mcp_post.php | 4 +- phpBB/includes/mcp/mcp_queue.php | 12 ++--- phpBB/includes/mcp/mcp_reports.php | 2 +- phpBB/includes/mcp/mcp_topic.php | 22 ++++----- phpBB/includes/search/fulltext_mysql.php | 14 +++--- phpBB/includes/search/fulltext_native.php | 15 +++--- 16 files changed, 142 insertions(+), 122 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/acp/acp_forums.php b/phpBB/includes/acp/acp_forums.php index c6dbf5eb9c..622d84d15e 100644 --- a/phpBB/includes/acp/acp_forums.php +++ b/phpBB/includes/acp/acp_forums.php @@ -314,7 +314,7 @@ class acp_forums $end = $start + $batch_size; // Sync all topics in batch mode... - sync('topic_approved', 'range', 'topic_id BETWEEN ' . $start . ' AND ' . $end, true, false); + sync('topic_visibility', 'range', 'topic_id BETWEEN ' . $start . ' AND ' . $end, true, false); sync('topic', 'range', 'topic_id BETWEEN ' . $start . ' AND ' . $end, true, true); if ($end < $row2['max_topic_id']) @@ -1793,7 +1793,7 @@ class acp_forums FROM ' . POSTS_TABLE . ' WHERE forum_id = ' . $forum_id . ' AND post_postcount = 1 - AND post_approved = 1'; + AND post_visibility = ' . ITEM_APPROVED; $result = $db->sql_query($sql); $post_counts = array(); @@ -1931,7 +1931,7 @@ class acp_forums // Make sure the overall post/topic count is correct... $sql = 'SELECT COUNT(post_id) AS stat FROM ' . POSTS_TABLE . ' - WHERE post_approved = 1'; + WHERE post_visibility = ' . ITEM_APPROVED; $result = $db->sql_query($sql); $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); @@ -1940,7 +1940,7 @@ class acp_forums $sql = 'SELECT COUNT(topic_id) AS stat FROM ' . TOPICS_TABLE . ' - WHERE topic_approved = 1'; + WHERE topic_visibility = ' . ITEM_APPROVED; $result = $db->sql_query($sql); $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); diff --git a/phpBB/includes/acp/acp_main.php b/phpBB/includes/acp/acp_main.php index eb613535bf..0584bb510e 100644 --- a/phpBB/includes/acp/acp_main.php +++ b/phpBB/includes/acp/acp_main.php @@ -144,14 +144,14 @@ class acp_main $sql = 'SELECT COUNT(post_id) AS stat FROM ' . POSTS_TABLE . ' - WHERE post_approved = 1'; + WHERE post_visibility = ' . ITEM_APPROVED; $result = $db->sql_query($sql); set_config('num_posts', (int) $db->sql_fetchfield('stat'), true); $db->sql_freeresult($result); $sql = 'SELECT COUNT(topic_id) AS stat FROM ' . TOPICS_TABLE . ' - WHERE topic_approved = 1'; + WHERE topic_visibility = ' . ITEM_APPROVED; $result = $db->sql_query($sql); set_config('num_topics', (int) $db->sql_fetchfield('stat'), true); $db->sql_freeresult($result); @@ -232,7 +232,7 @@ class acp_main $sql = 'SELECT COUNT(post_id) AS num_posts, poster_id FROM ' . POSTS_TABLE . ' WHERE post_id BETWEEN ' . ($start + 1) . ' AND ' . ($start + $step) . ' - AND post_postcount = 1 AND post_approved = 1 + AND post_postcount = 1 AND post_visibility = ' . ITEM_APPROVED . ' GROUP BY poster_id'; $result = $db->sql_query($sql); diff --git a/phpBB/includes/acp/acp_users.php b/phpBB/includes/acp/acp_users.php index b54257b04a..304027df45 100644 --- a/phpBB/includes/acp/acp_users.php +++ b/phpBB/includes/acp/acp_users.php @@ -676,7 +676,7 @@ class acp_users 'topic_time' => time(), 'forum_id' => $new_forum_id, 'icon_id' => 0, - 'topic_approved' => 1, + 'topic_visibility' => ITEM_APPROVED, 'topic_title' => $post_ary['title'], 'topic_first_poster_name' => $user_row['username'], 'topic_type' => POST_NORMAL, @@ -1033,7 +1033,7 @@ class acp_users $sql = 'SELECT COUNT(post_id) as posts_in_queue FROM ' . POSTS_TABLE . ' WHERE poster_id = ' . $user_id . ' - AND post_approved = 0'; + AND post_visibility = ' . ITEM_UNAPPROVED; $result = $db->sql_query($sql); $user_row['posts_in_queue'] = (int) $db->sql_fetchfield('posts_in_queue'); $db->sql_freeresult($result); diff --git a/phpBB/includes/constants.php b/phpBB/includes/constants.php index 68af41ab20..62c06dc1d0 100644 --- a/phpBB/includes/constants.php +++ b/phpBB/includes/constants.php @@ -87,6 +87,10 @@ define('ITEM_UNLOCKED', 0); define('ITEM_LOCKED', 1); define('ITEM_MOVED', 2); +define('ITEM_UNAPPROVED', 0); // => has not yet been approved +define('ITEM_APPROVED', 1); // => has been approved, and has not been soft deleted +define('ITEM_DELETED', 2); // => has been soft deleted + // Forum Flags define('FORUM_FLAG_LINK_TRACK', 1); define('FORUM_FLAG_PRUNE_POLL', 2); diff --git a/phpBB/includes/functions_admin.php b/phpBB/includes/functions_admin.php index 5e2ee8c8f6..328c8e9778 100644 --- a/phpBB/includes/functions_admin.php +++ b/phpBB/includes/functions_admin.php @@ -644,7 +644,7 @@ function delete_topics($where_type, $where_ids, $auto_sync = true, $post_count_s 'posts' => ($call_delete_posts) ? delete_posts($where_type, $where_ids, false, true, $post_count_sync, false) : 0, ); - $sql = 'SELECT topic_id, forum_id, topic_approved, topic_moved_id + $sql = 'SELECT topic_id, forum_id, topic_visibility, topic_moved_id FROM ' . TOPICS_TABLE . ' WHERE ' . $where_clause; $result = $db->sql_query($sql); @@ -654,7 +654,7 @@ function delete_topics($where_type, $where_ids, $auto_sync = true, $post_count_s $forum_ids[] = $row['forum_id']; $topic_ids[] = $row['topic_id']; - if ($row['topic_approved'] && !$row['topic_moved_id']) + if ($row['topic_visibility'] == ITEM_APPROVED && !$row['topic_moved_id']) { $approved_topics++; } @@ -767,7 +767,7 @@ function delete_posts($where_type, $where_ids, $auto_sync = true, $posted_sync = $approved_posts = 0; $post_ids = $topic_ids = $forum_ids = $post_counts = $remove_topics = array(); - $sql = 'SELECT post_id, poster_id, post_approved, post_postcount, topic_id, forum_id + $sql = 'SELECT post_id, poster_id, post_visibility, post_postcount, topic_id, forum_id FROM ' . POSTS_TABLE . ' WHERE ' . $where_clause; $result = $db->sql_query($sql); @@ -779,12 +779,12 @@ function delete_posts($where_type, $where_ids, $auto_sync = true, $posted_sync = $topic_ids[] = (int) $row['topic_id']; $forum_ids[] = (int) $row['forum_id']; - if ($row['post_postcount'] && $post_count_sync && $row['post_approved']) + if ($row['post_postcount'] && $post_count_sync && $row['post_visibility'] == ITEM_APPROVED) { $post_counts[$row['poster_id']] = (!empty($post_counts[$row['poster_id']])) ? $post_counts[$row['poster_id']] + 1 : 1; } - if ($row['post_approved']) + if ($row['post_visibility'] == ITEM_APPROVED) { $approved_posts++; } @@ -1274,7 +1274,7 @@ function phpbb_unlink($filename, $mode = 'file', $entry_removed = false) * - forum Resync complete forum * - topic Resync topics * - topic_moved Removes topic shadows that would be in the same forum as the topic they link to -* - topic_approved Resyncs the topic_approved flag according to the status of the first post +* - topic_visibility Resyncs the topic_visibility flag according to the status of the first post * - post_reported Resyncs the post_reported flag, relying on actual reports * - topic_reported Resyncs the topic_reported flag, relying on post_reported flags * - post_attachement Same as post_reported, but with attachment flags @@ -1294,7 +1294,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false, $where_ids = ($where_ids) ? array((int) $where_ids) : array(); } - if ($mode == 'forum' || $mode == 'topic' || $mode == 'topic_approved' || $mode == 'topic_reported' || $mode == 'post_reported') + if ($mode == 'forum' || $mode == 'topic' || $mode == 'topic_visibility' || $mode == 'topic_reported' || $mode == 'post_reported') { if (!$where_type) { @@ -1380,7 +1380,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false, $db->sql_transaction('commit'); break; - case 'topic_approved': + case 'topic_visibility': $db->sql_transaction('begin'); switch ($db->sql_layer) @@ -1388,22 +1388,22 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false, case 'mysql4': case 'mysqli': $sql = 'UPDATE ' . TOPICS_TABLE . ' t, ' . POSTS_TABLE . " p - SET t.topic_approved = p.post_approved + SET t.topic_visibility = p.post_visibility $where_sql_and t.topic_first_post_id = p.post_id"; $db->sql_query($sql); break; default: - $sql = 'SELECT t.topic_id, p.post_approved + $sql = 'SELECT t.topic_id, p.post_visibility FROM ' . TOPICS_TABLE . ' t, ' . POSTS_TABLE . " p $where_sql_and p.post_id = t.topic_first_post_id - AND p.post_approved <> t.topic_approved"; + AND p.post_visibility <> t.topic_visibility"; $result = $db->sql_query($sql); $topic_ids = array(); while ($row = $db->sql_fetchrow($result)) { - $topic_ids[] = $row['topic_id']; + $topic_ids[$row['topic_id']] = $row['post_visibility']; } $db->sql_freeresult($result); @@ -1412,10 +1412,13 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false, return; } - $sql = 'UPDATE ' . TOPICS_TABLE . ' - SET topic_approved = 1 - topic_approved - WHERE ' . $db->sql_in_set('topic_id', $topic_ids); - $db->sql_query($sql); + foreach ($topic_ids as $topic_id => $visibility) + { + $sql = 'UPDATE ' . TOPICS_TABLE . ' + SET topic_visibility = ' . $visibility . ' + WHERE topic_id' . $topic_id; + $db->sql_query($sql); + } break; } @@ -1680,10 +1683,10 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false, // 2: Get topic counts for each forum (optional) if ($sync_extra) { - $sql = 'SELECT forum_id, topic_approved, COUNT(topic_id) AS forum_topics + $sql = 'SELECT forum_id, topic_visibility, COUNT(topic_id) AS forum_topics FROM ' . TOPICS_TABLE . ' WHERE ' . $db->sql_in_set('forum_id', $forum_ids) . ' - GROUP BY forum_id, topic_approved'; + GROUP BY forum_id, topic_visibility'; $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) @@ -1691,7 +1694,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false, $forum_id = (int) $row['forum_id']; $forum_data[$forum_id]['topics_real'] += $row['forum_topics']; - if ($row['topic_approved']) + if ($row['topic_visibility'] == ITEM_APPROVED) { $forum_data[$forum_id]['topics'] = $row['forum_topics']; } @@ -1707,7 +1710,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false, $sql = 'SELECT SUM(t.topic_replies + 1) AS forum_posts FROM ' . TOPICS_TABLE . ' t WHERE ' . $db->sql_in_set('t.forum_id', $forum_ids) . ' - AND t.topic_approved = 1 + AND t.topic_visibility = ' . ITEM_APPROVED . ' AND t.topic_status <> ' . ITEM_MOVED; } else @@ -1715,7 +1718,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false, $sql = 'SELECT t.forum_id, SUM(t.topic_replies + 1) AS forum_posts FROM ' . TOPICS_TABLE . ' t WHERE ' . $db->sql_in_set('t.forum_id', $forum_ids) . ' - AND t.topic_approved = 1 + AND t.topic_visibility = ' . ITEM_APPROVED . ' AND t.topic_status <> ' . ITEM_MOVED . ' GROUP BY t.forum_id'; } @@ -1737,14 +1740,14 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false, $sql = 'SELECT MAX(t.topic_last_post_id) as last_post_id FROM ' . TOPICS_TABLE . ' t WHERE ' . $db->sql_in_set('t.forum_id', $forum_ids) . ' - AND t.topic_approved = 1'; + AND t.topic_visibility = ' . ITEM_APPROVED; } else { $sql = 'SELECT t.forum_id, MAX(t.topic_last_post_id) as last_post_id FROM ' . TOPICS_TABLE . ' t WHERE ' . $db->sql_in_set('t.forum_id', $forum_ids) . ' - AND t.topic_approved = 1 + AND t.topic_visibility = ' . ITEM_APPROVED . ' GROUP BY t.forum_id'; } @@ -1846,7 +1849,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false, $db->sql_transaction('begin'); - $sql = 'SELECT t.topic_id, t.forum_id, t.topic_moved_id, t.topic_approved, ' . (($sync_extra) ? 't.topic_attachment, t.topic_reported, ' : '') . 't.topic_poster, t.topic_time, t.topic_replies, t.topic_replies_real, t.topic_first_post_id, t.topic_first_poster_name, t.topic_first_poster_colour, t.topic_last_post_id, t.topic_last_post_subject, t.topic_last_poster_id, t.topic_last_poster_name, t.topic_last_poster_colour, t.topic_last_post_time + $sql = 'SELECT t.topic_id, t.forum_id, t.topic_moved_id, t.topic_visibility, ' . (($sync_extra) ? 't.topic_attachment, t.topic_reported, ' : '') . 't.topic_poster, t.topic_time, t.topic_replies, t.topic_replies_real, t.topic_first_post_id, t.topic_first_poster_name, t.topic_first_poster_colour, t.topic_last_post_id, t.topic_last_post_subject, t.topic_last_poster_id, t.topic_last_poster_name, t.topic_last_poster_colour, t.topic_last_post_time FROM ' . TOPICS_TABLE . " t $where_sql"; $result = $db->sql_query($sql); @@ -1880,10 +1883,10 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false, // Use "t" as table alias because of the $where_sql clause // NOTE: 't.post_approved' in the GROUP BY is causing a major slowdown. - $sql = 'SELECT t.topic_id, t.post_approved, COUNT(t.post_id) AS total_posts, MIN(t.post_id) AS first_post_id, MAX(t.post_id) AS last_post_id + $sql = 'SELECT t.topic_id, t.post_visibility, COUNT(t.post_id) AS total_posts, MIN(t.post_id) AS first_post_id, MAX(t.post_id) AS last_post_id FROM ' . POSTS_TABLE . " t $where_sql - GROUP BY t.topic_id, t.post_approved"; + GROUP BY t.topic_id, t.post_visibility"; $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) @@ -1907,7 +1910,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false, $topic_data[$topic_id]['replies_real'] += $row['total_posts']; $topic_data[$topic_id]['first_post_id'] = (!$topic_data[$topic_id]['first_post_id']) ? $row['first_post_id'] : min($topic_data[$topic_id]['first_post_id'], $row['first_post_id']); - if ($row['post_approved'] || !$topic_data[$topic_id]['last_post_id']) + if ($row['post_visibility'] || !$topic_data[$topic_id]['last_post_id']) { $topic_data[$topic_id]['replies'] = $row['total_posts'] - 1; $topic_data[$topic_id]['last_post_id'] = $row['last_post_id']; @@ -1952,7 +1955,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false, unset($delete_topics, $delete_topic_ids); } - $sql = 'SELECT p.post_id, p.topic_id, p.post_approved, p.poster_id, p.post_subject, p.post_username, p.post_time, u.username, u.user_colour + $sql = 'SELECT p.post_id, p.topic_id, p.post_visibility, p.poster_id, p.post_subject, p.post_username, p.post_time, u.username, u.user_colour FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . ' u WHERE ' . $db->sql_in_set('p.post_id', $post_ids) . ' AND u.user_id = p.poster_id'; @@ -1965,9 +1968,9 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false, if ($row['post_id'] == $topic_data[$topic_id]['first_post_id']) { - if ($topic_data[$topic_id]['topic_approved'] != $row['post_approved']) + if ($topic_data[$topic_id]['topic_visibility'] != $row['post_visibility']) { - $approved_unapproved_ids[] = $topic_id; + $approved_unapproved_ids[$topic_id] = $row['post_visibility']; } $topic_data[$topic_id]['time'] = $row['post_time']; $topic_data[$topic_id]['poster'] = $row['poster_id']; @@ -2029,7 +2032,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false, $sync_shadow_topics = array(); if (sizeof($post_ids)) { - $sql = 'SELECT p.post_id, p.topic_id, p.post_approved, p.poster_id, p.post_subject, p.post_username, p.post_time, u.username, u.user_colour + $sql = 'SELECT p.post_id, p.topic_id, p.post_visibility, p.poster_id, p.post_subject, p.post_username, p.post_time, u.username, u.user_colour FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . ' u WHERE ' . $db->sql_in_set('p.post_id', $post_ids) . ' AND u.user_id = p.poster_id'; @@ -2099,10 +2102,14 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false, // approved becomes unapproved, and vice-versa if (sizeof($approved_unapproved_ids)) { - $sql = 'UPDATE ' . TOPICS_TABLE . ' - SET topic_approved = 1 - topic_approved - WHERE ' . $db->sql_in_set('topic_id', $approved_unapproved_ids); - $db->sql_query($sql); + foreach ($approved_unapproved_ids as $update_topic_id => $status) + { + // @TODO: Consider grouping by $status and only running 3 queries + $sql = 'UPDATE ' . TOPICS_TABLE . ' + SET topic_visibility = ' . $status . ' + WHERE topic_id = ' . $update_topic_id; + $db->sql_query($sql); + } } unset($approved_unapproved_ids); diff --git a/phpBB/includes/functions_convert.php b/phpBB/includes/functions_convert.php index ac791e0d9b..a34a193f60 100644 --- a/phpBB/includes/functions_convert.php +++ b/phpBB/includes/functions_convert.php @@ -1768,7 +1768,7 @@ function sync_post_count($offset, $limit) $sql = 'SELECT COUNT(post_id) AS num_posts, poster_id FROM ' . POSTS_TABLE . ' WHERE post_postcount = 1 - AND post_approved = 1 + AND post_visibility = ' . ITEM_APPROVED . ' GROUP BY poster_id ORDER BY poster_id'; $result = $db->sql_query_limit($sql, $limit, $offset); @@ -1941,7 +1941,7 @@ function update_dynamic_config() $sql = 'SELECT COUNT(post_id) AS stat FROM ' . POSTS_TABLE . ' - WHERE post_approved = 1'; + WHERE post_visibility = ' . ITEM_APPROVED; $result = $db->sql_query($sql); $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); @@ -1950,7 +1950,7 @@ function update_dynamic_config() $sql = 'SELECT COUNT(topic_id) AS stat FROM ' . TOPICS_TABLE . ' - WHERE topic_approved = 1'; + WHERE topic_visibility = ' . ITEM_APPROVED; $result = $db->sql_query($sql); $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index c50395a5df..2f51200b48 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -176,7 +176,7 @@ function update_post_information($type, $ids, $return_update_sql = false) if ($type != 'topic') { $topic_join = ', ' . TOPICS_TABLE . ' t'; - $topic_condition = 'AND t.topic_id = p.topic_id AND t.topic_approved = 1'; + $topic_condition = 'AND t.topic_id = p.topic_id AND t.topic_visibility = ' . ITEM_APPROVED; } else { @@ -190,7 +190,7 @@ function update_post_information($type, $ids, $return_update_sql = false) FROM ' . POSTS_TABLE . " p $topic_join WHERE " . $db->sql_in_set('p.' . $type . '_id', $ids) . " $topic_condition - AND p.post_approved = 1"; + AND p.post_visibility = " . ITEM_APPROVED; } else { @@ -198,7 +198,7 @@ function update_post_information($type, $ids, $return_update_sql = false) FROM ' . POSTS_TABLE . " p $topic_join WHERE " . $db->sql_in_set('p.' . $type . '_id', $ids) . " $topic_condition - AND p.post_approved = 1 + AND p.post_visibility = " . ITEM_APPROVED . " GROUP BY p.{$type}_id"; } $result = $db->sql_query($sql); @@ -993,7 +993,7 @@ function topic_review($topic_id, $forum_id, $mode = 'topic_review', $cur_post_id $sql = 'SELECT p.post_id FROM ' . POSTS_TABLE . ' p' . " WHERE p.topic_id = $topic_id - " . ((!$auth->acl_get('m_approve', $forum_id)) ? 'AND p.post_approved = 1' : '') . ' + AND " . topic_visibility::get_visibility_sql('post', $forum_id, 'p.') . ' ' . (($mode == 'post_review') ? " AND p.post_id > $cur_post_id" : '') . ' ' . (($mode == 'post_review_edit') ? " AND p.post_id = $cur_post_id" : '') . ' ORDER BY p.post_time '; @@ -1489,7 +1489,7 @@ function delete_post($forum_id, $topic_id, $post_id, &$data) 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_approved']) ? ', forum_posts = forum_posts - 1, forum_topics = forum_topics - 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)) @@ -1509,18 +1509,18 @@ function delete_post($forum_id, $topic_id, $post_id, &$data) $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); - $sql_data[FORUMS_TABLE] = ($data['post_approved']) ? 'forum_posts = forum_posts - 1' : ''; + $sql_data[FORUMS_TABLE] = ($data['post_visibility'] == ITEM_APPROVED) ? 'forum_posts = forum_posts - 1' : ''; $sql_data[TOPICS_TABLE] = 'topic_poster = ' . intval($row['poster_id']) . ', topic_first_post_id = ' . intval($row['post_id']) . ", topic_first_poster_colour = '" . $db->sql_escape($row['user_colour']) . "', topic_first_poster_name = '" . (($row['poster_id'] == ANONYMOUS) ? $db->sql_escape($row['post_username']) : $db->sql_escape($row['username'])) . "', topic_time = " . (int) $row['post_time']; // Decrementing topic_replies here is fine because this case only happens if there is more than one post within the topic - basically removing one "reply" - $sql_data[TOPICS_TABLE] .= ', topic_replies_real = topic_replies_real - 1' . (($data['post_approved']) ? ', topic_replies = topic_replies - 1' : ''); + $sql_data[TOPICS_TABLE] .= ', topic_replies_real = topic_replies_real - 1' . (($data['post_visibility'] == ITEM_APPROVED) ? ', topic_replies = topic_replies - 1' : ''); $next_post_id = (int) $row['post_id']; break; case 'delete_last_post': - $sql_data[FORUMS_TABLE] = ($data['post_approved']) ? 'forum_posts = forum_posts - 1' : ''; + $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)) @@ -1529,7 +1529,7 @@ function delete_post($forum_id, $topic_id, $post_id, &$data) $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_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)) @@ -1541,8 +1541,8 @@ function delete_post($forum_id, $topic_id, $post_id, &$data) { $sql = 'SELECT MAX(post_id) as last_post_id FROM ' . POSTS_TABLE . " - WHERE topic_id = $topic_id " . - ((!$auth->acl_get('m_approve', $forum_id)) ? 'AND post_approved = 1' : ''); + WHERE topic_id = $topic_id + AND " . topic_visibility::get_visibility_sql('post', $forum_id); $result = $db->sql_query($sql); $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); @@ -1554,17 +1554,17 @@ function delete_post($forum_id, $topic_id, $post_id, &$data) case 'delete': $sql = 'SELECT post_id FROM ' . POSTS_TABLE . " - WHERE topic_id = $topic_id " . - ((!$auth->acl_get('m_approve', $forum_id)) ? 'AND post_approved = 1' : '') . ' + WHERE topic_id = $topic_id + AND " . topic_visibility::get_visibility_sql('post', $forum_id) . ' AND post_time > ' . $data['post_time'] . ' ORDER BY post_time ASC'; $result = $db->sql_query_limit($sql, 1); $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); - $sql_data[FORUMS_TABLE] = ($data['post_approved']) ? 'forum_posts = forum_posts - 1' : ''; + $sql_data[FORUMS_TABLE] = ($data['post_visibility'] == ITEM_APPROVED) ? 'forum_posts = forum_posts - 1' : ''; - $sql_data[TOPICS_TABLE] = 'topic_replies_real = topic_replies_real - 1' . (($data['post_approved']) ? ', topic_replies = topic_replies - 1' : ''); + $sql_data[TOPICS_TABLE] = 'topic_replies_real = topic_replies_real - 1' . (($data['post_visibility'] == ITEM_APPROVED) ? ', topic_replies = topic_replies - 1' : ''); $next_post_id = (int) $row['post_id']; break; } @@ -1674,9 +1674,9 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u $poster_id = ($mode == 'edit') ? $data['poster_id'] : (int) $user->data['user_id']; // Retrieve some additional information if not present - if ($mode == 'edit' && (!isset($data['post_approved']) || !isset($data['topic_approved']) || $data['post_approved'] === false || $data['topic_approved'] === false)) + if ($mode == 'edit' && (!isset($data['post_visibility']) || !isset($data['topic_visibility']) || $data['post_visibility'] === false || $data['topic_visibility'] === false)) { - $sql = 'SELECT p.post_approved, t.topic_type, t.topic_replies, t.topic_replies_real, t.topic_approved + $sql = 'SELECT p.post_visibility, t.topic_type, t.topic_replies, t.topic_replies_real, t.topic_visibility FROM ' . TOPICS_TABLE . ' t, ' . POSTS_TABLE . ' p WHERE t.topic_id = p.topic_id AND p.post_id = ' . $data['post_id']; @@ -1684,8 +1684,8 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u $topic_row = $db->sql_fetchrow($result); $db->sql_freeresult($result); - $data['topic_approved'] = $topic_row['topic_approved']; - $data['post_approved'] = $topic_row['post_approved']; + $data['topic_visibility'] = $topic_row['topic_visibility']; + $data['post_visibility'] = $topic_row['post_visibility']; } // This variable indicates if the user is able to post or put into the queue - it is used later for all code decisions regarding approval @@ -1719,7 +1719,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u 'icon_id' => $data['icon_id'], 'poster_ip' => $user->ip, 'post_time' => $current_time, - 'post_approved' => $post_approval, + 'post_visibility' => $post_approval, 'enable_bbcode' => $data['enable_bbcode'], 'enable_smilies' => $data['enable_smilies'], 'enable_magic_url' => $data['enable_urls'], @@ -1785,7 +1785,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u 'forum_id' => $data['forum_id'], 'poster_id' => $data['poster_id'], 'icon_id' => $data['icon_id'], - 'post_approved' => (!$post_approval) ? 0 : $data['post_approved'], + 'post_visibility' => (!$post_approval) ? 0 : $data['post_visibility'], 'enable_bbcode' => $data['enable_bbcode'], 'enable_smilies' => $data['enable_smilies'], 'enable_magic_url' => $data['enable_urls'], @@ -1807,7 +1807,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u break; } - $post_approved = $sql_data[POSTS_TABLE]['sql']['post_approved']; + $post_approved = $sql_data[POSTS_TABLE]['sql']['post_visibility']; $topic_row = array(); // And the topic ladies and gentlemen @@ -1820,7 +1820,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u 'topic_last_view_time' => $current_time, 'forum_id' => $data['forum_id'], 'icon_id' => $data['icon_id'], - 'topic_approved' => $post_approval, + 'topic_visibility' => $post_approval, 'topic_title' => $subject, 'topic_first_poster_name' => (!$user->data['is_registered'] && $username) ? $username : (($user->data['user_id'] != ANONYMOUS) ? $user->data['username'] : ''), 'topic_first_poster_colour' => $user->data['user_colour'], @@ -1897,7 +1897,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u $sql_data[TOPICS_TABLE]['sql'] = array( 'forum_id' => $data['forum_id'], 'icon_id' => $data['icon_id'], - 'topic_approved' => (!$post_approval) ? 0 : $data['topic_approved'], + 'topic_visibility' => (!$post_approval) ? 0 : $data['topic_visibility'], 'topic_title' => $subject, 'topic_first_poster_name' => $username, 'topic_type' => $topic_type, @@ -1913,12 +1913,12 @@ 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_approved']) + 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_approved + $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); @@ -1949,7 +1949,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u case 'edit_last_post': // Correctly set back the topic replies and forum posts... but only if the post was approved before. - if (!$post_approval && $data['post_approved']) + if (!$post_approval && $data['post_visibility'] == ITEM_APPROVED) { $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'; @@ -2173,7 +2173,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u // we need to update the last forum information // only applicable if the topic is approved - if ($post_approved || !$data['post_approved']) + if ($post_approved || $data['post_visibility'] != ITEM_APPROVED) { // the last post makes us update the forum table. This can happen if... // We make a new topic @@ -2219,13 +2219,13 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u $sql_data[FORUMS_TABLE]['stat'][] = "forum_last_poster_name = '" . $db->sql_escape($username) . "'"; } } - else if ($data['post_approved'] !== $post_approved) + else if ($data['post_visibility'] !== $post_approved) { // we need a fresh change of socks, everything has become invalidated $sql = 'SELECT MAX(topic_last_post_id) as last_post_id FROM ' . TOPICS_TABLE . ' WHERE forum_id = ' . (int) $data['forum_id'] . ' - AND topic_approved = 1'; + AND topic_visibility = ' . ITEM_APPROVED; $result = $db->sql_query($sql); $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); @@ -2290,13 +2290,13 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u } } } - else if (!$data['post_approved'] && ($post_mode == 'edit_last_post' || $post_mode == 'edit_topic' || ($post_mode == 'edit_first_post' && !$data['topic_replies']))) + else if (!$data['post_visibility'] == ITEM_APPROVED && ($post_mode == 'edit_last_post' || $post_mode == 'edit_topic' || ($post_mode == 'edit_first_post' && !$data['topic_replies']))) { // like having the rug pulled from under us $sql = 'SELECT MAX(post_id) as last_post_id FROM ' . POSTS_TABLE . ' WHERE topic_id = ' . (int) $data['topic_id'] . ' - AND post_approved = 1'; + AND post_visibility = ' . ITEM_APPROVED; $result = $db->sql_query($sql); $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); diff --git a/phpBB/includes/mcp/mcp_forum.php b/phpBB/includes/mcp/mcp_forum.php index 7b3bc82093..48b9c7c2d3 100644 --- a/phpBB/includes/mcp/mcp_forum.php +++ b/phpBB/includes/mcp/mcp_forum.php @@ -154,7 +154,7 @@ function mcp_forum_view($id, $mode, $action, $forum_info) $sql = 'SELECT t.topic_id FROM ' . TOPICS_TABLE . ' t WHERE t.forum_id = ' . $forum_id . ' - ' . (($auth->acl_get('m_approve', $forum_id)) ? '' : 'AND t.topic_approved = 1') . " + ' . topic_visibility::get_visibility_sql('topic', $forum_id, 't.') . " $limit_time_sql ORDER BY t.topic_type DESC, $sort_order_sql"; $result = $db->sql_query_limit($sql, $topics_per_page, $start); @@ -220,9 +220,10 @@ function mcp_forum_view($id, $mode, $action, $forum_info) $topic_title = censor_text($row['topic_title']); - $topic_unapproved = (!$row['topic_approved'] && $auth->acl_get('m_approve', $row['forum_id'])) ? true : false; - $posts_unapproved = ($row['topic_approved'] && $row['topic_replies'] < $row['topic_replies_real'] && $auth->acl_get('m_approve', $row['forum_id'])) ? true : false; + $topic_unapproved = ($row['topic_visibility'] == ITEM_UNAPPROVED && $auth->acl_get('m_approve', $row['forum_id'])) ? true : false; + $posts_unapproved = ($row['topic_visibility'] == ITEM_APPROVED && $row['topic_replies'] < $row['topic_replies_real'] && $auth->acl_get('m_approve', $row['forum_id'])) ? true : false; $u_mcp_queue = ($topic_unapproved || $posts_unapproved) ? $url . '&i=queue&mode=' . (($topic_unapproved) ? 'approve_details' : 'unapproved_posts') . '&t=' . $row['topic_id'] : ''; + $topic_deleted = ($row['topic_visibility'] == ITEM_DELETED) ? true : false; $topic_row = array( 'ATTACH_ICON_IMG' => ($auth->acl_get('u_download') && $auth->acl_get('f_download', $row['forum_id']) && $row['topic_attachment']) ? $user->img('icon_topic_attach', $user->lang['TOTAL_ATTACHMENTS']) : '', @@ -232,6 +233,7 @@ function mcp_forum_view($id, $mode, $action, $forum_info) 'TOPIC_ICON_IMG_WIDTH' => (!empty($icons[$row['icon_id']])) ? $icons[$row['icon_id']]['width'] : '', 'TOPIC_ICON_IMG_HEIGHT' => (!empty($icons[$row['icon_id']])) ? $icons[$row['icon_id']]['height'] : '', 'UNAPPROVED_IMG' => ($topic_unapproved || $posts_unapproved) ? $user->img('icon_topic_unapproved', ($topic_unapproved) ? 'TOPIC_UNAPPROVED' : 'POSTS_UNAPPROVED') : '', + 'DELETED_IMG' => ($topic_deleted) ? $user->img(/*TODO*/) : '', 'TOPIC_AUTHOR' => get_username_string('username', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']), 'TOPIC_AUTHOR_COLOUR' => get_username_string('colour', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']), @@ -254,7 +256,9 @@ function mcp_forum_view($id, $mode, $action, $forum_info) 'S_TOPIC_REPORTED' => (!empty($row['topic_reported']) && empty($row['topic_moved_id']) && $auth->acl_get('m_report', $row['forum_id'])) ? true : false, 'S_TOPIC_UNAPPROVED' => $topic_unapproved, 'S_POSTS_UNAPPROVED' => $posts_unapproved, + 'S_TOPIC_DELETED' => $topic_deleted, 'S_UNREAD_TOPIC' => $unread_topic, + ); if ($row['topic_status'] == ITEM_MOVED) diff --git a/phpBB/includes/mcp/mcp_front.php b/phpBB/includes/mcp/mcp_front.php index 13398e62bc..1b9521674d 100644 --- a/phpBB/includes/mcp/mcp_front.php +++ b/phpBB/includes/mcp/mcp_front.php @@ -39,7 +39,7 @@ function mcp_front_view($id, $mode, $action) $sql = 'SELECT COUNT(post_id) AS total FROM ' . POSTS_TABLE . ' WHERE ' . $db->sql_in_set('forum_id', $forum_list) . ' - AND post_approved = 0'; + AND post_visibility = ' . ITEM_UNAPPROVED; $result = $db->sql_query($sql); $total = (int) $db->sql_fetchfield('total'); $db->sql_freeresult($result); @@ -60,7 +60,7 @@ function mcp_front_view($id, $mode, $action) $sql = 'SELECT post_id FROM ' . POSTS_TABLE . ' WHERE ' . $db->sql_in_set('forum_id', $forum_list) . ' - AND post_approved = 0 + AND post_visibility = ' . ITEM_UNAPPROVED . ' ORDER BY post_time DESC'; $result = $db->sql_query_limit($sql, 5); diff --git a/phpBB/includes/mcp/mcp_main.php b/phpBB/includes/mcp/mcp_main.php index 95ca7c2e1b..db9872e04e 100644 --- a/phpBB/includes/mcp/mcp_main.php +++ b/phpBB/includes/mcp/mcp_main.php @@ -475,7 +475,7 @@ function mcp_move_topic($topic_ids) foreach ($topic_data as $topic_id => $topic_info) { - if ($topic_info['topic_approved']) + if ($topic_info['topic_visibility'] == ITEM_APPROVED) { $topics_authed_moved++; $topic_posts_added++; @@ -486,7 +486,7 @@ function mcp_move_topic($topic_ids) $topics_removed++; $topic_posts_removed += $topic_info['topic_replies']; - if ($topic_info['topic_approved']) + if ($topic_info['topic_visibility'] == ITEM_APPROVED) { $topics_authed_removed++; $topic_posts_removed++; @@ -528,13 +528,13 @@ function mcp_move_topic($topic_ids) add_log('mod', $to_forum_id, $topic_id, 'LOG_MOVE', $row['forum_name'], $forum_data['forum_name']); // Leave a redirection if required and only if the topic is visible to users - if ($leave_shadow && $row['topic_approved'] && $row['topic_type'] != POST_GLOBAL) + if ($leave_shadow && $row['topic_visibility'] == ITEM_APPROVED && $row['topic_type'] != POST_GLOBAL) { $shadow = array( 'forum_id' => (int) $row['forum_id'], 'icon_id' => (int) $row['icon_id'], 'topic_attachment' => (int) $row['topic_attachment'], - 'topic_approved' => 1, // a shadow topic is always approved + 'topic_visibliity' => ITEM_APPROVED, // a shadow topic is always approved 'topic_reported' => 0, // a shadow topic is never reported 'topic_title' => (string) $row['topic_title'], 'topic_poster' => (int) $row['topic_poster'], @@ -932,7 +932,7 @@ function mcp_fork_topic($topic_ids) 'forum_id' => (int) $to_forum_id, 'icon_id' => (int) $topic_row['icon_id'], 'topic_attachment' => (int) $topic_row['topic_attachment'], - 'topic_approved' => 1, + 'topic_visibility' => ITEM_APPROVED, 'topic_reported' => 0, 'topic_title' => (string) $topic_row['topic_title'], 'topic_poster' => (int) $topic_row['topic_poster'], @@ -1009,7 +1009,7 @@ function mcp_fork_topic($topic_ids) 'icon_id' => (int) $row['icon_id'], 'poster_ip' => (string) $row['poster_ip'], 'post_time' => (int) $row['post_time'], - 'post_approved' => 1, + 'post_visibility' => ITEM_APPROVED, 'post_reported' => 0, 'enable_bbcode' => (int) $row['enable_bbcode'], 'enable_smilies' => (int) $row['enable_smilies'], diff --git a/phpBB/includes/mcp/mcp_post.php b/phpBB/includes/mcp/mcp_post.php index 520c964228..90ce18de4e 100644 --- a/phpBB/includes/mcp/mcp_post.php +++ b/phpBB/includes/mcp/mcp_post.php @@ -185,7 +185,7 @@ function mcp_post_details($id, $mode, $action) 'S_CAN_DELETE_POST' => $auth->acl_get('m_delete', $post_info['forum_id']), 'S_POST_REPORTED' => ($post_info['post_reported']) ? true : false, - 'S_POST_UNAPPROVED' => (!$post_info['post_approved']) ? true : false, + 'S_POST_UNAPPROVED' => ($post_info['post_visibility'] == ITEM_UNAPPROVED) ? true : false, 'S_POST_LOCKED' => ($post_info['post_edit_locked']) ? true : false, 'S_USER_NOTES' => true, 'S_CLEAR_ALLOWED' => ($auth->acl_get('a_clearlogs')) ? true : false, @@ -415,7 +415,7 @@ function change_poster(&$post_info, $userdata) } // Adjust post counts... only if the post is approved (else, it was not added the users post count anyway) - if ($post_info['post_postcount'] && $post_info['post_approved']) + if ($post_info['post_postcount'] && $post_info['post_visibility'] == ITEM_APPROVED) { $sql = 'UPDATE ' . USERS_TABLE . ' SET user_posts = user_posts - 1 diff --git a/phpBB/includes/mcp/mcp_queue.php b/phpBB/includes/mcp/mcp_queue.php index b44685b8a3..833f924efc 100644 --- a/phpBB/includes/mcp/mcp_queue.php +++ b/phpBB/includes/mcp/mcp_queue.php @@ -183,7 +183,7 @@ class mcp_queue 'U_APPROVE_ACTION' => append_sid("{$phpbb_root_path}mcp.$phpEx", "i=queue&p=$post_id&f=$forum_id"), 'S_CAN_VIEWIP' => $auth->acl_get('m_info', $post_info['forum_id']), 'S_POST_REPORTED' => $post_info['post_reported'], - 'S_POST_UNAPPROVED' => !$post_info['post_approved'], + 'S_POST_UNAPPROVED' => ($post_info['post_visibility'] == ITEM_UNAPPROVED) , 'S_POST_LOCKED' => $post_info['post_edit_locked'], 'S_USER_NOTES' => true, @@ -309,7 +309,7 @@ class mcp_queue $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) . ' - AND p.post_approved = 0 + AND p.post_visibility = ' . ITEM_UNAPPROVED . ' ' . (($sort_order_sql[0] == 'u') ? 'AND u.user_id = p.poster_id' : '') . ' ' . (($topic_id) ? 'AND p.topic_id = ' . $topic_id : '') . " AND t.topic_id = p.topic_id @@ -361,7 +361,7 @@ class mcp_queue $sql = 'SELECT t.forum_id, t.topic_id, t.topic_title, t.topic_title AS post_subject, t.topic_time AS post_time, t.topic_poster AS poster_id, t.topic_first_post_id AS post_id, t.topic_attachment AS post_attachment, t.topic_first_poster_name AS username, t.topic_first_poster_colour AS user_colour FROM ' . TOPICS_TABLE . " t WHERE " . $db->sql_in_set('forum_id', $forum_list) . " - AND topic_approved = 0 + AND topic_visibility = " . ITEM_UNAPPROVED . " $limit_time_sql ORDER BY $sort_order_sql"; $result = $db->sql_query_limit($sql, $config['topics_per_page'], $start); @@ -484,7 +484,7 @@ function approve_post($post_id_list, $id, $mode) foreach ($post_info as $post_id => $post_data) { - if ($post_data['post_approved']) + if ($post_data['post_visibility'] == ITEM_APPROVED) { $post_approved_list[] = $post_id; continue; @@ -544,7 +544,7 @@ function approve_post($post_id_list, $id, $mode) if (sizeof($topic_approve_sql)) { $sql = 'UPDATE ' . TOPICS_TABLE . ' - SET topic_approved = 1 + SET topic_visibility = ' . ITEM_APPROVED . ' WHERE ' . $db->sql_in_set('topic_id', $topic_approve_sql); $db->sql_query($sql); } @@ -552,7 +552,7 @@ function approve_post($post_id_list, $id, $mode) if (sizeof($post_approve_sql)) { $sql = 'UPDATE ' . POSTS_TABLE . ' - SET post_approved = 1 + SET post_visibility = ' . ITEM_APPROVED . ' WHERE ' . $db->sql_in_set('post_id', $post_approve_sql); $db->sql_query($sql); } diff --git a/phpBB/includes/mcp/mcp_reports.php b/phpBB/includes/mcp/mcp_reports.php index 2890cd56e2..dc917a25e0 100644 --- a/phpBB/includes/mcp/mcp_reports.php +++ b/phpBB/includes/mcp/mcp_reports.php @@ -190,7 +190,7 @@ class mcp_reports 'S_CLOSE_ACTION' => append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=reports&mode=report_details&f=' . $post_info['forum_id'] . '&p=' . $post_id), 'S_CAN_VIEWIP' => $auth->acl_get('m_info', $post_info['forum_id']), 'S_POST_REPORTED' => $post_info['post_reported'], - 'S_POST_UNAPPROVED' => !$post_info['post_approved'], + 'S_POST_UNAPPROVED' => ($post_info['post_visibility'] == POST_UNAPPROVED), 'S_POST_LOCKED' => $post_info['post_edit_locked'], 'S_USER_NOTES' => true, diff --git a/phpBB/includes/mcp/mcp_topic.php b/phpBB/includes/mcp/mcp_topic.php index e39e553ab6..f6fd12f0c4 100644 --- a/phpBB/includes/mcp/mcp_topic.php +++ b/phpBB/includes/mcp/mcp_topic.php @@ -145,8 +145,8 @@ function mcp_topic_view($id, $mode, $action) $sql = 'SELECT u.username, u.username_clean, u.user_colour, p.* FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . ' u WHERE ' . (($action == 'reports') ? 'p.post_reported = 1 AND ' : '') . ' - p.topic_id = ' . $topic_id . ' ' . - ((!$auth->acl_get('m_approve', $topic_info['forum_id'])) ? ' AND p.post_approved = 1 ' : '') . ' + p.topic_id = ' . $topic_id . ' + AND ' . topic_visibility::get_visibility_sql('post', $topic_info['forum_id'], 'p.') . ' AND p.poster_id = u.user_id ' . $limit_time_sql . ' ORDER BY ' . $sort_order_sql; @@ -227,7 +227,7 @@ function mcp_topic_view($id, $mode, $action) parse_attachments($topic_info['forum_id'], $message, $attachments[$row['post_id']], $update_count); } - if (!$row['post_approved']) + if ($row['post_visibility'] == ITEM_UNAPPROVED) { $has_unapproved_posts = true; } @@ -249,7 +249,7 @@ 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'), 'S_POST_REPORTED' => ($row['post_reported'] && $auth->acl_get('m_report', $topic_info['forum_id'])), - 'S_POST_UNAPPROVED' => (!$row['post_approved'] && $auth->acl_get('m_approve', $topic_info['forum_id'])), + 'S_POST_UNAPPROVED' => ($row['post_visibility'] != ITEM_APPROVED && $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_HAS_ATTACHMENTS' => (!empty($attachments[$row['post_id']])) ? true : false, @@ -448,7 +448,7 @@ function split_topic($action, $topic_id, $to_forum_id, $subject) if ($sort_order_sql[0] == 'u') { - $sql = 'SELECT p.post_id, p.forum_id, p.post_approved + $sql = 'SELECT p.post_id, p.forum_id, p.post_visibility FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . " u WHERE p.topic_id = $topic_id AND p.poster_id = u.user_id @@ -457,7 +457,7 @@ function split_topic($action, $topic_id, $to_forum_id, $subject) } else { - $sql = 'SELECT p.post_id, p.forum_id, p.post_approved + $sql = 'SELECT p.post_id, p.forum_id, p.post_visibility FROM ' . POSTS_TABLE . " p WHERE p.topic_id = $topic_id $limit_time_sql @@ -470,7 +470,7 @@ function split_topic($action, $topic_id, $to_forum_id, $subject) while ($row = $db->sql_fetchrow($result)) { // If split from selected post (split_beyond), we split the unapproved items too. - if (!$row['post_approved'] && !$auth->acl_get('m_approve', $row['forum_id'])) + if ($row['post_visibility'] == ITEM_UNAPPROVED && !$auth->acl_get('m_approve', $row['forum_id'])) { // continue; } @@ -497,10 +497,10 @@ function split_topic($action, $topic_id, $to_forum_id, $subject) $icon_id = request_var('icon', 0); $sql_ary = array( - 'forum_id' => $to_forum_id, - 'topic_title' => $subject, - 'icon_id' => $icon_id, - 'topic_approved'=> 1 + 'forum_id' => $to_forum_id, + 'topic_title' => $subject, + 'icon_id' => $icon_id, + 'topic_visibility' => 1 ); $sql = 'INSERT INTO ' . TOPICS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary); diff --git a/phpBB/includes/search/fulltext_mysql.php b/phpBB/includes/search/fulltext_mysql.php index cf89ab1c24..73bf5c52f2 100644 --- a/phpBB/includes/search/fulltext_mysql.php +++ b/phpBB/includes/search/fulltext_mysql.php @@ -265,7 +265,7 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base * @param string $sort_dir is either a or d representing ASC and DESC * @param string $sort_days specifies the maximum amount of days a post may be old * @param array $ex_fid_ary specifies an array of forum ids which should not be searched - * @param array $m_approve_fid_ary specifies an array of forum ids in which the searcher is allowed to view unapproved posts + * @param array $m_approve_fid_sql specifies which types of posts a user may view, based on permissions * @param int $topic_id is set to 0 or a topic id, if it is not 0 then only posts in this topic should be searched * @param array $author_ary an array of author ids if the author should be ignored during the search the array is empty * @param string $author_name specifies the author match, when ANONYMOUS is also a search-match @@ -292,7 +292,7 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base $sort_key, $topic_id, implode(',', $ex_fid_ary), - implode(',', $m_approve_fid_ary), +// @TODO implode(',', $m_approve_fid_ary), implode(',', $author_ary) ))); @@ -354,7 +354,7 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base break; } - if (!sizeof($m_approve_fid_ary)) +/* if (!sizeof($m_approve_fid_ary)) { $m_approve_fid_sql = ' AND p.post_approved = 1'; } @@ -366,6 +366,7 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base { $m_approve_fid_sql = ' AND (p.post_approved = 1 OR ' . $this->db->sql_in_set('p.forum_id', $m_approve_fid_ary, true) . ')'; } +*/ $sql_select = (!$result_count) ? 'SQL_CALC_FOUND_ROWS ' : ''; $sql_select = ($type == 'posts') ? $sql_select . 'p.post_id' : 'DISTINCT ' . $sql_select . 't.topic_id'; @@ -445,7 +446,7 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base * @param string $sort_dir is either a or d representing ASC and DESC * @param string $sort_days specifies the maximum amount of days a post may be old * @param array $ex_fid_ary specifies an array of forum ids which should not be searched - * @param array $m_approve_fid_ary specifies an array of forum ids in which the searcher is allowed to view unapproved posts + * @param array $m_approve_fid_sql specifies which types of posts a user may view, based on permissions * @param int $topic_id is set to 0 or a topic id, if it is not 0 then only posts in this topic should be searched * @param array $author_ary an array of author ids * @param string $author_name specifies the author match, when ANONYMOUS is also a search-match @@ -473,7 +474,7 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base $sort_key, $topic_id, implode(',', $ex_fid_ary), - implode(',', $m_approve_fid_ary), +// @TODO implode(',', $m_approve_fid_ary), implode(',', $author_ary), $author_name, ))); @@ -523,7 +524,7 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base break; } - if (!sizeof($m_approve_fid_ary)) +/* if (!sizeof($m_approve_fid_ary)) { $m_approve_fid_sql = ' AND p.post_approved = 1'; } @@ -535,6 +536,7 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base { $m_approve_fid_sql = ' AND (p.post_approved = 1 OR ' . $this->db->sql_in_set('p.forum_id', $m_approve_fid_ary, true) . ')'; } +*/ // If the cache was completely empty count the results $calc_results = ($result_count) ? '' : 'SQL_CALC_FOUND_ROWS '; diff --git a/phpBB/includes/search/fulltext_native.php b/phpBB/includes/search/fulltext_native.php index 96b3f02ec6..c7e7a451e4 100644 --- a/phpBB/includes/search/fulltext_native.php +++ b/phpBB/includes/search/fulltext_native.php @@ -414,7 +414,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base * @param string $sort_dir is either a or d representing ASC and DESC * @param string $sort_days specifies the maximum amount of days a post may be old * @param array $ex_fid_ary specifies an array of forum ids which should not be searched - * @param array $m_approve_fid_ary specifies an array of forum ids in which the searcher is allowed to view unapproved posts + * @param array $m_approve_fid_sql specifies which types of posts the user can view * @param int $topic_id is set to 0 or a topic id, if it is not 0 then only posts in this topic should be searched * @param array $author_ary an array of author ids if the author should be ignored during the search the array is empty * @param string $author_name specifies the author match, when ANONYMOUS is also a search-match @@ -451,7 +451,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base $sort_key, $topic_id, implode(',', $ex_fid_ary), - implode(',', $m_approve_fid_ary), +// @TODO implode(',', $m_approve_fid_ary), implode(',', $author_ary), $author_name, ))); @@ -628,7 +628,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base $sql_where[] = '(' . implode(' OR ', $is_null_joins) . ')'; } - if (!sizeof($m_approve_fid_ary)) +/* if (!sizeof($m_approve_fid_ary)) { $sql_where[] = 'p.post_approved = 1'; } @@ -636,6 +636,8 @@ class phpbb_search_fulltext_native extends phpbb_search_base { $sql_where[] = '(p.post_approved = 1 OR ' . $this->db->sql_in_set('p.forum_id', $m_approve_fid_ary, true) . ')'; } +*/ + $sql_where[] = $m_approve_fid_sql; if ($topic_id) { @@ -808,7 +810,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base * @param string $sort_dir is either a or d representing ASC and DESC * @param string $sort_days specifies the maximum amount of days a post may be old * @param array $ex_fid_ary specifies an array of forum ids which should not be searched - * @param array $m_approve_fid_ary specifies an array of forum ids in which the searcher is allowed to view unapproved posts + * @param array $m_approve_fid_sql specifies which posts a user can view, based on permissions * @param int $topic_id is set to 0 or a topic id, if it is not 0 then only posts in this topic should be searched * @param array $author_ary an array of author ids * @param string $author_name specifies the author match, when ANONYMOUS is also a search-match @@ -836,7 +838,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base $sort_key, $topic_id, implode(',', $ex_fid_ary), - implode(',', $m_approve_fid_ary), +// @TODO implode(',', $m_approve_fid_ary), implode(',', $author_ary), $author_name, ))); @@ -886,7 +888,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base break; } - if (!sizeof($m_approve_fid_ary)) +/* if (!sizeof($m_approve_fid_ary)) { $m_approve_fid_sql = ' AND p.post_approved = 1'; } @@ -898,6 +900,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base { $m_approve_fid_sql = ' AND (p.post_approved = 1 OR ' . $this->db->sql_in_set('p.forum_id', $m_approve_fid_ary, true) . ')'; } +*/ $select = ($type == 'posts') ? 'p.post_id' : 't.topic_id'; $is_mysql = false; -- cgit v1.2.1 From 244f6e2ddc7818125edc273be1d83a5298ce6589 Mon Sep 17 00:00:00 2001 From: Josh Woody Date: Fri, 18 Jun 2010 08:29:53 -0500 Subject: [feature/soft-delete] Correct some mistakes in e8d47 Notably: Uncomment the die() in create_schema_files, and add the class that makes everything tick. PHPBB3-9657 --- phpBB/includes/class_visibility.php | 137 ++++++++++++++++++++++++++++++++++++ 1 file changed, 137 insertions(+) create mode 100644 phpBB/includes/class_visibility.php (limited to 'phpBB/includes') diff --git a/phpBB/includes/class_visibility.php b/phpBB/includes/class_visibility.php new file mode 100644 index 0000000000..28fc584b76 --- /dev/null +++ b/phpBB/includes/class_visibility.php @@ -0,0 +1,137 @@ +acl_get('m_approve', $forum_id)) + { + $status_ary[] = ITEM_UNAPPROVED; + } + + if ($auth->acl_get('m_restore', $forum_id)) + { + $status_ary[] = ITEM_DELETED; + } + + $clause = $db->sql_in_set($table_alias . $mode . '_visibility', $status_ary); + + // only allow the user to view deleted posts he himself made + if ($auth->acl_get('f_restore', $forum_id)) + { + $clause = 'AND (' . $clause . " + OR ($table_alias{$mode}_visibility = " . ITEM_DELETED . " + AND {$table_alias}poster_id = " . $user->data['user_id'] . '))'; + + } + + return $clause; + } + + public function get_visibility_sql_global($mode, $exclude_forum_ids = array(), $table_alias = '') + { + global $auth, $db, $user; + + // users can always see approved posts + $where_sql = "($table_alias{$mode}_visibility = " . ITEM_APPROVED; + + // in set notation: {approve_forums} = {m_approve} - {exclude_forums} + $approve_forums = array_diff(array_keys($auth->acl_getf('m_approve', true)), $exclude_forum_ids); + if (sizeof($approve_forums)) + { + // users can view unapproved topics in certain forums. specify them. + $where_sql .= " OR ($table_alias{$mode}_visibility = " . ITEM_UNAPPROVED . ' + AND ' . $db->sql_in_set($table_alias . 'forum_id', $approve_forums) . ')'; + } + + // this is exactly the same logic as for approve forums, above + $restore_forums = array_diff(array_keys($auth->acl_getf('m_restore', true)), $exclude_forum_ids); + if (sizeof($restore_forums)) + { + $where_sql .= " OR ($table_alias{$mode}_visibility = " . ITEM_DELETED . ' + AND ' . $db->sql_in_set($table_alias . 'forum_id', $restore_forums) . ')'; + } + + // we also allow the user to view deleted posts he himself made + $user_restore_forums = array_diff(array_keys($auth->acl_getf('f_restore', true)), $exclude_forum_ids); + if (sizeof($user_restore_forums)) + { + // specify the poster ID, the visibility type, and the forums we're interested in + $where_sql .= " OR ($table_alias{$mode}poster_id = " . $user->data['user_id'] . " + AND $table_alias{$mode}_visibility = " . ITEM_DELETED . " + AND " . $db->sql_in_set($table_alias . 'forum_id', $user_restore_forums) . ')'; + } + + $where_sql .= ')'; + + return $where_sql; + } + + public function set_topic_visibility($visibility, $topic_id, $forum_id) + { + global $db; + + $sql = 'UPDATE ' . TOPICS_TABLE . ' SET topic_visibility = ' . (int) $visibility . ' + WHERE topic_id = ' . (int) $topic_id; + $db->sql_query($sql); + + if ($visibility != ITEM_APPROVED) + { + $sql = 'SELECT post_id FROM ' . POSTS_TABLE . ' + WHERE topic_id = ' . (int) $topic_id; + $result = $db->sql_query($sql); + + $status = true; + while ($row = $db->sql_fetchrow($result)) + { + $status = min($status, self::set_post_visibility($visibility, false, $topic_id, $forum_id, true, true)); + } + } + else + { + // TOOD: figure out which posts we actually care about + $status = self::set_post_visibility($visibility, 0, false, $forum_id, true, true); + } + + return $status; + } + + public function set_post_visibility($visibility, $post_id, $topic_id, $forum_id, $is_starter, $is_latest) + { + global $db; + + if ($post_id) + { + $where_sql = 'post_id = ' . (int) $post_id; + } + else if ($topic_id) + { + $where_sql = 'topic_id = ' . (int) $topic_id; + } + else + { + // throw new MissingArgumentsException(); <-- a nice idea + return false; + } + + $sql = 'UPDATE ' . POSTS_TABLE . ' SET post_visibility = ' . (int) $visibility . ' + WHERE ' . $where_sql; + $db->sql_query($sql); + + if ($is_starter || $is_latest) + { + update_post_information('topic', $topic_id, false); + update_post_information('forum', $forum_id, false); + } + + // if we're changing the starter, we need to change the rest of the topic + if ($is_starter && !$is_latest) + { + self::set_topic_visibility($visibility, $topic_id, $forum_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/includes/class_visibility.php | 87 ++++++++++++++++++++++++++---------- phpBB/includes/functions_posting.php | 6 +-- phpBB/includes/mcp/mcp_forum.php | 2 +- phpBB/includes/mcp/mcp_topic.php | 2 +- 4 files changed, 68 insertions(+), 29 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/class_visibility.php b/phpBB/includes/class_visibility.php index 28fc584b76..46f188d833 100644 --- a/phpBB/includes/class_visibility.php +++ b/phpBB/includes/class_visibility.php @@ -1,7 +1,35 @@ sql_query($sql); - if ($visibility != ITEM_APPROVED) - { - $sql = 'SELECT post_id FROM ' . POSTS_TABLE . ' - WHERE topic_id = ' . (int) $topic_id; - $result = $db->sql_query($sql); - - $status = true; - while ($row = $db->sql_fetchrow($result)) - { - $status = min($status, self::set_post_visibility($visibility, false, $topic_id, $forum_id, true, true)); - } - } - else - { - // TOOD: figure out which posts we actually care about - $status = self::set_post_visibility($visibility, 0, false, $forum_id, true, true); - } + // if we're approving, disapproving, or deleteing a topic, assume that + // we are adjusting _all_ posts in that topic. + $status = self::set_post_visibility($visibility, false, $topic_id, $forum_id, true, true); + return $status; } + /** + * @param $visibility - int - element of {ITEM_UNAPPROVED, ITEM_APPROVED, ITEM_DELETED} + * @param $post_id - int - the post ID to act on + * @param $topic_id - int - forum where $post_id is found + * @param $forum_id - int - forum ID where $topic_id resides + * @param $is_starter - bool - is this the first post of the topic + * @param $is_latest - bool - is this the last post of the topic + */ public function set_post_visibility($visibility, $post_id, $topic_id, $forum_id, $is_starter, $is_latest) { global $db; + // if we're changing the starter, we need to change the rest of the topic + if ($is_starter && !$is_latest) + { + return self::set_topic_visibility($visibility, $topic_id, $forum_id); + } + if ($post_id) { $where_sql = 'post_id = ' . (int) $post_id; @@ -121,17 +165,12 @@ class topic_visibility WHERE ' . $where_sql; $db->sql_query($sql); + // Sync the first/last topic information if needed if ($is_starter || $is_latest) { update_post_information('topic', $topic_id, false); update_post_information('forum', $forum_id, false); } - - // if we're changing the starter, we need to change the rest of the topic - if ($is_starter && !$is_latest) - { - self::set_topic_visibility($visibility, $topic_id, $forum_id); - } } } ?> diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index 2f51200b48..12448ea0ce 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -993,7 +993,7 @@ function topic_review($topic_id, $forum_id, $mode = 'topic_review', $cur_post_id $sql = 'SELECT p.post_id FROM ' . POSTS_TABLE . ' p' . " WHERE p.topic_id = $topic_id - AND " . topic_visibility::get_visibility_sql('post', $forum_id, 'p.') . ' + AND " . phpbb_visibility::get_visibility_sql('post', $forum_id, 'p.') . ' ' . (($mode == 'post_review') ? " AND p.post_id > $cur_post_id" : '') . ' ' . (($mode == 'post_review_edit') ? " AND p.post_id = $cur_post_id" : '') . ' ORDER BY p.post_time '; @@ -1542,7 +1542,7 @@ function delete_post($forum_id, $topic_id, $post_id, &$data) $sql = 'SELECT MAX(post_id) as last_post_id FROM ' . POSTS_TABLE . " WHERE topic_id = $topic_id - AND " . topic_visibility::get_visibility_sql('post', $forum_id); + AND " . phpbb_visibility::get_visibility_sql('post', $forum_id); $result = $db->sql_query($sql); $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); @@ -1555,7 +1555,7 @@ function delete_post($forum_id, $topic_id, $post_id, &$data) $sql = 'SELECT post_id FROM ' . POSTS_TABLE . " WHERE topic_id = $topic_id - AND " . topic_visibility::get_visibility_sql('post', $forum_id) . ' + AND " . phpbb_visibility::get_visibility_sql('post', $forum_id) . ' AND post_time > ' . $data['post_time'] . ' ORDER BY post_time ASC'; $result = $db->sql_query_limit($sql, 1); diff --git a/phpBB/includes/mcp/mcp_forum.php b/phpBB/includes/mcp/mcp_forum.php index 48b9c7c2d3..90c0224b40 100644 --- a/phpBB/includes/mcp/mcp_forum.php +++ b/phpBB/includes/mcp/mcp_forum.php @@ -154,7 +154,7 @@ function mcp_forum_view($id, $mode, $action, $forum_info) $sql = 'SELECT t.topic_id FROM ' . TOPICS_TABLE . ' t WHERE t.forum_id = ' . $forum_id . ' - ' . topic_visibility::get_visibility_sql('topic', $forum_id, 't.') . " + ' . phpbb_visibility::get_visibility_sql('topic', $forum_id, 't.') . " $limit_time_sql ORDER BY t.topic_type DESC, $sort_order_sql"; $result = $db->sql_query_limit($sql, $topics_per_page, $start); diff --git a/phpBB/includes/mcp/mcp_topic.php b/phpBB/includes/mcp/mcp_topic.php index f6fd12f0c4..5c25da7a9d 100644 --- a/phpBB/includes/mcp/mcp_topic.php +++ b/phpBB/includes/mcp/mcp_topic.php @@ -146,7 +146,7 @@ function mcp_topic_view($id, $mode, $action) FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . ' u WHERE ' . (($action == 'reports') ? 'p.post_reported = 1 AND ' : '') . ' p.topic_id = ' . $topic_id . ' - AND ' . topic_visibility::get_visibility_sql('post', $topic_info['forum_id'], 'p.') . ' + AND ' . phpbb_visibility::get_visibility_sql('post', $topic_info['forum_id'], 'p.') . ' AND p.poster_id = u.user_id ' . $limit_time_sql . ' ORDER BY ' . $sort_order_sql; -- 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/includes/class_visibility.php | 265 +++++++++++++++++++++++++++++++++- phpBB/includes/functions_posting.php | 112 +++++++------- phpBB/includes/mcp/info/mcp_queue.php | 1 + phpBB/includes/mcp/mcp_queue.php | 152 ++++--------------- 4 files changed, 351 insertions(+), 179 deletions(-) (limited to 'phpBB/includes') 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(); -- cgit v1.2.1 From 67393751356e9f02f7c1ab0a2f7a3a508403edc3 Mon Sep 17 00:00:00 2001 From: Josh Woody Date: Tue, 29 Jun 2010 21:47:18 -0500 Subject: [feature/soft-delete] Add unit tests for the phpbb_visibility class Add unit tests for the phpbb_visibility class. Adjust the phpbb_visibility class to pass those unit tests. The changes are pretty small, actually. PHPBB3-9657 --- phpBB/includes/class_visibility.php | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/class_visibility.php b/phpBB/includes/class_visibility.php index 9798e938b1..869f1078c1 100644 --- a/phpBB/includes/class_visibility.php +++ b/phpBB/includes/class_visibility.php @@ -48,11 +48,12 @@ class phpbb_visibility $clause = $db->sql_in_set($table_alias . $mode . '_visibility', $status_ary); // only allow the user to view deleted posts he himself made - if ($auth->acl_get('f_restore', $forum_id)) + if ($auth->acl_get('f_restore', $forum_id) && !$auth->acl_get('m_restore', $forum_id)) { - $clause = 'AND (' . $clause . " + $poster_column = ($mode == 'topic') ? 'topic_poster' : 'poster_id'; + $clause = '(' . $clause . " OR ($table_alias{$mode}_visibility = " . ITEM_DELETED . " - AND {$table_alias}poster_id = " . $user->data['user_id'] . '))'; + AND $table_alias$poster_column = " . $user->data['user_id'] . '))'; } @@ -92,10 +93,12 @@ class phpbb_visibility // we also allow the user to view deleted posts he himself made $user_restore_forums = array_diff(array_keys($auth->acl_getf('f_restore', true)), $exclude_forum_ids); - if (sizeof($user_restore_forums)) + if (sizeof($user_restore_forums) && !sizeof($restore_forums)) { + $poster_column = ($mode == 'topic') ? 'topic_poster' : 'poster_id'; + // specify the poster ID, the visibility type, and the forums we're interested in - $where_sql .= " OR ($table_alias{$mode}poster_id = " . $user->data['user_id'] . " + $where_sql .= " OR ($table_alias$poster_column = " . $user->data['user_id'] . " AND $table_alias{$mode}_visibility = " . ITEM_DELETED . " AND " . $db->sql_in_set($table_alias . 'forum_id', $user_restore_forums) . ')'; } @@ -187,7 +190,7 @@ class phpbb_visibility { return true; } - else if ($auth->acl_get('f_softdelete', $forum_id) && $poster_id == $user->data['poster_id'] && !$post_locked) + else if ($auth->acl_get('f_softdelete', $forum_id) && $poster_id == $user->data['user_id'] && !$post_locked) { return true; } @@ -245,7 +248,7 @@ class phpbb_visibility // 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); + $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); -- 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/includes/class_content_visibility.php | 440 ++++++++++++++++++++++++++++ phpBB/includes/class_visibility.php | 440 ---------------------------- phpBB/includes/functions_posting.php | 22 +- phpBB/includes/mcp/mcp_forum.php | 2 +- phpBB/includes/mcp/mcp_queue.php | 2 +- phpBB/includes/mcp/mcp_topic.php | 2 +- 6 files changed, 454 insertions(+), 454 deletions(-) create mode 100644 phpBB/includes/class_content_visibility.php delete mode 100644 phpBB/includes/class_visibility.php (limited to 'phpBB/includes') diff --git a/phpBB/includes/class_content_visibility.php b/phpBB/includes/class_content_visibility.php new file mode 100644 index 0000000000..c7c9586e50 --- /dev/null +++ b/phpBB/includes/class_content_visibility.php @@ -0,0 +1,440 @@ +acl_get('m_approve', $forum_id)) + { + $status_ary[] = ITEM_UNAPPROVED; + } + + if ($auth->acl_get('m_restore', $forum_id)) + { + $status_ary[] = ITEM_DELETED; + } + + $clause = $db->sql_in_set($table_alias . $mode . '_visibility', $status_ary); + + // only allow the user to view deleted posts he himself made + if ($auth->acl_get('f_restore', $forum_id) && !$auth->acl_get('m_restore', $forum_id)) + { + $poster_column = ($mode == 'topic') ? 'topic_poster' : 'poster_id'; + $clause = '(' . $clause . " + OR ($table_alias{$mode}_visibility = " . ITEM_DELETED . " + AND $table_alias$poster_column = " . $user->data['user_id'] . '))'; + + } + + return $clause; + } + + /** + * Fetch visibility SQL for all forums on the board. + * @param $mode string - either "topic" or "post" + * @param $exclude_forum_ids - int array - + * @param $table_alias string - Table alias to prefix in SQL queries + * @return string with the appropriate combination SQL logic for topic/post_visibility + */ + public function get_visibility_sql_global($mode, $exclude_forum_ids = array(), $table_alias = '') + { + global $auth, $db, $user; + + // users can always see approved posts + $where_sql = "($table_alias{$mode}_visibility = " . ITEM_APPROVED; + + // in set notation: {approve_forums} = {m_approve} - {exclude_forums} + $approve_forums = array_diff(array_keys($auth->acl_getf('m_approve', true)), $exclude_forum_ids); + if (sizeof($approve_forums)) + { + // users can view unapproved topics in certain forums. specify them. + $where_sql .= " OR ($table_alias{$mode}_visibility = " . ITEM_UNAPPROVED . ' + AND ' . $db->sql_in_set($table_alias . 'forum_id', $approve_forums) . ')'; + } + + // this is exactly the same logic as for approve forums, above + $restore_forums = array_diff(array_keys($auth->acl_getf('m_restore', true)), $exclude_forum_ids); + if (sizeof($restore_forums)) + { + $where_sql .= " OR ($table_alias{$mode}_visibility = " . ITEM_DELETED . ' + AND ' . $db->sql_in_set($table_alias . 'forum_id', $restore_forums) . ')'; + } + + // we also allow the user to view deleted posts he himself made + $user_restore_forums = array_diff(array_keys($auth->acl_getf('f_restore', true)), $exclude_forum_ids); + if (sizeof($user_restore_forums) && !sizeof($restore_forums)) + { + $poster_column = ($mode == 'topic') ? 'topic_poster' : 'poster_id'; + + // specify the poster ID, the visibility type, and the forums we're interested in + $where_sql .= " OR ($table_alias$poster_column = " . $user->data['user_id'] . " + AND $table_alias{$mode}_visibility = " . ITEM_DELETED . " + AND " . $db->sql_in_set($table_alias . 'forum_id', $user_restore_forums) . ')'; + } + + $where_sql .= ')'; + + return $where_sql; + } + + /** + * Description: Allows approving (which is akin to undeleting), unapproving (!) or soft deleting an entire topic. + * Calls set_post_visibility as needed. + * @param $visibility - int - element of {ITEM_UNAPPROVED, ITEM_APPROVED, ITEM_DELETED} + * @param $topic_id - int - topic ID to act on + * @param $forum_id - int - forum ID where $topic_id resides + * @return bool true = success, false = fail + */ + public function set_topic_visibility($visibility, $topic_id, $forum_id) + { + global $db; + + $sql = 'UPDATE ' . TOPICS_TABLE . ' SET topic_visibility = ' . (int) $visibility . ' + WHERE topic_id = ' . (int) $topic_id; + $db->sql_query($sql); + + // if we're approving, disapproving, or deleteing a topic, assume that + // we are adjusting _all_ posts in that topic. + $status = self::set_post_visibility($visibility, false, $topic_id, $forum_id, true, true); + + return $status; + } + + /** + * @param $visibility - int - element of {ITEM_UNAPPROVED, ITEM_APPROVED, ITEM_DELETED} + * @param $post_id - int - the post ID to act on + * @param $topic_id - int - forum where $post_id is found + * @param $forum_id - int - forum ID where $topic_id resides + * @param $is_starter - bool - is this the first post of the topic + * @param $is_latest - bool - is this the last post of the topic + */ + public function set_post_visibility($visibility, $post_id, $topic_id, $forum_id, $is_starter, $is_latest) + { + global $db; + + // if we're changing the starter, we need to change the rest of the topic + if ($is_starter && !$is_latest) + { + return self::set_topic_visibility($visibility, $topic_id, $forum_id); + } + + if ($post_id) + { + $where_sql = 'post_id = ' . (int) $post_id; + } + else if ($topic_id) + { + $where_sql = 'topic_id = ' . (int) $topic_id; + } + else + { + // throw new MissingArgumentsException(); <-- a nice idea + return false; + } + + $sql = 'UPDATE ' . POSTS_TABLE . ' SET post_visibility = ' . (int) $visibility . ' + WHERE ' . $where_sql; + $db->sql_query($sql); + + // Sync the first/last topic information if needed + if ($is_starter || $is_latest) + { + update_post_information('topic', $topic_id, false); + 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['user_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/class_visibility.php b/phpBB/includes/class_visibility.php deleted file mode 100644 index 869f1078c1..0000000000 --- a/phpBB/includes/class_visibility.php +++ /dev/null @@ -1,440 +0,0 @@ -acl_get('m_approve', $forum_id)) - { - $status_ary[] = ITEM_UNAPPROVED; - } - - if ($auth->acl_get('m_restore', $forum_id)) - { - $status_ary[] = ITEM_DELETED; - } - - $clause = $db->sql_in_set($table_alias . $mode . '_visibility', $status_ary); - - // only allow the user to view deleted posts he himself made - if ($auth->acl_get('f_restore', $forum_id) && !$auth->acl_get('m_restore', $forum_id)) - { - $poster_column = ($mode == 'topic') ? 'topic_poster' : 'poster_id'; - $clause = '(' . $clause . " - OR ($table_alias{$mode}_visibility = " . ITEM_DELETED . " - AND $table_alias$poster_column = " . $user->data['user_id'] . '))'; - - } - - return $clause; - } - - /** - * Fetch visibility SQL for all forums on the board. - * @param $mode string - either "topic" or "post" - * @param $exclude_forum_ids - int array - - * @param $table_alias string - Table alias to prefix in SQL queries - * @return string with the appropriate combination SQL logic for topic/post_visibility - */ - public function get_visibility_sql_global($mode, $exclude_forum_ids = array(), $table_alias = '') - { - global $auth, $db, $user; - - // users can always see approved posts - $where_sql = "($table_alias{$mode}_visibility = " . ITEM_APPROVED; - - // in set notation: {approve_forums} = {m_approve} - {exclude_forums} - $approve_forums = array_diff(array_keys($auth->acl_getf('m_approve', true)), $exclude_forum_ids); - if (sizeof($approve_forums)) - { - // users can view unapproved topics in certain forums. specify them. - $where_sql .= " OR ($table_alias{$mode}_visibility = " . ITEM_UNAPPROVED . ' - AND ' . $db->sql_in_set($table_alias . 'forum_id', $approve_forums) . ')'; - } - - // this is exactly the same logic as for approve forums, above - $restore_forums = array_diff(array_keys($auth->acl_getf('m_restore', true)), $exclude_forum_ids); - if (sizeof($restore_forums)) - { - $where_sql .= " OR ($table_alias{$mode}_visibility = " . ITEM_DELETED . ' - AND ' . $db->sql_in_set($table_alias . 'forum_id', $restore_forums) . ')'; - } - - // we also allow the user to view deleted posts he himself made - $user_restore_forums = array_diff(array_keys($auth->acl_getf('f_restore', true)), $exclude_forum_ids); - if (sizeof($user_restore_forums) && !sizeof($restore_forums)) - { - $poster_column = ($mode == 'topic') ? 'topic_poster' : 'poster_id'; - - // specify the poster ID, the visibility type, and the forums we're interested in - $where_sql .= " OR ($table_alias$poster_column = " . $user->data['user_id'] . " - AND $table_alias{$mode}_visibility = " . ITEM_DELETED . " - AND " . $db->sql_in_set($table_alias . 'forum_id', $user_restore_forums) . ')'; - } - - $where_sql .= ')'; - - return $where_sql; - } - - /** - * Description: Allows approving (which is akin to undeleting), unapproving (!) or soft deleting an entire topic. - * Calls set_post_visibility as needed. - * @param $visibility - int - element of {ITEM_UNAPPROVED, ITEM_APPROVED, ITEM_DELETED} - * @param $topic_id - int - topic ID to act on - * @param $forum_id - int - forum ID where $topic_id resides - * @return bool true = success, false = fail - */ - public function set_topic_visibility($visibility, $topic_id, $forum_id) - { - global $db; - - $sql = 'UPDATE ' . TOPICS_TABLE . ' SET topic_visibility = ' . (int) $visibility . ' - WHERE topic_id = ' . (int) $topic_id; - $db->sql_query($sql); - - // if we're approving, disapproving, or deleteing a topic, assume that - // we are adjusting _all_ posts in that topic. - $status = self::set_post_visibility($visibility, false, $topic_id, $forum_id, true, true); - - return $status; - } - - /** - * @param $visibility - int - element of {ITEM_UNAPPROVED, ITEM_APPROVED, ITEM_DELETED} - * @param $post_id - int - the post ID to act on - * @param $topic_id - int - forum where $post_id is found - * @param $forum_id - int - forum ID where $topic_id resides - * @param $is_starter - bool - is this the first post of the topic - * @param $is_latest - bool - is this the last post of the topic - */ - public function set_post_visibility($visibility, $post_id, $topic_id, $forum_id, $is_starter, $is_latest) - { - global $db; - - // if we're changing the starter, we need to change the rest of the topic - if ($is_starter && !$is_latest) - { - return self::set_topic_visibility($visibility, $topic_id, $forum_id); - } - - if ($post_id) - { - $where_sql = 'post_id = ' . (int) $post_id; - } - else if ($topic_id) - { - $where_sql = 'topic_id = ' . (int) $topic_id; - } - else - { - // throw new MissingArgumentsException(); <-- a nice idea - return false; - } - - $sql = 'UPDATE ' . POSTS_TABLE . ' SET post_visibility = ' . (int) $visibility . ' - WHERE ' . $where_sql; - $db->sql_query($sql); - - // Sync the first/last topic information if needed - if ($is_starter || $is_latest) - { - update_post_information('topic', $topic_id, false); - 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['user_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 b264e35a93..364a3e7fe2 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -993,7 +993,7 @@ function topic_review($topic_id, $forum_id, $mode = 'topic_review', $cur_post_id $sql = 'SELECT p.post_id FROM ' . POSTS_TABLE . ' p' . " WHERE p.topic_id = $topic_id - AND " . phpbb_visibility::get_visibility_sql('post', $forum_id, 'p.') . ' + AND " . phpbb_content_visibility::get_visibility_sql('post', $forum_id, 'p.') . ' ' . (($mode == 'post_review') ? " AND p.post_id > $cur_post_id" : '') . ' ' . (($mode == 'post_review_edit') ? " AND p.post_id = $cur_post_id" : '') . ' ORDER BY p.post_time '; @@ -1466,8 +1466,8 @@ function delete_post($forum_id, $topic_id, $post_id, &$data, $is_soft = 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); + phpbb_content_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_content_visibility::hide_post($forum_id, time(), $sql_data); } else { @@ -1501,8 +1501,8 @@ function delete_post($forum_id, $topic_id, $post_id, &$data, $is_soft = 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); + phpbb_content_visibility::set_topic_visibility(POST_DELETED, $topic_id, $forum_id); + phpbb_content_visibility::hide_topic($topic_id, $forum_id, $topic_row, $sql_data); } else { @@ -1548,8 +1548,8 @@ function delete_post($forum_id, $topic_id, $post_id, &$data, $is_soft = false) case 'delete_last_post': if ($is_soft) { - phpbb_visibility::hide_post($forum_id, time(), $sql_data); - phpbb_visibility::set_post_visibility($post_id, $topic_id, $forum_id, false, true); + phpbb_content_visibility::hide_post($forum_id, time(), $sql_data); + phpbb_content_visibility::set_post_visibility($post_id, $topic_id, $forum_id, false, true); } else { @@ -1576,7 +1576,7 @@ function delete_post($forum_id, $topic_id, $post_id, &$data, $is_soft = false) $sql = 'SELECT MAX(post_id) as last_post_id FROM ' . POSTS_TABLE . " WHERE topic_id = $topic_id - AND " . phpbb_visibility::get_visibility_sql('post', $forum_id); + AND " . phpbb_content_visibility::get_visibility_sql('post', $forum_id); $result = $db->sql_query($sql); $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); @@ -1589,7 +1589,7 @@ function delete_post($forum_id, $topic_id, $post_id, &$data, $is_soft = false) $sql = 'SELECT post_id FROM ' . POSTS_TABLE . " WHERE topic_id = $topic_id - AND " . phpbb_visibility::get_visibility_sql('post', $forum_id) . ' + AND " . phpbb_content_visibility::get_visibility_sql('post', $forum_id) . ' AND post_time > ' . $data['post_time'] . ' ORDER BY post_time ASC'; $result = $db->sql_query_limit($sql, 1); @@ -1949,7 +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) { - phpbb_visibility::hide_topic($data['topic_id'], $data['forum_id'], $topic_row, $sql_data); + phpbb_content_visibility::hide_topic($data['topic_id'], $data['forum_id'], $topic_row, $sql_data); } break; @@ -1960,7 +1960,7 @@ 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); + //phpbb_content_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'; diff --git a/phpBB/includes/mcp/mcp_forum.php b/phpBB/includes/mcp/mcp_forum.php index 90c0224b40..ff079baeb8 100644 --- a/phpBB/includes/mcp/mcp_forum.php +++ b/phpBB/includes/mcp/mcp_forum.php @@ -154,7 +154,7 @@ function mcp_forum_view($id, $mode, $action, $forum_info) $sql = 'SELECT t.topic_id FROM ' . TOPICS_TABLE . ' t WHERE t.forum_id = ' . $forum_id . ' - ' . phpbb_visibility::get_visibility_sql('topic', $forum_id, 't.') . " + ' . phpbb_content_visibility::get_visibility_sql('topic', $forum_id, 't.') . " $limit_time_sql ORDER BY t.topic_type DESC, $sort_order_sql"; $result = $db->sql_query_limit($sql, $topics_per_page, $start); diff --git a/phpBB/includes/mcp/mcp_queue.php b/phpBB/includes/mcp/mcp_queue.php index c19fb9b2b6..221dfffebc 100644 --- a/phpBB/includes/mcp/mcp_queue.php +++ b/phpBB/includes/mcp/mcp_queue.php @@ -493,7 +493,7 @@ function approve_post($post_id_list, $id, $mode) { $notify_poster = (isset($_REQUEST['notify_poster'])) ? true : false; - phpbb_visibility::unhide_posts_topics('approve', $post_info, $post_id_list); + phpbb_content_visibility::unhide_posts_topics('approve', $post_info, $post_id_list); $messenger = new messenger(); diff --git a/phpBB/includes/mcp/mcp_topic.php b/phpBB/includes/mcp/mcp_topic.php index 5c25da7a9d..8320699a8c 100644 --- a/phpBB/includes/mcp/mcp_topic.php +++ b/phpBB/includes/mcp/mcp_topic.php @@ -146,7 +146,7 @@ function mcp_topic_view($id, $mode, $action) FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . ' u WHERE ' . (($action == 'reports') ? 'p.post_reported = 1 AND ' : '') . ' p.topic_id = ' . $topic_id . ' - AND ' . phpbb_visibility::get_visibility_sql('post', $topic_info['forum_id'], 'p.') . ' + AND ' . phpbb_content_visibility::get_visibility_sql('post', $topic_info['forum_id'], 'p.') . ' AND p.poster_id = u.user_id ' . $limit_time_sql . ' ORDER BY ' . $sort_order_sql; -- cgit v1.2.1 From f570558a8da65596b0ca2700e2e7829548d2393a Mon Sep 17 00:00:00 2001 From: Josh Woody Date: Mon, 5 Jul 2010 21:58:20 -0500 Subject: [feature/soft-delete] Add a processor for action == restore in mcp_queue.php Restoring a post within mcp_queue.php didn't do anything before this commit. Now it does, by way of a function which is very similar to approve_post. PHPBB3-9657 --- phpBB/includes/mcp/mcp_queue.php | 45 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/mcp/mcp_queue.php b/phpBB/includes/mcp/mcp_queue.php index 221dfffebc..597be855b7 100644 --- a/phpBB/includes/mcp/mcp_queue.php +++ b/phpBB/includes/mcp/mcp_queue.php @@ -62,7 +62,7 @@ class mcp_queue } else if ($action == 'restore') { -// do something + restore_post($post_id_list, 'queue', $mode); } else { @@ -462,6 +462,47 @@ class mcp_queue } } + +/** +* Approve Post/Topic +*/ +function restore_post($post_id_list, $id, $mode) +{ + global $db, $template, $user, $config; + global $phpEx, $phpbb_root_path; + + if (!check_ids($post_id_list, POSTS_TABLE, 'post_id', array('m_restore'))) + { + trigger_error('NOT_AUTHORISED'); + } + + $redirect = request_var('redirect', build_url(array('quickmod'))); + $redirect = reapply_sid($redirect); + $success_msg = ''; + + $post_info = get_post_data($post_id_list, 'm_restore'); + + phpbb_content_visibility::unhide_posts_topics('restore', $post_info, $post_id_list); + + if (!$success_msg) + { + redirect($redirect); + } + else + { + meta_refresh(3, $redirect); + + // If approving one post, also give links back to post... + $add_message = ''; + if (sizeof($post_id_list) == 1 && !empty($post_url)) + { + $add_message = '

' . sprintf($user->lang['RETURN_POST'], '', ''); + } + + trigger_error($user->lang[$success_msg] . '

' . sprintf($user->lang['RETURN_PAGE'], "", '') . $add_message); + } +} + /** * Approve Post/Topic */ @@ -493,7 +534,7 @@ function approve_post($post_id_list, $id, $mode) { $notify_poster = (isset($_REQUEST['notify_poster'])) ? true : false; - phpbb_content_visibility::unhide_posts_topics('approve', $post_info, $post_id_list); + phpbb_content_visibility::unhide_posts_topics('approve', $post_info, $post_id_list); $messenger = new messenger(); -- 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/includes/class_content_visibility.php | 42 ++++++++++++++++++++++------- phpBB/includes/functions_posting.php | 8 +++--- phpBB/includes/mcp/mcp_queue.php | 3 ++- 3 files changed, 38 insertions(+), 15 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/class_content_visibility.php b/phpBB/includes/class_content_visibility.php index c7c9586e50..93643773d9 100644 --- a/phpBB/includes/class_content_visibility.php +++ b/phpBB/includes/class_content_visibility.php @@ -30,7 +30,7 @@ class phpbb_content_visibility * @param $table_alias string - Table alias to prefix in SQL queries * @return string with the appropriate combination SQL logic for topic/post_visibility */ - public function get_visibility_sql($mode, $forum_id, $table_alias = '') + static public function get_visibility_sql($mode, $forum_id, $table_alias = '') { global $auth, $db, $user; @@ -67,7 +67,7 @@ class phpbb_content_visibility * @param $table_alias string - Table alias to prefix in SQL queries * @return string with the appropriate combination SQL logic for topic/post_visibility */ - public function get_visibility_sql_global($mode, $exclude_forum_ids = array(), $table_alias = '') + static public function get_visibility_sql_global($mode, $exclude_forum_ids = array(), $table_alias = '') { global $auth, $db, $user; @@ -116,7 +116,7 @@ class phpbb_content_visibility * @param $forum_id - int - forum ID where $topic_id resides * @return bool true = success, false = fail */ - public function set_topic_visibility($visibility, $topic_id, $forum_id) + static public function set_topic_visibility($visibility, $topic_id, $forum_id) { global $db; @@ -139,7 +139,7 @@ class phpbb_content_visibility * @param $is_starter - bool - is this the first post of the topic * @param $is_latest - bool - is this the last post of the topic */ - public function set_post_visibility($visibility, $post_id, $topic_id, $forum_id, $is_starter, $is_latest) + static public function set_post_visibility($visibility, $post_id, $topic_id, $forum_id, $is_starter, $is_latest) { global $db; @@ -182,7 +182,7 @@ class phpbb_content_visibility * @param $post_locked - bool - is the post locked? * @return bool */ - public function can_soft_delete($forum_id, $poster_id, $post_locked) + static function can_soft_delete($forum_id, $poster_id, $post_locked) { global $auth, $user; @@ -228,7 +228,7 @@ class phpbb_content_visibility * @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) + static public function hide_topic($topic_id, $forum_id, &$topic_row, &$sql_data) { global $auth, $config, $db; @@ -266,14 +266,27 @@ class phpbb_content_visibility * 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 $topic_row - array - contains information from the topics table about given topic * @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) + static public function hide_post($forum_id, $current_time, $topic_row, &$sql_data) { global $auth, $config, $db; - $sql_data[TOPICS_TABLE] = 'topic_replies = topic_replies - 1, topic_last_view_time = ' . $current_time; + // initialize the array if needed (php throws E_NOTICE when .= is used + // on a non-existing array element) + if (empty($sql_data[TOPICS_TABLE])) + { + $sql_data[TOPICS_TABLE] = ''; + } + + if ($topic_row['topic_replies'] > 0) + { + $sql_data[TOPICS_TABLE] = 'topic_replies = topic_replies - 1,'; + } + $sql_data[TOPICS_TABLE] .= ' topic_last_view_time = ' . $current_time; + $sql_data[FORUMS_TABLE] = 'forum_posts = forum_posts - 1'; set_config_count('num_posts', -1, true); @@ -293,7 +306,7 @@ class phpbb_content_visibility * 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) + static public function unhide_posts_topics($mode, $post_info, $post_id_list) { global $db, $config; @@ -435,6 +448,15 @@ class phpbb_content_visibility sync('forum', 'forum_id', array_keys($forum_id_list), true, true); unset($topic_id_list, $forum_id_list); - return true; + if ($total_topics) + { + $success_msg = ($total_topics == 1) ? 'TOPIC_APPROVED_SUCCESS' : 'TOPICS_APPROVED_SUCCESS'; + } + else + { + $success_msg = (sizeof($post_id_list) + sizeof($post_approved_list) == 1) ? 'POST_APPROVED_SUCCESS' : 'POSTS_APPROVED_SUCCESS'; + } + + return $success_msg; } } diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index 364a3e7fe2..b63a41df7d 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -1467,7 +1467,7 @@ function delete_post($forum_id, $topic_id, $post_id, &$data, $is_soft = false) if ($is_soft) { phpbb_content_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_content_visibility::hide_post($forum_id, time(), $sql_data); + phpbb_content_visibility::hide_post($forum_id, time(), $data, $sql_data); } else { @@ -1501,7 +1501,7 @@ function delete_post($forum_id, $topic_id, $post_id, &$data, $is_soft = false) if ($is_soft) { $topic_row = array(); - phpbb_content_visibility::set_topic_visibility(POST_DELETED, $topic_id, $forum_id); + phpbb_content_visibility::set_topic_visibility(ITEM_DELETED, $topic_id, $forum_id); phpbb_content_visibility::hide_topic($topic_id, $forum_id, $topic_row, $sql_data); } else @@ -1548,8 +1548,8 @@ function delete_post($forum_id, $topic_id, $post_id, &$data, $is_soft = false) case 'delete_last_post': if ($is_soft) { - phpbb_content_visibility::hide_post($forum_id, time(), $sql_data); - phpbb_content_visibility::set_post_visibility($post_id, $topic_id, $forum_id, false, true); + phpbb_content_visibility::hide_post($forum_id, time(), $data, $sql_data); + phpbb_content_visibility::set_post_visibility(ITEM_DELETED, $post_id, $topic_id, $forum_id, false, true); } else { diff --git a/phpBB/includes/mcp/mcp_queue.php b/phpBB/includes/mcp/mcp_queue.php index 597be855b7..6c36084e68 100644 --- a/phpBB/includes/mcp/mcp_queue.php +++ b/phpBB/includes/mcp/mcp_queue.php @@ -322,6 +322,7 @@ class mcp_queue if ($mode == 'unapproved_posts' || $mode == 'deleted_posts') { $visibility_const = ($mode == 'unapproved_posts') ? ITEM_UNAPPROVED : ITEM_DELETED; + $starter_sql = ($mode == 'unapproved_posts') ? 'AND t.topic_first_post_id <> p.post_id' : ''; $sql = 'SELECT p.post_id FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . ' t' . (($sort_order_sql[0] == 'u') ? ', ' . USERS_TABLE . ' u' : '') . ' @@ -330,7 +331,7 @@ class mcp_queue ' . (($sort_order_sql[0] == 'u') ? 'AND u.user_id = p.poster_id' : '') . ' ' . (($topic_id) ? 'AND p.topic_id = ' . $topic_id : '') . " AND t.topic_id = p.topic_id - AND t.topic_first_post_id <> p.post_id + $starter_sql $limit_time_sql ORDER BY $sort_order_sql"; $result = $db->sql_query_limit($sql, $config['topics_per_page'], $start); -- cgit v1.2.1 From 5ff35ccf72042cadc7f0bddc540eb26f1d99e11b Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 28 Aug 2012 21:54:33 +0200 Subject: [feature/soft-delete] Use autoloading for content_visibility class PHPBB3-9657 --- phpBB/includes/class_content_visibility.php | 462 ---------------------------- phpBB/includes/content_visibility.php | 461 +++++++++++++++++++++++++++ 2 files changed, 461 insertions(+), 462 deletions(-) delete mode 100644 phpBB/includes/class_content_visibility.php create mode 100644 phpBB/includes/content_visibility.php (limited to 'phpBB/includes') diff --git a/phpBB/includes/class_content_visibility.php b/phpBB/includes/class_content_visibility.php deleted file mode 100644 index 93643773d9..0000000000 --- a/phpBB/includes/class_content_visibility.php +++ /dev/null @@ -1,462 +0,0 @@ -acl_get('m_approve', $forum_id)) - { - $status_ary[] = ITEM_UNAPPROVED; - } - - if ($auth->acl_get('m_restore', $forum_id)) - { - $status_ary[] = ITEM_DELETED; - } - - $clause = $db->sql_in_set($table_alias . $mode . '_visibility', $status_ary); - - // only allow the user to view deleted posts he himself made - if ($auth->acl_get('f_restore', $forum_id) && !$auth->acl_get('m_restore', $forum_id)) - { - $poster_column = ($mode == 'topic') ? 'topic_poster' : 'poster_id'; - $clause = '(' . $clause . " - OR ($table_alias{$mode}_visibility = " . ITEM_DELETED . " - AND $table_alias$poster_column = " . $user->data['user_id'] . '))'; - - } - - return $clause; - } - - /** - * Fetch visibility SQL for all forums on the board. - * @param $mode string - either "topic" or "post" - * @param $exclude_forum_ids - int array - - * @param $table_alias string - Table alias to prefix in SQL queries - * @return string with the appropriate combination SQL logic for topic/post_visibility - */ - static public function get_visibility_sql_global($mode, $exclude_forum_ids = array(), $table_alias = '') - { - global $auth, $db, $user; - - // users can always see approved posts - $where_sql = "($table_alias{$mode}_visibility = " . ITEM_APPROVED; - - // in set notation: {approve_forums} = {m_approve} - {exclude_forums} - $approve_forums = array_diff(array_keys($auth->acl_getf('m_approve', true)), $exclude_forum_ids); - if (sizeof($approve_forums)) - { - // users can view unapproved topics in certain forums. specify them. - $where_sql .= " OR ($table_alias{$mode}_visibility = " . ITEM_UNAPPROVED . ' - AND ' . $db->sql_in_set($table_alias . 'forum_id', $approve_forums) . ')'; - } - - // this is exactly the same logic as for approve forums, above - $restore_forums = array_diff(array_keys($auth->acl_getf('m_restore', true)), $exclude_forum_ids); - if (sizeof($restore_forums)) - { - $where_sql .= " OR ($table_alias{$mode}_visibility = " . ITEM_DELETED . ' - AND ' . $db->sql_in_set($table_alias . 'forum_id', $restore_forums) . ')'; - } - - // we also allow the user to view deleted posts he himself made - $user_restore_forums = array_diff(array_keys($auth->acl_getf('f_restore', true)), $exclude_forum_ids); - if (sizeof($user_restore_forums) && !sizeof($restore_forums)) - { - $poster_column = ($mode == 'topic') ? 'topic_poster' : 'poster_id'; - - // specify the poster ID, the visibility type, and the forums we're interested in - $where_sql .= " OR ($table_alias$poster_column = " . $user->data['user_id'] . " - AND $table_alias{$mode}_visibility = " . ITEM_DELETED . " - AND " . $db->sql_in_set($table_alias . 'forum_id', $user_restore_forums) . ')'; - } - - $where_sql .= ')'; - - return $where_sql; - } - - /** - * Description: Allows approving (which is akin to undeleting), unapproving (!) or soft deleting an entire topic. - * Calls set_post_visibility as needed. - * @param $visibility - int - element of {ITEM_UNAPPROVED, ITEM_APPROVED, ITEM_DELETED} - * @param $topic_id - int - topic ID to act on - * @param $forum_id - int - forum ID where $topic_id resides - * @return bool true = success, false = fail - */ - static public function set_topic_visibility($visibility, $topic_id, $forum_id) - { - global $db; - - $sql = 'UPDATE ' . TOPICS_TABLE . ' SET topic_visibility = ' . (int) $visibility . ' - WHERE topic_id = ' . (int) $topic_id; - $db->sql_query($sql); - - // if we're approving, disapproving, or deleteing a topic, assume that - // we are adjusting _all_ posts in that topic. - $status = self::set_post_visibility($visibility, false, $topic_id, $forum_id, true, true); - - return $status; - } - - /** - * @param $visibility - int - element of {ITEM_UNAPPROVED, ITEM_APPROVED, ITEM_DELETED} - * @param $post_id - int - the post ID to act on - * @param $topic_id - int - forum where $post_id is found - * @param $forum_id - int - forum ID where $topic_id resides - * @param $is_starter - bool - is this the first post of the topic - * @param $is_latest - bool - is this the last post of the topic - */ - static public function set_post_visibility($visibility, $post_id, $topic_id, $forum_id, $is_starter, $is_latest) - { - global $db; - - // if we're changing the starter, we need to change the rest of the topic - if ($is_starter && !$is_latest) - { - return self::set_topic_visibility($visibility, $topic_id, $forum_id); - } - - if ($post_id) - { - $where_sql = 'post_id = ' . (int) $post_id; - } - else if ($topic_id) - { - $where_sql = 'topic_id = ' . (int) $topic_id; - } - else - { - // throw new MissingArgumentsException(); <-- a nice idea - return false; - } - - $sql = 'UPDATE ' . POSTS_TABLE . ' SET post_visibility = ' . (int) $visibility . ' - WHERE ' . $where_sql; - $db->sql_query($sql); - - // Sync the first/last topic information if needed - if ($is_starter || $is_latest) - { - update_post_information('topic', $topic_id, false); - 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 - */ - static 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['user_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 - */ - static 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 $topic_row - array - contains information from the topics table about given topic - * @param $sql_data - array - populated with the SQL changes, may be empty at call time - * @return void - */ - static public function hide_post($forum_id, $current_time, $topic_row, &$sql_data) - { - global $auth, $config, $db; - - // initialize the array if needed (php throws E_NOTICE when .= is used - // on a non-existing array element) - if (empty($sql_data[TOPICS_TABLE])) - { - $sql_data[TOPICS_TABLE] = ''; - } - - if ($topic_row['topic_replies'] > 0) - { - $sql_data[TOPICS_TABLE] = 'topic_replies = topic_replies - 1,'; - } - $sql_data[TOPICS_TABLE] .= ' 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 - */ - static 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); - - if ($total_topics) - { - $success_msg = ($total_topics == 1) ? 'TOPIC_APPROVED_SUCCESS' : 'TOPICS_APPROVED_SUCCESS'; - } - else - { - $success_msg = (sizeof($post_id_list) + sizeof($post_approved_list) == 1) ? 'POST_APPROVED_SUCCESS' : 'POSTS_APPROVED_SUCCESS'; - } - - return $success_msg; - } -} diff --git a/phpBB/includes/content_visibility.php b/phpBB/includes/content_visibility.php new file mode 100644 index 0000000000..12b51df3bb --- /dev/null +++ b/phpBB/includes/content_visibility.php @@ -0,0 +1,461 @@ +acl_get('m_approve', $forum_id)) + { + $status_ary[] = ITEM_UNAPPROVED; + } + + if ($auth->acl_get('m_restore', $forum_id)) + { + $status_ary[] = ITEM_DELETED; + } + + $clause = $db->sql_in_set($table_alias . $mode . '_visibility', $status_ary); + + // only allow the user to view deleted posts he himself made + if ($auth->acl_get('f_restore', $forum_id) && !$auth->acl_get('m_restore', $forum_id)) + { + $poster_column = ($mode == 'topic') ? 'topic_poster' : 'poster_id'; + $clause = '(' . $clause . " + OR ($table_alias{$mode}_visibility = " . ITEM_DELETED . " + AND $table_alias$poster_column = " . $user->data['user_id'] . '))'; + + } + + return $clause; + } + + /** + * Fetch visibility SQL for all forums on the board. + * @param $mode string - either "topic" or "post" + * @param $exclude_forum_ids - int array - + * @param $table_alias string - Table alias to prefix in SQL queries + * @return string with the appropriate combination SQL logic for topic/post_visibility + */ + static public function get_visibility_sql_global($mode, $exclude_forum_ids = array(), $table_alias = '') + { + global $auth, $db, $user; + + // users can always see approved posts + $where_sql = "($table_alias{$mode}_visibility = " . ITEM_APPROVED; + + // in set notation: {approve_forums} = {m_approve} - {exclude_forums} + $approve_forums = array_diff(array_keys($auth->acl_getf('m_approve', true)), $exclude_forum_ids); + if (sizeof($approve_forums)) + { + // users can view unapproved topics in certain forums. specify them. + $where_sql .= " OR ($table_alias{$mode}_visibility = " . ITEM_UNAPPROVED . ' + AND ' . $db->sql_in_set($table_alias . 'forum_id', $approve_forums) . ')'; + } + + // this is exactly the same logic as for approve forums, above + $restore_forums = array_diff(array_keys($auth->acl_getf('m_restore', true)), $exclude_forum_ids); + if (sizeof($restore_forums)) + { + $where_sql .= " OR ($table_alias{$mode}_visibility = " . ITEM_DELETED . ' + AND ' . $db->sql_in_set($table_alias . 'forum_id', $restore_forums) . ')'; + } + + // we also allow the user to view deleted posts he himself made + $user_restore_forums = array_diff(array_keys($auth->acl_getf('f_restore', true)), $exclude_forum_ids); + if (sizeof($user_restore_forums) && !sizeof($restore_forums)) + { + $poster_column = ($mode == 'topic') ? 'topic_poster' : 'poster_id'; + + // specify the poster ID, the visibility type, and the forums we're interested in + $where_sql .= " OR ($table_alias$poster_column = " . $user->data['user_id'] . " + AND $table_alias{$mode}_visibility = " . ITEM_DELETED . " + AND " . $db->sql_in_set($table_alias . 'forum_id', $user_restore_forums) . ')'; + } + + $where_sql .= ')'; + + return $where_sql; + } + + /** + * Description: Allows approving (which is akin to undeleting), unapproving (!) or soft deleting an entire topic. + * Calls set_post_visibility as needed. + * @param $visibility - int - element of {ITEM_UNAPPROVED, ITEM_APPROVED, ITEM_DELETED} + * @param $topic_id - int - topic ID to act on + * @param $forum_id - int - forum ID where $topic_id resides + * @return bool true = success, false = fail + */ + static public function set_topic_visibility($visibility, $topic_id, $forum_id) + { + global $db; + + $sql = 'UPDATE ' . TOPICS_TABLE . ' SET topic_visibility = ' . (int) $visibility . ' + WHERE topic_id = ' . (int) $topic_id; + $db->sql_query($sql); + + // if we're approving, disapproving, or deleteing a topic, assume that + // we are adjusting _all_ posts in that topic. + $status = self::set_post_visibility($visibility, false, $topic_id, $forum_id, true, true); + + return $status; + } + + /** + * @param $visibility - int - element of {ITEM_UNAPPROVED, ITEM_APPROVED, ITEM_DELETED} + * @param $post_id - int - the post ID to act on + * @param $topic_id - int - forum where $post_id is found + * @param $forum_id - int - forum ID where $topic_id resides + * @param $is_starter - bool - is this the first post of the topic + * @param $is_latest - bool - is this the last post of the topic + */ + static public function set_post_visibility($visibility, $post_id, $topic_id, $forum_id, $is_starter, $is_latest) + { + global $db; + + // if we're changing the starter, we need to change the rest of the topic + if ($is_starter && !$is_latest) + { + return self::set_topic_visibility($visibility, $topic_id, $forum_id); + } + + if ($post_id) + { + $where_sql = 'post_id = ' . (int) $post_id; + } + else if ($topic_id) + { + $where_sql = 'topic_id = ' . (int) $topic_id; + } + else + { + // throw new MissingArgumentsException(); <-- a nice idea + return false; + } + + $sql = 'UPDATE ' . POSTS_TABLE . ' SET post_visibility = ' . (int) $visibility . ' + WHERE ' . $where_sql; + $db->sql_query($sql); + + // Sync the first/last topic information if needed + if ($is_starter || $is_latest) + { + update_post_information('topic', $topic_id, false); + 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 + */ + static 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['user_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 + */ + static 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 $topic_row - array - contains information from the topics table about given topic + * @param $sql_data - array - populated with the SQL changes, may be empty at call time + * @return void + */ + static public function hide_post($forum_id, $current_time, $topic_row, &$sql_data) + { + global $auth, $config, $db; + + // initialize the array if needed (php throws E_NOTICE when .= is used + // on a non-existing array element) + if (empty($sql_data[TOPICS_TABLE])) + { + $sql_data[TOPICS_TABLE] = ''; + } + + if ($topic_row['topic_replies'] > 0) + { + $sql_data[TOPICS_TABLE] = 'topic_replies = topic_replies - 1,'; + } + $sql_data[TOPICS_TABLE] .= ' 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 + */ + static 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); + + if ($total_topics) + { + $success_msg = ($total_topics == 1) ? 'TOPIC_APPROVED_SUCCESS' : 'TOPICS_APPROVED_SUCCESS'; + } + else + { + $success_msg = (sizeof($post_id_list) + sizeof($post_approved_list) == 1) ? 'POST_APPROVED_SUCCESS' : 'POSTS_APPROVED_SUCCESS'; + } + + return $success_msg; + } +} -- cgit v1.2.1 From 1935568c3ef8f3dc243039973bb37c812be3d447 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 28 Aug 2012 21:57:52 +0200 Subject: [feature/soft-delete] Fix typo in column name topic_visibility PHPBB3-9657 --- phpBB/includes/mcp/mcp_main.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/mcp/mcp_main.php b/phpBB/includes/mcp/mcp_main.php index db9872e04e..a90fc0891e 100644 --- a/phpBB/includes/mcp/mcp_main.php +++ b/phpBB/includes/mcp/mcp_main.php @@ -534,7 +534,7 @@ function mcp_move_topic($topic_ids) 'forum_id' => (int) $row['forum_id'], 'icon_id' => (int) $row['icon_id'], 'topic_attachment' => (int) $row['topic_attachment'], - 'topic_visibliity' => ITEM_APPROVED, // a shadow topic is always approved + 'topic_visibility' => ITEM_APPROVED, // a shadow topic is always approved 'topic_reported' => 0, // a shadow topic is never reported 'topic_title' => (string) $row['topic_title'], 'topic_poster' => (int) $row['topic_poster'], -- cgit v1.2.1 From b774c09c7f25e3119eeffe7363c91c7b9fd6dbf7 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 28 Aug 2012 23:01:38 +0200 Subject: [feature/soft-delete] Use the variable which holds the correct item status PHPBB3-9657 --- phpBB/includes/mcp/mcp_queue.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/mcp/mcp_queue.php b/phpBB/includes/mcp/mcp_queue.php index 6c36084e68..a20ce10aa6 100644 --- a/phpBB/includes/mcp/mcp_queue.php +++ b/phpBB/includes/mcp/mcp_queue.php @@ -327,7 +327,7 @@ class mcp_queue $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) . ' - AND p.post_visibility = ' . ITEM_UNAPPROVED . ' + AND p.post_visibility = ' . $visibility_const . ' ' . (($sort_order_sql[0] == 'u') ? 'AND u.user_id = p.poster_id' : '') . ' ' . (($topic_id) ? 'AND p.topic_id = ' . $topic_id : '') . " AND t.topic_id = p.topic_id -- cgit v1.2.1 From 8a036fa3e4e1fc51a3eb7fded346ccbd84a291b5 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 29 Aug 2012 18:42:14 +0200 Subject: [feature/soft-delete] Update restoring feature to use ajax if requested. Also fixes the mcp as a hole: - displayes a success message - gives a link to the post, if only one was restored PHPBB3-9657 --- phpBB/includes/mcp/mcp_queue.php | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/mcp/mcp_queue.php b/phpBB/includes/mcp/mcp_queue.php index a20ce10aa6..cbf0ff0089 100644 --- a/phpBB/includes/mcp/mcp_queue.php +++ b/phpBB/includes/mcp/mcp_queue.php @@ -470,7 +470,7 @@ class mcp_queue function restore_post($post_id_list, $id, $mode) { global $db, $template, $user, $config; - global $phpEx, $phpbb_root_path; + global $phpEx, $phpbb_root_path, $request; if (!check_ids($post_id_list, POSTS_TABLE, 'post_id', array('m_restore'))) { @@ -483,7 +483,7 @@ function restore_post($post_id_list, $id, $mode) $post_info = get_post_data($post_id_list, 'm_restore'); - phpbb_content_visibility::unhide_posts_topics('restore', $post_info, $post_id_list); + $success_msg = phpbb_content_visibility::unhide_posts_topics('restore', $post_info, $post_id_list); if (!$success_msg) { @@ -500,7 +500,20 @@ function restore_post($post_id_list, $id, $mode) $add_message = '

' . sprintf($user->lang['RETURN_POST'], '', ''); } - trigger_error($user->lang[$success_msg] . '

' . sprintf($user->lang['RETURN_PAGE'], "", '') . $add_message); + $message = $user->lang[$success_msg] . '

' . sprintf($user->lang['RETURN_PAGE'], "", '') . $add_message; + + if ($request->is_ajax()) + { + $json_response = new phpbb_json_response; + $json_response->send(array( + 'MESSAGE_TITLE' => $user->lang['INFORMATION'], + 'MESSAGE_TEXT' => $message, + 'REFRESH_DATA' => null, + 'visible' => true, + )); + } + + trigger_error($message); } } @@ -659,7 +672,7 @@ function approve_post($post_id_list, $id, $mode) 'MESSAGE_TITLE' => $user->lang['INFORMATION'], 'MESSAGE_TEXT' => $message, 'REFRESH_DATA' => null, - 'approved' => true + 'visible' => true, )); } @@ -931,7 +944,7 @@ function disapprove_post($post_id_list, $id, $mode) 'MESSAGE_TITLE' => $user->lang['INFORMATION'], 'MESSAGE_TEXT' => $message, 'REFRESH_DATA' => null, - 'approved' => false + 'visible' => false, )); } -- cgit v1.2.1 From 44ed05f5678b36d907555ed040229564b336632f Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 29 Aug 2012 19:30:33 +0200 Subject: [feature/soft-delete] Simplify the query output if the user has m_restore PHPBB3-9657 --- phpBB/includes/content_visibility.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/content_visibility.php b/phpBB/includes/content_visibility.php index 12b51df3bb..5c3e9d39dd 100644 --- a/phpBB/includes/content_visibility.php +++ b/phpBB/includes/content_visibility.php @@ -42,6 +42,11 @@ class phpbb_content_visibility if ($auth->acl_get('m_restore', $forum_id)) { $status_ary[] = ITEM_DELETED; + + // If the user has m_restore, the rest of the function will not + // make more content visible, so we can return the query here. + // This avoids one OR in all queries + return $db->sql_in_set($table_alias . $mode . '_visibility', $status_ary); } $clause = $db->sql_in_set($table_alias . $mode . '_visibility', $status_ary); @@ -52,8 +57,7 @@ class phpbb_content_visibility $poster_column = ($mode == 'topic') ? 'topic_poster' : 'poster_id'; $clause = '(' . $clause . " OR ($table_alias{$mode}_visibility = " . ITEM_DELETED . " - AND $table_alias$poster_column = " . $user->data['user_id'] . '))'; - + AND $table_alias$poster_column = " . (int) $user->data['user_id'] . '))'; } return $clause; -- cgit v1.2.1 From a1e0690b6b25ffd64f6ae2fc2f7b17a04e931690 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 29 Aug 2012 22:12:33 +0200 Subject: [feature/soft-delete] Simplification part2: user can see all item visibilities If the user can see all visibilities, we can simply leave out the query part, instead of adding a bunch of ANDs. PHPBB3-9657 --- phpBB/includes/content_visibility.php | 8 +++++++- phpBB/includes/functions.php | 3 ++- 2 files changed, 9 insertions(+), 2 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/content_visibility.php b/phpBB/includes/content_visibility.php index 5c3e9d39dd..287c46a335 100644 --- a/phpBB/includes/content_visibility.php +++ b/phpBB/includes/content_visibility.php @@ -43,9 +43,15 @@ class phpbb_content_visibility { $status_ary[] = ITEM_DELETED; + if (sizeof($status_ary) == 3) + { + // The user can see all types, so we simplify this to an empty string, + // as we don't need to restrict anything on the query. + return ''; + } + // If the user has m_restore, the rest of the function will not // make more content visible, so we can return the query here. - // This avoids one OR in all queries return $db->sql_in_set($table_alias . $mode . '_visibility', $status_ary); } diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index ecec1e5e4a..4b7b3d5057 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -1855,7 +1855,8 @@ function update_forum_tracking_info($forum_id, $forum_last_post_time, $f_mark_ti // Handle update of unapproved topics info. // Only update for moderators having m_approve permission for the forum. - $sql_update_unapproved = ($auth->acl_get('m_approve', $forum_id)) ? '': 'AND t.topic_approved = 1'; + $sql_update_unapproved = phpbb_content_visibility::get_visibility_sql('topic', $forum_id, 't.'); + $sql_update_unapproved = ($sql_update_unapproved) ? ' AND ' . $sql_update_unapproved : ''; // Check the forum for any left unread topics. // If there are none, we mark the forum as read. -- cgit v1.2.1 From 1c043254c00023a5fe17b1131fa605ca11d823a0 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 30 Aug 2012 18:07:00 +0200 Subject: [feature/soft-delete] Add get_visibility_sql_forums based on global The resulting query is 4-times faster, as the forum_id IN () arrays are smaller and we need less AND/OR to build the hole query. The main difference between those two functions is, that this one takes an array of included ids and the _global one takes an array of excluded ids. PHPBB3-9657 --- phpBB/includes/content_visibility.php | 48 +++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/content_visibility.php b/phpBB/includes/content_visibility.php index 287c46a335..2e91521c78 100644 --- a/phpBB/includes/content_visibility.php +++ b/phpBB/includes/content_visibility.php @@ -69,6 +69,54 @@ class phpbb_content_visibility return $clause; } + /** + * Fetch visibility SQL for a set of forums + * @param $mode string - either "topic" or "post" + * @param $forum_ids - int array - + * @param $table_alias string - Table alias to prefix in SQL queries + * @return string with the appropriate combination SQL logic for topic/post_visibility + */ + static public function get_visibility_sql_forums($mode, $forum_ids = array(), $table_alias = '') + { + global $auth, $db, $user; + + // users can always see approved posts + $where_sql = "($table_alias{$mode}_visibility = " . ITEM_APPROVED; + + // in set notation: {approve_forums} = {m_approve} - {exclude_forums} + $approve_forums = array_intersect($forum_ids, array_keys($auth->acl_getf('m_approve', true))); + if (sizeof($approve_forums)) + { + // users can view unapproved topics in certain forums. specify them. + $where_sql .= " OR ($table_alias{$mode}_visibility = " . ITEM_UNAPPROVED . ' + AND ' . $db->sql_in_set($table_alias . 'forum_id', $approve_forums) . ')'; + } + + // this is exactly the same logic as for approve forums, above + $restore_forums = array_intersect($forum_ids, array_keys($auth->acl_getf('m_restore', true))); + if (sizeof($restore_forums)) + { + $where_sql .= " OR ($table_alias{$mode}_visibility = " . ITEM_DELETED . ' + AND ' . $db->sql_in_set($table_alias . 'forum_id', $restore_forums) . ')'; + } + + // we also allow the user to view deleted posts he himself made + $user_restore_forums = array_diff(array_intersect($forum_ids, array_keys($auth->acl_getf('f_restore', true))), $restore_forums); + if (sizeof($user_restore_forums) && !sizeof($restore_forums)) + { + $poster_column = ($mode == 'topic') ? 'topic_poster' : 'poster_id'; + + // specify the poster ID, the visibility type, and the forums we're interested in + $where_sql .= " OR ($table_alias$poster_column = " . $user->data['user_id'] . " + AND $table_alias{$mode}_visibility = " . ITEM_DELETED . " + AND " . $db->sql_in_set($table_alias . 'forum_id', $user_restore_forums) . ')'; + } + + $where_sql .= ')'; + + return $where_sql; + } + /** * Fetch visibility SQL for all forums on the board. * @param $mode string - either "topic" or "post" -- cgit v1.2.1 From 5b54ec2d64009eae17a7bfc12975caef03f7bec0 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 30 Aug 2012 19:47:16 +0200 Subject: [feature/soft-delete] Try to fix search.php at least it's running now, but the performance is not very good. PHPBB3-9657 --- phpBB/includes/search/fulltext_native.php | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/search/fulltext_native.php b/phpBB/includes/search/fulltext_native.php index c7e7a451e4..e7fb4bd105 100644 --- a/phpBB/includes/search/fulltext_native.php +++ b/phpBB/includes/search/fulltext_native.php @@ -819,7 +819,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base * @param int $per_page number of ids each page is supposed to contain * @return boolean|int total number of results */ - public function author_search($type, $firstpost_only, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_ary, $author_name, &$id_ary, $start, $per_page) + public function author_search($type, $firstpost_only, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $post_visibility, $topic_id, $author_ary, $author_name, &$id_ary, $start, $per_page) { // No author? No posts. if (!sizeof($author_ary)) @@ -838,7 +838,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base $sort_key, $topic_id, implode(',', $ex_fid_ary), -// @TODO implode(',', $m_approve_fid_ary), + $post_visibility, implode(',', $author_ary), $author_name, ))); @@ -888,20 +888,6 @@ class phpbb_search_fulltext_native extends phpbb_search_base break; } -/* if (!sizeof($m_approve_fid_ary)) - { - $m_approve_fid_sql = ' AND p.post_approved = 1'; - } - else if ($m_approve_fid_ary == array(-1)) - { - $m_approve_fid_sql = ''; - } - else - { - $m_approve_fid_sql = ' AND (p.post_approved = 1 OR ' . $this->db->sql_in_set('p.forum_id', $m_approve_fid_ary, true) . ')'; - } -*/ - $select = ($type == 'posts') ? 'p.post_id' : 't.topic_id'; $is_mysql = false; @@ -924,7 +910,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base WHERE $sql_author $sql_topic_id $sql_firstpost - $m_approve_fid_sql + $post_visibility $sql_fora $sql_time"; } @@ -944,7 +930,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base WHERE $sql_author $sql_topic_id $sql_firstpost - $m_approve_fid_sql + $post_visibility $sql_fora AND t.topic_id = p.topic_id $sql_time" . (($this->db->sql_layer == 'sqlite') ? ')' : ''); @@ -970,7 +956,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base WHERE $sql_author $sql_topic_id $sql_firstpost - $m_approve_fid_sql + $post_visibility $sql_fora $sql_sort_join $sql_time @@ -984,7 +970,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base WHERE $sql_author $sql_topic_id $sql_firstpost - $m_approve_fid_sql + $post_visibility $sql_fora AND t.topic_id = p.topic_id $sql_sort_join -- cgit v1.2.1 From a6d3432f8bb39f20a93a65f9145eec608ea7fd37 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 30 Aug 2012 22:20:52 +0200 Subject: [feature/soft-delete] Update search to use $post_visibility Todo: Sphinx currently does not respect this setting at all. PHPBB3-9657 --- phpBB/includes/search/fulltext_mysql.php | 40 +++++------------------------ phpBB/includes/search/fulltext_native.php | 19 ++++---------- phpBB/includes/search/fulltext_postgres.php | 38 +++++---------------------- phpBB/includes/search/fulltext_sphinx.php | 12 +++++---- 4 files changed, 26 insertions(+), 83 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/search/fulltext_mysql.php b/phpBB/includes/search/fulltext_mysql.php index 73bf5c52f2..81fb82de93 100644 --- a/phpBB/includes/search/fulltext_mysql.php +++ b/phpBB/includes/search/fulltext_mysql.php @@ -265,7 +265,7 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base * @param string $sort_dir is either a or d representing ASC and DESC * @param string $sort_days specifies the maximum amount of days a post may be old * @param array $ex_fid_ary specifies an array of forum ids which should not be searched - * @param array $m_approve_fid_sql specifies which types of posts a user may view, based on permissions + * @param string $post_visibility specifies which types of posts the user can view in which forums * @param int $topic_id is set to 0 or a topic id, if it is not 0 then only posts in this topic should be searched * @param array $author_ary an array of author ids if the author should be ignored during the search the array is empty * @param string $author_name specifies the author match, when ANONYMOUS is also a search-match @@ -274,7 +274,7 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base * @param int $per_page number of ids each page is supposed to contain * @return boolean|int total number of results */ - public function keyword_search($type, $fields, $terms, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_ary, $author_name, &$id_ary, $start, $per_page) + public function keyword_search($type, $fields, $terms, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $post_visibility, $topic_id, $author_ary, $author_name, &$id_ary, $start, $per_page) { // No keywords? No posts. if (!$this->search_query) @@ -292,7 +292,7 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base $sort_key, $topic_id, implode(',', $ex_fid_ary), -// @TODO implode(',', $m_approve_fid_ary), + $post_visibility, implode(',', $author_ary) ))); @@ -354,20 +354,6 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base break; } -/* if (!sizeof($m_approve_fid_ary)) - { - $m_approve_fid_sql = ' AND p.post_approved = 1'; - } - else if ($m_approve_fid_ary === array(-1)) - { - $m_approve_fid_sql = ''; - } - else - { - $m_approve_fid_sql = ' AND (p.post_approved = 1 OR ' . $this->db->sql_in_set('p.forum_id', $m_approve_fid_ary, true) . ')'; - } -*/ - $sql_select = (!$result_count) ? 'SQL_CALC_FOUND_ROWS ' : ''; $sql_select = ($type == 'posts') ? $sql_select . 'p.post_id' : 'DISTINCT ' . $sql_select . 't.topic_id'; $sql_from = ($join_topic) ? TOPICS_TABLE . ' t, ' : ''; @@ -390,7 +376,7 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base $sql_where_options .= ($topic_id) ? ' AND p.topic_id = ' . $topic_id : ''; $sql_where_options .= ($join_topic) ? ' AND t.topic_id = p.topic_id' : ''; $sql_where_options .= (sizeof($ex_fid_ary)) ? ' AND ' . $this->db->sql_in_set('p.forum_id', $ex_fid_ary, true) : ''; - $sql_where_options .= $m_approve_fid_sql; + $sql_where_options .= ' AND ' . $post_visibility; $sql_where_options .= $sql_author; $sql_where_options .= ($sort_days) ? ' AND p.post_time >= ' . (time() - ($sort_days * 86400)) : ''; $sql_where_options .= $sql_match_where; @@ -446,7 +432,7 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base * @param string $sort_dir is either a or d representing ASC and DESC * @param string $sort_days specifies the maximum amount of days a post may be old * @param array $ex_fid_ary specifies an array of forum ids which should not be searched - * @param array $m_approve_fid_sql specifies which types of posts a user may view, based on permissions + * @param string $post_visibility specifies which types of posts the user can view in which forums * @param int $topic_id is set to 0 or a topic id, if it is not 0 then only posts in this topic should be searched * @param array $author_ary an array of author ids * @param string $author_name specifies the author match, when ANONYMOUS is also a search-match @@ -474,7 +460,7 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base $sort_key, $topic_id, implode(',', $ex_fid_ary), -// @TODO implode(',', $m_approve_fid_ary), + $post_visibility, implode(',', $author_ary), $author_name, ))); @@ -524,19 +510,7 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base break; } -/* if (!sizeof($m_approve_fid_ary)) - { - $m_approve_fid_sql = ' AND p.post_approved = 1'; - } - else if ($m_approve_fid_ary == array(-1)) - { - $m_approve_fid_sql = ''; - } - else - { - $m_approve_fid_sql = ' AND (p.post_approved = 1 OR ' . $this->db->sql_in_set('p.forum_id', $m_approve_fid_ary, true) . ')'; - } -*/ + $m_approve_fid_sql = ' AND ' . $post_visibility; // If the cache was completely empty count the results $calc_results = ($result_count) ? '' : 'SQL_CALC_FOUND_ROWS '; diff --git a/phpBB/includes/search/fulltext_native.php b/phpBB/includes/search/fulltext_native.php index e7fb4bd105..56332e872b 100644 --- a/phpBB/includes/search/fulltext_native.php +++ b/phpBB/includes/search/fulltext_native.php @@ -414,7 +414,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base * @param string $sort_dir is either a or d representing ASC and DESC * @param string $sort_days specifies the maximum amount of days a post may be old * @param array $ex_fid_ary specifies an array of forum ids which should not be searched - * @param array $m_approve_fid_sql specifies which types of posts the user can view + * @param string $post_visibility specifies which types of posts the user can view in which forums * @param int $topic_id is set to 0 or a topic id, if it is not 0 then only posts in this topic should be searched * @param array $author_ary an array of author ids if the author should be ignored during the search the array is empty * @param string $author_name specifies the author match, when ANONYMOUS is also a search-match @@ -423,7 +423,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base * @param int $per_page number of ids each page is supposed to contain * @return boolean|int total number of results */ - public function keyword_search($type, $fields, $terms, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_ary, $author_name, &$id_ary, $start, $per_page) + public function keyword_search($type, $fields, $terms, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $post_visibility, $topic_id, $author_ary, $author_name, &$id_ary, $start, $per_page) { // No keywords? No posts. if (empty($this->search_query)) @@ -451,7 +451,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base $sort_key, $topic_id, implode(',', $ex_fid_ary), -// @TODO implode(',', $m_approve_fid_ary), + $post_visibility, implode(',', $author_ary), $author_name, ))); @@ -628,16 +628,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base $sql_where[] = '(' . implode(' OR ', $is_null_joins) . ')'; } -/* if (!sizeof($m_approve_fid_ary)) - { - $sql_where[] = 'p.post_approved = 1'; - } - else if ($m_approve_fid_ary !== array(-1)) - { - $sql_where[] = '(p.post_approved = 1 OR ' . $this->db->sql_in_set('p.forum_id', $m_approve_fid_ary, true) . ')'; - } -*/ - $sql_where[] = $m_approve_fid_sql; + $sql_where[] = $post_visibility; if ($topic_id) { @@ -810,7 +801,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base * @param string $sort_dir is either a or d representing ASC and DESC * @param string $sort_days specifies the maximum amount of days a post may be old * @param array $ex_fid_ary specifies an array of forum ids which should not be searched - * @param array $m_approve_fid_sql specifies which posts a user can view, based on permissions + * @param string $post_visibility specifies which types of posts the user can view in which forums * @param int $topic_id is set to 0 or a topic id, if it is not 0 then only posts in this topic should be searched * @param array $author_ary an array of author ids * @param string $author_name specifies the author match, when ANONYMOUS is also a search-match diff --git a/phpBB/includes/search/fulltext_postgres.php b/phpBB/includes/search/fulltext_postgres.php index 50ed785093..fc2050e76c 100644 --- a/phpBB/includes/search/fulltext_postgres.php +++ b/phpBB/includes/search/fulltext_postgres.php @@ -234,7 +234,7 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base * @param string $sort_dir is either a or d representing ASC and DESC * @param string $sort_days specifies the maximum amount of days a post may be old * @param array $ex_fid_ary specifies an array of forum ids which should not be searched - * @param array $m_approve_fid_ary specifies an array of forum ids in which the searcher is allowed to view unapproved posts + * @param string $post_visibility specifies which types of posts the user can view in which forums * @param int $topic_id is set to 0 or a topic id, if it is not 0 then only posts in this topic should be searched * @param array $author_ary an array of author ids if the author should be ignored during the search the array is empty * @param string $author_name specifies the author match, when ANONYMOUS is also a search-match @@ -261,7 +261,7 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base $sort_key, $topic_id, implode(',', $ex_fid_ary), - implode(',', $m_approve_fid_ary), + $post_visibility, implode(',', $author_ary) ))); @@ -323,19 +323,6 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base break; } - if (!sizeof($m_approve_fid_ary)) - { - $m_approve_fid_sql = ' AND p.post_approved = 1'; - } - else if ($m_approve_fid_ary === array(-1)) - { - $m_approve_fid_sql = ''; - } - else - { - $m_approve_fid_sql = ' AND (p.post_approved = 1 OR ' . $this->db->sql_in_set('p.forum_id', $m_approve_fid_ary, true) . ')'; - } - $sql_select = ($type == 'posts') ? 'p.post_id' : 'DISTINCT t.topic_id'; $sql_from = ($join_topic) ? TOPICS_TABLE . ' t, ' : ''; $field = ($type == 'posts') ? 'post_id' : 'topic_id'; @@ -359,7 +346,7 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base $sql_where_options .= ($topic_id) ? ' AND p.topic_id = ' . $topic_id : ''; $sql_where_options .= ($join_topic) ? ' AND t.topic_id = p.topic_id' : ''; $sql_where_options .= (sizeof($ex_fid_ary)) ? ' AND ' . $this->db->sql_in_set('p.forum_id', $ex_fid_ary, true) : ''; - $sql_where_options .= $m_approve_fid_sql; + $sql_where_options .= ' AND ' . $post_visibility; $sql_where_options .= $sql_author; $sql_where_options .= ($sort_days) ? ' AND p.post_time >= ' . (time() - ($sort_days * 86400)) : ''; $sql_where_options .= $sql_match_where; @@ -418,7 +405,7 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base * @param string $sort_dir is either a or d representing ASC and DESC * @param string $sort_days specifies the maximum amount of days a post may be old * @param array $ex_fid_ary specifies an array of forum ids which should not be searched - * @param array $m_approve_fid_ary specifies an array of forum ids in which the searcher is allowed to view unapproved posts + * @param string $post_visibility specifies which types of posts the user can view in which forums * @param int $topic_id is set to 0 or a topic id, if it is not 0 then only posts in this topic should be searched * @param array $author_ary an array of author ids * @param string $author_name specifies the author match, when ANONYMOUS is also a search-match @@ -427,7 +414,7 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base * @param int $per_page number of ids each page is supposed to contain * @return boolean|int total number of results */ - public function author_search($type, $firstpost_only, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_ary, $author_name, &$id_ary, $start, $per_page) + public function author_search($type, $firstpost_only, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $post_visibility, $topic_id, $author_ary, $author_name, &$id_ary, $start, $per_page) { // No author? No posts. if (!sizeof($author_ary)) @@ -446,7 +433,7 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base $sort_key, $topic_id, implode(',', $ex_fid_ary), - implode(',', $m_approve_fid_ary), + $post_visibility, implode(',', $author_ary), $author_name, ))); @@ -496,18 +483,7 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base break; } - if (!sizeof($m_approve_fid_ary)) - { - $m_approve_fid_sql = ' AND p.post_approved = 1'; - } - else if ($m_approve_fid_ary == array(-1)) - { - $m_approve_fid_sql = ''; - } - else - { - $m_approve_fid_sql = ' AND (p.post_approved = 1 OR ' . $this->db->sql_in_set('p.forum_id', $m_approve_fid_ary, true) . ')'; - } + $m_approve_fid_sql = ' AND ' . $post_visibility; // Build the query for really selecting the post_ids if ($type == 'posts') diff --git a/phpBB/includes/search/fulltext_sphinx.php b/phpBB/includes/search/fulltext_sphinx.php index 288c0b5940..ad9854071d 100644 --- a/phpBB/includes/search/fulltext_sphinx.php +++ b/phpBB/includes/search/fulltext_sphinx.php @@ -340,7 +340,7 @@ class phpbb_search_fulltext_sphinx * @param string $sort_dir is either a or d representing ASC and DESC * @param string $sort_days specifies the maximum amount of days a post may be old * @param array $ex_fid_ary specifies an array of forum ids which should not be searched - * @param array $m_approve_fid_ary specifies an array of forum ids in which the searcher is allowed to view unapproved posts + * @param string $post_visibility specifies which types of posts the user can view in which forums * @param int $topic_id is set to 0 or a topic id, if it is not 0 then only posts in this topic should be searched * @param array $author_ary an array of author ids if the author should be ignored during the search the array is empty * @param string $author_name specifies the author match, when ANONYMOUS is also a search-match @@ -349,7 +349,7 @@ class phpbb_search_fulltext_sphinx * @param int $per_page number of ids each page is supposed to contain * @return boolean|int total number of results */ - public function keyword_search($type, $fields, $terms, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_ary, $author_name, &$id_ary, $start, $per_page) + public function keyword_search($type, $fields, $terms, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $post_visibility, $topic_id, $author_ary, $author_name, &$id_ary, $start, $per_page) { // No keywords? No posts. if (!strlen($this->search_query) && !sizeof($author_ary)) @@ -466,6 +466,8 @@ class phpbb_search_fulltext_sphinx if (sizeof($ex_fid_ary)) { + //@todo: Limit using $post_visibility + // All forums that a user is allowed to access $fid_ary = array_unique(array_intersect(array_keys($this->auth->acl_getf('f_read', true)), array_keys($this->auth->acl_getf('f_search', true)))); // All forums that the user wants to and can search in @@ -541,7 +543,7 @@ class phpbb_search_fulltext_sphinx * @param string $sort_dir is either a or d representing ASC and DESC * @param string $sort_days specifies the maximum amount of days a post may be old * @param array $ex_fid_ary specifies an array of forum ids which should not be searched - * @param array $m_approve_fid_ary specifies an array of forum ids in which the searcher is allowed to view unapproved posts + * @param string $post_visibility specifies which types of posts the user can view in which forums * @param int $topic_id is set to 0 or a topic id, if it is not 0 then only posts in this topic should be searched * @param array $author_ary an array of author ids * @param string $author_name specifies the author match, when ANONYMOUS is also a search-match @@ -550,14 +552,14 @@ class phpbb_search_fulltext_sphinx * @param int $per_page number of ids each page is supposed to contain * @return boolean|int total number of results */ - public function author_search($type, $firstpost_only, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_ary, $author_name, &$id_ary, $start, $per_page) + public function author_search($type, $firstpost_only, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $post_visibility, $topic_id, $author_ary, $author_name, &$id_ary, $start, $per_page) { $this->search_query = ''; $this->sphinx->SetMatchMode(SPH_MATCH_FULLSCAN); $fields = ($firstpost_only) ? 'firstpost' : 'all'; $terms = 'all'; - return $this->keyword_search($type, $fields, $terms, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_ary, $author_name, $id_ary, $start, $per_page); + return $this->keyword_search($type, $fields, $terms, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $post_visibility, $topic_id, $author_ary, $author_name, $id_ary, $start, $per_page); } /** -- cgit v1.2.1 From c03d692a98fafa921a832e063c76a3d844632ca7 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 30 Aug 2012 22:57:00 +0200 Subject: [feature/soft-delete] Fix some more usages of _approved column names PHPBB3-9657 --- phpBB/includes/functions_admin.php | 2 +- phpBB/includes/functions_display.php | 30 ++++++++++-------------------- phpBB/includes/mcp/mcp_queue.php | 11 +---------- 3 files changed, 12 insertions(+), 31 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_admin.php b/phpBB/includes/functions_admin.php index 328c8e9778..54130df935 100644 --- a/phpBB/includes/functions_admin.php +++ b/phpBB/includes/functions_admin.php @@ -1882,7 +1882,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false, $db->sql_freeresult($result); // Use "t" as table alias because of the $where_sql clause - // NOTE: 't.post_approved' in the GROUP BY is causing a major slowdown. + // NOTE: 't.post_visibility' in the GROUP BY is causing a major slowdown. $sql = 'SELECT t.topic_id, t.post_visibility, COUNT(t.post_id) AS total_posts, MIN(t.post_id) AS first_post_id, MAX(t.post_id) AS last_post_id FROM ' . POSTS_TABLE . " t $where_sql diff --git a/phpBB/includes/functions_display.php b/phpBB/includes/functions_display.php index 881c95907b..2781f1a7bb 100644 --- a/phpBB/includes/functions_display.php +++ b/phpBB/includes/functions_display.php @@ -987,33 +987,25 @@ function display_user_activity(&$userdata) $forum_ary = array(); - // Do not include those forums the user is not having read access to... - $forum_read_ary = $auth->acl_getf('!f_read'); - - foreach ($forum_read_ary as $forum_id => $not_allowed) + $forum_read_ary = $auth->acl_getf('f_read'); + foreach ($forum_read_ary as $forum_id => $allowed) { - if ($not_allowed['f_read']) + if ($allowed['f_read']) { $forum_ary[] = (int) $forum_id; } } - $forum_ary = array_unique($forum_ary); - $forum_sql = (sizeof($forum_ary)) ? 'AND ' . $db->sql_in_set('forum_id', $forum_ary, true) : ''; - - $fid_m_approve = $auth->acl_getf('m_approve', true); - $sql_m_approve = (!empty($fid_m_approve)) ? 'OR ' . $db->sql_in_set('forum_id', array_keys($fid_m_approve)) : ''; + $forum_ary = array_diff($forum_ary, $user->get_passworded_forums());; // Obtain active forum $sql = 'SELECT forum_id, COUNT(post_id) AS num_posts FROM ' . POSTS_TABLE . ' - WHERE poster_id = ' . $userdata['user_id'] . " + WHERE poster_id = ' . $userdata['user_id'] . ' AND post_postcount = 1 - AND (post_approved = 1 - $sql_m_approve) - $forum_sql + AND ' . phpbb_content_visibility::get_visibility_sql_forums('post', $forum_ary) . ' GROUP BY forum_id - ORDER BY num_posts DESC"; + ORDER BY num_posts DESC'; $result = $db->sql_query_limit($sql, 1); $active_f_row = $db->sql_fetchrow($result); $db->sql_freeresult($result); @@ -1035,13 +1027,11 @@ function display_user_activity(&$userdata) $sql = 'SELECT topic_id, COUNT(post_id) AS num_posts FROM ' . POSTS_TABLE . ' - WHERE poster_id = ' . $userdata['user_id'] . " + WHERE poster_id = ' . $userdata['user_id'] . ' AND post_postcount = 1 - AND (post_approved = 1 - $sql_m_approve) - $forum_sql_topic + AND ' . phpbb_content_visibility::get_visibility_sql_forums('post', $forum_ary) . ' GROUP BY topic_id - ORDER BY num_posts DESC"; + ORDER BY num_posts DESC'; $result = $db->sql_query_limit($sql, 1); $active_t_row = $db->sql_fetchrow($result); $db->sql_freeresult($result); diff --git a/phpBB/includes/mcp/mcp_queue.php b/phpBB/includes/mcp/mcp_queue.php index cbf0ff0089..3b18b7f0e7 100644 --- a/phpBB/includes/mcp/mcp_queue.php +++ b/phpBB/includes/mcp/mcp_queue.php @@ -548,7 +548,7 @@ function approve_post($post_id_list, $id, $mode) { $notify_poster = (isset($_REQUEST['notify_poster'])) ? true : false; - phpbb_content_visibility::unhide_posts_topics('approve', $post_info, $post_id_list); + $success_msg = phpbb_content_visibility::unhide_posts_topics('approve', $post_info, $post_id_list); $messenger = new messenger(); @@ -607,15 +607,6 @@ function approve_post($post_id_list, $id, $mode) $post_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f={$post_data['forum_id']}&t={$post_data['topic_id']}&p={$post_data['post_id']}") . '#p' . $post_data['post_id']; } unset($post_info); - - if ($total_topics) - { - $success_msg = ($total_topics == 1) ? 'TOPIC_APPROVED_SUCCESS' : 'TOPICS_APPROVED_SUCCESS'; - } - else - { - $success_msg = (sizeof($post_id_list) + sizeof($post_approved_list) == 1) ? 'POST_APPROVED_SUCCESS' : 'POSTS_APPROVED_SUCCESS'; - } } else { -- cgit v1.2.1 From 8b2181eb851081a103802764517f7189ba8fc114 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 28 Sep 2012 16:14:44 +0200 Subject: [feature/soft-delete] Comment out stuff about f_restore for performance reason PHPBB3-9657 --- phpBB/includes/content_visibility.php | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/content_visibility.php b/phpBB/includes/content_visibility.php index 2e91521c78..55adf00e8c 100644 --- a/phpBB/includes/content_visibility.php +++ b/phpBB/includes/content_visibility.php @@ -47,9 +47,15 @@ class phpbb_content_visibility { // The user can see all types, so we simplify this to an empty string, // as we don't need to restrict anything on the query. - return ''; + return '1 = 1'; } + } + + return $db->sql_in_set($table_alias . $mode . '_visibility', $status_ary); + /** + * @todo: Commented out, because the performance is not the best + * // If the user has m_restore, the rest of the function will not // make more content visible, so we can return the query here. return $db->sql_in_set($table_alias . $mode . '_visibility', $status_ary); @@ -64,7 +70,7 @@ class phpbb_content_visibility $clause = '(' . $clause . " OR ($table_alias{$mode}_visibility = " . ITEM_DELETED . " AND $table_alias$poster_column = " . (int) $user->data['user_id'] . '))'; - } + }*/ return $clause; } @@ -100,6 +106,9 @@ class phpbb_content_visibility AND ' . $db->sql_in_set($table_alias . 'forum_id', $restore_forums) . ')'; } + /* + * @todo: Commented out, because the performance is not the best + * // we also allow the user to view deleted posts he himself made $user_restore_forums = array_diff(array_intersect($forum_ids, array_keys($auth->acl_getf('f_restore', true))), $restore_forums); if (sizeof($user_restore_forums) && !sizeof($restore_forums)) @@ -111,6 +120,7 @@ class phpbb_content_visibility AND $table_alias{$mode}_visibility = " . ITEM_DELETED . " AND " . $db->sql_in_set($table_alias . 'forum_id', $user_restore_forums) . ')'; } + */ $where_sql .= ')'; @@ -148,6 +158,9 @@ class phpbb_content_visibility AND ' . $db->sql_in_set($table_alias . 'forum_id', $restore_forums) . ')'; } + /* + * @todo: Commented out, because the performance is not the best + * // we also allow the user to view deleted posts he himself made $user_restore_forums = array_diff(array_keys($auth->acl_getf('f_restore', true)), $exclude_forum_ids); if (sizeof($user_restore_forums) && !sizeof($restore_forums)) @@ -159,6 +172,7 @@ class phpbb_content_visibility AND $table_alias{$mode}_visibility = " . ITEM_DELETED . " AND " . $db->sql_in_set($table_alias . 'forum_id', $user_restore_forums) . ')'; } + */ $where_sql .= ')'; -- cgit v1.2.1 From e5377e98c7eca8754f423ef495e4b092590f4e03 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 28 Sep 2012 16:53:38 +0200 Subject: [feature/soft-delete] Allow setting the visibility change reason PHPBB3-9657 --- phpBB/includes/content_visibility.php | 49 +++++++++++++++++++++++++---------- phpBB/includes/functions_posting.php | 8 +++--- 2 files changed, 39 insertions(+), 18 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/content_visibility.php b/phpBB/includes/content_visibility.php index 55adf00e8c..165c28f1af 100644 --- a/phpBB/includes/content_visibility.php +++ b/phpBB/includes/content_visibility.php @@ -185,21 +185,28 @@ class phpbb_content_visibility * @param $visibility - int - element of {ITEM_UNAPPROVED, ITEM_APPROVED, ITEM_DELETED} * @param $topic_id - int - topic ID to act on * @param $forum_id - int - forum ID where $topic_id resides - * @return bool true = success, false = fail + * @return void */ - static public function set_topic_visibility($visibility, $topic_id, $forum_id) + static public function set_topic_visibility($visibility, $topic_id, $forum_id, $user_id, $time, $reason) { global $db; - $sql = 'UPDATE ' . TOPICS_TABLE . ' SET topic_visibility = ' . (int) $visibility . ' + $data = array( + 'topic_visibility' => (int) $visibility, + 'topic_delete_user' => (int) $user_id, + 'topic_delete_time' => ((int) $time) ?: time(), + 'topic_delete_reason' => truncate_string($reason, 255, 255, false), + ); + + $sql = 'UPDATE ' . TOPICS_TABLE . ' + SET ' . $db->sql_build_array('UPDATE', $data) . ' WHERE topic_id = ' . (int) $topic_id; $db->sql_query($sql); - // if we're approving, disapproving, or deleteing a topic, assume that - // we are adjusting _all_ posts in that topic. - $status = self::set_post_visibility($visibility, false, $topic_id, $forum_id, true, true); - - return $status; + // If we're approving, disapproving, or deleteing a topic + // we also update all posts in that topic that need to be changed. + // However, we do not set the same reason for every post. + self::set_post_visibility($visibility, false, $topic_id, $forum_id, $user_id, $time, '', true, true); } /** @@ -209,8 +216,9 @@ class phpbb_content_visibility * @param $forum_id - int - forum ID where $topic_id resides * @param $is_starter - bool - is this the first post of the topic * @param $is_latest - bool - is this the last post of the topic + * @return void */ - static public function set_post_visibility($visibility, $post_id, $topic_id, $forum_id, $is_starter, $is_latest) + static public function set_post_visibility($visibility, $post_id, $topic_id, $forum_id, $user_id, $time, $reason, $is_starter, $is_latest) { global $db; @@ -230,19 +238,32 @@ class phpbb_content_visibility } else { - // throw new MissingArgumentsException(); <-- a nice idea - return false; + return; } - $sql = 'UPDATE ' . POSTS_TABLE . ' SET post_visibility = ' . (int) $visibility . ' + $data = array( + 'post_visibility' => (int) $visibility, + 'post_delete_user' => (int) $user_id, + 'post_delete_time' => ((int) $time) ?: time(), + 'post_delete_reason' => truncate_string($reason, 255, 255, false), + ); + + $sql = 'UPDATE ' . POSTS_TABLE . ' + SET ' . $db->sql_build_array('UPDATE', $data) . ' WHERE ' . $where_sql; $db->sql_query($sql); // Sync the first/last topic information if needed if ($is_starter || $is_latest) { - update_post_information('topic', $topic_id, false); - update_post_information('forum', $forum_id, false); + if ($topic_id) + { + update_post_information('topic', $topic_id, false); + } + if ($forum_id) + { + update_post_information('forum', $forum_id, false); + } } } diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index b63a41df7d..38f173330a 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, $is_soft = false) +function delete_post($forum_id, $topic_id, $post_id, &$data, $is_soft = false, $softdelete_reason = '') { global $db, $user, $auth; global $config, $phpEx, $phpbb_root_path; @@ -1466,7 +1466,7 @@ function delete_post($forum_id, $topic_id, $post_id, &$data, $is_soft = false) if ($is_soft) { - phpbb_content_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_content_visibility::set_post_visibility(ITEM_DELETED, $post_id, $topic_id, $forum_id, $user->data['user_id'], time(), $softdelete_reason, ($data['topic_first_post_id'] == $post_id), ($data['topic_last_post_id'] == $post_id)); phpbb_content_visibility::hide_post($forum_id, time(), $data, $sql_data); } else @@ -1501,7 +1501,7 @@ function delete_post($forum_id, $topic_id, $post_id, &$data, $is_soft = false) if ($is_soft) { $topic_row = array(); - phpbb_content_visibility::set_topic_visibility(ITEM_DELETED, $topic_id, $forum_id); + phpbb_content_visibility::set_topic_visibility(ITEM_DELETED, $topic_id, $forum_id, $user->data['user_id'], time(), $softdelete_reason); phpbb_content_visibility::hide_topic($topic_id, $forum_id, $topic_row, $sql_data); } else @@ -1548,8 +1548,8 @@ function delete_post($forum_id, $topic_id, $post_id, &$data, $is_soft = false) case 'delete_last_post': if ($is_soft) { + phpbb_content_visibility::set_post_visibility(ITEM_DELETED, $post_id, $topic_id, $forum_id, $user->data['user_id'], time(), $softdelete_reason, false, true); phpbb_content_visibility::hide_post($forum_id, time(), $data, $sql_data); - phpbb_content_visibility::set_post_visibility(ITEM_DELETED, $post_id, $topic_id, $forum_id, false, true); } else { -- cgit v1.2.1 From 1943de36f32609b37230da32aa679466043702fe Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 1 Oct 2012 16:25:05 +0200 Subject: [feature/soft-delete] Comment out user_posts update for the moment It should rely on the permissions of the post not the current user. PHPBB3-9657 --- phpBB/includes/content_visibility.php | 10 ++++++++++ phpBB/includes/mcp/mcp_queue.php | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/content_visibility.php b/phpBB/includes/content_visibility.php index 165c28f1af..9d2bf34370 100644 --- a/phpBB/includes/content_visibility.php +++ b/phpBB/includes/content_visibility.php @@ -346,10 +346,16 @@ class phpbb_content_visibility set_config_count('num_posts', ($topic_row['topic_replies'] + 1) * (-1), true); // Only decrement this post, since this is the one non-approved now + // + /** + * @todo: this is wrong, it should rely on post_postcount + * also a user might have more than one post in the topic + * if ($auth->acl_get('f_postcount', $forum_id)) { $sql_data[USERS_TABLE] = 'user_posts = user_posts - 1'; } + */ } /** @@ -383,10 +389,14 @@ class phpbb_content_visibility set_config_count('num_posts', -1, true); + /** + * @todo: this is wrong, it should rely on post_postcount + * if ($auth->acl_get('f_postcount', $forum_id)) { $sql_data[USERS_TABLE] = 'user_posts = user_posts - 1'; } + */ } /** diff --git a/phpBB/includes/mcp/mcp_queue.php b/phpBB/includes/mcp/mcp_queue.php index 3b18b7f0e7..b1b4ea99aa 100644 --- a/phpBB/includes/mcp/mcp_queue.php +++ b/phpBB/includes/mcp/mcp_queue.php @@ -465,7 +465,7 @@ class mcp_queue /** -* Approve Post/Topic +* Restore Post/Topic */ function restore_post($post_id_list, $id, $mode) { -- cgit v1.2.1 From 4a65940e6206aef6b85a0aacfb5324ecabf76e12 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 1 Oct 2012 22:14:04 +0200 Subject: [feature/soft-delete] Add unit tests for get_forums_visibility_sql() PHPBB3-9657 --- phpBB/includes/content_visibility.php | 5 +++-- phpBB/includes/functions_display.php | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/content_visibility.php b/phpBB/includes/content_visibility.php index 9d2bf34370..a598d863a4 100644 --- a/phpBB/includes/content_visibility.php +++ b/phpBB/includes/content_visibility.php @@ -82,12 +82,13 @@ class phpbb_content_visibility * @param $table_alias string - Table alias to prefix in SQL queries * @return string with the appropriate combination SQL logic for topic/post_visibility */ - static public function get_visibility_sql_forums($mode, $forum_ids = array(), $table_alias = '') + static public function get_forums_visibility_sql($mode, $forum_ids = array(), $table_alias = '') { global $auth, $db, $user; // users can always see approved posts - $where_sql = "($table_alias{$mode}_visibility = " . ITEM_APPROVED; + $where_sql = "(($table_alias{$mode}_visibility = " . ITEM_APPROVED . ' + AND ' . $db->sql_in_set($table_alias . 'forum_id', $forum_ids) . ')'; // in set notation: {approve_forums} = {m_approve} - {exclude_forums} $approve_forums = array_intersect($forum_ids, array_keys($auth->acl_getf('m_approve', true))); diff --git a/phpBB/includes/functions_display.php b/phpBB/includes/functions_display.php index 2781f1a7bb..5849f5cf4c 100644 --- a/phpBB/includes/functions_display.php +++ b/phpBB/includes/functions_display.php @@ -1003,7 +1003,7 @@ function display_user_activity(&$userdata) FROM ' . POSTS_TABLE . ' WHERE poster_id = ' . $userdata['user_id'] . ' AND post_postcount = 1 - AND ' . phpbb_content_visibility::get_visibility_sql_forums('post', $forum_ary) . ' + AND ' . phpbb_content_visibility::get_forums_visibility_sql('post', $forum_ary) . ' GROUP BY forum_id ORDER BY num_posts DESC'; $result = $db->sql_query_limit($sql, 1); @@ -1029,7 +1029,7 @@ function display_user_activity(&$userdata) FROM ' . POSTS_TABLE . ' WHERE poster_id = ' . $userdata['user_id'] . ' AND post_postcount = 1 - AND ' . phpbb_content_visibility::get_visibility_sql_forums('post', $forum_ary) . ' + AND ' . phpbb_content_visibility::get_forums_visibility_sql('post', $forum_ary) . ' GROUP BY topic_id ORDER BY num_posts DESC'; $result = $db->sql_query_limit($sql, 1); -- cgit v1.2.1 From b629b2cd95a9da67376f7a628c15199007e2ebd6 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 1 Oct 2012 22:44:39 +0200 Subject: [feature/soft-delete] Add unit tests for get_global_visibility_sql() PHPBB3-9657 --- phpBB/includes/content_visibility.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/content_visibility.php b/phpBB/includes/content_visibility.php index a598d863a4..e927460a49 100644 --- a/phpBB/includes/content_visibility.php +++ b/phpBB/includes/content_visibility.php @@ -135,12 +135,20 @@ class phpbb_content_visibility * @param $table_alias string - Table alias to prefix in SQL queries * @return string with the appropriate combination SQL logic for topic/post_visibility */ - static public function get_visibility_sql_global($mode, $exclude_forum_ids = array(), $table_alias = '') + static public function get_global_visibility_sql($mode, $exclude_forum_ids = array(), $table_alias = '') { global $auth, $db, $user; // users can always see approved posts - $where_sql = "($table_alias{$mode}_visibility = " . ITEM_APPROVED; + if (sizeof($exclude_forum_ids)) + { + $where_sql = '((' . $db->sql_in_set($table_alias . 'forum_id', $exclude_forum_ids, true, true) . " + AND $table_alias{$mode}_visibility = " . ITEM_APPROVED . ')'; + } + else + { + $where_sql = "($table_alias{$mode}_visibility = " . ITEM_APPROVED; + } // in set notation: {approve_forums} = {m_approve} - {exclude_forums} $approve_forums = array_diff(array_keys($auth->acl_getf('m_approve', true)), $exclude_forum_ids); -- cgit v1.2.1 From a84e4029e4ecde691a0d34ef72ddab4fc56a07ee Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 2 Oct 2012 12:46:44 +0200 Subject: [feature/soft-delete] Update doc blocks to proper format PHPBB3-9657 --- phpBB/includes/content_visibility.php | 39 ++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 14 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/content_visibility.php b/phpBB/includes/content_visibility.php index e927460a49..1aa2ad1a29 100644 --- a/phpBB/includes/content_visibility.php +++ b/phpBB/includes/content_visibility.php @@ -24,10 +24,13 @@ class phpbb_content_visibility { /** * Create topic/post visibility SQL for a given forum ID - * @param $mode string - either "topic" or "post" - * @param $forum_id int - current forum ID - * @param $table_alias string - Table alias to prefix in SQL queries - * @return string with the appropriate combination SQL logic for topic/post_visibility + * + * Note: Read permissions are not checked. + * + * @param $mode string Either "topic" or "post" + * @param $forum_id int The forum id is used for permission checks + * @param $table_alias string Table alias to prefix in SQL queries + * @return string The appropriate combination SQL logic for topic/post_visibility */ static public function get_visibility_sql($mode, $forum_id, $table_alias = '') { @@ -76,11 +79,15 @@ class phpbb_content_visibility } /** - * Fetch visibility SQL for a set of forums - * @param $mode string - either "topic" or "post" - * @param $forum_ids - int array - - * @param $table_alias string - Table alias to prefix in SQL queries - * @return string with the appropriate combination SQL logic for topic/post_visibility + * Create topic/post visibility SQL for a set of forums + * + * Note: Read permissions are not checked. Forums without read permissions + * should not be in $forum_ids + * + * @param $mode string Either "topic" or "post" + * @param $forum_ids array Array of forum ids which the posts/topics are limited to + * @param $table_alias string Table alias to prefix in SQL queries + * @return string The appropriate combination SQL logic for topic/post_visibility */ static public function get_forums_visibility_sql($mode, $forum_ids = array(), $table_alias = '') { @@ -129,11 +136,15 @@ class phpbb_content_visibility } /** - * Fetch visibility SQL for all forums on the board. - * @param $mode string - either "topic" or "post" - * @param $exclude_forum_ids - int array - - * @param $table_alias string - Table alias to prefix in SQL queries - * @return string with the appropriate combination SQL logic for topic/post_visibility + * Create topic/post visibility SQL for all forums on the board + * + * Note: Read permissions are not checked. Forums without read permissions + * should be in $exclude_forum_ids + * + * @param $mode string Either "topic" or "post" + * @param $exclude_forum_ids array Array of forum ids which are excluded + * @param $table_alias string Table alias to prefix in SQL queries + * @return string The appropriate combination SQL logic for topic/post_visibility */ static public function get_global_visibility_sql($mode, $exclude_forum_ids = array(), $table_alias = '') { -- cgit v1.2.1 From 5b64ebc11d10b66212661282a4dcfd411d038211 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 2 Oct 2012 15:34:18 +0200 Subject: [feature/soft-delete] Fix a bug in sync() and set_post_visibility() PHPBB3-9657 --- phpBB/includes/content_visibility.php | 15 ++++++++------- phpBB/includes/functions_admin.php | 6 +++--- 2 files changed, 11 insertions(+), 10 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/content_visibility.php b/phpBB/includes/content_visibility.php index 1aa2ad1a29..8bc67a7fd2 100644 --- a/phpBB/includes/content_visibility.php +++ b/phpBB/includes/content_visibility.php @@ -242,12 +242,6 @@ class phpbb_content_visibility { global $db; - // if we're changing the starter, we need to change the rest of the topic - if ($is_starter && !$is_latest) - { - return self::set_topic_visibility($visibility, $topic_id, $forum_id); - } - if ($post_id) { $where_sql = 'post_id = ' . (int) $post_id; @@ -274,8 +268,9 @@ class phpbb_content_visibility $db->sql_query($sql); // Sync the first/last topic information if needed - if ($is_starter || $is_latest) + if (!$is_starter && $is_latest) { + // update_post_information can only update the last post info ... if ($topic_id) { update_post_information('topic', $topic_id, false); @@ -285,6 +280,12 @@ class phpbb_content_visibility update_post_information('forum', $forum_id, false); } } + else if (($is_starter || $is_latest) && $topic_id) + { + // ... so we need to use sync, if the first post is changed. + // The forum is resynced recursive by sync() itself. + sync('topic', 'topic_id', $topic_id, true); + } } /** diff --git a/phpBB/includes/functions_admin.php b/phpBB/includes/functions_admin.php index 54130df935..bb8b02bbea 100644 --- a/phpBB/includes/functions_admin.php +++ b/phpBB/includes/functions_admin.php @@ -1908,12 +1908,12 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false, unset($delete_topics[$topic_id]); $topic_data[$topic_id]['replies_real'] += $row['total_posts']; - $topic_data[$topic_id]['first_post_id'] = (!$topic_data[$topic_id]['first_post_id']) ? $row['first_post_id'] : min($topic_data[$topic_id]['first_post_id'], $row['first_post_id']); - if ($row['post_visibility'] || !$topic_data[$topic_id]['last_post_id']) + if ($row['post_visibility'] == ITEM_APPROVED) { - $topic_data[$topic_id]['replies'] = $row['total_posts'] - 1; + $topic_data[$topic_id]['first_post_id'] = $row['first_post_id']; $topic_data[$topic_id]['last_post_id'] = $row['last_post_id']; + $topic_data[$topic_id]['replies'] = $row['total_posts'] - 1; } } } -- cgit v1.2.1 From 2a81e4b48ee223d8538e960b6e8e6e1c3e1277b2 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 5 Oct 2012 12:06:36 +0200 Subject: [feature/soft-delete] Fix the get functions to match the new logic PHPBB3-9567 --- phpBB/includes/content_visibility.php | 138 +++++++++------------------------- 1 file changed, 35 insertions(+), 103 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/content_visibility.php b/phpBB/includes/content_visibility.php index 8bc67a7fd2..112780224f 100644 --- a/phpBB/includes/content_visibility.php +++ b/phpBB/includes/content_visibility.php @@ -34,48 +34,14 @@ class phpbb_content_visibility */ static public function get_visibility_sql($mode, $forum_id, $table_alias = '') { - global $auth, $db, $user; + global $auth; - $status_ary = array(ITEM_APPROVED); if ($auth->acl_get('m_approve', $forum_id)) { - $status_ary[] = ITEM_UNAPPROVED; + return '1 = 1'; } - if ($auth->acl_get('m_restore', $forum_id)) - { - $status_ary[] = ITEM_DELETED; - - if (sizeof($status_ary) == 3) - { - // The user can see all types, so we simplify this to an empty string, - // as we don't need to restrict anything on the query. - return '1 = 1'; - } - } - - return $db->sql_in_set($table_alias . $mode . '_visibility', $status_ary); - - /** - * @todo: Commented out, because the performance is not the best - * - // If the user has m_restore, the rest of the function will not - // make more content visible, so we can return the query here. - return $db->sql_in_set($table_alias . $mode . '_visibility', $status_ary); - } - - $clause = $db->sql_in_set($table_alias . $mode . '_visibility', $status_ary); - - // only allow the user to view deleted posts he himself made - if ($auth->acl_get('f_restore', $forum_id) && !$auth->acl_get('m_restore', $forum_id)) - { - $poster_column = ($mode == 'topic') ? 'topic_poster' : 'poster_id'; - $clause = '(' . $clause . " - OR ($table_alias{$mode}_visibility = " . ITEM_DELETED . " - AND $table_alias$poster_column = " . (int) $user->data['user_id'] . '))'; - }*/ - - return $clause; + return $table_alias . $mode . '_visibility = ' . ITEM_APPROVED; } /** @@ -91,46 +57,37 @@ class phpbb_content_visibility */ static public function get_forums_visibility_sql($mode, $forum_ids = array(), $table_alias = '') { - global $auth, $db, $user; + global $auth, $db; - // users can always see approved posts - $where_sql = "(($table_alias{$mode}_visibility = " . ITEM_APPROVED . ' - AND ' . $db->sql_in_set($table_alias . 'forum_id', $forum_ids) . ')'; + $where_sql = '('; - // in set notation: {approve_forums} = {m_approve} - {exclude_forums} $approve_forums = array_intersect($forum_ids, array_keys($auth->acl_getf('m_approve', true))); + if (sizeof($approve_forums)) { - // users can view unapproved topics in certain forums. specify them. - $where_sql .= " OR ($table_alias{$mode}_visibility = " . ITEM_UNAPPROVED . ' - AND ' . $db->sql_in_set($table_alias . 'forum_id', $approve_forums) . ')'; - } + // Remove moderator forums from the rest + $forum_ids = array_diff($forum_ids, $approve_forums); - // this is exactly the same logic as for approve forums, above - $restore_forums = array_intersect($forum_ids, array_keys($auth->acl_getf('m_restore', true))); - if (sizeof($restore_forums)) - { - $where_sql .= " OR ($table_alias{$mode}_visibility = " . ITEM_DELETED . ' - AND ' . $db->sql_in_set($table_alias . 'forum_id', $restore_forums) . ')'; + if (!sizeof($forum_ids)) + { + // The user can see all posts/topics in all specified forums + return $db->sql_in_set($table_alias . 'forum_id', $approve_forums); + } + else + { + // Moderator can view all posts/topics in some forums + $where_sql .= $db->sql_in_set($table_alias . 'forum_id', $approve_forums) . ' OR '; + } } - - /* - * @todo: Commented out, because the performance is not the best - * - // we also allow the user to view deleted posts he himself made - $user_restore_forums = array_diff(array_intersect($forum_ids, array_keys($auth->acl_getf('f_restore', true))), $restore_forums); - if (sizeof($user_restore_forums) && !sizeof($restore_forums)) + else { - $poster_column = ($mode == 'topic') ? 'topic_poster' : 'poster_id'; - - // specify the poster ID, the visibility type, and the forums we're interested in - $where_sql .= " OR ($table_alias$poster_column = " . $user->data['user_id'] . " - AND $table_alias{$mode}_visibility = " . ITEM_DELETED . " - AND " . $db->sql_in_set($table_alias . 'forum_id', $user_restore_forums) . ')'; + // The user is just a normal user + return "$table_alias{$mode}_visibility = " . ITEM_APPROVED . ' + AND ' . $db->sql_in_set($table_alias . 'forum_id', $forum_ids, false, true); } - */ - $where_sql .= ')'; + $where_sql .= "($table_alias{$mode}_visibility = " . ITEM_APPROVED . ' + AND ' . $db->sql_in_set($table_alias . 'forum_id', $forum_ids) . '))'; return $where_sql; } @@ -148,55 +105,30 @@ class phpbb_content_visibility */ static public function get_global_visibility_sql($mode, $exclude_forum_ids = array(), $table_alias = '') { - global $auth, $db, $user; + global $auth, $db; + + $where_sqls = array(); + + $approve_forums = array_diff(array_keys($auth->acl_getf('m_approve', true)), $exclude_forum_ids); - // users can always see approved posts if (sizeof($exclude_forum_ids)) { - $where_sql = '((' . $db->sql_in_set($table_alias . 'forum_id', $exclude_forum_ids, true, true) . " + $where_sqls[] = '(' . $db->sql_in_set($table_alias . 'forum_id', $exclude_forum_ids, true) . " AND $table_alias{$mode}_visibility = " . ITEM_APPROVED . ')'; } else { - $where_sql = "($table_alias{$mode}_visibility = " . ITEM_APPROVED; + $where_sqls[] = "$table_alias{$mode}_visibility = " . ITEM_APPROVED; } - // in set notation: {approve_forums} = {m_approve} - {exclude_forums} - $approve_forums = array_diff(array_keys($auth->acl_getf('m_approve', true)), $exclude_forum_ids); if (sizeof($approve_forums)) { - // users can view unapproved topics in certain forums. specify them. - $where_sql .= " OR ($table_alias{$mode}_visibility = " . ITEM_UNAPPROVED . ' - AND ' . $db->sql_in_set($table_alias . 'forum_id', $approve_forums) . ')'; + $where_sqls[] = $db->sql_in_set($table_alias . 'forum_id', $approve_forums); + return '(' . implode(' OR ', $where_sqls) . ')'; } - // this is exactly the same logic as for approve forums, above - $restore_forums = array_diff(array_keys($auth->acl_getf('m_restore', true)), $exclude_forum_ids); - if (sizeof($restore_forums)) - { - $where_sql .= " OR ($table_alias{$mode}_visibility = " . ITEM_DELETED . ' - AND ' . $db->sql_in_set($table_alias . 'forum_id', $restore_forums) . ')'; - } - - /* - * @todo: Commented out, because the performance is not the best - * - // we also allow the user to view deleted posts he himself made - $user_restore_forums = array_diff(array_keys($auth->acl_getf('f_restore', true)), $exclude_forum_ids); - if (sizeof($user_restore_forums) && !sizeof($restore_forums)) - { - $poster_column = ($mode == 'topic') ? 'topic_poster' : 'poster_id'; - - // specify the poster ID, the visibility type, and the forums we're interested in - $where_sql .= " OR ($table_alias$poster_column = " . $user->data['user_id'] . " - AND $table_alias{$mode}_visibility = " . ITEM_DELETED . " - AND " . $db->sql_in_set($table_alias . 'forum_id', $user_restore_forums) . ')'; - } - */ - - $where_sql .= ')'; - - return $where_sql; + // There is only one element, so we just return that one + return $where_sqls[0]; } /** -- cgit v1.2.1 From 63d11c976b0bcef68ce4809c8c76124451df88ea Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 5 Oct 2012 12:37:01 +0200 Subject: [feature/soft-delete] Fix sync('topic') to match the new logic This also fixes set_post_visibility() PHPBB3-9567 --- phpBB/includes/content_visibility.php | 2 +- phpBB/includes/functions_admin.php | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/content_visibility.php b/phpBB/includes/content_visibility.php index 112780224f..fbcdf27f08 100644 --- a/phpBB/includes/content_visibility.php +++ b/phpBB/includes/content_visibility.php @@ -212,7 +212,7 @@ class phpbb_content_visibility update_post_information('forum', $forum_id, false); } } - else if (($is_starter || $is_latest) && $topic_id) + else if ($is_starter && $topic_id) { // ... so we need to use sync, if the first post is changed. // The forum is resynced recursive by sync() itself. diff --git a/phpBB/includes/functions_admin.php b/phpBB/includes/functions_admin.php index bb8b02bbea..04c99b5e62 100644 --- a/phpBB/includes/functions_admin.php +++ b/phpBB/includes/functions_admin.php @@ -1889,6 +1889,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false, GROUP BY t.topic_id, t.post_visibility"; $result = $db->sql_query($sql); + $topic_firstlast_data = array(); while ($row = $db->sql_fetchrow($result)) { $topic_id = (int) $row['topic_id']; @@ -1911,10 +1912,19 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false, if ($row['post_visibility'] == ITEM_APPROVED) { + $topic_firstlast_data[$topic_id]['visibility'] = ITEM_APPROVED; $topic_data[$topic_id]['first_post_id'] = $row['first_post_id']; $topic_data[$topic_id]['last_post_id'] = $row['last_post_id']; $topic_data[$topic_id]['replies'] = $row['total_posts'] - 1; } + else if (!isset($topic_firstlast_data[$topic_id]['visibility']) || $topic_firstlast_data[$topic_id]['visibility'] != ITEM_APPROVED) + { + // If there is no approved post, we take the min/max of the other visibilities + // for the last and first post info, because it is only visible to moderators anyway + $topic_data[$topic_id]['first_post_id'] = (!empty($topic_data[$topic_id]['first_post_id'])) ? min($topic_data[$topic_id]['first_post_id'], $row['first_post_id']) : $row['first_post_id']; + $topic_data[$topic_id]['last_post_id'] = max($topic_data[$topic_id]['last_post_id'], $row['last_post_id']); + $topic_firstlast_data[$topic_id]['visibility'] = $row['post_visibility']; + } } } $db->sql_freeresult($result); -- cgit v1.2.1 From bfa6a50a4ff2caf1589a1039c1037d4153223d63 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 5 Oct 2012 13:12:36 +0200 Subject: [feature/soft-delete] Extend functionality for updating a hole topic Limit the posts to a certain visibility and deletion time This allows us to only restore posts, that were approved when the topic got soft deleted. So previous soft deleted and unapproved posts are still soft deleted/unapproved PHPBB3-9567 --- phpBB/includes/content_visibility.php | 37 ++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/content_visibility.php b/phpBB/includes/content_visibility.php index fbcdf27f08..be08a5f536 100644 --- a/phpBB/includes/content_visibility.php +++ b/phpBB/includes/content_visibility.php @@ -162,18 +162,28 @@ class phpbb_content_visibility } /** - * @param $visibility - int - element of {ITEM_UNAPPROVED, ITEM_APPROVED, ITEM_DELETED} - * @param $post_id - int - the post ID to act on - * @param $topic_id - int - forum where $post_id is found - * @param $forum_id - int - forum ID where $topic_id resides - * @param $is_starter - bool - is this the first post of the topic - * @param $is_latest - bool - is this the last post of the topic + * Change visibility status of one post or a hole topic + * + * @param $visibility int Element of {ITEM_APPROVED, ITEM_DELETED} + * @param $post_id mixed Post ID to act on, if it is empty, + * all posts of topic_id will be modified + * @param $topic_id int Topic where $post_id is found + * @param $forum_id int Forum where $topic_id is found + * @param $is_starter bool Is this the first post of the topic changed? + * @param $is_latest bool Is this the last post of the topic changed? + * @param $limit_visibility mixed Limit updating per topic_id to a certain visibility + * @param $limit_delete_time mixed Limit updating per topic_id to a certain deletion time * @return void */ - static public function set_post_visibility($visibility, $post_id, $topic_id, $forum_id, $user_id, $time, $reason, $is_starter, $is_latest) + static public function set_post_visibility($visibility, $post_id, $topic_id, $forum_id, $user_id, $time, $reason, $is_starter, $is_latest, $limit_visibility = false, $limit_delete_time = false) { global $db; + if (!in_array($visibility, array(ITEM_APPROVED, ITEM_DELETED))) + { + return; + } + if ($post_id) { $where_sql = 'post_id = ' . (int) $post_id; @@ -181,6 +191,19 @@ class phpbb_content_visibility else if ($topic_id) { $where_sql = 'topic_id = ' . (int) $topic_id; + + // Limit the posts to a certain visibility and deletion time + // This allows us to only restore posts, that were approved + // when the topic got soft deleted. So previous soft deleted + // and unapproved posts are still soft deleted/unapproved + if ($limit_visibility !== false) + { + $where_sql .= ' AND post_visibility = ' . (int) $limit_visibility; + } + if ($limit_delete_time !== false) + { + $where_sql .= ' AND post_delete_time = ' . (int) $limit_delete_time; + } } else { -- cgit v1.2.1 From 42bb97a95cf57074edf2a30f1b4f417cfce81d13 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 5 Oct 2012 13:15:55 +0200 Subject: [feature/soft-delete] Make use of set_post_visibility() limits when applicable PHPBB3-9567 --- phpBB/includes/content_visibility.php | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/content_visibility.php b/phpBB/includes/content_visibility.php index be08a5f536..7bcabbdfd6 100644 --- a/phpBB/includes/content_visibility.php +++ b/phpBB/includes/content_visibility.php @@ -143,6 +143,24 @@ class phpbb_content_visibility { global $db; + if (in_array($visibility, array(ITEM_APPROVED, ITEM_DELETED))) + { + return; + } + + $sql = 'SELECT topic_visibility, topic_delete_time + FROM ' . TOPICS_TABLE . ' + WHERE topic_id = ' . (int) $topic_id; + $result = $db->sql_query($sql); + $original_topic_data = $db->sql_fetchrow($result); + $db->sql_freeresult($result); + + if (!$original_topic_data) + { + // The topic does not exist... + return; + } + $data = array( 'topic_visibility' => (int) $visibility, 'topic_delete_user' => (int) $user_id, @@ -155,10 +173,16 @@ class phpbb_content_visibility WHERE topic_id = ' . (int) $topic_id; $db->sql_query($sql); - // If we're approving, disapproving, or deleteing a topic - // we also update all posts in that topic that need to be changed. - // However, we do not set the same reason for every post. - self::set_post_visibility($visibility, false, $topic_id, $forum_id, $user_id, $time, '', true, true); + // If we're restoring a topic we only restore posts, that were soft deleted through the topic soft deletion. + if ($original_topic_data['topic_delete_time'] && $original_topic_data['topic_visibility'] == ITEM_DELETED && $visibility == ITEM_APPROVED) + { + // Note, we do not set the same reason for every post. + self::set_post_visibility($visibility, false, $topic_id, $forum_id, $user_id, $time, '', true, true, $original_topic_data['topic_visibility'], $original_topic_data['topic_delete_time']); + } + else + { + self::set_post_visibility($visibility, false, $topic_id, $forum_id, $user_id, $time, '', true, true); + } } /** -- cgit v1.2.1 From 92c5039af971722198ce634d719db6290d58c678 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 5 Oct 2012 13:18:06 +0200 Subject: [feature/soft-delete] Allow forcing the set_visibility for all posts PHPBB3-9567 --- phpBB/includes/content_visibility.php | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/content_visibility.php b/phpBB/includes/content_visibility.php index 7bcabbdfd6..4f5da25919 100644 --- a/phpBB/includes/content_visibility.php +++ b/phpBB/includes/content_visibility.php @@ -139,7 +139,7 @@ class phpbb_content_visibility * @param $forum_id - int - forum ID where $topic_id resides * @return void */ - static public function set_topic_visibility($visibility, $topic_id, $forum_id, $user_id, $time, $reason) + static public function set_topic_visibility($visibility, $topic_id, $forum_id, $user_id, $time, $reason, $force_update_all = false) { global $db; @@ -148,17 +148,20 @@ class phpbb_content_visibility return; } - $sql = 'SELECT topic_visibility, topic_delete_time - FROM ' . TOPICS_TABLE . ' - WHERE topic_id = ' . (int) $topic_id; - $result = $db->sql_query($sql); - $original_topic_data = $db->sql_fetchrow($result); - $db->sql_freeresult($result); - - if (!$original_topic_data) + if (!$force_update_all && $visibility == ITEM_APPROVED) { - // The topic does not exist... - return; + $sql = 'SELECT topic_visibility, topic_delete_time + FROM ' . TOPICS_TABLE . ' + WHERE topic_id = ' . (int) $topic_id; + $result = $db->sql_query($sql); + $original_topic_data = $db->sql_fetchrow($result); + $db->sql_freeresult($result); + + if (!$original_topic_data) + { + // The topic does not exist... + return; + } } $data = array( @@ -174,7 +177,7 @@ class phpbb_content_visibility $db->sql_query($sql); // If we're restoring a topic we only restore posts, that were soft deleted through the topic soft deletion. - if ($original_topic_data['topic_delete_time'] && $original_topic_data['topic_visibility'] == ITEM_DELETED && $visibility == ITEM_APPROVED) + if (!$force_update_all && $original_topic_data['topic_delete_time'] && $original_topic_data['topic_visibility'] == ITEM_DELETED && $visibility == ITEM_APPROVED) { // Note, we do not set the same reason for every post. self::set_post_visibility($visibility, false, $topic_id, $forum_id, $user_id, $time, '', true, true, $original_topic_data['topic_visibility'], $original_topic_data['topic_delete_time']); -- cgit v1.2.1 From 01a78907bd05fc51f62ebd169065277365c5d1f4 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 5 Oct 2012 13:30:59 +0200 Subject: [feature/soft-delete] Update set_topic_visibility() with some more logic By default, when a soft deleted topic is restored. Only posts that were approved at the time of soft deleting, are being restored. Same applies to soft deleting. Only approved posts will be marked as soft deleted. If you want to update all posts, use the force option. PHPBB3-9567 --- phpBB/includes/content_visibility.php | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/content_visibility.php b/phpBB/includes/content_visibility.php index 4f5da25919..238e131f1d 100644 --- a/phpBB/includes/content_visibility.php +++ b/phpBB/includes/content_visibility.php @@ -132,11 +132,24 @@ class phpbb_content_visibility } /** - * Description: Allows approving (which is akin to undeleting), unapproving (!) or soft deleting an entire topic. + * Set topic visibility + * + * Allows approving (which is akin to undeleting/restore) or soft deleting an entire topic. * Calls set_post_visibility as needed. - * @param $visibility - int - element of {ITEM_UNAPPROVED, ITEM_APPROVED, ITEM_DELETED} - * @param $topic_id - int - topic ID to act on - * @param $forum_id - int - forum ID where $topic_id resides + * + * Note: By default, when a soft deleted topic is restored. Only posts that + * were approved at the time of soft deleting, are being restored. + * Same applies to soft deleting. Only approved posts will be marked + * as soft deleted. + * If you want to update all posts, use the force option. + * + * @param $visibility int Element of {ITEM_APPROVED, ITEM_DELETED} + * @param $topic_id mixed Topic ID to act on + * @param $forum_id int Forum where $topic_id is found + * @param $user_id int User performing the action + * @param $time int Timestamp when the action is performed + * @param $reason string Reason why the visibilty was changed. + * @param $force_update_all bool Force to update all posts within the topic * @return void */ static public function set_topic_visibility($visibility, $topic_id, $forum_id, $user_id, $time, $reason, $force_update_all = false) @@ -164,6 +177,7 @@ class phpbb_content_visibility } } + // Note, we do not set a reason for the posts, just for the topic $data = array( 'topic_visibility' => (int) $visibility, 'topic_delete_user' => (int) $user_id, @@ -176,12 +190,16 @@ class phpbb_content_visibility WHERE topic_id = ' . (int) $topic_id; $db->sql_query($sql); - // If we're restoring a topic we only restore posts, that were soft deleted through the topic soft deletion. if (!$force_update_all && $original_topic_data['topic_delete_time'] && $original_topic_data['topic_visibility'] == ITEM_DELETED && $visibility == ITEM_APPROVED) { - // Note, we do not set the same reason for every post. + // If we're restoring a topic we only restore posts, that were soft deleted through the topic soft deletion. self::set_post_visibility($visibility, false, $topic_id, $forum_id, $user_id, $time, '', true, true, $original_topic_data['topic_visibility'], $original_topic_data['topic_delete_time']); } + else if (!$force_update_all && $original_topic_data['topic_visibility'] == ITEM_APPROVED && $visibility == ITEM_DELETED) + { + // If we're soft deleting a topic we only approved posts are soft deleted. + self::set_post_visibility($visibility, false, $topic_id, $forum_id, $user_id, $time, '', true, true, $original_topic_data['topic_visibility']); + } else { self::set_post_visibility($visibility, false, $topic_id, $forum_id, $user_id, $time, '', true, true); -- cgit v1.2.1 From 7969cc7319002fdf24d041e8d298577cd04d9c4a Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 5 Oct 2012 13:31:47 +0200 Subject: [feature/soft-delete] Fix docs of set_post_visibility() PHPBB3-9567 --- phpBB/includes/content_visibility.php | 3 +++ 1 file changed, 3 insertions(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/content_visibility.php b/phpBB/includes/content_visibility.php index 238e131f1d..325993bd2a 100644 --- a/phpBB/includes/content_visibility.php +++ b/phpBB/includes/content_visibility.php @@ -214,6 +214,9 @@ class phpbb_content_visibility * all posts of topic_id will be modified * @param $topic_id int Topic where $post_id is found * @param $forum_id int Forum where $topic_id is found + * @param $user_id int User performing the action + * @param $time int Timestamp when the action is performed + * @param $reason string Reason why the visibilty was changed. * @param $is_starter bool Is this the first post of the topic changed? * @param $is_latest bool Is this the last post of the topic changed? * @param $limit_visibility mixed Limit updating per topic_id to a certain visibility -- cgit v1.2.1 From 526721c7db9ddc8fc39fd84409042deb470a1736 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 5 Oct 2012 14:26:52 +0200 Subject: [feature/soft-delete] Fix set_topic_visibility() so it passes the tests PHPBB3-9567 --- phpBB/includes/content_visibility.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/content_visibility.php b/phpBB/includes/content_visibility.php index 325993bd2a..a0bb3e9fd4 100644 --- a/phpBB/includes/content_visibility.php +++ b/phpBB/includes/content_visibility.php @@ -156,12 +156,12 @@ class phpbb_content_visibility { global $db; - if (in_array($visibility, array(ITEM_APPROVED, ITEM_DELETED))) + if (!in_array($visibility, array(ITEM_APPROVED, ITEM_DELETED))) { return; } - if (!$force_update_all && $visibility == ITEM_APPROVED) + if (!$force_update_all) { $sql = 'SELECT topic_visibility, topic_delete_time FROM ' . TOPICS_TABLE . ' -- 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/includes/content_visibility.php | 28 ++++------------------------ 1 file changed, 4 insertions(+), 24 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/content_visibility.php b/phpBB/includes/content_visibility.php index a0bb3e9fd4..f2915a5143 100644 --- a/phpBB/includes/content_visibility.php +++ b/phpBB/includes/content_visibility.php @@ -293,9 +293,10 @@ class phpbb_content_visibility /** * 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? + * + * @param $forum_id int Forum ID whose permissions to check + * @param $poster_id int Poster ID of the post in question + * @param $post_locked bool Is the post locked? * @return bool */ static function can_soft_delete($forum_id, $poster_id, $post_locked) @@ -310,28 +311,7 @@ class phpbb_content_visibility { 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; } -- cgit v1.2.1 From c22d5bd37c26fb5e007519a0ea93001ecd060a1c Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 5 Oct 2012 17:00:14 +0200 Subject: [feature/soft-delete] Clean the code of hide_post() and rely on postcount PHPBB3-9567 --- phpBB/includes/content_visibility.php | 41 ++++++++++------------------------- 1 file changed, 12 insertions(+), 29 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/content_visibility.php b/phpBB/includes/content_visibility.php index f2915a5143..2b79868930 100644 --- a/phpBB/includes/content_visibility.php +++ b/phpBB/includes/content_visibility.php @@ -316,8 +316,7 @@ class phpbb_content_visibility } /** - * Do the required math to hide a complete topic (going from approved to - * unapproved or from approved to deleted) + * Do the required math to hide a complete topic (going 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 @@ -326,7 +325,7 @@ class phpbb_content_visibility */ static public function hide_topic($topic_id, $forum_id, &$topic_row, &$sql_data) { - global $auth, $config, $db; + global $db; // Do we need to grab some topic informations? if (!sizeof($topic_row)) @@ -339,9 +338,6 @@ class phpbb_content_visibility $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); @@ -363,44 +359,31 @@ class phpbb_content_visibility } /** - * Do the required math to hide a single post (going from approved to - * unapproved or from approved to deleted) + * Do the required math to hide a single post (going 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 $topic_row - array - contains information from the topics table about given topic + * @param $data - array - contains information from the topics table about given topic * @param $sql_data - array - populated with the SQL changes, may be empty at call time * @return void */ - static public function hide_post($forum_id, $current_time, $topic_row, &$sql_data) + //static public function remove_post_from_postcount($forum_id, $current_time, $data, &$sql_data) + static public function hide_post($forum_id, $current_time, $data, &$sql_data) { - global $auth, $config, $db; - - // initialize the array if needed (php throws E_NOTICE when .= is used - // on a non-existing array element) - if (empty($sql_data[TOPICS_TABLE])) - { - $sql_data[TOPICS_TABLE] = ''; - } - - if ($topic_row['topic_replies'] > 0) + $sql_data[TOPICS_TABLE] = 'topic_last_view_time = ' . $current_time; + if ($data['topic_replies'] > 0) { - $sql_data[TOPICS_TABLE] = 'topic_replies = topic_replies - 1,'; + $sql_data[TOPICS_TABLE] .= ', topic_replies = topic_replies - 1,'; } - $sql_data[TOPICS_TABLE] .= ' topic_last_view_time = ' . $current_time; $sql_data[FORUMS_TABLE] = 'forum_posts = forum_posts - 1'; - set_config_count('num_posts', -1, true); - - /** - * @todo: this is wrong, it should rely on post_postcount - * - if ($auth->acl_get('f_postcount', $forum_id)) + if ($data['post_postcount']) { $sql_data[USERS_TABLE] = 'user_posts = user_posts - 1'; } - */ + + set_config_count('num_posts', -1, true); } /** -- cgit v1.2.1 From 3088855aa6c9bed9a15f3bd4ab1113d37be916a5 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 5 Oct 2012 17:46:29 +0200 Subject: [feature/soft-delete] Fix SQL error in search PHPBB3-9567 --- phpBB/includes/search/fulltext_native.php | 1 + phpBB/includes/search/fulltext_postgres.php | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/search/fulltext_native.php b/phpBB/includes/search/fulltext_native.php index 56332e872b..0e520b63a2 100644 --- a/phpBB/includes/search/fulltext_native.php +++ b/phpBB/includes/search/fulltext_native.php @@ -857,6 +857,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base $sql_time = ($sort_days) ? ' AND p.post_time >= ' . (time() - ($sort_days * 86400)) : ''; $sql_topic_id = ($topic_id) ? ' AND p.topic_id = ' . (int) $topic_id : ''; $sql_firstpost = ($firstpost_only) ? ' AND p.post_id = t.topic_first_post_id' : ''; + $post_visibility = ($post_visibility) ? ' AND ' . $post_visibility : ''; // Build sql strings for sorting $sql_sort = $sort_by_sql[$sort_key] . (($sort_dir == 'a') ? ' ASC' : ' DESC'); diff --git a/phpBB/includes/search/fulltext_postgres.php b/phpBB/includes/search/fulltext_postgres.php index fc2050e76c..dfe90db0f0 100644 --- a/phpBB/includes/search/fulltext_postgres.php +++ b/phpBB/includes/search/fulltext_postgres.php @@ -243,7 +243,7 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base * @param int $per_page number of ids each page is supposed to contain * @return boolean|int total number of results */ - public function keyword_search($type, $fields, $terms, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_ary, $author_name, &$id_ary, $start, $per_page) + public function keyword_search($type, $fields, $terms, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $post_visibility, $topic_id, $author_ary, $author_name, &$id_ary, $start, $per_page) { // No keywords? No posts. if (!$this->search_query) -- cgit v1.2.1 From 009bd698fb46a529f09d9d9a63748e63eec62895 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 6 Oct 2012 03:59:49 +0200 Subject: [feature/soft-delete] Update and simplify the logic on delete_post() Todo: delete_topic case PHPBB3-9567 --- phpBB/includes/content_visibility.php | 25 +++++------ phpBB/includes/functions_posting.php | 80 +++++++++++++++++------------------ 2 files changed, 48 insertions(+), 57 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/content_visibility.php b/phpBB/includes/content_visibility.php index 2b79868930..f8b632bbe8 100644 --- a/phpBB/includes/content_visibility.php +++ b/phpBB/includes/content_visibility.php @@ -359,28 +359,22 @@ class phpbb_content_visibility } /** - * Do the required math to hide a single post (going 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 $data - array - contains information from the topics table about given topic - * @param $sql_data - array - populated with the SQL changes, may be empty at call time + * Remove post from topic and forum statistics + * + * @param $forum_id int Forum where the topic is found + * @param $data array Contains information from the topics table about given topic + * @param $sql_data array Populated with the SQL changes, may be empty at call time * @return void */ - //static public function remove_post_from_postcount($forum_id, $current_time, $data, &$sql_data) - static public function hide_post($forum_id, $current_time, $data, &$sql_data) + static public function remove_post_from_postcount($forum_id, $data, &$sql_data) { - $sql_data[TOPICS_TABLE] = 'topic_last_view_time = ' . $current_time; - if ($data['topic_replies'] > 0) - { - $sql_data[TOPICS_TABLE] .= ', topic_replies = topic_replies - 1,'; - } + $sql_data[TOPICS_TABLE] = ($sql_data[TOPICS_TABLE]) ? $sql_data[TOPICS_TABLE] . ', ' : '') . 'topic_replies = topic_replies - 1'; - $sql_data[FORUMS_TABLE] = 'forum_posts = forum_posts - 1'; + $sql_data[FORUMS_TABLE] = ($sql_data[FORUMS_TABLE]) ? $sql_data[FORUMS_TABLE] . ', ' : '') . 'forum_posts = forum_posts - 1'; if ($data['post_postcount']) { - $sql_data[USERS_TABLE] = 'user_posts = user_posts - 1'; + $sql_data[USERS_TABLE] = ($sql_data[USERS_TABLE]) ? $sql_data[USERS_TABLE] . ', ' : '') . 'user_posts = user_posts - 1'; } set_config_count('num_posts', -1, true); @@ -539,6 +533,7 @@ class phpbb_content_visibility if ($total_topics) { + //@todo: plurals! $success_msg = ($total_topics == 1) ? 'TOPIC_APPROVED_SUCCESS' : 'TOPICS_APPROVED_SUCCESS'; } else diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index 38f173330a..7738fcbc4e 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -1422,14 +1422,10 @@ function delete_post($forum_id, $topic_id, $post_id, &$data, $is_soft = false, $ { $post_mode = 'delete_topic'; } - else if ($data['topic_first_post_id'] == $post_id && !$is_soft) + else if ($data['topic_first_post_id'] == $post_id) { $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'; @@ -1464,10 +1460,10 @@ function delete_post($forum_id, $topic_id, $post_id, &$data, $is_soft = false, $ $db->sql_freeresult($result); } + // (Soft) delete the post if ($is_soft) { phpbb_content_visibility::set_post_visibility(ITEM_DELETED, $post_id, $topic_id, $forum_id, $user->data['user_id'], time(), $softdelete_reason, ($data['topic_first_post_id'] == $post_id), ($data['topic_last_post_id'] == $post_id)); - phpbb_content_visibility::hide_post($forum_id, time(), $data, $sql_data); } else { @@ -1535,53 +1531,45 @@ function delete_post($forum_id, $topic_id, $post_id, &$data, $is_soft = false, $ $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); - $sql_data[FORUMS_TABLE] = ($data['post_visibility'] == ITEM_APPROVED) ? 'forum_posts = forum_posts - 1' : ''; - - $sql_data[TOPICS_TABLE] = 'topic_poster = ' . intval($row['poster_id']) . ', topic_first_post_id = ' . intval($row['post_id']) . ", topic_first_poster_colour = '" . $db->sql_escape($row['user_colour']) . "', topic_first_poster_name = '" . (($row['poster_id'] == ANONYMOUS) ? $db->sql_escape($row['post_username']) : $db->sql_escape($row['username'])) . "', topic_time = " . (int) $row['post_time']; - - // Decrementing topic_replies here is fine because this case only happens if there is more than one post within the topic - basically removing one "reply" - $sql_data[TOPICS_TABLE] .= ', topic_replies_real = topic_replies_real - 1' . (($data['post_visibility'] == ITEM_APPROVED) ? ', topic_replies = topic_replies - 1' : ''); - $next_post_id = (int) $row['post_id']; + + $sql_data[TOPICS_TABLE] = $db->sql_build_array('UPDATE', array( + 'topic_poster' => (int) $row['poster_id'], + 'topic_first_post_id' => (int) $row['post_id'] + 'topic_first_poster_colour' => $row['user_colour'], + 'topic_first_poster_name' => ($row['poster_id'] == ANONYMOUS) ? $row['post_username'] : $row['username'], + 'topic_time' => (int) $row['post_time'], + )); break; case 'delete_last_post': - if ($is_soft) + if (!$is_soft) { - phpbb_content_visibility::set_post_visibility(ITEM_DELETED, $post_id, $topic_id, $forum_id, $user->data['user_id'], time(), $softdelete_reason, false, true); - phpbb_content_visibility::hide_post($forum_id, time(), $data, $sql_data); - } - 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[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] = ($sql_data[TOPICS_TABLE]) ? $sql_data[TOPICS_TABLE] . ', ' : '') . 'topic_bumped = 0, topic_bumper = 0'; - $update_sql = update_post_information('topic', $topic_id, true); - 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]); + $update_sql = update_post_information('topic', $topic_id, true); + if (!empty($update_sql)) + { + $sql_data[TOPICS_TABLE] .= ', ' . implode(', ', $update_sql[$topic_id]); + $next_post_id = (int) str_replace('topic_last_post_id = ', '', $update_sql[$topic_id][0]); + } } - else + + if (!$next_post_id) { $sql = 'SELECT MAX(post_id) as last_post_id FROM ' . POSTS_TABLE . " WHERE topic_id = $topic_id AND " . phpbb_content_visibility::get_visibility_sql('post', $forum_id); $result = $db->sql_query($sql); - $row = $db->sql_fetchrow($result); + $next_post_id = (int) $db->sql_fetchfield('last_post_id'); $db->sql_freeresult($result); - - $next_post_id = (int) $row['last_post_id']; } break; @@ -1593,14 +1581,22 @@ function delete_post($forum_id, $topic_id, $post_id, &$data, $is_soft = false, $ AND post_time > ' . $data['post_time'] . ' ORDER BY post_time ASC'; $result = $db->sql_query_limit($sql, 1); - $row = $db->sql_fetchrow($result); + $next_post_id = (int) $db->sql_fetchfield('post_id'); $db->sql_freeresult($result); + break; + } - $sql_data[FORUMS_TABLE] = ($data['post_visibility'] == ITEM_APPROVED) ? 'forum_posts = forum_posts - 1' : ''; + if (($post_mode == 'delete') || ($post_mode == 'delete_last_post') || ($post_mode == 'delete_first_post')) + { + if ($data['post_visibility'] == ITEM_APPROVED) + { + phpbb_content_visibility::remove_post_from_postcount($forum_id, $data, $sql_data); + } - $sql_data[TOPICS_TABLE] = 'topic_replies_real = topic_replies_real - 1' . (($data['post_visibility'] == ITEM_APPROVED) ? ', topic_replies = topic_replies - 1' : ''); - $next_post_id = (int) $row['post_id']; - break; + if (!$is_soft) + { + $sql_data[TOPICS_TABLE] .= ', topic_replies_real = topic_replies_real - 1'; + } } if (($post_mode == 'delete') || ($post_mode == 'delete_last_post') || ($post_mode == 'delete_first_post')) @@ -1625,7 +1621,7 @@ function delete_post($forum_id, $topic_id, $post_id, &$data, $is_soft = false, $ $where_sql = array( FORUMS_TABLE => "forum_id = $forum_id", TOPICS_TABLE => "topic_id = $topic_id", - USERS_TABLE => 'user_id = ' . $data['poster_id'] + USERS_TABLE => 'user_id = ' . $data['poster_id'], ); foreach ($sql_data as $table => $update_sql) @@ -1960,7 +1956,7 @@ 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_content_visibility::hide_post($forum_id, $current_time, $sql_data); + //phpbb_content_visibility::remove_post_from_postcount($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'; @@ -2302,7 +2298,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u } } } - else if (!$data['post_visibility'] == ITEM_APPROVED && ($post_mode == 'edit_last_post' || $post_mode == 'edit_topic' || ($post_mode == 'edit_first_post' && !$data['topic_replies']))) + else if ($data['post_visibility'] != ITEM_APPROVED && ($post_mode == 'edit_last_post' || $post_mode == 'edit_topic' || ($post_mode == 'edit_first_post' && !$data['topic_replies']))) { // like having the rug pulled from under us $sql = 'SELECT MAX(post_id) as last_post_id -- cgit v1.2.1 From 44005f338e227c10a21270456d181d56749d3f29 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 6 Oct 2012 16:36:38 +0200 Subject: [feature/soft-delete] Fix delete_post() function PHPBB3-9567 --- phpBB/includes/content_visibility.php | 23 +++++++++-------- phpBB/includes/functions_posting.php | 48 +++++++++++++++++++++++------------ 2 files changed, 44 insertions(+), 27 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/content_visibility.php b/phpBB/includes/content_visibility.php index f8b632bbe8..54c580cd40 100644 --- a/phpBB/includes/content_visibility.php +++ b/phpBB/includes/content_visibility.php @@ -316,14 +316,15 @@ class phpbb_content_visibility } /** - * Do the required math to hide a complete topic (going 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 + * Remove topic from forum statistics + * + * @param $topic_id int The topic to act on + * @param $forum_id int Forum where the topic is found + * @param $topic_row array Contains information from 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 */ - static public function hide_topic($topic_id, $forum_id, &$topic_row, &$sql_data) + static public function remove_topic_from_statistic($topic_id, $forum_id, &$topic_row, &$sql_data) { global $db; @@ -339,7 +340,7 @@ class phpbb_content_visibility } // 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] = (($sql_data[FORUMS_TABLE]) ? $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); @@ -366,15 +367,15 @@ class phpbb_content_visibility * @param $sql_data array Populated with the SQL changes, may be empty at call time * @return void */ - static public function remove_post_from_postcount($forum_id, $data, &$sql_data) + static public function remove_post_from_statistic($forum_id, $data, &$sql_data) { - $sql_data[TOPICS_TABLE] = ($sql_data[TOPICS_TABLE]) ? $sql_data[TOPICS_TABLE] . ', ' : '') . 'topic_replies = topic_replies - 1'; + $sql_data[TOPICS_TABLE] = (($sql_data[TOPICS_TABLE]) ? $sql_data[TOPICS_TABLE] . ', ' : '') . 'topic_replies = topic_replies - 1'; - $sql_data[FORUMS_TABLE] = ($sql_data[FORUMS_TABLE]) ? $sql_data[FORUMS_TABLE] . ', ' : '') . 'forum_posts = forum_posts - 1'; + $sql_data[FORUMS_TABLE] = (($sql_data[FORUMS_TABLE]) ? $sql_data[FORUMS_TABLE] . ', ' : '') . 'forum_posts = forum_posts - 1'; if ($data['post_postcount']) { - $sql_data[USERS_TABLE] = ($sql_data[USERS_TABLE]) ? $sql_data[USERS_TABLE] . ', ' : '') . 'user_posts = user_posts - 1'; + $sql_data[USERS_TABLE] = (($sql_data[USERS_TABLE]) ? $sql_data[USERS_TABLE] . ', ' : '') . 'user_posts = user_posts - 1'; } set_config_count('num_posts', -1, true); diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index 7738fcbc4e..d9fbd84ce1 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -1490,7 +1490,11 @@ function delete_post($forum_id, $topic_id, $post_id, &$data, $is_soft = false, $ { // counting is fun! we only have to do sizeof($forum_ids) number of queries, // even if the topic is moved back to where its shadow lives (we count how many times it is in a forum) - $db->sql_query('UPDATE ' . FORUMS_TABLE . ' SET forum_topics_real = forum_topics_real - ' . $topic_count . ', forum_topics = forum_topics - ' . $topic_count . ' WHERE forum_id = ' . $updated_forum); + $sql = 'UPDATE ' . FORUMS_TABLE . ' + SET forum_topics_real = forum_topics_real - ' . $topic_count . ', + forum_topics = forum_topics - ' . $topic_count . ' + WHERE forum_id = ' . $updated_forum; + $db->sql_query($sql); update_post_information('forum', $updated_forum); } @@ -1498,18 +1502,15 @@ function delete_post($forum_id, $topic_id, $post_id, &$data, $is_soft = false, $ { $topic_row = array(); phpbb_content_visibility::set_topic_visibility(ITEM_DELETED, $topic_id, $forum_id, $user->data['user_id'], time(), $softdelete_reason); - phpbb_content_visibility::hide_topic($topic_id, $forum_id, $topic_row, $sql_data); + phpbb_content_visibility::remove_topic_from_statistic($topic_id, $forum_id, $topic_row, $sql_data); } else { delete_topics('topic_id', array($topic_id), false); - 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' : ''; - } + $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)) @@ -1526,16 +1527,30 @@ function delete_post($forum_id, $topic_id, $post_id, &$data, $is_soft = false, $ FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . " u WHERE p.topic_id = $topic_id AND p.poster_id = u.user_id - ORDER BY p.post_time ASC"; + AND p.post_visibility = " . ITEM_APPROVED . ' + ORDER BY p.post_time ASC'; $result = $db->sql_query_limit($sql, 1); $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); + if (!$row) + { + // No approved post, so the first is a not-approved post (unapproved or soft deleted) + $sql = 'SELECT p.post_id, p.poster_id, p.post_time, p.post_username, u.username, u.user_colour + FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . " u + WHERE p.topic_id = $topic_id + AND p.poster_id = u.user_id + ORDER BY p.post_time ASC"; + $result = $db->sql_query_limit($sql, 1); + $row = $db->sql_fetchrow($result); + $db->sql_freeresult($result); + } + $next_post_id = (int) $row['post_id']; $sql_data[TOPICS_TABLE] = $db->sql_build_array('UPDATE', array( 'topic_poster' => (int) $row['poster_id'], - 'topic_first_post_id' => (int) $row['post_id'] + 'topic_first_post_id' => (int) $row['post_id'], 'topic_first_poster_colour' => $row['user_colour'], 'topic_first_poster_name' => ($row['poster_id'] == ANONYMOUS) ? $row['post_username'] : $row['username'], 'topic_time' => (int) $row['post_time'], @@ -1545,13 +1560,14 @@ function delete_post($forum_id, $topic_id, $post_id, &$data, $is_soft = false, $ case 'delete_last_post': if (!$is_soft) { + // Update last post information when hard deleting. Soft delete already did that by itself. $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[FORUMS_TABLE] = (($sql_data[FORUMS_TABLE]) ? $sql_data[FORUMS_TABLE] . ', ' : '') . implode(', ', $update_sql[$forum_id]); } - $sql_data[TOPICS_TABLE] = ($sql_data[TOPICS_TABLE]) ? $sql_data[TOPICS_TABLE] . ', ' : '') . 'topic_bumped = 0, topic_bumper = 0'; + $sql_data[TOPICS_TABLE] = (($sql_data[TOPICS_TABLE]) ? $sql_data[TOPICS_TABLE] . ', ' : '') . 'topic_bumped = 0, topic_bumper = 0'; $update_sql = update_post_information('topic', $topic_id, true); if (!empty($update_sql)) @@ -1586,11 +1602,11 @@ function delete_post($forum_id, $topic_id, $post_id, &$data, $is_soft = false, $ break; } - if (($post_mode == 'delete') || ($post_mode == 'delete_last_post') || ($post_mode == 'delete_first_post')) + if (($post_mode == 'delete') || ($post_mode == 'delete_last_post') || ($post_mode == 'delete_first_post' && !$is_soft)) { if ($data['post_visibility'] == ITEM_APPROVED) { - phpbb_content_visibility::remove_post_from_postcount($forum_id, $data, $sql_data); + phpbb_content_visibility::remove_post_from_statistic($forum_id, $data, $sql_data); } if (!$is_soft) @@ -1945,7 +1961,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) { - phpbb_content_visibility::hide_topic($data['topic_id'], $data['forum_id'], $topic_row, $sql_data); + phpbb_content_visibility::remove_topic_from_statistic($data['topic_id'], $data['forum_id'], $topic_row, $sql_data); } break; @@ -1956,8 +1972,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_content_visibility::remove_post_from_postcount($forum_id, $current_time, $sql_data); - // ^^ hide_post SQL is identical, except that it does not include the ['stat'] sub-array + //phpbb_content_visibility::remove_post_from_statistic($forum_id, $current_time, $sql_data); + // ^^ remove_post_from_statistic 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'; -- cgit v1.2.1 From 25804eb8e8b17196116e233b2c8ad3b444cfb5ae Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 6 Oct 2012 19:56:52 +0200 Subject: [feature/soft-delete] Add test case for (soft)deleting the only post + fix PHPBB3-9567 --- phpBB/includes/content_visibility.php | 2 +- phpBB/includes/functions_posting.php | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/content_visibility.php b/phpBB/includes/content_visibility.php index 54c580cd40..0d08cb83b6 100644 --- a/phpBB/includes/content_visibility.php +++ b/phpBB/includes/content_visibility.php @@ -416,7 +416,7 @@ class phpbb_content_visibility $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) + // User post update (we do not care about topic or post, since user topics are strictly connected to posts) // But we care about forums where post counts get not increased. ;) if ($post_data['post_postcount']) { diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index d9fbd84ce1..9cf7b59ad3 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -1461,11 +1461,11 @@ function delete_post($forum_id, $topic_id, $post_id, &$data, $is_soft = false, $ } // (Soft) delete the post - if ($is_soft) + if ($is_soft && ($post_mode != 'delete_topic')) { phpbb_content_visibility::set_post_visibility(ITEM_DELETED, $post_id, $topic_id, $forum_id, $user->data['user_id'], time(), $softdelete_reason, ($data['topic_first_post_id'] == $post_id), ($data['topic_last_post_id'] == $post_id)); } - else + else if (!$is_soft) { if (!delete_posts('post_id', array($post_id), false, false)) { @@ -1502,7 +1502,6 @@ function delete_post($forum_id, $topic_id, $post_id, &$data, $is_soft = false, $ { $topic_row = array(); phpbb_content_visibility::set_topic_visibility(ITEM_DELETED, $topic_id, $forum_id, $user->data['user_id'], time(), $softdelete_reason); - phpbb_content_visibility::remove_topic_from_statistic($topic_id, $forum_id, $topic_row, $sql_data); } else { -- cgit v1.2.1 From c525e900d3b96b829c939010db343d8032698011 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 8 Oct 2012 15:01:20 +0200 Subject: [feature/soft-delete] Allow to update multiple posts with set_post_visibility PHPBB3-9567 --- phpBB/includes/content_visibility.php | 15 +++++++++++---- phpBB/includes/functions_posting.php | 2 -- 2 files changed, 11 insertions(+), 6 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/content_visibility.php b/phpBB/includes/content_visibility.php index 0d08cb83b6..868400b5f6 100644 --- a/phpBB/includes/content_visibility.php +++ b/phpBB/includes/content_visibility.php @@ -210,8 +210,8 @@ class phpbb_content_visibility * Change visibility status of one post or a hole topic * * @param $visibility int Element of {ITEM_APPROVED, ITEM_DELETED} - * @param $post_id mixed Post ID to act on, if it is empty, - * all posts of topic_id will be modified + * @param $post_id mixed Post ID or array of post IDs to act on, + * if it is empty, all posts of topic_id will be modified * @param $topic_id int Topic where $post_id is found * @param $forum_id int Forum where $topic_id is found * @param $user_id int User performing the action @@ -234,7 +234,14 @@ class phpbb_content_visibility if ($post_id) { - $where_sql = 'post_id = ' . (int) $post_id; + if (is_array($post_id)) + { + $where_sql = $db->sql_in_set('post_id', array_map('intval', $post_id)); + } + else + { + $where_sql = 'post_id = ' . (int) $post_id; + } } else if ($topic_id) { @@ -382,7 +389,7 @@ class phpbb_content_visibility } /** - * One function to rule them all ... and unhide posts and topics. This could + * 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'} diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index 9cf7b59ad3..2ae4fe2bd8 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -1629,8 +1629,6 @@ function delete_post($forum_id, $topic_id, $post_id, &$data, $is_soft = false, $ } } -// $sql_data[USERS_TABLE] = ($data['post_postcount']) ? 'user_posts = user_posts - 1' : ''; - $db->sql_transaction('begin'); $where_sql = array( -- cgit v1.2.1 From 91398c9e48df7ce0da6763790d9ec233ab06e729 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 8 Oct 2012 15:03:54 +0200 Subject: [feature/soft-delete] Change order of functions PHPBB3-9567 --- phpBB/includes/content_visibility.php | 50 +++++++++++++++++------------------ 1 file changed, 25 insertions(+), 25 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/content_visibility.php b/phpBB/includes/content_visibility.php index 868400b5f6..182df69ec2 100644 --- a/phpBB/includes/content_visibility.php +++ b/phpBB/includes/content_visibility.php @@ -22,6 +22,30 @@ if (!defined('IN_PHPBB')) */ class phpbb_content_visibility { + /** + * Can the current logged-in user soft-delete posts? + * + * @param $forum_id int Forum ID whose permissions to check + * @param $poster_id int Poster ID of the post in question + * @param $post_locked bool Is the post locked? + * @return bool + */ + static 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['user_id'] && !$post_locked) + { + return true; + } + + return false; + } + /** * Create topic/post visibility SQL for a given forum ID * @@ -207,7 +231,7 @@ class phpbb_content_visibility } /** - * Change visibility status of one post or a hole topic + * Change visibility status of one post or all posts of a topic * * @param $visibility int Element of {ITEM_APPROVED, ITEM_DELETED} * @param $post_id mixed Post ID or array of post IDs to act on, @@ -298,30 +322,6 @@ class phpbb_content_visibility } } - /** - * Can the current logged-in user soft-delete posts? - * - * @param $forum_id int Forum ID whose permissions to check - * @param $poster_id int Poster ID of the post in question - * @param $post_locked bool Is the post locked? - * @return bool - */ - static 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['user_id'] && !$post_locked) - { - return true; - } - - return false; - } - /** * Remove topic from forum statistics * -- cgit v1.2.1 From 53e01bba19784b0fb36324c10c010f969f05d253 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 8 Oct 2012 22:47:50 +0200 Subject: [feature/soft-delete] Update post counts within set_post_visibility This is an additional query in some rare cases, but it makes it much easier to use and understand. This is mostly a preparation for the restore case. PHPBB3-9567 --- phpBB/includes/content_visibility.php | 337 ++++++++++++++++++++++++---------- phpBB/includes/functions_posting.php | 22 +-- 2 files changed, 247 insertions(+), 112 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/content_visibility.php b/phpBB/includes/content_visibility.php index 182df69ec2..7761587c53 100644 --- a/phpBB/includes/content_visibility.php +++ b/phpBB/includes/content_visibility.php @@ -155,6 +155,208 @@ class phpbb_content_visibility return $where_sqls[0]; } + /** + * Change visibility status of one post or all posts of a topic + * + * @param $visibility int Element of {ITEM_APPROVED, ITEM_DELETED} + * @param $post_id mixed Post ID or array of post IDs to act on, + * if it is empty, all posts of topic_id will be modified + * @param $topic_id int Topic where $post_id is found + * @param $forum_id int Forum where $topic_id is found + * @param $user_id int User performing the action + * @param $time int Timestamp when the action is performed + * @param $reason string Reason why the visibilty was changed. + * @param $is_starter bool Is this the first post of the topic changed? + * @param $is_latest bool Is this the last post of the topic changed? + * @param $limit_visibility mixed Limit updating per topic_id to a certain visibility + * @param $limit_delete_time mixed Limit updating per topic_id to a certain deletion time + * @return array Changed post data, empty array if an error occured. + */ + static public function set_post_visibility($visibility, $post_id, $topic_id, $forum_id, $user_id, $time, $reason, $is_starter, $is_latest, $limit_visibility = false, $limit_delete_time = false) + { + global $db; + + if (!in_array($visibility, array(ITEM_APPROVED, ITEM_DELETED))) + { + return array(); + } + + if ($post_id) + { + if (is_array($post_id)) + { + $where_sql = $db->sql_in_set('post_id', array_map('intval', $post_id)); + } + else + { + $where_sql = 'post_id = ' . (int) $post_id; + } + $where_sql .= ' AND topic_id = ' . (int) $topic_id; + } + else + { + $where_sql = 'topic_id = ' . (int) $topic_id; + + // Limit the posts to a certain visibility and deletion time + // This allows us to only restore posts, that were approved + // when the topic got soft deleted. So previous soft deleted + // and unapproved posts are still soft deleted/unapproved + if ($limit_visibility !== false) + { + $where_sql .= ' AND post_visibility = ' . (int) $limit_visibility; + } + if ($limit_delete_time !== false) + { + $where_sql .= ' AND post_delete_time = ' . (int) $limit_delete_time; + } + } + + $sql = 'SELECT poster_id, post_id, post_postcount, post_visibility + FROM ' . POSTS_TABLE . ' + WHERE ' . $where_sql; + $result = $db->sql_query($sql); + + $post_ids = $poster_postcounts = $postcounts = $postcount_visibility = array(); + while ($row = $db->sql_fetchrow($result)) + { + $post_ids[] = (int) $row['post_id']; + + if ($row['post_visibility'] != $visibility) + { + if ($row['post_postcount'] && !isset($poster_postcounts[$row['poster_id']])) + { + $poster_postcounts[$row['poster_id']] = 1; + } + else if ($row['post_postcount']) + { + $poster_postcounts[$row['poster_id']]++; + } + + if (!isset($postcount_visibility[$row['post_visibility']])) + { + $postcount_visibility[$row['post_visibility']] = 1; + } + else + { + $postcount_visibility[$row['post_visibility']]++; + } + } + } + $db->sql_freeresult($result); + + if (empty($post_ids)) + { + return array(); + } + + $data = array( + 'post_visibility' => (int) $visibility, + 'post_delete_user' => (int) $user_id, + 'post_delete_time' => ((int) $time) ?: time(), + 'post_delete_reason' => truncate_string($reason, 255, 255, false), + ); + + $sql = 'UPDATE ' . POSTS_TABLE . ' + SET ' . $db->sql_build_array('UPDATE', $data) . ' + WHERE ' . $db->sql_in_set('post_id', $post_ids); + $db->sql_query($sql); + + // Group the authors by post count, to reduce the number of queries + foreach ($poster_postcounts as $poster_id => $num_posts) + { + $postcounts[$num_posts][] = $poster_id; + } + + // Update users postcounts + foreach ($postcounts as $num_posts => $poster_ids) + { + if ($visibility == ITEM_DELETED) + { + $sql = 'UPDATE ' . USERS_TABLE . ' + SET user_posts = 0 + WHERE ' . $db->sql_in_set('user_id', $poster_ids) . ' + AND user_posts < ' . $num_posts; + $db->sql_query($sql); + + $sql = 'UPDATE ' . USERS_TABLE . ' + SET user_posts = user_posts - ' . $num_posts . ' + WHERE ' . $db->sql_in_set('user_id', $poster_ids) . ' + AND user_posts >= ' . $num_posts; + $db->sql_query($sql); + } + else + { + $sql = 'UPDATE ' . USERS_TABLE . ' + SET user_posts = user_posts + ' . $num_posts . ' + WHERE ' . $db->sql_in_set('user_id', $poster_ids) . ' + AND user_posts >= ' . $num_posts; + $db->sql_query($sql); + } + } + + $update_topic_postcount = true; + + // Sync the first/last topic information if needed + if (!$is_starter && $is_latest) + { + // update_post_information can only update the last post info ... + if ($topic_id) + { + update_post_information('topic', $topic_id, false); + } + if ($forum_id) + { + update_post_information('forum', $forum_id, false); + } + } + else if ($is_starter && $topic_id) + { + // ... so we need to use sync, if the first post is changed. + // The forum is resynced recursive by sync() itself. + sync('topic', 'topic_id', $topic_id, true); + + // sync recalculates the topic replies and forum posts by itself, so we don't do that. + $update_topic_postcount = false; + } + + // Update the topic's reply count and the forum's post count + if ($update_topic_postcount) + { + $num_posts = 0; + foreach ($postcount_visibility as $post_visibility => $visibility_posts) + { + // If we soft delete, we need to substract approved posts from the counters ... + if ($post_visibility == ITEM_APPROVED && $visibility == ITEM_DELETED) + { + $num_posts += $visibility_posts; + } + // ... and when we approve/restore, all others. + else if ($post_visibility != ITEM_APPROVED && $visibility == ITEM_APPROVED) + { + $num_posts += $visibility_posts; + } + } + + if ($num_posts) + { + $sql_num_posts = (($visibility == ITEM_DELETED) ? ' - ' : ' + ') . $num_posts; + + // Update the number for replies and posts + $sql = 'UPDATE ' . TOPICS_TABLE . " + SET topic_replies = topic_replies $sql_num_posts + WHERE topic_id = $topic_id"; + $db->sql_query($sql); + + $sql = 'UPDATE ' . FORUMS_TABLE . " + SET forum_posts = forum_posts $sql_num_posts + WHERE forum_id = $forum_id"; + $db->sql_query($sql); + } + } + + return $data; + } + /** * Set topic visibility * @@ -174,7 +376,7 @@ class phpbb_content_visibility * @param $time int Timestamp when the action is performed * @param $reason string Reason why the visibilty was changed. * @param $force_update_all bool Force to update all posts within the topic - * @return void + * @return array Changed topic data, empty array if an error occured. */ static public function set_topic_visibility($visibility, $topic_id, $forum_id, $user_id, $time, $reason, $force_update_all = false) { @@ -182,7 +384,7 @@ class phpbb_content_visibility if (!in_array($visibility, array(ITEM_APPROVED, ITEM_DELETED))) { - return; + return array(); } if (!$force_update_all) @@ -197,7 +399,7 @@ class phpbb_content_visibility if (!$original_topic_data) { // The topic does not exist... - return; + return array(); } } @@ -214,6 +416,11 @@ class phpbb_content_visibility WHERE topic_id = ' . (int) $topic_id; $db->sql_query($sql); + if (!$db->sql_affectedrows()) + { + return array(); + } + if (!$force_update_all && $original_topic_data['topic_delete_time'] && $original_topic_data['topic_visibility'] == ITEM_DELETED && $visibility == ITEM_APPROVED) { // If we're restoring a topic we only restore posts, that were soft deleted through the topic soft deletion. @@ -228,98 +435,50 @@ class phpbb_content_visibility { self::set_post_visibility($visibility, false, $topic_id, $forum_id, $user_id, $time, '', true, true); } + + return $data; } /** - * Change visibility status of one post or all posts of a topic + * Add post to topic and forum statistics * - * @param $visibility int Element of {ITEM_APPROVED, ITEM_DELETED} - * @param $post_id mixed Post ID or array of post IDs to act on, - * if it is empty, all posts of topic_id will be modified - * @param $topic_id int Topic where $post_id is found - * @param $forum_id int Forum where $topic_id is found - * @param $user_id int User performing the action - * @param $time int Timestamp when the action is performed - * @param $reason string Reason why the visibilty was changed. - * @param $is_starter bool Is this the first post of the topic changed? - * @param $is_latest bool Is this the last post of the topic changed? - * @param $limit_visibility mixed Limit updating per topic_id to a certain visibility - * @param $limit_delete_time mixed Limit updating per topic_id to a certain deletion time + * @param $data array Contains information from the topics table about given topic + * @param $sql_data array Populated with the SQL changes, may be empty at call time * @return void */ - static public function set_post_visibility($visibility, $post_id, $topic_id, $forum_id, $user_id, $time, $reason, $is_starter, $is_latest, $limit_visibility = false, $limit_delete_time = false) + static public function add_post_to_statistic($data, &$sql_data) { - global $db; + $sql_data[TOPICS_TABLE] = (($sql_data[TOPICS_TABLE]) ? $sql_data[TOPICS_TABLE] . ', ' : '') . 'topic_replies = topic_replies + 1'; - if (!in_array($visibility, array(ITEM_APPROVED, ITEM_DELETED))) - { - return; - } + $sql_data[FORUMS_TABLE] = (($sql_data[FORUMS_TABLE]) ? $sql_data[FORUMS_TABLE] . ', ' : '') . 'forum_posts = forum_posts + 1'; - if ($post_id) + if ($data['post_postcount']) { - if (is_array($post_id)) - { - $where_sql = $db->sql_in_set('post_id', array_map('intval', $post_id)); - } - else - { - $where_sql = 'post_id = ' . (int) $post_id; - } + $sql_data[USERS_TABLE] = (($sql_data[USERS_TABLE]) ? $sql_data[USERS_TABLE] . ', ' : '') . 'user_posts = user_posts + 1'; } - else if ($topic_id) - { - $where_sql = 'topic_id = ' . (int) $topic_id; - // Limit the posts to a certain visibility and deletion time - // This allows us to only restore posts, that were approved - // when the topic got soft deleted. So previous soft deleted - // and unapproved posts are still soft deleted/unapproved - if ($limit_visibility !== false) - { - $where_sql .= ' AND post_visibility = ' . (int) $limit_visibility; - } - if ($limit_delete_time !== false) - { - $where_sql .= ' AND post_delete_time = ' . (int) $limit_delete_time; - } - } - else - { - return; - } + set_config_count('num_posts', 1, true); + } - $data = array( - 'post_visibility' => (int) $visibility, - 'post_delete_user' => (int) $user_id, - 'post_delete_time' => ((int) $time) ?: time(), - 'post_delete_reason' => truncate_string($reason, 255, 255, false), - ); + /** + * Remove post from topic and forum statistics + * + * @param $data array Contains information from the topics table about given topic + * @param $sql_data array Populated with the SQL changes, may be empty at call time + * @return void + */ + static public function remove_post_from_statistic($data, &$sql_data) + { + $sql_data[TOPICS_TABLE] = (($sql_data[TOPICS_TABLE]) ? $sql_data[TOPICS_TABLE] . ', ' : '') . 'topic_replies = topic_replies - 1'; - $sql = 'UPDATE ' . POSTS_TABLE . ' - SET ' . $db->sql_build_array('UPDATE', $data) . ' - WHERE ' . $where_sql; - $db->sql_query($sql); + $sql_data[FORUMS_TABLE] = (($sql_data[FORUMS_TABLE]) ? $sql_data[FORUMS_TABLE] . ', ' : '') . 'forum_posts = forum_posts - 1'; - // Sync the first/last topic information if needed - if (!$is_starter && $is_latest) - { - // update_post_information can only update the last post info ... - if ($topic_id) - { - update_post_information('topic', $topic_id, false); - } - if ($forum_id) - { - update_post_information('forum', $forum_id, false); - } - } - else if ($is_starter && $topic_id) + if ($data['post_postcount']) { - // ... so we need to use sync, if the first post is changed. - // The forum is resynced recursive by sync() itself. - sync('topic', 'topic_id', $topic_id, true); + $sql_data[USERS_TABLE] = (($sql_data[USERS_TABLE]) ? $sql_data[USERS_TABLE] . ', ' : '') . 'user_posts = user_posts - 1'; } + + set_config_count('num_posts', -1, true); } /** @@ -366,28 +525,6 @@ class phpbb_content_visibility */ } - /** - * Remove post from topic and forum statistics - * - * @param $forum_id int Forum where the topic is found - * @param $data array Contains information from the topics table about given topic - * @param $sql_data array Populated with the SQL changes, may be empty at call time - * @return void - */ - static public function remove_post_from_statistic($forum_id, $data, &$sql_data) - { - $sql_data[TOPICS_TABLE] = (($sql_data[TOPICS_TABLE]) ? $sql_data[TOPICS_TABLE] . ', ' : '') . 'topic_replies = topic_replies - 1'; - - $sql_data[FORUMS_TABLE] = (($sql_data[FORUMS_TABLE]) ? $sql_data[FORUMS_TABLE] . ', ' : '') . 'forum_posts = forum_posts - 1'; - - if ($data['post_postcount']) - { - $sql_data[USERS_TABLE] = (($sql_data[USERS_TABLE]) ? $sql_data[USERS_TABLE] . ', ' : '') . 'user_posts = user_posts - 1'; - } - - set_config_count('num_posts', -1, true); - } - /** * 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 diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index 2ae4fe2bd8..250d20b005 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -1601,21 +1601,19 @@ function delete_post($forum_id, $topic_id, $post_id, &$data, $is_soft = false, $ break; } - if (($post_mode == 'delete') || ($post_mode == 'delete_last_post') || ($post_mode == 'delete_first_post' && !$is_soft)) - { - if ($data['post_visibility'] == ITEM_APPROVED) - { - phpbb_content_visibility::remove_post_from_statistic($forum_id, $data, $sql_data); - } + if (($post_mode == 'delete') || ($post_mode == 'delete_last_post') || ($post_mode == 'delete_first_post')) + { if (!$is_soft) { - $sql_data[TOPICS_TABLE] .= ', topic_replies_real = topic_replies_real - 1'; + if ($data['post_visibility'] == ITEM_APPROVED) + { + phpbb_content_visibility::remove_post_from_statistic($data, $sql_data); + } + + $sql_data[TOPICS_TABLE] = (($sql_data[TOPICS_TABLE]) ? $sql_data[TOPICS_TABLE] . ', ' : '') . 'topic_replies_real = topic_replies_real - 1'; } - } - if (($post_mode == 'delete') || ($post_mode == 'delete_last_post') || ($post_mode == 'delete_first_post')) - { $sql = 'SELECT 1 AS has_attachments FROM ' . ATTACHMENTS_TABLE . ' WHERE topic_id = ' . $topic_id; @@ -1625,7 +1623,7 @@ function delete_post($forum_id, $topic_id, $post_id, &$data, $is_soft = false, $ if (!$has_attachments) { - $sql_data[TOPICS_TABLE] .= ', topic_attachment = 0'; + $sql_data[TOPICS_TABLE] = (($sql_data[TOPICS_TABLE]) ? $sql_data[TOPICS_TABLE] . ', ' : '') . 'topic_attachment = 0'; } } @@ -1969,7 +1967,7 @@ 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_content_visibility::remove_post_from_statistic($forum_id, $current_time, $sql_data); + //phpbb_content_visibility::remove_post_from_statistic($current_time, $sql_data); // ^^ remove_post_from_statistic 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'; -- 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/includes/content_visibility.php | 6 ++++++ phpBB/includes/functions_posting.php | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/content_visibility.php b/phpBB/includes/content_visibility.php index 7761587c53..dcb7f363f8 100644 --- a/phpBB/includes/content_visibility.php +++ b/phpBB/includes/content_visibility.php @@ -311,6 +311,12 @@ class phpbb_content_visibility } else if ($is_starter && $topic_id) { + if (!function_exists('sync')) + { + global $phpEx, $phpbb_root_path; + include($phpbb_root_path . 'includes/functions_admin.' . $phpEx); + } + // ... so we need to use sync, if the first post is changed. // The forum is resynced recursive by sync() itself. sync('topic', 'topic_id', $topic_id, true); diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index 250d20b005..6d74c6b2d7 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -1481,7 +1481,7 @@ function delete_post($forum_id, $topic_id, $post_id, &$data, $is_soft = false, $ $db->sql_transaction('commit'); // Collect the necessary information for updating the tables - $sql_data[FORUMS_TABLE] = ''; + $sql_data[FORUMS_TABLE] = $sql_data[TOPICS_TABLE] = ''; switch ($post_mode) { case 'delete_topic': -- cgit v1.2.1 From 94417742885d066823314f100b1bdbe5b8b76c91 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 9 Oct 2012 11:55:31 +0200 Subject: [feature/soft-delete] Topic visibility is already synced by sync('topic') PHPBB3-9567 --- phpBB/includes/acp/acp_forums.php | 1 - 1 file changed, 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/acp/acp_forums.php b/phpBB/includes/acp/acp_forums.php index 622d84d15e..7f2539ec8d 100644 --- a/phpBB/includes/acp/acp_forums.php +++ b/phpBB/includes/acp/acp_forums.php @@ -314,7 +314,6 @@ class acp_forums $end = $start + $batch_size; // Sync all topics in batch mode... - sync('topic_visibility', 'range', 'topic_id BETWEEN ' . $start . ' AND ' . $end, true, false); sync('topic', 'range', 'topic_id BETWEEN ' . $start . ' AND ' . $end, true, true); if ($end < $row2['max_topic_id']) -- cgit v1.2.1 From 2841ecc44f2c9773fe3eb19134f52bfcf4beb05e Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 9 Oct 2012 12:08:17 +0200 Subject: [feature/soft-delete] Fix display_user_activity() The Logic of $forum_ary was inverted, so if the array is empty, we can skip the queries. We also should not merge passworded forums into the $forum_ary as we removed them from that array right before that. PHPBB3-9567 --- phpBB/includes/functions_display.php | 84 ++++++++++++++++++------------------ 1 file changed, 42 insertions(+), 42 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_display.php b/phpBB/includes/functions_display.php index 5849f5cf4c..10f07bfbf1 100644 --- a/phpBB/includes/functions_display.php +++ b/phpBB/includes/functions_display.php @@ -996,54 +996,54 @@ function display_user_activity(&$userdata) } } - $forum_ary = array_diff($forum_ary, $user->get_passworded_forums());; - - // Obtain active forum - $sql = 'SELECT forum_id, COUNT(post_id) AS num_posts - FROM ' . POSTS_TABLE . ' - WHERE poster_id = ' . $userdata['user_id'] . ' - AND post_postcount = 1 - AND ' . phpbb_content_visibility::get_forums_visibility_sql('post', $forum_ary) . ' - GROUP BY forum_id - ORDER BY num_posts DESC'; - $result = $db->sql_query_limit($sql, 1); - $active_f_row = $db->sql_fetchrow($result); - $db->sql_freeresult($result); + $forum_ary = array_diff($forum_ary, $user->get_passworded_forums()); - if (!empty($active_f_row)) + $active_f_row = $active_t_row = array(); + if (!empty($forum_ary)) { - $sql = 'SELECT forum_name - FROM ' . FORUMS_TABLE . ' - WHERE forum_id = ' . $active_f_row['forum_id']; - $result = $db->sql_query($sql, 3600); - $active_f_row['forum_name'] = (string) $db->sql_fetchfield('forum_name'); + // Obtain active forum + $sql = 'SELECT forum_id, COUNT(post_id) AS num_posts + FROM ' . POSTS_TABLE . ' + WHERE poster_id = ' . $userdata['user_id'] . ' + AND post_postcount = 1 + AND ' . phpbb_content_visibility::get_forums_visibility_sql('post', $forum_ary) . ' + GROUP BY forum_id + ORDER BY num_posts DESC'; + $result = $db->sql_query_limit($sql, 1); + $active_f_row = $db->sql_fetchrow($result); $db->sql_freeresult($result); - } - // Obtain active topic - // We need to exclude passworded forums here so we do not leak the topic title - $forum_ary_topic = array_unique(array_merge($forum_ary, $user->get_passworded_forums())); - $forum_sql_topic = (!empty($forum_ary_topic)) ? 'AND ' . $db->sql_in_set('forum_id', $forum_ary_topic, true) : ''; - - $sql = 'SELECT topic_id, COUNT(post_id) AS num_posts - FROM ' . POSTS_TABLE . ' - WHERE poster_id = ' . $userdata['user_id'] . ' - AND post_postcount = 1 - AND ' . phpbb_content_visibility::get_forums_visibility_sql('post', $forum_ary) . ' - GROUP BY topic_id - ORDER BY num_posts DESC'; - $result = $db->sql_query_limit($sql, 1); - $active_t_row = $db->sql_fetchrow($result); - $db->sql_freeresult($result); + if (!empty($active_f_row)) + { + $sql = 'SELECT forum_name + FROM ' . FORUMS_TABLE . ' + WHERE forum_id = ' . $active_f_row['forum_id']; + $result = $db->sql_query($sql, 3600); + $active_f_row['forum_name'] = (string) $db->sql_fetchfield('forum_name'); + $db->sql_freeresult($result); + } - if (!empty($active_t_row)) - { - $sql = 'SELECT topic_title - FROM ' . TOPICS_TABLE . ' - WHERE topic_id = ' . $active_t_row['topic_id']; - $result = $db->sql_query($sql); - $active_t_row['topic_title'] = (string) $db->sql_fetchfield('topic_title'); + // Obtain active topic + $sql = 'SELECT topic_id, COUNT(post_id) AS num_posts + FROM ' . POSTS_TABLE . ' + WHERE poster_id = ' . $userdata['user_id'] . ' + AND post_postcount = 1 + AND ' . phpbb_content_visibility::get_forums_visibility_sql('post', $forum_ary) . ' + GROUP BY topic_id + ORDER BY num_posts DESC'; + $result = $db->sql_query_limit($sql, 1); + $active_t_row = $db->sql_fetchrow($result); $db->sql_freeresult($result); + + if (!empty($active_t_row)) + { + $sql = 'SELECT topic_title + FROM ' . TOPICS_TABLE . ' + WHERE topic_id = ' . $active_t_row['topic_id']; + $result = $db->sql_query($sql); + $active_t_row['topic_title'] = (string) $db->sql_fetchfield('topic_title'); + $db->sql_freeresult($result); + } } $userdata['active_t_row'] = $active_t_row; -- cgit v1.2.1 From 7cc8b3eef82a70a1aa708614e37fd82482d9d7d2 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 9 Oct 2012 12:23:15 +0200 Subject: [feature/soft-delete] Correctly update user_posts count Before soft delete this was much easier, as an unapproved topic could only have one post, because no one could reply to unapproved topics. Now we need to run multiple queries to correctly reduce the post counts. PHPBB3-9567 --- phpBB/includes/content_visibility.php | 38 ++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/content_visibility.php b/phpBB/includes/content_visibility.php index dcb7f363f8..8854981303 100644 --- a/phpBB/includes/content_visibility.php +++ b/phpBB/includes/content_visibility.php @@ -518,17 +518,37 @@ class phpbb_content_visibility 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 - // - /** - * @todo: this is wrong, it should rely on post_postcount - * also a user might have more than one post in the topic - * - if ($auth->acl_get('f_postcount', $forum_id)) + // Get user post count information + $sql = 'SELECT poster_id, COUNT(post_id) AS num_posts + FROM ' . POSTS_TABLE . ' + WHERE topic_id = ' . $topic_id . ' + AND post_postcount = 1 + AND post_visibility = ' . ITEM_APPROVED . ' + GROUP BY poster_id'; + $result = $db->sql_query($sql); + + $postcounts = array(); + while ($row = $db->sql_fetchrow($result)) + { + $postcounts[(int) $row['num_posts']][] = (int) $row['poster_id']; + } + $db->sql_freeresult($result); + + // Decrement users post count + foreach ($postcounts as $num_posts => $poster_ids) { - $sql_data[USERS_TABLE] = 'user_posts = user_posts - 1'; + $sql = 'UPDATE ' . USERS_TABLE . ' + SET user_posts = 0 + WHERE user_posts < ' . $num_posts . ' + AND ' . $db->sql_in_set('user_id', $poster_ids); + $db->sql_query($sql); + + $sql = 'UPDATE ' . USERS_TABLE . ' + SET user_posts = user_posts - ' . $num_posts . ' + WHERE user_posts >= ' . $num_posts . ' + AND ' . $db->sql_in_set('user_id', $poster_ids); + $db->sql_query($sql); } - */ } /** -- cgit v1.2.1 From 224be5bc4f7ffdf6f22c3da3aff94fb7a3d7571f Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 9 Oct 2012 14:02:42 +0200 Subject: [feature/soft-delete] Fix sync('topic_visibility') The function can not rely on the first post anymore, as that one could be soft deleted but the topic still has approved replies which are still visible. PHPBB3-9567 --- phpBB/includes/functions_admin.php | 73 +++++++++++++++++++++----------------- 1 file changed, 41 insertions(+), 32 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_admin.php b/phpBB/includes/functions_admin.php index 04c99b5e62..0a351aa6e8 100644 --- a/phpBB/includes/functions_admin.php +++ b/phpBB/includes/functions_admin.php @@ -1383,43 +1383,52 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false, case 'topic_visibility': $db->sql_transaction('begin'); - switch ($db->sql_layer) + + $sql = 'SELECT t.topic_id, p.post_visibility + FROM ' . TOPICS_TABLE . ' t, ' . POSTS_TABLE . " p + $where_sql_and p.topic_id = t.topic_id + AND p.post_visibility = " . ITEM_APPROVED; + $result = $db->sql_query($sql); + + $topics_approved = array(); + while ($row = $db->sql_fetchrow($result)) { - case 'mysql4': - case 'mysqli': - $sql = 'UPDATE ' . TOPICS_TABLE . ' t, ' . POSTS_TABLE . " p - SET t.topic_visibility = p.post_visibility - $where_sql_and t.topic_first_post_id = p.post_id"; - $db->sql_query($sql); - break; + $topics_approved[] = (int) $row['topic_id']; + } + $db->sql_freeresult($result); - default: - $sql = 'SELECT t.topic_id, p.post_visibility - FROM ' . TOPICS_TABLE . ' t, ' . POSTS_TABLE . " p - $where_sql_and p.post_id = t.topic_first_post_id - AND p.post_visibility <> t.topic_visibility"; - $result = $db->sql_query($sql); + $sql = 'SELECT t.topic_id, p.post_visibility + FROM ' . TOPICS_TABLE . ' t, ' . POSTS_TABLE . " p + $where_sql_and " . $db->sql_in_set('t.topic_id', $topics_approved, true, true) . ' + AND p.topic_id = t.topic_id + AND p.post_visibility = ' . ITEM_DELETED; + $result = $db->sql_query($sql); - $topic_ids = array(); - while ($row = $db->sql_fetchrow($result)) - { - $topic_ids[$row['topic_id']] = $row['post_visibility']; - } - $db->sql_freeresult($result); + $topics_softdeleted = array(); + while ($row = $db->sql_fetchrow($result)) + { + $topics_softdeleted[] = (int) $row['topic_id']; + } + $db->sql_freeresult($result); - if (!sizeof($topic_ids)) - { - return; - } + $topics_softdeleted = array_diff($topics_softdeleted, $topics_approved); + $topics_not_unapproved = array_merge($topics_softdeleted, $topics_approved); - foreach ($topic_ids as $topic_id => $visibility) - { - $sql = 'UPDATE ' . TOPICS_TABLE . ' - SET topic_visibility = ' . $visibility . ' - WHERE topic_id' . $topic_id; - $db->sql_query($sql); - } - break; + $update_ary = array( + ITEM_UNAPPROVED => (!empty($topics_not_unapproved)) ? $where_sql_and . ' ' . $db->sql_in_set('topic_id', $topics_not_unapproved, true) : '', + ITEM_APPROVED => (!empty($topics_approved)) ? ' WHERE ' . $db->sql_in_set('topic_id', $topics_approved) : '', + ITEM_DELETED => (!empty($topics_softdeleted)) ? ' WHERE ' . $db->sql_in_set('topic_id', $topics_softdeleted) : '', + ); + + foreach ($topic_visiblities as $visibility => $sql_where) + { + if ($sql_where) + { + $sql = 'UPDATE ' . TOPICS_TABLE . ' + SET topic_visibility = ' . $visibility . ' + ' . $sql_where; + $db->sql_query($sql); + } } $db->sql_transaction('commit'); -- cgit v1.2.1 From fbf85b76c15c27e478f24947098d56c8c4bb3435 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 9 Oct 2012 15:38:50 +0200 Subject: [feature/soft-delete] Correctly synchronize the topic_visibility in sync() This also makes sync('topic_visibility') obsolete, but we keep it for now. Also fix a unit test, because ITEM_DELETED overpowers ITEM_UNAPPROVED PHPBB3-9567 --- phpBB/includes/functions_admin.php | 35 +++++++++++------------------------ 1 file changed, 11 insertions(+), 24 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_admin.php b/phpBB/includes/functions_admin.php index 0a351aa6e8..cb84d1cfb1 100644 --- a/phpBB/includes/functions_admin.php +++ b/phpBB/includes/functions_admin.php @@ -1854,7 +1854,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false, break; case 'topic': - $topic_data = $post_ids = $approved_unapproved_ids = $resync_forums = $delete_topics = $delete_posts = $moved_topics = array(); + $topic_data = $post_ids = $resync_forums = $delete_topics = $delete_posts = $moved_topics = array(); $db->sql_transaction('begin'); @@ -1873,6 +1873,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false, $topic_id = (int) $row['topic_id']; $topic_data[$topic_id] = $row; + $topic_data[$topic_id]['visibility'] = ITEM_UNAPPROVED; $topic_data[$topic_id]['replies_real'] = -1; $topic_data[$topic_id]['replies'] = 0; $topic_data[$topic_id]['first_post_id'] = 0; @@ -1898,7 +1899,6 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false, GROUP BY t.topic_id, t.post_visibility"; $result = $db->sql_query($sql); - $topic_firstlast_data = array(); while ($row = $db->sql_fetchrow($result)) { $topic_id = (int) $row['topic_id']; @@ -1921,18 +1921,23 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false, if ($row['post_visibility'] == ITEM_APPROVED) { - $topic_firstlast_data[$topic_id]['visibility'] = ITEM_APPROVED; + $topic_data[$topic_id]['visibility'] = ITEM_APPROVED; $topic_data[$topic_id]['first_post_id'] = $row['first_post_id']; $topic_data[$topic_id]['last_post_id'] = $row['last_post_id']; $topic_data[$topic_id]['replies'] = $row['total_posts'] - 1; } - else if (!isset($topic_firstlast_data[$topic_id]['visibility']) || $topic_firstlast_data[$topic_id]['visibility'] != ITEM_APPROVED) + else if ($topic_data[$topic_id]['visibility'] != ITEM_APPROVED) { // If there is no approved post, we take the min/max of the other visibilities // for the last and first post info, because it is only visible to moderators anyway $topic_data[$topic_id]['first_post_id'] = (!empty($topic_data[$topic_id]['first_post_id'])) ? min($topic_data[$topic_id]['first_post_id'], $row['first_post_id']) : $row['first_post_id']; $topic_data[$topic_id]['last_post_id'] = max($topic_data[$topic_id]['last_post_id'], $row['last_post_id']); - $topic_firstlast_data[$topic_id]['visibility'] = $row['post_visibility']; + + if ($topic_data[$topic_id]['visibility'] == ITEM_UNAPPROVED) + { + // Soft delete status is stronger than unapproved. + $topic_data[$topic_id]['visibility'] = $row['post_visibility']; + } } } } @@ -1987,10 +1992,6 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false, if ($row['post_id'] == $topic_data[$topic_id]['first_post_id']) { - if ($topic_data[$topic_id]['topic_visibility'] != $row['post_visibility']) - { - $approved_unapproved_ids[$topic_id] = $row['post_visibility']; - } $topic_data[$topic_id]['time'] = $row['post_time']; $topic_data[$topic_id]['poster'] = $row['poster_id']; $topic_data[$topic_id]['first_poster_name'] = ($row['poster_id'] == ANONYMOUS) ? $row['post_username'] : $row['username']; @@ -2118,22 +2119,8 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false, unset($sync_shadow_topics, $shadow_topic_data); } - // approved becomes unapproved, and vice-versa - if (sizeof($approved_unapproved_ids)) - { - foreach ($approved_unapproved_ids as $update_topic_id => $status) - { - // @TODO: Consider grouping by $status and only running 3 queries - $sql = 'UPDATE ' . TOPICS_TABLE . ' - SET topic_visibility = ' . $status . ' - WHERE topic_id = ' . $update_topic_id; - $db->sql_query($sql); - } - } - unset($approved_unapproved_ids); - // These are fields that will be synchronised - $fieldnames = array('time', 'replies', 'replies_real', 'poster', 'first_post_id', 'first_poster_name', 'first_poster_colour', 'last_post_id', 'last_post_subject', 'last_post_time', 'last_poster_id', 'last_poster_name', 'last_poster_colour'); + $fieldnames = array('time', 'visibility', 'replies', 'replies_real', 'poster', 'first_post_id', 'first_poster_name', 'first_poster_colour', 'last_post_id', 'last_post_subject', 'last_post_time', 'last_poster_id', 'last_poster_name', 'last_poster_colour'); if ($sync_extra) { -- cgit v1.2.1 From e4c9e55b53923baedfc9318eb589a914a4ffccef Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 9 Oct 2012 22:24:06 +0200 Subject: [feature/soft-delete] Fix several issues within submit_post() - $post_visibility is not boolean, so we need to check for == ITEM_APPROVED - sync() already updates the topic/forum info, so we don't need to do that again - use set_post_visibility() when changing the posts visibility Should be ready for testing. PHPBB3-9567 --- phpBB/includes/functions_posting.php | 291 +++++++++++------------------------ 1 file changed, 91 insertions(+), 200 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index 6d74c6b2d7..b6223b72d4 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -1729,21 +1729,24 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u $data['post_visibility'] = $topic_row['post_visibility']; } - // This variable indicates if the user is able to post or put into the queue - it is used later for all code decisions regarding approval - // The variable name should be $post_approved, because it indicates if the post is approved or not - $post_approval = 1; + // This variable indicates if the user is able to post or put into the queue + $post_visibility = ITEM_APPROVED; // 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'])) { // Post not approved, but in queue - $post_approval = 0; + $post_visibility = ITEM_UNAPPROVED; } - // Mods are able to force approved/unapproved posts. True means the post is approved, false the post is unapproved + // MODs/Extensions are able to force any visibility on posts if (isset($data['force_approved_state'])) { - $post_approval = ($data['force_approved_state']) ? ITEM_APPROVED : ITEM_UNAPPROVED; + $post_visibility = (in_array((int) $data['force_approved_state'], array(ITEM_APPROVED, ITEM_UNAPPROVED, ITEM_DELETED))) ? (int) $data['force_approved_state'] : $post_visibility; + } + if (isset($data['force_visibility'])) + { + $post_visibility = (in_array((int) $data['force_visibility'], array(ITEM_APPROVED, ITEM_UNAPPROVED, ITEM_DELETED))) ? (int) $data['force_visibility'] : $post_visibility; } // Start the transaction here @@ -1760,7 +1763,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u 'icon_id' => $data['icon_id'], 'poster_ip' => $user->ip, 'post_time' => $current_time, - 'post_visibility' => $post_approval, + 'post_visibility' => $post_visibility, 'enable_bbcode' => $data['enable_bbcode'], 'enable_smilies' => $data['enable_smilies'], 'enable_magic_url' => $data['enable_urls'], @@ -1826,7 +1829,8 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u 'forum_id' => $data['forum_id'], 'poster_id' => $data['poster_id'], 'icon_id' => $data['icon_id'], - 'post_visibility' => (!$post_approval) ? 0 : $data['post_visibility'], + // We will change the visibility later + //'post_visibility' => $post_visibility, 'enable_bbcode' => $data['enable_bbcode'], 'enable_smilies' => $data['enable_smilies'], 'enable_magic_url' => $data['enable_urls'], @@ -1847,8 +1851,6 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u break; } - - $post_approved = $sql_data[POSTS_TABLE]['sql']['post_visibility']; $topic_row = array(); // And the topic ladies and gentlemen @@ -1861,7 +1863,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u 'topic_last_view_time' => $current_time, 'forum_id' => $data['forum_id'], 'icon_id' => $data['icon_id'], - 'topic_visibility' => $post_approval, + 'topic_visibility' => $post_visibility, 'topic_title' => $subject, 'topic_first_poster_name' => (!$user->data['is_registered'] && $username) ? $username : (($user->data['user_id'] != ANONYMOUS) ? $user->data['username'] : ''), 'topic_first_poster_colour' => $user->data['user_colour'], @@ -1893,13 +1895,13 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u ); } - $sql_data[USERS_TABLE]['stat'][] = "user_lastpost_time = $current_time" . (($auth->acl_get('f_postcount', $data['forum_id']) && $post_approval) ? ', user_posts = user_posts + 1' : ''); + $sql_data[USERS_TABLE]['stat'][] = "user_lastpost_time = $current_time" . (($auth->acl_get('f_postcount', $data['forum_id']) && $post_visibility == ITEM_APPROVED) ? ', user_posts = user_posts + 1' : ''); - if ($post_approval) + if ($post_visibility == ITEM_APPROVED) { $sql_data[FORUMS_TABLE]['stat'][] = 'forum_posts = forum_posts + 1'; } - $sql_data[FORUMS_TABLE]['stat'][] = 'forum_topics_real = forum_topics_real + 1' . (($post_approval) ? ', forum_topics = forum_topics + 1' : ''); + $sql_data[FORUMS_TABLE]['stat'][] = 'forum_topics_real = forum_topics_real + 1' . (($post_visibility == ITEM_APPROVED) ? ', forum_topics = forum_topics + 1' : ''); break; case 'reply': @@ -1907,12 +1909,12 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u topic_replies_real = topic_replies_real + 1, topic_bumped = 0, topic_bumper = 0' . - (($post_approval) ? ', topic_replies = topic_replies + 1' : '') . + (($post_visibility == ITEM_APPROVED) ? ', topic_replies = topic_replies + 1' : '') . ((!empty($data['attachment_data']) || (isset($data['topic_attachment']) && $data['topic_attachment'])) ? ', topic_attachment = 1' : ''); - $sql_data[USERS_TABLE]['stat'][] = "user_lastpost_time = $current_time" . (($auth->acl_get('f_postcount', $data['forum_id']) && $post_approval) ? ', user_posts = user_posts + 1' : ''); + $sql_data[USERS_TABLE]['stat'][] = "user_lastpost_time = $current_time" . (($auth->acl_get('f_postcount', $data['forum_id']) && $post_visibility == ITEM_APPROVED) ? ', user_posts = user_posts + 1' : ''); - if ($post_approval) + if ($post_visibility == ITEM_APPROVED) { $sql_data[FORUMS_TABLE]['stat'][] = 'forum_posts = forum_posts + 1'; } @@ -1938,7 +1940,6 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u $sql_data[TOPICS_TABLE]['sql'] = array( 'forum_id' => $data['forum_id'], 'icon_id' => $data['icon_id'], - 'topic_visibility' => (!$post_approval) ? 0 : $data['topic_visibility'], 'topic_title' => $subject, 'topic_first_poster_name' => $username, 'topic_type' => $topic_type, @@ -1953,34 +1954,6 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u 'topic_attachment' => (!empty($data['attachment_data'])) ? 1 : (isset($data['topic_attachment']) ? $data['topic_attachment'] : 0), ); - // 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) - { - phpbb_content_visibility::remove_topic_from_statistic($data['topic_id'], $data['forum_id'], $topic_row, $sql_data); - } - - break; - - case 'edit': - case 'edit_last_post': - - // 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_content_visibility::remove_post_from_statistic($current_time, $sql_data); - // ^^ remove_post_from_statistic 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'; - - set_config_count('num_posts', -1, true); - - if ($auth->acl_get('f_postcount', $data['forum_id'])) - { - $sql_data[USERS_TABLE]['stat'][] = 'user_posts = user_posts - 1'; - } - - } - break; } @@ -2013,19 +1986,40 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u $db->sql_query($sql); $data['post_id'] = $db->sql_nextid(); - if ($post_mode == 'post') + if ($post_mode == 'post' || $post_visibility == ITEM_APPROVED) { $sql_data[TOPICS_TABLE]['sql'] = array( - 'topic_first_post_id' => $data['post_id'], 'topic_last_post_id' => $data['post_id'], 'topic_last_post_time' => $current_time, - 'topic_last_poster_id' => (int) $user->data['user_id'], - 'topic_last_poster_name' => (!$user->data['is_registered'] && $username) ? $username : (($user->data['user_id'] != ANONYMOUS) ? $user->data['username'] : ''), + 'topic_last_poster_id' => $sql_data[POSTS_TABLE]['sql']['poster_id'], + 'topic_last_poster_name' => $sql_data[POSTS_TABLE]['sql']['post_username'], 'topic_last_poster_colour' => $user->data['user_colour'], 'topic_last_post_subject' => (string) $subject, ); } + if ($post_mode == 'post') + { + $sql_data[TOPICS_TABLE]['sql']['topic_first_post_id'] = $data['post_id']; + } + + // Update total post count and forum information + if ($post_visibility == ITEM_APPROVED) + { + if ($post_mode == 'post') + { + set_config_count('num_topics', 1, true); + } + set_config_count('num_posts', 1, true); + + $sql_data[FORUMS_TABLE]['stat'][] = 'forum_last_post_id = ' . $data['post_id']; + $sql_data[FORUMS_TABLE]['stat'][] = "forum_last_post_subject = '" . $db->sql_escape($subject) . "'"; + $sql_data[FORUMS_TABLE]['stat'][] = 'forum_last_post_time = ' . $current_time; + $sql_data[FORUMS_TABLE]['stat'][] = 'forum_last_poster_id = ' . (int) $user->data['user_id']; + $sql_data[FORUMS_TABLE]['stat'][] = "forum_last_poster_name = '" . $db->sql_escape((!$user->data['is_registered'] && $username) ? $username : (($user->data['user_id'] != ANONYMOUS) ? $user->data['username'] : '')) . "'"; + $sql_data[FORUMS_TABLE]['stat'][] = "forum_last_poster_colour = '" . $db->sql_escape($user->data['user_colour']) . "'"; + } + unset($sql_data[POSTS_TABLE]['sql']); } @@ -2036,6 +2030,8 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u SET ' . $db->sql_build_array('UPDATE', $sql_data[TOPICS_TABLE]['sql']) . ' WHERE topic_id = ' . $data['topic_id']; $db->sql_query($sql); + + unset($sql_data[TOPICS_TABLE]['sql']); } // Update the posts table @@ -2045,6 +2041,8 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u SET ' . $db->sql_build_array('UPDATE', $sql_data[POSTS_TABLE]['sql']) . ' WHERE post_id = ' . $data['post_id']; $db->sql_query($sql); + + unset($sql_data[POSTS_TABLE]['sql']); } // Update Poll Tables @@ -2190,114 +2188,20 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u } } - // we need to update the last forum information - // only applicable if the topic is approved - if ($post_approved || $data['post_visibility'] != ITEM_APPROVED) + // Fix the post's and topic's visibility and first/last post information, when the post is edited + if (($post_mode != 'post' && $post_mode != 'reply') && $data['post_visibility'] != $post_visibility) { - // the last post makes us update the forum table. This can happen if... - // We make a new topic - // We reply to a topic - // We edit the last post in a topic and this post is the latest in the forum (maybe) - // We edit the only post in the topic - // We edit the first post in the topic and all the other posts are not approved - if (($post_mode == 'post' || $post_mode == 'reply') && $post_approved) - { - $sql_data[FORUMS_TABLE]['stat'][] = 'forum_last_post_id = ' . $data['post_id']; - $sql_data[FORUMS_TABLE]['stat'][] = "forum_last_post_subject = '" . $db->sql_escape($subject) . "'"; - $sql_data[FORUMS_TABLE]['stat'][] = 'forum_last_post_time = ' . $current_time; - $sql_data[FORUMS_TABLE]['stat'][] = 'forum_last_poster_id = ' . (int) $user->data['user_id']; - $sql_data[FORUMS_TABLE]['stat'][] = "forum_last_poster_name = '" . $db->sql_escape((!$user->data['is_registered'] && $username) ? $username : (($user->data['user_id'] != ANONYMOUS) ? $user->data['username'] : '')) . "'"; - $sql_data[FORUMS_TABLE]['stat'][] = "forum_last_poster_colour = '" . $db->sql_escape($user->data['user_colour']) . "'"; - } - else if ($post_mode == 'edit_last_post' || $post_mode == 'edit_topic' || ($post_mode == 'edit_first_post' && !$data['topic_replies'])) - { - // this does not _necessarily_ mean that we must update the info again, - // it just means that we might have to - $sql = 'SELECT forum_last_post_id, forum_last_post_subject - FROM ' . FORUMS_TABLE . ' - WHERE forum_id = ' . (int) $data['forum_id']; - $result = $db->sql_query($sql); - $row = $db->sql_fetchrow($result); - $db->sql_freeresult($result); - - // this post is the latest post in the forum, better update - if ($row['forum_last_post_id'] == $data['post_id']) - { - // If post approved and subject changed, or poster is anonymous, we need to update the forum_last* rows - if ($post_approved && ($row['forum_last_post_subject'] !== $subject || $data['poster_id'] == ANONYMOUS)) - { - // the post's subject changed - if ($row['forum_last_post_subject'] !== $subject) - { - $sql_data[FORUMS_TABLE]['stat'][] = 'forum_last_post_subject = \'' . $db->sql_escape($subject) . '\''; - } + // If the post was not approved, it could also be the starter, + // so we sync the starter after approving/restoring, to ensure that the stats are correct + // Same applies for the last post + $is_starter = ($post_mode == 'edit_first_post' || $data['post_visibility'] != ITEM_APPROVED); + $is_latest = ($post_mode == 'edit_last_post' || $post_mode == 'edit_topic' || $data['post_visibility'] != ITEM_APPROVED); - // Update the user name if poster is anonymous... just in case an admin changed it - if ($data['poster_id'] == ANONYMOUS) - { - $sql_data[FORUMS_TABLE]['stat'][] = "forum_last_poster_name = '" . $db->sql_escape($username) . "'"; - } - } - else if ($data['post_visibility'] !== $post_approved) - { - // we need a fresh change of socks, everything has become invalidated - $sql = 'SELECT MAX(topic_last_post_id) as last_post_id - FROM ' . TOPICS_TABLE . ' - WHERE forum_id = ' . (int) $data['forum_id'] . ' - AND topic_visibility = ' . ITEM_APPROVED; - $result = $db->sql_query($sql); - $row = $db->sql_fetchrow($result); - $db->sql_freeresult($result); - - // any posts left in this forum? - if (!empty($row['last_post_id'])) - { - $sql = 'SELECT p.post_id, p.post_subject, p.post_time, p.poster_id, p.post_username, u.user_id, u.username, u.user_colour - FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . ' u - WHERE p.poster_id = u.user_id - AND p.post_id = ' . (int) $row['last_post_id']; - $result = $db->sql_query($sql); - $row = $db->sql_fetchrow($result); - $db->sql_freeresult($result); - - // salvation, a post is found! jam it into the forums table - $sql_data[FORUMS_TABLE]['stat'][] = 'forum_last_post_id = ' . (int) $row['post_id']; - $sql_data[FORUMS_TABLE]['stat'][] = "forum_last_post_subject = '" . $db->sql_escape($row['post_subject']) . "'"; - $sql_data[FORUMS_TABLE]['stat'][] = 'forum_last_post_time = ' . (int) $row['post_time']; - $sql_data[FORUMS_TABLE]['stat'][] = 'forum_last_poster_id = ' . (int) $row['poster_id']; - $sql_data[FORUMS_TABLE]['stat'][] = "forum_last_poster_name = '" . $db->sql_escape(($row['poster_id'] == ANONYMOUS) ? $row['post_username'] : $row['username']) . "'"; - $sql_data[FORUMS_TABLE]['stat'][] = "forum_last_poster_colour = '" . $db->sql_escape($row['user_colour']) . "'"; - } - else - { - // just our luck, the last topic in the forum has just been turned unapproved... - $sql_data[FORUMS_TABLE]['stat'][] = 'forum_last_post_id = 0'; - $sql_data[FORUMS_TABLE]['stat'][] = "forum_last_post_subject = ''"; - $sql_data[FORUMS_TABLE]['stat'][] = 'forum_last_post_time = 0'; - $sql_data[FORUMS_TABLE]['stat'][] = 'forum_last_poster_id = 0'; - $sql_data[FORUMS_TABLE]['stat'][] = "forum_last_poster_name = ''"; - $sql_data[FORUMS_TABLE]['stat'][] = "forum_last_poster_colour = ''"; - } - } - } - } + phpbb_content_visibility::set_post_visibility($post_visibility, $data['post_id'], $data['topic_id'], $data['forum_id'], $user->data['user_id'], time(), '', $is_starter, $is_latest); } - - // topic sync time! - // simply, we update if it is a reply or the last post is edited - if ($post_approved) + else if ($post_mode == 'edit_last_post' || $post_mode == 'edit_topic' || ($post_mode == 'edit_first_post' && !$data['topic_replies'])) { - // reply requires the whole thing - if ($post_mode == 'reply') - { - $sql_data[TOPICS_TABLE]['stat'][] = 'topic_last_post_id = ' . (int) $data['post_id']; - $sql_data[TOPICS_TABLE]['stat'][] = 'topic_last_poster_id = ' . (int) $user->data['user_id']; - $sql_data[TOPICS_TABLE]['stat'][] = "topic_last_poster_name = '" . $db->sql_escape((!$user->data['is_registered'] && $username) ? $username : (($user->data['user_id'] != ANONYMOUS) ? $user->data['username'] : '')) . "'"; - $sql_data[TOPICS_TABLE]['stat'][] = "topic_last_poster_colour = '" . (($user->data['user_id'] != ANONYMOUS) ? $db->sql_escape($user->data['user_colour']) : '') . "'"; - $sql_data[TOPICS_TABLE]['stat'][] = "topic_last_post_subject = '" . $db->sql_escape($subject) . "'"; - $sql_data[TOPICS_TABLE]['stat'][] = 'topic_last_post_time = ' . (int) $current_time; - } - else if ($post_mode == 'edit_last_post' || $post_mode == 'edit_topic' || ($post_mode == 'edit_first_post' && !$data['topic_replies'])) + if ($post_visibility == ITEM_APPROVED || $data['topic_visibility'] == $post_visibility) { // only the subject can be changed from edit $sql_data[TOPICS_TABLE]['stat'][] = "topic_last_post_subject = '" . $db->sql_escape($subject) . "'"; @@ -2307,57 +2211,44 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u { $sql_data[TOPICS_TABLE]['stat'][] = "topic_last_poster_name = '" . $db->sql_escape($username) . "'"; } - } - } - else if ($data['post_visibility'] != ITEM_APPROVED && ($post_mode == 'edit_last_post' || $post_mode == 'edit_topic' || ($post_mode == 'edit_first_post' && !$data['topic_replies']))) - { - // like having the rug pulled from under us - $sql = 'SELECT MAX(post_id) as last_post_id - FROM ' . POSTS_TABLE . ' - WHERE topic_id = ' . (int) $data['topic_id'] . ' - AND post_visibility = ' . ITEM_APPROVED; - $result = $db->sql_query($sql); - $row = $db->sql_fetchrow($result); - $db->sql_freeresult($result); - - // any posts left in this forum? - if (!empty($row['last_post_id'])) - { - $sql = 'SELECT p.post_id, p.post_subject, p.post_time, p.poster_id, p.post_username, u.user_id, u.username, u.user_colour - FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . ' u - WHERE p.poster_id = u.user_id - AND p.post_id = ' . (int) $row['last_post_id']; - $result = $db->sql_query($sql); - $row = $db->sql_fetchrow($result); - $db->sql_freeresult($result); - // salvation, a post is found! jam it into the topics table - $sql_data[TOPICS_TABLE]['stat'][] = 'topic_last_post_id = ' . (int) $row['post_id']; - $sql_data[TOPICS_TABLE]['stat'][] = "topic_last_post_subject = '" . $db->sql_escape($row['post_subject']) . "'"; - $sql_data[TOPICS_TABLE]['stat'][] = 'topic_last_post_time = ' . (int) $row['post_time']; - $sql_data[TOPICS_TABLE]['stat'][] = 'topic_last_poster_id = ' . (int) $row['poster_id']; - $sql_data[TOPICS_TABLE]['stat'][] = "topic_last_poster_name = '" . $db->sql_escape(($row['poster_id'] == ANONYMOUS) ? $row['post_username'] : $row['username']) . "'"; - $sql_data[TOPICS_TABLE]['stat'][] = "topic_last_poster_colour = '" . $db->sql_escape($row['user_colour']) . "'"; - } - } + if ($post_visibility == ITEM_APPROVED) + { + // this does not _necessarily_ mean that we must update the info again, + // it just means that we might have to + $sql = 'SELECT forum_last_post_id, forum_last_post_subject + FROM ' . FORUMS_TABLE . ' + WHERE forum_id = ' . (int) $data['forum_id']; + $result = $db->sql_query($sql); + $row = $db->sql_fetchrow($result); + $db->sql_freeresult($result); - // Update total post count, do not consider moderated posts/topics - if ($post_approval) - { - if ($post_mode == 'post') - { - set_config_count('num_topics', 1, true); - set_config_count('num_posts', 1, true); - } + // this post is the latest post in the forum, better update + if ($row['forum_last_post_id'] == $data['post_id'] && ($row['forum_last_post_subject'] !== $subject || $data['poster_id'] == ANONYMOUS)) + { + // the post's subject changed + if ($row['forum_last_post_subject'] !== $subject) + { + $sql_data[FORUMS_TABLE]['stat'][] = "forum_last_post_subject = '" . $db->sql_escape($subject) . "'"; + } - if ($post_mode == 'reply') - { - set_config_count('num_posts', 1, true); + // Update the user name if poster is anonymous... just in case a moderator changed it + if ($data['poster_id'] == ANONYMOUS) + { + $sql_data[FORUMS_TABLE]['stat'][] = "forum_last_poster_name = '" . $db->sql_escape($username) . "'"; + } + } + } } } // Update forum stats - $where_sql = array(POSTS_TABLE => 'post_id = ' . $data['post_id'], TOPICS_TABLE => 'topic_id = ' . $data['topic_id'], FORUMS_TABLE => 'forum_id = ' . $data['forum_id'], USERS_TABLE => 'user_id = ' . $poster_id); + $where_sql = array( + POSTS_TABLE => 'post_id = ' . $data['post_id'], + TOPICS_TABLE => 'topic_id = ' . $data['topic_id'], + FORUMS_TABLE => 'forum_id = ' . $data['forum_id'], + USERS_TABLE => 'user_id = ' . $poster_id + ); foreach ($sql_data as $table => $update_ary) { @@ -2469,14 +2360,14 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u } // Send Notifications - if (($mode == 'reply' || $mode == 'quote' || $mode == 'post') && $post_approval) + if (($mode == 'reply' || $mode == 'quote' || $mode == 'post') && $post_visibility == ITEM_APPROVED) { user_notification($mode, $subject, $data['topic_title'], $data['forum_name'], $data['forum_id'], $data['topic_id'], $data['post_id']); } $params = $add_anchor = ''; - if ($post_approval) + if ($post_visibility == ITEM_APPROVED) { $params .= '&t=' . $data['topic_id']; -- cgit v1.2.1 From 18f77020e5c4a33e2b9bb1145342dab7ea55fd32 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 10 Oct 2012 23:10:46 +0200 Subject: [feature/soft-delete] Fix several problems in the forum mcp PHPBB3-9567 --- phpBB/includes/mcp/info/mcp_queue.php | 2 +- phpBB/includes/mcp/mcp_forum.php | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/mcp/info/mcp_queue.php b/phpBB/includes/mcp/info/mcp_queue.php index 31e9cc9af6..43f6c81694 100644 --- a/phpBB/includes/mcp/info/mcp_queue.php +++ b/phpBB/includes/mcp/info/mcp_queue.php @@ -21,7 +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')), + 'deleted_posts' => array('title' => 'MCP_QUEUE_DELETED_POSTS', 'auth' => 'aclf_m_approve', '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_forum.php b/phpBB/includes/mcp/mcp_forum.php index ff079baeb8..02a1ba6dcc 100644 --- a/phpBB/includes/mcp/mcp_forum.php +++ b/phpBB/includes/mcp/mcp_forum.php @@ -154,7 +154,7 @@ function mcp_forum_view($id, $mode, $action, $forum_info) $sql = 'SELECT t.topic_id FROM ' . TOPICS_TABLE . ' t WHERE t.forum_id = ' . $forum_id . ' - ' . phpbb_content_visibility::get_visibility_sql('topic', $forum_id, 't.') . " + AND ' . phpbb_content_visibility::get_visibility_sql('topic', $forum_id, 't.') . " $limit_time_sql ORDER BY t.topic_type DESC, $sort_order_sql"; $result = $db->sql_query_limit($sql, $topics_per_page, $start); @@ -222,8 +222,9 @@ function mcp_forum_view($id, $mode, $action, $forum_info) $topic_unapproved = ($row['topic_visibility'] == ITEM_UNAPPROVED && $auth->acl_get('m_approve', $row['forum_id'])) ? true : false; $posts_unapproved = ($row['topic_visibility'] == ITEM_APPROVED && $row['topic_replies'] < $row['topic_replies_real'] && $auth->acl_get('m_approve', $row['forum_id'])) ? true : false; - $u_mcp_queue = ($topic_unapproved || $posts_unapproved) ? $url . '&i=queue&mode=' . (($topic_unapproved) ? 'approve_details' : 'unapproved_posts') . '&t=' . $row['topic_id'] : ''; $topic_deleted = ($row['topic_visibility'] == ITEM_DELETED) ? true : false; + $u_mcp_queue = ($topic_unapproved || $posts_unapproved) ? $url . '&i=queue&mode=' . (($topic_unapproved) ? 'approve_details' : 'unapproved_posts') . '&t=' . $row['topic_id'] : ''; + $u_mcp_queue = (!$u_mcp_queue && $topic_deleted) ? $url . 'i=queue&mode=deleted_posts&t=' . $topic_id : $u_mcp_queue; $topic_row = array( 'ATTACH_ICON_IMG' => ($auth->acl_get('u_download') && $auth->acl_get('f_download', $row['forum_id']) && $row['topic_attachment']) ? $user->img('icon_topic_attach', $user->lang['TOTAL_ATTACHMENTS']) : '', @@ -233,7 +234,7 @@ function mcp_forum_view($id, $mode, $action, $forum_info) 'TOPIC_ICON_IMG_WIDTH' => (!empty($icons[$row['icon_id']])) ? $icons[$row['icon_id']]['width'] : '', 'TOPIC_ICON_IMG_HEIGHT' => (!empty($icons[$row['icon_id']])) ? $icons[$row['icon_id']]['height'] : '', 'UNAPPROVED_IMG' => ($topic_unapproved || $posts_unapproved) ? $user->img('icon_topic_unapproved', ($topic_unapproved) ? 'TOPIC_UNAPPROVED' : 'POSTS_UNAPPROVED') : '', - 'DELETED_IMG' => ($topic_deleted) ? $user->img(/*TODO*/) : '', + 'DELETED_IMG' => ($topic_deleted) ? $user->img('icon_topic_deleted', 'POSTS_DELETED') : '', 'TOPIC_AUTHOR' => get_username_string('username', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']), 'TOPIC_AUTHOR_COLOUR' => get_username_string('colour', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']), @@ -256,7 +257,7 @@ function mcp_forum_view($id, $mode, $action, $forum_info) 'S_TOPIC_REPORTED' => (!empty($row['topic_reported']) && empty($row['topic_moved_id']) && $auth->acl_get('m_report', $row['forum_id'])) ? true : false, 'S_TOPIC_UNAPPROVED' => $topic_unapproved, 'S_POSTS_UNAPPROVED' => $posts_unapproved, - 'S_TOPIC_DELETED' => $topic_deleted, + 'S_TOPIC_DELETED' => $topic_deleted, 'S_UNREAD_TOPIC' => $unread_topic, ); -- cgit v1.2.1 From 4bf922fa03ae80533c726bd10aeab1f0bad0d179 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 13 Oct 2012 19:00:08 +0200 Subject: [feature/soft-delete] Fix restoring posts via MCP PHPBB3-9567 --- phpBB/includes/mcp/mcp_queue.php | 60 +++++++++++++++++++++++++++++++--------- 1 file changed, 47 insertions(+), 13 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/mcp/mcp_queue.php b/phpBB/includes/mcp/mcp_queue.php index b1b4ea99aa..184959dfb6 100644 --- a/phpBB/includes/mcp/mcp_queue.php +++ b/phpBB/includes/mcp/mcp_queue.php @@ -230,14 +230,7 @@ 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'; - } + $m_perm = 'm_approve'; $user->add_lang(array('viewtopic', 'viewforum')); @@ -472,7 +465,7 @@ function restore_post($post_id_list, $id, $mode) global $db, $template, $user, $config; global $phpEx, $phpbb_root_path, $request; - if (!check_ids($post_id_list, POSTS_TABLE, 'post_id', array('m_restore'))) + if (!check_ids($post_id_list, POSTS_TABLE, 'post_id', array('m_approve'))) { trigger_error('NOT_AUTHORISED'); } @@ -481,9 +474,51 @@ function restore_post($post_id_list, $id, $mode) $redirect = reapply_sid($redirect); $success_msg = ''; - $post_info = get_post_data($post_id_list, 'm_restore'); + $post_info = get_post_data($post_id_list, 'm_approve'); + + $topic_info = 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; + } + } + + foreach ($topic_info as $topic_id => $topic_data) + { + phpbb_content_visibility::set_post_visibility(ITEM_APPROVED, $topic_data['posts'], $topic_id, $topic_data['forum_id'], $user->data['user_id'], time(), '', isset($topic_data['first_post']), isset($topic_data['last_post'])); + } - $success_msg = phpbb_content_visibility::unhide_posts_topics('restore', $post_info, $post_id_list); + $success_msg = ''; + /** + * Currently only works for approving posts + if (sizeof($topic_info) > 1) + { + $success_msg = ((sizeof($post_info) == 1) ? 'TOPIC_APPROVED_SUCCESS' : 'TOPICS_APPROVED_SUCCESS'; + } + else + */ + if (sizeof($post_info) >= 1) + { + $success_msg = (sizeof($post_info) == 1) ? 'POST_APPROVED_SUCCESS' : 'POSTS_APPROVED_SUCCESS'; + } if (!$success_msg) { @@ -491,8 +526,6 @@ function restore_post($post_id_list, $id, $mode) } else { - meta_refresh(3, $redirect); - // If approving one post, also give links back to post... $add_message = ''; if (sizeof($post_id_list) == 1 && !empty($post_url)) @@ -513,6 +546,7 @@ function restore_post($post_id_list, $id, $mode) )); } + meta_refresh(3, $redirect); trigger_error($message); } } -- cgit v1.2.1 From 7c2cc9cfeface2ea4267dca204f56f794e3418af Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 15 Oct 2012 14:02:16 +0200 Subject: [feature/soft-delete] Turn restore_post() into a method and add the docs PHPBB3-9567 --- phpBB/includes/mcp/mcp_queue.php | 153 ++++++++++++++++++++------------------- 1 file changed, 77 insertions(+), 76 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/mcp/mcp_queue.php b/phpBB/includes/mcp/mcp_queue.php index 184959dfb6..31a5e09582 100644 --- a/phpBB/includes/mcp/mcp_queue.php +++ b/phpBB/includes/mcp/mcp_queue.php @@ -62,7 +62,7 @@ class mcp_queue } else if ($action == 'restore') { - restore_post($post_id_list, 'queue', $mode); + $this->restore_posts($post_id_list, 'queue', $mode); } else { @@ -443,7 +443,7 @@ class mcp_queue 'S_FORUM_OPTIONS' => $forum_options, 'S_MCP_ACTION' => build_url(array('t', 'f', 'sd', 'st', 'sk')), 'S_TOPICS' => ($mode == 'unapproved_topics') ? true : false, - 'S_RESTORE' => ($mode == 'deleted_posts') ? 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, @@ -454,103 +454,104 @@ class mcp_queue break; } } -} - - -/** -* Restore Post/Topic -*/ -function restore_post($post_id_list, $id, $mode) -{ - global $db, $template, $user, $config; - global $phpEx, $phpbb_root_path, $request; - if (!check_ids($post_id_list, POSTS_TABLE, 'post_id', array('m_approve'))) + /** + * Restore Posts + * + * @todo: Add some XSS protection, or even a confirm_box() + * + * @param $post_id_list array IDs of the posts to restore + * @param $id mixed Category of the current active module + * @param $mode string Active module + * @return void + */ + function restore_posts($post_id_list, $id, $mode) { - trigger_error('NOT_AUTHORISED'); - } + global $db, $template, $user, $config; + global $phpEx, $phpbb_root_path, $request; - $redirect = request_var('redirect', build_url(array('quickmod'))); - $redirect = reapply_sid($redirect); - $success_msg = ''; + if (!check_ids($post_id_list, POSTS_TABLE, 'post_id', array('m_approve'))) + { + trigger_error('NOT_AUTHORISED'); + } - $post_info = get_post_data($post_id_list, 'm_approve'); + $redirect = request_var('redirect', build_url(array('quickmod'))); + $redirect = reapply_sid($redirect); + $success_msg = ''; - $topic_info = array(); + $post_info = get_post_data($post_id_list, 'm_approve'); - // Group the posts by topic_id - foreach ($post_info as $post_id => $post_data) - { - if ($post_data['post_visibility'] == ITEM_APPROVED) + $topic_info = array(); + + // Group the posts by topic_id + foreach ($post_info as $post_id => $post_data) { - continue; - } - $topic_id = (int) $post_data['topic_id']; + 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']; + $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_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; + } + + $post_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f={$post_data['forum_id']}&t={$post_data['topic_id']}&p={$post_data['post_id']}") . '#p' . $post_data['post_id']; } - if ($post_id == $post_data['topic_last_post_id']) + foreach ($topic_info as $topic_id => $topic_data) { - $topic_info[$topic_id]['last_post'] = true; + phpbb_content_visibility::set_post_visibility(ITEM_APPROVED, $topic_data['posts'], $topic_id, $topic_data['forum_id'], $user->data['user_id'], time(), '', isset($topic_data['first_post']), isset($topic_data['last_post'])); } - } - - foreach ($topic_info as $topic_id => $topic_data) - { - phpbb_content_visibility::set_post_visibility(ITEM_APPROVED, $topic_data['posts'], $topic_id, $topic_data['forum_id'], $user->data['user_id'], time(), '', isset($topic_data['first_post']), isset($topic_data['last_post'])); - } - $success_msg = ''; - /** - * Currently only works for approving posts - if (sizeof($topic_info) > 1) - { - $success_msg = ((sizeof($post_info) == 1) ? 'TOPIC_APPROVED_SUCCESS' : 'TOPICS_APPROVED_SUCCESS'; - } - else - */ - if (sizeof($post_info) >= 1) - { - $success_msg = (sizeof($post_info) == 1) ? 'POST_APPROVED_SUCCESS' : 'POSTS_APPROVED_SUCCESS'; - } - - if (!$success_msg) - { - redirect($redirect); - } - else - { - // If approving one post, also give links back to post... - $add_message = ''; - if (sizeof($post_id_list) == 1 && !empty($post_url)) + $success_msg = ''; + if (sizeof($post_info) >= 1) { - $add_message = '

' . sprintf($user->lang['RETURN_POST'], '', ''); + $success_msg = (sizeof($post_info) == 1) ? 'POST_RESTORED_SUCCESS' : 'POSTS_RESTORED_SUCCESS'; } - $message = $user->lang[$success_msg] . '

' . sprintf($user->lang['RETURN_PAGE'], "", '') . $add_message; - - if ($request->is_ajax()) + if (!$success_msg) { - $json_response = new phpbb_json_response; - $json_response->send(array( - 'MESSAGE_TITLE' => $user->lang['INFORMATION'], - 'MESSAGE_TEXT' => $message, - 'REFRESH_DATA' => null, - 'visible' => true, - )); + redirect($redirect); } + else + { + // If restoring one post, also give links back to post... + $add_message = ''; + if (sizeof($post_id_list) == 1 && !empty($post_url)) + { + $add_message = '

' . sprintf($user->lang['RETURN_POST'], '', ''); + } - meta_refresh(3, $redirect); - trigger_error($message); + $message = $user->lang[$success_msg] . '

' . sprintf($user->lang['RETURN_PAGE'], "", '') . $add_message; + + if ($request->is_ajax()) + { + $json_response = new phpbb_json_response; + $json_response->send(array( + 'MESSAGE_TITLE' => $user->lang['INFORMATION'], + 'MESSAGE_TEXT' => $message, + 'REFRESH_DATA' => null, + 'visible' => true, + )); + } + + meta_refresh(3, $redirect); + trigger_error($message); + } } } + /** * Approve Post/Topic */ -- cgit v1.2.1 From a92927d24cace3b3444cb3502de765c6e8e16fa9 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 15 Oct 2012 15:05:02 +0200 Subject: [feature/soft-delete] Turn other functions into methods as well PHPBB3-9567 --- phpBB/includes/mcp/mcp_queue.php | 637 +++++++++++++++++++-------------------- 1 file changed, 318 insertions(+), 319 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/mcp/mcp_queue.php b/phpBB/includes/mcp/mcp_queue.php index 31a5e09582..99c4a6eccb 100644 --- a/phpBB/includes/mcp/mcp_queue.php +++ b/phpBB/includes/mcp/mcp_queue.php @@ -58,7 +58,7 @@ class mcp_queue if ($action == 'approve') { - approve_post($post_id_list, 'queue', $mode); + $this->approve_posts($post_id_list, 'queue', $mode); } else if ($action == 'restore') { @@ -66,7 +66,7 @@ class mcp_queue } else { - disapprove_post($post_id_list, 'queue', $mode); + $this->disapprove_posts($post_id_list, 'queue', $mode); } break; @@ -549,432 +549,431 @@ class mcp_queue trigger_error($message); } } -} - -/** -* Approve Post/Topic -*/ -function approve_post($post_id_list, $id, $mode) -{ - global $db, $template, $user, $config; - global $phpEx, $phpbb_root_path; - global $request; - - if (!check_ids($post_id_list, POSTS_TABLE, 'post_id', array('m_approve'))) + /** + * Approve Post/Topic + */ + function approve_posts($post_id_list, $id, $mode) { - trigger_error('NOT_AUTHORISED'); - } + global $db, $template, $user, $config; + global $phpEx, $phpbb_root_path; + global $request; + + if (!check_ids($post_id_list, POSTS_TABLE, 'post_id', array('m_approve'))) + { + trigger_error('NOT_AUTHORISED'); + } - $redirect = request_var('redirect', build_url(array('quickmod'))); - $success_msg = ''; + $redirect = request_var('redirect', build_url(array('quickmod'))); + $success_msg = ''; - $s_hidden_fields = build_hidden_fields(array( - 'i' => $id, - 'mode' => $mode, - 'post_id_list' => $post_id_list, - 'action' => 'approve', - 'redirect' => $redirect) - ); + $s_hidden_fields = build_hidden_fields(array( + 'i' => $id, + 'mode' => $mode, + 'post_id_list' => $post_id_list, + 'action' => 'approve', + 'redirect' => $redirect) + ); - $post_info = get_post_data($post_id_list, 'm_approve'); + $post_info = get_post_data($post_id_list, 'm_approve'); - if (confirm_box(true)) - { - $notify_poster = (isset($_REQUEST['notify_poster'])) ? true : false; + if (confirm_box(true)) + { + $notify_poster = (isset($_REQUEST['notify_poster'])) ? true : false; - $success_msg = phpbb_content_visibility::unhide_posts_topics('approve', $post_info, $post_id_list); + $success_msg = phpbb_content_visibility::unhide_posts_topics('approve', $post_info, $post_id_list); - $messenger = new messenger(); + $messenger = new messenger(); - // Notify Poster? - if ($notify_poster) - { - foreach ($post_info as $post_id => $post_data) + // Notify Poster? + if ($notify_poster) { - if ($post_data['poster_id'] == ANONYMOUS) + foreach ($post_info as $post_id => $post_data) { - continue; - } + if ($post_data['poster_id'] == ANONYMOUS) + { + continue; + } - $email_template = ($post_data['post_id'] == $post_data['topic_first_post_id'] && $post_data['post_id'] == $post_data['topic_last_post_id']) ? 'topic_approved' : 'post_approved'; + $email_template = ($post_data['post_id'] == $post_data['topic_first_post_id'] && $post_data['post_id'] == $post_data['topic_last_post_id']) ? 'topic_approved' : 'post_approved'; - $messenger->template($email_template, $post_data['user_lang']); + $messenger->template($email_template, $post_data['user_lang']); - $messenger->to($post_data['user_email'], $post_data['username']); - $messenger->im($post_data['user_jabber'], $post_data['username']); + $messenger->to($post_data['user_email'], $post_data['username']); + $messenger->im($post_data['user_jabber'], $post_data['username']); - $messenger->assign_vars(array( - 'USERNAME' => htmlspecialchars_decode($post_data['username']), - 'POST_SUBJECT' => htmlspecialchars_decode(censor_text($post_data['post_subject'])), - 'TOPIC_TITLE' => htmlspecialchars_decode(censor_text($post_data['topic_title'])), + $messenger->assign_vars(array( + 'USERNAME' => htmlspecialchars_decode($post_data['username']), + 'POST_SUBJECT' => htmlspecialchars_decode(censor_text($post_data['post_subject'])), + 'TOPIC_TITLE' => htmlspecialchars_decode(censor_text($post_data['topic_title'])), - 'U_VIEW_TOPIC' => generate_board_url() . "/viewtopic.$phpEx?f={$post_data['forum_id']}&t={$post_data['topic_id']}&e=0", - 'U_VIEW_POST' => generate_board_url() . "/viewtopic.$phpEx?f={$post_data['forum_id']}&t={$post_data['topic_id']}&p=$post_id&e=$post_id") - ); + 'U_VIEW_TOPIC' => generate_board_url() . "/viewtopic.$phpEx?f={$post_data['forum_id']}&t={$post_data['topic_id']}&e=0", + 'U_VIEW_POST' => generate_board_url() . "/viewtopic.$phpEx?f={$post_data['forum_id']}&t={$post_data['topic_id']}&p=$post_id&e=$post_id") + ); - $messenger->send($post_data['user_notify_type']); + $messenger->send($post_data['user_notify_type']); + } } - } - $messenger->save_queue(); + $messenger->save_queue(); - // Send out normal user notifications - $email_sig = str_replace('
', "\n", "-- \n" . $config['board_email_sig']); + // Send out normal user notifications + $email_sig = str_replace('
', "\n", "-- \n" . $config['board_email_sig']); - foreach ($post_info as $post_id => $post_data) - { - if ($post_id == $post_data['topic_first_post_id'] && $post_id == $post_data['topic_last_post_id']) + foreach ($post_info as $post_id => $post_data) { - // Forum Notifications - user_notification('post', $post_data['topic_title'], $post_data['topic_title'], $post_data['forum_name'], $post_data['forum_id'], $post_data['topic_id'], $post_id); + if ($post_id == $post_data['topic_first_post_id'] && $post_id == $post_data['topic_last_post_id']) + { + // Forum Notifications + user_notification('post', $post_data['topic_title'], $post_data['topic_title'], $post_data['forum_name'], $post_data['forum_id'], $post_data['topic_id'], $post_id); + } + else + { + // Topic Notifications + user_notification('reply', $post_data['post_subject'], $post_data['topic_title'], $post_data['forum_name'], $post_data['forum_id'], $post_data['topic_id'], $post_id); + } } - else + + if (sizeof($post_id_list) == 1) { - // Topic Notifications - user_notification('reply', $post_data['post_subject'], $post_data['topic_title'], $post_data['forum_name'], $post_data['forum_id'], $post_data['topic_id'], $post_id); + $post_data = $post_info[$post_id_list[0]]; + $post_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f={$post_data['forum_id']}&t={$post_data['topic_id']}&p={$post_data['post_id']}") . '#p' . $post_data['post_id']; } + unset($post_info); } - - if (sizeof($post_id_list) == 1) + else { - $post_data = $post_info[$post_id_list[0]]; - $post_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f={$post_data['forum_id']}&t={$post_data['topic_id']}&p={$post_data['post_id']}") . '#p' . $post_data['post_id']; - } - unset($post_info); - } - else - { - $show_notify = false; + $show_notify = false; - if ($config['email_enable'] || $config['jab_enable']) - { - foreach ($post_info as $post_data) + if ($config['email_enable'] || $config['jab_enable']) { - if ($post_data['poster_id'] == ANONYMOUS) + foreach ($post_info as $post_data) { - continue; - } - else - { - $show_notify = true; - break; + if ($post_data['poster_id'] == ANONYMOUS) + { + continue; + } + else + { + $show_notify = true; + break; + } } } - } - $template->assign_vars(array( - 'S_NOTIFY_POSTER' => $show_notify, - 'S_APPROVE' => true) - ); - - confirm_box(false, 'APPROVE_POST' . ((sizeof($post_id_list) == 1) ? '' : 'S'), $s_hidden_fields, 'mcp_approve.html'); - } - - $redirect = request_var('redirect', "index.$phpEx"); - $redirect = reapply_sid($redirect); - - if (!$success_msg) - { - redirect($redirect); - } - else - { - meta_refresh(3, $redirect); + $template->assign_vars(array( + 'S_NOTIFY_POSTER' => $show_notify, + 'S_APPROVE' => true) + ); - // If approving one post, also give links back to post... - $add_message = ''; - if (sizeof($post_id_list) == 1 && !empty($post_url)) - { - $add_message = '

' . sprintf($user->lang['RETURN_POST'], '', ''); + confirm_box(false, 'APPROVE_POST' . ((sizeof($post_id_list) == 1) ? '' : 'S'), $s_hidden_fields, 'mcp_approve.html'); } - $message = $user->lang[$success_msg] . '

' . sprintf($user->lang['RETURN_PAGE'], "", '') . $add_message; + $redirect = request_var('redirect', "index.$phpEx"); + $redirect = reapply_sid($redirect); - if ($request->is_ajax()) + if (!$success_msg) { - $json_response = new phpbb_json_response; - $json_response->send(array( - 'MESSAGE_TITLE' => $user->lang['INFORMATION'], - 'MESSAGE_TEXT' => $message, - 'REFRESH_DATA' => null, - 'visible' => true, - )); + redirect($redirect); } + else + { + meta_refresh(3, $redirect); - trigger_error($message); - } -} + // If approving one post, also give links back to post... + $add_message = ''; + if (sizeof($post_id_list) == 1 && !empty($post_url)) + { + $add_message = '

' . sprintf($user->lang['RETURN_POST'], '', ''); + } -/** -* Disapprove Post/Topic -*/ -function disapprove_post($post_id_list, $id, $mode) -{ - global $db, $template, $user, $config; - global $phpEx, $phpbb_root_path; - global $request; + $message = $user->lang[$success_msg] . '

' . sprintf($user->lang['RETURN_PAGE'], "", '') . $add_message; - if (!check_ids($post_id_list, POSTS_TABLE, 'post_id', array('m_approve'))) - { - trigger_error('NOT_AUTHORISED'); + if ($request->is_ajax()) + { + $json_response = new phpbb_json_response; + $json_response->send(array( + 'MESSAGE_TITLE' => $user->lang['INFORMATION'], + 'MESSAGE_TEXT' => $message, + 'REFRESH_DATA' => null, + 'visible' => true, + )); + } + + trigger_error($message); + } } - $redirect = request_var('redirect', build_url(array('t', 'mode', 'quickmod')) . "&mode=$mode"); - $reason = utf8_normalize_nfc(request_var('reason', '', true)); - $reason_id = request_var('reason_id', 0); - $success_msg = $additional_msg = ''; + /** + * Disapprove Post/Topic + */ + function disapprove_posts($post_id_list, $id, $mode) + { + global $db, $template, $user, $config; + global $phpEx, $phpbb_root_path; + global $request; - $s_hidden_fields = build_hidden_fields(array( - 'i' => $id, - 'mode' => $mode, - 'post_id_list' => $post_id_list, - 'action' => 'disapprove', - 'redirect' => $redirect) - ); + if (!check_ids($post_id_list, POSTS_TABLE, 'post_id', array('m_approve'))) + { + trigger_error('NOT_AUTHORISED'); + } - $notify_poster = (isset($_REQUEST['notify_poster'])) ? true : false; - $disapprove_reason = ''; + $redirect = request_var('redirect', build_url(array('t', 'mode', 'quickmod')) . "&mode=$mode"); + $reason = utf8_normalize_nfc(request_var('reason', '', true)); + $reason_id = request_var('reason_id', 0); + $success_msg = $additional_msg = ''; + + $s_hidden_fields = build_hidden_fields(array( + 'i' => $id, + 'mode' => $mode, + 'post_id_list' => $post_id_list, + 'action' => 'disapprove', + 'redirect' => $redirect) + ); - if ($reason_id) - { - $sql = 'SELECT reason_title, reason_description - FROM ' . REPORTS_REASONS_TABLE . " - WHERE reason_id = $reason_id"; - $result = $db->sql_query($sql); - $row = $db->sql_fetchrow($result); - $db->sql_freeresult($result); - - if (!$row || (!$reason && strtolower($row['reason_title']) == 'other')) - { - $additional_msg = $user->lang['NO_REASON_DISAPPROVAL']; + $notify_poster = (isset($_REQUEST['notify_poster'])) ? true : false; + $disapprove_reason = ''; - $request->overwrite('confirm', null, phpbb_request_interface::POST); - $request->overwrite('confirm_key', null, phpbb_request_interface::POST); - $request->overwrite('confirm_key', null, phpbb_request_interface::REQUEST); - } - else + if ($reason_id) { - // If the reason is defined within the language file, we will use the localized version, else just use the database entry... - $disapprove_reason = (strtolower($row['reason_title']) != 'other') ? ((isset($user->lang['report_reasons']['DESCRIPTION'][strtoupper($row['reason_title'])])) ? $user->lang['report_reasons']['DESCRIPTION'][strtoupper($row['reason_title'])] : $row['reason_description']) : ''; - $disapprove_reason .= ($reason) ? "\n\n" . $reason : ''; - - if (isset($user->lang['report_reasons']['DESCRIPTION'][strtoupper($row['reason_title'])])) + $sql = 'SELECT reason_title, reason_description + FROM ' . REPORTS_REASONS_TABLE . " + WHERE reason_id = $reason_id"; + $result = $db->sql_query($sql); + $row = $db->sql_fetchrow($result); + $db->sql_freeresult($result); + + if (!$row || (!$reason && strtolower($row['reason_title']) == 'other')) { - $disapprove_reason_lang = strtoupper($row['reason_title']); + $additional_msg = $user->lang['NO_REASON_DISAPPROVAL']; + + $request->overwrite('confirm', null, phpbb_request_interface::POST); + $request->overwrite('confirm_key', null, phpbb_request_interface::POST); + $request->overwrite('confirm_key', null, phpbb_request_interface::REQUEST); } + else + { + // If the reason is defined within the language file, we will use the localized version, else just use the database entry... + $disapprove_reason = (strtolower($row['reason_title']) != 'other') ? ((isset($user->lang['report_reasons']['DESCRIPTION'][strtoupper($row['reason_title'])])) ? $user->lang['report_reasons']['DESCRIPTION'][strtoupper($row['reason_title'])] : $row['reason_description']) : ''; + $disapprove_reason .= ($reason) ? "\n\n" . $reason : ''; - $email_disapprove_reason = $disapprove_reason; - } - } + if (isset($user->lang['report_reasons']['DESCRIPTION'][strtoupper($row['reason_title'])])) + { + $disapprove_reason_lang = strtoupper($row['reason_title']); + } - $post_info = get_post_data($post_id_list, 'm_approve'); + $email_disapprove_reason = $disapprove_reason; + } + } - if (confirm_box(true)) - { - $disapprove_log = $disapprove_log_topics = $disapprove_log_posts = array(); - $topic_replies_real = $post_disapprove_list = array(); + $post_info = get_post_data($post_id_list, 'm_approve'); - // Build a list of posts to be unapproved and get the related topics real replies count - foreach ($post_info as $post_id => $post_data) + if (confirm_box(true)) { - $post_disapprove_list[$post_id] = $post_data['topic_id']; - if (!isset($topic_replies_real[$post_data['topic_id']])) + $disapprove_log = $disapprove_log_topics = $disapprove_log_posts = array(); + $topic_replies_real = $post_disapprove_list = array(); + + // Build a list of posts to be unapproved and get the related topics real replies count + foreach ($post_info as $post_id => $post_data) { - $topic_replies_real[$post_data['topic_id']] = $post_data['topic_replies_real']; + $post_disapprove_list[$post_id] = $post_data['topic_id']; + if (!isset($topic_replies_real[$post_data['topic_id']])) + { + $topic_replies_real[$post_data['topic_id']] = $post_data['topic_replies_real']; + } } - } - // Now we build the log array - foreach ($post_disapprove_list as $post_id => $topic_id) - { - // If the count of disapproved posts for the topic is greater - // than topic's real replies count, the whole topic is disapproved/deleted - if (sizeof(array_keys($post_disapprove_list, $topic_id)) > $topic_replies_real[$topic_id]) + // Now we build the log array + foreach ($post_disapprove_list as $post_id => $topic_id) { - // Don't write the log more than once for every topic - if (!isset($disapprove_log_topics[$topic_id])) + // If the count of disapproved posts for the topic is greater + // than topic's real replies count, the whole topic is disapproved/deleted + if (sizeof(array_keys($post_disapprove_list, $topic_id)) > $topic_replies_real[$topic_id]) + { + // Don't write the log more than once for every topic + if (!isset($disapprove_log_topics[$topic_id])) + { + // Build disapproved topics log + $disapprove_log_topics[$topic_id] = array( + 'type' => 'topic', + 'post_subject' => $post_info[$post_id]['topic_title'], + 'forum_id' => $post_info[$post_id]['forum_id'], + 'topic_id' => 0, // useless to log a topic id, as it will be deleted + ); + } + } + else { - // Build disapproved topics log - $disapprove_log_topics[$topic_id] = array( - 'type' => 'topic', - 'post_subject' => $post_info[$post_id]['topic_title'], + // Build disapproved posts log + $disapprove_log_posts[] = array( + 'type' => 'post', + 'post_subject' => $post_info[$post_id]['post_subject'], 'forum_id' => $post_info[$post_id]['forum_id'], - 'topic_id' => 0, // useless to log a topic id, as it will be deleted + 'topic_id' => $post_info[$post_id]['topic_id'], ); - } - } - else - { - // Build disapproved posts log - $disapprove_log_posts[] = array( - 'type' => 'post', - 'post_subject' => $post_info[$post_id]['post_subject'], - 'forum_id' => $post_info[$post_id]['forum_id'], - 'topic_id' => $post_info[$post_id]['topic_id'], - ); + } } - } - // Get disapproved posts/topics counts separately - $num_disapproved_topics = sizeof($disapprove_log_topics); - $num_disapproved_posts = sizeof($disapprove_log_posts); + // Get disapproved posts/topics counts separately + $num_disapproved_topics = sizeof($disapprove_log_topics); + $num_disapproved_posts = sizeof($disapprove_log_posts); - // Build the whole log - $disapprove_log = array_merge($disapprove_log_topics, $disapprove_log_posts); + // Build the whole log + $disapprove_log = array_merge($disapprove_log_topics, $disapprove_log_posts); - // Unset unneeded arrays - unset($post_data, $disapprove_log_topics, $disapprove_log_posts); + // Unset unneeded arrays + unset($post_data, $disapprove_log_topics, $disapprove_log_posts); - // Let's do the job - delete disapproved posts - if (sizeof($post_disapprove_list)) - { - if (!function_exists('delete_posts')) + // Let's do the job - delete disapproved posts + if (sizeof($post_disapprove_list)) { - include_once($phpbb_root_path . 'includes/functions_admin.' . $phpEx); - } + if (!function_exists('delete_posts')) + { + include_once($phpbb_root_path . 'includes/functions_admin.' . $phpEx); + } - // We do not check for permissions here, because the moderator allowed approval/disapproval should be allowed to delete the disapproved posts - // Note: function delete_posts triggers related forums/topics sync, - // so we don't need to call update_post_information later and to adjust real topic replies or forum topics count manually - delete_posts('post_id', array_keys($post_disapprove_list)); + // We do not check for permissions here, because the moderator allowed approval/disapproval should be allowed to delete the disapproved posts + // Note: function delete_posts triggers related forums/topics sync, + // so we don't need to call update_post_information later and to adjust real topic replies or forum topics count manually + delete_posts('post_id', array_keys($post_disapprove_list)); - foreach ($disapprove_log as $log_data) - { - add_log('mod', $log_data['forum_id'], $log_data['topic_id'], ($log_data['type'] == 'topic') ? 'LOG_TOPIC_DISAPPROVED' : 'LOG_POST_DISAPPROVED', $log_data['post_subject'], $disapprove_reason); + foreach ($disapprove_log as $log_data) + { + add_log('mod', $log_data['forum_id'], $log_data['topic_id'], ($log_data['type'] == 'topic') ? 'LOG_TOPIC_DISAPPROVED' : 'LOG_POST_DISAPPROVED', $log_data['post_subject'], $disapprove_reason); + } } - } - - $messenger = new messenger(); - // Notify Poster? - if ($notify_poster) - { - $lang_reasons = array(); + $messenger = new messenger(); - foreach ($post_info as $post_id => $post_data) + // Notify Poster? + if ($notify_poster) { - if ($post_data['poster_id'] == ANONYMOUS) - { - continue; - } + $lang_reasons = array(); - if (isset($disapprove_reason_lang)) + foreach ($post_info as $post_id => $post_data) { - // Okay we need to get the reason from the posters language - if (!isset($lang_reasons[$post_data['user_lang']])) + if ($post_data['poster_id'] == ANONYMOUS) { - // Assign the current users translation as the default, this is not ideal but getting the board default adds another layer of complexity. - $lang_reasons[$post_data['user_lang']] = $user->lang['report_reasons']['DESCRIPTION'][$disapprove_reason_lang]; + continue; + } - // Only load up the language pack if the language is different to the current one - if ($post_data['user_lang'] != $user->lang_name && file_exists($phpbb_root_path . '/language/' . $post_data['user_lang'] . '/mcp.' . $phpEx)) + if (isset($disapprove_reason_lang)) + { + // Okay we need to get the reason from the posters language + if (!isset($lang_reasons[$post_data['user_lang']])) { - // Load up the language pack - $lang = array(); - @include($phpbb_root_path . '/language/' . basename($post_data['user_lang']) . '/mcp.' . $phpEx); + // Assign the current users translation as the default, this is not ideal but getting the board default adds another layer of complexity. + $lang_reasons[$post_data['user_lang']] = $user->lang['report_reasons']['DESCRIPTION'][$disapprove_reason_lang]; - // If we find the reason in this language pack use it - if (isset($lang['report_reasons']['DESCRIPTION'][$disapprove_reason_lang])) + // Only load up the language pack if the language is different to the current one + if ($post_data['user_lang'] != $user->lang_name && file_exists($phpbb_root_path . '/language/' . $post_data['user_lang'] . '/mcp.' . $phpEx)) { - $lang_reasons[$post_data['user_lang']] = $lang['report_reasons']['DESCRIPTION'][$disapprove_reason_lang]; - } + // Load up the language pack + $lang = array(); + @include($phpbb_root_path . '/language/' . basename($post_data['user_lang']) . '/mcp.' . $phpEx); - unset($lang); // Free memory + // If we find the reason in this language pack use it + if (isset($lang['report_reasons']['DESCRIPTION'][$disapprove_reason_lang])) + { + $lang_reasons[$post_data['user_lang']] = $lang['report_reasons']['DESCRIPTION'][$disapprove_reason_lang]; + } + + unset($lang); // Free memory + } } + + $email_disapprove_reason = $lang_reasons[$post_data['user_lang']]; + $email_disapprove_reason .= ($reason) ? "\n\n" . $reason : ''; } - $email_disapprove_reason = $lang_reasons[$post_data['user_lang']]; - $email_disapprove_reason .= ($reason) ? "\n\n" . $reason : ''; - } + $email_template = ($post_data['post_id'] == $post_data['topic_first_post_id'] && $post_data['post_id'] == $post_data['topic_last_post_id']) ? 'topic_disapproved' : 'post_disapproved'; - $email_template = ($post_data['post_id'] == $post_data['topic_first_post_id'] && $post_data['post_id'] == $post_data['topic_last_post_id']) ? 'topic_disapproved' : 'post_disapproved'; + $messenger->template($email_template, $post_data['user_lang']); - $messenger->template($email_template, $post_data['user_lang']); + $messenger->to($post_data['user_email'], $post_data['username']); + $messenger->im($post_data['user_jabber'], $post_data['username']); - $messenger->to($post_data['user_email'], $post_data['username']); - $messenger->im($post_data['user_jabber'], $post_data['username']); + $messenger->assign_vars(array( + 'USERNAME' => htmlspecialchars_decode($post_data['username']), + 'REASON' => htmlspecialchars_decode($email_disapprove_reason), + 'POST_SUBJECT' => htmlspecialchars_decode(censor_text($post_data['post_subject'])), + 'TOPIC_TITLE' => htmlspecialchars_decode(censor_text($post_data['topic_title']))) + ); - $messenger->assign_vars(array( - 'USERNAME' => htmlspecialchars_decode($post_data['username']), - 'REASON' => htmlspecialchars_decode($email_disapprove_reason), - 'POST_SUBJECT' => htmlspecialchars_decode(censor_text($post_data['post_subject'])), - 'TOPIC_TITLE' => htmlspecialchars_decode(censor_text($post_data['topic_title']))) - ); + $messenger->send($post_data['user_notify_type']); + } - $messenger->send($post_data['user_notify_type']); + unset($lang_reasons); } + unset($post_info, $disapprove_reason, $email_disapprove_reason, $disapprove_reason_lang); - unset($lang_reasons); - } - unset($post_info, $disapprove_reason, $email_disapprove_reason, $disapprove_reason_lang); + $messenger->save_queue(); - $messenger->save_queue(); - - if ($num_disapproved_topics) - { - $success_msg = ($num_disapproved_topics == 1) ? 'TOPIC_DISAPPROVED_SUCCESS' : 'TOPICS_DISAPPROVED_SUCCESS'; + if ($num_disapproved_topics) + { + $success_msg = ($num_disapproved_topics == 1) ? 'TOPIC_DISAPPROVED_SUCCESS' : 'TOPICS_DISAPPROVED_SUCCESS'; + } + else + { + $success_msg = ($num_disapproved_posts == 1) ? 'POST_DISAPPROVED_SUCCESS' : 'POSTS_DISAPPROVED_SUCCESS'; + } } else { - $success_msg = ($num_disapproved_posts == 1) ? 'POST_DISAPPROVED_SUCCESS' : 'POSTS_DISAPPROVED_SUCCESS'; - } - } - else - { - include_once($phpbb_root_path . 'includes/functions_display.' . $phpEx); + include_once($phpbb_root_path . 'includes/functions_display.' . $phpEx); - display_reasons($reason_id); + display_reasons($reason_id); - $show_notify = false; + $show_notify = false; - foreach ($post_info as $post_data) - { - if ($post_data['poster_id'] == ANONYMOUS) - { - continue; - } - else + foreach ($post_info as $post_data) { - $show_notify = true; - break; + if ($post_data['poster_id'] == ANONYMOUS) + { + continue; + } + else + { + $show_notify = true; + break; + } } - } - $template->assign_vars(array( - 'S_NOTIFY_POSTER' => $show_notify, - 'S_APPROVE' => false, - 'REASON' => $reason, - 'ADDITIONAL_MSG' => $additional_msg) - ); + $template->assign_vars(array( + 'S_NOTIFY_POSTER' => $show_notify, + 'S_APPROVE' => false, + 'REASON' => $reason, + 'ADDITIONAL_MSG' => $additional_msg) + ); - confirm_box(false, 'DISAPPROVE_POST' . ((sizeof($post_id_list) == 1) ? '' : 'S'), $s_hidden_fields, 'mcp_approve.html'); - } - - $redirect = request_var('redirect', "index.$phpEx"); - $redirect = reapply_sid($redirect); + confirm_box(false, 'DISAPPROVE_POST' . ((sizeof($post_id_list) == 1) ? '' : 'S'), $s_hidden_fields, 'mcp_approve.html'); + } - if (!$success_msg) - { - redirect($redirect); - } - else - { - $message = $user->lang[$success_msg] . '

' . sprintf($user->lang['RETURN_PAGE'], "", ''); + $redirect = request_var('redirect', "index.$phpEx"); + $redirect = reapply_sid($redirect); - if ($request->is_ajax()) + if (!$success_msg) { - $json_response = new phpbb_json_response; - $json_response->send(array( - 'MESSAGE_TITLE' => $user->lang['INFORMATION'], - 'MESSAGE_TEXT' => $message, - 'REFRESH_DATA' => null, - 'visible' => false, - )); + redirect($redirect); } + else + { + $message = $user->lang[$success_msg] . '

' . sprintf($user->lang['RETURN_PAGE'], "", ''); - meta_refresh(3, $redirect); - trigger_error($message); + if ($request->is_ajax()) + { + $json_response = new phpbb_json_response; + $json_response->send(array( + 'MESSAGE_TITLE' => $user->lang['INFORMATION'], + 'MESSAGE_TEXT' => $message, + 'REFRESH_DATA' => null, + 'visible' => false, + )); + } + + meta_refresh(3, $redirect); + trigger_error($message); + } } } -- cgit v1.2.1 From b1ce8a8c13eca920abf3659fcbfec267684071bb Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 15 Oct 2012 15:19:32 +0200 Subject: [feature/soft-delete] Add checkbox to restoring posts like on approve PHPBB3-9567 --- phpBB/includes/mcp/mcp_queue.php | 72 +++++++++++++++++++++++++--------------- 1 file changed, 45 insertions(+), 27 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/mcp/mcp_queue.php b/phpBB/includes/mcp/mcp_queue.php index 99c4a6eccb..a56d4ac898 100644 --- a/phpBB/includes/mcp/mcp_queue.php +++ b/phpBB/includes/mcp/mcp_queue.php @@ -458,8 +458,6 @@ class mcp_queue /** * Restore Posts * - * @todo: Add some XSS protection, or even a confirm_box() - * * @param $post_id_list array IDs of the posts to restore * @param $id mixed Category of the current active module * @param $mode string Active module @@ -476,49 +474,69 @@ class mcp_queue } $redirect = request_var('redirect', build_url(array('quickmod'))); - $redirect = reapply_sid($redirect); $success_msg = ''; - $post_info = get_post_data($post_id_list, 'm_approve'); + $s_hidden_fields = build_hidden_fields(array( + 'i' => $id, + 'mode' => $mode, + 'post_id_list' => $post_id_list, + 'action' => 'approve', + 'redirect' => $redirect) + ); - $topic_info = array(); + $post_info = get_post_data($post_id_list, 'm_approve'); - // Group the posts by topic_id - foreach ($post_info as $post_id => $post_data) + if (confirm_box(true)) { - if ($post_data['post_visibility'] == ITEM_APPROVED) + $topic_info = array(); + + // Group the posts by topic_id + foreach ($post_info as $post_id => $post_data) { - continue; - } - $topic_id = (int) $post_data['topic_id']; + 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']; + $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_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; + } + + $post_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f={$post_data['forum_id']}&t={$post_data['topic_id']}&p={$post_data['post_id']}") . '#p' . $post_data['post_id']; } - if ($post_id == $post_data['topic_last_post_id']) + foreach ($topic_info as $topic_id => $topic_data) { - $topic_info[$topic_id]['last_post'] = true; + phpbb_content_visibility::set_post_visibility(ITEM_APPROVED, $topic_data['posts'], $topic_id, $topic_data['forum_id'], $user->data['user_id'], time(), '', isset($topic_data['first_post']), isset($topic_data['last_post'])); } - $post_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f={$post_data['forum_id']}&t={$post_data['topic_id']}&p={$post_data['post_id']}") . '#p' . $post_data['post_id']; + if (sizeof($post_info) >= 1) + { + $success_msg = (sizeof($post_info) == 1) ? 'POST_RESTORED_SUCCESS' : 'POSTS_RESTORED_SUCCESS'; + } } - - foreach ($topic_info as $topic_id => $topic_data) + else { - phpbb_content_visibility::set_post_visibility(ITEM_APPROVED, $topic_data['posts'], $topic_id, $topic_data['forum_id'], $user->data['user_id'], time(), '', isset($topic_data['first_post']), isset($topic_data['last_post'])); - } + $template->assign_vars(array( + 'S_APPROVE' => true, + )); - $success_msg = ''; - if (sizeof($post_info) >= 1) - { - $success_msg = (sizeof($post_info) == 1) ? 'POST_RESTORED_SUCCESS' : 'POSTS_RESTORED_SUCCESS'; + confirm_box(false, 'RESTORE_POST' . ((sizeof($post_id_list) == 1) ? '' : 'S'), $s_hidden_fields, 'mcp_approve.html'); } + $redirect = request_var('redirect', "index.$phpEx"); + $redirect = reapply_sid($redirect); + if (!$success_msg) { redirect($redirect); -- cgit v1.2.1 From 33073fafbe53cb103e9e00bceb249a0879a2eb9c Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 15 Oct 2012 15:53:32 +0200 Subject: [feature/soft-delete] Add module for soft deleted topics Unapproved/soft deleted posts are posts, that have a different visibility than the topic. All others will be hidden from the posts list and can be managed with the topic modules. PHPBB3-9567 --- phpBB/includes/mcp/info/mcp_queue.php | 1 + phpBB/includes/mcp/mcp_queue.php | 120 +++++++++++++++++++++++++++++----- 2 files changed, 105 insertions(+), 16 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/mcp/info/mcp_queue.php b/phpBB/includes/mcp/info/mcp_queue.php index 43f6c81694..68cac5abd2 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_topics' => array('title' => 'MCP_QUEUE_DELETED_TOPICS', 'auth' => 'aclf_m_approve', 'cat' => array('MCP_QUEUE')), 'deleted_posts' => array('title' => 'MCP_QUEUE_DELETED_POSTS', 'auth' => 'aclf_m_approve', '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 a56d4ac898..d61c5fa5ef 100644 --- a/phpBB/includes/mcp/mcp_queue.php +++ b/phpBB/includes/mcp/mcp_queue.php @@ -229,8 +229,12 @@ class mcp_queue case 'unapproved_topics': case 'unapproved_posts': + case 'deleted_topics': case 'deleted_posts': $m_perm = 'm_approve'; + $is_topics = ($mode == 'unapproved_topics' || $mode == 'deleted_topics') ? true : false; + $is_restore = ($mode == 'deleted_posts' || $mode == 'deleted_topics') ? true : false; + $visibility_const = (!$is_restore) ? ITEM_UNAPPROVED : ITEM_DELETED; $user->add_lang(array('viewtopic', 'viewforum')); @@ -312,11 +316,8 @@ class mcp_queue $forum_names = array(); - if ($mode == 'unapproved_posts' || $mode == 'deleted_posts') + if (!$is_topics) { - $visibility_const = ($mode == 'unapproved_posts') ? ITEM_UNAPPROVED : ITEM_DELETED; - $starter_sql = ($mode == 'unapproved_posts') ? 'AND t.topic_first_post_id <> p.post_id' : ''; - $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) . ' @@ -324,7 +325,7 @@ class mcp_queue ' . (($sort_order_sql[0] == 'u') ? 'AND u.user_id = p.poster_id' : '') . ' ' . (($topic_id) ? 'AND p.topic_id = ' . $topic_id : '') . " AND t.topic_id = p.topic_id - $starter_sql + AND t.topic_visibility <> p.post_visibility $limit_time_sql ORDER BY $sort_order_sql"; $result = $db->sql_query_limit($sql, $config['topics_per_page'], $start); @@ -370,9 +371,9 @@ class mcp_queue else { $sql = 'SELECT t.forum_id, t.topic_id, t.topic_title, t.topic_title AS post_subject, t.topic_time AS post_time, t.topic_poster AS poster_id, t.topic_first_post_id AS post_id, t.topic_attachment AS post_attachment, t.topic_first_poster_name AS username, t.topic_first_poster_colour AS user_colour - FROM ' . TOPICS_TABLE . " t - WHERE " . $db->sql_in_set('forum_id', $forum_list) . " - AND topic_visibility = " . ITEM_UNAPPROVED . " + FROM ' . TOPICS_TABLE . ' t + WHERE ' . $db->sql_in_set('forum_id', $forum_list) . ' + AND topic_visibility = ' . $visibility_const . " $limit_time_sql ORDER BY $sort_order_sql"; $result = $db->sql_query_limit($sql, $config['topics_per_page'], $start); @@ -432,22 +433,22 @@ class mcp_queue $base_url = $this->u_action . "&f=$forum_id&st=$sort_days&sk=$sort_key&sd=$sort_dir"; phpbb_generate_template_pagination($template, $base_url, 'pagination', 'start', $total, $config['topics_per_page'], $start); - + // Now display the page $template->assign_vars(array( - 'L_DISPLAY_ITEMS' => ($mode == 'unapproved_posts') ? $user->lang['DISPLAY_POSTS'] : $user->lang['DISPLAY_TOPICS'], + 'L_DISPLAY_ITEMS' => (!$is_topics) ? $user->lang['DISPLAY_POSTS'] : $user->lang['DISPLAY_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_topics') ? true : false, - 'S_RESTORE' => ($mode == 'deleted_posts') ? true : false, + 'S_TOPICS' => $is_topics, + 'S_RESTORE' => $is_restore, 'PAGE_NUMBER' => phpbb_on_page($template, $user, $base_url, $total, $config['topics_per_page'], $start), 'TOPIC_ID' => $topic_id, - 'TOTAL' => $user->lang((($mode == 'unapproved_posts') ? 'VIEW_TOPIC_POSTS' : 'VIEW_FORUM_TOPICS'), (int) $total), + 'TOTAL' => $user->lang(((!$is_topics) ? 'VIEW_TOPIC_POSTS' : 'VIEW_FORUM_TOPICS'), (int) $total), )); $this->tpl_name = 'mcp_queue'; @@ -480,9 +481,9 @@ class mcp_queue 'i' => $id, 'mode' => $mode, 'post_id_list' => $post_id_list, - 'action' => 'approve', - 'redirect' => $redirect) - ); + 'action' => 'restore', + 'redirect' => $redirect, + )); $post_info = get_post_data($post_id_list, 'm_approve'); @@ -568,6 +569,93 @@ class mcp_queue } } + /** + * Restore topics + * + * @param $topic_id_list array IDs of the topics to restore + * @param $id mixed Category of the current active module + * @param $mode string Active module + * @return void + */ + function restore_topics($topic_id_list, $id, $mode) + { + global $db, $template, $user, $config; + global $phpEx, $phpbb_root_path, $request; + + if (!check_ids($topic_id_list, TOPICS_TABLE, 'topic_id', array('m_approve'))) + { + trigger_error('NOT_AUTHORISED'); + } + + $redirect = request_var('redirect', build_url(array('quickmod'))); + $success_msg = ''; + + $s_hidden_fields = build_hidden_fields(array( + 'i' => $id, + 'mode' => $mode, + 'topic_id_list' => $topic_id_list, + 'action' => 'restore', + 'redirect' => $redirect, + )); + + $topic_info = get_topic_data($topic_id_list, 'm_approve'); + + if (confirm_box(true)) + { + foreach ($topic_info as $topic_id => $topic_data) + { + phpbb_content_visibility::set_post_visibility(ITEM_APPROVED, $topic_id, $topic_data['forum_id'], $user->data['user_id'], time(), ''); + $topic_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f={$topic_data['forum_id']}&t={$topic_id}"); + } + + if (sizeof($topic_info) >= 1) + { + $success_msg = 'TOPIC' . ((sizeof($topic_info) == 1) ? '' : 'S') . '_RESTORED_SUCCESS'; + } + } + else + { + $template->assign_vars(array( + 'S_APPROVE' => true, + )); + + confirm_box(false, 'RESTORE_TOPIC' . ((sizeof($topic_info) == 1) ? '' : 'S'), $s_hidden_fields, 'mcp_approve.html'); + } + + $redirect = request_var('redirect', "index.$phpEx"); + $redirect = reapply_sid($redirect); + + if (!$success_msg) + { + redirect($redirect); + } + else + { + // If restoring one topic, also give links back to topic... + $add_message = ''; + if (sizeof($topic_info) == 1 && !empty($topic_url)) + { + $add_message = '

' . sprintf($user->lang['RETURN_TOPIC'], '', ''); + } + + $message = $user->lang[$success_msg] . '

' . sprintf($user->lang['RETURN_PAGE'], "", '') . $add_message; + + if ($request->is_ajax()) + { + $json_response = new phpbb_json_response; + $json_response->send(array( + 'MESSAGE_TITLE' => $user->lang['INFORMATION'], + 'MESSAGE_TEXT' => $message, + 'REFRESH_DATA' => null, + 'visible' => true, + )); + } + + meta_refresh(3, $redirect); + trigger_error($message); + } + } + /** * Approve Post/Topic */ -- cgit v1.2.1 From 51d54109e0ad159a521be57192b6547bebc02fe3 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 16 Oct 2012 13:55:22 +0200 Subject: [feature/soft-delete] Merge approving and restoring posts into one function PHPBB3-9567 --- phpBB/includes/mcp/mcp_queue.php | 189 +++++++++++++++++++++++++-------------- 1 file changed, 124 insertions(+), 65 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/mcp/mcp_queue.php b/phpBB/includes/mcp/mcp_queue.php index d61c5fa5ef..26e6ad574f 100644 --- a/phpBB/includes/mcp/mcp_queue.php +++ b/phpBB/includes/mcp/mcp_queue.php @@ -50,23 +50,33 @@ class mcp_queue include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx); $post_id_list = request_var('post_id_list', array(0)); + $topic_id_list = request_var('topic_id_list', array(0)); - if (!sizeof($post_id_list)) + if (!empty($post_id_list)) { - trigger_error('NO_POST_SELECTED'); - } - - if ($action == 'approve') - { - $this->approve_posts($post_id_list, 'queue', $mode); + if ($action != 'disapprove') + { + $this->approve_posts($action, $post_id_list, 'queue', $mode); + } + else + { + $this->disapprove_posts($post_id_list, 'queue', $mode); + } } - else if ($action == 'restore') + else if (!empty($topic_id_list)) { - $this->restore_posts($post_id_list, 'queue', $mode); + if ($action != 'disapprove') + { + $this->approve_topics($action, $post_id_list, 'queue', $mode); + } + else + { + $this->disapprove_posts($post_id_list, 'queue', $mode); + } } else { - $this->disapprove_posts($post_id_list, 'queue', $mode); + trigger_error('NO_POST_SELECTED'); } break; @@ -657,13 +667,18 @@ class mcp_queue } /** - * Approve Post/Topic + * Approve/Restore posts + * + * @param $action string Action we perform on the posts ('approve' or 'restore') + * @param $post_id_list array IDs of the posts to restore + * @param $id mixed Category of the current active module + * @param $mode string Active module + * @return void */ - function approve_posts($post_id_list, $id, $mode) + function approve_posts($action, $post_id_list, $id, $mode) { global $db, $template, $user, $config; - global $phpEx, $phpbb_root_path; - global $request; + global $phpEx, $phpbb_root_path, $request; if (!check_ids($post_id_list, POSTS_TABLE, 'post_id', array('m_approve'))) { @@ -671,87 +686,131 @@ class mcp_queue } $redirect = request_var('redirect', build_url(array('quickmod'))); - $success_msg = ''; + $success_msg = $post_url = ''; + $approve_log = array(); $s_hidden_fields = build_hidden_fields(array( 'i' => $id, 'mode' => $mode, 'post_id_list' => $post_id_list, - 'action' => 'approve', - 'redirect' => $redirect) - ); + 'action' => $action, + 'redirect' => $redirect, + )); $post_info = get_post_data($post_id_list, 'm_approve'); if (confirm_box(true)) { - $notify_poster = (isset($_REQUEST['notify_poster'])) ? true : false; - - $success_msg = phpbb_content_visibility::unhide_posts_topics('approve', $post_info, $post_id_list); + $notify_poster = ($action == 'approve' && isset($_REQUEST['notify_poster'])) ? true : false; - $messenger = new messenger(); + $topic_info = array(); - // Notify Poster? - if ($notify_poster) + // Group the posts by topic_id + foreach ($post_info as $post_id => $post_data) { - foreach ($post_info as $post_id => $post_data) + if ($post_data['post_visibility'] == ITEM_APPROVED) { - if ($post_data['poster_id'] == ANONYMOUS) - { - continue; - } + continue; + } + $topic_id = (int) $post_data['topic_id']; - $email_template = ($post_data['post_id'] == $post_data['topic_first_post_id'] && $post_data['post_id'] == $post_data['topic_last_post_id']) ? 'topic_approved' : 'post_approved'; + $topic_info[$topic_id]['posts'][] = (int) $post_id; + $topic_info[$topic_id]['forum_id'] = (int) $post_data['forum_id']; - $messenger->template($email_template, $post_data['user_lang']); + if ($post_id == $post_data['topic_first_post_id']) + { + $topic_info[$topic_id]['first_post'] = true; + } - $messenger->to($post_data['user_email'], $post_data['username']); - $messenger->im($post_data['user_jabber'], $post_data['username']); + if ($post_id == $post_data['topic_last_post_id']) + { + $topic_info[$topic_id]['last_post'] = true; + } - $messenger->assign_vars(array( - 'USERNAME' => htmlspecialchars_decode($post_data['username']), - 'POST_SUBJECT' => htmlspecialchars_decode(censor_text($post_data['post_subject'])), - 'TOPIC_TITLE' => htmlspecialchars_decode(censor_text($post_data['topic_title'])), + $post_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f={$post_data['forum_id']}&t={$post_data['topic_id']}&p={$post_data['post_id']}") . '#p' . $post_data['post_id']; - 'U_VIEW_TOPIC' => generate_board_url() . "/viewtopic.$phpEx?f={$post_data['forum_id']}&t={$post_data['topic_id']}&e=0", - 'U_VIEW_POST' => generate_board_url() . "/viewtopic.$phpEx?f={$post_data['forum_id']}&t={$post_data['topic_id']}&p=$post_id&e=$post_id") - ); + $approve_log[] = array( + 'forum_id' => $post_data['forum_id'], + 'topic_id' => $post_data['topic_id'], + 'post_subject' => $post_data['post_subject'], + ); + } - $messenger->send($post_data['user_notify_type']); - } + foreach ($topic_info as $topic_id => $topic_data) + { + phpbb_content_visibility::set_post_visibility(ITEM_APPROVED, $topic_data['posts'], $topic_id, $topic_data['forum_id'], $user->data['user_id'], time(), '', isset($topic_data['first_post']), isset($topic_data['last_post'])); } - $messenger->save_queue(); + if (sizeof($post_info) >= 1) + { + $success_msg = (sizeof($post_info) == 1) ? 'POST_' . strtoupper($action) . 'D_SUCCESS' : 'POSTS_' . strtoupper($action) . 'D_SUCCESS'; + } - // Send out normal user notifications - $email_sig = str_replace('
', "\n", "-- \n" . $config['board_email_sig']); + foreach ($approve_log as $log_data) + { + add_log('mod', $log_data['forum_id'], $log_data['topic_id'], 'LOG_POST_' . strtoupper($action) . 'D', $log_data['post_subject']); + } - foreach ($post_info as $post_id => $post_data) + // Only send out the mails, when the posts are being approved + if ($action == 'approve') { - if ($post_id == $post_data['topic_first_post_id'] && $post_id == $post_data['topic_last_post_id']) + $messenger = new messenger(); + + // Notify Poster? + if ($notify_poster) { - // Forum Notifications - user_notification('post', $post_data['topic_title'], $post_data['topic_title'], $post_data['forum_name'], $post_data['forum_id'], $post_data['topic_id'], $post_id); + foreach ($post_info as $post_id => $post_data) + { + if ($post_data['poster_id'] == ANONYMOUS) + { + continue; + } + + $email_template = ($post_data['post_id'] == $post_data['topic_first_post_id'] && $post_data['post_id'] == $post_data['topic_last_post_id']) ? 'topic_approved' : 'post_approved'; + + $messenger->template($email_template, $post_data['user_lang']); + + $messenger->to($post_data['user_email'], $post_data['username']); + $messenger->im($post_data['user_jabber'], $post_data['username']); + + $messenger->assign_vars(array( + 'USERNAME' => htmlspecialchars_decode($post_data['username']), + 'POST_SUBJECT' => htmlspecialchars_decode(censor_text($post_data['post_subject'])), + 'TOPIC_TITLE' => htmlspecialchars_decode(censor_text($post_data['topic_title'])), + + 'U_VIEW_TOPIC' => generate_board_url() . "/viewtopic.$phpEx?f={$post_data['forum_id']}&t={$post_data['topic_id']}&e=0", + 'U_VIEW_POST' => generate_board_url() . "/viewtopic.$phpEx?f={$post_data['forum_id']}&t={$post_data['topic_id']}&p=$post_id&e=$post_id") + ); + + $messenger->send($post_data['user_notify_type']); + } } - else + + $messenger->save_queue(); + + // Send out normal user notifications + $email_sig = str_replace('
', "\n", "-- \n" . $config['board_email_sig']); + + foreach ($post_info as $post_id => $post_data) { - // Topic Notifications - user_notification('reply', $post_data['post_subject'], $post_data['topic_title'], $post_data['forum_name'], $post_data['forum_id'], $post_data['topic_id'], $post_id); + if ($post_id == $post_data['topic_first_post_id'] && $post_id == $post_data['topic_last_post_id']) + { + // Forum Notifications + user_notification('post', $post_data['topic_title'], $post_data['topic_title'], $post_data['forum_name'], $post_data['forum_id'], $post_data['topic_id'], $post_id); + } + else + { + // Topic Notifications + user_notification('reply', $post_data['post_subject'], $post_data['topic_title'], $post_data['forum_name'], $post_data['forum_id'], $post_data['topic_id'], $post_id); + } } } - - if (sizeof($post_id_list) == 1) - { - $post_data = $post_info[$post_id_list[0]]; - $post_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f={$post_data['forum_id']}&t={$post_data['topic_id']}&p={$post_data['post_id']}") . '#p' . $post_data['post_id']; - } - unset($post_info); } else { $show_notify = false; - if ($config['email_enable'] || $config['jab_enable']) + if ($action == 'approve' && ($config['email_enable'] || $config['jab_enable'])) { foreach ($post_info as $post_data) { @@ -768,11 +827,11 @@ class mcp_queue } $template->assign_vars(array( - 'S_NOTIFY_POSTER' => $show_notify, - 'S_APPROVE' => true) - ); + 'S_NOTIFY_POSTER' => $show_notify, + 'S_' . strtoupper($action) => true, + )); - confirm_box(false, 'APPROVE_POST' . ((sizeof($post_id_list) == 1) ? '' : 'S'), $s_hidden_fields, 'mcp_approve.html'); + confirm_box(false, strtoupper($action) . '_POST' . ((sizeof($post_id_list) == 1) ? '' : 'S'), $s_hidden_fields, 'mcp_approve.html'); } $redirect = request_var('redirect', "index.$phpEx"); @@ -788,7 +847,7 @@ class mcp_queue // If approving one post, also give links back to post... $add_message = ''; - if (sizeof($post_id_list) == 1 && !empty($post_url)) + if (sizeof($post_info) == 1 && $post_url) { $add_message = '

' . sprintf($user->lang['RETURN_POST'], '', ''); } -- cgit v1.2.1 From 722835a4baad13e6886ffd724f92ffaf61990b90 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 16 Oct 2012 14:18:56 +0200 Subject: [feature/soft-delete] Merge approving and restoring topics into one function PHPBB3-9567 --- phpBB/includes/mcp/mcp_queue.php | 187 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 173 insertions(+), 14 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/mcp/mcp_queue.php b/phpBB/includes/mcp/mcp_queue.php index 26e6ad574f..f4a78525c8 100644 --- a/phpBB/includes/mcp/mcp_queue.php +++ b/phpBB/includes/mcp/mcp_queue.php @@ -670,7 +670,7 @@ class mcp_queue * Approve/Restore posts * * @param $action string Action we perform on the posts ('approve' or 'restore') - * @param $post_id_list array IDs of the posts to restore + * @param $post_id_list array IDs of the posts to approve/restore * @param $id mixed Category of the current active module * @param $mode string Active module * @return void @@ -766,9 +766,7 @@ class mcp_queue continue; } - $email_template = ($post_data['post_id'] == $post_data['topic_first_post_id'] && $post_data['post_id'] == $post_data['topic_last_post_id']) ? 'topic_approved' : 'post_approved'; - - $messenger->template($email_template, $post_data['user_lang']); + $messenger->template('post_approved', $post_data['user_lang']); $messenger->to($post_data['user_email'], $post_data['username']); $messenger->im($post_data['user_jabber'], $post_data['username']); @@ -793,16 +791,8 @@ class mcp_queue foreach ($post_info as $post_id => $post_data) { - if ($post_id == $post_data['topic_first_post_id'] && $post_id == $post_data['topic_last_post_id']) - { - // Forum Notifications - user_notification('post', $post_data['topic_title'], $post_data['topic_title'], $post_data['forum_name'], $post_data['forum_id'], $post_data['topic_id'], $post_id); - } - else - { - // Topic Notifications - user_notification('reply', $post_data['post_subject'], $post_data['topic_title'], $post_data['forum_name'], $post_data['forum_id'], $post_data['topic_id'], $post_id); - } + // Topic Notifications + user_notification('reply', $post_data['post_subject'], $post_data['topic_title'], $post_data['forum_name'], $post_data['forum_id'], $post_data['topic_id'], $post_id); } } } @@ -869,6 +859,175 @@ class mcp_queue } } + /** + * Approve/Restore topics + * + * @param $action string Action we perform on the posts ('approve' or 'restore') + * @param $topic_id_list array IDs of the topics to approve/restore + * @param $id mixed Category of the current active module + * @param $mode string Active module + * @return void + */ + function approve_topics($action, $topic_id_list, $id, $mode) + { + global $db, $template, $user, $config; + global $phpEx, $phpbb_root_path, $request; + + if (!check_ids($topic_id_list, TOPICS_TABLE, 'topic_id', array('m_approve'))) + { + trigger_error('NOT_AUTHORISED'); + } + + $redirect = request_var('redirect', build_url(array('quickmod'))); + $success_msg = $topic_url = ''; + $approve_log = array(); + + $s_hidden_fields = build_hidden_fields(array( + 'i' => $id, + 'mode' => $mode, + 'topic_id_list' => $topic_id_list, + 'action' => $action, + 'redirect' => $redirect, + )); + + $topic_info = get_topic_data($topic_id_list, 'm_approve'); + + if (confirm_box(true)) + { + $notify_poster = ($action == 'approve' && isset($_REQUEST['notify_poster'])) ? true : false; + + foreach ($topic_info as $topic_id => $topic_data) + { + phpbb_content_visibility::set_post_visibility(ITEM_APPROVED, $topic_id, $topic_data['forum_id'], $user->data['user_id'], time(), ''); + + $topic_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f={$topic_data['forum_id']}&t={$topic_id}"); + + $approve_log[] = array( + 'forum_id' => $topic_data['forum_id'], + 'topic_id' => $topic_data['topic_id'], + 'topic_title' => $topic_data['topic_title'], + ); + } + + foreach ($topic_info as $topic_id => $topic_data) + { + phpbb_content_visibility::set_topic_visibility(ITEM_APPROVED, $topic_id, $topic_data['forum_id'], $user->data['user_id'], time(), ''); + } + + if (sizeof($topic_info) >= 1) + { + $success_msg = (sizeof($topic_info) == 1) ? 'TOPIC_' . strtoupper($action) . 'D_SUCCESS' : 'TOPICS_' . strtoupper($action) . 'D_SUCCESS'; + } + + foreach ($approve_log as $log_data) + { + add_log('mod', $log_data['forum_id'], $log_data['topic_id'], 'LOG_TOPIC_' . strtoupper($action) . 'D', $log_data['topic_title']); + } + + // Only send out the mails, when the posts are being approved + if ($action == 'approve') + { + $messenger = new messenger(); + + // Notify Poster? + if ($notify_poster) + { + foreach ($topic_info as $topic_id => $topic_data) + { + if ($topic_data['topic_poster'] == ANONYMOUS) + { + continue; + } + + $messenger->template('topic_approved', $topic_data['user_lang']); + $messenger->to($topic_data['user_email'], $topic_data['username']); + $messenger->im($topic_data['user_jabber'], $topic_data['username']); + + $messenger->assign_vars(array( + 'USERNAME' => htmlspecialchars_decode($topic_data['username']), + 'TOPIC_TITLE' => htmlspecialchars_decode(censor_text($topic_data['topic_title'])), + 'U_VIEW_TOPIC' => generate_board_url() . "/viewtopic.$phpEx?f={$topic_data['forum_id']}&t={$topic_data['topic_id']}&e=0", + ); + + $messenger->send($topic_data['user_notify_type']); + } + } + + $messenger->save_queue(); + + // Send out normal user notifications + $email_sig = str_replace('
', "\n", "-- \n" . $config['board_email_sig']); + + foreach ($topic_info as $topic_id => $topic_data) + { + // Forum Notifications + user_notification('post', $topic_data['topic_title'], $topic_data['topic_title'], $topic_data['forum_name'], $topic_data['forum_id'], $topic_data['topic_id'], 0); + } + } + } + else + { + $show_notify = false; + + if ($action == 'approve' && ($config['email_enable'] || $config['jab_enable'])) + { + foreach ($topic_info as $topic_data) + { + if ($topic_data['topic_poster'] == ANONYMOUS) + { + continue; + } + else + { + $show_notify = true; + break; + } + } + } + + $template->assign_vars(array( + 'S_NOTIFY_POSTER' => $show_notify, + 'S_' . strtoupper($action) => true, + )); + + confirm_box(false, strtoupper($action) . '_POST' . ((sizeof($post_id_list) == 1) ? '' : 'S'), $s_hidden_fields, 'mcp_approve.html'); + } + + $redirect = request_var('redirect', "index.$phpEx"); + $redirect = reapply_sid($redirect); + + if (!$success_msg) + { + redirect($redirect); + } + else + { + meta_refresh(3, $redirect); + + // If approving one topic, also give links back to topic... + $add_message = ''; + if (sizeof($topic_info) == 1 && $topic_url) + { + $add_message = '

' . sprintf($user->lang['RETURN_TOPIC'], '', ''); + } + + $message = $user->lang[$success_msg] . '

' . sprintf($user->lang['RETURN_PAGE'], "", '') . $add_message; + + if ($request->is_ajax()) + { + $json_response = new phpbb_json_response; + $json_response->send(array( + 'MESSAGE_TITLE' => $user->lang['INFORMATION'], + 'MESSAGE_TEXT' => $message, + 'REFRESH_DATA' => null, + 'visible' => true, + )); + } + + trigger_error($message); + } + } + /** * Disapprove Post/Topic */ -- cgit v1.2.1 From 43d041bdecb5e564ad48efdf4702cad3714c7837 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 16 Oct 2012 14:20:23 +0200 Subject: [feature/soft-delete] Removed unused old functions PHPBB3-9567 --- phpBB/includes/content_visibility.php | 164 ---------------------------- phpBB/includes/mcp/mcp_queue.php | 200 ---------------------------------- 2 files changed, 364 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/content_visibility.php b/phpBB/includes/content_visibility.php index 8854981303..8bfdfd2917 100644 --- a/phpBB/includes/content_visibility.php +++ b/phpBB/includes/content_visibility.php @@ -550,168 +550,4 @@ class phpbb_content_visibility $db->sql_query($sql); } } - - /** - * 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 - */ - static 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 topics 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); - - if ($total_topics) - { - //@todo: plurals! - $success_msg = ($total_topics == 1) ? 'TOPIC_APPROVED_SUCCESS' : 'TOPICS_APPROVED_SUCCESS'; - } - else - { - $success_msg = (sizeof($post_id_list) + sizeof($post_approved_list) == 1) ? 'POST_APPROVED_SUCCESS' : 'POSTS_APPROVED_SUCCESS'; - } - - return $success_msg; - } } diff --git a/phpBB/includes/mcp/mcp_queue.php b/phpBB/includes/mcp/mcp_queue.php index f4a78525c8..5e7c53c8de 100644 --- a/phpBB/includes/mcp/mcp_queue.php +++ b/phpBB/includes/mcp/mcp_queue.php @@ -466,206 +466,6 @@ class mcp_queue } } - /** - * Restore Posts - * - * @param $post_id_list array IDs of the posts to restore - * @param $id mixed Category of the current active module - * @param $mode string Active module - * @return void - */ - function restore_posts($post_id_list, $id, $mode) - { - global $db, $template, $user, $config; - global $phpEx, $phpbb_root_path, $request; - - if (!check_ids($post_id_list, POSTS_TABLE, 'post_id', array('m_approve'))) - { - trigger_error('NOT_AUTHORISED'); - } - - $redirect = request_var('redirect', build_url(array('quickmod'))); - $success_msg = ''; - - $s_hidden_fields = build_hidden_fields(array( - 'i' => $id, - 'mode' => $mode, - 'post_id_list' => $post_id_list, - 'action' => 'restore', - 'redirect' => $redirect, - )); - - $post_info = get_post_data($post_id_list, 'm_approve'); - - if (confirm_box(true)) - { - $topic_info = 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; - } - - $post_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f={$post_data['forum_id']}&t={$post_data['topic_id']}&p={$post_data['post_id']}") . '#p' . $post_data['post_id']; - } - - foreach ($topic_info as $topic_id => $topic_data) - { - phpbb_content_visibility::set_post_visibility(ITEM_APPROVED, $topic_data['posts'], $topic_id, $topic_data['forum_id'], $user->data['user_id'], time(), '', isset($topic_data['first_post']), isset($topic_data['last_post'])); - } - - if (sizeof($post_info) >= 1) - { - $success_msg = (sizeof($post_info) == 1) ? 'POST_RESTORED_SUCCESS' : 'POSTS_RESTORED_SUCCESS'; - } - } - else - { - $template->assign_vars(array( - 'S_APPROVE' => true, - )); - - confirm_box(false, 'RESTORE_POST' . ((sizeof($post_id_list) == 1) ? '' : 'S'), $s_hidden_fields, 'mcp_approve.html'); - } - - $redirect = request_var('redirect', "index.$phpEx"); - $redirect = reapply_sid($redirect); - - if (!$success_msg) - { - redirect($redirect); - } - else - { - // If restoring one post, also give links back to post... - $add_message = ''; - if (sizeof($post_id_list) == 1 && !empty($post_url)) - { - $add_message = '

' . sprintf($user->lang['RETURN_POST'], '', ''); - } - - $message = $user->lang[$success_msg] . '

' . sprintf($user->lang['RETURN_PAGE'], "", '') . $add_message; - - if ($request->is_ajax()) - { - $json_response = new phpbb_json_response; - $json_response->send(array( - 'MESSAGE_TITLE' => $user->lang['INFORMATION'], - 'MESSAGE_TEXT' => $message, - 'REFRESH_DATA' => null, - 'visible' => true, - )); - } - - meta_refresh(3, $redirect); - trigger_error($message); - } - } - - /** - * Restore topics - * - * @param $topic_id_list array IDs of the topics to restore - * @param $id mixed Category of the current active module - * @param $mode string Active module - * @return void - */ - function restore_topics($topic_id_list, $id, $mode) - { - global $db, $template, $user, $config; - global $phpEx, $phpbb_root_path, $request; - - if (!check_ids($topic_id_list, TOPICS_TABLE, 'topic_id', array('m_approve'))) - { - trigger_error('NOT_AUTHORISED'); - } - - $redirect = request_var('redirect', build_url(array('quickmod'))); - $success_msg = ''; - - $s_hidden_fields = build_hidden_fields(array( - 'i' => $id, - 'mode' => $mode, - 'topic_id_list' => $topic_id_list, - 'action' => 'restore', - 'redirect' => $redirect, - )); - - $topic_info = get_topic_data($topic_id_list, 'm_approve'); - - if (confirm_box(true)) - { - foreach ($topic_info as $topic_id => $topic_data) - { - phpbb_content_visibility::set_post_visibility(ITEM_APPROVED, $topic_id, $topic_data['forum_id'], $user->data['user_id'], time(), ''); - $topic_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f={$topic_data['forum_id']}&t={$topic_id}"); - } - - if (sizeof($topic_info) >= 1) - { - $success_msg = 'TOPIC' . ((sizeof($topic_info) == 1) ? '' : 'S') . '_RESTORED_SUCCESS'; - } - } - else - { - $template->assign_vars(array( - 'S_APPROVE' => true, - )); - - confirm_box(false, 'RESTORE_TOPIC' . ((sizeof($topic_info) == 1) ? '' : 'S'), $s_hidden_fields, 'mcp_approve.html'); - } - - $redirect = request_var('redirect', "index.$phpEx"); - $redirect = reapply_sid($redirect); - - if (!$success_msg) - { - redirect($redirect); - } - else - { - // If restoring one topic, also give links back to topic... - $add_message = ''; - if (sizeof($topic_info) == 1 && !empty($topic_url)) - { - $add_message = '

' . sprintf($user->lang['RETURN_TOPIC'], '', ''); - } - - $message = $user->lang[$success_msg] . '

' . sprintf($user->lang['RETURN_PAGE'], "", '') . $add_message; - - if ($request->is_ajax()) - { - $json_response = new phpbb_json_response; - $json_response->send(array( - 'MESSAGE_TITLE' => $user->lang['INFORMATION'], - 'MESSAGE_TEXT' => $message, - 'REFRESH_DATA' => null, - 'visible' => true, - )); - } - - meta_refresh(3, $redirect); - trigger_error($message); - } - } - /** * Approve/Restore posts * -- cgit v1.2.1 From 2adb37049e8c7eab5fa762a8968605a8f608aaa8 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 17 Oct 2012 15:23:16 +0200 Subject: [feature/soft-delete] Display guest username in topic list instead of "Guest" PHPBB3-9567 --- phpBB/includes/mcp/mcp_queue.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/mcp/mcp_queue.php b/phpBB/includes/mcp/mcp_queue.php index 5e7c53c8de..bf34c7c53c 100644 --- a/phpBB/includes/mcp/mcp_queue.php +++ b/phpBB/includes/mcp/mcp_queue.php @@ -417,7 +417,7 @@ class mcp_queue { if (empty($row['post_username'])) { - $row['post_username'] = $user->lang['GUEST']; + $row['post_username'] = $row['username'] ?: $user->lang['GUEST']; } $template->assign_block_vars('postrow', array( @@ -747,7 +747,7 @@ class mcp_queue 'USERNAME' => htmlspecialchars_decode($topic_data['username']), 'TOPIC_TITLE' => htmlspecialchars_decode(censor_text($topic_data['topic_title'])), 'U_VIEW_TOPIC' => generate_board_url() . "/viewtopic.$phpEx?f={$topic_data['forum_id']}&t={$topic_data['topic_id']}&e=0", - ); + )); $messenger->send($topic_data['user_notify_type']); } -- cgit v1.2.1 From 0822d2bb61dda3b887911d6686a8c6db05131c47 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 17 Oct 2012 15:32:57 +0200 Subject: [feature/soft-delete] Split unapproved/soft deleted posts from topics If a topic is soft deleted through a moderator, the topic_delete_user is set. If it is passively soft deleted (f.e. while the only approved post is deleted) the topic_delete_user is not set. This way, we can distinguish between these two cases. The same also applies to unapproved posts. So we need to set the topic_delete_user when an unapproved topic is posted. Topics that were soft deleted/unapproved by a user (rather then passive) are going to be displayed in the Topics modules, while all others are in the posts modules of the MCP queue. PHPBB3-9567 --- phpBB/includes/functions_posting.php | 1 + phpBB/includes/mcp/mcp_queue.php | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index b6223b72d4..1a0fdcee85 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -1864,6 +1864,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u 'forum_id' => $data['forum_id'], 'icon_id' => $data['icon_id'], 'topic_visibility' => $post_visibility, + 'topic_delete_user' => ($post_visibility != ITEM_APPROVED) ? (int) $user->data['user_id'] : 0, 'topic_title' => $subject, 'topic_first_poster_name' => (!$user->data['is_registered'] && $username) ? $username : (($user->data['user_id'] != ANONYMOUS) ? $user->data['username'] : ''), 'topic_first_poster_colour' => $user->data['user_colour'], diff --git a/phpBB/includes/mcp/mcp_queue.php b/phpBB/includes/mcp/mcp_queue.php index bf34c7c53c..554a7c080b 100644 --- a/phpBB/includes/mcp/mcp_queue.php +++ b/phpBB/includes/mcp/mcp_queue.php @@ -335,7 +335,8 @@ class mcp_queue ' . (($sort_order_sql[0] == 'u') ? 'AND u.user_id = p.poster_id' : '') . ' ' . (($topic_id) ? 'AND p.topic_id = ' . $topic_id : '') . " AND t.topic_id = p.topic_id - AND t.topic_visibility <> p.post_visibility + AND (t.topic_visibility <> p.post_visibility + OR t.topic_delete_user = 0) $limit_time_sql ORDER BY $sort_order_sql"; $result = $db->sql_query_limit($sql, $config['topics_per_page'], $start); @@ -384,6 +385,7 @@ class mcp_queue FROM ' . TOPICS_TABLE . ' t WHERE ' . $db->sql_in_set('forum_id', $forum_list) . ' AND topic_visibility = ' . $visibility_const . " + AND topic_delete_user <> 0 $limit_time_sql ORDER BY $sort_order_sql"; $result = $db->sql_query_limit($sql, $config['topics_per_page'], $start); -- cgit v1.2.1 From e7a137820bf6ca341df5c0c503e2767451f57c5e Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 21 Oct 2012 22:30:20 +0200 Subject: [feature/soft-delete] Use correct language when restoring topics in MCP PHPBB3-9567 --- phpBB/includes/mcp/mcp_queue.php | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/mcp/mcp_queue.php b/phpBB/includes/mcp/mcp_queue.php index 554a7c080b..3d36229ee7 100644 --- a/phpBB/includes/mcp/mcp_queue.php +++ b/phpBB/includes/mcp/mcp_queue.php @@ -67,11 +67,11 @@ class mcp_queue { if ($action != 'disapprove') { - $this->approve_topics($action, $post_id_list, 'queue', $mode); + $this->approve_topics($action, $topic_id_list, 'queue', $mode); } else { - $this->disapprove_posts($post_id_list, 'queue', $mode); + //@todo: $this->disapprove_posts($post_id_list, 'queue', $mode); } } else @@ -434,6 +434,7 @@ class mcp_queue 'U_POST_AUTHOR' => get_username_string('profile', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']), 'POST_ID' => $row['post_id'], + 'TOPIC_ID' => $row['topic_id'], 'FORUM_NAME' => $forum_names[$row['forum_id']], 'POST_SUBJECT' => ($row['post_subject'] != '') ? $row['post_subject'] : $user->lang['NO_SUBJECT'], 'TOPIC_TITLE' => $row['topic_title'], @@ -700,7 +701,7 @@ class mcp_queue foreach ($topic_info as $topic_id => $topic_data) { - phpbb_content_visibility::set_post_visibility(ITEM_APPROVED, $topic_id, $topic_data['forum_id'], $user->data['user_id'], time(), ''); + phpbb_content_visibility::set_topic_visibility(ITEM_APPROVED, $topic_id, $topic_data['forum_id'], $user->data['user_id'], time(), ''); $topic_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f={$topic_data['forum_id']}&t={$topic_id}"); @@ -711,11 +712,6 @@ class mcp_queue ); } - foreach ($topic_info as $topic_id => $topic_data) - { - phpbb_content_visibility::set_topic_visibility(ITEM_APPROVED, $topic_id, $topic_data['forum_id'], $user->data['user_id'], time(), ''); - } - if (sizeof($topic_info) >= 1) { $success_msg = (sizeof($topic_info) == 1) ? 'TOPIC_' . strtoupper($action) . 'D_SUCCESS' : 'TOPICS_' . strtoupper($action) . 'D_SUCCESS'; @@ -792,7 +788,7 @@ class mcp_queue 'S_' . strtoupper($action) => true, )); - confirm_box(false, strtoupper($action) . '_POST' . ((sizeof($post_id_list) == 1) ? '' : 'S'), $s_hidden_fields, 'mcp_approve.html'); + confirm_box(false, strtoupper($action) . '_TOPIC' . ((sizeof($topic_id_list) == 1) ? '' : 'S'), $s_hidden_fields, 'mcp_approve.html'); } $redirect = request_var('redirect', "index.$phpEx"); -- cgit v1.2.1 From 6c39563e9f7fad18f1425292dca652861f5e1cb6 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 21 Oct 2012 23:38:55 +0200 Subject: [feature/soft-delete] Add a function to calculate the actual post/topic count PHPBB3-9567 --- phpBB/includes/content_visibility.php | 20 ++++++++++++++++++++ phpBB/includes/functions_display.php | 5 +++-- 2 files changed, 23 insertions(+), 2 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/content_visibility.php b/phpBB/includes/content_visibility.php index 8bfdfd2917..2a0cc3c850 100644 --- a/phpBB/includes/content_visibility.php +++ b/phpBB/includes/content_visibility.php @@ -46,6 +46,26 @@ class phpbb_content_visibility return false; } + /** + * Get the topics post count or the forums post/topic count based on permissions + * + * @param $mode string One of topic_posts, forum_posts or forum_topics + * @param $data array Array with the topic/forum data to calculate from + * @param $forum_id int The forum id is used for permission checks + * @return int Number of posts/topics the user can see in the topic/forum + */ + static public function get_count($mode, $data, $forum_id) + { + global $auth; + + if (!$auth->acl_get('m_approve', $forum_id)) + { + return (int) $data[$mode]; + } + + return (int) $data[$mode] + (int) $data[$mode . '_unapproved'] + (int) $data[$mode . '_softdeleted']; + } + /** * Create topic/post visibility SQL for a given forum ID * diff --git a/phpBB/includes/functions_display.php b/phpBB/includes/functions_display.php index 10f07bfbf1..ed91d9ad1c 100644 --- a/phpBB/includes/functions_display.php +++ b/phpBB/includes/functions_display.php @@ -200,8 +200,9 @@ function display_forums($root_data = '', $display_moderators = true, $return_mod } // Count the difference of real to public topics, so we can display an information to moderators - $row['forum_id_unapproved_topics'] = ($auth->acl_get('m_approve', $forum_id) && ($row['forum_topics_real'] != $row['forum_topics'])) ? $forum_id : 0; - $row['forum_topics'] = ($auth->acl_get('m_approve', $forum_id)) ? $row['forum_topics_real'] : $row['forum_topics']; + $row['forum_id_unapproved_topics'] = ($auth->acl_get('m_approve', $forum_id) && $row['forum_topics_unapproved']) ? $forum_id : 0; + $row['forum_posts'] = phpbb_content_visibility::get_count('forum_posts', $row, $forum_id); + $row['forum_topics'] = phpbb_content_visibility::get_count('forum_topics', $row, $forum_id); // Display active topics from this forum? if ($show_active && $row['forum_type'] == FORUM_POST && $auth->acl_get('f_read', $forum_id) && ($row['forum_flags'] & FORUM_FLAG_ACTIVE_TOPICS)) -- cgit v1.2.1 From 9945561b4b58e4825fd2290ae1fbbb3d49fd3e7c Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 22 Oct 2012 11:14:00 +0200 Subject: [feature/soft-delete] Correctly calculate the number of replies everywhere PHPBB3-9567 --- phpBB/includes/mcp/mcp_forum.php | 5 +++-- phpBB/includes/mcp/mcp_topic.php | 9 +-------- phpBB/includes/ucp/ucp_main.php | 2 +- 3 files changed, 5 insertions(+), 11 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/mcp/mcp_forum.php b/phpBB/includes/mcp/mcp_forum.php index 02a1ba6dcc..c04a4d37d4 100644 --- a/phpBB/includes/mcp/mcp_forum.php +++ b/phpBB/includes/mcp/mcp_forum.php @@ -203,7 +203,7 @@ function mcp_forum_view($id, $mode, $action, $forum_info) $row = &$topic_rows[$topic_id]; - $replies = ($auth->acl_get('m_approve', $forum_id)) ? $row['topic_replies_real'] : $row['topic_replies']; + $replies = phpbb_content_visibility::get_count('topic_posts', $row, $forum_id) - 1; if ($row['topic_status'] == ITEM_MOVED) { @@ -220,6 +220,7 @@ function mcp_forum_view($id, $mode, $action, $forum_info) $topic_title = censor_text($row['topic_title']); + // @todo: $topic_unapproved = ($row['topic_visibility'] == ITEM_UNAPPROVED && $auth->acl_get('m_approve', $row['forum_id'])) ? true : false; $posts_unapproved = ($row['topic_visibility'] == ITEM_APPROVED && $row['topic_replies'] < $row['topic_replies_real'] && $auth->acl_get('m_approve', $row['forum_id'])) ? true : false; $topic_deleted = ($row['topic_visibility'] == ITEM_DELETED) ? true : false; @@ -248,7 +249,7 @@ function mcp_forum_view($id, $mode, $action, $forum_info) 'TOPIC_TYPE' => $topic_type, 'TOPIC_TITLE' => $topic_title, - 'REPLIES' => ($auth->acl_get('m_approve', $row['forum_id'])) ? $row['topic_replies_real'] : $row['topic_replies'], + 'REPLIES' => phpbb_content_visibility::get_count('topic_posts', $row, $row['forum_id']) - 1, 'LAST_POST_TIME' => $user->format_date($row['topic_last_post_time']), 'FIRST_POST_TIME' => $user->format_date($row['topic_time']), 'LAST_POST_SUBJECT' => $row['topic_last_post_subject'], diff --git a/phpBB/includes/mcp/mcp_topic.php b/phpBB/includes/mcp/mcp_topic.php index 8320699a8c..0259a12ca8 100644 --- a/phpBB/includes/mcp/mcp_topic.php +++ b/phpBB/includes/mcp/mcp_topic.php @@ -115,14 +115,7 @@ function mcp_topic_view($id, $mode, $action) if ($total == -1) { - if ($auth->acl_get('m_approve', $topic_info['forum_id'])) - { - $total = $topic_info['topic_replies_real'] + 1; - } - else - { - $total = $topic_info['topic_replies'] + 1; - } + $total = phpbb_content_visibility::get_count('topic_posts', $topic_info, $topic_info['forum_id']); } $posts_per_page = max(0, request_var('posts_per_page', intval($config['posts_per_page']))); diff --git a/phpBB/includes/ucp/ucp_main.php b/phpBB/includes/ucp/ucp_main.php index 94fd59433b..7aa06464b7 100644 --- a/phpBB/includes/ucp/ucp_main.php +++ b/phpBB/includes/ucp/ucp_main.php @@ -778,7 +778,7 @@ class ucp_main $unread_topic = (isset($topic_tracking_info[$topic_id]) && $row['topic_last_post_time'] > $topic_tracking_info[$topic_id]) ? true : false; // Replies - $replies = ($auth->acl_get('m_approve', $forum_id)) ? $row['topic_replies_real'] : $row['topic_replies']; + $replies = phpbb_content_visibility::get_count('topic_posts', $row, $forum_id) - 1; if ($row['topic_status'] == ITEM_MOVED && !empty($row['topic_moved_id'])) { -- cgit v1.2.1 From 168dd29f24843e97182c894a5d43a7d38f8a195c Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 22 Oct 2012 14:21:44 +0200 Subject: [feature/soft-delete] Fix sync() and some more functions to use the new fields PHPBB3-9567 --- phpBB/includes/acp/acp_users.php | 12 +++++---- phpBB/includes/content_visibility.php | 8 +++--- phpBB/includes/functions_admin.php | 49 +++++++++++++++++++++++++---------- 3 files changed, 48 insertions(+), 21 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/acp/acp_users.php b/phpBB/includes/acp/acp_users.php index 304027df45..1a3511bc50 100644 --- a/phpBB/includes/acp/acp_users.php +++ b/phpBB/includes/acp/acp_users.php @@ -621,29 +621,31 @@ class acp_users $topic_id_ary = $move_topic_ary = $move_post_ary = $new_topic_id_ary = array(); $forum_id_ary = array($new_forum_id); - $sql = 'SELECT topic_id, COUNT(post_id) AS total_posts + $sql = 'SELECT topic_id, post_visibility, COUNT(post_id) AS total_posts FROM ' . POSTS_TABLE . " WHERE poster_id = $user_id AND forum_id <> $new_forum_id - GROUP BY topic_id"; + GROUP BY topic_id, post_visibility"; $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { - $topic_id_ary[$row['topic_id']] = $row['total_posts']; + $topic_id_ary[$row['topic_id']][$row['post_visibility']] = $row['total_posts']; } $db->sql_freeresult($result); if (sizeof($topic_id_ary)) { - $sql = 'SELECT topic_id, forum_id, topic_title, topic_replies, topic_replies_real, topic_attachment + $sql = 'SELECT topic_id, forum_id, topic_title, topic_posts, topic_posts_unapproved, topic_posts_softdeleted, topic_attachment FROM ' . TOPICS_TABLE . ' WHERE ' . $db->sql_in_set('topic_id', array_keys($topic_id_ary)); $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { - if (max($row['topic_replies'], $row['topic_replies_real']) + 1 == $topic_id_ary[$row['topic_id']]) + if ($topic_id_ary[$row['topic_id']][ITEM_APPROVED] == $row['topic_posts'] + && $topic_id_ary[$row['topic_id']][ITEM_UNAPPROVED] == $row['topic_posts_unapproved'] + && $topic_id_ary[$row['topic_id']][ITEM_DELETED] == $row['topic_posts_softdeleted']) { $move_topic_ary[] = $row['topic_id']; } diff --git a/phpBB/includes/content_visibility.php b/phpBB/includes/content_visibility.php index 2a0cc3c850..5596fe98df 100644 --- a/phpBB/includes/content_visibility.php +++ b/phpBB/includes/content_visibility.php @@ -523,7 +523,7 @@ class phpbb_content_visibility // Do we need to grab some topic informations? if (!sizeof($topic_row)) { - $sql = 'SELECT topic_type, topic_replies, topic_replies_real, topic_visibility + $sql = 'SELECT topic_type, topic_posts, topic_posts_unapproved, topic_posts_softdeleted, topic_visibility FROM ' . TOPICS_TABLE . ' WHERE topic_id = ' . $topic_id; $result = $db->sql_query($sql); @@ -533,10 +533,12 @@ class phpbb_content_visibility // If this is an edited topic or the first post the topic gets completely disapproved later on... $sql_data[FORUMS_TABLE] = (($sql_data[FORUMS_TABLE]) ? $sql_data[FORUMS_TABLE] . ', ' : '') . 'forum_topics = forum_topics - 1'; - $sql_data[FORUMS_TABLE] .= ', forum_posts = forum_posts - ' . ($topic_row['topic_replies'] + 1); + $sql_data[FORUMS_TABLE] .= ', forum_posts = forum_posts - ' . $topic_row['topic_posts']; + $sql_data[FORUMS_TABLE] .= ', forum_posts_unapproved = forum_posts_unapproved - ' . $topic_row['topic_posts_unapproved']; + $sql_data[FORUMS_TABLE] .= ', forum_posts_softdeleted = forum_posts_softdeleted - ' . $topic_row['topic_posts_softdeleted']; set_config_count('num_topics', -1, true); - set_config_count('num_posts', ($topic_row['topic_replies'] + 1) * (-1), true); + set_config_count('num_posts', $topic_row['topic_posts'] * (-1), true); // Get user post count information $sql = 'SELECT poster_id, COUNT(post_id) AS num_posts diff --git a/phpBB/includes/functions_admin.php b/phpBB/includes/functions_admin.php index cb84d1cfb1..a38fa2a70f 100644 --- a/phpBB/includes/functions_admin.php +++ b/phpBB/includes/functions_admin.php @@ -1670,8 +1670,11 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false, if ($sync_extra) { $forum_data[$forum_id]['posts'] = 0; + $forum_data[$forum_id]['posts_unapproved'] = 0; + $forum_data[$forum_id]['posts_softdeleted'] = 0; $forum_data[$forum_id]['topics'] = 0; - $forum_data[$forum_id]['topics_real'] = 0; + $forum_data[$forum_id]['topics_unapproved'] = 0; + $forum_data[$forum_id]['topics_softdeleted'] = 0; } $forum_data[$forum_id]['last_post_id'] = 0; $forum_data[$forum_id]['last_post_subject'] = ''; @@ -1692,7 +1695,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false, // 2: Get topic counts for each forum (optional) if ($sync_extra) { - $sql = 'SELECT forum_id, topic_visibility, COUNT(topic_id) AS forum_topics + $sql = 'SELECT forum_id, topic_visibility, COUNT(topic_id) AS total_topics FROM ' . TOPICS_TABLE . ' WHERE ' . $db->sql_in_set('forum_id', $forum_ids) . ' GROUP BY forum_id, topic_visibility'; @@ -1701,11 +1704,18 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false, while ($row = $db->sql_fetchrow($result)) { $forum_id = (int) $row['forum_id']; - $forum_data[$forum_id]['topics_real'] += $row['forum_topics']; if ($row['topic_visibility'] == ITEM_APPROVED) { - $forum_data[$forum_id]['topics'] = $row['forum_topics']; + $forum_data[$forum_id]['topics'] = $row['total_topics']; + } + else if ($row['topic_visibility'] == ITEM_UNAPPROVED) + { + $forum_data[$forum_id]['topics_unapproved'] = $row['total_topics']; + } + else if ($row['topic_visibility'] == ITEM_DELETED) + { + $forum_data[$forum_id]['topics_softdeleted'] = $row['total_topics']; } } $db->sql_freeresult($result); @@ -1716,7 +1726,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false, { if (sizeof($forum_ids) == 1) { - $sql = 'SELECT SUM(t.topic_replies + 1) AS forum_posts + $sql = 'SELECT SUM(t.topic_posts) AS forum_posts, SUM(t.topic_posts_unapproved) AS forum_posts_unapproved, SUM(t.topic_posts_softdeleted) AS forum_posts_softdeleted FROM ' . TOPICS_TABLE . ' t WHERE ' . $db->sql_in_set('t.forum_id', $forum_ids) . ' AND t.topic_visibility = ' . ITEM_APPROVED . ' @@ -1724,7 +1734,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false, } else { - $sql = 'SELECT t.forum_id, SUM(t.topic_replies + 1) AS forum_posts + $sql = 'SELECT t.forum_id, SUM(t.topic_posts) AS forum_posts, SUM(t.topic_posts_unapproved) AS forum_posts_unapproved, SUM(t.topic_posts_softdeleted) AS forum_posts_softdeleted FROM ' . TOPICS_TABLE . ' t WHERE ' . $db->sql_in_set('t.forum_id', $forum_ids) . ' AND t.topic_visibility = ' . ITEM_APPROVED . ' @@ -1739,6 +1749,8 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false, $forum_id = (sizeof($forum_ids) == 1) ? (int) $forum_ids[0] : (int) $row['forum_id']; $forum_data[$forum_id]['posts'] = (int) $row['forum_posts']; + $forum_data[$forum_id]['posts_unapproved'] = (int) $row['forum_posts_unapproved']; + $forum_data[$forum_id]['posts_softdeleted'] = (int) $row['forum_posts_softdeleted']; } $db->sql_freeresult($result); } @@ -1819,7 +1831,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false, if ($sync_extra) { - array_push($fieldnames, 'posts', 'topics', 'topics_real'); + array_push($fieldnames, 'posts', 'posts_unapproved', 'posts_softdeleted', 'topics', 'topics_unapproved', 'topics_softdeleted'); } foreach ($forum_data as $forum_id => $row) @@ -1858,7 +1870,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false, $db->sql_transaction('begin'); - $sql = 'SELECT t.topic_id, t.forum_id, t.topic_moved_id, t.topic_visibility, ' . (($sync_extra) ? 't.topic_attachment, t.topic_reported, ' : '') . 't.topic_poster, t.topic_time, t.topic_replies, t.topic_replies_real, t.topic_first_post_id, t.topic_first_poster_name, t.topic_first_poster_colour, t.topic_last_post_id, t.topic_last_post_subject, t.topic_last_poster_id, t.topic_last_poster_name, t.topic_last_poster_colour, t.topic_last_post_time + $sql = 'SELECT t.topic_id, t.forum_id, t.topic_moved_id, t.topic_visibility, ' . (($sync_extra) ? 't.topic_attachment, t.topic_reported, ' : '') . 't.topic_poster, t.topic_time, t.topic_posts, t.topic_posts_unapproved, t.topic_posts_softdeleted, t.topic_first_post_id, t.topic_first_poster_name, t.topic_first_poster_colour, t.topic_last_post_id, t.topic_last_post_subject, t.topic_last_poster_id, t.topic_last_poster_name, t.topic_last_poster_colour, t.topic_last_post_time FROM ' . TOPICS_TABLE . " t $where_sql"; $result = $db->sql_query($sql); @@ -1874,8 +1886,9 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false, $topic_id = (int) $row['topic_id']; $topic_data[$topic_id] = $row; $topic_data[$topic_id]['visibility'] = ITEM_UNAPPROVED; - $topic_data[$topic_id]['replies_real'] = -1; - $topic_data[$topic_id]['replies'] = 0; + $topic_data[$topic_id]['posts'] = 0; + $topic_data[$topic_id]['posts_unapproved'] = 0; + $topic_data[$topic_id]['posts_softdeleted'] = 0; $topic_data[$topic_id]['first_post_id'] = 0; $topic_data[$topic_id]['last_post_id'] = 0; unset($topic_data[$topic_id]['topic_id']); @@ -1917,14 +1930,24 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false, // When we'll be done, only topics with no posts will remain unset($delete_topics[$topic_id]); - $topic_data[$topic_id]['replies_real'] += $row['total_posts']; + if ($row['post_visibility'] == ITEM_APPROVED) + { + $topic_data[$topic_id]['posts'] = $row['total_posts']; + } + else if ($row['post_visibility'] == ITEM_UNAPPROVED) + { + $topic_data[$topic_id]['posts_unapproved'] = $row['total_posts']; + } + else if ($row['post_visibility'] == ITEM_DELETED) + { + $topic_data[$topic_id]['posts_softdeleted'] = $row['total_posts']; + } if ($row['post_visibility'] == ITEM_APPROVED) { $topic_data[$topic_id]['visibility'] = ITEM_APPROVED; $topic_data[$topic_id]['first_post_id'] = $row['first_post_id']; $topic_data[$topic_id]['last_post_id'] = $row['last_post_id']; - $topic_data[$topic_id]['replies'] = $row['total_posts'] - 1; } else if ($topic_data[$topic_id]['visibility'] != ITEM_APPROVED) { @@ -2120,7 +2143,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false, } // These are fields that will be synchronised - $fieldnames = array('time', 'visibility', 'replies', 'replies_real', 'poster', 'first_post_id', 'first_poster_name', 'first_poster_colour', 'last_post_id', 'last_post_subject', 'last_post_time', 'last_poster_id', 'last_poster_name', 'last_poster_colour'); + $fieldnames = array('time', 'visibility', 'posts', 'posts_unapproved', 'posts_softdeleted', 'poster', 'first_post_id', 'first_poster_name', 'first_poster_colour', 'last_post_id', 'last_post_subject', 'last_post_time', 'last_poster_id', 'last_poster_name', 'last_poster_colour'); if ($sync_extra) { -- 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/includes/mcp/mcp_forum.php | 2 +- phpBB/includes/mcp/mcp_main.php | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/mcp/mcp_forum.php b/phpBB/includes/mcp/mcp_forum.php index c04a4d37d4..bacc4c444c 100644 --- a/phpBB/includes/mcp/mcp_forum.php +++ b/phpBB/includes/mcp/mcp_forum.php @@ -222,7 +222,7 @@ function mcp_forum_view($id, $mode, $action, $forum_info) // @todo: $topic_unapproved = ($row['topic_visibility'] == ITEM_UNAPPROVED && $auth->acl_get('m_approve', $row['forum_id'])) ? true : false; - $posts_unapproved = ($row['topic_visibility'] == ITEM_APPROVED && $row['topic_replies'] < $row['topic_replies_real'] && $auth->acl_get('m_approve', $row['forum_id'])) ? true : false; + $posts_unapproved = ($row['topic_visibility'] == ITEM_APPROVED && $row['topic_posts_unapproved'] && $auth->acl_get('m_approve', $row['forum_id'])) ? true : false; $topic_deleted = ($row['topic_visibility'] == ITEM_DELETED) ? true : false; $u_mcp_queue = ($topic_unapproved || $posts_unapproved) ? $url . '&i=queue&mode=' . (($topic_unapproved) ? 'approve_details' : 'unapproved_posts') . '&t=' . $row['topic_id'] : ''; $u_mcp_queue = (!$u_mcp_queue && $topic_deleted) ? $url . 'i=queue&mode=deleted_posts&t=' . $topic_id : $u_mcp_queue; diff --git a/phpBB/includes/mcp/mcp_main.php b/phpBB/includes/mcp/mcp_main.php index a90fc0891e..3ccd1695ad 100644 --- a/phpBB/includes/mcp/mcp_main.php +++ b/phpBB/includes/mcp/mcp_main.php @@ -541,8 +541,9 @@ function mcp_move_topic($topic_ids) 'topic_time' => (int) $row['topic_time'], 'topic_time_limit' => (int) $row['topic_time_limit'], 'topic_views' => (int) $row['topic_views'], - 'topic_replies' => (int) $row['topic_replies'], - 'topic_replies_real' => (int) $row['topic_replies_real'], + 'topic_posts' => (int) $row['topic_posts'], + 'topic_posts_unapproved'=> (int) $row['topic_posts_unapproved'], + 'topic_posts_softdeleted'=> (int) $row['topic_posts_softdeleted'], 'topic_status' => ITEM_MOVED, 'topic_type' => POST_NORMAL, 'topic_first_post_id' => (int) $row['topic_first_post_id'], @@ -574,6 +575,7 @@ function mcp_move_topic($topic_ids) } unset($topic_data); + //@todo: needs fixing if ($topic_posts_removed) { $sync_sql[$forum_id][] = 'forum_posts = forum_posts - ' . $topic_posts_removed; @@ -937,8 +939,9 @@ function mcp_fork_topic($topic_ids) 'topic_title' => (string) $topic_row['topic_title'], 'topic_poster' => (int) $topic_row['topic_poster'], 'topic_time' => (int) $topic_row['topic_time'], - 'topic_replies' => (int) $topic_row['topic_replies_real'], - 'topic_replies_real' => (int) $topic_row['topic_replies_real'], + 'topic_posts' => (int) $topic_row['topic_posts'], + 'topic_posts_unapproved' => (int) $topic_row['topic_posts_unapproved'], + 'topic_posts_softdeleted' => (int) $topic_row['topic_posts_softdeleted'], 'topic_status' => (int) $topic_row['topic_status'], 'topic_type' => (int) $topic_row['topic_type'], 'topic_first_poster_name' => (string) $topic_row['topic_first_poster_name'], -- cgit v1.2.1 From 90154db1dbe3cd24f5af82ad5f665d607aad97ed Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 22 Oct 2012 16:38:53 +0200 Subject: [feature/soft-delete] Fix submit_post() topic_replies* usage PHPBB3-9567 --- phpBB/includes/content_visibility.php | 3 +-- phpBB/includes/functions_posting.php | 47 +++++++++++++++++++++++++++-------- 2 files changed, 38 insertions(+), 12 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/content_visibility.php b/phpBB/includes/content_visibility.php index 5596fe98df..20e743a4c4 100644 --- a/phpBB/includes/content_visibility.php +++ b/phpBB/includes/content_visibility.php @@ -495,8 +495,7 @@ class phpbb_content_visibility */ static public function remove_post_from_statistic($data, &$sql_data) { - $sql_data[TOPICS_TABLE] = (($sql_data[TOPICS_TABLE]) ? $sql_data[TOPICS_TABLE] . ', ' : '') . 'topic_replies = topic_replies - 1'; - + $sql_data[TOPICS_TABLE] = (($sql_data[TOPICS_TABLE]) ? $sql_data[TOPICS_TABLE] . ', ' : '') . 'topic_posts = topic_posts - 1'; $sql_data[FORUMS_TABLE] = (($sql_data[FORUMS_TABLE]) ? $sql_data[FORUMS_TABLE] . ', ' : '') . 'forum_posts = forum_posts - 1'; if ($data['post_postcount']) diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index 1a0fdcee85..02b6b0e697 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -1418,7 +1418,7 @@ function delete_post($forum_id, $topic_id, $post_id, &$data, $is_soft = false, $ // Specify our post mode $post_mode = 'delete'; - if (($data['topic_first_post_id'] === $data['topic_last_post_id']) && $data['topic_replies_real'] == 0) + if (($data['topic_first_post_id'] === $data['topic_last_post_id']) && ($data['topic_posts'] + $data['topic_posts_unapproved'] + $data['topic_posts_softdeleted'] == 1)) { $post_mode = 'delete_topic'; } @@ -1610,8 +1610,16 @@ function delete_post($forum_id, $topic_id, $post_id, &$data, $is_soft = false, $ { phpbb_content_visibility::remove_post_from_statistic($data, $sql_data); } - - $sql_data[TOPICS_TABLE] = (($sql_data[TOPICS_TABLE]) ? $sql_data[TOPICS_TABLE] . ', ' : '') . 'topic_replies_real = topic_replies_real - 1'; + else if ($data['post_visibility'] == ITEM_UNAPPROVED) + { + $sql_data[FORUMS_TABLE] = (($sql_data[FORUMS_TABLE]) ? $sql_data[FORUMS_TABLE] . ', ' : '') . 'forum_posts_unapproved = forum_posts_unapproved - 1'; + $sql_data[TOPICS_TABLE] = (($sql_data[TOPICS_TABLE]) ? $sql_data[TOPICS_TABLE] . ', ' : '') . 'topic_posts_unapproved = topic_posts_unapproved - 1'; + } + else if ($data['post_visibility'] == ITEM_DELETED) + { + $sql_data[FORUMS_TABLE] = (($sql_data[FORUMS_TABLE]) ? $sql_data[FORUMS_TABLE] . ', ' : '') . 'forum_posts_deleted = forum_posts_deleted - 1'; + $sql_data[TOPICS_TABLE] = (($sql_data[TOPICS_TABLE]) ? $sql_data[TOPICS_TABLE] . ', ' : '') . 'topic_posts_deleted = topic_posts_deleted - 1'; + } } $sql = 'SELECT 1 AS has_attachments @@ -1702,7 +1710,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u } else if ($mode == 'edit') { - $post_mode = ($data['topic_replies_real'] == 0) ? 'edit_topic' : (($data['topic_first_post_id'] == $data['post_id']) ? 'edit_first_post' : (($data['topic_last_post_id'] == $data['post_id']) ? 'edit_last_post' : 'edit')); + $post_mode = ($data['topic_posts'] + $data['topic_posts_unapproved'] + $data['topic_posts_softdeleted'] == 1) ? 'edit_topic' : (($data['topic_first_post_id'] == $data['post_id']) ? 'edit_first_post' : (($data['topic_last_post_id'] == $data['post_id']) ? 'edit_last_post' : 'edit')); } // First of all make sure the subject and topic title are having the correct length. @@ -1717,7 +1725,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u // Retrieve some additional information if not present if ($mode == 'edit' && (!isset($data['post_visibility']) || !isset($data['topic_visibility']) || $data['post_visibility'] === false || $data['topic_visibility'] === false)) { - $sql = 'SELECT p.post_visibility, t.topic_type, t.topic_replies, t.topic_replies_real, t.topic_visibility + $sql = 'SELECT p.post_visibility, t.topic_type, t.topic_posts, t.topic_posts_unapproved, t.topic_posts_softdeleted, t.topic_visibility FROM ' . TOPICS_TABLE . ' t, ' . POSTS_TABLE . ' p WHERE t.topic_id = p.topic_id AND p.post_id = ' . $data['post_id']; @@ -1900,17 +1908,28 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u if ($post_visibility == ITEM_APPROVED) { + $sql_data[FORUMS_TABLE]['stat'][] = 'forum_topics = forum_topics + 1'; $sql_data[FORUMS_TABLE]['stat'][] = 'forum_posts = forum_posts + 1'; } - $sql_data[FORUMS_TABLE]['stat'][] = 'forum_topics_real = forum_topics_real + 1' . (($post_visibility == ITEM_APPROVED) ? ', forum_topics = forum_topics + 1' : ''); + else if ($post_visibility == ITEM_UNAPPROVED) + { + $sql_data[FORUMS_TABLE]['stat'][] = 'forum_topics_unapproved = forum_topics_unapproved + 1'; + $sql_data[FORUMS_TABLE]['stat'][] = 'forum_posts_unapproved = forum_posts_unapproved + 1'; + } + else if ($post_visibility == ITEM_DELETED) + { + $sql_data[FORUMS_TABLE]['stat'][] = 'forum_topics_softdeleted = forum_topics_softdeleted + 1'; + $sql_data[FORUMS_TABLE]['stat'][] = 'forum_posts_softdeleted = forum_posts_softdeleted + 1'; + } break; case 'reply': $sql_data[TOPICS_TABLE]['stat'][] = 'topic_last_view_time = ' . $current_time . ', - topic_replies_real = topic_replies_real + 1, topic_bumped = 0, topic_bumper = 0' . - (($post_visibility == ITEM_APPROVED) ? ', topic_replies = topic_replies + 1' : '') . + (($post_visibility == ITEM_APPROVED) ? ', topic_posts = topic_posts + 1' : '') . + (($post_visibility == ITEM_UNAPPROVED) ? ', topic_posts_unapproved = topic_posts_unapproved + 1' : '') . + (($post_visibility == ITEM_DELETED) ? ', topic_posts_softdeleted = topic_posts_softdeleted + 1' : '') . ((!empty($data['attachment_data']) || (isset($data['topic_attachment']) && $data['topic_attachment'])) ? ', topic_attachment = 1' : ''); $sql_data[USERS_TABLE]['stat'][] = "user_lastpost_time = $current_time" . (($auth->acl_get('f_postcount', $data['forum_id']) && $post_visibility == ITEM_APPROVED) ? ', user_posts = user_posts + 1' : ''); @@ -1919,6 +1938,14 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u { $sql_data[FORUMS_TABLE]['stat'][] = 'forum_posts = forum_posts + 1'; } + else if ($post_visibility == ITEM_UNAPPROVED) + { + $sql_data[FORUMS_TABLE]['stat'][] = 'forum_posts_unapproved = forum_posts_unapproved + 1'; + } + else if ($post_visibility == ITEM_DELETED) + { + $sql_data[FORUMS_TABLE]['stat'][] = 'forum_posts_softdeleted = forum_posts_softdeleted + 1'; + } break; case 'edit_topic': @@ -1979,8 +2006,8 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u if ($post_mode == 'reply') { $sql_data[POSTS_TABLE]['sql'] = array_merge($sql_data[POSTS_TABLE]['sql'], array( - 'topic_id' => $data['topic_id']) - ); + 'topic_id' => $data['topic_id'], + )); } $sql = 'INSERT INTO ' . POSTS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_data[POSTS_TABLE]['sql']); -- cgit v1.2.1 From eb9c39971bfe7c11d62466b8fab239a8fcbc8952 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 22 Oct 2012 17:34:37 +0200 Subject: [feature/soft-delete] Fix forum syncing in ACP and deleting posts PHPBB3-9567 --- phpBB/includes/acp/acp_forums.php | 22 +++++++++++++--------- phpBB/includes/functions_posting.php | 15 ++++++++++++--- 2 files changed, 25 insertions(+), 12 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/acp/acp_forums.php b/phpBB/includes/acp/acp_forums.php index 7f2539ec8d..8029181f39 100644 --- a/phpBB/includes/acp/acp_forums.php +++ b/phpBB/includes/acp/acp_forums.php @@ -283,7 +283,7 @@ class acp_forums @set_time_limit(0); - $sql = 'SELECT forum_name, forum_topics_real + $sql = 'SELECT forum_name, (forum_topics + forum_topics_unapproved + forum_topics_softdeleted) AS total_topics FROM ' . FORUMS_TABLE . " WHERE forum_id = $forum_id"; $result = $db->sql_query($sql); @@ -295,7 +295,7 @@ class acp_forums trigger_error($user->lang['NO_FORUM'] . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id), E_USER_WARNING); } - if ($row['forum_topics_real']) + if ($row['total_topics']) { $sql = 'SELECT MIN(topic_id) as min_topic_id, MAX(topic_id) as max_topic_id FROM ' . TOPICS_TABLE . ' @@ -329,15 +329,15 @@ class acp_forums $start += $batch_size; - $url = $this->u_action . "&parent_id={$this->parent_id}&f=$forum_id&action=sync&start=$start&topics_done=$topics_done&total={$row['forum_topics_real']}"; + $url = $this->u_action . "&parent_id={$this->parent_id}&f=$forum_id&action=sync&start=$start&topics_done=$topics_done&total={$row['total_topics']}"; meta_refresh(0, $url); $template->assign_vars(array( - 'U_PROGRESS_BAR' => $this->u_action . "&action=progress_bar&start=$topics_done&total={$row['forum_topics_real']}", - 'UA_PROGRESS_BAR' => addslashes($this->u_action . "&action=progress_bar&start=$topics_done&total={$row['forum_topics_real']}"), + 'U_PROGRESS_BAR' => $this->u_action . "&action=progress_bar&start=$topics_done&total={$row['total_topics']}", + 'UA_PROGRESS_BAR' => addslashes($this->u_action . "&action=progress_bar&start=$topics_done&total={$row['total_topics']}"), 'S_CONTINUE_SYNC' => true, - 'L_PROGRESS_EXPLAIN' => sprintf($user->lang['SYNC_IN_PROGRESS_EXPLAIN'], $topics_done, $row['forum_topics_real'])) + 'L_PROGRESS_EXPLAIN' => sprintf($user->lang['SYNC_IN_PROGRESS_EXPLAIN'], $topics_done, $row['total_topics'])) ); return; @@ -351,7 +351,7 @@ class acp_forums 'U_PROGRESS_BAR' => $this->u_action . '&action=progress_bar', 'UA_PROGRESS_BAR' => addslashes($this->u_action . '&action=progress_bar'), 'S_CONTINUE_SYNC' => true, - 'L_PROGRESS_EXPLAIN' => sprintf($user->lang['SYNC_IN_PROGRESS_EXPLAIN'], 0, $row['forum_topics_real'])) + 'L_PROGRESS_EXPLAIN' => sprintf($user->lang['SYNC_IN_PROGRESS_EXPLAIN'], 0, $row['total_topics'])) ); return; @@ -1143,7 +1143,8 @@ class acp_forums return array($user->lang['NO_FORUM_ACTION']); } - $forum_data_sql['forum_posts'] = $forum_data_sql['forum_topics'] = $forum_data_sql['forum_topics_real'] = $forum_data_sql['forum_last_post_id'] = $forum_data_sql['forum_last_poster_id'] = $forum_data_sql['forum_last_post_time'] = 0; + $forum_data_sql['forum_posts'] = $forum_data_sql['forum_posts_unapproved'] = $forum_data_sql['forum_posts_softdeleted'] = $forum_data_sql['forum_topics'] = $forum_data_sql['forum_topics_unapproved'] = $forum_data_sql['forum_topics_softdeleted'] = 0; + $forum_data_sql['forum_last_post_id'] = $forum_data_sql['forum_last_poster_id'] = $forum_data_sql['forum_last_post_time'] = 0; $forum_data_sql['forum_last_poster_name'] = $forum_data_sql['forum_last_poster_colour'] = ''; } else if ($row['forum_type'] == FORUM_CAT && $forum_data_sql['forum_type'] == FORUM_LINK) @@ -1264,8 +1265,11 @@ class acp_forums { // Changing a category to a forum? Reset the data (you can't post directly in a cat, you must use a forum) $forum_data_sql['forum_posts'] = 0; + $forum_data_sql['forum_posts_unapproved'] = 0; + $forum_data_sql['forum_posts_softdeleted'] = 0; $forum_data_sql['forum_topics'] = 0; - $forum_data_sql['forum_topics_real'] = 0; + $forum_data_sql['forum_topics_unapproved'] = 0; + $forum_data_sql['forum_topics_softdeleted'] = 0; $forum_data_sql['forum_last_post_id'] = 0; $forum_data_sql['forum_last_post_subject'] = ''; $forum_data_sql['forum_last_post_time'] = 0; diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index 02b6b0e697..7962690ca8 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -1507,9 +1507,18 @@ function delete_post($forum_id, $topic_id, $post_id, &$data, $is_soft = false, $ { 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' : ''; + if ($data['topic_visibility'] == ITEM_APPROVED) + { + $sql_data[FORUMS_TABLE] .= 'forum_posts = forum_posts - 1, forum_topics = forum_topics - 1'; + } + else if ($data['topic_visibility'] == ITEM_UNAPPROVED) + { + $sql_data[FORUMS_TABLE] .= 'forum_posts_unapproved = forum_posts_unapproved - 1, forum_topics_unapproved = forum_topics_unapproved - 1'; + } + else if ($data['topic_visibility'] == ITEM_DELETED) + { + $sql_data[FORUMS_TABLE] .= 'forum_posts_softdeleted = forum_posts_softdeleted - 1, forum_topics_softdeleted = forum_topics_softdeleted - 1'; + } $update_sql = update_post_information('forum', $forum_id, true); if (sizeof($update_sql)) -- cgit v1.2.1 From fec72c4b782cda044b9a05122530f3a32213b407 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 23 Oct 2012 12:52:31 +0200 Subject: [feature/soft-delete] Fix mcp_move_topic() topic/post count handling PHPBB3-9567 --- phpBB/includes/mcp/mcp_main.php | 95 +++++++++++++++++++---------------------- 1 file changed, 43 insertions(+), 52 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/mcp/mcp_main.php b/phpBB/includes/mcp/mcp_main.php index 3ccd1695ad..6245a1b32b 100644 --- a/phpBB/includes/mcp/mcp_main.php +++ b/phpBB/includes/mcp/mcp_main.php @@ -455,59 +455,31 @@ function mcp_move_topic($topic_ids) $forum_sync_data[$forum_id] = current($topic_data); $forum_sync_data[$to_forum_id] = $forum_data; - // Real topics added to target forum - $topics_moved = sizeof($topic_data); - - // Approved topics added to target forum - $topics_authed_moved = 0; - - // Posts (topic replies + topic post if approved) added to target forum - $topic_posts_added = 0; - - // Posts (topic replies + topic post if approved and not global announcement) removed from source forum - $topic_posts_removed = 0; - - // Real topics removed from source forum (all topics without global announcements) - $topics_removed = 0; - - // Approved topics removed from source forum (except global announcements) - $topics_authed_removed = 0; + $topics_moved = $topics_moved_unapproved = $topics_moved_softdeleted = 0; + $posts_moved = $posts_moved_unapproved = $posts_moved_softdeleted = 0; foreach ($topic_data as $topic_id => $topic_info) { if ($topic_info['topic_visibility'] == ITEM_APPROVED) { - $topics_authed_moved++; - $topic_posts_added++; + $topics_moved++; } - - $topic_posts_added += $topic_info['topic_replies']; - - $topics_removed++; - $topic_posts_removed += $topic_info['topic_replies']; - - if ($topic_info['topic_visibility'] == ITEM_APPROVED) + elseif ($topic_info['topic_visibility'] == ITEM_UNAPPROVED) { - $topics_authed_removed++; - $topic_posts_removed++; + $topics_moved_unapproved++; + } + elseif ($topic_info['topic_visibility'] == ITEM_DELETED) + { + $topics_moved_softdeleted++; } - } - - $db->sql_transaction('begin'); - - $sync_sql = array(); - - if ($topic_posts_added) - { - $sync_sql[$to_forum_id][] = 'forum_posts = forum_posts + ' . $topic_posts_added; - } - if ($topics_authed_moved) - { - $sync_sql[$to_forum_id][] = 'forum_topics = forum_topics + ' . (int) $topics_authed_moved; + $posts_moved += $topic_info['topic_posts']; + $posts_moved_unapproved += $topic_info['topic_posts_unapproved']; + $posts_moved_softdeleted += $topic_info['topic_posts_softdeleted']; } + $topics_moved = sizeof($topic_data); - $sync_sql[$to_forum_id][] = 'forum_topics_real = forum_topics_real + ' . (int) $topics_moved; + $db->sql_transaction('begin'); // Move topics, but do not resync yet move_topics($topic_ids, $to_forum_id, false); @@ -569,26 +541,45 @@ function mcp_move_topic($topic_ids) $db->sql_query('INSERT INTO ' . TOPICS_TABLE . $db->sql_build_array('INSERT', $shadow)); // Shadow topics only count on new "topics" and not posts... a shadow topic alone has 0 posts - $topics_removed--; - $topics_authed_removed--; + $shadow_topics++; } } unset($topic_data); - //@todo: needs fixing - if ($topic_posts_removed) + $sync_sql = array(); + if ($posts_moved) { - $sync_sql[$forum_id][] = 'forum_posts = forum_posts - ' . $topic_posts_removed; + $sync_sql[$to_forum_id][] = 'forum_posts = forum_posts + ' . (int) $posts_moved; + $sync_sql[$forum_id][] = 'forum_posts = forum_posts - ' . (int) $posts_moved; } - - if ($topics_removed) + if ($posts_moved_unapproved) { - $sync_sql[$forum_id][] = 'forum_topics_real = forum_topics_real - ' . (int) $topics_removed; + $sync_sql[$to_forum_id][] = 'forum_posts_unapproved = forum_posts_unapproved + ' . (int) $posts_moved_unapproved; + $sync_sql[$forum_id][] = 'forum_posts_unapproved = forum_posts_unapproved - ' . (int) $posts_moved_unapproved; + } + if ($posts_moved_softdeleted) + { + $sync_sql[$to_forum_id][] = 'forum_posts_softdeleted = forum_posts_softdeleted + ' . (int) $posts_moved_softdeleted; + $sync_sql[$forum_id][] = 'forum_posts_softdeleted = forum_posts_softdeleted - ' . (int) $posts_moved_softdeleted; } - if ($topics_authed_removed) + if ($topics_moved) + { + $sync_sql[$to_forum_id][] = 'forum_topics = forum_topics + ' . (int) $topics_moved; + if ($topics_moved - $shadow_topics > 0) + { + $sync_sql[$forum_id][] = 'forum_topics = forum_topics - ' . (int) ($topics_moved - $shadow_topics); + } + } + if ($topics_moved_unapproved) + { + $sync_sql[$to_forum_id][] = 'forum_topics_unapproved = forum_topics_unapproved + ' . (int) $topics_moved_unapproved; + $sync_sql[$forum_id][] = 'forum_topics_unapproved = forum_topics_unapproved - ' . (int) $topics_moved_unapproved; + } + if ($topics_moved_softdeleted) { - $sync_sql[$forum_id][] = 'forum_topics = forum_topics - ' . (int) $topics_authed_removed; + $sync_sql[$to_forum_id][] = 'forum_topics_softdeleted = forum_topics_softdeleted + ' . (int) $topics_moved_softdeleted; + $sync_sql[$forum_id][] = 'forum_topics_softdeleted = forum_topics_softdeleted - ' . (int) $topics_moved_softdeleted; } $success_msg = (sizeof($topic_ids) == 1) ? 'TOPIC_MOVED_SUCCESS' : 'TOPICS_MOVED_SUCCESS'; -- cgit v1.2.1 From 43e6b3a921d45150cd5c2a931e3e14758081f321 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 23 Oct 2012 15:30:52 +0200 Subject: [feature/soft-delete] Fix some more topic/post count handling Only disapproving in queue is missing. PHPBB3-9567 --- phpBB/includes/functions_posting.php | 3 +-- phpBB/includes/mcp/mcp_main.php | 22 +++++++--------------- phpBB/includes/mcp/mcp_queue.php | 2 +- 3 files changed, 9 insertions(+), 18 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index 7962690ca8..473149a8ec 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -1491,8 +1491,7 @@ function delete_post($forum_id, $topic_id, $post_id, &$data, $is_soft = false, $ // counting is fun! we only have to do sizeof($forum_ids) number of queries, // even if the topic is moved back to where its shadow lives (we count how many times it is in a forum) $sql = 'UPDATE ' . FORUMS_TABLE . ' - SET forum_topics_real = forum_topics_real - ' . $topic_count . ', - forum_topics = forum_topics - ' . $topic_count . ' + SET forum_topics = forum_topics - ' . $topic_count . ' WHERE forum_id = ' . $updated_forum; $db->sql_query($sql); update_post_information('forum', $updated_forum); diff --git a/phpBB/includes/mcp/mcp_main.php b/phpBB/includes/mcp/mcp_main.php index 6245a1b32b..99b23e9db1 100644 --- a/phpBB/includes/mcp/mcp_main.php +++ b/phpBB/includes/mcp/mcp_main.php @@ -1097,23 +1097,15 @@ function mcp_fork_topic($topic_ids) } // Sync new topics, parent forums and board stats - sync('topic', 'topic_id', $new_topic_id_list); - - $sync_sql = array(); - - $sync_sql[$to_forum_id][] = 'forum_posts = forum_posts + ' . $total_posts; - $sync_sql[$to_forum_id][] = 'forum_topics = forum_topics + ' . sizeof($new_topic_id_list); - $sync_sql[$to_forum_id][] = 'forum_topics_real = forum_topics_real + ' . sizeof($new_topic_id_list); - - foreach ($sync_sql as $forum_id_key => $array) - { - $sql = 'UPDATE ' . FORUMS_TABLE . ' - SET ' . implode(', ', $array) . ' - WHERE forum_id = ' . $forum_id_key; - $db->sql_query($sql); - } + $sql = 'UPDATE ' . FORUMS_TABLE . ' + SET forum_posts = forum_posts + ' . $total_posts . ', + forum_topics = forum_topics + ' . sizeof($new_topic_id_list) . ' + WHERE forum_id = ' . $to_forum_id; + $db->sql_query($sql); + sync('topic', 'topic_id', $new_topic_id_list); sync('forum', 'forum_id', $to_forum_id); + set_config_count('num_topics', sizeof($new_topic_id_list), true); set_config_count('num_posts', $total_posts, true); diff --git a/phpBB/includes/mcp/mcp_queue.php b/phpBB/includes/mcp/mcp_queue.php index 3d36229ee7..c954edacb2 100644 --- a/phpBB/includes/mcp/mcp_queue.php +++ b/phpBB/includes/mcp/mcp_queue.php @@ -895,7 +895,7 @@ class mcp_queue $disapprove_log = $disapprove_log_topics = $disapprove_log_posts = array(); $topic_replies_real = $post_disapprove_list = array(); - // Build a list of posts to be unapproved and get the related topics real replies count + // Build a list of posts to be disapproved and get the related topics real replies count foreach ($post_info as $post_id => $post_data) { $post_disapprove_list[$post_id] = $post_data['topic_id']; -- cgit v1.2.1 From 727759c4d8bda3f1534b1e3366ce0eeeb27c887f Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 23 Oct 2012 22:47:57 +0200 Subject: [feature/soft-delete] Fix disapproving posts/topics in queue PHPBB3-9567 --- phpBB/includes/mcp/mcp_queue.php | 63 ++++++++++++++++++++++++++++------------ 1 file changed, 44 insertions(+), 19 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/mcp/mcp_queue.php b/phpBB/includes/mcp/mcp_queue.php index c954edacb2..cc6a90390a 100644 --- a/phpBB/includes/mcp/mcp_queue.php +++ b/phpBB/includes/mcp/mcp_queue.php @@ -52,33 +52,48 @@ class mcp_queue $post_id_list = request_var('post_id_list', array(0)); $topic_id_list = request_var('topic_id_list', array(0)); - if (!empty($post_id_list)) + if ($action != 'disapprove') { - if ($action != 'disapprove') + if (!empty($post_id_list)) { $this->approve_posts($action, $post_id_list, 'queue', $mode); } + else if (!empty($topic_id_list)) + { + $this->approve_topics($action, $topic_id_list, 'queue', $mode); + } else { - $this->disapprove_posts($post_id_list, 'queue', $mode); + trigger_error('NO_POST_SELECTED'); } } - else if (!empty($topic_id_list)) + else { - if ($action != 'disapprove') + if (!empty($topic_id_list)) { - $this->approve_topics($action, $topic_id_list, 'queue', $mode); + $sql = 'SELECT post_id + FROM ' . POSTS_TABLE . ' + WHERE post_visibility = ' . ITEM_UNAPPROVED . ' + AND ' . $db->sql_in_set('topic_id', $topic_id_list); + $result = $db->sql_query($sql); + + $post_id_list = array(); + while ($row = $db->sql_fetchrow($result)) + { + $post_id_list[] = (int) $row['post_id']; + } + $db->sql_freeresult($result); + } + + if (!empty($post_id_list)) + { + $this->disapprove_posts($post_id_list, 'queue', $mode); } else { - //@todo: $this->disapprove_posts($post_id_list, 'queue', $mode); + trigger_error('NO_POST_SELECTED'); } } - else - { - trigger_error('NO_POST_SELECTED'); - } - break; } @@ -827,7 +842,12 @@ class mcp_queue } /** - * Disapprove Post/Topic + * Disapprove Post + * + * @param $post_id_list array IDs of the posts to approve/restore + * @param $id mixed Category of the current active module + * @param $mode string Active module + * @return void */ function disapprove_posts($post_id_list, $id, $mode) { @@ -893,24 +913,29 @@ class mcp_queue if (confirm_box(true)) { $disapprove_log = $disapprove_log_topics = $disapprove_log_posts = array(); - $topic_replies_real = $post_disapprove_list = array(); + $topic_posts_unapproved = $post_disapprove_list = $topic_information = array(); // Build a list of posts to be disapproved and get the related topics real replies count foreach ($post_info as $post_id => $post_data) { $post_disapprove_list[$post_id] = $post_data['topic_id']; - if (!isset($topic_replies_real[$post_data['topic_id']])) + if (!isset($topic_posts_unapproved[$post_data['topic_id']])) { - $topic_replies_real[$post_data['topic_id']] = $post_data['topic_replies_real']; + $topic_information[$post_data['topic_id']] = $post_data; + $topic_posts_unapproved[$post_data['topic_id']] = 0; } + $topic_posts_unapproved[$post_data['topic_id']]++; } // Now we build the log array foreach ($post_disapprove_list as $post_id => $topic_id) { - // If the count of disapproved posts for the topic is greater - // than topic's real replies count, the whole topic is disapproved/deleted - if (sizeof(array_keys($post_disapprove_list, $topic_id)) > $topic_replies_real[$topic_id]) + // If the count of disapproved posts for the topic is equal + // to the number of unapproved posts in the topic, and there are no different + // posts, we disapprove the hole topic + if ($topic_information[$topic_id]['topic_posts'] == 0 && + $topic_information[$topic_id]['topic_posts_softdeleted'] == 0 && + $topic_information[$topic_id]['topic_posts_unapproved'] == $topic_posts_unapproved[$topic_id]) { // Don't write the log more than once for every topic if (!isset($disapprove_log_topics[$topic_id])) -- cgit v1.2.1 From b3d5f2b4e42404610f5db8dda25859db942fd60e Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 23 Oct 2012 23:37:25 +0200 Subject: [feature/soft-delete] Fix unit tests for delete_posts() PHPBB3-9567 --- phpBB/includes/content_visibility.php | 71 +++++++++++++++++++++++++++-------- phpBB/includes/functions_admin.php | 2 - 2 files changed, 56 insertions(+), 17 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/content_visibility.php b/phpBB/includes/content_visibility.php index 20e743a4c4..da7e6b9c4f 100644 --- a/phpBB/includes/content_visibility.php +++ b/phpBB/includes/content_visibility.php @@ -348,34 +348,75 @@ class phpbb_content_visibility // Update the topic's reply count and the forum's post count if ($update_topic_postcount) { - $num_posts = 0; + $cur_posts = $cur_unapproved_posts = $cur_softdeleted_posts = 0; foreach ($postcount_visibility as $post_visibility => $visibility_posts) { - // If we soft delete, we need to substract approved posts from the counters ... - if ($post_visibility == ITEM_APPROVED && $visibility == ITEM_DELETED) + // We need to substract the posts from the counters ... + if ($post_visibility == ITEM_APPROVED) { - $num_posts += $visibility_posts; + $cur_posts += $visibility_posts; } - // ... and when we approve/restore, all others. - else if ($post_visibility != ITEM_APPROVED && $visibility == ITEM_APPROVED) + else if ($post_visibility == ITEM_UNAPPROVED) { - $num_posts += $visibility_posts; + $cur_unapproved_posts += $visibility_posts; + } + else if ($post_visibility == ITEM_DELETED) + { + $cur_softdeleted_posts += $visibility_posts; + } + } + + $sql_ary = array(); + if ($visibility == ITEM_DELETED) + { + if ($cur_posts) + { + $sql_ary['posts'] = ' - ' . $cur_posts; + } + if ($cur_unapproved_posts) + { + $sql_ary['posts_unapproved'] = ' - ' . $cur_unapproved_posts; + } + if ($cur_posts + $cur_unapproved_posts) + { + $sql_ary['posts_softdeleted'] = ' + ' . ($cur_posts + $cur_unapproved_posts); + } + } + else + { + if ($cur_unapproved_posts) + { + $sql_ary['posts_unapproved'] = ' - ' . $cur_unapproved_posts; + } + if ($cur_softdeleted_posts) + { + $sql_ary['posts_softdeleted'] = ' - ' . $cur_softdeleted_posts; + } + if ($cur_posts + $cur_unapproved_posts) + { + $sql_ary['posts'] = ' + ' . ($cur_softdeleted_posts + $cur_unapproved_posts); } } - if ($num_posts) + if (sizeof($sql_ary)) { - $sql_num_posts = (($visibility == ITEM_DELETED) ? ' - ' : ' + ') . $num_posts; + $topic_sql = $forum_sql = array(); + + foreach ($sql_ary as $field => $value_change) + { + $topic_sql[] = 'topic_' . $field . ' = topic_' . $field . $value_change; + $forum_sql[] = 'forum_' . $field . ' = forum_' . $field . $value_change; + } // Update the number for replies and posts - $sql = 'UPDATE ' . TOPICS_TABLE . " - SET topic_replies = topic_replies $sql_num_posts - WHERE topic_id = $topic_id"; + $sql = 'UPDATE ' . TOPICS_TABLE . ' + SET ' . implode(', ', $topic_sql) . ' + WHERE topic_id = ' . $topic_id; $db->sql_query($sql); - $sql = 'UPDATE ' . FORUMS_TABLE . " - SET forum_posts = forum_posts $sql_num_posts - WHERE forum_id = $forum_id"; + $sql = 'UPDATE ' . FORUMS_TABLE . ' + SET ' . implode(', ', $forum_sql) . ' + WHERE forum_id = ' . $forum_id; $db->sql_query($sql); } } diff --git a/phpBB/includes/functions_admin.php b/phpBB/includes/functions_admin.php index a38fa2a70f..e2a133270b 100644 --- a/phpBB/includes/functions_admin.php +++ b/phpBB/includes/functions_admin.php @@ -1729,7 +1729,6 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false, $sql = 'SELECT SUM(t.topic_posts) AS forum_posts, SUM(t.topic_posts_unapproved) AS forum_posts_unapproved, SUM(t.topic_posts_softdeleted) AS forum_posts_softdeleted FROM ' . TOPICS_TABLE . ' t WHERE ' . $db->sql_in_set('t.forum_id', $forum_ids) . ' - AND t.topic_visibility = ' . ITEM_APPROVED . ' AND t.topic_status <> ' . ITEM_MOVED; } else @@ -1737,7 +1736,6 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false, $sql = 'SELECT t.forum_id, SUM(t.topic_posts) AS forum_posts, SUM(t.topic_posts_unapproved) AS forum_posts_unapproved, SUM(t.topic_posts_softdeleted) AS forum_posts_softdeleted FROM ' . TOPICS_TABLE . ' t WHERE ' . $db->sql_in_set('t.forum_id', $forum_ids) . ' - AND t.topic_visibility = ' . ITEM_APPROVED . ' AND t.topic_status <> ' . ITEM_MOVED . ' GROUP BY t.forum_id'; } -- 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/includes/content_visibility.php | 1 + 1 file changed, 1 insertion(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/content_visibility.php b/phpBB/includes/content_visibility.php index da7e6b9c4f..6dffe73114 100644 --- a/phpBB/includes/content_visibility.php +++ b/phpBB/includes/content_visibility.php @@ -225,6 +225,7 @@ class phpbb_content_visibility { $where_sql .= ' AND post_visibility = ' . (int) $limit_visibility; } + if ($limit_delete_time !== false) { $where_sql .= ' AND post_delete_time = ' . (int) $limit_delete_time; -- 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/includes/mcp/mcp_main.php | 137 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 129 insertions(+), 8 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/mcp/mcp_main.php b/phpBB/includes/mcp/mcp_main.php index 99b23e9db1..6756e19078 100644 --- a/phpBB/includes/mcp/mcp_main.php +++ b/phpBB/includes/mcp/mcp_main.php @@ -33,7 +33,7 @@ class mcp_main function main($id, $mode) { global $auth, $db, $user, $template, $action; - global $config, $phpbb_root_path, $phpEx; + global $config, $phpbb_root_path, $phpEx, $request; $quickmod = ($mode == 'quickmod') ? true : false; @@ -108,14 +108,18 @@ class mcp_main case 'delete_topic': $user->add_lang('viewtopic'); + // 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); $topic_ids = (!$quickmod) ? request_var('topic_id_list', array(0)) : array(request_var('t', 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($topic_ids)) { trigger_error('NO_TOPIC_SELECTED'); } - mcp_delete_topic($topic_ids); + mcp_delete_topic($topic_ids, $soft_delete, ($soft_delete) ? request_var('delete_reason', '', true) : ''); break; case 'delete_post': @@ -130,6 +134,19 @@ class mcp_main mcp_delete_post($post_ids); break; + + case 'restore_topic': + $user->add_lang('posting'); + + $topic_ids = (!$quickmod) ? request_var('topic_id_list', array(0)) : array(request_var('t', 0)); + + if (!sizeof($topic_ids)) + { + trigger_error('NO_TOPIC_SELECTED'); + } + + mcp_restore_topic($topic_ids); + break; } switch ($mode) @@ -628,10 +645,82 @@ function mcp_move_topic($topic_ids) } } +/** +* Restore Topics +*/ +function mcp_restore_topic($topic_ids) +{ + global $auth, $user, $db, $phpEx, $phpbb_root_path; + + if (!check_ids($topic_ids, TOPICS_TABLE, 'topic_id', array('m_approve'))) + { + return; + } + + $redirect = request_var('redirect', build_url(array('action', 'quickmod'))); + $forum_id = request_var('f', 0); + + $s_hidden_fields = build_hidden_fields(array( + 'topic_id_list' => $topic_ids, + 'f' => $forum_id, + 'action' => 'restore_topic', + 'redirect' => $redirect, + )); + $success_msg = ''; + + if (confirm_box(true)) + { + $success_msg = (sizeof($topic_ids) == 1) ? 'TOPIC_RESTORED_SUCCESS' : 'TOPICS_RESTORED_SUCCESS'; + + $data = get_topic_data($topic_ids); + + foreach ($data as $topic_id => $row) + { + $return = phpbb_content_visibility::set_topic_visibility(ITEM_APPROVED, $topic_id, $row['forum_id'], $user->data['user_id'], time(), ''); + if (!empty($return)) + { + add_log('mod', $row['forum_id'], $topic_id, 'LOG_RESTORE_TOPIC', $row['topic_title'], $row['topic_first_poster_name']); + } + } + } + else + { + confirm_box(false, (sizeof($topic_ids) == 1) ? 'RESTORE_TOPIC' : 'RESTORE_TOPICS', $s_hidden_fields); + } + + $topic_id = request_var('t', 0); + if (!isset($_REQUEST['quickmod'])) + { + $redirect = request_var('redirect', "index.$phpEx"); + $redirect = reapply_sid($redirect); + $redirect_message = 'PAGE'; + } + else if ($topic_id) + { + $redirect = append_sid("{$phpbb_root_path}viewtopic.$phpEx", 't=' . $topic_id); + $redirect_message = 'TOPIC'; + } + else + { + $redirect = append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id); + $redirect_message = 'FORUM'; + } + + if (!$success_msg) + { + redirect($redirect); + } + else + { + meta_refresh(3, $redirect); + trigger_error($user->lang[$success_msg] . '

' . sprintf($user->lang['RETURN_' . $redirect_message], '', '')); + } +} + /** * Delete Topics */ -function mcp_delete_topic($topic_ids) +function mcp_delete_topic($topic_ids, $is_soft = false, $soft_delete_reason = '') { global $auth, $user, $db, $phpEx, $phpbb_root_path; @@ -647,8 +736,8 @@ function mcp_delete_topic($topic_ids) 'topic_id_list' => $topic_ids, 'f' => $forum_id, 'action' => 'delete_topic', - 'redirect' => $redirect) - ); + 'redirect' => $redirect, + )); $success_msg = ''; if (confirm_box(true)) @@ -665,23 +754,55 @@ function mcp_delete_topic($topic_ids) } else { - add_log('mod', $row['forum_id'], $topic_id, 'LOG_DELETE_TOPIC', $row['topic_title'], $row['topic_first_poster_name']); + // Only soft delete non-shadow topics + if ($is_soft) + { + $return = phpbb_content_visibility::set_topic_visibility(ITEM_DELETED, $topic_id, $row['forum_id'], $user->data['user_id'], time(), $soft_delete_reason); + if (!empty($return)) + { + add_log('mod', $row['forum_id'], $topic_id, 'LOG_SOFTDELETE_TOPIC', $row['topic_title'], $row['topic_first_poster_name']); + } + } + else + { + add_log('mod', $row['forum_id'], $topic_id, 'LOG_DELETE_TOPIC', $row['topic_title'], $row['topic_first_poster_name']); + } } } - $return = delete_topics('topic_id', $topic_ids); + if (!$is_soft) + { + $return = delete_topics('topic_id', $topic_ids); + } } else { - confirm_box(false, (sizeof($topic_ids) == 1) ? 'DELETE_TOPIC' : 'DELETE_TOPICS', $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($topic_ids) == 1) ? 'DELETE_TOPIC' : 'DELETE_TOPICS', $s_hidden_fields, 'posting_delete_post_body.html'); } + $topic_id = request_var('t', 0); if (!isset($_REQUEST['quickmod'])) { $redirect = request_var('redirect', "index.$phpEx"); $redirect = reapply_sid($redirect); $redirect_message = 'PAGE'; } + else if ($is_soft && $topic_id) + { + $redirect = append_sid("{$phpbb_root_path}viewtopic.$phpEx", 't=' . $topic_id); + $redirect_message = 'TOPIC'; + } else { $redirect = append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id); -- cgit v1.2.1 From ed602857e6c5aee7b9958a3dbc9285c309b33420 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 28 Oct 2012 22:37:00 +0100 Subject: [feature/soft-delete] Correctly increase topics post counts when posting PHPBB3-9567 --- phpBB/includes/functions_posting.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index 473149a8ec..807b178a4c 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -1879,6 +1879,8 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u 'topic_last_view_time' => $current_time, 'forum_id' => $data['forum_id'], 'icon_id' => $data['icon_id'], + 'topic_posts' => ($post_visibility == ITEM_APPROVED) ? 1 : 0, + 'topic_posts_softdeleted' => ($post_visibility != ITEM_APPROVED) ? 1 : 0, 'topic_visibility' => $post_visibility, 'topic_delete_user' => ($post_visibility != ITEM_APPROVED) ? (int) $user->data['user_id'] : 0, 'topic_title' => $subject, -- cgit v1.2.1 From f0e2d21f8c15544ba59297788cd9e59e743ddbbb Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 30 Oct 2012 21:46:04 +0100 Subject: [feature/soft-delete] Allow to soft delete posts in the MCP quick moderation PHPBB3-9567 --- phpBB/includes/mcp/mcp_main.php | 90 +++++++++++++++++++++++++++++++++++++--- phpBB/includes/mcp/mcp_topic.php | 4 +- 2 files changed, 88 insertions(+), 6 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/mcp/mcp_main.php b/phpBB/includes/mcp/mcp_main.php index 6756e19078..bb2dd7d63d 100644 --- a/phpBB/includes/mcp/mcp_main.php +++ b/phpBB/includes/mcp/mcp_main.php @@ -125,14 +125,18 @@ class mcp_main case 'delete_post': $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)); + $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)) { 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; case 'restore_topic': @@ -823,11 +827,11 @@ function mcp_delete_topic($topic_ids, $is_soft = false, $soft_delete_reason = '' /** * 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; - 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; } @@ -843,7 +847,72 @@ function mcp_delete_post($post_ids) ); $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'], '', ''); + } + $return_link[] = sprintf($user->lang['RETURN_FORUM'], '', ''); + + } + else if (confirm_box(true)) { if (!function_exists('delete_posts')) { @@ -924,7 +993,18 @@ function mcp_delete_post($post_ids) } 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"); diff --git a/phpBB/includes/mcp/mcp_topic.php b/phpBB/includes/mcp/mcp_topic.php index 0259a12ca8..0d768bcce9 100644 --- a/phpBB/includes/mcp/mcp_topic.php +++ b/phpBB/includes/mcp/mcp_topic.php @@ -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'), '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_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'), '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'), 'S_MCP_ACTION' => "$url&i=$id&mode=$mode&action=$action&start=$start", -- cgit v1.2.1 From 18dec1026ad8cc5dea6117ca1336ca9eba41aa2a Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 31 Oct 2012 14:09:23 +0100 Subject: [feature/soft-delete] Fix restoring/approving posts with mcp moderation PHPBB3-9567 --- phpBB/includes/mcp/mcp_queue.php | 16 ++++++++-------- phpBB/includes/mcp/mcp_topic.php | 18 ++++++++++++------ 2 files changed, 20 insertions(+), 14 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/mcp/mcp_queue.php b/phpBB/includes/mcp/mcp_queue.php index cc6a90390a..5fe09a2524 100644 --- a/phpBB/includes/mcp/mcp_queue.php +++ b/phpBB/includes/mcp/mcp_queue.php @@ -25,12 +25,12 @@ class mcp_queue var $p_master; var $u_action; - function mcp_queue(&$p_master) + public function mcp_queue(&$p_master) { $this->p_master = &$p_master; } - function main($id, $mode) + public function main($id, $mode) { global $auth, $db, $user, $template, $cache; global $config, $phpbb_root_path, $phpEx, $action; @@ -56,11 +56,11 @@ class mcp_queue { if (!empty($post_id_list)) { - $this->approve_posts($action, $post_id_list, 'queue', $mode); + self::approve_posts($action, $post_id_list, 'queue', $mode); } else if (!empty($topic_id_list)) { - $this->approve_topics($action, $topic_id_list, 'queue', $mode); + self::approve_topics($action, $topic_id_list, 'queue', $mode); } else { @@ -87,7 +87,7 @@ class mcp_queue if (!empty($post_id_list)) { - $this->disapprove_posts($post_id_list, 'queue', $mode); + self::disapprove_posts($post_id_list, 'queue', $mode); } else { @@ -493,7 +493,7 @@ class mcp_queue * @param $mode string Active module * @return void */ - function approve_posts($action, $post_id_list, $id, $mode) + static public function approve_posts($action, $post_id_list, $id, $mode) { global $db, $template, $user, $config; global $phpEx, $phpbb_root_path, $request; @@ -686,7 +686,7 @@ class mcp_queue * @param $mode string Active module * @return void */ - function approve_topics($action, $topic_id_list, $id, $mode) + static public function approve_topics($action, $topic_id_list, $id, $mode) { global $db, $template, $user, $config; global $phpEx, $phpbb_root_path, $request; @@ -849,7 +849,7 @@ class mcp_queue * @param $mode string Active module * @return void */ - function disapprove_posts($post_id_list, $id, $mode) + static public function disapprove_posts($post_id_list, $id, $mode) { global $db, $template, $user, $config; global $phpEx, $phpbb_root_path; diff --git a/phpBB/includes/mcp/mcp_topic.php b/phpBB/includes/mcp/mcp_topic.php index 0d768bcce9..3b13506862 100644 --- a/phpBB/includes/mcp/mcp_topic.php +++ b/phpBB/includes/mcp/mcp_topic.php @@ -84,8 +84,8 @@ function mcp_topic_view($id, $mode, $action) $subject = $topic_info['topic_title']; } - // Approve posts? - if ($action == 'approve' && $auth->acl_get('m_approve', $topic_info['forum_id'])) + // Restore or pprove posts? + if (($action == 'restore' || $action == 'approve') && $auth->acl_get('m_approve', $topic_info['forum_id'])) { include($phpbb_root_path . 'includes/mcp/mcp_queue.' . $phpEx); include_once($phpbb_root_path . 'includes/functions_posting.' . $phpEx); @@ -98,7 +98,7 @@ function mcp_topic_view($id, $mode, $action) if (!$sort) { - approve_post($post_id_list, $id, $mode); + mcp_queue::approve_posts($action, $post_id_list, $id, $mode); } } @@ -175,7 +175,7 @@ function mcp_topic_view($id, $mode, $action) $topic_tracking_info = get_complete_topic_tracking($topic_info['forum_id'], $topic_id); } - $has_unapproved_posts = false; + $has_unapproved_posts = $has_deleted_posts = false; // Grab extensions $extensions = $attachments = array(); @@ -225,6 +225,11 @@ function mcp_topic_view($id, $mode, $action) $has_unapproved_posts = true; } + if ($row['post_visibility'] == ITEM_DELETED) + { + $has_deleted_posts = true; + } + $post_unread = (isset($topic_tracking_info[$topic_id]) && $row['post_time'] > $topic_tracking_info[$topic_id]) ? true : false; $template->assign_block_vars('postrow', array( @@ -305,7 +310,7 @@ function mcp_topic_view($id, $mode, $action) { phpbb_generate_template_pagination($template, $base_url, 'pagination', 'start', $total, $posts_per_page, $start); } - + $template->assign_vars(array( 'TOPIC_TITLE' => $topic_info['topic_title'], 'U_VIEW_TOPIC' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $topic_info['forum_id'] . '&t=' . $topic_info['topic_id']), @@ -319,7 +324,7 @@ function mcp_topic_view($id, $mode, $action) 'REPORTED_IMG' => $user->img('icon_topic_reported', 'POST_REPORTED'), 'UNAPPROVED_IMG' => $user->img('icon_topic_unapproved', 'POST_UNAPPROVED'), - 'DELETED_IMG' => $user->img('icon_topic_deleted', 'POST_DELETED'), + 'DELETED_IMG' => $user->img('icon_topic_deleted', 'POST_DELETED'), 'INFO_IMG' => $user->img('icon_post_info', 'VIEW_INFO'), 'S_MCP_ACTION' => "$url&i=$id&mode=$mode&action=$action&start=$start", @@ -328,6 +333,7 @@ function mcp_topic_view($id, $mode, $action) 'S_CAN_MERGE' => ($auth->acl_get('m_merge', $topic_info['forum_id'])) ? true : false, 'S_CAN_DELETE' => ($auth->acl_get('m_delete', $topic_info['forum_id'])) ? true : false, 'S_CAN_APPROVE' => ($has_unapproved_posts && $auth->acl_get('m_approve', $topic_info['forum_id'])) ? true : false, + 'S_CAN_RESTORE' => ($has_deleted_posts && $auth->acl_get('m_approve', $topic_info['forum_id'])) ? true : false, 'S_CAN_LOCK' => ($auth->acl_get('m_lock', $topic_info['forum_id'])) ? true : false, 'S_CAN_REPORT' => ($auth->acl_get('m_report', $topic_info['forum_id'])) ? true : false, 'S_CAN_SYNC' => $auth->acl_get('m_', $topic_info['forum_id']), -- 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/includes/mcp/mcp_main.php | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/mcp/mcp_main.php b/phpBB/includes/mcp/mcp_main.php index bb2dd7d63d..c7e2252729 100644 --- a/phpBB/includes/mcp/mcp_main.php +++ b/phpBB/includes/mcp/mcp_main.php @@ -785,7 +785,21 @@ function mcp_delete_topic($topic_ids, $is_soft = false, $soft_delete_reason = '' $user->add_lang('posting'); + $only_softdeleted = false; + // If there are only soft deleted topics, we display a message why the option is not available + if ($auth->acl_get('m_delete', $forum_id) && $auth->acl_get('m_softdelete', $forum_id)) + { + $sql = 'SELECT topic_id + FROM ' . TOPICS_TABLE . ' + WHERE ' . $db->sql_in_set('topic_id', $topic_ids) . ' + AND topic_visibility <> ' . ITEM_DELETED; + $result = $db->sql_query_limit($sql, 1); + $only_softdeleted = (bool) $db->sql_fetchfield('topic_id'); + $db->sql_freeresult($result); + } + $template->assign_vars(array( + 'S_SOFTDELETED' => $only_softdeleted, 'S_TOPIC_MODE' => true, 'S_ALLOWED_DELETE' => $auth->acl_get('m_delete', $forum_id), 'S_ALLOWED_SOFTDELETE' => $auth->acl_get('m_softdelete', $forum_id), @@ -997,8 +1011,21 @@ function mcp_delete_post($post_ids, $is_soft = false, $soft_delete_reason = '') $user->add_lang('posting'); + $only_softdeleted = false; + // If there are only soft deleted posts, we display a message why the option is not available + if ($auth->acl_get('m_delete', $forum_id) && $auth->acl_get('m_softdelete', $forum_id)) + { + $sql = 'SELECT post_id + FROM ' . POSTS_TABLE . ' + WHERE ' . $db->sql_in_set('post_id', $post_ids) . ' + AND post_visibility <> ' . ITEM_DELETED; + $result = $db->sql_query_limit($sql, 1); + $only_softdeleted = (bool) $db->sql_fetchfield('post_id'); + $db->sql_freeresult($result); + } + $template->assign_vars(array( - 'S_TOPIC_MODE' => true, + 'S_SOFTDELETED' => $only_softdeleted, '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), -- 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/includes/mcp/mcp_main.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/mcp/mcp_main.php b/phpBB/includes/mcp/mcp_main.php index c7e2252729..72c1be95b2 100644 --- a/phpBB/includes/mcp/mcp_main.php +++ b/phpBB/includes/mcp/mcp_main.php @@ -806,7 +806,10 @@ function mcp_delete_topic($topic_ids, $is_soft = false, $soft_delete_reason = '' 'S_DELETE_REASON' => $auth->acl_get('m_softdelete', $forum_id), )); - confirm_box(false, (sizeof($topic_ids) == 1) ? 'DELETE_TOPIC' : 'DELETE_TOPICS', $s_hidden_fields, 'posting_delete_post_body.html'); + $l_confirm = (sizeof($post_ids) == 1) ? 'DELETE_TOPIC' : 'DELETE_TOPICS'; + $l_confirm .= ($only_softdeleted) ? '_PERMANENTLY' : ''; + + confirm_box(false, $l_confirm, $s_hidden_fields, 'confirm_delete_body.html'); } $topic_id = request_var('t', 0); @@ -1031,7 +1034,10 @@ function mcp_delete_post($post_ids, $is_soft = false, $soft_delete_reason = '') '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'); + $l_confirm = (sizeof($post_ids) == 1) ? 'DELETE_POST' : 'DELETE_POSTS'; + $l_confirm .= ($only_softdeleted) ? '_PERMANENTLY' : ''; + + confirm_box(false, $l_confirm, $s_hidden_fields, 'confirm_delete_body.html'); } $redirect = request_var('redirect', "index.$phpEx"); -- 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/includes/content_visibility.php | 6 +++--- phpBB/includes/functions_admin.php | 2 +- phpBB/includes/functions_posting.php | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/content_visibility.php b/phpBB/includes/content_visibility.php index 6dffe73114..8f7e86cdf5 100644 --- a/phpBB/includes/content_visibility.php +++ b/phpBB/includes/content_visibility.php @@ -537,12 +537,12 @@ class phpbb_content_visibility */ static public function remove_post_from_statistic($data, &$sql_data) { - $sql_data[TOPICS_TABLE] = (($sql_data[TOPICS_TABLE]) ? $sql_data[TOPICS_TABLE] . ', ' : '') . 'topic_posts = topic_posts - 1'; - $sql_data[FORUMS_TABLE] = (($sql_data[FORUMS_TABLE]) ? $sql_data[FORUMS_TABLE] . ', ' : '') . 'forum_posts = forum_posts - 1'; + $sql_data[TOPICS_TABLE] = ((!empty($sql_data[TOPICS_TABLE])) ? $sql_data[TOPICS_TABLE] . ', ' : '') . 'topic_posts = topic_posts - 1'; + $sql_data[FORUMS_TABLE] = ((!empty($sql_data[FORUMS_TABLE])) ? $sql_data[FORUMS_TABLE] . ', ' : '') . 'forum_posts = forum_posts - 1'; if ($data['post_postcount']) { - $sql_data[USERS_TABLE] = (($sql_data[USERS_TABLE]) ? $sql_data[USERS_TABLE] . ', ' : '') . 'user_posts = user_posts - 1'; + $sql_data[USERS_TABLE] = ((!empty($sql_data[USERS_TABLE])) ? $sql_data[USERS_TABLE] . ', ' : '') . 'user_posts = user_posts - 1'; } set_config_count('num_posts', -1, true); diff --git a/phpBB/includes/functions_admin.php b/phpBB/includes/functions_admin.php index e2a133270b..f1c3cf62b1 100644 --- a/phpBB/includes/functions_admin.php +++ b/phpBB/includes/functions_admin.php @@ -881,7 +881,7 @@ function delete_posts($where_type, $where_ids, $auto_sync = true, $posted_sync = sync('forum', 'forum_id', $forum_ids, true, true); } - if ($approved_posts) + if ($approved_posts && $post_count_sync) { set_config_count('num_posts', $approved_posts * (-1), true); } diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index 807b178a4c..8e8e3aac9f 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -1467,7 +1467,7 @@ function delete_post($forum_id, $topic_id, $post_id, &$data, $is_soft = false, $ } else if (!$is_soft) { - if (!delete_posts('post_id', array($post_id), false, false)) + if (!delete_posts('post_id', array($post_id), false, false, false)) { // Try to delete topic, we may had an previous error causing inconsistency if ($post_mode == 'delete_topic') @@ -1625,8 +1625,8 @@ function delete_post($forum_id, $topic_id, $post_id, &$data, $is_soft = false, $ } else if ($data['post_visibility'] == ITEM_DELETED) { - $sql_data[FORUMS_TABLE] = (($sql_data[FORUMS_TABLE]) ? $sql_data[FORUMS_TABLE] . ', ' : '') . 'forum_posts_deleted = forum_posts_deleted - 1'; - $sql_data[TOPICS_TABLE] = (($sql_data[TOPICS_TABLE]) ? $sql_data[TOPICS_TABLE] . ', ' : '') . 'topic_posts_deleted = topic_posts_deleted - 1'; + $sql_data[FORUMS_TABLE] = (($sql_data[FORUMS_TABLE]) ? $sql_data[FORUMS_TABLE] . ', ' : '') . 'forum_posts_softdeleted = forum_posts_softdeleted - 1'; + $sql_data[TOPICS_TABLE] = (($sql_data[TOPICS_TABLE]) ? $sql_data[TOPICS_TABLE] . ', ' : '') . 'topic_posts_softdeleted = topic_posts_softdeleted - 1'; } } @@ -2030,7 +2030,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u 'topic_last_post_id' => $data['post_id'], 'topic_last_post_time' => $current_time, 'topic_last_poster_id' => $sql_data[POSTS_TABLE]['sql']['poster_id'], - 'topic_last_poster_name' => $sql_data[POSTS_TABLE]['sql']['post_username'], + 'topic_last_poster_name' => ($user->data['user_id'] == ANONYMOUS) ? $sql_data[POSTS_TABLE]['sql']['post_username'] : $user->data['username'], 'topic_last_poster_colour' => $user->data['user_colour'], 'topic_last_post_subject' => (string) $subject, ); -- cgit v1.2.1 From 6999d776d48831a48fa7f2882c7bbf767308e512 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 2 Nov 2012 14:23:17 +0100 Subject: [feature/soft-delete] Correctly manage soft deleting via MCP PHPBB3-9567 --- phpBB/includes/mcp/mcp_main.php | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/mcp/mcp_main.php b/phpBB/includes/mcp/mcp_main.php index 72c1be95b2..4a0b6091fe 100644 --- a/phpBB/includes/mcp/mcp_main.php +++ b/phpBB/includes/mcp/mcp_main.php @@ -112,7 +112,7 @@ class mcp_main // 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); $topic_ids = (!$quickmod) ? request_var('topic_id_list', array(0)) : array(request_var('t', 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; + $soft_delete = (($request->is_set_post('confirm') && !$request->is_set_post('delete_permanent')) || !$auth->acl_get('m_delete', $forum_id)) ? true : false; if (!sizeof($topic_ids)) { @@ -129,7 +129,7 @@ class mcp_main // 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)); - $soft_delete = (($auth->acl_get('m_softdelete', $forum_id) && $request->is_set_post('soft_delete')) || !$auth->acl_get('m_delete', $forum_id)) ? true : false; + $soft_delete = (($request->is_set_post('confirm') && !$request->is_set_post('delete_permanent')) || !$auth->acl_get('m_delete', $forum_id)) ? true : false; if (!sizeof($post_ids)) { @@ -736,12 +736,12 @@ function mcp_delete_topic($topic_ids, $is_soft = false, $soft_delete_reason = '' $redirect = request_var('redirect', build_url(array('action', 'quickmod'))); $forum_id = request_var('f', 0); - $s_hidden_fields = build_hidden_fields(array( + $s_hidden_fields = array( 'topic_id_list' => $topic_ids, 'f' => $forum_id, 'action' => 'delete_topic', 'redirect' => $redirect, - )); + ); $success_msg = ''; if (confirm_box(true)) @@ -807,9 +807,17 @@ function mcp_delete_topic($topic_ids, $is_soft = false, $soft_delete_reason = '' )); $l_confirm = (sizeof($post_ids) == 1) ? 'DELETE_TOPIC' : 'DELETE_TOPICS'; - $l_confirm .= ($only_softdeleted) ? '_PERMANENTLY' : ''; + if ($only_softdeleted) + { + $l_confirm .= '_PERMANENTLY'; + $s_hidden_fields['delete_permanent'] = '1'; + } + else if (!$auth->acl_get('m_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'); } $topic_id = request_var('t', 0); @@ -856,11 +864,11 @@ function mcp_delete_post($post_ids, $is_soft = false, $soft_delete_reason = '') $redirect = request_var('redirect', build_url(array('action', 'quickmod'))); $forum_id = request_var('f', 0); - $s_hidden_fields = build_hidden_fields(array( + $s_hidden_fields = array( 'post_id_list' => $post_ids, 'f' => $forum_id, 'action' => 'delete_post', - 'redirect' => $redirect) + 'redirect' => $redirect, ); $success_msg = ''; @@ -1035,9 +1043,17 @@ function mcp_delete_post($post_ids, $is_soft = false, $soft_delete_reason = '') )); $l_confirm = (sizeof($post_ids) == 1) ? 'DELETE_POST' : 'DELETE_POSTS'; - $l_confirm .= ($only_softdeleted) ? '_PERMANENTLY' : ''; + if ($only_softdeleted) + { + $l_confirm .= '_PERMANENTLY'; + $s_hidden_fields['delete_permanent'] = '1'; + } + else if (!$auth->acl_get('m_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'); } $redirect = request_var('redirect', "index.$phpEx"); -- cgit v1.2.1 From 334265fc839f95d24cce44ec675ae8cef7b4bfaa Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 3 Nov 2012 22:57:49 +0100 Subject: [feature/soft-delete] Fix displaying the button/permission When the post is already softdeleted the options should only be available if *_delete is granted. PHPBB3-9567 --- phpBB/includes/functions_display.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_display.php b/phpBB/includes/functions_display.php index ed91d9ad1c..6f166e2a14 100644 --- a/phpBB/includes/functions_display.php +++ b/phpBB/includes/functions_display.php @@ -788,7 +788,7 @@ function gen_forum_auth_level($mode, $forum_id, $forum_status) ($auth->acl_get('f_post', $forum_id) && !$locked) ? $user->lang['RULES_POST_CAN'] : $user->lang['RULES_POST_CANNOT'], ($auth->acl_get('f_reply', $forum_id) && !$locked) ? $user->lang['RULES_REPLY_CAN'] : $user->lang['RULES_REPLY_CANNOT'], ($user->data['is_registered'] && $auth->acl_gets('f_edit', 'm_edit', $forum_id) && !$locked) ? $user->lang['RULES_EDIT_CAN'] : $user->lang['RULES_EDIT_CANNOT'], - ($user->data['is_registered'] && $auth->acl_gets('f_delete', 'm_delete', $forum_id) && !$locked) ? $user->lang['RULES_DELETE_CAN'] : $user->lang['RULES_DELETE_CANNOT'], + ($user->data['is_registered'] && ($auth->acl_gets('f_delete', 'm_delete', $forum_id) || $auth->acl_gets('f_softdelete', 'm_softdelete', $forum_id)) && !$locked) ? $user->lang['RULES_DELETE_CAN'] : $user->lang['RULES_DELETE_CANNOT'], ); if ($config['allow_attachments']) -- cgit v1.2.1 From 269330749f1e456caf5c2e787448820449586ed4 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 3 Nov 2012 23:37:35 +0100 Subject: [feature/soft-delete] Fix naming of soft delete (we wont use that in the UI) PHPBB3-9567 --- phpBB/includes/mcp/mcp_topic.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/mcp/mcp_topic.php b/phpBB/includes/mcp/mcp_topic.php index 3b13506862..cea5b9db8c 100644 --- a/phpBB/includes/mcp/mcp_topic.php +++ b/phpBB/includes/mcp/mcp_topic.php @@ -324,7 +324,7 @@ function mcp_topic_view($id, $mode, $action) 'REPORTED_IMG' => $user->img('icon_topic_reported', 'POST_REPORTED'), 'UNAPPROVED_IMG' => $user->img('icon_topic_unapproved', 'POST_UNAPPROVED'), - 'DELETED_IMG' => $user->img('icon_topic_deleted', 'POST_DELETED'), + 'DELETED_IMG' => $user->img('icon_topic_deleted', 'POST_DELETED_RESTORE'), 'INFO_IMG' => $user->img('icon_post_info', 'VIEW_INFO'), 'S_MCP_ACTION' => "$url&i=$id&mode=$mode&action=$action&start=$start", -- cgit v1.2.1 From bb173afe3fee816dab9d11764a8b9ff53dc5a1df Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 8 Nov 2012 22:17:59 +0100 Subject: [feature/soft-delete] Fix adding posts to *_posts when restoring soft deleted PHPBB3-9567 --- phpBB/includes/content_visibility.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/content_visibility.php b/phpBB/includes/content_visibility.php index 8f7e86cdf5..a1b7c16c2d 100644 --- a/phpBB/includes/content_visibility.php +++ b/phpBB/includes/content_visibility.php @@ -393,7 +393,7 @@ class phpbb_content_visibility { $sql_ary['posts_softdeleted'] = ' - ' . $cur_softdeleted_posts; } - if ($cur_posts + $cur_unapproved_posts) + if ($cur_softdeleted_posts + $cur_unapproved_posts) { $sql_ary['posts'] = ' + ' . ($cur_softdeleted_posts + $cur_unapproved_posts); } -- 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/includes/mcp/mcp_main.php | 50 ++++++++++++++++++++-------------------- phpBB/includes/mcp/mcp_queue.php | 31 ++++++++++++------------- 2 files changed, 40 insertions(+), 41 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/mcp/mcp_main.php b/phpBB/includes/mcp/mcp_main.php index 4a0b6091fe..945b80ba41 100644 --- a/phpBB/includes/mcp/mcp_main.php +++ b/phpBB/includes/mcp/mcp_main.php @@ -110,8 +110,8 @@ class mcp_main // 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); - $topic_ids = (!$quickmod) ? request_var('topic_id_list', array(0)) : array(request_var('t', 0)); + $forum_id = $request->variable('f', 0); + $topic_ids = (!$quickmod) ? $request->variable('topic_id_list', array(0)) : array($request->variable('t', 0)); $soft_delete = (($request->is_set_post('confirm') && !$request->is_set_post('delete_permanent')) || !$auth->acl_get('m_delete', $forum_id)) ? true : false; if (!sizeof($topic_ids)) @@ -119,7 +119,7 @@ class mcp_main trigger_error('NO_TOPIC_SELECTED'); } - mcp_delete_topic($topic_ids, $soft_delete, ($soft_delete) ? request_var('delete_reason', '', true) : ''); + mcp_delete_topic($topic_ids, $soft_delete, ($soft_delete) ? $request->variable('delete_reason', '', true) : ''); break; case 'delete_post': @@ -127,8 +127,8 @@ class mcp_main // 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)); + $forum_id = $request->variable('f', 0); + $post_ids = (!$quickmod) ? $request->variable('post_id_list', array(0)) : array($request->variable('p', 0)); $soft_delete = (($request->is_set_post('confirm') && !$request->is_set_post('delete_permanent')) || !$auth->acl_get('m_delete', $forum_id)) ? true : false; if (!sizeof($post_ids)) @@ -136,13 +136,13 @@ class mcp_main trigger_error('NO_POST_SELECTED'); } - mcp_delete_post($post_ids, $soft_delete, ($soft_delete) ? request_var('delete_reason', '', true) : ''); + mcp_delete_post($post_ids, $soft_delete, ($soft_delete) ? $request->variable('delete_reason', '', true) : ''); break; case 'restore_topic': $user->add_lang('posting'); - $topic_ids = (!$quickmod) ? request_var('topic_id_list', array(0)) : array(request_var('t', 0)); + $topic_ids = (!$quickmod) ? $request->variable('topic_id_list', array(0)) : array($request->variable('t', 0)); if (!sizeof($topic_ids)) { @@ -654,15 +654,15 @@ function mcp_move_topic($topic_ids) */ function mcp_restore_topic($topic_ids) { - global $auth, $user, $db, $phpEx, $phpbb_root_path; + global $auth, $user, $db, $phpEx, $phpbb_root_path, $request; if (!check_ids($topic_ids, TOPICS_TABLE, 'topic_id', array('m_approve'))) { return; } - $redirect = request_var('redirect', build_url(array('action', 'quickmod'))); - $forum_id = request_var('f', 0); + $redirect = $request->variable('redirect', build_url(array('action', 'quickmod'))); + $forum_id = $request->variable('f', 0); $s_hidden_fields = build_hidden_fields(array( 'topic_id_list' => $topic_ids, @@ -692,10 +692,10 @@ function mcp_restore_topic($topic_ids) confirm_box(false, (sizeof($topic_ids) == 1) ? 'RESTORE_TOPIC' : 'RESTORE_TOPICS', $s_hidden_fields); } - $topic_id = request_var('t', 0); - if (!isset($_REQUEST['quickmod'])) + $topic_id = $request->variable('t', 0); + if (!$request->is_set('quickmod', phpbb_request_interface::REQUEST)) { - $redirect = request_var('redirect', "index.$phpEx"); + $redirect = $request->variable('redirect', "index.$phpEx"); $redirect = reapply_sid($redirect); $redirect_message = 'PAGE'; } @@ -726,15 +726,15 @@ function mcp_restore_topic($topic_ids) */ function mcp_delete_topic($topic_ids, $is_soft = false, $soft_delete_reason = '') { - global $auth, $user, $db, $phpEx, $phpbb_root_path; + global $auth, $user, $db, $phpEx, $phpbb_root_path, $request; if (!check_ids($topic_ids, TOPICS_TABLE, 'topic_id', array('m_delete'))) { return; } - $redirect = request_var('redirect', build_url(array('action', 'quickmod'))); - $forum_id = request_var('f', 0); + $redirect = $request->variable('redirect', build_url(array('action', 'quickmod'))); + $forum_id = $request->variable('f', 0); $s_hidden_fields = array( 'topic_id_list' => $topic_ids, @@ -820,10 +820,10 @@ function mcp_delete_topic($topic_ids, $is_soft = false, $soft_delete_reason = '' confirm_box(false, $l_confirm, build_hidden_fields($s_hidden_fields), 'confirm_delete_body.html'); } - $topic_id = request_var('t', 0); - if (!isset($_REQUEST['quickmod'])) + $topic_id = $request->variable('t', 0); + if (!$request->is_set('quickmod', phpbb_request_interface::REQUEST)) { - $redirect = request_var('redirect', "index.$phpEx"); + $redirect = $request->variable('redirect', "index.$phpEx"); $redirect = reapply_sid($redirect); $redirect_message = 'PAGE'; } @@ -854,15 +854,15 @@ function mcp_delete_topic($topic_ids, $is_soft = false, $soft_delete_reason = '' */ 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, $request; if (!check_ids($post_ids, POSTS_TABLE, 'post_id', array('m_softdelete'))) { return; } - $redirect = request_var('redirect', build_url(array('action', 'quickmod'))); - $forum_id = request_var('f', 0); + $redirect = $request->variable('redirect', build_url(array('action', 'quickmod'))); + $forum_id = $request->variable('f', 0); $s_hidden_fields = array( 'post_id_list' => $post_ids, @@ -926,7 +926,7 @@ function mcp_delete_post($post_ids, $is_soft = false, $soft_delete_reason = '') add_log('mod', $row['forum_id'], $row['topic_id'], 'LOG_SOFTDELETE_POST', $row['post_subject'], $post_username); } - $topic_id = request_var('t', 0); + $topic_id = $request->variable('t', 0); // Return links $return_link = array(); @@ -980,7 +980,7 @@ function mcp_delete_post($post_ids, $is_soft = false, $soft_delete_reason = '') $deleted_topics = ($row = $db->sql_fetchrow($result)) ? ($affected_topics - $row['topics_left']) : $affected_topics; $db->sql_freeresult($result); - $topic_id = request_var('t', 0); + $topic_id = $request->variable('t', 0); // Return links $return_link = array(); @@ -1056,7 +1056,7 @@ function mcp_delete_post($post_ids, $is_soft = false, $soft_delete_reason = '') confirm_box(false, $l_confirm, build_hidden_fields($s_hidden_fields), 'confirm_delete_body.html'); } - $redirect = request_var('redirect', "index.$phpEx"); + $redirect = $request->variable('redirect', "index.$phpEx"); $redirect = reapply_sid($redirect); if (!$success_msg) diff --git a/phpBB/includes/mcp/mcp_queue.php b/phpBB/includes/mcp/mcp_queue.php index 5fe09a2524..b6a36f184a 100644 --- a/phpBB/includes/mcp/mcp_queue.php +++ b/phpBB/includes/mcp/mcp_queue.php @@ -32,7 +32,7 @@ class mcp_queue public function main($id, $mode) { - global $auth, $db, $user, $template, $cache; + global $auth, $db, $user, $template, $cache, $request; global $config, $phpbb_root_path, $phpEx, $action; include_once($phpbb_root_path . 'includes/functions_posting.' . $phpEx); @@ -49,8 +49,8 @@ class mcp_queue case 'restore': include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx); - $post_id_list = request_var('post_id_list', array(0)); - $topic_id_list = request_var('topic_id_list', array(0)); + $post_id_list = $request->variable('post_id_list', array(0)); + $topic_id_list = $request->variable('topic_id_list', array(0)); if ($action != 'disapprove') { @@ -213,7 +213,7 @@ class mcp_queue 'U_APPROVE_ACTION' => append_sid("{$phpbb_root_path}mcp.$phpEx", "i=queue&p=$post_id&f=$forum_id"), 'S_CAN_VIEWIP' => $auth->acl_get('m_info', $post_info['forum_id']), 'S_POST_REPORTED' => $post_info['post_reported'], - 'S_POST_UNAPPROVED' => ($post_info['post_visibility'] == ITEM_UNAPPROVED) , + 'S_POST_UNAPPROVED' => ($post_info['post_visibility'] == ITEM_UNAPPROVED), 'S_POST_LOCKED' => $post_info['post_edit_locked'], 'S_USER_NOTES' => true, @@ -263,7 +263,7 @@ class mcp_queue $user->add_lang(array('viewtopic', 'viewforum')); - $topic_id = request_var('t', 0); + $topic_id = $request->variable('t', 0); $forum_info = array(); if ($topic_id) @@ -503,7 +503,7 @@ class mcp_queue trigger_error('NOT_AUTHORISED'); } - $redirect = request_var('redirect', build_url(array('quickmod'))); + $redirect = $request->variable('redirect', build_url(array('quickmod'))); $success_msg = $post_url = ''; $approve_log = array(); @@ -519,7 +519,7 @@ class mcp_queue if (confirm_box(true)) { - $notify_poster = ($action == 'approve' && isset($_REQUEST['notify_poster'])) ? true : false; + $notify_poster = ($action == 'approve' && isset($_REQUEST['notify_poster'])); $topic_info = array(); @@ -642,7 +642,7 @@ class mcp_queue confirm_box(false, strtoupper($action) . '_POST' . ((sizeof($post_id_list) == 1) ? '' : 'S'), $s_hidden_fields, 'mcp_approve.html'); } - $redirect = request_var('redirect', "index.$phpEx"); + $redirect = $request->variable('redirect', "index.$phpEx"); $redirect = reapply_sid($redirect); if (!$success_msg) @@ -696,7 +696,7 @@ class mcp_queue trigger_error('NOT_AUTHORISED'); } - $redirect = request_var('redirect', build_url(array('quickmod'))); + $redirect = $request->variable('redirect', build_url(array('quickmod'))); $success_msg = $topic_url = ''; $approve_log = array(); @@ -806,7 +806,7 @@ class mcp_queue confirm_box(false, strtoupper($action) . '_TOPIC' . ((sizeof($topic_id_list) == 1) ? '' : 'S'), $s_hidden_fields, 'mcp_approve.html'); } - $redirect = request_var('redirect', "index.$phpEx"); + $redirect = $request->variable('redirect', "index.$phpEx"); $redirect = reapply_sid($redirect); if (!$success_msg) @@ -852,17 +852,16 @@ class mcp_queue static public function disapprove_posts($post_id_list, $id, $mode) { global $db, $template, $user, $config; - global $phpEx, $phpbb_root_path; - global $request; + global $phpEx, $phpbb_root_path, $request; if (!check_ids($post_id_list, POSTS_TABLE, 'post_id', array('m_approve'))) { trigger_error('NOT_AUTHORISED'); } - $redirect = request_var('redirect', build_url(array('t', 'mode', 'quickmod')) . "&mode=$mode"); - $reason = utf8_normalize_nfc(request_var('reason', '', true)); - $reason_id = request_var('reason_id', 0); + $redirect = $request->variable('redirect', build_url(array('t', 'mode', 'quickmod')) . "&mode=$mode"); + $reason = $request->variable('reason', '', true); + $reason_id = $request->variable('reason_id', 0); $success_msg = $additional_msg = ''; $s_hidden_fields = build_hidden_fields(array( @@ -1097,7 +1096,7 @@ class mcp_queue confirm_box(false, 'DISAPPROVE_POST' . ((sizeof($post_id_list) == 1) ? '' : 'S'), $s_hidden_fields, 'mcp_approve.html'); } - $redirect = request_var('redirect', "index.$phpEx"); + $redirect = $request->variable('redirect', "index.$phpEx"); $redirect = reapply_sid($redirect); if (!$success_msg) -- 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/includes/acp/acp_forums.php | 10 +++++----- phpBB/includes/content_visibility.php | 14 +++++++------- phpBB/includes/functions_admin.php | 14 +++++++------- phpBB/includes/functions_posting.php | 9 +++++---- phpBB/includes/mcp/mcp_main.php | 6 +++--- phpBB/includes/mcp/mcp_queue.php | 2 +- 6 files changed, 28 insertions(+), 27 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/acp/acp_forums.php b/phpBB/includes/acp/acp_forums.php index 8029181f39..bb91acba74 100644 --- a/phpBB/includes/acp/acp_forums.php +++ b/phpBB/includes/acp/acp_forums.php @@ -856,8 +856,8 @@ class acp_forums 'FORUM_IMAGE_SRC' => ($row['forum_image']) ? $phpbb_root_path . $row['forum_image'] : '', 'FORUM_NAME' => $row['forum_name'], 'FORUM_DESCRIPTION' => generate_text_for_display($row['forum_desc'], $row['forum_desc_uid'], $row['forum_desc_bitfield'], $row['forum_desc_options']), - 'FORUM_TOPICS' => $row['forum_topics'], - 'FORUM_POSTS' => $row['forum_posts'], + 'FORUM_TOPICS' => $row['forum_topics_approved'], + 'FORUM_POSTS' => $row['forum_posts_approved'], 'S_FORUM_LINK' => ($forum_type == FORUM_LINK) ? true : false, 'S_FORUM_POST' => ($forum_type == FORUM_POST) ? true : false, @@ -1143,7 +1143,7 @@ class acp_forums return array($user->lang['NO_FORUM_ACTION']); } - $forum_data_sql['forum_posts'] = $forum_data_sql['forum_posts_unapproved'] = $forum_data_sql['forum_posts_softdeleted'] = $forum_data_sql['forum_topics'] = $forum_data_sql['forum_topics_unapproved'] = $forum_data_sql['forum_topics_softdeleted'] = 0; + $forum_data_sql['forum_posts_approved'] = $forum_data_sql['forum_posts_unapproved'] = $forum_data_sql['forum_posts_softdeleted'] = $forum_data_sql['forum_topics_approved'] = $forum_data_sql['forum_topics_unapproved'] = $forum_data_sql['forum_topics_softdeleted'] = 0; $forum_data_sql['forum_last_post_id'] = $forum_data_sql['forum_last_poster_id'] = $forum_data_sql['forum_last_post_time'] = 0; $forum_data_sql['forum_last_poster_name'] = $forum_data_sql['forum_last_poster_colour'] = ''; } @@ -1264,10 +1264,10 @@ class acp_forums else if ($row['forum_type'] == FORUM_CAT && $forum_data_sql['forum_type'] == FORUM_POST) { // Changing a category to a forum? Reset the data (you can't post directly in a cat, you must use a forum) - $forum_data_sql['forum_posts'] = 0; + $forum_data_sql['forum_posts_approved'] = 0; $forum_data_sql['forum_posts_unapproved'] = 0; $forum_data_sql['forum_posts_softdeleted'] = 0; - $forum_data_sql['forum_topics'] = 0; + $forum_data_sql['forum_topics_approved'] = 0; $forum_data_sql['forum_topics_unapproved'] = 0; $forum_data_sql['forum_topics_softdeleted'] = 0; $forum_data_sql['forum_last_post_id'] = 0; diff --git a/phpBB/includes/content_visibility.php b/phpBB/includes/content_visibility.php index a1b7c16c2d..bea70571f9 100644 --- a/phpBB/includes/content_visibility.php +++ b/phpBB/includes/content_visibility.php @@ -60,10 +60,10 @@ class phpbb_content_visibility if (!$auth->acl_get('m_approve', $forum_id)) { - return (int) $data[$mode]; + return (int) $data[$mode . '_approved']; } - return (int) $data[$mode] + (int) $data[$mode . '_unapproved'] + (int) $data[$mode . '_softdeleted']; + return (int) $data[$mode . '_approved'] + (int) $data[$mode . '_unapproved'] + (int) $data[$mode . '_softdeleted']; } /** @@ -372,7 +372,7 @@ class phpbb_content_visibility { if ($cur_posts) { - $sql_ary['posts'] = ' - ' . $cur_posts; + $sql_ary['posts_approved'] = ' - ' . $cur_posts; } if ($cur_unapproved_posts) { @@ -395,7 +395,7 @@ class phpbb_content_visibility } if ($cur_softdeleted_posts + $cur_unapproved_posts) { - $sql_ary['posts'] = ' + ' . ($cur_softdeleted_posts + $cur_unapproved_posts); + $sql_ary['posts_approved'] = ' + ' . ($cur_softdeleted_posts + $cur_unapproved_posts); } } @@ -564,7 +564,7 @@ class phpbb_content_visibility // Do we need to grab some topic informations? if (!sizeof($topic_row)) { - $sql = 'SELECT topic_type, topic_posts, topic_posts_unapproved, topic_posts_softdeleted, topic_visibility + $sql = 'SELECT topic_type, topic_posts_approved, topic_posts_unapproved, topic_posts_softdeleted, topic_visibility FROM ' . TOPICS_TABLE . ' WHERE topic_id = ' . $topic_id; $result = $db->sql_query($sql); @@ -573,8 +573,8 @@ class phpbb_content_visibility } // If this is an edited topic or the first post the topic gets completely disapproved later on... - $sql_data[FORUMS_TABLE] = (($sql_data[FORUMS_TABLE]) ? $sql_data[FORUMS_TABLE] . ', ' : '') . 'forum_topics = forum_topics - 1'; - $sql_data[FORUMS_TABLE] .= ', forum_posts = forum_posts - ' . $topic_row['topic_posts']; + $sql_data[FORUMS_TABLE] = (($sql_data[FORUMS_TABLE]) ? $sql_data[FORUMS_TABLE] . ', ' : '') . 'forum_topics_approved = forum_topics_approved - 1'; + $sql_data[FORUMS_TABLE] .= ', forum_posts_approved = forum_posts_approved - ' . $topic_row['topic_posts_approved']; $sql_data[FORUMS_TABLE] .= ', forum_posts_unapproved = forum_posts_unapproved - ' . $topic_row['topic_posts_unapproved']; $sql_data[FORUMS_TABLE] .= ', forum_posts_softdeleted = forum_posts_softdeleted - ' . $topic_row['topic_posts_softdeleted']; diff --git a/phpBB/includes/functions_admin.php b/phpBB/includes/functions_admin.php index f1c3cf62b1..2bf36d967a 100644 --- a/phpBB/includes/functions_admin.php +++ b/phpBB/includes/functions_admin.php @@ -1669,10 +1669,10 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false, $forum_data[$forum_id] = $row; if ($sync_extra) { - $forum_data[$forum_id]['posts'] = 0; + $forum_data[$forum_id]['posts_approved'] = 0; $forum_data[$forum_id]['posts_unapproved'] = 0; $forum_data[$forum_id]['posts_softdeleted'] = 0; - $forum_data[$forum_id]['topics'] = 0; + $forum_data[$forum_id]['topics_approved'] = 0; $forum_data[$forum_id]['topics_unapproved'] = 0; $forum_data[$forum_id]['topics_softdeleted'] = 0; } @@ -1746,7 +1746,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false, { $forum_id = (sizeof($forum_ids) == 1) ? (int) $forum_ids[0] : (int) $row['forum_id']; - $forum_data[$forum_id]['posts'] = (int) $row['forum_posts']; + $forum_data[$forum_id]['posts_approved'] = (int) $row['forum_posts']; $forum_data[$forum_id]['posts_unapproved'] = (int) $row['forum_posts_unapproved']; $forum_data[$forum_id]['posts_softdeleted'] = (int) $row['forum_posts_softdeleted']; } @@ -1829,7 +1829,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false, if ($sync_extra) { - array_push($fieldnames, 'posts', 'posts_unapproved', 'posts_softdeleted', 'topics', 'topics_unapproved', 'topics_softdeleted'); + array_push($fieldnames, 'posts_approved', 'posts_unapproved', 'posts_softdeleted', 'topics_approved', 'topics_unapproved', 'topics_softdeleted'); } foreach ($forum_data as $forum_id => $row) @@ -1884,7 +1884,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false, $topic_id = (int) $row['topic_id']; $topic_data[$topic_id] = $row; $topic_data[$topic_id]['visibility'] = ITEM_UNAPPROVED; - $topic_data[$topic_id]['posts'] = 0; + $topic_data[$topic_id]['posts_approved'] = 0; $topic_data[$topic_id]['posts_unapproved'] = 0; $topic_data[$topic_id]['posts_softdeleted'] = 0; $topic_data[$topic_id]['first_post_id'] = 0; @@ -1930,7 +1930,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false, if ($row['post_visibility'] == ITEM_APPROVED) { - $topic_data[$topic_id]['posts'] = $row['total_posts']; + $topic_data[$topic_id]['posts_approved'] = $row['total_posts']; } else if ($row['post_visibility'] == ITEM_UNAPPROVED) { @@ -2141,7 +2141,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false, } // These are fields that will be synchronised - $fieldnames = array('time', 'visibility', 'posts', 'posts_unapproved', 'posts_softdeleted', 'poster', 'first_post_id', 'first_poster_name', 'first_poster_colour', 'last_post_id', 'last_post_subject', 'last_post_time', 'last_poster_id', 'last_poster_name', 'last_poster_colour'); + $fieldnames = array('time', 'visibility', 'posts_approved', 'posts_unapproved', 'posts_softdeleted', 'poster', 'first_post_id', 'first_poster_name', 'first_poster_colour', 'last_post_id', 'last_post_subject', 'last_post_time', 'last_poster_id', 'last_poster_name', 'last_poster_colour'); if ($sync_extra) { diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index 8e8e3aac9f..62567e302a 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -1418,7 +1418,7 @@ function delete_post($forum_id, $topic_id, $post_id, &$data, $is_soft = false, $ // Specify our post mode $post_mode = 'delete'; - if (($data['topic_first_post_id'] === $data['topic_last_post_id']) && ($data['topic_posts'] + $data['topic_posts_unapproved'] + $data['topic_posts_softdeleted'] == 1)) + if (($data['topic_first_post_id'] === $data['topic_last_post_id']) && ($data['topic_posts_approved'] + $data['topic_posts_unapproved'] + $data['topic_posts_softdeleted'] == 1)) { $post_mode = 'delete_topic'; } @@ -1718,7 +1718,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u } else if ($mode == 'edit') { - $post_mode = ($data['topic_posts'] + $data['topic_posts_unapproved'] + $data['topic_posts_softdeleted'] == 1) ? 'edit_topic' : (($data['topic_first_post_id'] == $data['post_id']) ? 'edit_first_post' : (($data['topic_last_post_id'] == $data['post_id']) ? 'edit_last_post' : 'edit')); + $post_mode = ($data['topic_posts_approved'] + $data['topic_posts_unapproved'] + $data['topic_posts_softdeleted'] == 1) ? 'edit_topic' : (($data['topic_first_post_id'] == $data['post_id']) ? 'edit_first_post' : (($data['topic_last_post_id'] == $data['post_id']) ? 'edit_last_post' : 'edit')); } // First of all make sure the subject and topic title are having the correct length. @@ -1879,8 +1879,9 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u 'topic_last_view_time' => $current_time, 'forum_id' => $data['forum_id'], 'icon_id' => $data['icon_id'], - 'topic_posts' => ($post_visibility == ITEM_APPROVED) ? 1 : 0, - 'topic_posts_softdeleted' => ($post_visibility != ITEM_APPROVED) ? 1 : 0, + 'topic_posts_approved' => ($post_visibility == ITEM_APPROVED) ? 1 : 0, + 'topic_posts_softdeleted' => ($post_visibility == ITEM_DELETED) ? 1 : 0, + 'topic_posts_unapproved' => ($post_visibility == ITEM_UNAPPROVED) ? 1 : 0, 'topic_visibility' => $post_visibility, 'topic_delete_user' => ($post_visibility != ITEM_APPROVED) ? (int) $user->data['user_id'] : 0, 'topic_title' => $subject, diff --git a/phpBB/includes/mcp/mcp_main.php b/phpBB/includes/mcp/mcp_main.php index 945b80ba41..aeaa37f4cb 100644 --- a/phpBB/includes/mcp/mcp_main.php +++ b/phpBB/includes/mcp/mcp_main.php @@ -494,7 +494,7 @@ function mcp_move_topic($topic_ids) $topics_moved_softdeleted++; } - $posts_moved += $topic_info['topic_posts']; + $posts_moved += $topic_info['topic_posts_approved']; $posts_moved_unapproved += $topic_info['topic_posts_unapproved']; $posts_moved_softdeleted += $topic_info['topic_posts_softdeleted']; } @@ -534,7 +534,7 @@ function mcp_move_topic($topic_ids) 'topic_time' => (int) $row['topic_time'], 'topic_time_limit' => (int) $row['topic_time_limit'], 'topic_views' => (int) $row['topic_views'], - 'topic_posts' => (int) $row['topic_posts'], + 'topic_posts_approved' => (int) $row['topic_posts_approved'], 'topic_posts_unapproved'=> (int) $row['topic_posts_unapproved'], 'topic_posts_softdeleted'=> (int) $row['topic_posts_softdeleted'], 'topic_status' => ITEM_MOVED, @@ -1180,7 +1180,7 @@ function mcp_fork_topic($topic_ids) 'topic_title' => (string) $topic_row['topic_title'], 'topic_poster' => (int) $topic_row['topic_poster'], 'topic_time' => (int) $topic_row['topic_time'], - 'topic_posts' => (int) $topic_row['topic_posts'], + 'topic_posts_approved' => (int) $topic_row['topic_posts_approved'], 'topic_posts_unapproved' => (int) $topic_row['topic_posts_unapproved'], 'topic_posts_softdeleted' => (int) $topic_row['topic_posts_softdeleted'], 'topic_status' => (int) $topic_row['topic_status'], diff --git a/phpBB/includes/mcp/mcp_queue.php b/phpBB/includes/mcp/mcp_queue.php index b6a36f184a..ab2d5124af 100644 --- a/phpBB/includes/mcp/mcp_queue.php +++ b/phpBB/includes/mcp/mcp_queue.php @@ -932,7 +932,7 @@ class mcp_queue // If the count of disapproved posts for the topic is equal // to the number of unapproved posts in the topic, and there are no different // posts, we disapprove the hole topic - if ($topic_information[$topic_id]['topic_posts'] == 0 && + if ($topic_information[$topic_id]['topic_posts_approved'] == 0 && $topic_information[$topic_id]['topic_posts_softdeleted'] == 0 && $topic_information[$topic_id]['topic_posts_unapproved'] == $topic_posts_unapproved[$topic_id]) { -- cgit v1.2.1 From f77a6eaab5485329a3b13922649fb8902e6e397f Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 10 Nov 2012 11:24:52 +0100 Subject: [feature/soft-delete] Fix the rest of *_approved and the delete_post unit test PHPBB3-9567 --- phpBB/includes/acp/acp_forums.php | 2 +- phpBB/includes/acp/acp_users.php | 4 ++-- phpBB/includes/content_visibility.php | 10 +++++----- phpBB/includes/functions_admin.php | 10 +++++----- phpBB/includes/functions_posting.php | 15 +++++++-------- phpBB/includes/mcp/mcp_forum.php | 2 +- phpBB/includes/mcp/mcp_main.php | 12 ++++++------ phpBB/includes/mcp/mcp_queue.php | 6 +++--- phpBB/includes/mcp/mcp_reports.php | 6 +++--- 9 files changed, 33 insertions(+), 34 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/acp/acp_forums.php b/phpBB/includes/acp/acp_forums.php index bb91acba74..e8f0a01b2e 100644 --- a/phpBB/includes/acp/acp_forums.php +++ b/phpBB/includes/acp/acp_forums.php @@ -283,7 +283,7 @@ class acp_forums @set_time_limit(0); - $sql = 'SELECT forum_name, (forum_topics + forum_topics_unapproved + forum_topics_softdeleted) AS total_topics + $sql = 'SELECT forum_name, (forum_topics_approved + forum_topics_unapproved + forum_topics_softdeleted) AS total_topics FROM ' . FORUMS_TABLE . " WHERE forum_id = $forum_id"; $result = $db->sql_query($sql); diff --git a/phpBB/includes/acp/acp_users.php b/phpBB/includes/acp/acp_users.php index 1a3511bc50..bb5b4a04d5 100644 --- a/phpBB/includes/acp/acp_users.php +++ b/phpBB/includes/acp/acp_users.php @@ -636,14 +636,14 @@ class acp_users if (sizeof($topic_id_ary)) { - $sql = 'SELECT topic_id, forum_id, topic_title, topic_posts, topic_posts_unapproved, topic_posts_softdeleted, topic_attachment + $sql = 'SELECT topic_id, forum_id, topic_title, topic_posts_approved, topic_posts_unapproved, topic_posts_softdeleted, topic_attachment FROM ' . TOPICS_TABLE . ' WHERE ' . $db->sql_in_set('topic_id', array_keys($topic_id_ary)); $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { - if ($topic_id_ary[$row['topic_id']][ITEM_APPROVED] == $row['topic_posts'] + if ($topic_id_ary[$row['topic_id']][ITEM_APPROVED] == $row['topic_posts_approved'] && $topic_id_ary[$row['topic_id']][ITEM_UNAPPROVED] == $row['topic_posts_unapproved'] && $topic_id_ary[$row['topic_id']][ITEM_DELETED] == $row['topic_posts_softdeleted']) { diff --git a/phpBB/includes/content_visibility.php b/phpBB/includes/content_visibility.php index bea70571f9..3118be6574 100644 --- a/phpBB/includes/content_visibility.php +++ b/phpBB/includes/content_visibility.php @@ -516,9 +516,9 @@ class phpbb_content_visibility */ static public function add_post_to_statistic($data, &$sql_data) { - $sql_data[TOPICS_TABLE] = (($sql_data[TOPICS_TABLE]) ? $sql_data[TOPICS_TABLE] . ', ' : '') . 'topic_replies = topic_replies + 1'; + $sql_data[TOPICS_TABLE] = (($sql_data[TOPICS_TABLE]) ? $sql_data[TOPICS_TABLE] . ', ' : '') . 'topic_posts_approved = topic_posts_approved + 1'; - $sql_data[FORUMS_TABLE] = (($sql_data[FORUMS_TABLE]) ? $sql_data[FORUMS_TABLE] . ', ' : '') . 'forum_posts = forum_posts + 1'; + $sql_data[FORUMS_TABLE] = (($sql_data[FORUMS_TABLE]) ? $sql_data[FORUMS_TABLE] . ', ' : '') . 'forum_posts_approved = forum_posts_approved + 1'; if ($data['post_postcount']) { @@ -537,8 +537,8 @@ class phpbb_content_visibility */ static public function remove_post_from_statistic($data, &$sql_data) { - $sql_data[TOPICS_TABLE] = ((!empty($sql_data[TOPICS_TABLE])) ? $sql_data[TOPICS_TABLE] . ', ' : '') . 'topic_posts = topic_posts - 1'; - $sql_data[FORUMS_TABLE] = ((!empty($sql_data[FORUMS_TABLE])) ? $sql_data[FORUMS_TABLE] . ', ' : '') . 'forum_posts = forum_posts - 1'; + $sql_data[TOPICS_TABLE] = ((!empty($sql_data[TOPICS_TABLE])) ? $sql_data[TOPICS_TABLE] . ', ' : '') . 'topic_posts_approved = topic_posts_approved - 1'; + $sql_data[FORUMS_TABLE] = ((!empty($sql_data[FORUMS_TABLE])) ? $sql_data[FORUMS_TABLE] . ', ' : '') . 'forum_posts_approved = forum_posts_approved - 1'; if ($data['post_postcount']) { @@ -579,7 +579,7 @@ class phpbb_content_visibility $sql_data[FORUMS_TABLE] .= ', forum_posts_softdeleted = forum_posts_softdeleted - ' . $topic_row['topic_posts_softdeleted']; set_config_count('num_topics', -1, true); - set_config_count('num_posts', $topic_row['topic_posts'] * (-1), true); + set_config_count('num_posts', $topic_row['topic_posts_approved'] * (-1), true); // Get user post count information $sql = 'SELECT poster_id, COUNT(post_id) AS num_posts diff --git a/phpBB/includes/functions_admin.php b/phpBB/includes/functions_admin.php index 2bf36d967a..5cbe234347 100644 --- a/phpBB/includes/functions_admin.php +++ b/phpBB/includes/functions_admin.php @@ -1707,7 +1707,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false, if ($row['topic_visibility'] == ITEM_APPROVED) { - $forum_data[$forum_id]['topics'] = $row['total_topics']; + $forum_data[$forum_id]['topics_approved'] = $row['total_topics']; } else if ($row['topic_visibility'] == ITEM_UNAPPROVED) { @@ -1726,14 +1726,14 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false, { if (sizeof($forum_ids) == 1) { - $sql = 'SELECT SUM(t.topic_posts) AS forum_posts, SUM(t.topic_posts_unapproved) AS forum_posts_unapproved, SUM(t.topic_posts_softdeleted) AS forum_posts_softdeleted + $sql = 'SELECT SUM(t.topic_posts_approved) AS forum_posts_approved, SUM(t.topic_posts_unapproved) AS forum_posts_unapproved, SUM(t.topic_posts_softdeleted) AS forum_posts_softdeleted FROM ' . TOPICS_TABLE . ' t WHERE ' . $db->sql_in_set('t.forum_id', $forum_ids) . ' AND t.topic_status <> ' . ITEM_MOVED; } else { - $sql = 'SELECT t.forum_id, SUM(t.topic_posts) AS forum_posts, SUM(t.topic_posts_unapproved) AS forum_posts_unapproved, SUM(t.topic_posts_softdeleted) AS forum_posts_softdeleted + $sql = 'SELECT t.forum_id, SUM(t.topic_posts_approved) AS forum_posts_approved, SUM(t.topic_posts_unapproved) AS forum_posts_unapproved, SUM(t.topic_posts_softdeleted) AS forum_posts_softdeleted FROM ' . TOPICS_TABLE . ' t WHERE ' . $db->sql_in_set('t.forum_id', $forum_ids) . ' AND t.topic_status <> ' . ITEM_MOVED . ' @@ -1746,7 +1746,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false, { $forum_id = (sizeof($forum_ids) == 1) ? (int) $forum_ids[0] : (int) $row['forum_id']; - $forum_data[$forum_id]['posts_approved'] = (int) $row['forum_posts']; + $forum_data[$forum_id]['posts_approved'] = (int) $row['forum_posts_approved']; $forum_data[$forum_id]['posts_unapproved'] = (int) $row['forum_posts_unapproved']; $forum_data[$forum_id]['posts_softdeleted'] = (int) $row['forum_posts_softdeleted']; } @@ -1868,7 +1868,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false, $db->sql_transaction('begin'); - $sql = 'SELECT t.topic_id, t.forum_id, t.topic_moved_id, t.topic_visibility, ' . (($sync_extra) ? 't.topic_attachment, t.topic_reported, ' : '') . 't.topic_poster, t.topic_time, t.topic_posts, t.topic_posts_unapproved, t.topic_posts_softdeleted, t.topic_first_post_id, t.topic_first_poster_name, t.topic_first_poster_colour, t.topic_last_post_id, t.topic_last_post_subject, t.topic_last_poster_id, t.topic_last_poster_name, t.topic_last_poster_colour, t.topic_last_post_time + $sql = 'SELECT t.topic_id, t.forum_id, t.topic_moved_id, t.topic_visibility, ' . (($sync_extra) ? 't.topic_attachment, t.topic_reported, ' : '') . 't.topic_poster, t.topic_time, t.topic_posts_approved, t.topic_posts_unapproved, t.topic_posts_softdeleted, t.topic_first_post_id, t.topic_first_poster_name, t.topic_first_poster_colour, t.topic_last_post_id, t.topic_last_post_subject, t.topic_last_poster_id, t.topic_last_poster_name, t.topic_last_poster_colour, t.topic_last_post_time FROM ' . TOPICS_TABLE . " t $where_sql"; $result = $db->sql_query($sql); diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index 62567e302a..53beb6ac76 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -1491,7 +1491,7 @@ function delete_post($forum_id, $topic_id, $post_id, &$data, $is_soft = false, $ // counting is fun! we only have to do sizeof($forum_ids) number of queries, // even if the topic is moved back to where its shadow lives (we count how many times it is in a forum) $sql = 'UPDATE ' . FORUMS_TABLE . ' - SET forum_topics = forum_topics - ' . $topic_count . ' + SET forum_topics_approved = forum_topics_approved - ' . $topic_count . ' WHERE forum_id = ' . $updated_forum; $db->sql_query($sql); update_post_information('forum', $updated_forum); @@ -1508,7 +1508,7 @@ function delete_post($forum_id, $topic_id, $post_id, &$data, $is_soft = false, $ if ($data['topic_visibility'] == ITEM_APPROVED) { - $sql_data[FORUMS_TABLE] .= 'forum_posts = forum_posts - 1, forum_topics = forum_topics - 1'; + $sql_data[FORUMS_TABLE] .= 'forum_posts_approved = forum_posts_approved - 1, forum_topics_approved = forum_topics_approved - 1'; } else if ($data['topic_visibility'] == ITEM_UNAPPROVED) { @@ -1609,7 +1609,6 @@ function delete_post($forum_id, $topic_id, $post_id, &$data, $is_soft = false, $ break; } - if (($post_mode == 'delete') || ($post_mode == 'delete_last_post') || ($post_mode == 'delete_first_post')) { if (!$is_soft) @@ -1733,7 +1732,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u // Retrieve some additional information if not present if ($mode == 'edit' && (!isset($data['post_visibility']) || !isset($data['topic_visibility']) || $data['post_visibility'] === false || $data['topic_visibility'] === false)) { - $sql = 'SELECT p.post_visibility, t.topic_type, t.topic_posts, t.topic_posts_unapproved, t.topic_posts_softdeleted, t.topic_visibility + $sql = 'SELECT p.post_visibility, t.topic_type, t.topic_posts_approved, t.topic_posts_unapproved, t.topic_posts_softdeleted, t.topic_visibility FROM ' . TOPICS_TABLE . ' t, ' . POSTS_TABLE . ' p WHERE t.topic_id = p.topic_id AND p.post_id = ' . $data['post_id']; @@ -1919,8 +1918,8 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u if ($post_visibility == ITEM_APPROVED) { - $sql_data[FORUMS_TABLE]['stat'][] = 'forum_topics = forum_topics + 1'; - $sql_data[FORUMS_TABLE]['stat'][] = 'forum_posts = forum_posts + 1'; + $sql_data[FORUMS_TABLE]['stat'][] = 'forum_topics_approved = forum_topics_approved + 1'; + $sql_data[FORUMS_TABLE]['stat'][] = 'forum_posts_approved = forum_posts_approved + 1'; } else if ($post_visibility == ITEM_UNAPPROVED) { @@ -1938,7 +1937,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u $sql_data[TOPICS_TABLE]['stat'][] = 'topic_last_view_time = ' . $current_time . ', topic_bumped = 0, topic_bumper = 0' . - (($post_visibility == ITEM_APPROVED) ? ', topic_posts = topic_posts + 1' : '') . + (($post_visibility == ITEM_APPROVED) ? ', topic_posts_approved = topic_posts_approved + 1' : '') . (($post_visibility == ITEM_UNAPPROVED) ? ', topic_posts_unapproved = topic_posts_unapproved + 1' : '') . (($post_visibility == ITEM_DELETED) ? ', topic_posts_softdeleted = topic_posts_softdeleted + 1' : '') . ((!empty($data['attachment_data']) || (isset($data['topic_attachment']) && $data['topic_attachment'])) ? ', topic_attachment = 1' : ''); @@ -1947,7 +1946,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u if ($post_visibility == ITEM_APPROVED) { - $sql_data[FORUMS_TABLE]['stat'][] = 'forum_posts = forum_posts + 1'; + $sql_data[FORUMS_TABLE]['stat'][] = 'forum_posts_approved = forum_posts_approved + 1'; } else if ($post_visibility == ITEM_UNAPPROVED) { diff --git a/phpBB/includes/mcp/mcp_forum.php b/phpBB/includes/mcp/mcp_forum.php index bacc4c444c..7c3bffe717 100644 --- a/phpBB/includes/mcp/mcp_forum.php +++ b/phpBB/includes/mcp/mcp_forum.php @@ -98,7 +98,7 @@ function mcp_forum_view($id, $mode, $action, $forum_info) $sort_by_sql = $sort_order_sql = array(); mcp_sorting('viewforum', $sort_days, $sort_key, $sort_dir, $sort_by_sql, $sort_order_sql, $total, $forum_id); - $forum_topics = ($total == -1) ? $forum_info['forum_topics'] : $total; + $forum_topics = ($total == -1) ? $forum_info['forum_topics_approved'] : $total; $limit_time_sql = ($sort_days) ? 'AND t.topic_last_post_time >= ' . (time() - ($sort_days * 86400)) : ''; $base_url = $url . "&i=$id&action=$action&mode=$mode&sd=$sort_dir&sk=$sort_key&st=$sort_days" . (($merge_select) ? $selected_ids : ''); diff --git a/phpBB/includes/mcp/mcp_main.php b/phpBB/includes/mcp/mcp_main.php index aeaa37f4cb..d8ef3e261b 100644 --- a/phpBB/includes/mcp/mcp_main.php +++ b/phpBB/includes/mcp/mcp_main.php @@ -570,8 +570,8 @@ function mcp_move_topic($topic_ids) $sync_sql = array(); if ($posts_moved) { - $sync_sql[$to_forum_id][] = 'forum_posts = forum_posts + ' . (int) $posts_moved; - $sync_sql[$forum_id][] = 'forum_posts = forum_posts - ' . (int) $posts_moved; + $sync_sql[$to_forum_id][] = 'forum_posts_approved = forum_posts_approved + ' . (int) $posts_moved; + $sync_sql[$forum_id][] = 'forum_posts_approved = forum_posts_approved - ' . (int) $posts_moved; } if ($posts_moved_unapproved) { @@ -586,10 +586,10 @@ function mcp_move_topic($topic_ids) if ($topics_moved) { - $sync_sql[$to_forum_id][] = 'forum_topics = forum_topics + ' . (int) $topics_moved; + $sync_sql[$to_forum_id][] = 'forum_topics_approved = forum_topics_approved + ' . (int) $topics_moved; if ($topics_moved - $shadow_topics > 0) { - $sync_sql[$forum_id][] = 'forum_topics = forum_topics - ' . (int) ($topics_moved - $shadow_topics); + $sync_sql[$forum_id][] = 'forum_topics_approved = forum_topics_approved - ' . (int) ($topics_moved - $shadow_topics); } } if ($topics_moved_unapproved) @@ -1348,8 +1348,8 @@ function mcp_fork_topic($topic_ids) // Sync new topics, parent forums and board stats $sql = 'UPDATE ' . FORUMS_TABLE . ' - SET forum_posts = forum_posts + ' . $total_posts . ', - forum_topics = forum_topics + ' . sizeof($new_topic_id_list) . ' + SET forum_posts_approved = forum_posts_approved + ' . $total_posts . ', + forum_topics_approved = forum_topics_approved + ' . sizeof($new_topic_id_list) . ' WHERE forum_id = ' . $to_forum_id; $db->sql_query($sql); diff --git a/phpBB/includes/mcp/mcp_queue.php b/phpBB/includes/mcp/mcp_queue.php index ab2d5124af..e56aa17ee8 100644 --- a/phpBB/includes/mcp/mcp_queue.php +++ b/phpBB/includes/mcp/mcp_queue.php @@ -305,11 +305,11 @@ class mcp_queue trigger_error('NOT_MODERATOR'); } - $sql = 'SELECT SUM(forum_topics) as sum_forum_topics + $sql = 'SELECT SUM(forum_topics_approved) as sum_forum_topics FROM ' . FORUMS_TABLE . ' WHERE ' . $db->sql_in_set('forum_id', $forum_list); $result = $db->sql_query($sql); - $forum_info['forum_topics'] = (int) $db->sql_fetchfield('sum_forum_topics'); + $forum_info['forum_topics_approved'] = (int) $db->sql_fetchfield('sum_forum_topics'); $db->sql_freeresult($result); } else @@ -336,7 +336,7 @@ class mcp_queue $sort_by_sql = $sort_order_sql = array(); mcp_sorting($mode, $sort_days, $sort_key, $sort_dir, $sort_by_sql, $sort_order_sql, $total, $forum_id, $topic_id); - $forum_topics = ($total == -1) ? $forum_info['forum_topics'] : $total; + $forum_topics = ($total == -1) ? $forum_info['forum_topics_approved'] : $total; $limit_time_sql = ($sort_days) ? 'AND t.topic_last_post_time >= ' . (time() - ($sort_days * 86400)) : ''; $forum_names = array(); diff --git a/phpBB/includes/mcp/mcp_reports.php b/phpBB/includes/mcp/mcp_reports.php index dc917a25e0..38d2ea48fa 100644 --- a/phpBB/includes/mcp/mcp_reports.php +++ b/phpBB/includes/mcp/mcp_reports.php @@ -295,11 +295,11 @@ class mcp_reports $global_id = $forum_list[0]; - $sql = 'SELECT SUM(forum_topics) as sum_forum_topics + $sql = 'SELECT SUM(forum_topics_approved) as sum_forum_topics FROM ' . FORUMS_TABLE . ' WHERE ' . $db->sql_in_set('forum_id', $forum_list); $result = $db->sql_query($sql); - $forum_info['forum_topics'] = (int) $db->sql_fetchfield('sum_forum_topics'); + $forum_info['forum_topics_approved'] = (int) $db->sql_fetchfield('sum_forum_topics'); $db->sql_freeresult($result); } else @@ -331,7 +331,7 @@ class mcp_reports $sort_by_sql = $sort_order_sql = array(); mcp_sorting($mode, $sort_days, $sort_key, $sort_dir, $sort_by_sql, $sort_order_sql, $total, $forum_id, $topic_id); - $forum_topics = ($total == -1) ? $forum_info['forum_topics'] : $total; + $forum_topics = ($total == -1) ? $forum_info['forum_topics_approved'] : $total; $limit_time_sql = ($sort_days) ? 'AND r.report_time >= ' . (time() - ($sort_days * 86400)) : ''; if ($mode == 'reports') -- cgit v1.2.1 From 6e93fee9d2f5951ff85bf658e3da42e4f6d153ec Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 10 Nov 2012 11:55:06 +0100 Subject: [feature/soft-delete] Link to delete_topics module when the topic is deleted PHPBB3-9567 --- phpBB/includes/mcp/mcp_forum.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/mcp/mcp_forum.php b/phpBB/includes/mcp/mcp_forum.php index 7c3bffe717..e8c5550cb7 100644 --- a/phpBB/includes/mcp/mcp_forum.php +++ b/phpBB/includes/mcp/mcp_forum.php @@ -220,12 +220,11 @@ function mcp_forum_view($id, $mode, $action, $forum_info) $topic_title = censor_text($row['topic_title']); - // @todo: $topic_unapproved = ($row['topic_visibility'] == ITEM_UNAPPROVED && $auth->acl_get('m_approve', $row['forum_id'])) ? true : false; $posts_unapproved = ($row['topic_visibility'] == ITEM_APPROVED && $row['topic_posts_unapproved'] && $auth->acl_get('m_approve', $row['forum_id'])) ? true : false; - $topic_deleted = ($row['topic_visibility'] == ITEM_DELETED) ? true : false; + $topic_deleted = $row['topic_visibility'] == ITEM_DELETED; $u_mcp_queue = ($topic_unapproved || $posts_unapproved) ? $url . '&i=queue&mode=' . (($topic_unapproved) ? 'approve_details' : 'unapproved_posts') . '&t=' . $row['topic_id'] : ''; - $u_mcp_queue = (!$u_mcp_queue && $topic_deleted) ? $url . 'i=queue&mode=deleted_posts&t=' . $topic_id : $u_mcp_queue; + $u_mcp_queue = (!$u_mcp_queue && $topic_deleted) ? $url . 'i=queue&mode=deleted_topics&t=' . $topic_id : $u_mcp_queue; $topic_row = array( 'ATTACH_ICON_IMG' => ($auth->acl_get('u_download') && $auth->acl_get('f_download', $row['forum_id']) && $row['topic_attachment']) ? $user->img('icon_topic_attach', $user->lang['TOTAL_ATTACHMENTS']) : '', -- cgit v1.2.1 From 293b070efba81dd03d633fc9641c83c63c468bb8 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 18 Dec 2012 14:50:00 +0100 Subject: [feature/soft-delete] Fix a problem with the "only softdeleted posts" logic PHPBB3-9657 --- phpBB/includes/mcp/mcp_main.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/mcp/mcp_main.php b/phpBB/includes/mcp/mcp_main.php index d8ef3e261b..d29ecfe003 100644 --- a/phpBB/includes/mcp/mcp_main.php +++ b/phpBB/includes/mcp/mcp_main.php @@ -786,15 +786,15 @@ function mcp_delete_topic($topic_ids, $is_soft = false, $soft_delete_reason = '' $user->add_lang('posting'); $only_softdeleted = false; - // If there are only soft deleted topics, we display a message why the option is not available if ($auth->acl_get('m_delete', $forum_id) && $auth->acl_get('m_softdelete', $forum_id)) { + // If there are only soft deleted topics, we display a message why the option is not available $sql = 'SELECT topic_id FROM ' . TOPICS_TABLE . ' WHERE ' . $db->sql_in_set('topic_id', $topic_ids) . ' AND topic_visibility <> ' . ITEM_DELETED; $result = $db->sql_query_limit($sql, 1); - $only_softdeleted = (bool) $db->sql_fetchfield('topic_id'); + $only_softdeleted = !$db->sql_fetchfield('topic_id'); $db->sql_freeresult($result); } @@ -806,7 +806,7 @@ function mcp_delete_topic($topic_ids, $is_soft = false, $soft_delete_reason = '' 'S_DELETE_REASON' => $auth->acl_get('m_softdelete', $forum_id), )); - $l_confirm = (sizeof($post_ids) == 1) ? 'DELETE_TOPIC' : 'DELETE_TOPICS'; + $l_confirm = (sizeof($topic_ids) == 1) ? 'DELETE_TOPIC' : 'DELETE_TOPICS'; if ($only_softdeleted) { $l_confirm .= '_PERMANENTLY'; @@ -1023,15 +1023,15 @@ function mcp_delete_post($post_ids, $is_soft = false, $soft_delete_reason = '') $user->add_lang('posting'); $only_softdeleted = false; - // If there are only soft deleted posts, we display a message why the option is not available if ($auth->acl_get('m_delete', $forum_id) && $auth->acl_get('m_softdelete', $forum_id)) { + // If there are only soft deleted posts, we display a message why the option is not available $sql = 'SELECT post_id FROM ' . POSTS_TABLE . ' WHERE ' . $db->sql_in_set('post_id', $post_ids) . ' AND post_visibility <> ' . ITEM_DELETED; $result = $db->sql_query_limit($sql, 1); - $only_softdeleted = (bool) $db->sql_fetchfield('post_id'); + $only_softdeleted = !$db->sql_fetchfield('post_id'); $db->sql_freeresult($result); } -- cgit v1.2.1 From 4300d06a172fd7950405dc23077b57354452d9b1 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 18 Dec 2012 14:51:05 +0100 Subject: [feature/soft-delete] Add "Restore" to the mcp forum quick moderation PHPBB3-9657 --- phpBB/includes/mcp/mcp_forum.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/mcp/mcp_forum.php b/phpBB/includes/mcp/mcp_forum.php index 693a9d77e2..5fb9710eed 100644 --- a/phpBB/includes/mcp/mcp_forum.php +++ b/phpBB/includes/mcp/mcp_forum.php @@ -116,6 +116,7 @@ function mcp_forum_view($id, $mode, $action, $forum_info) 'S_CAN_REPORT' => $auth->acl_get('m_report', $forum_id), 'S_CAN_DELETE' => $auth->acl_get('m_delete', $forum_id), + 'S_CAN_RESTORE' => $auth->acl_get('m_approve', $forum_id), 'S_CAN_MERGE' => $auth->acl_get('m_merge', $forum_id), 'S_CAN_MOVE' => $auth->acl_get('m_move', $forum_id), 'S_CAN_FORK' => $auth->acl_get('m_', $forum_id), @@ -224,7 +225,7 @@ function mcp_forum_view($id, $mode, $action, $forum_info) $posts_unapproved = ($row['topic_visibility'] == ITEM_APPROVED && $row['topic_posts_unapproved'] && $auth->acl_get('m_approve', $row['forum_id'])) ? true : false; $topic_deleted = $row['topic_visibility'] == ITEM_DELETED; $u_mcp_queue = ($topic_unapproved || $posts_unapproved) ? $url . '&i=queue&mode=' . (($topic_unapproved) ? 'approve_details' : 'unapproved_posts') . '&t=' . $row['topic_id'] : ''; - $u_mcp_queue = (!$u_mcp_queue && $topic_deleted) ? $url . 'i=queue&mode=deleted_topics&t=' . $topic_id : $u_mcp_queue; + $u_mcp_queue = (!$u_mcp_queue && $topic_deleted) ? $url . '&i=queue&mode=deleted_topics&t=' . $topic_id : $u_mcp_queue; $topic_row = array( 'ATTACH_ICON_IMG' => ($auth->acl_get('u_download') && $auth->acl_get('f_download', $row['forum_id']) && $row['topic_attachment']) ? $user->img('icon_topic_attach', $user->lang['TOTAL_ATTACHMENTS']) : '', -- cgit v1.2.1 From 63f3cd45bb30354b4707b542e54e7dad0f99e15c Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 18 Dec 2012 15:08:05 +0100 Subject: [feature/soft-delete] Add delete information to approve deatils page PHPBB3-9657 --- phpBB/includes/mcp/mcp_queue.php | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/mcp/mcp_queue.php b/phpBB/includes/mcp/mcp_queue.php index e56aa17ee8..4180b5b08f 100644 --- a/phpBB/includes/mcp/mcp_queue.php +++ b/phpBB/includes/mcp/mcp_queue.php @@ -205,6 +205,33 @@ class mcp_queue } } + // Deleting information + if ($post_info['post_visibility'] == ITEM_DELETED && $post_info['post_delete_user']) + { + // User having deleted the post also being the post author? + if (!$post_info['post_delete_user'] || $post_info['post_delete_user'] == $post_info['poster_id']) + { + $display_username = get_username_string('full', $post_info['poster_id'], $post_info['username'], $post_info['user_colour'], $post_info['post_username']); + } + else + { + $sql = 'SELECT u.user_id, u.username, u.user_colour + FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . ' u + WHERE p.post_id = ' . $post_info['post_id'] . ' + AND p.post_delete_user = u.user_id'; + $result = $db->sql_query($sql); + $post_delete_userinfo = $db->sql_fetchrow($result); + $db->sql_freeresult($result); + $display_username = get_username_string('full', $post_info['post_delete_user'], $post_delete_userinfo['username'], $post_delete_userinfo['user_colour']); + } + + $l_deleted_by = $user->lang('DELETED_INFORMATION', $display_username, $user->format_date($post_info['post_delete_time'], false, true)); + } + else + { + $l_deleted_by = ''; + } + $post_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $post_info['forum_id'] . '&p=' . $post_info['post_id'] . '#p' . $post_info['post_id']); $topic_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $post_info['forum_id'] . '&t=' . $post_info['topic_id']); @@ -216,6 +243,9 @@ class mcp_queue 'S_POST_UNAPPROVED' => ($post_info['post_visibility'] == ITEM_UNAPPROVED), 'S_POST_LOCKED' => $post_info['post_edit_locked'], 'S_USER_NOTES' => true, + 'S_POST_DELETED' => ($post_info['post_visibility'] == ITEM_DELETED), + 'DELETED_MESSAGE' => $l_deleted_by, + 'DELETE_REASON' => $post_info['post_delete_reason'], 'U_EDIT' => ($auth->acl_get('m_edit', $post_info['forum_id'])) ? append_sid("{$phpbb_root_path}posting.$phpEx", "mode=edit&f={$post_info['forum_id']}&p={$post_info['post_id']}") : '', 'U_MCP_APPROVE' => append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=queue&mode=approve_details&f=' . $post_info['forum_id'] . '&p=' . $post_id), @@ -227,6 +257,7 @@ class mcp_queue 'MINI_POST_IMG' => ($post_unread) ? $user->img('icon_post_target_unread', 'UNREAD_POST') : $user->img('icon_post_target', 'POST'), + 'RETURN_QUEUE' => sprintf($user->lang['RETURN_QUEUE'], '", ''), 'RETURN_POST' => sprintf($user->lang['RETURN_POST'], '', ''), 'RETURN_TOPIC_SIMPLE' => sprintf($user->lang['RETURN_TOPIC_SIMPLE'], '', ''), -- cgit v1.2.1 From 6435b481c571dd44494f07b970339b104a8ffdd6 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 18 Dec 2012 15:32:13 +0100 Subject: [feature/soft-delete] Fix a problem with "delete topics" in mcp PHPBB3-9657 --- phpBB/includes/mcp/mcp_queue.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/mcp/mcp_queue.php b/phpBB/includes/mcp/mcp_queue.php index 4180b5b08f..8b7b4ffda8 100644 --- a/phpBB/includes/mcp/mcp_queue.php +++ b/phpBB/includes/mcp/mcp_queue.php @@ -71,9 +71,10 @@ class mcp_queue { if (!empty($topic_id_list)) { + $post_visibility = ($mode == 'deleted_topics') ? ITEM_DELETED : ITEM_UNAPPROVED; $sql = 'SELECT post_id FROM ' . POSTS_TABLE . ' - WHERE post_visibility = ' . ITEM_UNAPPROVED . ' + WHERE post_visibility = ' . $post_visibility . ' AND ' . $db->sql_in_set('topic_id', $topic_id_list); $result = $db->sql_query($sql); -- cgit v1.2.1 From 24e1881ea1fd4da0bdf6de8f58cf8527b9087270 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 20 Dec 2012 15:23:29 +0100 Subject: [feature/soft-delete] Split up on the initial switch instead of a second one Also fixing some documentation issues PHPBB3-9657 --- phpBB/includes/mcp/mcp_queue.php | 71 +++++++++++++++++----------------------- 1 file changed, 30 insertions(+), 41 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/mcp/mcp_queue.php b/phpBB/includes/mcp/mcp_queue.php index 8b7b4ffda8..dd3321e4e5 100644 --- a/phpBB/includes/mcp/mcp_queue.php +++ b/phpBB/includes/mcp/mcp_queue.php @@ -45,55 +45,44 @@ class mcp_queue switch ($action) { case 'approve': - case 'disapprove': case 'restore': include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx); $post_id_list = $request->variable('post_id_list', array(0)); $topic_id_list = $request->variable('topic_id_list', array(0)); - if ($action != 'disapprove') + if (!empty($post_id_list)) { - if (!empty($post_id_list)) - { - self::approve_posts($action, $post_id_list, 'queue', $mode); - } - else if (!empty($topic_id_list)) - { - self::approve_topics($action, $topic_id_list, 'queue', $mode); - } - else - { - trigger_error('NO_POST_SELECTED'); - } + self::approve_posts($action, $post_id_list, 'queue', $mode); + } + else if (!empty($topic_id_list)) + { + self::approve_topics($action, $topic_id_list, 'queue', $mode); } else { - if (!empty($topic_id_list)) - { - $post_visibility = ($mode == 'deleted_topics') ? ITEM_DELETED : ITEM_UNAPPROVED; - $sql = 'SELECT post_id - FROM ' . POSTS_TABLE . ' - WHERE post_visibility = ' . $post_visibility . ' - AND ' . $db->sql_in_set('topic_id', $topic_id_list); - $result = $db->sql_query($sql); + trigger_error('NO_POST_SELECTED'); + } + break; - $post_id_list = array(); - while ($row = $db->sql_fetchrow($result)) - { - $post_id_list[] = (int) $row['post_id']; - } - $db->sql_freeresult($result); - } + case 'delete': + case 'disapprove': + include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx); - if (!empty($post_id_list)) - { - self::disapprove_posts($post_id_list, 'queue', $mode); - } - else - { - trigger_error('NO_POST_SELECTED'); - } + $post_id_list = $request->variable('post_id_list', array(0)); + $topic_id_list = $request->variable('topic_id_list', array(0)); + + if (!empty($post_id_list)) + { + self::disapprove_posts($post_id_list, 'queue', $mode); + } + else if (!empty($topic_id_list)) + { + self::disapprove_topics($action, $topic_id_list, 'queue', $mode); + } + else + { + trigger_error('NO_POST_SELECTED'); } break; } @@ -523,7 +512,7 @@ class mcp_queue * @param $post_id_list array IDs of the posts to approve/restore * @param $id mixed Category of the current active module * @param $mode string Active module - * @return void + * @return null */ static public function approve_posts($action, $post_id_list, $id, $mode) { @@ -716,7 +705,7 @@ class mcp_queue * @param $topic_id_list array IDs of the topics to approve/restore * @param $id mixed Category of the current active module * @param $mode string Active module - * @return void + * @return null */ static public function approve_topics($action, $topic_id_list, $id, $mode) { @@ -876,10 +865,10 @@ class mcp_queue /** * Disapprove Post * - * @param $post_id_list array IDs of the posts to approve/restore + * @param $post_id_list array IDs of the posts to disapprove/delete * @param $id mixed Category of the current active module * @param $mode string Active module - * @return void + * @return null */ static public function disapprove_posts($post_id_list, $id, $mode) { -- cgit v1.2.1 From 4498c5aaebb1122b783b52a66f78d56e0ff2c63c Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 20 Dec 2012 19:23:26 +0100 Subject: [feature/soft-delete] Split deleting soft-deleted posts from unapproving posts PHPBB3-9657 --- phpBB/includes/mcp/mcp_main.php | 8 ++--- phpBB/includes/mcp/mcp_queue.php | 63 ++++++++++++++++++++++++++++++++++++---- 2 files changed, 61 insertions(+), 10 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/mcp/mcp_main.php b/phpBB/includes/mcp/mcp_main.php index d29ecfe003..cf7c8af255 100644 --- a/phpBB/includes/mcp/mcp_main.php +++ b/phpBB/includes/mcp/mcp_main.php @@ -724,7 +724,7 @@ function mcp_restore_topic($topic_ids) /** * Delete Topics */ -function mcp_delete_topic($topic_ids, $is_soft = false, $soft_delete_reason = '') +function mcp_delete_topic($topic_ids, $is_soft = false, $soft_delete_reason = '', $action = 'delete_topic') { global $auth, $user, $db, $phpEx, $phpbb_root_path, $request; @@ -739,7 +739,7 @@ function mcp_delete_topic($topic_ids, $is_soft = false, $soft_delete_reason = '' $s_hidden_fields = array( 'topic_id_list' => $topic_ids, 'f' => $forum_id, - 'action' => 'delete_topic', + 'action' => $action, 'redirect' => $redirect, ); $success_msg = ''; @@ -852,7 +852,7 @@ function mcp_delete_topic($topic_ids, $is_soft = false, $soft_delete_reason = '' /** * Delete Posts */ -function mcp_delete_post($post_ids, $is_soft = false, $soft_delete_reason = '') +function mcp_delete_post($post_ids, $is_soft = false, $soft_delete_reason = '', $action = 'delete_post') { global $auth, $user, $db, $phpEx, $phpbb_root_path, $request; @@ -867,7 +867,7 @@ function mcp_delete_post($post_ids, $is_soft = false, $soft_delete_reason = '') $s_hidden_fields = array( 'post_id_list' => $post_ids, 'f' => $forum_id, - 'action' => 'delete_post', + 'action' => $action, 'redirect' => $redirect, ); $success_msg = ''; diff --git a/phpBB/includes/mcp/mcp_queue.php b/phpBB/includes/mcp/mcp_queue.php index dd3321e4e5..d9ec10e6da 100644 --- a/phpBB/includes/mcp/mcp_queue.php +++ b/phpBB/includes/mcp/mcp_queue.php @@ -66,19 +66,70 @@ class mcp_queue break; case 'delete': - case 'disapprove': - include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx); - $post_id_list = $request->variable('post_id_list', array(0)); $topic_id_list = $request->variable('topic_id_list', array(0)); if (!empty($post_id_list)) { - self::disapprove_posts($post_id_list, 'queue', $mode); + if (!function_exists('mcp_delete_post')) + { + global $phpbb_root_path, $phpEx; + include($phpbb_root_path . 'includes/mcp/mcp_main.' . $phpEx); + } + mcp_delete_post($post_id_list, false, '', $action); } else if (!empty($topic_id_list)) { - self::disapprove_topics($action, $topic_id_list, 'queue', $mode); + if (!function_exists('mcp_delete_topic')) + { + global $phpbb_root_path, $phpEx; + include($phpbb_root_path . 'includes/mcp/mcp_main.' . $phpEx); + } + mcp_delete_topic($topic_id_list, false, '', $action); + } + else + { + trigger_error('NO_POST_SELECTED'); + } + break; + + case 'disapprove': + $post_id_list = $request->variable('post_id_list', array(0)); + $topic_id_list = $request->variable('topic_id_list', array(0)); + + if (!empty($topic_id_list) && $mode == 'deleted_topics') + { + if (!function_exists('mcp_delete_topics')) + { + global $phpbb_root_path, $phpEx; + include($phpbb_root_path . 'includes/mcp/mcp_main.' . $phpEx); + } + mcp_delete_topic($topic_id_list, false, '', 'disapprove'); + return; + } + + include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx); + + if (!empty($topic_id_list)) + { + $post_visibility = ($mode == 'deleted_topics') ? ITEM_DELETED : ITEM_UNAPPROVED; + $sql = 'SELECT post_id + FROM ' . POSTS_TABLE . ' + WHERE post_visibility = ' . $post_visibility . ' + AND ' . $db->sql_in_set('topic_id', $topic_id_list); + $result = $db->sql_query($sql); + + $post_id_list = array(); + while ($row = $db->sql_fetchrow($result)) + { + $post_id_list[] = (int) $row['post_id']; + } + $db->sql_freeresult($result); + } + + if (!empty($post_id_list)) + { + self::disapprove_posts($post_id_list, 'queue', $mode); } else { @@ -893,7 +944,7 @@ class mcp_queue 'redirect' => $redirect) ); - $notify_poster = (isset($_REQUEST['notify_poster'])) ? true : false; + $notify_poster = $request->is_set('notify_poster'); $disapprove_reason = ''; if ($reason_id) -- cgit v1.2.1 From a21de6e3f845f56026757e370b0bae8a02997bad Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 5 Mar 2013 17:09:33 +0100 Subject: [ticket/9657] Rebuild notifications in mcp_queue.php PHPBB3-9657 --- phpBB/includes/mcp/mcp_queue.php | 157 ++++++++++++++++++--------------------- 1 file changed, 72 insertions(+), 85 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/mcp/mcp_queue.php b/phpBB/includes/mcp/mcp_queue.php index 6f9f16bde4..01abdc82d8 100644 --- a/phpBB/includes/mcp/mcp_queue.php +++ b/phpBB/includes/mcp/mcp_queue.php @@ -650,46 +650,39 @@ class mcp_queue // Only send out the mails, when the posts are being approved if ($action == 'approve') { - $messenger = new messenger(); + $phpbb_notifications = $phpbb_container->get('notification_manager'); - // Notify Poster? - if ($notify_poster) + // Send out normal user notifications + $email_sig = str_replace('
', "\n", "-- \n" . $config['board_email_sig']); + + // Handle notifications + foreach ($post_info as $post_id => $post_data) { - foreach ($post_info as $post_id => $post_data) + $phpbb_notifications->delete_notifications('post_in_queue', $post_id); + + $phpbb_notifications->add_notifications(array( + 'quote', + 'bookmark', + 'post', + ), $post_data); + + $phpbb_notifications->mark_notifications_read(array( + 'quote', + 'bookmark', + 'post', + ), $post_data['post_id'], $user->data['user_id']); + + // Notify Poster? + if ($notify_poster) { if ($post_data['poster_id'] == ANONYMOUS) { continue; } - $messenger->template('post_approved', $post_data['user_lang']); - - $messenger->to($post_data['user_email'], $post_data['username']); - $messenger->im($post_data['user_jabber'], $post_data['username']); - - $messenger->assign_vars(array( - 'USERNAME' => htmlspecialchars_decode($post_data['username']), - 'POST_SUBJECT' => htmlspecialchars_decode(censor_text($post_data['post_subject'])), - 'TOPIC_TITLE' => htmlspecialchars_decode(censor_text($post_data['topic_title'])), - - 'U_VIEW_TOPIC' => generate_board_url() . "/viewtopic.$phpEx?f={$post_data['forum_id']}&t={$post_data['topic_id']}&e=0", - 'U_VIEW_POST' => generate_board_url() . "/viewtopic.$phpEx?f={$post_data['forum_id']}&t={$post_data['topic_id']}&p=$post_id&e=$post_id") - ); - - $messenger->send($post_data['user_notify_type']); + $phpbb_notifications->add_notifications('approve_post', $post_data); } } - - $messenger->save_queue(); - - // Send out normal user notifications - $email_sig = str_replace('
', "\n", "-- \n" . $config['board_email_sig']); - - foreach ($post_info as $post_id => $post_data) - { - // Topic Notifications - user_notification('reply', $post_data['post_subject'], $post_data['topic_title'], $post_data['forum_name'], $post_data['forum_id'], $post_data['topic_id'], $post_id); - } } } else @@ -818,41 +811,27 @@ class mcp_queue // Only send out the mails, when the posts are being approved if ($action == 'approve') { - $messenger = new messenger(); - - // Notify Poster? - if ($notify_poster) - { - foreach ($topic_info as $topic_id => $topic_data) - { - if ($topic_data['topic_poster'] == ANONYMOUS) - { - continue; - } - - $messenger->template('topic_approved', $topic_data['user_lang']); - $messenger->to($topic_data['user_email'], $topic_data['username']); - $messenger->im($topic_data['user_jabber'], $topic_data['username']); - - $messenger->assign_vars(array( - 'USERNAME' => htmlspecialchars_decode($topic_data['username']), - 'TOPIC_TITLE' => htmlspecialchars_decode(censor_text($topic_data['topic_title'])), - 'U_VIEW_TOPIC' => generate_board_url() . "/viewtopic.$phpEx?f={$topic_data['forum_id']}&t={$topic_data['topic_id']}&e=0", - )); - - $messenger->send($topic_data['user_notify_type']); - } - } - - $messenger->save_queue(); - // Send out normal user notifications $email_sig = str_replace('
', "\n", "-- \n" . $config['board_email_sig']); + // Handle notifications + $phpbb_notifications = $phpbb_container->get('notification_manager'); + foreach ($topic_info as $topic_id => $topic_data) { - // Forum Notifications - user_notification('post', $topic_data['topic_title'], $topic_data['topic_title'], $topic_data['forum_name'], $topic_data['forum_id'], $topic_data['topic_id'], 0); + $phpbb_notifications->delete_notifications('topic_in_queue', $post_data['topic_id']); + $phpbb_notifications->add_notifications(array( + 'quote', + 'topic', + ), $post_data); + + $phpbb_notifications->mark_notifications_read('quote', $post_data['post_id'], $user->data['user_id']); + $phpbb_notifications->mark_notifications_read('topic', $post_data['topic_id'], $user->data['user_id']); + + if ($notify_poster) + { + $phpbb_notifications->add_notifications('approve_topic', $post_data); + } } } } @@ -1068,20 +1047,33 @@ class mcp_queue } } - $messenger = new messenger(); + $phpbb_notifications = $phpbb_container->get('notification_manager'); - // Notify Poster? - if ($notify_poster) + $lang_reasons = array(); + + foreach ($post_info as $post_id => $post_data) { - $lang_reasons = array(); + $disapprove_all_posts_in_topic = $topic_information[$topic_id]['topic_posts_approved'] == 0 && + $topic_information[$topic_id]['topic_posts_softdeleted'] == 0 && + $topic_information[$topic_id]['topic_posts_unapproved'] == $topic_posts_unapproved[$topic_id]; - foreach ($post_info as $post_id => $post_data) + $phpbb_notifications->delete_notifications('post_in_queue', $post_id); + + // Do we disapprove the whole topic? Remove potential notifications + if ($disapprove_all_posts_in_topic) + { + $phpbb_notifications->delete_notifications('topic_in_queue', $post_data['topic_id']); + } + + // Notify Poster? + if ($notify_poster) { if ($post_data['poster_id'] == ANONYMOUS) { continue; } + $post_data['disapprove_reason'] = ''; if (isset($disapprove_reason_lang)) { // Okay we need to get the reason from the posters language @@ -1107,32 +1099,27 @@ class mcp_queue } } - $email_disapprove_reason = $lang_reasons[$post_data['user_lang']]; - $email_disapprove_reason .= ($reason) ? "\n\n" . $reason : ''; + $post_data['disapprove_reason'] = $lang_reasons[$post_data['user_lang']]; + $post_data['disapprove_reason'] .= ($reason) ? "\n\n" . $reason : ''; } - $email_template = ($post_data['post_id'] == $post_data['topic_first_post_id'] && $post_data['post_id'] == $post_data['topic_last_post_id']) ? 'topic_disapproved' : 'post_disapproved'; - - $messenger->template($email_template, $post_data['user_lang']); - $messenger->to($post_data['user_email'], $post_data['username']); - $messenger->im($post_data['user_jabber'], $post_data['username']); - - $messenger->assign_vars(array( - 'USERNAME' => htmlspecialchars_decode($post_data['username']), - 'REASON' => htmlspecialchars_decode($email_disapprove_reason), - 'POST_SUBJECT' => htmlspecialchars_decode(censor_text($post_data['post_subject'])), - 'TOPIC_TITLE' => htmlspecialchars_decode(censor_text($post_data['topic_title']))) - ); - - $messenger->send($post_data['user_notify_type']); + if ($disapprove_all_posts_in_topic && $topic_information[$topic_id]['topic_posts_unapproved'] == 1) + { + // If there is only 1 post when disapproving the topic, + // we send the user a "disapprove topic" notification... + $phpbb_notifications->add_notifications('disapprove_topic', $post_data); + } + else + { + // ... otherwise there are multiple unapproved posts and + // all of them are disapproved as posts. + $phpbb_notifications->add_notifications('disapprove_post', $post_data); + } } - - unset($lang_reasons); } - unset($post_info, $disapprove_reason, $email_disapprove_reason, $disapprove_reason_lang); - $messenger->save_queue(); + unset($lang_reasons,$post_info, $disapprove_reason, $email_disapprove_reason, $disapprove_reason_lang); if ($num_disapproved_topics) { -- cgit v1.2.1 From 6c6912f9e65f0683a806548bdc1a3526ed9ae107 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 5 Mar 2013 18:23:13 +0100 Subject: [ticket/9657] FIx merge conflict from merging develop PHPBB3-9657 --- phpBB/includes/search/fulltext_native.php | 6 +----- phpBB/includes/search/fulltext_postgres.php | 6 +----- 2 files changed, 2 insertions(+), 10 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/search/fulltext_native.php b/phpBB/includes/search/fulltext_native.php index 90ea553ddc..2a9b552928 100644 --- a/phpBB/includes/search/fulltext_native.php +++ b/phpBB/includes/search/fulltext_native.php @@ -913,11 +913,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base * @param int $per_page number of ids each page is supposed to contain * @return boolean|int total number of results */ -<<<<<<< HEAD - public function author_search($type, $firstpost_only, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $post_visibility, $topic_id, $author_ary, $author_name, &$id_ary, $start, $per_page) -======= - public function author_search($type, $firstpost_only, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_ary, $author_name, &$id_ary, &$start, $per_page) ->>>>>>> bee4f8d8185d4ff5278be758db4ea4a814f09b4f + public function author_search($type, $firstpost_only, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $post_visibility, $topic_id, $author_ary, $author_name, &$id_ary, &$start, $per_page) { // No author? No posts if (!sizeof($author_ary)) diff --git a/phpBB/includes/search/fulltext_postgres.php b/phpBB/includes/search/fulltext_postgres.php index d5deb47222..8ccd27f43a 100644 --- a/phpBB/includes/search/fulltext_postgres.php +++ b/phpBB/includes/search/fulltext_postgres.php @@ -546,11 +546,7 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base * @param int $per_page number of ids each page is supposed to contain * @return boolean|int total number of results */ -<<<<<<< HEAD - public function author_search($type, $firstpost_only, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $post_visibility, $topic_id, $author_ary, $author_name, &$id_ary, $start, $per_page) -======= - public function author_search($type, $firstpost_only, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_ary, $author_name, &$id_ary, &$start, $per_page) ->>>>>>> bee4f8d8185d4ff5278be758db4ea4a814f09b4f + public function author_search($type, $firstpost_only, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $post_visibility, $topic_id, $author_ary, $author_name, &$id_ary, &$start, $per_page) { // No author? No posts if (!sizeof($author_ary)) -- cgit v1.2.1 From e1f5e98fbca5c3f989a829fa763a471e04082e64 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 6 Mar 2013 12:26:43 +0100 Subject: [ticket/9657] Correctly state when to refresh last/first post info on approving PHPBB3-9657 --- phpBB/includes/mcp/mcp_queue.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/mcp/mcp_queue.php b/phpBB/includes/mcp/mcp_queue.php index 01abdc82d8..0e835b0aa9 100644 --- a/phpBB/includes/mcp/mcp_queue.php +++ b/phpBB/includes/mcp/mcp_queue.php @@ -613,12 +613,14 @@ class mcp_queue $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']) + // Refresh the first post, if the time or id is older then the current one + if ($post_id <= $post_data['topic_first_post_id'] || $post_data['post_time'] <= $post_data['topic_time']) { $topic_info[$topic_id]['first_post'] = true; } - if ($post_id == $post_data['topic_last_post_id']) + // Refresh the last post, if the time or id is newer then the current one + if ($post_id >= $post_data['topic_last_post_id'] || $post_data['post_time'] >= $post_data['topic_last_post_time']) { $topic_info[$topic_id]['last_post'] = true; } -- cgit v1.2.1 From 9bddf73d315de89fc65b74bcc81aca8dfe57a796 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 6 Mar 2013 13:52:11 +0100 Subject: [ticket/9657] Add migration files for updating the database PHPBB3-9657 --- .../db/migration/data/310/softdelete_p1.php | 171 +++++++++++++++++++++ .../db/migration/data/310/softdelete_p2.php | 74 +++++++++ 2 files changed, 245 insertions(+) create mode 100644 phpBB/includes/db/migration/data/310/softdelete_p1.php create mode 100644 phpBB/includes/db/migration/data/310/softdelete_p2.php (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/migration/data/310/softdelete_p1.php b/phpBB/includes/db/migration/data/310/softdelete_p1.php new file mode 100644 index 0000000000..35f6138ef6 --- /dev/null +++ b/phpBB/includes/db/migration/data/310/softdelete_p1.php @@ -0,0 +1,171 @@ +db_tools->sql_column_exists($this->table_prefix . 'posts', 'post_visibility'); + } + + static public function depends_on() + { + return array('phpbb_db_migration_data_310_dev'); + } + + public function update_schema() + { + return array( + 'add_columns' => array( + $this->table_prefix . 'forums' => array( + 'forum_posts_approved' => array('UINT', 0), + 'forum_posts_unapproved' => array('UINT', 0), + 'forum_posts_softdeleted' => array('UINT', 0), + 'forum_topics_approved' => array('UINT', 0), + 'forum_topics_unapproved' => array('UINT', 0), + 'forum_topics_softdeleted' => array('UINT', 0), + ), + $this->table_prefix . 'posts' => array( + 'post_visibility' => array('TINT:3', 0), + 'post_delete_time' => array('TIMESTAMP', 0), + 'post_delete_reason' => array('STEXT_UNI', ''), + 'post_delete_user' => array('UINT', 0), + ), + $this->table_prefix . 'topics' => array( + 'topic_visibility' => array('TINT:3', 0), + 'topic_delete_time' => array('TIMESTAMP', 0), + 'topic_delete_reason' => array('STEXT_UNI', ''), + 'topic_delete_user' => array('UINT', 0), + 'topic_posts_approved' => array('UINT', 0), + 'topic_posts_unapproved' => array('UINT', 0), + 'topic_posts_softdeleted' => array('UINT', 0), + ), + ), + 'add_index' => array( + $this->table_prefix . 'posts' => array( + 'post_visibility' => array('post_visibility'), + ), + $this->table_prefix . 'topics' => array( + 'topic_visibility' => array('topic_visibility'), + 'forum_vis_last' => array('forum_id', 'topic_visibility', 'topic_last_post_id'), + ), + ), + ); + } + + public function revert_schema() + { + return array( + 'drop_columns' => array( + $this->table_prefix . 'forums' => array( + 'forum_posts_approved', + 'forum_posts_unapproved', + 'forum_posts_softdeleted', + 'forum_topics_approved', + 'forum_topics_unapproved', + 'forum_topics_softdeleted', + ), + $this->table_prefix . 'posts' => array( + 'post_visibility', + 'post_delete_time', + 'post_delete_reason', + 'post_delete_user', + ), + $this->table_prefix . 'topics' => array( + 'topic_visibility', + 'topic_delete_time', + 'topic_delete_reason', + 'topic_delete_user', + 'topic_posts_approved', + 'topic_posts_unapproved', + 'topic_posts_softdeleted', + ), + ), + 'drop_keys' => array( + $this->table_prefix . 'posts' => array('post_visibility'), + $this->table_prefix . 'topics' => array('topic_visibility', 'forum_vis_last'), + ), + ); + } + + public function update_data() + { + return array( + array('custom', array(array($this, 'update_post_visibility'))), + array('custom', array(array($this, 'update_topic_visibility'))), + array('custom', array(array($this, 'update_topic_forum_counts'))), + + array('permission.add', array('f_softdelete', false)), + array('permission.add', array('m_softdelete', false)), + ); + } + + public function update_post_visibility() + { + $sql = 'UPDATE ' . $this->table_prefix . 'posts + SET post_visibility = post_approved'; + $this->sql_query($sql); + } + + public function update_topic_visibility() + { + $sql = 'UPDATE ' . $this->table_prefix . 'topics + SET topic_visibility = topic_approved'; + $this->sql_query($sql); + } + + public function update_topic_forum_counts() + { + $sql = 'UPDATE ' . $this->table_prefix . 'topics + SET topic_posts_approved = topic_replies + 1, + topic_posts_unapproved = topic_replies_real - topic_replies + WHERE topic_visibility = ' . ITEM_APPROVED; + $this->sql_query($sql); + + $sql = 'UPDATE ' . $this->table_prefix . 'topics + SET topic_posts_approved = 0, + topic_posts_unapproved = (topic_replies_real - topic_replies) + 1 + WHERE topic_visibility = ' . ITEM_UNAPPROVED; + $this->sql_query($sql); + + $sql = 'SELECT forum_id, topic_visibility, COUNT(topic_id) AS sum_topics, SUM(topic_posts) AS sum_posts, SUM(topic_posts_unapproved) AS sum_posts_unapproved + FROM ' . $this->table_prefix . 'topics + GROUP BY forum_id, topic_visibility'; + $result = $this->db->sql_query($sql); + + $update_forums = array(); + while ($row = $this->db->sql_fetchrow($result)) + { + $forum_id = (int) $row['forum_id']; + if (!isset($update_forums[$forum_id])) + { + $update_forums[$forum_id] = array( + 'forum_posts_approved' => 0, + 'forum_posts_unapproved' => 0, + 'forum_topics_approved' => 0, + 'forum_topics_unapproved' => 0, + ); + } + + $update_forums[$forum_id]['forum_posts_approved'] += (int) $row['sum_posts']; + $update_forums[$forum_id]['forum_posts_unapproved'] += (int) $row['sum_posts_unapproved']; + + $update_forums[$forum_id][(($row['topic_visibility'] == ITEM_APPROVED) ? 'forum_topics_approved' : 'forum_topics_unapproved')] += (int) $row['sum_topics']; + } + $this->db->sql_freeresult($result); + + foreach ($update_forums as $forum_id => $forum_data) + { + $sql = 'UPDATE ' . FORUMS_TABLE . ' + SET ' . $this->db->sql_build_array('UPDATE', $forum_data) . ' + WHERE forum_id = ' . $forum_id; + $this->sql_query($sql); + } + } +} diff --git a/phpBB/includes/db/migration/data/310/softdelete_p2.php b/phpBB/includes/db/migration/data/310/softdelete_p2.php new file mode 100644 index 0000000000..15de8e7185 --- /dev/null +++ b/phpBB/includes/db/migration/data/310/softdelete_p2.php @@ -0,0 +1,74 @@ +db_tools->sql_column_exists($this->table_prefix . 'posts', 'post_approved'); + } + + static public function depends_on() + { + return array( + 'phpbb_db_migration_data_310_dev', + 'phpbb_db_migration_data_310_softdelete_p1', + ); + } + + public function update_schema() + { + return array( + 'drop_columns' => array( + $this->table_prefix . 'forums' => array('forum_posts', 'forum_topics', 'forum_topics_real'), + $this->table_prefix . 'posts' => array('post_approved'), + $this->table_prefix . 'topics' => array('topic_approved', 'topic_replies', 'topic_replies_real'), + ), + 'drop_keys' => array( + $this->table_prefix . 'posts' => array('post_approved'), + $this->table_prefix . 'topics' => array('forum_appr_last'), + ), + ); + } + + public function revert_schema() + { + return array( + 'add_columns' => array( + $this->table_prefix . 'forums' => array( + 'forum_posts' => array('UINT', 0), + 'forum_topics' => array('UINT', 0), + 'forum_topics_real' => array('UINT', 0), + ), + $this->table_prefix . 'posts' => array( + 'post_approved' => array('BOOL', 1), + ), + $this->table_prefix . 'topics' => array( + 'topic_approved' => array('BOOL', 1), + 'topic_replies' => array('UINT', 0), + 'topic_replies_real' => array('UINT', 0), + ), + ), + 'add_index' => array( + $this->table_prefix . 'posts' => array( + 'post_approved' => array('post_approved'), + ), + $this->table_prefix . 'topics' => array( + 'forum_appr_last' => array('forum_id', 'topic_approved', 'topic_last_post_id'), + ), + ), + ); + } + + public function update_data() + { + return array( + ); + } +} -- cgit v1.2.1 From 74a9ecfd24e745a0c0ad394bac915d121ea72278 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 6 Mar 2013 16:29:50 +0100 Subject: [ticket/9657] Fix wrongly added notifications when post is posted softdeleted The post/topic should not trigger "*_in_queue" notifications if it is softdeleted, as it is not in the queue then. PHPBB3-9657 --- phpBB/includes/functions_posting.php | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index f9dacae655..d2ff095e25 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -2214,7 +2214,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u break; } } - else + else if ($post_visibility == ITEM_UNAPPROVED) { switch ($mode) { @@ -2231,6 +2231,32 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u case 'edit_first_post': case 'edit': case 'edit_last_post': + // @todo: Check whether these notification deletions are correct + $phpbb_notifications->delete_notifications('topic', $data['topic_id']); + + $phpbb_notifications->delete_notifications(array( + 'quote', + 'bookmark', + 'post', + ), $data['post_id']); + break; + } + } + else if ($post_visibility == ITEM_DELETED) + { + switch ($mode) + { + case 'post': + case 'reply': + case 'quote': + // Nothing to do here + break; + + case 'edit_topic': + case 'edit_first_post': + case 'edit': + case 'edit_last_post': + // @todo: Check whether these notification deletions are correct $phpbb_notifications->delete_notifications('topic', $data['topic_id']); $phpbb_notifications->delete_notifications(array( -- cgit v1.2.1 From 60c0da8b54e5347e472d2ce97e756623717fd011 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 7 Mar 2013 13:15:55 +0100 Subject: [ticket/9657] Remove empty update_data() method from p2 migration PHPBB3-9657 --- phpBB/includes/db/migration/data/310/softdelete_p2.php | 6 ------ 1 file changed, 6 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/migration/data/310/softdelete_p2.php b/phpBB/includes/db/migration/data/310/softdelete_p2.php index 15de8e7185..7320a2c2bf 100644 --- a/phpBB/includes/db/migration/data/310/softdelete_p2.php +++ b/phpBB/includes/db/migration/data/310/softdelete_p2.php @@ -65,10 +65,4 @@ class phpbb_db_migration_data_310_softdelete_p2 extends phpbb_db_migration ), ); } - - public function update_data() - { - return array( - ); - } } -- cgit v1.2.1 From bff6cf40ba03320247c777d651d47673b3d36d2b Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 7 Mar 2013 14:02:11 +0100 Subject: [ticket/9657] Fix colum name in migration file PHPBB3-9657 --- phpBB/includes/db/migration/data/310/softdelete_p1.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/migration/data/310/softdelete_p1.php b/phpBB/includes/db/migration/data/310/softdelete_p1.php index 35f6138ef6..84f8eebd4a 100644 --- a/phpBB/includes/db/migration/data/310/softdelete_p1.php +++ b/phpBB/includes/db/migration/data/310/softdelete_p1.php @@ -134,7 +134,7 @@ class phpbb_db_migration_data_310_softdelete_p1 extends phpbb_db_migration WHERE topic_visibility = ' . ITEM_UNAPPROVED; $this->sql_query($sql); - $sql = 'SELECT forum_id, topic_visibility, COUNT(topic_id) AS sum_topics, SUM(topic_posts) AS sum_posts, SUM(topic_posts_unapproved) AS sum_posts_unapproved + $sql = 'SELECT forum_id, topic_visibility, COUNT(topic_id) AS sum_topics, SUM(topic_posts_approved) AS sum_posts_approved, SUM(topic_posts_unapproved) AS sum_posts_unapproved FROM ' . $this->table_prefix . 'topics GROUP BY forum_id, topic_visibility'; $result = $this->db->sql_query($sql); @@ -153,7 +153,7 @@ class phpbb_db_migration_data_310_softdelete_p1 extends phpbb_db_migration ); } - $update_forums[$forum_id]['forum_posts_approved'] += (int) $row['sum_posts']; + $update_forums[$forum_id]['forum_posts_approved'] += (int) $row['sum_posts_approved']; $update_forums[$forum_id]['forum_posts_unapproved'] += (int) $row['sum_posts_unapproved']; $update_forums[$forum_id][(($row['topic_visibility'] == ITEM_APPROVED) ? 'forum_topics_approved' : 'forum_topics_unapproved')] += (int) $row['sum_topics']; -- cgit v1.2.1 From 1a498524138a7a3192ad14ad10f714b34488321f Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 7 Mar 2013 14:15:14 +0100 Subject: [ticket/9657] Remove unused email variables PHPBB3-9657 --- phpBB/includes/mcp/mcp_queue.php | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/mcp/mcp_queue.php b/phpBB/includes/mcp/mcp_queue.php index 0e835b0aa9..4383c5d571 100644 --- a/phpBB/includes/mcp/mcp_queue.php +++ b/phpBB/includes/mcp/mcp_queue.php @@ -654,9 +654,6 @@ class mcp_queue { $phpbb_notifications = $phpbb_container->get('notification_manager'); - // Send out normal user notifications - $email_sig = str_replace('
', "\n", "-- \n" . $config['board_email_sig']); - // Handle notifications foreach ($post_info as $post_id => $post_data) { @@ -813,9 +810,6 @@ class mcp_queue // Only send out the mails, when the posts are being approved if ($action == 'approve') { - // Send out normal user notifications - $email_sig = str_replace('
', "\n", "-- \n" . $config['board_email_sig']); - // Handle notifications $phpbb_notifications = $phpbb_container->get('notification_manager'); @@ -961,8 +955,6 @@ class mcp_queue { $disapprove_reason_lang = strtoupper($row['reason_title']); } - - $email_disapprove_reason = $disapprove_reason; } } @@ -1121,7 +1113,7 @@ class mcp_queue } } - unset($lang_reasons,$post_info, $disapprove_reason, $email_disapprove_reason, $disapprove_reason_lang); + unset($lang_reasons, $post_info, $disapprove_reason, $disapprove_reason_lang); if ($num_disapproved_topics) { -- cgit v1.2.1 From 7db5eec5d28449af2d313f52b4d4c1c4534ba870 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 10 Mar 2013 22:15:29 +0100 Subject: [ticket/9657] Correctly increase users post count when approving posts PHPBB3-9657 --- phpBB/includes/content_visibility.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/content_visibility.php b/phpBB/includes/content_visibility.php index 3118be6574..6ca1f8b25c 100644 --- a/phpBB/includes/content_visibility.php +++ b/phpBB/includes/content_visibility.php @@ -309,8 +309,7 @@ class phpbb_content_visibility { $sql = 'UPDATE ' . USERS_TABLE . ' SET user_posts = user_posts + ' . $num_posts . ' - WHERE ' . $db->sql_in_set('user_id', $poster_ids) . ' - AND user_posts >= ' . $num_posts; + WHERE ' . $db->sql_in_set('user_id', $poster_ids); $db->sql_query($sql); } } -- cgit v1.2.1 From cc5ba36a061215e0d96f32b67e9f1391e699ac63 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 10 Mar 2013 22:18:37 +0100 Subject: [ticket/9657] Cast IDs to integer PHPBB3-9657 --- phpBB/includes/content_visibility.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/content_visibility.php b/phpBB/includes/content_visibility.php index 6ca1f8b25c..ac827bd822 100644 --- a/phpBB/includes/content_visibility.php +++ b/phpBB/includes/content_visibility.php @@ -244,13 +244,13 @@ class phpbb_content_visibility if ($row['post_visibility'] != $visibility) { - if ($row['post_postcount'] && !isset($poster_postcounts[$row['poster_id']])) + if ($row['post_postcount'] && !isset($poster_postcounts[(int) $row['poster_id']])) { - $poster_postcounts[$row['poster_id']] = 1; + $poster_postcounts[(int) $row['poster_id']] = 1; } else if ($row['post_postcount']) { - $poster_postcounts[$row['poster_id']]++; + $poster_postcounts[(int) $row['poster_id']]++; } if (!isset($postcount_visibility[$row['post_visibility']])) @@ -411,12 +411,12 @@ class phpbb_content_visibility // Update the number for replies and posts $sql = 'UPDATE ' . TOPICS_TABLE . ' SET ' . implode(', ', $topic_sql) . ' - WHERE topic_id = ' . $topic_id; + WHERE topic_id = ' . (int) $topic_id; $db->sql_query($sql); $sql = 'UPDATE ' . FORUMS_TABLE . ' SET ' . implode(', ', $forum_sql) . ' - WHERE forum_id = ' . $forum_id; + WHERE forum_id = ' . (int) $forum_id; $db->sql_query($sql); } } -- cgit v1.2.1 From 147c98fa32ba5c1aeedb73486665a461f3b375aa Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 10 Mar 2013 22:21:38 +0100 Subject: [ticket/9657] Fix newly added empty line PHPBB3-9657 --- phpBB/includes/mcp/mcp_forum.php | 1 - 1 file changed, 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/mcp/mcp_forum.php b/phpBB/includes/mcp/mcp_forum.php index ddd27a1be2..a7302ce912 100644 --- a/phpBB/includes/mcp/mcp_forum.php +++ b/phpBB/includes/mcp/mcp_forum.php @@ -260,7 +260,6 @@ function mcp_forum_view($id, $mode, $action, $forum_info) 'S_POSTS_UNAPPROVED' => $posts_unapproved, 'S_TOPIC_DELETED' => $topic_deleted, 'S_UNREAD_TOPIC' => $unread_topic, - ); if ($row['topic_status'] == ITEM_MOVED) -- cgit v1.2.1 From f6dd688e7266ccbd4fda5bb5091cbb9056ebcf20 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 11 Mar 2013 12:40:33 +0100 Subject: [ticket/9657] Fix missing global $phpbb_container PHPBB3-9657 --- phpBB/includes/mcp/mcp_queue.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/mcp/mcp_queue.php b/phpBB/includes/mcp/mcp_queue.php index 4383c5d571..835f19555f 100644 --- a/phpBB/includes/mcp/mcp_queue.php +++ b/phpBB/includes/mcp/mcp_queue.php @@ -904,7 +904,7 @@ class mcp_queue */ static public function disapprove_posts($post_id_list, $id, $mode) { - global $db, $template, $user, $config; + global $db, $template, $user, $config, $phpbb_container; global $phpEx, $phpbb_root_path, $request; if (!check_ids($post_id_list, POSTS_TABLE, 'post_id', array('m_approve'))) -- cgit v1.2.1 From b727e1eedaab27c99a733b94bcdddbc55cc929d9 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 11 Mar 2013 16:37:43 +0100 Subject: [ticket/9657] Correctly split disapproving from perma deleting posts PHPBB3-9657 --- phpBB/includes/mcp/mcp_queue.php | 63 ++++++++++++++++++++++++++++++++++------ 1 file changed, 54 insertions(+), 9 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/mcp/mcp_queue.php b/phpBB/includes/mcp/mcp_queue.php index 835f19555f..29c0375e6c 100644 --- a/phpBB/includes/mcp/mcp_queue.php +++ b/phpBB/includes/mcp/mcp_queue.php @@ -960,6 +960,17 @@ class mcp_queue $post_info = get_post_data($post_id_list, 'm_approve'); + $is_disapproving = false; + foreach ($post_info as $post_id => $post_data) + { + if ($post_data['post_visibility'] == ITEM_DELETED) + { + continue; + } + + $is_disapproving = true; + } + if (confirm_box(true)) { $disapprove_log = $disapprove_log_topics = $disapprove_log_posts = array(); @@ -996,6 +1007,7 @@ class mcp_queue 'post_subject' => $post_info[$post_id]['topic_title'], 'forum_id' => $post_info[$post_id]['forum_id'], 'topic_id' => 0, // useless to log a topic id, as it will be deleted + 'post_username' => ($post_info[$post_id]['poster_id'] == ANONYMOUS && !empty($post_info[$post_id]['post_username'])) ? $post_info[$post_id]['post_username'] : $post_info[$post_id]['username'], ); } } @@ -1007,6 +1019,7 @@ class mcp_queue 'post_subject' => $post_info[$post_id]['post_subject'], 'forum_id' => $post_info[$post_id]['forum_id'], 'topic_id' => $post_info[$post_id]['topic_id'], + 'post_username' => ($post_info[$post_id]['poster_id'] == ANONYMOUS && !empty($post_info[$post_id]['post_username'])) ? $post_info[$post_id]['post_username'] : $post_info[$post_id]['username'], ); } @@ -1037,7 +1050,16 @@ class mcp_queue foreach ($disapprove_log as $log_data) { - add_log('mod', $log_data['forum_id'], $log_data['topic_id'], ($log_data['type'] == 'topic') ? 'LOG_TOPIC_DISAPPROVED' : 'LOG_POST_DISAPPROVED', $log_data['post_subject'], $disapprove_reason); + if ($is_disapproving) + { + $l_log_message = ($log_data['type'] == 'topic') ? 'LOG_TOPIC_DISAPPROVED' : 'LOG_POST_DISAPPROVED'; + add_log('mod', $log_data['forum_id'], $log_data['topic_id'], $l_log_message, $log_data['post_subject'], $disapprove_reason); + } + else + { + $l_log_message = ($log_data['type'] == 'topic') ? 'LOG_DELETE_TOPIC' : 'LOG_DELETE_POST'; + add_log('mod', $log_data['forum_id'], $log_data['topic_id'], $l_log_message, $log_data['post_subject'], $log_data['post_username']); + } } } @@ -1115,21 +1137,29 @@ class mcp_queue unset($lang_reasons, $post_info, $disapprove_reason, $disapprove_reason_lang); + if ($num_disapproved_topics) { - $success_msg = ($num_disapproved_topics == 1) ? 'TOPIC_DISAPPROVED_SUCCESS' : 'TOPICS_DISAPPROVED_SUCCESS'; + $success_msg = ($num_disapproved_topics == 1) ? 'TOPIC' : 'TOPICS'; } else { - $success_msg = ($num_disapproved_posts == 1) ? 'POST_DISAPPROVED_SUCCESS' : 'POSTS_DISAPPROVED_SUCCESS'; + $success_msg = ($num_disapproved_posts == 1) ? 'POST' : 'POSTS'; + } + + if ($is_disapproving) + { + $success_msg .= '_DISAPPROVED_SUCCESS'; + } + else + { + $success_msg .= '_DELETED_SUCCESS'; } } else { include_once($phpbb_root_path . 'includes/functions_display.' . $phpEx); - display_reasons($reason_id); - $show_notify = false; foreach ($post_info as $post_data) @@ -1145,14 +1175,29 @@ class mcp_queue } } + $l_confirm_msg = 'DISAPPROVE_POST'; + $confirm_template = 'mcp_approve.html'; + if ($is_disapproving) + { + display_reasons($reason_id); + } + else + { + $user->add_lang('posting'); + + $l_confirm_msg = 'DELETE_POST_PERMANENTLY'; + $confirm_template = 'confirm_delete_body.html'; + } + $l_confirm_msg .= ((sizeof($post_id_list) == 1) ? '' : 'S'); + $template->assign_vars(array( 'S_NOTIFY_POSTER' => $show_notify, 'S_APPROVE' => false, - 'REASON' => $reason, - 'ADDITIONAL_MSG' => $additional_msg) - ); + 'REASON' => ($is_disapproving) ? $reason : '', + 'ADDITIONAL_MSG' => $additional_msg, + )); - confirm_box(false, 'DISAPPROVE_POST' . ((sizeof($post_id_list) == 1) ? '' : 'S'), $s_hidden_fields, 'mcp_approve.html'); + confirm_box(false, $l_confirm_msg, $s_hidden_fields, $confirm_template); } $redirect = $request->variable('redirect', "index.$phpEx"); -- cgit v1.2.1 From b712cff49662c4356ec69048cd5a834c1415c0cf Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 12 Mar 2013 11:36:40 +0100 Subject: [ticket/9657] Populate data about post's delete status in mcp_post PHPBB3-9657 --- phpBB/includes/mcp/mcp_post.php | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/mcp/mcp_post.php b/phpBB/includes/mcp/mcp_post.php index 90ce18de4e..734fa96a78 100644 --- a/phpBB/includes/mcp/mcp_post.php +++ b/phpBB/includes/mcp/mcp_post.php @@ -174,6 +174,33 @@ function mcp_post_details($id, $mode, $action) } } + // Deleting information + if ($post_info['post_visibility'] == ITEM_DELETED && $post_info['post_delete_user']) + { + // User having deleted the post also being the post author? + if (!$post_info['post_delete_user'] || $post_info['post_delete_user'] == $post_info['poster_id']) + { + $display_username = get_username_string('full', $post_info['poster_id'], $post_info['username'], $post_info['user_colour'], $post_info['post_username']); + } + else + { + $sql = 'SELECT user_id, username, user_colour + FROM ' . USERS_TABLE . ' + WHERE user_id = ' . (int) $post_info['post_delete_user']; + $result = $db->sql_query($sql); + $user_delete_row = $db->sql_fetchrow($result); + $db->sql_freeresult($result); + $display_username = get_username_string('full', $post_info['post_delete_user'], $user_delete_row['username'], $user_delete_row['user_colour']); + } + + $user->add_lang('viewtopic'); + $l_deleted_by = $user->lang('DELETED_INFORMATION', $display_username, $user->format_date($post_info['post_delete_time'], false, true)); + } + else + { + $l_deleted_by = ''; + } + $template->assign_vars(array( 'U_MCP_ACTION' => "$url&i=main&quickmod=1&mode=post_details", // Use this for mode paramaters 'U_POST_ACTION' => "$url&i=$id&mode=post_details", // Use this for action parameters @@ -186,9 +213,12 @@ function mcp_post_details($id, $mode, $action) 'S_POST_REPORTED' => ($post_info['post_reported']) ? true : false, 'S_POST_UNAPPROVED' => ($post_info['post_visibility'] == ITEM_UNAPPROVED) ? true : false, + 'S_POST_DELETED' => ($post_info['post_visibility'] == ITEM_DELETED) ? true : false, 'S_POST_LOCKED' => ($post_info['post_edit_locked']) ? true : false, 'S_USER_NOTES' => true, 'S_CLEAR_ALLOWED' => ($auth->acl_get('a_clearlogs')) ? true : false, + 'DELETED_MESSAGE' => $l_deleted_by, + 'DELETE_REASON' => $post_info['post_delete_reason'], 'U_EDIT' => ($auth->acl_get('m_edit', $post_info['forum_id'])) ? append_sid("{$phpbb_root_path}posting.$phpEx", "mode=edit&f={$post_info['forum_id']}&p={$post_info['post_id']}") : '', 'U_FIND_USERNAME' => append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=searchuser&form=mcp_chgposter&field=username&select_single=true'), @@ -205,6 +235,7 @@ function mcp_post_details($id, $mode, $action) 'RETURN_FORUM' => sprintf($user->lang['RETURN_FORUM'], '', ''), 'REPORTED_IMG' => $user->img('icon_topic_reported', $user->lang['POST_REPORTED']), 'UNAPPROVED_IMG' => $user->img('icon_topic_unapproved', $user->lang['POST_UNAPPROVED']), + 'DELETED_IMG' => $user->img('icon_topic_deleted', $user->lang['POST_DELETED']), 'EDIT_IMG' => $user->img('icon_post_edit', $user->lang['EDIT_POST']), 'SEARCH_IMG' => $user->img('icon_user_search', $user->lang['SEARCH']), -- cgit v1.2.1 From d41cf293e1609be9d0cc08e5ccd37947481e61ca Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 14 Mar 2013 12:10:07 +0100 Subject: [ticket/9657] Check for post visibility when searching with Sphinx This update will require admins to manually update their Sphinx config file aswell as to delete the index and rebuild it from scratch. Before this is done the search will not be usable anymore. PHPBB3-9657 --- phpBB/includes/search/fulltext_sphinx.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/search/fulltext_sphinx.php b/phpBB/includes/search/fulltext_sphinx.php index 441fb2583b..5d5e0ab8f9 100644 --- a/phpBB/includes/search/fulltext_sphinx.php +++ b/phpBB/includes/search/fulltext_sphinx.php @@ -274,6 +274,7 @@ class phpbb_search_fulltext_sphinx p.forum_id, p.topic_id, p.poster_id, + p.post_visibility, CASE WHEN p.post_id = t.topic_first_post_id THEN 1 ELSE 0 END as topic_first_post, p.post_time, p.post_subject, @@ -291,6 +292,7 @@ class phpbb_search_fulltext_sphinx array('sql_attr_uint', 'forum_id'), array('sql_attr_uint', 'topic_id'), array('sql_attr_uint', 'poster_id'), + array('sql_attr_uint', 'post_visibility'), array('sql_attr_bool', 'topic_first_post'), array('sql_attr_bool', 'deleted'), array('sql_attr_timestamp' , 'post_time'), @@ -306,6 +308,7 @@ class phpbb_search_fulltext_sphinx p.forum_id, p.topic_id, p.poster_id, + p.post_visibility, CASE WHEN p.post_id = t.topic_first_post_id THEN 1 ELSE 0 END as topic_first_post, p.post_time, p.post_subject, @@ -569,10 +572,13 @@ class phpbb_search_fulltext_sphinx $this->sphinx->SetFilter('poster_id', $author_ary); } + // As this is not simply possible at the moment, we limit the result to approved posts. + // This will make it impossible for moderators to search unapproved and softdeleted posts, + // but at least it will also cause the same for normal users. + $this->sphinx->SetFilter('post_visibility', array(ITEM_APPROVED)); + if (sizeof($ex_fid_ary)) { - //@todo: Limit using $post_visibility - // All forums that a user is allowed to access $fid_ary = array_unique(array_intersect(array_keys($this->auth->acl_getf('f_read', true)), array_keys($this->auth->acl_getf('f_search', true)))); // All forums that the user wants to and can search in -- cgit v1.2.1 From cdb13fc7be4771bc89da624fe0b5f38b0cc3ccd1 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 11 Jul 2013 11:52:12 +0200 Subject: [ticket/9657] Correctly use " vs ' and variables in queries PHPBB3-9657 --- phpBB/includes/content_visibility.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/content_visibility.php b/phpBB/includes/content_visibility.php index ac827bd822..88f57a0020 100644 --- a/phpBB/includes/content_visibility.php +++ b/phpBB/includes/content_visibility.php @@ -126,11 +126,11 @@ class phpbb_content_visibility else { // The user is just a normal user - return "$table_alias{$mode}_visibility = " . ITEM_APPROVED . ' + return $table_alias . $mode . '_visibility = ' . ITEM_APPROVED . ' AND ' . $db->sql_in_set($table_alias . 'forum_id', $forum_ids, false, true); } - $where_sql .= "($table_alias{$mode}_visibility = " . ITEM_APPROVED . ' + $where_sql .= '(' . $table_alias . $mode . '_visibility = ' . ITEM_APPROVED . ' AND ' . $db->sql_in_set($table_alias . 'forum_id', $forum_ids) . '))'; return $where_sql; @@ -157,12 +157,12 @@ class phpbb_content_visibility if (sizeof($exclude_forum_ids)) { - $where_sqls[] = '(' . $db->sql_in_set($table_alias . 'forum_id', $exclude_forum_ids, true) . " - AND $table_alias{$mode}_visibility = " . ITEM_APPROVED . ')'; + $where_sqls[] = '(' . $db->sql_in_set($table_alias . 'forum_id', $exclude_forum_ids, true) . ' + AND ' . $table_alias . $mode . '_visibility = ' . ITEM_APPROVED . ')'; } else { - $where_sqls[] = "$table_alias{$mode}_visibility = " . ITEM_APPROVED; + $where_sqls[] = $table_alias . $mode . '_visibility = ' . ITEM_APPROVED; } if (sizeof($approve_forums)) -- cgit v1.2.1 From dc2f13d55d181c1a927b6daa8652f68ee87b4a90 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 11 Jul 2013 11:56:05 +0200 Subject: [ticket/9657] Cast topic_id to integer PHPBB3-9657 --- phpBB/includes/content_visibility.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/content_visibility.php b/phpBB/includes/content_visibility.php index 88f57a0020..f4126d0fff 100644 --- a/phpBB/includes/content_visibility.php +++ b/phpBB/includes/content_visibility.php @@ -565,7 +565,7 @@ class phpbb_content_visibility { $sql = 'SELECT topic_type, topic_posts_approved, topic_posts_unapproved, topic_posts_softdeleted, topic_visibility FROM ' . TOPICS_TABLE . ' - WHERE topic_id = ' . $topic_id; + WHERE topic_id = ' . (int) $topic_id; $result = $db->sql_query($sql); $topic_row = $db->sql_fetchrow($result); $db->sql_freeresult($result); @@ -583,7 +583,7 @@ class phpbb_content_visibility // Get user post count information $sql = 'SELECT poster_id, COUNT(post_id) AS num_posts FROM ' . POSTS_TABLE . ' - WHERE topic_id = ' . $topic_id . ' + WHERE topic_id = ' . (int) $topic_id . ' AND post_postcount = 1 AND post_visibility = ' . ITEM_APPROVED . ' GROUP BY poster_id'; -- cgit v1.2.1 From 5b47d731470ddc1b5723ed13b63cc3f90f3e6671 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 11 Jul 2013 12:08:09 +0200 Subject: [ticket/9657] DO not use \" inside of double quotes PHPBB3-9657 --- phpBB/includes/mcp/mcp_queue.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/mcp/mcp_queue.php b/phpBB/includes/mcp/mcp_queue.php index 29c0375e6c..a253a43136 100644 --- a/phpBB/includes/mcp/mcp_queue.php +++ b/phpBB/includes/mcp/mcp_queue.php @@ -305,7 +305,7 @@ class mcp_queue 'MINI_POST_IMG' => ($post_unread) ? $user->img('icon_post_target_unread', 'UNREAD_POST') : $user->img('icon_post_target', 'POST'), - 'RETURN_QUEUE' => sprintf($user->lang['RETURN_QUEUE'], '", ''), + 'RETURN_QUEUE' => sprintf($user->lang['RETURN_QUEUE'], '', ''), 'RETURN_POST' => sprintf($user->lang['RETURN_POST'], '', ''), 'RETURN_TOPIC_SIMPLE' => sprintf($user->lang['RETURN_TOPIC_SIMPLE'], '', ''), 'REPORTED_IMG' => $user->img('icon_topic_reported', $user->lang['POST_REPORTED']), @@ -730,7 +730,7 @@ class mcp_queue $add_message = '

' . sprintf($user->lang['RETURN_POST'], '', ''); } - $message = $user->lang[$success_msg] . '

' . sprintf($user->lang['RETURN_PAGE'], "", '') . $add_message; + $message = $user->lang[$success_msg] . '

' . sprintf($user->lang['RETURN_PAGE'], '', '') . $add_message; if ($request->is_ajax()) { @@ -877,7 +877,7 @@ class mcp_queue $add_message = '

' . sprintf($user->lang['RETURN_TOPIC'], '', ''); } - $message = $user->lang[$success_msg] . '

' . sprintf($user->lang['RETURN_PAGE'], "", '') . $add_message; + $message = $user->lang[$success_msg] . '

' . sprintf($user->lang['RETURN_PAGE'], '', '') . $add_message; if ($request->is_ajax()) { @@ -1209,7 +1209,7 @@ class mcp_queue } else { - $message = $user->lang[$success_msg] . '

' . sprintf($user->lang['RETURN_PAGE'], "", ''); + $message = $user->lang[$success_msg] . '

' . sprintf($user->lang['RETURN_PAGE'], '', ''); if ($request->is_ajax()) { -- cgit v1.2.1 From ed151cd6aaa5ec875d56d33e8908771a1244f98a Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 11 Jul 2013 12:12:18 +0200 Subject: [ticket/9657] Add , to last element of an array PHPBB3-9657 --- phpBB/includes/mcp/mcp_queue.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/mcp/mcp_queue.php b/phpBB/includes/mcp/mcp_queue.php index a253a43136..a42ae6c48c 100644 --- a/phpBB/includes/mcp/mcp_queue.php +++ b/phpBB/includes/mcp/mcp_queue.php @@ -182,8 +182,8 @@ class mcp_queue $template->assign_vars(array( 'S_TOPIC_REVIEW' => true, 'S_BBCODE_ALLOWED' => $post_info['enable_bbcode'], - 'TOPIC_TITLE' => $post_info['topic_title']) - ); + 'TOPIC_TITLE' => $post_info['topic_title'], + )); } $extensions = $attachments = $topic_tracking_info = array(); @@ -246,8 +246,8 @@ class mcp_queue foreach ($attachments as $attachment) { $template->assign_block_vars('attachment', array( - 'DISPLAY_ATTACHMENT' => $attachment) - ); + 'DISPLAY_ATTACHMENT' => $attachment, + )); } } } @@ -922,8 +922,8 @@ class mcp_queue 'mode' => $mode, 'post_id_list' => $post_id_list, 'action' => 'disapprove', - 'redirect' => $redirect) - ); + 'redirect' => $redirect, + )); $notify_poster = $request->is_set('notify_poster'); $disapprove_reason = ''; -- cgit v1.2.1 From 9f89cb4cfbbd46ad45a9c7942fc2233b489bb076 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 11 Jul 2013 13:31:39 +0200 Subject: [ticket/9657] Make content visibility a service and inject everything PHPBB3-9657 --- phpBB/includes/content_visibility.php | 224 ++++++++++++++++++++-------------- 1 file changed, 130 insertions(+), 94 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/content_visibility.php b/phpBB/includes/content_visibility.php index f4126d0fff..edf6aa3b31 100644 --- a/phpBB/includes/content_visibility.php +++ b/phpBB/includes/content_visibility.php @@ -22,6 +22,59 @@ if (!defined('IN_PHPBB')) */ class phpbb_content_visibility { + /** + * Database object + * @var phpbb_db_driver + */ + protected $this->db; + + /** + * User object + * @var phpbb_user + */ + protected $this->user; + + /** + * Auth object + * @var phpbb_auth + */ + protected $this->auth; + + /** + * phpBB root path + * @var string + */ + protected $phpbb_root_path; + + /** + * PHP Extension + * @var string + */ + protected $php_ext; + + /** + * Constructor + * + * @param phpbb_auth $this->auth Auth object + * @param phpbb_db_driver $this->db Database object + * @param phpbb_user $this->user User object + * @param string $phpbb_root_path Root path + * @param string $php_ext PHP Extension + * @return null + */ + public function __construct($this->auth, phpbb_db_driver $this->db, $this->user, $phpbb_root_path, $phpEx, $forums_table, $posts_table, $topics_table, $users_table) + { + $this->auth = $this->auth; + $this->db = $this->db; + $this->user = $this->user; + $this->phpbb_root_path = $phpbb_root_path; + $this->php_ext = $php_ext; + $this->forums_table = $forums_table; + $this->posts_table = $posts_table; + $this->topics_table = $topics_table; + $this->users_table = $users_table; + } + /** * Can the current logged-in user soft-delete posts? * @@ -30,15 +83,13 @@ class phpbb_content_visibility * @param $post_locked bool Is the post locked? * @return bool */ - static function can_soft_delete($forum_id, $poster_id, $post_locked) + public function can_soft_delete($forum_id, $poster_id, $post_locked) { - global $auth, $user; - - if ($auth->acl_get('m_softdelete', $forum_id)) + if ($this->auth->acl_get('m_softdelete', $forum_id)) { return true; } - else if ($auth->acl_get('f_softdelete', $forum_id) && $poster_id == $user->data['user_id'] && !$post_locked) + else if ($this->auth->acl_get('f_softdelete', $forum_id) && $poster_id == $this->user->data['user_id'] && !$post_locked) { return true; } @@ -54,11 +105,9 @@ class phpbb_content_visibility * @param $forum_id int The forum id is used for permission checks * @return int Number of posts/topics the user can see in the topic/forum */ - static public function get_count($mode, $data, $forum_id) + public function get_count($mode, $data, $forum_id) { - global $auth; - - if (!$auth->acl_get('m_approve', $forum_id)) + if (!$this->auth->acl_get('m_approve', $forum_id)) { return (int) $data[$mode . '_approved']; } @@ -76,11 +125,9 @@ class phpbb_content_visibility * @param $table_alias string Table alias to prefix in SQL queries * @return string The appropriate combination SQL logic for topic/post_visibility */ - static public function get_visibility_sql($mode, $forum_id, $table_alias = '') + public function get_visibility_sql($mode, $forum_id, $table_alias = '') { - global $auth; - - if ($auth->acl_get('m_approve', $forum_id)) + if ($this->auth->acl_get('m_approve', $forum_id)) { return '1 = 1'; } @@ -99,13 +146,11 @@ class phpbb_content_visibility * @param $table_alias string Table alias to prefix in SQL queries * @return string The appropriate combination SQL logic for topic/post_visibility */ - static public function get_forums_visibility_sql($mode, $forum_ids = array(), $table_alias = '') + public function get_forums_visibility_sql($mode, $forum_ids = array(), $table_alias = '') { - global $auth, $db; - $where_sql = '('; - $approve_forums = array_intersect($forum_ids, array_keys($auth->acl_getf('m_approve', true))); + $approve_forums = array_intersect($forum_ids, array_keys($this->auth->acl_getf('m_approve', true))); if (sizeof($approve_forums)) { @@ -115,23 +160,23 @@ class phpbb_content_visibility if (!sizeof($forum_ids)) { // The user can see all posts/topics in all specified forums - return $db->sql_in_set($table_alias . 'forum_id', $approve_forums); + return $this->db->sql_in_set($table_alias . 'forum_id', $approve_forums); } else { // Moderator can view all posts/topics in some forums - $where_sql .= $db->sql_in_set($table_alias . 'forum_id', $approve_forums) . ' OR '; + $where_sql .= $this->db->sql_in_set($table_alias . 'forum_id', $approve_forums) . ' OR '; } } else { // The user is just a normal user return $table_alias . $mode . '_visibility = ' . ITEM_APPROVED . ' - AND ' . $db->sql_in_set($table_alias . 'forum_id', $forum_ids, false, true); + AND ' . $this->db->sql_in_set($table_alias . 'forum_id', $forum_ids, false, true); } $where_sql .= '(' . $table_alias . $mode . '_visibility = ' . ITEM_APPROVED . ' - AND ' . $db->sql_in_set($table_alias . 'forum_id', $forum_ids) . '))'; + AND ' . $this->db->sql_in_set($table_alias . 'forum_id', $forum_ids) . '))'; return $where_sql; } @@ -147,17 +192,15 @@ class phpbb_content_visibility * @param $table_alias string Table alias to prefix in SQL queries * @return string The appropriate combination SQL logic for topic/post_visibility */ - static public function get_global_visibility_sql($mode, $exclude_forum_ids = array(), $table_alias = '') + public function get_global_visibility_sql($mode, $exclude_forum_ids = array(), $table_alias = '') { - global $auth, $db; - $where_sqls = array(); - $approve_forums = array_diff(array_keys($auth->acl_getf('m_approve', true)), $exclude_forum_ids); + $approve_forums = array_diff(array_keys($this->auth->acl_getf('m_approve', true)), $exclude_forum_ids); if (sizeof($exclude_forum_ids)) { - $where_sqls[] = '(' . $db->sql_in_set($table_alias . 'forum_id', $exclude_forum_ids, true) . ' + $where_sqls[] = '(' . $this->db->sql_in_set($table_alias . 'forum_id', $exclude_forum_ids, true) . ' AND ' . $table_alias . $mode . '_visibility = ' . ITEM_APPROVED . ')'; } else @@ -167,7 +210,7 @@ class phpbb_content_visibility if (sizeof($approve_forums)) { - $where_sqls[] = $db->sql_in_set($table_alias . 'forum_id', $approve_forums); + $where_sqls[] = $this->db->sql_in_set($table_alias . 'forum_id', $approve_forums); return '(' . implode(' OR ', $where_sqls) . ')'; } @@ -192,10 +235,8 @@ class phpbb_content_visibility * @param $limit_delete_time mixed Limit updating per topic_id to a certain deletion time * @return array Changed post data, empty array if an error occured. */ - static public function set_post_visibility($visibility, $post_id, $topic_id, $forum_id, $user_id, $time, $reason, $is_starter, $is_latest, $limit_visibility = false, $limit_delete_time = false) + public function set_post_visibility($visibility, $post_id, $topic_id, $forum_id, $user_id, $time, $reason, $is_starter, $is_latest, $limit_visibility = false, $limit_delete_time = false) { - global $db; - if (!in_array($visibility, array(ITEM_APPROVED, ITEM_DELETED))) { return array(); @@ -205,7 +246,7 @@ class phpbb_content_visibility { if (is_array($post_id)) { - $where_sql = $db->sql_in_set('post_id', array_map('intval', $post_id)); + $where_sql = $this->db->sql_in_set('post_id', array_map('intval', $post_id)); } else { @@ -233,12 +274,12 @@ class phpbb_content_visibility } $sql = 'SELECT poster_id, post_id, post_postcount, post_visibility - FROM ' . POSTS_TABLE . ' + FROM ' . $this->posts_table . ' WHERE ' . $where_sql; - $result = $db->sql_query($sql); + $result = $this->db->sql_query($sql); $post_ids = $poster_postcounts = $postcounts = $postcount_visibility = array(); - while ($row = $db->sql_fetchrow($result)) + while ($row = $this->db->sql_fetchrow($result)) { $post_ids[] = (int) $row['post_id']; @@ -263,7 +304,7 @@ class phpbb_content_visibility } } } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); if (empty($post_ids)) { @@ -277,10 +318,10 @@ class phpbb_content_visibility 'post_delete_reason' => truncate_string($reason, 255, 255, false), ); - $sql = 'UPDATE ' . POSTS_TABLE . ' - SET ' . $db->sql_build_array('UPDATE', $data) . ' - WHERE ' . $db->sql_in_set('post_id', $post_ids); - $db->sql_query($sql); + $sql = 'UPDATE ' . $this->posts_table . ' + SET ' . $this->db->sql_build_array('UPDATE', $data) . ' + WHERE ' . $this->db->sql_in_set('post_id', $post_ids); + $this->db->sql_query($sql); // Group the authors by post count, to reduce the number of queries foreach ($poster_postcounts as $poster_id => $num_posts) @@ -293,24 +334,24 @@ class phpbb_content_visibility { if ($visibility == ITEM_DELETED) { - $sql = 'UPDATE ' . USERS_TABLE . ' + $sql = 'UPDATE ' . $this->users_table . ' SET user_posts = 0 - WHERE ' . $db->sql_in_set('user_id', $poster_ids) . ' + WHERE ' . $this->db->sql_in_set('user_id', $poster_ids) . ' AND user_posts < ' . $num_posts; - $db->sql_query($sql); + $this->db->sql_query($sql); - $sql = 'UPDATE ' . USERS_TABLE . ' + $sql = 'UPDATE ' . $this->users_table . ' SET user_posts = user_posts - ' . $num_posts . ' - WHERE ' . $db->sql_in_set('user_id', $poster_ids) . ' + WHERE ' . $this->db->sql_in_set('user_id', $poster_ids) . ' AND user_posts >= ' . $num_posts; - $db->sql_query($sql); + $this->db->sql_query($sql); } else { - $sql = 'UPDATE ' . USERS_TABLE . ' + $sql = 'UPDATE ' . $this->users_table . ' SET user_posts = user_posts + ' . $num_posts . ' - WHERE ' . $db->sql_in_set('user_id', $poster_ids); - $db->sql_query($sql); + WHERE ' . $this->db->sql_in_set('user_id', $poster_ids); + $this->db->sql_query($sql); } } @@ -333,8 +374,7 @@ class phpbb_content_visibility { if (!function_exists('sync')) { - global $phpEx, $phpbb_root_path; - include($phpbb_root_path . 'includes/functions_admin.' . $phpEx); + include($this->phpbb_root_path . 'includes/functions_admin.' . $this->php_ext); } // ... so we need to use sync, if the first post is changed. @@ -409,15 +449,15 @@ class phpbb_content_visibility } // Update the number for replies and posts - $sql = 'UPDATE ' . TOPICS_TABLE . ' + $sql = 'UPDATE ' . $this->topics_table . ' SET ' . implode(', ', $topic_sql) . ' WHERE topic_id = ' . (int) $topic_id; - $db->sql_query($sql); + $this->db->sql_query($sql); - $sql = 'UPDATE ' . FORUMS_TABLE . ' + $sql = 'UPDATE ' . $this->forums_table . ' SET ' . implode(', ', $forum_sql) . ' WHERE forum_id = ' . (int) $forum_id; - $db->sql_query($sql); + $this->db->sql_query($sql); } } @@ -445,10 +485,8 @@ class phpbb_content_visibility * @param $force_update_all bool Force to update all posts within the topic * @return array Changed topic data, empty array if an error occured. */ - static public function set_topic_visibility($visibility, $topic_id, $forum_id, $user_id, $time, $reason, $force_update_all = false) + public function set_topic_visibility($visibility, $topic_id, $forum_id, $user_id, $time, $reason, $force_update_all = false) { - global $db; - if (!in_array($visibility, array(ITEM_APPROVED, ITEM_DELETED))) { return array(); @@ -457,11 +495,11 @@ class phpbb_content_visibility if (!$force_update_all) { $sql = 'SELECT topic_visibility, topic_delete_time - FROM ' . TOPICS_TABLE . ' + FROM ' . $this->topics_table . ' WHERE topic_id = ' . (int) $topic_id; - $result = $db->sql_query($sql); - $original_topic_data = $db->sql_fetchrow($result); - $db->sql_freeresult($result); + $result = $this->db->sql_query($sql); + $original_topic_data = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); if (!$original_topic_data) { @@ -478,12 +516,12 @@ class phpbb_content_visibility 'topic_delete_reason' => truncate_string($reason, 255, 255, false), ); - $sql = 'UPDATE ' . TOPICS_TABLE . ' - SET ' . $db->sql_build_array('UPDATE', $data) . ' + $sql = 'UPDATE ' . $this->topics_table . ' + SET ' . $this->db->sql_build_array('UPDATE', $data) . ' WHERE topic_id = ' . (int) $topic_id; - $db->sql_query($sql); + $this->db->sql_query($sql); - if (!$db->sql_affectedrows()) + if (!$this->db->sql_affectedrows()) { return array(); } @@ -513,15 +551,15 @@ class phpbb_content_visibility * @param $sql_data array Populated with the SQL changes, may be empty at call time * @return void */ - static public function add_post_to_statistic($data, &$sql_data) + public function add_post_to_statistic($data, &$sql_data) { - $sql_data[TOPICS_TABLE] = (($sql_data[TOPICS_TABLE]) ? $sql_data[TOPICS_TABLE] . ', ' : '') . 'topic_posts_approved = topic_posts_approved + 1'; + $sql_data[$this->topics_table] = (($sql_data[$this->topics_table]) ? $sql_data[$this->topics_table] . ', ' : '') . 'topic_posts_approved = topic_posts_approved + 1'; - $sql_data[FORUMS_TABLE] = (($sql_data[FORUMS_TABLE]) ? $sql_data[FORUMS_TABLE] . ', ' : '') . 'forum_posts_approved = forum_posts_approved + 1'; + $sql_data[$this->forums_table] = (($sql_data[$this->forums_table]) ? $sql_data[$this->forums_table] . ', ' : '') . 'forum_posts_approved = forum_posts_approved + 1'; if ($data['post_postcount']) { - $sql_data[USERS_TABLE] = (($sql_data[USERS_TABLE]) ? $sql_data[USERS_TABLE] . ', ' : '') . 'user_posts = user_posts + 1'; + $sql_data[$this->users_table] = (($sql_data[$this->users_table]) ? $sql_data[$this->users_table] . ', ' : '') . 'user_posts = user_posts + 1'; } set_config_count('num_posts', 1, true); @@ -534,14 +572,14 @@ class phpbb_content_visibility * @param $sql_data array Populated with the SQL changes, may be empty at call time * @return void */ - static public function remove_post_from_statistic($data, &$sql_data) + public function remove_post_from_statistic($data, &$sql_data) { - $sql_data[TOPICS_TABLE] = ((!empty($sql_data[TOPICS_TABLE])) ? $sql_data[TOPICS_TABLE] . ', ' : '') . 'topic_posts_approved = topic_posts_approved - 1'; - $sql_data[FORUMS_TABLE] = ((!empty($sql_data[FORUMS_TABLE])) ? $sql_data[FORUMS_TABLE] . ', ' : '') . 'forum_posts_approved = forum_posts_approved - 1'; + $sql_data[$this->topics_table] = ((!empty($sql_data[$this->topics_table])) ? $sql_data[$this->topics_table] . ', ' : '') . 'topic_posts_approved = topic_posts_approved - 1'; + $sql_data[$this->forums_table] = ((!empty($sql_data[$this->forums_table])) ? $sql_data[$this->forums_table] . ', ' : '') . 'forum_posts_approved = forum_posts_approved - 1'; if ($data['post_postcount']) { - $sql_data[USERS_TABLE] = ((!empty($sql_data[USERS_TABLE])) ? $sql_data[USERS_TABLE] . ', ' : '') . 'user_posts = user_posts - 1'; + $sql_data[$this->users_table] = ((!empty($sql_data[$this->users_table])) ? $sql_data[$this->users_table] . ', ' : '') . 'user_posts = user_posts - 1'; } set_config_count('num_posts', -1, true); @@ -556,60 +594,58 @@ class phpbb_content_visibility * @param $sql_data array Populated with the SQL changes, may be empty at call time * @return void */ - static public function remove_topic_from_statistic($topic_id, $forum_id, &$topic_row, &$sql_data) + public function remove_topic_from_statistic($topic_id, $forum_id, &$topic_row, &$sql_data) { - global $db; - // Do we need to grab some topic informations? if (!sizeof($topic_row)) { $sql = 'SELECT topic_type, topic_posts_approved, topic_posts_unapproved, topic_posts_softdeleted, topic_visibility - FROM ' . TOPICS_TABLE . ' + FROM ' . $this->topics_table . ' WHERE topic_id = ' . (int) $topic_id; - $result = $db->sql_query($sql); - $topic_row = $db->sql_fetchrow($result); - $db->sql_freeresult($result); + $result = $this->db->sql_query($sql); + $topic_row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); } // If this is an edited topic or the first post the topic gets completely disapproved later on... - $sql_data[FORUMS_TABLE] = (($sql_data[FORUMS_TABLE]) ? $sql_data[FORUMS_TABLE] . ', ' : '') . 'forum_topics_approved = forum_topics_approved - 1'; - $sql_data[FORUMS_TABLE] .= ', forum_posts_approved = forum_posts_approved - ' . $topic_row['topic_posts_approved']; - $sql_data[FORUMS_TABLE] .= ', forum_posts_unapproved = forum_posts_unapproved - ' . $topic_row['topic_posts_unapproved']; - $sql_data[FORUMS_TABLE] .= ', forum_posts_softdeleted = forum_posts_softdeleted - ' . $topic_row['topic_posts_softdeleted']; + $sql_data[$this->forums_table] = (($sql_data[$this->forums_table]) ? $sql_data[$this->forums_table] . ', ' : '') . 'forum_topics_approved = forum_topics_approved - 1'; + $sql_data[$this->forums_table] .= ', forum_posts_approved = forum_posts_approved - ' . $topic_row['topic_posts_approved']; + $sql_data[$this->forums_table] .= ', forum_posts_unapproved = forum_posts_unapproved - ' . $topic_row['topic_posts_unapproved']; + $sql_data[$this->forums_table] .= ', forum_posts_softdeleted = forum_posts_softdeleted - ' . $topic_row['topic_posts_softdeleted']; set_config_count('num_topics', -1, true); set_config_count('num_posts', $topic_row['topic_posts_approved'] * (-1), true); // Get user post count information $sql = 'SELECT poster_id, COUNT(post_id) AS num_posts - FROM ' . POSTS_TABLE . ' + FROM ' . $this->posts_table . ' WHERE topic_id = ' . (int) $topic_id . ' AND post_postcount = 1 AND post_visibility = ' . ITEM_APPROVED . ' GROUP BY poster_id'; - $result = $db->sql_query($sql); + $result = $this->db->sql_query($sql); $postcounts = array(); - while ($row = $db->sql_fetchrow($result)) + while ($row = $this->db->sql_fetchrow($result)) { $postcounts[(int) $row['num_posts']][] = (int) $row['poster_id']; } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); // Decrement users post count foreach ($postcounts as $num_posts => $poster_ids) { - $sql = 'UPDATE ' . USERS_TABLE . ' + $sql = 'UPDATE ' . $this->users_table . ' SET user_posts = 0 WHERE user_posts < ' . $num_posts . ' - AND ' . $db->sql_in_set('user_id', $poster_ids); - $db->sql_query($sql); + AND ' . $this->db->sql_in_set('user_id', $poster_ids); + $this->db->sql_query($sql); - $sql = 'UPDATE ' . USERS_TABLE . ' + $sql = 'UPDATE ' . $this->users_table . ' SET user_posts = user_posts - ' . $num_posts . ' WHERE user_posts >= ' . $num_posts . ' - AND ' . $db->sql_in_set('user_id', $poster_ids); - $db->sql_query($sql); + AND ' . $this->db->sql_in_set('user_id', $poster_ids); + $this->db->sql_query($sql); } } } -- 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/includes/feed/base.php | 4 +++- phpBB/includes/feed/forum.php | 4 ++-- phpBB/includes/feed/overall.php | 4 ++-- phpBB/includes/feed/topic.php | 2 +- phpBB/includes/feed/topic_base.php | 2 +- phpBB/includes/functions.php | 5 +++-- phpBB/includes/functions_display.php | 16 ++++++++++------ phpBB/includes/functions_posting.php | 23 ++++++++++++++--------- phpBB/includes/mcp/mcp_forum.php | 10 ++++++---- phpBB/includes/mcp/mcp_main.php | 15 +++++++++------ phpBB/includes/mcp/mcp_queue.php | 8 +++++--- phpBB/includes/mcp/mcp_topic.php | 7 ++++--- phpBB/includes/ucp/ucp_main.php | 6 ++++-- 13 files changed, 64 insertions(+), 42 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/feed/base.php b/phpBB/includes/feed/base.php index af28ee8dc8..84fdbe415a 100644 --- a/phpBB/includes/feed/base.php +++ b/phpBB/includes/feed/base.php @@ -80,10 +80,11 @@ abstract class phpbb_feed_base * @param phpbb_cache_driver_interface $cache Cache object * @param phpbb_user $user User object * @param phpbb_auth $auth Auth object + * @param phpbb_content_visibility $content_visibility Auth object * @param string $phpEx php file extension * @return null */ - function __construct(phpbb_feed_helper $helper, phpbb_config $config, phpbb_db_driver $db, phpbb_cache_driver_interface $cache, phpbb_user $user, phpbb_auth $auth, $phpEx) + function __construct(phpbb_feed_helper $helper, phpbb_config $config, phpbb_db_driver $db, phpbb_cache_driver_interface $cache, phpbb_user $user, phpbb_auth $auth, $content_visibility, $phpEx) { $this->config = $config; $this->helper = $helper; @@ -91,6 +92,7 @@ abstract class phpbb_feed_base $this->cache = $cache; $this->user = $user; $this->auth = $auth; + $this->content_visibility = $content_visibility; $this->phpEx = $phpEx; $this->set_keys(); diff --git a/phpBB/includes/feed/forum.php b/phpBB/includes/feed/forum.php index 83b836b81d..fc217c203c 100644 --- a/phpBB/includes/feed/forum.php +++ b/phpBB/includes/feed/forum.php @@ -90,7 +90,7 @@ class phpbb_feed_forum extends phpbb_feed_post_base function get_sql() { - $sql_visibility = phpbb_content_visibility::get_visibility_sql('topic', $this->forum_id); + $sql_visibility = $this->content_visibility->get_visibility_sql('topic', $this->forum_id); // Determine topics with recent activity $sql = 'SELECT topic_id, topic_last_post_time @@ -116,7 +116,7 @@ class phpbb_feed_forum extends phpbb_feed_post_base return false; } - $sql_visibility = phpbb_content_visibility::get_visibility_sql('post', $this->forum_id, 'p.'); + $sql_visibility = $this->content_visibility->get_visibility_sql('post', $this->forum_id, 'p.'); $this->sql = array( 'SELECT' => 'p.post_id, p.topic_id, p.post_time, p.post_edit_time, p.post_visibility, p.post_subject, p.post_text, p.bbcode_bitfield, p.bbcode_uid, p.enable_bbcode, p.enable_smilies, p.enable_magic_url, ' . diff --git a/phpBB/includes/feed/overall.php b/phpBB/includes/feed/overall.php index 7e48120b97..af45840d69 100644 --- a/phpBB/includes/feed/overall.php +++ b/phpBB/includes/feed/overall.php @@ -37,7 +37,7 @@ class phpbb_feed_overall extends phpbb_feed_post_base $sql = 'SELECT topic_id, topic_last_post_time FROM ' . TOPICS_TABLE . ' WHERE topic_moved_id = 0 - AND ' . phpbb_content_visibility::get_forums_visibility_sql('topic', $forum_ids) . ' + AND ' . $this->content_visibility->get_forums_visibility_sql('topic', $forum_ids) . ' ORDER BY topic_last_post_time DESC'; $result = $this->db->sql_query_limit($sql, $this->num_items); @@ -56,7 +56,7 @@ class phpbb_feed_overall extends phpbb_feed_post_base return false; } - $sql_visibility = phpbb_content_visibility::get_visibility_sql('post', array(), 'p.'); + $sql_visibility = $this->content_visibility->get_visibility_sql('post', array(), 'p.'); // Get the actual data $this->sql = array( diff --git a/phpBB/includes/feed/topic.php b/phpBB/includes/feed/topic.php index 42bd291343..10f86486c6 100644 --- a/phpBB/includes/feed/topic.php +++ b/phpBB/includes/feed/topic.php @@ -93,7 +93,7 @@ class phpbb_feed_topic extends phpbb_feed_post_base function get_sql() { - $sql_visibility = phpbb_content_visibility::get_visibility_sql('post', $this->forum_id, 'p.'); + $sql_visibility = $this->content_visibility->get_visibility_sql('post', $this->forum_id, 'p.'); $this->sql = array( 'SELECT' => 'p.post_id, p.post_time, p.post_edit_time, p.post_visibility, p.post_subject, p.post_text, p.bbcode_bitfield, p.bbcode_uid, p.enable_bbcode, p.enable_smilies, p.enable_magic_url, ' . diff --git a/phpBB/includes/feed/topic_base.php b/phpBB/includes/feed/topic_base.php index a2f5a56f1d..b104a46631 100644 --- a/phpBB/includes/feed/topic_base.php +++ b/phpBB/includes/feed/topic_base.php @@ -51,7 +51,7 @@ abstract class phpbb_feed_topic_base extends phpbb_feed_base { $item_row['statistics'] = $this->user->lang['POSTED'] . ' ' . $this->user->lang['POST_BY_AUTHOR'] . ' ' . $this->user_viewprofile($row) . ' ' . $this->separator_stats . ' ' . $this->user->format_date($row[$this->get('published')]) - . ' ' . $this->separator_stats . ' ' . $this->user->lang['REPLIES'] . ' ' . phpbb_content_visibility::get_count('topic_posts', $row, $row['forum_id']) - 1 + . ' ' . $this->separator_stats . ' ' . $this->user->lang['REPLIES'] . ' ' . $this->content_visibility->get_count('topic_posts', $row, $row['forum_id']) - 1 . ' ' . $this->separator_stats . ' ' . $this->user->lang['VIEWS'] . ' ' . $row['topic_views'] . (($this->is_moderator_approve_forum($row['forum_id']) && $row['topic_posts_unapproved']) ? ' ' . $this->separator_stats . ' ' . $this->user->lang['POSTS_UNAPPROVED'] : ''); } diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index e884a2f94c..9664b5663c 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -1974,7 +1974,7 @@ function get_unread_topics($user_id = false, $sql_extra = '', $sql_sort = '', $s */ function update_forum_tracking_info($forum_id, $forum_last_post_time, $f_mark_time = false, $mark_time_forum = false) { - global $db, $tracking_topics, $user, $config, $auth, $request; + global $db, $tracking_topics, $user, $config, $auth, $request, $phpbb_container; // Determine the users last forum mark time if not given. if ($mark_time_forum === false) @@ -1999,7 +1999,8 @@ function update_forum_tracking_info($forum_id, $forum_last_post_time, $f_mark_ti // Handle update of unapproved topics info. // Only update for moderators having m_approve permission for the forum. - $sql_update_unapproved = phpbb_content_visibility::get_visibility_sql('topic', $forum_id, 't.'); + $phpbb_content_visibility = $phpbb_container->get('content.visibility'); + $sql_update_unapproved = $phpbb_content_visibility->get_visibility_sql('topic', $forum_id, 't.'); $sql_update_unapproved = ($sql_update_unapproved) ? ' AND ' . $sql_update_unapproved : ''; // Check the forum for any left unread topics. diff --git a/phpBB/includes/functions_display.php b/phpBB/includes/functions_display.php index 797ca718d8..143813e4ed 100644 --- a/phpBB/includes/functions_display.php +++ b/phpBB/includes/functions_display.php @@ -22,7 +22,7 @@ function display_forums($root_data = '', $display_moderators = true, $return_mod { global $db, $auth, $user, $template; global $phpbb_root_path, $phpEx, $config; - global $request, $phpbb_dispatcher; + global $request, $phpbb_dispatcher, $phpbb_container; $forum_rows = $subforums = $forum_ids = $forum_ids_moderator = $forum_moderators = $active_forum_ary = array(); $parent_id = $visible_forums = 0; @@ -149,6 +149,8 @@ function display_forums($root_data = '', $display_moderators = true, $return_mod $forum_tracking_info = array(); $branch_root_id = $root_data['forum_id']; + $phpbb_content_visibility = $phpbb_container->get('content.visibility'); + while ($row = $db->sql_fetchrow($result)) { /** @@ -215,8 +217,8 @@ function display_forums($root_data = '', $display_moderators = true, $return_mod // Count the difference of real to public topics, so we can display an information to moderators $row['forum_id_unapproved_topics'] = ($auth->acl_get('m_approve', $forum_id) && $row['forum_topics_unapproved']) ? $forum_id : 0; - $row['forum_posts'] = phpbb_content_visibility::get_count('forum_posts', $row, $forum_id); - $row['forum_topics'] = phpbb_content_visibility::get_count('forum_topics', $row, $forum_id); + $row['forum_posts'] = $phpbb_content_visibility->get_count('forum_posts', $row, $forum_id); + $row['forum_topics'] = $phpbb_content_visibility->get_count('forum_topics', $row, $forum_id); // Display active topics from this forum? if ($show_active && $row['forum_type'] == FORUM_POST && $auth->acl_get('f_read', $forum_id) && ($row['forum_flags'] & FORUM_FLAG_ACTIVE_TOPICS)) @@ -1006,7 +1008,7 @@ function display_reasons($reason_id = 0) function display_user_activity(&$userdata) { global $auth, $template, $db, $user; - global $phpbb_root_path, $phpEx; + global $phpbb_root_path, $phpEx, $phpbb_container; // Do not display user activity for users having more than 5000 posts... if ($userdata['user_posts'] > 5000) @@ -1030,12 +1032,14 @@ function display_user_activity(&$userdata) $active_f_row = $active_t_row = array(); if (!empty($forum_ary)) { + $phpbb_content_visibility = $phpbb_container->get('content.visibility'); + // Obtain active forum $sql = 'SELECT forum_id, COUNT(post_id) AS num_posts FROM ' . POSTS_TABLE . ' WHERE poster_id = ' . $userdata['user_id'] . ' AND post_postcount = 1 - AND ' . phpbb_content_visibility::get_forums_visibility_sql('post', $forum_ary) . ' + AND ' . $phpbb_content_visibility->get_forums_visibility_sql('post', $forum_ary) . ' GROUP BY forum_id ORDER BY num_posts DESC'; $result = $db->sql_query_limit($sql, 1); @@ -1057,7 +1061,7 @@ function display_user_activity(&$userdata) FROM ' . POSTS_TABLE . ' WHERE poster_id = ' . $userdata['user_id'] . ' AND post_postcount = 1 - AND ' . phpbb_content_visibility::get_forums_visibility_sql('post', $forum_ary) . ' + AND ' . $phpbb_content_visibility->get_forums_visibility_sql('post', $forum_ary) . ' GROUP BY topic_id ORDER BY num_posts DESC'; $result = $db->sql_query_limit($sql, 1); diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index de88f7cc98..03565c27bb 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -982,13 +982,15 @@ function load_drafts($topic_id = 0, $forum_id = 0, $id = 0, $pm_action = '', $ms function topic_review($topic_id, $forum_id, $mode = 'topic_review', $cur_post_id = 0, $show_quote_button = true) { global $user, $auth, $db, $template, $bbcode, $cache; - global $config, $phpbb_root_path, $phpEx; + global $config, $phpbb_root_path, $phpEx, $phpbb_container; + + $phpbb_content_visibility = $phpbb_container->get('content.visibility'); // Go ahead and pull all data for this topic $sql = 'SELECT p.post_id FROM ' . POSTS_TABLE . ' p' . " WHERE p.topic_id = $topic_id - AND " . phpbb_content_visibility::get_visibility_sql('post', $forum_id, 'p.') . ' + AND " . $phpbb_content_visibility->get_visibility_sql('post', $forum_id, 'p.') . ' ' . (($mode == 'post_review') ? " AND p.post_id > $cur_post_id" : '') . ' ' . (($mode == 'post_review_edit') ? " AND p.post_id = $cur_post_id" : '') . ' ORDER BY p.post_time '; @@ -1177,7 +1179,7 @@ function topic_review($topic_id, $forum_id, $mode = 'topic_review', $cur_post_id */ function delete_post($forum_id, $topic_id, $post_id, &$data, $is_soft = false, $softdelete_reason = '') { - global $db, $user, $auth; + global $db, $user, $auth, $phpbb_container; global $config, $phpEx, $phpbb_root_path; // Specify our post mode @@ -1224,10 +1226,12 @@ function delete_post($forum_id, $topic_id, $post_id, &$data, $is_soft = false, $ $db->sql_freeresult($result); } + $phpbb_content_visibility = $phpbb_container->get('content.visibility'); + // (Soft) delete the post if ($is_soft && ($post_mode != 'delete_topic')) { - phpbb_content_visibility::set_post_visibility(ITEM_DELETED, $post_id, $topic_id, $forum_id, $user->data['user_id'], time(), $softdelete_reason, ($data['topic_first_post_id'] == $post_id), ($data['topic_last_post_id'] == $post_id)); + $phpbb_content_visibility->set_post_visibility(ITEM_DELETED, $post_id, $topic_id, $forum_id, $user->data['user_id'], time(), $softdelete_reason, ($data['topic_first_post_id'] == $post_id), ($data['topic_last_post_id'] == $post_id)); } else if (!$is_soft) { @@ -1264,7 +1268,7 @@ function delete_post($forum_id, $topic_id, $post_id, &$data, $is_soft = false, $ if ($is_soft) { $topic_row = array(); - phpbb_content_visibility::set_topic_visibility(ITEM_DELETED, $topic_id, $forum_id, $user->data['user_id'], time(), $softdelete_reason); + $phpbb_content_visibility->set_topic_visibility(ITEM_DELETED, $topic_id, $forum_id, $user->data['user_id'], time(), $softdelete_reason); } else { @@ -1353,7 +1357,7 @@ function delete_post($forum_id, $topic_id, $post_id, &$data, $is_soft = false, $ $sql = 'SELECT MAX(post_id) as last_post_id FROM ' . POSTS_TABLE . " WHERE topic_id = $topic_id - AND " . phpbb_content_visibility::get_visibility_sql('post', $forum_id); + AND " . $phpbb_content_visibility->get_visibility_sql('post', $forum_id); $result = $db->sql_query($sql); $next_post_id = (int) $db->sql_fetchfield('last_post_id'); $db->sql_freeresult($result); @@ -1364,7 +1368,7 @@ function delete_post($forum_id, $topic_id, $post_id, &$data, $is_soft = false, $ $sql = 'SELECT post_id FROM ' . POSTS_TABLE . " WHERE topic_id = $topic_id - AND " . phpbb_content_visibility::get_visibility_sql('post', $forum_id) . ' + AND " . $phpbb_content_visibility->get_visibility_sql('post', $forum_id) . ' AND post_time > ' . $data['post_time'] . ' ORDER BY post_time ASC'; $result = $db->sql_query_limit($sql, 1); @@ -1379,7 +1383,7 @@ function delete_post($forum_id, $topic_id, $post_id, &$data, $is_soft = false, $ { if ($data['post_visibility'] == ITEM_APPROVED) { - phpbb_content_visibility::remove_post_from_statistic($data, $sql_data); + $phpbb_content_visibility->remove_post_from_statistic($data, $sql_data); } else if ($data['post_visibility'] == ITEM_UNAPPROVED) { @@ -2000,7 +2004,8 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u $is_starter = ($post_mode == 'edit_first_post' || $data['post_visibility'] != ITEM_APPROVED); $is_latest = ($post_mode == 'edit_last_post' || $post_mode == 'edit_topic' || $data['post_visibility'] != ITEM_APPROVED); - phpbb_content_visibility::set_post_visibility($post_visibility, $data['post_id'], $data['topic_id'], $data['forum_id'], $user->data['user_id'], time(), '', $is_starter, $is_latest); + $phpbb_content_visibility = $phpbb_container->get('content.visibility'); + $phpbb_content_visibility->set_post_visibility($post_visibility, $data['post_id'], $data['topic_id'], $data['forum_id'], $user->data['user_id'], time(), '', $is_starter, $is_latest); } else if ($post_mode == 'edit_last_post' || $post_mode == 'edit_topic' || ($post_mode == 'edit_first_post' && !$data['topic_replies'])) { diff --git a/phpBB/includes/mcp/mcp_forum.php b/phpBB/includes/mcp/mcp_forum.php index a7302ce912..841a0afddb 100644 --- a/phpBB/includes/mcp/mcp_forum.php +++ b/phpBB/includes/mcp/mcp_forum.php @@ -22,7 +22,7 @@ function mcp_forum_view($id, $mode, $action, $forum_info) { global $template, $db, $user, $auth, $cache, $module; global $phpEx, $phpbb_root_path, $config; - global $request, $phpbb_dispatcher; + global $request, $phpbb_dispatcher, $phpbb_container; $user->add_lang(array('viewtopic', 'viewforum')); @@ -152,10 +152,12 @@ function mcp_forum_view($id, $mode, $action, $forum_info) $read_tracking_join = $read_tracking_select = ''; } + $phpbb_content_visibility = $phpbb_container->get('content.visibility'); + $sql = 'SELECT t.topic_id FROM ' . TOPICS_TABLE . ' t WHERE t.forum_id = ' . $forum_id . ' - AND ' . phpbb_content_visibility::get_visibility_sql('topic', $forum_id, 't.') . " + AND ' . $phpbb_content_visibility->get_visibility_sql('topic', $forum_id, 't.') . " $limit_time_sql ORDER BY t.topic_type DESC, $sort_order_sql"; $result = $db->sql_query_limit($sql, $topics_per_page, $start); @@ -204,7 +206,7 @@ function mcp_forum_view($id, $mode, $action, $forum_info) $row = &$topic_rows[$topic_id]; - $replies = phpbb_content_visibility::get_count('topic_posts', $row, $forum_id) - 1; + $replies = $phpbb_content_visibility->get_count('topic_posts', $row, $forum_id) - 1; if ($row['topic_status'] == ITEM_MOVED) { @@ -249,7 +251,7 @@ function mcp_forum_view($id, $mode, $action, $forum_info) 'TOPIC_TYPE' => $topic_type, 'TOPIC_TITLE' => $topic_title, - 'REPLIES' => phpbb_content_visibility::get_count('topic_posts', $row, $row['forum_id']) - 1, + 'REPLIES' => $phpbb_content_visibility->get_count('topic_posts', $row, $row['forum_id']) - 1, 'LAST_POST_TIME' => $user->format_date($row['topic_last_post_time']), 'FIRST_POST_TIME' => $user->format_date($row['topic_time']), 'LAST_POST_SUBJECT' => $row['topic_last_post_subject'], diff --git a/phpBB/includes/mcp/mcp_main.php b/phpBB/includes/mcp/mcp_main.php index c044e5c871..62c3eda447 100644 --- a/phpBB/includes/mcp/mcp_main.php +++ b/phpBB/includes/mcp/mcp_main.php @@ -654,7 +654,7 @@ function mcp_move_topic($topic_ids) */ function mcp_restore_topic($topic_ids) { - global $auth, $user, $db, $phpEx, $phpbb_root_path, $request; + global $auth, $user, $db, $phpEx, $phpbb_root_path, $request, $phpbb_container; if (!check_ids($topic_ids, TOPICS_TABLE, 'topic_id', array('m_approve'))) { @@ -678,9 +678,10 @@ function mcp_restore_topic($topic_ids) $data = get_topic_data($topic_ids); + $phpbb_content_visibility = $phpbb_container->get('content.visibility'); foreach ($data as $topic_id => $row) { - $return = phpbb_content_visibility::set_topic_visibility(ITEM_APPROVED, $topic_id, $row['forum_id'], $user->data['user_id'], time(), ''); + $return = $phpbb_content_visibility->set_topic_visibility(ITEM_APPROVED, $topic_id, $row['forum_id'], $user->data['user_id'], time(), ''); if (!empty($return)) { add_log('mod', $row['forum_id'], $topic_id, 'LOG_RESTORE_TOPIC', $row['topic_title'], $row['topic_first_poster_name']); @@ -726,7 +727,7 @@ function mcp_restore_topic($topic_ids) */ function mcp_delete_topic($topic_ids, $is_soft = false, $soft_delete_reason = '', $action = 'delete_topic') { - global $auth, $user, $db, $phpEx, $phpbb_root_path, $request; + global $auth, $user, $db, $phpEx, $phpbb_root_path, $request, $phpbb_container; if (!check_ids($topic_ids, TOPICS_TABLE, 'topic_id', array('m_delete'))) { @@ -761,7 +762,8 @@ function mcp_delete_topic($topic_ids, $is_soft = false, $soft_delete_reason = '' // Only soft delete non-shadow topics if ($is_soft) { - $return = phpbb_content_visibility::set_topic_visibility(ITEM_DELETED, $topic_id, $row['forum_id'], $user->data['user_id'], time(), $soft_delete_reason); + $phpbb_content_visibility = $phpbb_container->get('content.visibility'); + $return = $phpbb_content_visibility->set_topic_visibility(ITEM_DELETED, $topic_id, $row['forum_id'], $user->data['user_id'], time(), $soft_delete_reason); if (!empty($return)) { add_log('mod', $row['forum_id'], $topic_id, 'LOG_SOFTDELETE_TOPIC', $row['topic_title'], $row['topic_first_poster_name']); @@ -854,7 +856,7 @@ function mcp_delete_topic($topic_ids, $is_soft = false, $soft_delete_reason = '' */ function mcp_delete_post($post_ids, $is_soft = false, $soft_delete_reason = '', $action = 'delete_post') { - global $auth, $user, $db, $phpEx, $phpbb_root_path, $request; + global $auth, $user, $db, $phpEx, $phpbb_root_path, $request, $phpbb_container; if (!check_ids($post_ids, POSTS_TABLE, 'post_id', array('m_softdelete'))) { @@ -910,9 +912,10 @@ function mcp_delete_post($post_ids, $is_soft = false, $soft_delete_reason = '', ); } + $phpbb_content_visibility = $phpbb_container->get('content.visibility'); 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'])); + $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. diff --git a/phpBB/includes/mcp/mcp_queue.php b/phpBB/includes/mcp/mcp_queue.php index a42ae6c48c..514d7bc4ee 100644 --- a/phpBB/includes/mcp/mcp_queue.php +++ b/phpBB/includes/mcp/mcp_queue.php @@ -634,9 +634,10 @@ class mcp_queue ); } + $phpbb_content_visibility = $phpbb_container->get('content.visibility'); foreach ($topic_info as $topic_id => $topic_data) { - phpbb_content_visibility::set_post_visibility(ITEM_APPROVED, $topic_data['posts'], $topic_id, $topic_data['forum_id'], $user->data['user_id'], time(), '', isset($topic_data['first_post']), isset($topic_data['last_post'])); + $phpbb_content_visibility->set_post_visibility(ITEM_APPROVED, $topic_data['posts'], $topic_id, $topic_data['forum_id'], $user->data['user_id'], time(), '', isset($topic_data['first_post']), isset($topic_data['last_post'])); } if (sizeof($post_info) >= 1) @@ -759,7 +760,7 @@ class mcp_queue static public function approve_topics($action, $topic_id_list, $id, $mode) { global $db, $template, $user, $config; - global $phpEx, $phpbb_root_path, $request; + global $phpEx, $phpbb_root_path, $request, $phpbb_container; if (!check_ids($topic_id_list, TOPICS_TABLE, 'topic_id', array('m_approve'))) { @@ -784,9 +785,10 @@ class mcp_queue { $notify_poster = ($action == 'approve' && isset($_REQUEST['notify_poster'])) ? true : false; + $phpbb_content_visibility = $phpbb_container->get('content.visibility'); foreach ($topic_info as $topic_id => $topic_data) { - phpbb_content_visibility::set_topic_visibility(ITEM_APPROVED, $topic_id, $topic_data['forum_id'], $user->data['user_id'], time(), ''); + $phpbb_content_visibility->set_topic_visibility(ITEM_APPROVED, $topic_id, $topic_data['forum_id'], $user->data['user_id'], time(), ''); $topic_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f={$topic_data['forum_id']}&t={$topic_id}"); diff --git a/phpBB/includes/mcp/mcp_topic.php b/phpBB/includes/mcp/mcp_topic.php index 1d2030edb1..d0e4a2e057 100644 --- a/phpBB/includes/mcp/mcp_topic.php +++ b/phpBB/includes/mcp/mcp_topic.php @@ -21,7 +21,7 @@ if (!defined('IN_PHPBB')) function mcp_topic_view($id, $mode, $action) { global $phpEx, $phpbb_root_path, $config; - global $template, $db, $user, $auth, $cache; + global $template, $db, $user, $auth, $cache, $phpbb_container; $url = append_sid("{$phpbb_root_path}mcp.$phpEx?" . extra_url()); @@ -112,10 +112,11 @@ function mcp_topic_view($id, $mode, $action) mcp_sorting('viewtopic', $sort_days, $sort_key, $sort_dir, $sort_by_sql, $sort_order_sql, $total, $topic_info['forum_id'], $topic_id, $where_sql); $limit_time_sql = ($sort_days) ? 'AND p.post_time >= ' . (time() - ($sort_days * 86400)) : ''; + $phpbb_content_visibility = $phpbb_container->get('content.visibility'); if ($total == -1) { - $total = phpbb_content_visibility::get_count('topic_posts', $topic_info, $topic_info['forum_id']); + $total = $phpbb_content_visibility->get_count('topic_posts', $topic_info, $topic_info['forum_id']); } $posts_per_page = max(0, request_var('posts_per_page', intval($config['posts_per_page']))); @@ -139,7 +140,7 @@ function mcp_topic_view($id, $mode, $action) FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . ' u WHERE ' . (($action == 'reports') ? 'p.post_reported = 1 AND ' : '') . ' p.topic_id = ' . $topic_id . ' - AND ' . phpbb_content_visibility::get_visibility_sql('post', $topic_info['forum_id'], 'p.') . ' + AND ' . $phpbb_content_visibility->get_visibility_sql('post', $topic_info['forum_id'], 'p.') . ' AND p.poster_id = u.user_id ' . $limit_time_sql . ' ORDER BY ' . $sort_order_sql; diff --git a/phpBB/includes/ucp/ucp_main.php b/phpBB/includes/ucp/ucp_main.php index 7aa06464b7..615b567134 100644 --- a/phpBB/includes/ucp/ucp_main.php +++ b/phpBB/includes/ucp/ucp_main.php @@ -642,7 +642,7 @@ class ucp_main */ function assign_topiclist($mode = 'subscribed', $forbidden_forum_ary = array()) { - global $user, $db, $template, $config, $cache, $auth, $phpbb_root_path, $phpEx; + global $user, $db, $template, $config, $cache, $auth, $phpbb_root_path, $phpEx, $phpbb_container; $table = ($mode == 'subscribed') ? TOPICS_WATCH_TABLE : BOOKMARKS_TABLE; $start = request_var('start', 0); @@ -768,6 +768,8 @@ class ucp_main } } + $phpbb_content_visibility = $phpbb_container->get('content.visibility'); + foreach ($topic_list as $topic_id) { $row = &$rowset[$topic_id]; @@ -778,7 +780,7 @@ class ucp_main $unread_topic = (isset($topic_tracking_info[$topic_id]) && $row['topic_last_post_time'] > $topic_tracking_info[$topic_id]) ? true : false; // Replies - $replies = phpbb_content_visibility::get_count('topic_posts', $row, $forum_id) - 1; + $replies = $phpbb_content_visibility->get_count('topic_posts', $row, $forum_id) - 1; if ($row['topic_status'] == ITEM_MOVED && !empty($row['topic_moved_id'])) { -- cgit v1.2.1 From 753dc62267118e44b16653113521fe6d0a360720 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 11 Jul 2013 15:02:07 +0200 Subject: [ticket/9657] Fix unit tests PHPBB3-9657 --- phpBB/includes/content_visibility.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/content_visibility.php b/phpBB/includes/content_visibility.php index edf6aa3b31..43efef5d7f 100644 --- a/phpBB/includes/content_visibility.php +++ b/phpBB/includes/content_visibility.php @@ -26,19 +26,19 @@ class phpbb_content_visibility * Database object * @var phpbb_db_driver */ - protected $this->db; + protected $db; /** * User object * @var phpbb_user */ - protected $this->user; + protected $user; /** * Auth object * @var phpbb_auth */ - protected $this->auth; + protected $auth; /** * phpBB root path @@ -55,18 +55,18 @@ class phpbb_content_visibility /** * Constructor * - * @param phpbb_auth $this->auth Auth object - * @param phpbb_db_driver $this->db Database object - * @param phpbb_user $this->user User object + * @param phpbb_auth $auth Auth object + * @param phpbb_db_driver $db Database object + * @param phpbb_user $user User object * @param string $phpbb_root_path Root path * @param string $php_ext PHP Extension * @return null */ - public function __construct($this->auth, phpbb_db_driver $this->db, $this->user, $phpbb_root_path, $phpEx, $forums_table, $posts_table, $topics_table, $users_table) + public function __construct($auth, phpbb_db_driver $db, $user, $phpbb_root_path, $phpEx, $forums_table, $posts_table, $topics_table, $users_table) { - $this->auth = $this->auth; - $this->db = $this->db; - $this->user = $this->user; + $this->auth = $auth; + $this->db = $db; + $this->user = $user; $this->phpbb_root_path = $phpbb_root_path; $this->php_ext = $php_ext; $this->forums_table = $forums_table; -- cgit v1.2.1 From 0e5e128174f862f16069b56ef6f5b9803fe5cb9b Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 11 Jul 2013 18:02:45 -0400 Subject: [ticket/9657] Fix variable naming of phpEx to php_ext PHPBB3-9657 --- phpBB/includes/content_visibility.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/content_visibility.php b/phpBB/includes/content_visibility.php index 43efef5d7f..01e688d106 100644 --- a/phpBB/includes/content_visibility.php +++ b/phpBB/includes/content_visibility.php @@ -62,7 +62,7 @@ class phpbb_content_visibility * @param string $php_ext PHP Extension * @return null */ - public function __construct($auth, phpbb_db_driver $db, $user, $phpbb_root_path, $phpEx, $forums_table, $posts_table, $topics_table, $users_table) + public function __construct($auth, phpbb_db_driver $db, $user, $phpbb_root_path, $php_ext, $forums_table, $posts_table, $topics_table, $users_table) { $this->auth = $auth; $this->db = $db; -- cgit v1.2.1 From 54012dfb2f11e275e65078689a554f865562041e Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 11 Jul 2013 18:04:56 -0400 Subject: [ticket/9657] Initialise variable outside of the loop PHPBB3-9657 --- phpBB/includes/mcp/mcp_main.php | 1 + 1 file changed, 1 insertion(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/mcp/mcp_main.php b/phpBB/includes/mcp/mcp_main.php index 62c3eda447..b80532a4a0 100644 --- a/phpBB/includes/mcp/mcp_main.php +++ b/phpBB/includes/mcp/mcp_main.php @@ -513,6 +513,7 @@ function mcp_move_topic($topic_ids) $db->sql_query($sql); } + $shadow_topics = 0; $forum_ids = array($to_forum_id); foreach ($topic_data as $topic_id => $row) { -- cgit v1.2.1 From 53c0647aed4a4995d3ae00ed775ff563eaa61b9a Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 11 Jul 2013 22:16:45 -0400 Subject: [ticket/9657] Use include instead of include_once PHPBB3-9657 --- phpBB/includes/mcp/mcp_queue.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/mcp/mcp_queue.php b/phpBB/includes/mcp/mcp_queue.php index 514d7bc4ee..ac3391c294 100644 --- a/phpBB/includes/mcp/mcp_queue.php +++ b/phpBB/includes/mcp/mcp_queue.php @@ -108,7 +108,10 @@ class mcp_queue return; } - include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx); + if (!class_exists('messenger')) + { + include($phpbb_root_path . 'includes/functions_messenger.' . $phpEx); + } if (!empty($topic_id_list)) { @@ -1042,7 +1045,7 @@ class mcp_queue { if (!function_exists('delete_posts')) { - include_once($phpbb_root_path . 'includes/functions_admin.' . $phpEx); + include($phpbb_root_path . 'includes/functions_admin.' . $phpEx); } // We do not check for permissions here, because the moderator allowed approval/disapproval should be allowed to delete the disapproved posts @@ -1160,7 +1163,10 @@ class mcp_queue } else { - include_once($phpbb_root_path . 'includes/functions_display.' . $phpEx); + if (!function_exists('display_reasons')) + { + include($phpbb_root_path . 'includes/functions_display.' . $phpEx); + } $show_notify = false; -- cgit v1.2.1 From 5ab0090e6c9fa1b497938a932cdf28ba55a17e7c Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 11 Jul 2013 22:35:55 -0400 Subject: [ticket/9657] Remove sql_visibility as it is always non-empty PHPBB3-9657 --- phpBB/includes/feed/forum.php | 7 ++----- phpBB/includes/feed/overall.php | 4 +--- phpBB/includes/feed/topic.php | 4 +--- phpBB/includes/functions.php | 10 ++++------ 4 files changed, 8 insertions(+), 17 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/feed/forum.php b/phpBB/includes/feed/forum.php index fc217c203c..4a159ff3d4 100644 --- a/phpBB/includes/feed/forum.php +++ b/phpBB/includes/feed/forum.php @@ -90,14 +90,12 @@ class phpbb_feed_forum extends phpbb_feed_post_base function get_sql() { - $sql_visibility = $this->content_visibility->get_visibility_sql('topic', $this->forum_id); - // Determine topics with recent activity $sql = 'SELECT topic_id, topic_last_post_time FROM ' . TOPICS_TABLE . ' WHERE forum_id = ' . $this->forum_id . ' AND topic_moved_id = 0 - ' . (($sql_visibility) ? ' AND ' . $sql_visibility : '') . ' + AND ' . $this->content_visibility->get_visibility_sql('topic', $this->forum_id) . ' ORDER BY topic_last_post_time DESC'; $result = $this->db->sql_query_limit($sql, $this->num_items); @@ -116,8 +114,6 @@ class phpbb_feed_forum extends phpbb_feed_post_base return false; } - $sql_visibility = $this->content_visibility->get_visibility_sql('post', $this->forum_id, 'p.'); - $this->sql = array( 'SELECT' => 'p.post_id, p.topic_id, p.post_time, p.post_edit_time, p.post_visibility, p.post_subject, p.post_text, p.bbcode_bitfield, p.bbcode_uid, p.enable_bbcode, p.enable_smilies, p.enable_magic_url, ' . 'u.username, u.user_id', @@ -127,6 +123,7 @@ class phpbb_feed_forum extends phpbb_feed_post_base ), 'WHERE' => $this->db->sql_in_set('p.topic_id', $topic_ids) . ' ' . (($sql_visibility) ? ' AND ' . $sql_visibility : '') . ' + AND ' . $this->content_visibility->get_visibility_sql('post', $this->forum_id, 'p.') . ' AND p.post_time >= ' . $min_post_time . ' AND p.poster_id = u.user_id', 'ORDER_BY' => 'p.post_time DESC', diff --git a/phpBB/includes/feed/overall.php b/phpBB/includes/feed/overall.php index af45840d69..869df7cde0 100644 --- a/phpBB/includes/feed/overall.php +++ b/phpBB/includes/feed/overall.php @@ -56,8 +56,6 @@ class phpbb_feed_overall extends phpbb_feed_post_base return false; } - $sql_visibility = $this->content_visibility->get_visibility_sql('post', array(), 'p.'); - // Get the actual data $this->sql = array( 'SELECT' => 'f.forum_id, f.forum_name, ' . @@ -74,7 +72,7 @@ class phpbb_feed_overall extends phpbb_feed_post_base ), ), 'WHERE' => $this->db->sql_in_set('p.topic_id', $topic_ids) . ' - ' . (($sql_visibility) ? ' AND ' . $sql_visibility : '') . ' + AND ' . $this->content_visibility->get_visibility_sql('post', array(), 'p.') . ' AND p.post_time >= ' . $min_post_time . ' AND u.user_id = p.poster_id', 'ORDER_BY' => 'p.post_time DESC', diff --git a/phpBB/includes/feed/topic.php b/phpBB/includes/feed/topic.php index 10f86486c6..36f958ac60 100644 --- a/phpBB/includes/feed/topic.php +++ b/phpBB/includes/feed/topic.php @@ -93,8 +93,6 @@ class phpbb_feed_topic extends phpbb_feed_post_base function get_sql() { - $sql_visibility = $this->content_visibility->get_visibility_sql('post', $this->forum_id, 'p.'); - $this->sql = array( 'SELECT' => 'p.post_id, p.post_time, p.post_edit_time, p.post_visibility, p.post_subject, p.post_text, p.bbcode_bitfield, p.bbcode_uid, p.enable_bbcode, p.enable_smilies, p.enable_magic_url, ' . 'u.username, u.user_id', @@ -103,7 +101,7 @@ class phpbb_feed_topic extends phpbb_feed_post_base USERS_TABLE => 'u', ), 'WHERE' => 'p.topic_id = ' . $this->topic_id . ' - ' . (($sql_visibility) ? ' AND ' . $sql_visibility : '') . ' + AND ' . $this->content_visibility->get_visibility_sql('post', $this->forum_id, 'p.') . ' AND p.poster_id = u.user_id', 'ORDER_BY' => 'p.post_time DESC', ); diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 9664b5663c..93ad723eda 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -2000,8 +2000,6 @@ function update_forum_tracking_info($forum_id, $forum_last_post_time, $f_mark_ti // Handle update of unapproved topics info. // Only update for moderators having m_approve permission for the forum. $phpbb_content_visibility = $phpbb_container->get('content.visibility'); - $sql_update_unapproved = $phpbb_content_visibility->get_visibility_sql('topic', $forum_id, 't.'); - $sql_update_unapproved = ($sql_update_unapproved) ? ' AND ' . $sql_update_unapproved : ''; // Check the forum for any left unread topics. // If there are none, we mark the forum as read. @@ -2021,8 +2019,8 @@ function update_forum_tracking_info($forum_id, $forum_last_post_time, $f_mark_ti AND tt.user_id = ' . $user->data['user_id'] . ') WHERE t.forum_id = ' . $forum_id . ' AND t.topic_last_post_time > ' . $mark_time_forum . ' - AND t.topic_moved_id = 0 ' . - $sql_update_unapproved . ' + AND t.topic_moved_id = 0 + AND ' . $phpbb_content_visibility->get_visibility_sql('topic', $forum_id, 't.') . ' AND (tt.topic_id IS NULL OR tt.mark_time < t.topic_last_post_time)'; $result = $db->sql_query_limit($sql, 1); @@ -2046,8 +2044,8 @@ function update_forum_tracking_info($forum_id, $forum_last_post_time, $f_mark_ti FROM ' . TOPICS_TABLE . ' t WHERE t.forum_id = ' . $forum_id . ' AND t.topic_last_post_time > ' . $mark_time_forum . ' - AND t.topic_moved_id = 0 ' . - $sql_update_unapproved; + AND t.topic_moved_id = 0 + AND ' . $phpbb_content_visibility->get_visibility_sql('topic', $forum_id, 't.'); $result = $db->sql_query($sql); $check_forum = $tracking_topics['tf'][$forum_id]; -- cgit v1.2.1 From 003a104f931201704998f5c00c5cf982896b470b Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 11 Jul 2013 22:41:24 -0400 Subject: [ticket/9657] Add type hints for classes PHPBB3-9657 --- phpBB/includes/content_visibility.php | 2 +- phpBB/includes/feed/base.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/content_visibility.php b/phpBB/includes/content_visibility.php index 01e688d106..4ad5f6793e 100644 --- a/phpBB/includes/content_visibility.php +++ b/phpBB/includes/content_visibility.php @@ -62,7 +62,7 @@ class phpbb_content_visibility * @param string $php_ext PHP Extension * @return null */ - public function __construct($auth, phpbb_db_driver $db, $user, $phpbb_root_path, $php_ext, $forums_table, $posts_table, $topics_table, $users_table) + public function __construct(phpbb_auth $auth, phpbb_db_driver $db, phpbb_user $user, $phpbb_root_path, $php_ext, $forums_table, $posts_table, $topics_table, $users_table) { $this->auth = $auth; $this->db = $db; diff --git a/phpBB/includes/feed/base.php b/phpBB/includes/feed/base.php index 84fdbe415a..296d830932 100644 --- a/phpBB/includes/feed/base.php +++ b/phpBB/includes/feed/base.php @@ -84,7 +84,7 @@ abstract class phpbb_feed_base * @param string $phpEx php file extension * @return null */ - function __construct(phpbb_feed_helper $helper, phpbb_config $config, phpbb_db_driver $db, phpbb_cache_driver_interface $cache, phpbb_user $user, phpbb_auth $auth, $content_visibility, $phpEx) + function __construct(phpbb_feed_helper $helper, phpbb_config $config, phpbb_db_driver $db, phpbb_cache_driver_interface $cache, phpbb_user $user, phpbb_auth $auth, phpbb_content_visibility $content_visibility, $phpEx) { $this->config = $config; $this->helper = $helper; -- cgit v1.2.1 From 1911285b77fa791ca202f810e4ba40c822aa5ae9 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 11 Jul 2013 22:44:06 -0400 Subject: [ticket/9657] Notifications do not require emails or jabber anymore PHPBB3-9657 --- phpBB/includes/mcp/mcp_queue.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/mcp/mcp_queue.php b/phpBB/includes/mcp/mcp_queue.php index ac3391c294..8a9390212f 100644 --- a/phpBB/includes/mcp/mcp_queue.php +++ b/phpBB/includes/mcp/mcp_queue.php @@ -692,7 +692,7 @@ class mcp_queue { $show_notify = false; - if ($action == 'approve' && ($config['email_enable'] || $config['jab_enable'])) + if ($action == 'approve') { foreach ($post_info as $post_data) { @@ -840,7 +840,7 @@ class mcp_queue { $show_notify = false; - if ($action == 'approve' && ($config['email_enable'] || $config['jab_enable'])) + if ($action == 'approve') { foreach ($topic_info as $topic_data) { -- cgit v1.2.1 From 8c5ff0775a4563f2a4ad1e7f30379576e1c5ca21 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 12 Jul 2013 15:42:28 -0400 Subject: [ticket/9657] Fix a little error when moving softdeleted topics PHPBB3-9657 --- phpBB/includes/mcp/mcp_main.php | 1 - 1 file changed, 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/mcp/mcp_main.php b/phpBB/includes/mcp/mcp_main.php index b80532a4a0..eddfdc3759 100644 --- a/phpBB/includes/mcp/mcp_main.php +++ b/phpBB/includes/mcp/mcp_main.php @@ -498,7 +498,6 @@ function mcp_move_topic($topic_ids) $posts_moved_unapproved += $topic_info['topic_posts_unapproved']; $posts_moved_softdeleted += $topic_info['topic_posts_softdeleted']; } - $topics_moved = sizeof($topic_data); $db->sql_transaction('begin'); -- cgit v1.2.1 From 28e3341fcde976754f122a9c540b20aa705658fc Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 13 Jul 2013 00:54:39 -0400 Subject: [ticket/9657] Keep approval state of posts/topics when copying them PHPBB3-9657 --- phpBB/includes/mcp/mcp_main.php | 41 +++++++++++++++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 6 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/mcp/mcp_main.php b/phpBB/includes/mcp/mcp_main.php index eddfdc3759..275edbe55a 100644 --- a/phpBB/includes/mcp/mcp_main.php +++ b/phpBB/includes/mcp/mcp_main.php @@ -1144,10 +1144,10 @@ function mcp_fork_topic($topic_ids) { $topic_data = get_topic_data($topic_ids, 'f_post'); - $total_posts = 0; + $total_topics = $total_topics_unapproved = $total_topics_softdeleted = 0; + $total_posts = $total_posts_unapproved = $total_posts_softdeleted = 0; $new_topic_id_list = array(); - foreach ($topic_data as $topic_id => $topic_row) { if (!isset($search_type) && $topic_row['enable_indexing']) @@ -1178,7 +1178,7 @@ function mcp_fork_topic($topic_ids) 'forum_id' => (int) $to_forum_id, 'icon_id' => (int) $topic_row['icon_id'], 'topic_attachment' => (int) $topic_row['topic_attachment'], - 'topic_visibility' => ITEM_APPROVED, + 'topic_visibility' => (int) $topic_row['topic_visibility'], 'topic_reported' => 0, 'topic_title' => (string) $topic_row['topic_title'], 'topic_poster' => (int) $topic_row['topic_poster'], @@ -1206,6 +1206,19 @@ function mcp_fork_topic($topic_ids) $new_topic_id = $db->sql_nextid(); $new_topic_id_list[$topic_id] = $new_topic_id; + switch ($topic_row['topic_visibility']) + { + case ITEM_APPROVED: + $total_topics++; + break; + case ITEM_UNAPPROVED: + $total_topics_unapproved++; + break; + case ITEM_DELETED: + $total_topics_softdeleted++; + break; + } + if ($topic_row['poll_start']) { $poll_rows = array(); @@ -1246,7 +1259,6 @@ function mcp_fork_topic($topic_ids) continue; } - $total_posts += sizeof($post_rows); foreach ($post_rows as $row) { $sql_ary = array( @@ -1256,7 +1268,7 @@ function mcp_fork_topic($topic_ids) 'icon_id' => (int) $row['icon_id'], 'poster_ip' => (string) $row['poster_ip'], 'post_time' => (int) $row['post_time'], - 'post_visibility' => ITEM_APPROVED, + 'post_visibility' => (int) $row['post_visibility'], 'post_reported' => 0, 'enable_bbcode' => (int) $row['enable_bbcode'], 'enable_smilies' => (int) $row['enable_smilies'], @@ -1280,6 +1292,19 @@ function mcp_fork_topic($topic_ids) $db->sql_query('INSERT INTO ' . POSTS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary)); $new_post_id = $db->sql_nextid(); + switch ($row['post_visibility']) + { + case ITEM_APPROVED: + $total_posts++; + break; + case ITEM_UNAPPROVED: + $total_posts_unapproved++; + break; + case ITEM_DELETED: + $total_posts_softdeleted++; + break; + } + // Copy whether the topic is dotted markread('post', $to_forum_id, $new_topic_id, 0, $row['poster_id']); @@ -1374,7 +1399,11 @@ function mcp_fork_topic($topic_ids) // Sync new topics, parent forums and board stats $sql = 'UPDATE ' . FORUMS_TABLE . ' SET forum_posts_approved = forum_posts_approved + ' . $total_posts . ', - forum_topics_approved = forum_topics_approved + ' . sizeof($new_topic_id_list) . ' + forum_posts_unapproved = forum_posts_unapproved + ' . $total_posts_unapproved . ', + forum_posts_softdeleted = forum_posts_softdeleted + ' . $total_posts_softdeleted . ', + forum_topics_approved = forum_topics_approved + ' . $total_topics . ', + forum_topics_unapproved = forum_topics_unapproved + ' . $total_topics_unapproved . ', + forum_topics_softdeleted = forum_topics_softdeleted + ' . $total_topics_softdeleted . ' WHERE forum_id = ' . $to_forum_id; $db->sql_query($sql); -- cgit v1.2.1 From 6cde302ffaf9d238e279704955a5c00ee0bdfd36 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 13 Jul 2013 10:47:42 -0400 Subject: [ticket/9657] Remove old code PHPBB3-9657 --- phpBB/includes/feed/forum.php | 1 - 1 file changed, 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/feed/forum.php b/phpBB/includes/feed/forum.php index 4a159ff3d4..b5f0dd0f8f 100644 --- a/phpBB/includes/feed/forum.php +++ b/phpBB/includes/feed/forum.php @@ -122,7 +122,6 @@ class phpbb_feed_forum extends phpbb_feed_post_base USERS_TABLE => 'u', ), 'WHERE' => $this->db->sql_in_set('p.topic_id', $topic_ids) . ' - ' . (($sql_visibility) ? ' AND ' . $sql_visibility : '') . ' AND ' . $this->content_visibility->get_visibility_sql('post', $this->forum_id, 'p.') . ' AND p.post_time >= ' . $min_post_time . ' AND p.poster_id = u.user_id', -- cgit v1.2.1