Index: includes/functions_posting.php =================================================================== --- includes/functions_posting.php (revision 9753) +++ includes/functions_posting.php (working copy) @@ -1610,7 +1610,7 @@ $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 (!isset($data['post_approved']) || !isset($data['topic_approved']) || $data['post_approved'] === false || $data['topic_approved'] === false) { $sql = 'SELECT p.post_approved, t.topic_type, t.topic_replies, t.topic_replies_real, t.topic_approved FROM ' . TOPICS_TABLE . ' t, ' . POSTS_TABLE . ' p @@ -1624,6 +1624,9 @@ $data['post_approved'] = $topic_row['post_approved']; } + // This variable indicates if the forum stats must be updated + $forum_stats = ($data['topic_approved'] || $data['post_approved']) ? true : false; + // 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 $post_approval = 1; @@ -1784,7 +1787,7 @@ if ($topic_type != POST_GLOBAL) { - if ($post_approval) + if ($forum_stats) { $sql_data[FORUMS_TABLE]['stat'][] = 'forum_posts = forum_posts + 1'; } @@ -1802,7 +1805,7 @@ $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' : ''); - if ($post_approval && $topic_type != POST_GLOBAL) + if ($forum_stats && $topic_type != POST_GLOBAL) { $sql_data[FORUMS_TABLE]['stat'][] = 'forum_posts = forum_posts + 1'; } @@ -1844,7 +1847,7 @@ ); // 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 (!$forum_stats) { // Do we need to grab some topic informations? if (!sizeof($topic_row)) @@ -1880,7 +1883,7 @@ 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 (!$forum_stats) { $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'; @@ -2160,7 +2163,7 @@ // we need to update the last forum information // only applicable if the topic is not global and it is approved // we also check to make sure we are not dealing with globaling the latest topic (pretty rare but still needs to be checked) - if ($topic_type != POST_GLOBAL && !$make_global && ($post_approved || !$data['post_approved'])) + if ($topic_type != POST_GLOBAL && !$make_global && $forum_stats) { // the last post makes us update the forum table. This can happen if... // We make a new topic @@ -2325,7 +2328,7 @@ // topic sync time! // simply, we update if it is a reply or the last post is edited - if ($post_approved) + if ($forum_stats) { // reply requires the whole thing if ($post_mode == 'reply') @@ -2349,7 +2352,7 @@ } } } - else if (!$data['post_approved'] && ($post_mode == 'edit_last_post' || $post_mode == 'edit_topic' || ($post_mode == 'edit_first_post' && !$data['topic_replies']))) + else if (!$forum_stats && ($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 @@ -2382,7 +2385,7 @@ } // Update total post count, do not consider moderated posts/topics - if ($post_approval) + if ($forum_stats) { if ($post_mode == 'post') {