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/functions_posting.php | 64 ++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 32 deletions(-) (limited to 'phpBB/includes/functions_posting.php') 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); -- 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/functions_posting.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'phpBB/includes/functions_posting.php') 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); -- 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/functions_posting.php | 112 +++++++++++++++++++---------------- 1 file changed, 62 insertions(+), 50 deletions(-) (limited to 'phpBB/includes/functions_posting.php') 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; -- 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/functions_posting.php | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'phpBB/includes/functions_posting.php') 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'; -- 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/functions_posting.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'phpBB/includes/functions_posting.php') 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 { -- cgit v1.2.1 From 74e2a8f893a2e7a69ba129a74dd0b3c31e742e79 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sun, 9 Sep 2012 13:29:47 -0500 Subject: [ticket/11103] Post notifications PHPBB3-11103 --- phpBB/includes/functions_posting.php | 252 +++-------------------------------- 1 file changed, 19 insertions(+), 233 deletions(-) (limited to 'phpBB/includes/functions_posting.php') diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index c50395a5df..6c5c4535a3 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -61,7 +61,7 @@ function generate_smilies($mode, $forum_id) 'body' => 'posting_smilies.html') ); - generate_pagination(append_sid("{$phpbb_root_path}posting.$phpEx", 'mode=smilies&f=' . $forum_id), $smiley_count, $config['smilies_per_page'], $start); + generate_pagination(append_sid("{$phpbb_root_path}posting.$phpEx", 'mode=smilies&f=' . $forum_id), $smiley_count, $config['smilies_per_page'], $start); } $display_link = false; @@ -1173,237 +1173,6 @@ function topic_review($topic_id, $forum_id, $mode = 'topic_review', $cur_post_id return true; } -/** -* User Notification -*/ -function user_notification($mode, $subject, $topic_title, $forum_name, $forum_id, $topic_id, $post_id) -{ - global $db, $user, $config, $phpbb_root_path, $phpEx, $auth; - - $topic_notification = ($mode == 'reply' || $mode == 'quote') ? true : false; - $forum_notification = ($mode == 'post') ? true : false; - - if (!$topic_notification && !$forum_notification) - { - trigger_error('NO_MODE'); - } - - if (($topic_notification && !$config['allow_topic_notify']) || ($forum_notification && !$config['allow_forum_notify'])) - { - return; - } - - $topic_title = ($topic_notification) ? $topic_title : $subject; - $topic_title = censor_text($topic_title); - - // Exclude guests, current user and banned users from notifications - if (!function_exists('phpbb_get_banned_user_ids')) - { - include($phpbb_root_path . 'includes/functions_user.' . $phpEx); - } - $sql_ignore_users = phpbb_get_banned_user_ids(); - $sql_ignore_users[ANONYMOUS] = ANONYMOUS; - $sql_ignore_users[$user->data['user_id']] = $user->data['user_id']; - - $notify_rows = array(); - - // -- get forum_userids || topic_userids - $sql = 'SELECT u.user_id, u.username, u.user_email, u.user_lang, u.user_notify_type, u.user_jabber - FROM ' . (($topic_notification) ? TOPICS_WATCH_TABLE : FORUMS_WATCH_TABLE) . ' w, ' . USERS_TABLE . ' u - WHERE w.' . (($topic_notification) ? 'topic_id' : 'forum_id') . ' = ' . (($topic_notification) ? $topic_id : $forum_id) . ' - AND ' . $db->sql_in_set('w.user_id', $sql_ignore_users, true) . ' - AND w.notify_status = ' . NOTIFY_YES . ' - AND u.user_type IN (' . USER_NORMAL . ', ' . USER_FOUNDER . ') - AND u.user_id = w.user_id'; - $result = $db->sql_query($sql); - - while ($row = $db->sql_fetchrow($result)) - { - $notify_user_id = (int) $row['user_id']; - $notify_rows[$notify_user_id] = array( - 'user_id' => $notify_user_id, - 'username' => $row['username'], - 'user_email' => $row['user_email'], - 'user_jabber' => $row['user_jabber'], - 'user_lang' => $row['user_lang'], - 'notify_type' => ($topic_notification) ? 'topic' : 'forum', - 'template' => ($topic_notification) ? 'topic_notify' : 'newtopic_notify', - 'method' => $row['user_notify_type'], - 'allowed' => false - ); - - // Add users who have been already notified to ignore list - $sql_ignore_users[$notify_user_id] = $notify_user_id; - } - $db->sql_freeresult($result); - - // forum notification is sent to those not already receiving topic notifications - if ($topic_notification) - { - $sql = 'SELECT u.user_id, u.username, u.user_email, u.user_lang, u.user_notify_type, u.user_jabber - FROM ' . FORUMS_WATCH_TABLE . ' fw, ' . USERS_TABLE . " u - WHERE fw.forum_id = $forum_id - AND " . $db->sql_in_set('fw.user_id', $sql_ignore_users, true) . ' - AND fw.notify_status = ' . NOTIFY_YES . ' - AND u.user_type IN (' . USER_NORMAL . ', ' . USER_FOUNDER . ') - AND u.user_id = fw.user_id'; - $result = $db->sql_query($sql); - - while ($row = $db->sql_fetchrow($result)) - { - $notify_user_id = (int) $row['user_id']; - $notify_rows[$notify_user_id] = array( - 'user_id' => $notify_user_id, - 'username' => $row['username'], - 'user_email' => $row['user_email'], - 'user_jabber' => $row['user_jabber'], - 'user_lang' => $row['user_lang'], - 'notify_type' => 'forum', - 'template' => 'forum_notify', - 'method' => $row['user_notify_type'], - 'allowed' => false - ); - } - $db->sql_freeresult($result); - } - - if (!sizeof($notify_rows)) - { - return; - } - - // Make sure users are allowed to read the forum - foreach ($auth->acl_get_list(array_keys($notify_rows), 'f_read', $forum_id) as $forum_id => $forum_ary) - { - foreach ($forum_ary as $auth_option => $user_ary) - { - foreach ($user_ary as $user_id) - { - $notify_rows[$user_id]['allowed'] = true; - } - } - } - - // Now, we have to do a little step before really sending, we need to distinguish our users a little bit. ;) - $msg_users = $delete_ids = $update_notification = array(); - foreach ($notify_rows as $user_id => $row) - { - if (!$row['allowed'] || !trim($row['user_email'])) - { - $delete_ids[$row['notify_type']][] = $row['user_id']; - } - else - { - $msg_users[] = $row; - $update_notification[$row['notify_type']][] = $row['user_id']; - - /* - * We also update the forums watch table for this user when we are - * sending out a topic notification to prevent sending out another - * notification in case this user is also subscribed to the forum - * this topic was posted in. - * Since an UPDATE query is used, this has no effect on users only - * subscribed to the topic (i.e. no row is created) and should not - * be a performance issue. - */ - if ($row['notify_type'] === 'topic') - { - $update_notification['forum'][] = $row['user_id']; - } - } - } - unset($notify_rows); - - // Now, we are able to really send out notifications - if (sizeof($msg_users)) - { - include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx); - $messenger = new messenger(); - - $msg_list_ary = array(); - foreach ($msg_users as $row) - { - $pos = (!isset($msg_list_ary[$row['template']])) ? 0 : sizeof($msg_list_ary[$row['template']]); - - $msg_list_ary[$row['template']][$pos]['method'] = $row['method']; - $msg_list_ary[$row['template']][$pos]['email'] = $row['user_email']; - $msg_list_ary[$row['template']][$pos]['jabber'] = $row['user_jabber']; - $msg_list_ary[$row['template']][$pos]['name'] = $row['username']; - $msg_list_ary[$row['template']][$pos]['lang'] = $row['user_lang']; - $msg_list_ary[$row['template']][$pos]['user_id']= $row['user_id']; - } - unset($msg_users); - - foreach ($msg_list_ary as $email_template => $email_list) - { - foreach ($email_list as $addr) - { - $messenger->template($email_template, $addr['lang']); - - $messenger->to($addr['email'], $addr['name']); - $messenger->im($addr['jabber'], $addr['name']); - - $messenger->assign_vars(array( - 'USERNAME' => htmlspecialchars_decode($addr['name']), - 'TOPIC_TITLE' => htmlspecialchars_decode($topic_title), - 'FORUM_NAME' => htmlspecialchars_decode($forum_name), - - 'U_FORUM' => generate_board_url() . "/viewforum.$phpEx?f=$forum_id", - 'U_TOPIC' => generate_board_url() . "/viewtopic.$phpEx?f=$forum_id&t=$topic_id", - 'U_NEWEST_POST' => generate_board_url() . "/viewtopic.$phpEx?f=$forum_id&t=$topic_id&p=$post_id&e=$post_id", - 'U_STOP_WATCHING_TOPIC' => generate_board_url() . "/viewtopic.$phpEx?uid={$addr['user_id']}&f=$forum_id&t=$topic_id&unwatch=topic", - 'U_STOP_WATCHING_FORUM' => generate_board_url() . "/viewforum.$phpEx?uid={$addr['user_id']}&f=$forum_id&unwatch=forum", - )); - - $messenger->send($addr['method']); - } - } - unset($msg_list_ary); - - $messenger->save_queue(); - } - - // Handle the DB updates - $db->sql_transaction('begin'); - - if (!empty($update_notification['topic'])) - { - $sql = 'UPDATE ' . TOPICS_WATCH_TABLE . ' - SET notify_status = ' . NOTIFY_NO . " - WHERE topic_id = $topic_id - AND " . $db->sql_in_set('user_id', $update_notification['topic']); - $db->sql_query($sql); - } - - if (!empty($update_notification['forum'])) - { - $sql = 'UPDATE ' . FORUMS_WATCH_TABLE . ' - SET notify_status = ' . NOTIFY_NO . " - WHERE forum_id = $forum_id - AND " . $db->sql_in_set('user_id', $update_notification['forum']); - $db->sql_query($sql); - } - - // Now delete the user_ids not authorised to receive notifications on this topic/forum - if (!empty($delete_ids['topic'])) - { - $sql = 'DELETE FROM ' . TOPICS_WATCH_TABLE . " - WHERE topic_id = $topic_id - AND " . $db->sql_in_set('user_id', $delete_ids['topic']); - $db->sql_query($sql); - } - - if (!empty($delete_ids['forum'])) - { - $sql = 'DELETE FROM ' . FORUMS_WATCH_TABLE . " - WHERE forum_id = $forum_id - AND " . $db->sql_in_set('user_id', $delete_ids['forum']); - $db->sql_query($sql); - } - - $db->sql_transaction('commit'); -} - // // Post handling functions // @@ -1640,6 +1409,7 @@ function delete_post($forum_id, $topic_id, $post_id, &$data) function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $update_message = true, $update_search_index = true) { global $db, $auth, $user, $config, $phpEx, $template, $phpbb_root_path; + global $phpbb_container; // We do not handle erasing posts here if ($mode == 'delete') @@ -2452,7 +2222,23 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u // Send Notifications if (($mode == 'reply' || $mode == 'quote' || $mode == 'post') && $post_approval) { - user_notification($mode, $subject, $data['topic_title'], $data['forum_name'], $data['forum_id'], $data['topic_id'], $data['post_id']); + $notifications = $phpbb_container->get('notifications'); + + switch ($mode) + { + case 'reply' : + case 'quote' : + $notifications->add_notifications('post', array_merge($data, array( + 'post_username' => $username, + ))); + break; + + case 'post' : + $notifications->add_notifications('topic', array_merge($data, array( + 'post_username' => $username, + ))); + break; + } } $params = $add_anchor = ''; -- cgit v1.2.1 From e09f25d59707fc842b073fa2909cefc3d16ecbf3 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sun, 9 Sep 2012 14:55:40 -0500 Subject: [ticket/11103] Update notifications on post/topic edit PHPBB3-11103 --- phpBB/includes/functions_posting.php | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'phpBB/includes/functions_posting.php') diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index 6c5c4535a3..64840bfa51 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -2220,12 +2220,18 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u } // Send Notifications - if (($mode == 'reply' || $mode == 'quote' || $mode == 'post') && $post_approval) + if ($post_approval) { $notifications = $phpbb_container->get('notifications'); switch ($mode) { + case 'post' : + $notifications->add_notifications('topic', array_merge($data, array( + 'post_username' => $username, + ))); + break; + case 'reply' : case 'quote' : $notifications->add_notifications('post', array_merge($data, array( @@ -2233,8 +2239,15 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u ))); break; - case 'post' : - $notifications->add_notifications('topic', array_merge($data, array( + case 'edit_topic' : + case 'edit_first_post' : + case 'edit' : + case 'edit_last_post' : + $notifications->update_notifications('topic', array_merge($data, array( + 'post_username' => $username, + 'topic_title' => $subject, + ))); + $notifications->update_notifications('post', array_merge($data, array( 'post_username' => $username, ))); break; -- cgit v1.2.1 From 207bbdf48cb05abfb611f238e4ba07131131c74d Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Wed, 12 Sep 2012 23:55:29 -0500 Subject: [ticket/11103] Quote notifications PHPBB3-11103 --- phpBB/includes/functions_posting.php | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'phpBB/includes/functions_posting.php') diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index 64840bfa51..ff0a59a4e3 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -2230,6 +2230,9 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u $notifications->add_notifications('topic', array_merge($data, array( 'post_username' => $username, ))); + $notifications->add_notifications('quote', array_merge($data, array( + 'post_username' => $username, + ))); break; case 'reply' : @@ -2237,6 +2240,9 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u $notifications->add_notifications('post', array_merge($data, array( 'post_username' => $username, ))); + $notifications->add_notifications('quote', array_merge($data, array( + 'post_username' => $username, + ))); break; case 'edit_topic' : @@ -2250,6 +2256,9 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u $notifications->update_notifications('post', array_merge($data, array( 'post_username' => $username, ))); + $notifications->add_notifications('quote', array_merge($data, array( + 'post_username' => $username, + ))); break; } } -- cgit v1.2.1 From 44aa773ce07d81d4585f3a24a728f9b445c4c098 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Fri, 14 Sep 2012 14:55:14 -0500 Subject: [ticket/11103] Allow notification types to override update functionality This is needed for quote editing because we need to check if the users are still all quoted or notify new quotes appropriately. PHPBB3-11103 --- phpBB/includes/functions_posting.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes/functions_posting.php') diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index ff0a59a4e3..26d9b81896 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -2256,7 +2256,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u $notifications->update_notifications('post', array_merge($data, array( 'post_username' => $username, ))); - $notifications->add_notifications('quote', array_merge($data, array( + $notifications->update_notifications('quote', array_merge($data, array( 'post_username' => $username, ))); break; -- cgit v1.2.1 From ed1ec8e720a7ec3c1270cd631cc37e531f315f26 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Fri, 14 Sep 2012 16:54:20 -0500 Subject: [ticket/11103] Add/Update/Mark Read functions accept an array for the type This saves a lot of code in some areas (where the same data is sent, just for different types) Notifications for bookmarks PHPBB3-11103 --- phpBB/includes/functions_posting.php | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) (limited to 'phpBB/includes/functions_posting.php') diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index 26d9b81896..56f84562f7 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -2227,20 +2227,14 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u switch ($mode) { case 'post' : - $notifications->add_notifications('topic', array_merge($data, array( - 'post_username' => $username, - ))); - $notifications->add_notifications('quote', array_merge($data, array( + $notifications->add_notifications(array('topic', 'quote'), array_merge($data, array( 'post_username' => $username, ))); break; case 'reply' : case 'quote' : - $notifications->add_notifications('post', array_merge($data, array( - 'post_username' => $username, - ))); - $notifications->add_notifications('quote', array_merge($data, array( + $notifications->add_notifications(array('quote', 'bookmark', 'post'), array_merge($data, array( 'post_username' => $username, ))); break; @@ -2253,10 +2247,8 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u 'post_username' => $username, 'topic_title' => $subject, ))); - $notifications->update_notifications('post', array_merge($data, array( - 'post_username' => $username, - ))); - $notifications->update_notifications('quote', array_merge($data, array( + + $notifications->update_notifications(array('quote', 'bookmark', 'post'), array_merge($data, array( 'post_username' => $username, ))); break; -- cgit v1.2.1 From 8e977544fb6763412e45f84791de8c3eccf321c9 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Fri, 14 Sep 2012 17:01:08 -0500 Subject: [ticket/11103] Normalization of $phpbb_notifications variable name Use $phpbb_notifications instead of $notifications everywhere for consistency and conflict prevention. PHPBB3-11103 --- phpBB/includes/functions_posting.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'phpBB/includes/functions_posting.php') diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index 56f84562f7..e48a2b6bec 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -2222,19 +2222,19 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u // Send Notifications if ($post_approval) { - $notifications = $phpbb_container->get('notifications'); + $phpbb_notifications = $phpbb_container->get('notifications'); switch ($mode) { case 'post' : - $notifications->add_notifications(array('topic', 'quote'), array_merge($data, array( + $phpbb_notifications->add_notifications(array('topic', 'quote'), array_merge($data, array( 'post_username' => $username, ))); break; case 'reply' : case 'quote' : - $notifications->add_notifications(array('quote', 'bookmark', 'post'), array_merge($data, array( + $phpbb_notifications->add_notifications(array('quote', 'bookmark', 'post'), array_merge($data, array( 'post_username' => $username, ))); break; @@ -2243,12 +2243,12 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u case 'edit_first_post' : case 'edit' : case 'edit_last_post' : - $notifications->update_notifications('topic', array_merge($data, array( + $phpbb_notifications->update_notifications('topic', array_merge($data, array( 'post_username' => $username, 'topic_title' => $subject, ))); - $notifications->update_notifications(array('quote', 'bookmark', 'post'), array_merge($data, array( + $phpbb_notifications->update_notifications(array('quote', 'bookmark', 'post'), array_merge($data, array( 'post_username' => $username, ))); break; -- cgit v1.2.1 From 959c81d00e830e89fa9d583ee93bf8f166013fe0 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Fri, 14 Sep 2012 18:05:13 -0500 Subject: [ticket/11103] Use appropriate email templates to send notifications Fixing a number of bugs PHPBB3-11103 --- phpBB/includes/functions_posting.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'phpBB/includes/functions_posting.php') diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index e48a2b6bec..fc2c5a47b6 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -2229,6 +2229,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u case 'post' : $phpbb_notifications->add_notifications(array('topic', 'quote'), array_merge($data, array( 'post_username' => $username, + 'poster_id' => (int) $user->data['user_id'], ))); break; @@ -2236,6 +2237,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u case 'quote' : $phpbb_notifications->add_notifications(array('quote', 'bookmark', 'post'), array_merge($data, array( 'post_username' => $username, + 'poster_id' => (int) $user->data['user_id'], ))); break; -- cgit v1.2.1 From 05b573ebf76c737f89deaefd22ce963aa910e5d1 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sat, 15 Sep 2012 13:51:02 -0500 Subject: [ticket/11103] Topic and post dis/approval notifications Remove the formatted title function, plaintext is not needed since email templates are used Fix a number of bugs. PHPBB3-11103 --- phpBB/includes/functions_posting.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'phpBB/includes/functions_posting.php') diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index fc2c5a47b6..6089ef0014 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -2238,6 +2238,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u $phpbb_notifications->add_notifications(array('quote', 'bookmark', 'post'), array_merge($data, array( 'post_username' => $username, 'poster_id' => (int) $user->data['user_id'], + 'post_text' => $data['message'], ))); break; @@ -2252,6 +2253,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u $phpbb_notifications->update_notifications(array('quote', 'bookmark', 'post'), array_merge($data, array( 'post_username' => $username, + 'post_text' => $data['message'], ))); break; } -- cgit v1.2.1 From 7454d5c2d526f237bf24825b80edf6c9f1750fc6 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sat, 15 Sep 2012 14:33:15 -0500 Subject: [ticket/11103] Topic/Post in queue notification Also, bug fixes and cleanup PHPBB3-11103 --- phpBB/includes/functions_posting.php | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) (limited to 'phpBB/includes/functions_posting.php') diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index 6089ef0014..4dd840ad53 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -2220,10 +2220,9 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u } // Send Notifications + $phpbb_notifications = $phpbb_container->get('notifications'); if ($post_approval) { - $phpbb_notifications = $phpbb_container->get('notifications'); - switch ($mode) { case 'post' : @@ -2258,6 +2257,34 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u break; } } + else + { + switch ($mode) + { + case 'post' : + $phpbb_notifications->add_notifications(array('topic_in_queue'), array_merge($data, array( + 'post_username' => $username, + 'poster_id' => (int) $user->data['user_id'], + ))); + break; + + case 'reply' : + case 'quote' : + $phpbb_notifications->add_notifications(array('post_in_queue'), array_merge($data, array( + 'post_username' => $username, + 'poster_id' => (int) $user->data['user_id'], + ))); + break; + + case 'edit_topic' : + case 'edit_first_post' : + case 'edit' : + case 'edit_last_post' : + $phpbb_notifications->delete_notifications('topic', $data['topic_id']); + $phpbb_notifications->delete_notifications(array('quote', 'bookmark', 'post'), $data['post_id']); + break; + } + } $params = $add_anchor = ''; -- cgit v1.2.1 From 3897a442f7fe0107cf71adc02af999b496bfebaf Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Thu, 20 Sep 2012 10:40:18 -0500 Subject: [ticket/11103] Bug fixing PHPBB3-11103 --- phpBB/includes/functions_posting.php | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'phpBB/includes/functions_posting.php') diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index 4dd840ad53..4ae5989fed 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -2229,6 +2229,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u $phpbb_notifications->add_notifications(array('topic', 'quote'), array_merge($data, array( 'post_username' => $username, 'poster_id' => (int) $user->data['user_id'], + 'post_time' => $current_time, ))); break; @@ -2238,6 +2239,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u 'post_username' => $username, 'poster_id' => (int) $user->data['user_id'], 'post_text' => $data['message'], + 'post_time' => $current_time, ))); break; @@ -2265,6 +2267,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u $phpbb_notifications->add_notifications(array('topic_in_queue'), array_merge($data, array( 'post_username' => $username, 'poster_id' => (int) $user->data['user_id'], + 'post_time' => $current_time, ))); break; @@ -2273,6 +2276,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u $phpbb_notifications->add_notifications(array('post_in_queue'), array_merge($data, array( 'post_username' => $username, 'poster_id' => (int) $user->data['user_id'], + 'post_time' => $current_time, ))); break; -- cgit v1.2.1 From aa3f6f4002094d29952d0383107af687bf7dcb15 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Tue, 25 Sep 2012 10:10:10 -0500 Subject: [ticket/11103] Fixing some bugs with the post/topic notifications PHPBB3-11103 --- phpBB/includes/functions_posting.php | 43 +++++++++++------------------------- 1 file changed, 13 insertions(+), 30 deletions(-) (limited to 'phpBB/includes/functions_posting.php') diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index 4ae5989fed..41bdd9f598 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -2221,41 +2221,32 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u // Send Notifications $phpbb_notifications = $phpbb_container->get('notifications'); + $notification_data = array_merge($data, array( + 'topic_title' => (isset($data['topic_title'])) ? $data['topic_title'] : $subject, + 'post_username' => $username, + 'poster_id' => $poster_id, + 'post_text' => $data['message'], + 'post_time' => $current_time, + 'post_subject' => $subject, + )); if ($post_approval) { switch ($mode) { case 'post' : - $phpbb_notifications->add_notifications(array('topic', 'quote'), array_merge($data, array( - 'post_username' => $username, - 'poster_id' => (int) $user->data['user_id'], - 'post_time' => $current_time, - ))); + $phpbb_notifications->add_notifications(array('topic', 'quote'), $notification_data); break; case 'reply' : case 'quote' : - $phpbb_notifications->add_notifications(array('quote', 'bookmark', 'post'), array_merge($data, array( - 'post_username' => $username, - 'poster_id' => (int) $user->data['user_id'], - 'post_text' => $data['message'], - 'post_time' => $current_time, - ))); + $phpbb_notifications->add_notifications(array('quote', 'bookmark', 'post'), $notification_data); break; case 'edit_topic' : case 'edit_first_post' : case 'edit' : case 'edit_last_post' : - $phpbb_notifications->update_notifications('topic', array_merge($data, array( - 'post_username' => $username, - 'topic_title' => $subject, - ))); - - $phpbb_notifications->update_notifications(array('quote', 'bookmark', 'post'), array_merge($data, array( - 'post_username' => $username, - 'post_text' => $data['message'], - ))); + $phpbb_notifications->update_notifications(array('quote', 'bookmark', 'topic', 'post'), $notification_data); break; } } @@ -2264,20 +2255,12 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u switch ($mode) { case 'post' : - $phpbb_notifications->add_notifications(array('topic_in_queue'), array_merge($data, array( - 'post_username' => $username, - 'poster_id' => (int) $user->data['user_id'], - 'post_time' => $current_time, - ))); + $phpbb_notifications->add_notifications(array('topic_in_queue'), $notification_data); break; case 'reply' : case 'quote' : - $phpbb_notifications->add_notifications(array('post_in_queue'), array_merge($data, array( - 'post_username' => $username, - 'poster_id' => (int) $user->data['user_id'], - 'post_time' => $current_time, - ))); + $phpbb_notifications->add_notifications(array('post_in_queue'), $notification_data); break; case 'edit_topic' : -- cgit v1.2.1 From 2a5baad61bace05ee4907f7125555777cf7b1401 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Thu, 27 Sep 2012 20:05:06 -0500 Subject: [ticket/11103] Only notify a user once for a single item Note: The user may be notified multiple times IF they use different notification options. e.g They are subscribed to topics they have bookmarked by a notification and subscribed to the topic by an email notification. In this case, they would receive two notifications. This occurs because we do not want to omit any more direct types of notifications (if they want an email, they should _always_ get at least one email). PHPBB3-11103 --- phpBB/includes/functions_posting.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes/functions_posting.php') diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index 41bdd9f598..6262cee4ad 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -2234,7 +2234,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u switch ($mode) { case 'post' : - $phpbb_notifications->add_notifications(array('topic', 'quote'), $notification_data); + $phpbb_notifications->add_notifications(array('quote', 'topic'), $notification_data); break; case 'reply' : -- 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/functions_posting.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'phpBB/includes/functions_posting.php') 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 b9bc65eed88bbd2dff12102909903cbf4dc9b368 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Thu, 4 Oct 2012 14:47:13 -0500 Subject: [ticket/11103] Make $phpbb_notifications a global and use it everywhere Do not use phpbb_container everywhere (makes testing difficult) PHPBB3-11103 --- phpBB/includes/functions_posting.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/includes/functions_posting.php') diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index 6262cee4ad..3658757e5e 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -1409,7 +1409,7 @@ function delete_post($forum_id, $topic_id, $post_id, &$data) function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $update_message = true, $update_search_index = true) { global $db, $auth, $user, $config, $phpEx, $template, $phpbb_root_path; - global $phpbb_container; + global $phpbb_notifications; // We do not handle erasing posts here if ($mode == 'delete') @@ -2220,7 +2220,6 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u } // Send Notifications - $phpbb_notifications = $phpbb_container->get('notifications'); $notification_data = array_merge($data, array( 'topic_title' => (isset($data['topic_title'])) ? $data['topic_title'] : $subject, 'post_username' => $username, @@ -2229,6 +2228,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u 'post_time' => $current_time, 'post_subject' => $subject, )); + if ($post_approval) { switch ($mode) -- 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/functions_posting.php | 80 +++++++++++++++++------------------- 1 file changed, 38 insertions(+), 42 deletions(-) (limited to 'phpBB/includes/functions_posting.php') 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/functions_posting.php | 48 ++++++++++++++++++++++++------------ 1 file changed, 32 insertions(+), 16 deletions(-) (limited to 'phpBB/includes/functions_posting.php') 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/functions_posting.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'phpBB/includes/functions_posting.php') 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/functions_posting.php | 2 -- 1 file changed, 2 deletions(-) (limited to 'phpBB/includes/functions_posting.php') 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 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/functions_posting.php | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) (limited to 'phpBB/includes/functions_posting.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/functions_posting.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes/functions_posting.php') 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 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/functions_posting.php') 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 0d5d328c81362acdcbccffc28288505db8517616 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sun, 14 Oct 2012 12:42:18 -0500 Subject: [ticket/11103] Spacing consistency PHPBB3-11103 --- phpBB/includes/functions_posting.php | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'phpBB/includes/functions_posting.php') diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index 3658757e5e..4deffe653b 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -2233,19 +2233,19 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u { switch ($mode) { - case 'post' : + case 'post': $phpbb_notifications->add_notifications(array('quote', 'topic'), $notification_data); break; - case 'reply' : - case 'quote' : + case 'reply': + case 'quote': $phpbb_notifications->add_notifications(array('quote', 'bookmark', 'post'), $notification_data); break; - case 'edit_topic' : - case 'edit_first_post' : - case 'edit' : - case 'edit_last_post' : + case 'edit_topic': + case 'edit_first_post': + case 'edit': + case 'edit_last_post': $phpbb_notifications->update_notifications(array('quote', 'bookmark', 'topic', 'post'), $notification_data); break; } @@ -2254,19 +2254,19 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u { switch ($mode) { - case 'post' : + case 'post': $phpbb_notifications->add_notifications(array('topic_in_queue'), $notification_data); break; - case 'reply' : - case 'quote' : + case 'reply': + case 'quote': $phpbb_notifications->add_notifications(array('post_in_queue'), $notification_data); break; - case 'edit_topic' : - case 'edit_first_post' : - case 'edit' : - case 'edit_last_post' : + case 'edit_topic': + case 'edit_first_post': + case 'edit': + case 'edit_last_post': $phpbb_notifications->delete_notifications('topic', $data['topic_id']); $phpbb_notifications->delete_notifications(array('quote', 'bookmark', 'post'), $data['post_id']); break; -- 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 + 1 file changed, 1 insertion(+) (limited to 'phpBB/includes/functions_posting.php') 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'], -- cgit v1.2.1 From 94d682f77431add84867bb0b196ad0719b293606 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sat, 20 Oct 2012 20:54:18 -0500 Subject: [ticket/11103] Use the full class name as the item_type/method This is going to require you recreate the db tables. PHPBB3-11103 --- phpBB/includes/functions_posting.php | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) (limited to 'phpBB/includes/functions_posting.php') diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index 4deffe653b..02c31eb6cc 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -2234,19 +2234,31 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u switch ($mode) { case 'post': - $phpbb_notifications->add_notifications(array('quote', 'topic'), $notification_data); + $phpbb_notifications->add_notifications(array( + 'phpbb_notification_type_quote', + 'phpbb_notification_type_topic', + ), $notification_data); break; case 'reply': case 'quote': - $phpbb_notifications->add_notifications(array('quote', 'bookmark', 'post'), $notification_data); + $phpbb_notifications->add_notifications(array( + 'phpbb_notification_type_quote', + 'phpbb_notification_type_bookmark', + 'phpbb_notification_type_post', + ), $notification_data); break; case 'edit_topic': case 'edit_first_post': case 'edit': case 'edit_last_post': - $phpbb_notifications->update_notifications(array('quote', 'bookmark', 'topic', 'post'), $notification_data); + $phpbb_notifications->update_notifications(array( + 'phpbb_notification_type_quote', + 'phpbb_notification_type_bookmark', + 'phpbb_notification_type_topic', + 'phpbb_notification_type_post', + ), $notification_data); break; } } @@ -2255,20 +2267,24 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u switch ($mode) { case 'post': - $phpbb_notifications->add_notifications(array('topic_in_queue'), $notification_data); + $phpbb_notifications->add_notifications('phpbb_notification_type_topic_in_queue', $notification_data); break; case 'reply': case 'quote': - $phpbb_notifications->add_notifications(array('post_in_queue'), $notification_data); + $phpbb_notifications->add_notifications('phpbb_notification_type_post_in_queue', $notification_data); break; case 'edit_topic': case 'edit_first_post': case 'edit': case 'edit_last_post': - $phpbb_notifications->delete_notifications('topic', $data['topic_id']); - $phpbb_notifications->delete_notifications(array('quote', 'bookmark', 'post'), $data['post_id']); + $phpbb_notifications->delete_notifications('phpbb_notification_type_topic', $data['topic_id']); + $phpbb_notifications->delete_notifications(array( + 'phpbb_notification_type_quote', + 'phpbb_notification_type_bookmark', + 'phpbb_notification_type_post', + ), $data['post_id']); break; } } -- 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/functions_posting.php | 47 ++++++++++++++++++++++++++++-------- 1 file changed, 37 insertions(+), 10 deletions(-) (limited to 'phpBB/includes/functions_posting.php') 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/functions_posting.php | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'phpBB/includes/functions_posting.php') 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 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 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'phpBB/includes/functions_posting.php') 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); -- 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/functions_posting.php') 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 a811e65147db4d5c98914d201f2e4478f31f64fc Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 29 Oct 2012 18:18:33 -0500 Subject: [ticket/11103] Revert an overwrite that occured on merging from develop PHPBB3-11103 --- phpBB/includes/functions_posting.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'phpBB/includes/functions_posting.php') diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index 02c31eb6cc..4df199d72d 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -296,13 +296,15 @@ function posting_gen_topic_icons($mode, $icon_id) if (sizeof($icons)) { + $root_path = (defined('PHPBB_USE_BOARD_URL_PATH') && PHPBB_USE_BOARD_URL_PATH) ? generate_board_url() . '/' : $phpbb_root_path; + foreach ($icons as $id => $data) { if ($data['display']) { $template->assign_block_vars('topic_icon', array( 'ICON_ID' => $id, - 'ICON_IMG' => $phpbb_root_path . $config['icons_path'] . '/' . $data['img'], + 'ICON_IMG' => $root_path . $config['icons_path'] . '/' . $data['img'], 'ICON_WIDTH' => $data['width'], 'ICON_HEIGHT' => $data['height'], -- 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/functions_posting.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'phpBB/includes/functions_posting.php') 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 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/functions_posting.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'phpBB/includes/functions_posting.php') 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, -- 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/functions_posting.php | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'phpBB/includes/functions_posting.php') 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) { -- cgit v1.2.1 From 2afb8b9df873c3f9572a32ab7a62ea8ba8d8a45b Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Tue, 20 Nov 2012 18:14:48 -0600 Subject: [ticket/11103] Create user loader class, update for DIC Create a very basic user loader class to handle querying/storing user data in a centralized location. Use DIC collection service for notification types/methods. Cleanup unused dependencies. Fix some other issues. PHPBB3-11103 --- phpBB/includes/functions_posting.php | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'phpBB/includes/functions_posting.php') diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index 4df199d72d..8ba1fed6a7 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -2237,17 +2237,17 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u { case 'post': $phpbb_notifications->add_notifications(array( - 'phpbb_notification_type_quote', - 'phpbb_notification_type_topic', + 'quote', + 'topic', ), $notification_data); break; case 'reply': case 'quote': $phpbb_notifications->add_notifications(array( - 'phpbb_notification_type_quote', - 'phpbb_notification_type_bookmark', - 'phpbb_notification_type_post', + 'quote', + 'bookmark', + 'post', ), $notification_data); break; @@ -2256,10 +2256,10 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u case 'edit': case 'edit_last_post': $phpbb_notifications->update_notifications(array( - 'phpbb_notification_type_quote', - 'phpbb_notification_type_bookmark', - 'phpbb_notification_type_topic', - 'phpbb_notification_type_post', + 'quote', + 'bookmark', + 'topic', + 'post', ), $notification_data); break; } @@ -2269,23 +2269,23 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u switch ($mode) { case 'post': - $phpbb_notifications->add_notifications('phpbb_notification_type_topic_in_queue', $notification_data); + $phpbb_notifications->add_notifications('topic_in_queue', $notification_data); break; case 'reply': case 'quote': - $phpbb_notifications->add_notifications('phpbb_notification_type_post_in_queue', $notification_data); + $phpbb_notifications->add_notifications('post_in_queue', $notification_data); break; case 'edit_topic': case 'edit_first_post': case 'edit': case 'edit_last_post': - $phpbb_notifications->delete_notifications('phpbb_notification_type_topic', $data['topic_id']); + $phpbb_notifications->delete_notifications('topic', $data['topic_id']); $phpbb_notifications->delete_notifications(array( - 'phpbb_notification_type_quote', - 'phpbb_notification_type_bookmark', - 'phpbb_notification_type_post', + 'quote', + 'bookmark', + 'post', ), $data['post_id']); break; } -- cgit v1.2.1 From 249f3c8885d461ae3981dfd7b62093c2175175e3 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Thu, 13 Dec 2012 19:19:40 -0600 Subject: [ticket/11103] Instantiate $phpbb_notifications as needed https://github.com/phpbb/phpbb3/pull/992#discussion_r2413976 PHPBB3-11103 --- phpBB/includes/functions_posting.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'phpBB/includes/functions_posting.php') diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index 8ba1fed6a7..1648228af5 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -1410,8 +1410,7 @@ function delete_post($forum_id, $topic_id, $post_id, &$data) */ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $update_message = true, $update_search_index = true) { - global $db, $auth, $user, $config, $phpEx, $template, $phpbb_root_path; - global $phpbb_notifications; + global $db, $auth, $user, $config, $phpEx, $template, $phpbb_root_path, $phpbb_container; // We do not handle erasing posts here if ($mode == 'delete') @@ -2231,6 +2230,8 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u 'post_subject' => $subject, )); + $phpbb_notifications = $phpbb_container->get('notification_manager'); + if ($post_approval) { switch ($mode) @@ -2282,6 +2283,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u case 'edit': case 'edit_last_post': $phpbb_notifications->delete_notifications('topic', $data['topic_id']); + $phpbb_notifications->delete_notifications(array( 'quote', 'bookmark', -- cgit v1.2.1 From 917a2fa9a6cf8b01a347df67fc14d3fc826aa3ed Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Tue, 22 May 2012 02:20:21 +0200 Subject: [ticket/10880] The m_approve permisson no longer implies f_noapprove. PHPBB3-10880 --- phpBB/includes/functions_posting.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'phpBB/includes/functions_posting.php') diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index a1029ab97a..e5cbae0d71 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -1698,8 +1698,9 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u // The variable name should be $post_approved, because it indicates if the post is approved or not $post_approval = 1; - // 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'])) + // Check the permissions for post approval. + // Moderators must go through post approval like ordinary users. + if (!$auth->acl_get('f_noapprove', $data['forum_id'])) { // Post not approved, but in queue $post_approval = 0; -- 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/functions_posting.php') 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 8191755cca418ad2124e11e4e93559b9cad7d8bd Mon Sep 17 00:00:00 2001 From: erangamapa Date: Sat, 25 May 2013 10:50:43 +0530 Subject: [ticket/11145] Wrong error thrown when uploading a bigger image. When attaching an image to a post with a size larger than maximum defined in php.ini, 'ATTACHED_IMAGE_NOT_IMAGE' error is thrown. $file->is_image() is returning false value when image size is too large. Therefore, moved not image test down after image size test. PHPBB3-11145 --- phpBB/includes/functions_posting.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'phpBB/includes/functions_posting.php') diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index e5cbae0d71..2e5130c5b8 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -423,16 +423,6 @@ function upload_attachment($form_name, $forum_id, $local = false, $local_storage $cat_id = (isset($extensions[$file->get('extension')]['display_cat'])) ? $extensions[$file->get('extension')]['display_cat'] : ATTACHMENT_CATEGORY_NONE; - // Make sure the image category only holds valid images... - if ($cat_id == ATTACHMENT_CATEGORY_IMAGE && !$file->is_image()) - { - $file->remove(); - - // If this error occurs a user tried to exploit an IE Bug by renaming extensions - // Since the image category is displaying content inline we need to catch this. - trigger_error($user->lang['ATTACHED_IMAGE_NOT_IMAGE']); - } - // Do we have to create a thumbnail? $filedata['thumbnail'] = ($cat_id == ATTACHMENT_CATEGORY_IMAGE && $config['img_create_thumbnail']) ? 1 : 0; @@ -473,6 +463,16 @@ function upload_attachment($form_name, $forum_id, $local = false, $local_storage return $filedata; } + // Make sure the image category only holds valid images... + if ($cat_id == ATTACHMENT_CATEGORY_IMAGE && !$file->is_image()) + { + $file->remove(); + + // If this error occurs a user tried to exploit an IE Bug by renaming extensions + // Since the image category is displaying content inline we need to catch this. + trigger_error($user->lang['ATTACHED_IMAGE_NOT_IMAGE']); + } + $filedata['filesize'] = $file->get('filesize'); $filedata['mimetype'] = $file->get('mimetype'); $filedata['extension'] = $file->get('extension'); -- cgit v1.2.1 From cb54f56c3db0bedefaa76113f7491203962004ed Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Mon, 4 Mar 2013 02:39:44 +0100 Subject: [ticket/11586] Combine administrator/moderator checks together. PHPBB3-11586 --- phpBB/includes/functions_posting.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'phpBB/includes/functions_posting.php') diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index e823f8be75..8b4a833d8e 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -434,15 +434,15 @@ function upload_attachment($form_name, $forum_id, $local = false, $local_storage // Do we have to create a thumbnail? $filedata['thumbnail'] = ($cat_id == ATTACHMENT_CATEGORY_IMAGE && $config['img_create_thumbnail']) ? 1 : 0; - // Check Image Size, if it is an image - if (!$auth->acl_get('a_') && !$auth->acl_get('m_', $forum_id) && $cat_id == ATTACHMENT_CATEGORY_IMAGE) - { - $file->upload->set_allowed_dimensions(0, 0, $config['img_max_width'], $config['img_max_height']); - } - - // Admins and mods are allowed to exceed the allowed filesize if (!$auth->acl_get('a_') && !$auth->acl_get('m_', $forum_id)) { + // Check Image Size, if it is an image + if ($cat_id == ATTACHMENT_CATEGORY_IMAGE) + { + $file->upload->set_allowed_dimensions(0, 0, $config['img_max_width'], $config['img_max_height']); + } + + // Admins and mods are allowed to exceed the allowed filesize if (!empty($extensions[$file->get('extension')]['max_filesize'])) { $allowed_filesize = $extensions[$file->get('extension')]['max_filesize']; -- cgit v1.2.1 From 11c80c040243244757ea75ef4ab23a70a725254f Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Mon, 4 Mar 2013 02:43:48 +0100 Subject: [ticket/11586] Use a variable for $cat_id == ATTACHMENT_CATEGORY_IMAGE. PHPBB3-11586 --- phpBB/includes/functions_posting.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'phpBB/includes/functions_posting.php') diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index 8b4a833d8e..a31d3b5a3f 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -429,15 +429,16 @@ function upload_attachment($form_name, $forum_id, $local = false, $local_storage return $filedata; } - $cat_id = (isset($extensions[$file->get('extension')]['display_cat'])) ? $extensions[$file->get('extension')]['display_cat'] : ATTACHMENT_CATEGORY_NONE; + // Whether the uploaded file is in the image category + $is_image = (isset($extensions[$file->get('extension')]['display_cat'])) ? $extensions[$file->get('extension')]['display_cat'] == ATTACHMENT_CATEGORY_IMAGE : false; // Do we have to create a thumbnail? - $filedata['thumbnail'] = ($cat_id == ATTACHMENT_CATEGORY_IMAGE && $config['img_create_thumbnail']) ? 1 : 0; + $filedata['thumbnail'] = ($is_image && $config['img_create_thumbnail']) ? 1 : 0; if (!$auth->acl_get('a_') && !$auth->acl_get('m_', $forum_id)) { // Check Image Size, if it is an image - if ($cat_id == ATTACHMENT_CATEGORY_IMAGE) + if ($is_image) { $file->upload->set_allowed_dimensions(0, 0, $config['img_max_width'], $config['img_max_height']); } @@ -457,10 +458,9 @@ function upload_attachment($form_name, $forum_id, $local = false, $local_storage $file->clean_filename('unique', $user->data['user_id'] . '_'); - // Are we uploading an image *and* this image being within the image category? Only then perform additional image checks. - $no_image = ($cat_id == ATTACHMENT_CATEGORY_IMAGE) ? false : true; - - $file->move_file($config['upload_path'], false, $no_image); + // Are we uploading an image *and* this image being within the image category? + // Only then perform additional image checks. + $file->move_file($config['upload_path'], false, !$is_image); if (sizeof($file->error)) { @@ -472,7 +472,7 @@ function upload_attachment($form_name, $forum_id, $local = false, $local_storage } // Make sure the image category only holds valid images... - if ($cat_id == ATTACHMENT_CATEGORY_IMAGE && !$file->is_image()) + if ($is_image && !$file->is_image()) { $file->remove(); -- cgit v1.2.1 From 50e3173e8c2f8304ad79e228df8526f9caf7b999 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Mon, 4 Mar 2013 02:46:12 +0100 Subject: [ticket/11586] Combine $filedata['post_attach'] assign into a single statement. PHPBB3-11586 --- phpBB/includes/functions_posting.php | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) (limited to 'phpBB/includes/functions_posting.php') diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index a31d3b5a3f..d6f7c9bab4 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -403,14 +403,7 @@ function upload_attachment($form_name, $forum_id, $local = false, $local_storage $upload->set_disallowed_content(explode('|', $config['mime_triggers'])); } - if (!$local) - { - $filedata['post_attach'] = ($upload->is_valid($form_name)) ? true : false; - } - else - { - $filedata['post_attach'] = true; - } + $filedata['post_attach'] = $local || $upload->is_valid($form_name); if (!$filedata['post_attach']) { -- cgit v1.2.1 From 5fa25880e23f1ad72321da2e04c574d99f5546a2 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Mon, 4 Mar 2013 02:49:48 +0100 Subject: [ticket/11586] Move $filedata['thumbnail'] to where it might be returned. PHPBB3-11586 --- phpBB/includes/functions_posting.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'phpBB/includes/functions_posting.php') diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index d6f7c9bab4..b9b518ad32 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -425,9 +425,6 @@ function upload_attachment($form_name, $forum_id, $local = false, $local_storage // Whether the uploaded file is in the image category $is_image = (isset($extensions[$file->get('extension')]['display_cat'])) ? $extensions[$file->get('extension')]['display_cat'] == ATTACHMENT_CATEGORY_IMAGE : false; - // Do we have to create a thumbnail? - $filedata['thumbnail'] = ($is_image && $config['img_create_thumbnail']) ? 1 : 0; - if (!$auth->acl_get('a_') && !$auth->acl_get('m_', $forum_id)) { // Check Image Size, if it is an image @@ -455,6 +452,9 @@ function upload_attachment($form_name, $forum_id, $local = false, $local_storage // Only then perform additional image checks. $file->move_file($config['upload_path'], false, !$is_image); + // Do we have to create a thumbnail? + $filedata['thumbnail'] = ($is_image && $config['img_create_thumbnail']) ? 1 : 0; + if (sizeof($file->error)) { $file->remove(); -- 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/functions_posting.php | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'phpBB/includes/functions_posting.php') 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'])) { -- cgit v1.2.1 From f96f2a9e23b41106c6a8ed71ad3538141c648c2f Mon Sep 17 00:00:00 2001 From: Bruno Ais Date: Mon, 15 Jul 2013 20:06:54 +0100 Subject: [ticket/11639] generate_text_for_display on functions_posting.php sub-task of ticket PHPBB3-11635: find and fix all bypasses of generate_text_for_* PHPBB3-11639 --- phpBB/includes/functions_posting.php | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'phpBB/includes/functions_posting.php') diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index b9b518ad32..d277ef06a3 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -1104,14 +1104,12 @@ function topic_review($topic_id, $forum_id, $mode = 'topic_review', $cur_post_id $decoded_message = bbcode_nl2br($decoded_message); } - - if ($row['bbcode_bitfield']) - { - $bbcode->bbcode_second_pass($message, $row['bbcode_uid'], $row['bbcode_bitfield']); - } - - $message = bbcode_nl2br($message); - $message = smiley_text($message, !$row['enable_smilies']); + $parse_flags = ($row['bbcode_bitfield'] ? OPTION_FLAG_BBCODE : 0); + $parse_flags |= ($row['enable_smilies'] ? OPTION_FLAG_SMILIES : 0); + + $message = generate_text_for_display($message, $row['bbcode_uid'], $row['bbcode_bitfield'], $parse_flags , false); + + unset($parse_flags); if (!empty($attachments[$row['post_id']])) { -- cgit v1.2.1 From dde9a1fb27e6db3c1b4cd41d8848496a3ef8d363 Mon Sep 17 00:00:00 2001 From: Bruno Ais Date: Mon, 15 Jul 2013 20:08:17 +0100 Subject: [ticket/11639] Added an useful comment. sub-task of ticket PHPBB3-11635: find and fix all bypasses of generate_text_for_* PHPBB3-11639 --- phpBB/includes/functions_posting.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'phpBB/includes/functions_posting.php') diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index d277ef06a3..49fbe92256 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -1104,9 +1104,10 @@ function topic_review($topic_id, $forum_id, $mode = 'topic_review', $cur_post_id $decoded_message = bbcode_nl2br($decoded_message); } + $parse_flags = ($row['bbcode_bitfield'] ? OPTION_FLAG_BBCODE : 0); $parse_flags |= ($row['enable_smilies'] ? OPTION_FLAG_SMILIES : 0); - + // Do not censor text because it has already been censored before $message = generate_text_for_display($message, $row['bbcode_uid'], $row['bbcode_bitfield'], $parse_flags , false); unset($parse_flags); -- cgit v1.2.1 From 5f19ca6a6f3ad6641954c58c44ef0c94d1609e5a Mon Sep 17 00:00:00 2001 From: Bruno Ais Date: Mon, 15 Jul 2013 20:09:59 +0100 Subject: [ticket/11639] Whitespace fixing sub-task of ticket PHPBB3-11635: find and fix all bypasses of generate_text_for_* PHPBB3-11639 --- phpBB/includes/functions_posting.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/includes/functions_posting.php') diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index 49fbe92256..ad75ed1079 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -1104,12 +1104,12 @@ function topic_review($topic_id, $forum_id, $mode = 'topic_review', $cur_post_id $decoded_message = bbcode_nl2br($decoded_message); } - + $parse_flags = ($row['bbcode_bitfield'] ? OPTION_FLAG_BBCODE : 0); $parse_flags |= ($row['enable_smilies'] ? OPTION_FLAG_SMILIES : 0); // Do not censor text because it has already been censored before $message = generate_text_for_display($message, $row['bbcode_uid'], $row['bbcode_bitfield'], $parse_flags , false); - + unset($parse_flags); if (!empty($attachments[$row['post_id']])) -- cgit v1.2.1 From 0ef1bcac2b3152bbf389b512fd373987a7d0edce Mon Sep 17 00:00:00 2001 From: Bruno Ais Date: Sat, 20 Jul 2013 16:31:08 +0100 Subject: [ticket/11639] Whitespace fixing sub-task of ticket PHPBB3-11635: find and fix all bypasses of generate_text_for_* PHPBB3-11639 --- phpBB/includes/functions_posting.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes/functions_posting.php') diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index ad75ed1079..49a1797321 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -1108,7 +1108,7 @@ function topic_review($topic_id, $forum_id, $mode = 'topic_review', $cur_post_id $parse_flags = ($row['bbcode_bitfield'] ? OPTION_FLAG_BBCODE : 0); $parse_flags |= ($row['enable_smilies'] ? OPTION_FLAG_SMILIES : 0); // Do not censor text because it has already been censored before - $message = generate_text_for_display($message, $row['bbcode_uid'], $row['bbcode_bitfield'], $parse_flags , false); + $message = generate_text_for_display($message, $row['bbcode_uid'], $row['bbcode_bitfield'], $parse_flags, false); unset($parse_flags); -- cgit v1.2.1 From 603dc1f78617e64e41f61daf85f463b0465123ec Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sat, 20 Jul 2013 15:09:28 +0200 Subject: [ticket/11717] Use topic_posts_approved instead of topic_replies Due to the move to soft-delete, the topic_replies column no longer exists in the topics table. Instead, the column topic_posts_approved should be used. PHPBB3-11717 --- phpBB/includes/functions_posting.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'phpBB/includes/functions_posting.php') diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index 03565c27bb..f80736a6c4 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -1995,6 +1995,9 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u } } + $first_post_topic_info = ($post_mode == 'edit_first_post' && (($post_visibility == ITEM_DELETED && $data['topic_posts_softdeleted'] == 1) || + ($post_visibility == ITEM_UNAPPROVED && $data['topic_posts_unapproved'] == 1) || + ($post_visibility == ITEM_APPROVED && $data['topic_posts_approved'] == 1))); // 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) { @@ -2007,7 +2010,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u $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'])) + else if ($post_mode == 'edit_last_post' || $post_mode == 'edit_topic' || $first_post_topic_info) { if ($post_visibility == ITEM_APPROVED || $data['topic_visibility'] == $post_visibility) { -- cgit v1.2.1 From effafa4b4d82e8f0debcda2e84e03117433e5a7d Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Mon, 22 Jul 2013 10:42:46 +0200 Subject: [ticket/11717] Add 'has' to boolean variable and reduce line length PHPBB3-11717 --- phpBB/includes/functions_posting.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'phpBB/includes/functions_posting.php') diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index f80736a6c4..103cc81205 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -1995,9 +1995,10 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u } } - $first_post_topic_info = ($post_mode == 'edit_first_post' && (($post_visibility == ITEM_DELETED && $data['topic_posts_softdeleted'] == 1) || - ($post_visibility == ITEM_UNAPPROVED && $data['topic_posts_unapproved'] == 1) || - ($post_visibility == ITEM_APPROVED && $data['topic_posts_approved'] == 1))); + $first_post_has_topic_info = ($post_mode == 'edit_first_post' && + (($post_visibility == ITEM_DELETED && $data['topic_posts_softdeleted'] == 1) || + ($post_visibility == ITEM_UNAPPROVED && $data['topic_posts_unapproved'] == 1) || + ($post_visibility == ITEM_APPROVED && $data['topic_posts_approved'] == 1))); // 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) { @@ -2010,7 +2011,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u $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' || $first_post_topic_info) + else if ($post_mode == 'edit_last_post' || $post_mode == 'edit_topic' || $first_post_has_topic_info) { if ($post_visibility == ITEM_APPROVED || $data['topic_visibility'] == $post_visibility) { -- cgit v1.2.1 From 1372b4f20801d6079798832f15caf38949fe9333 Mon Sep 17 00:00:00 2001 From: Bruno Ais Date: Wed, 24 Jul 2013 10:33:06 +0100 Subject: [ticket/11639] Removed a non-needed unset sub-task of ticket PHPBB3-11635: find and fix all bypasses of generate_text_for_* PHPBB3-11639 --- phpBB/includes/functions_posting.php | 2 -- 1 file changed, 2 deletions(-) (limited to 'phpBB/includes/functions_posting.php') diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index 49a1797321..acf0cc874b 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -1110,8 +1110,6 @@ function topic_review($topic_id, $forum_id, $mode = 'topic_review', $cur_post_id // Do not censor text because it has already been censored before $message = generate_text_for_display($message, $row['bbcode_uid'], $row['bbcode_bitfield'], $parse_flags, false); - unset($parse_flags); - if (!empty($attachments[$row['post_id']])) { $update_count = array(); -- cgit v1.2.1 From 28a0a9e0b1cf77f1be64934f98e4c607d6098362 Mon Sep 17 00:00:00 2001 From: brunoais Date: Sat, 3 Aug 2013 21:46:06 +0100 Subject: [ticket/11639] Changing how censorship is handled. sub-task of ticket PHPBB3-11635: find and fix all bypasses of generate_text_for_* PHPBB3-11639 --- phpBB/includes/functions_posting.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'phpBB/includes/functions_posting.php') diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index acf0cc874b..c528d36fef 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -1093,13 +1093,12 @@ function topic_review($topic_id, $forum_id, $mode = 'topic_review', $cur_post_id $poster_id = $row['user_id']; $post_subject = $row['post_subject']; - $message = censor_text($row['post_text']); $decoded_message = false; if ($show_quote_button && $auth->acl_get('f_reply', $forum_id)) { - $decoded_message = $message; + $decoded_message = censor_text($row['post_text']); decode_message($decoded_message, $row['bbcode_uid']); $decoded_message = bbcode_nl2br($decoded_message); @@ -1107,8 +1106,7 @@ function topic_review($topic_id, $forum_id, $mode = 'topic_review', $cur_post_id $parse_flags = ($row['bbcode_bitfield'] ? OPTION_FLAG_BBCODE : 0); $parse_flags |= ($row['enable_smilies'] ? OPTION_FLAG_SMILIES : 0); - // Do not censor text because it has already been censored before - $message = generate_text_for_display($message, $row['bbcode_uid'], $row['bbcode_bitfield'], $parse_flags, false); + $message = generate_text_for_display($row['post_text'], $row['bbcode_uid'], $row['bbcode_bitfield'], $parse_flags, true); if (!empty($attachments[$row['post_id']])) { -- cgit v1.2.1 From 2845b153d8e86b80c6b9a8c0869474affb277516 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 23 Aug 2013 22:52:33 +0200 Subject: [ticket/11769] Correctly supply the post author's username in posting.php Only supply the username, when it is a guest posting or we edit and it was supplied, otherwise post_data might hold data of the post we quote, in which case username is the original poster, not the current one. PHPBB3-11769 --- phpBB/includes/functions_posting.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'phpBB/includes/functions_posting.php') diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index 2e5130c5b8..aff7129fce 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -2604,7 +2604,10 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u // Send Notifications if (($mode == 'reply' || $mode == 'quote' || $mode == 'post') && $post_approval) { - $username = ($username) ? $username : $user->data['username']; + // If a username was supplied or the poster is a guest, we use the supplied username. + // This way we will use "...post by guest-username..." in notifications, + // when guest-username was supplied and ommit the username-part otherwise. + $username = ($username || !$user->data['is_registered']) ? $username : $user->data['username']; user_notification($mode, $subject, $data['topic_title'], $data['forum_name'], $data['forum_id'], $data['topic_id'], $data['post_id'], $username); } -- cgit v1.2.1 From d717203af1263e552886251fbee9b718be45f623 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 23 Aug 2013 23:49:11 +0200 Subject: [ticket/11769] Fix language issues in the doc blocks PHPBB3-11769 --- phpBB/includes/functions_posting.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'phpBB/includes/functions_posting.php') diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index aff7129fce..32206df868 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -2604,9 +2604,9 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u // Send Notifications if (($mode == 'reply' || $mode == 'quote' || $mode == 'post') && $post_approval) { - // If a username was supplied or the poster is a guest, we use the supplied username. - // This way we will use "...post by guest-username..." in notifications, - // when guest-username was supplied and ommit the username-part otherwise. + // If a username was supplied or the poster is a guest, we will use the supplied username. + // Doing it this way we can use "...post by guest-username..." in notifications when + // "guest-username" is supplied or ommit the username if it is not. $username = ($username || !$user->data['is_registered']) ? $username : $user->data['username']; user_notification($mode, $subject, $data['topic_title'], $data['forum_name'], $data['forum_id'], $data['topic_id'], $data['post_id'], $username); } -- cgit v1.2.1 From 42b9c3c479a28ba74c214676a17e7e783150e227 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 2 Sep 2013 01:11:40 +0200 Subject: [ticket/11769] Allow '0' as username PHPBB3-11769 --- phpBB/includes/functions_posting.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes/functions_posting.php') diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index 32206df868..11a5067ef9 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -2607,7 +2607,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u // If a username was supplied or the poster is a guest, we will use the supplied username. // Doing it this way we can use "...post by guest-username..." in notifications when // "guest-username" is supplied or ommit the username if it is not. - $username = ($username || !$user->data['is_registered']) ? $username : $user->data['username']; + $username = ($username !== '' || !$user->data['is_registered']) ? $username : $user->data['username']; user_notification($mode, $subject, $data['topic_title'], $data['forum_name'], $data['forum_id'], $data['topic_id'], $data['post_id'], $username); } -- cgit v1.2.1