if (empty($posts)) { message($lang_misc['No posts selected']); } if (isset($_POST['delete_posts_comply'])) { //confirm_referrer('moderate.php'); if (@preg_match('/[^0-9,]/', $posts)) { message($lang_common['Bad request']); } // Verify that the post IDs are valid $result = $db->query('SELECT 1 FROM ' . $db->prefix . 'posts WHERE id IN(' . $posts . ') AND topic_id=' . $tid) or error('Unable to check posts', __FILE__, __LINE__, $db->error()); if ($db->num_rows($result) != substr_count($posts, ',') + 1) { message($lang_common['Bad request']); } //Attachment Mod Block Start foreach (explode(',', $posts) as $value) { attach_delete_post($value); } //Attachment Mod Block End // Delete the posts $db->query('DELETE FROM ' . $db->prefix . 'posts WHERE id IN(' . $posts . ')') or error('Unable to delete posts', __FILE__, __LINE__, $db->error()); require PUN_ROOT . 'include/search_idx.php'; strip_search_index($posts); // Get last_post, last_post_id, and last_poster for the topic after deletion $result = $db->query('SELECT id, poster, posted FROM ' . $db->prefix . 'posts WHERE topic_id=' . $tid . ' ORDER BY id DESC LIMIT 1') or error('Unable to fetch post info', __FILE__, __LINE__, $db->error()); $last_post = $db->fetch_assoc($result); // How many posts did we just delete? $num_posts_deleted = substr_count($posts, ',') + 1; // Update the topic $db->query('UPDATE ' . $db->prefix . 'topics SET last_post=' . $last_post['posted'] . ', last_post_id=' . $last_post['id'] . ', last_poster=\'' . $db->escape($last_post['poster']) . '\', num_replies=num_replies-' . $num_posts_deleted . ' WHERE id=' . $tid) or error('Unable to update topic', __FILE__, __LINE__, $db->error()); update_forum($fid); redirect('viewtopic.php?id=' . $tid, $lang_misc['Delete posts redirect']);
$admins = get_admin_ids(); for ($i = 0; $i < count($admins); $i++) { $data[] = $admins[$i]; $markers[] = '?'; } $sql .= ' AND poster_id NOT IN(' . implode(',', $markers) . ')'; } // Run the SQL $ps = $db->run($sql, $data); if (!$ps->rowCount()) { message($lang_common['Bad request'], false, '404 Not Found'); } else { $deleted_posts = $ps->rowCount(); } foreach ($posts as $id) { attach_delete_post($id); } // Delete the posts if ($panther_config['o_delete_full'] == '1') { $db->run('DELETE FROM ' . $db->prefix . 'posts WHERE id IN(' . implode(',', $placeholders) . ')', $post_data); } else { $db->run('UPDATE ' . $db->prefix . 'posts SET deleted=1 WHERE id IN(' . implode(',', $placeholders) . ')', $post_data); } require PANTHER_ROOT . 'include/search_idx.php'; strip_search_index($posts); $data = array(':id' => $tid); // Get last_post, last_post_id, and last_poster for the topic after deletion $ps = $db->select('posts', 'id, poster, posted', $data, 'topic_id=:id', 'id DESC LIMIT 1'); $last_post = $ps->fetch(); // How many posts did we just delete? $num_replies = $cur_topic['num_replies'] - $deleted_posts;
function delete_post($post_id, $topic_id) { global $db, $panther_config; $topic_data = array(':id' => $topic_id); $post_data = array(':id' => $post_id); $ps = $db->select('posts', 'id, poster, posted', $topic_data, 'topic_id=:id AND approved=1 AND deleted=0', 'id DESC LIMIT 2'); list($last_id, , ) = $ps->fetch(PDO::FETCH_NUM); list($second_last_id, $second_poster, $second_posted) = $ps->fetch(PDO::FETCH_NUM); // Delete the post attach_delete_post($post_id); $update = array('deleted' => 1); $db->update('posts', $update, 'id=:id', $post_data); strip_search_index(array($post_id)); // Count number of replies in the topic $ps = $db->select('posts', 'COUNT(id)', $topic_data, 'topic_id=:id AND approved=1 AND deleted=0'); $num_replies = $ps->fetchColumn() - 1; // Decrement the deleted post // If the message we deleted is the most recent in the topic (at the end of the topic) if ($last_id == $post_id) { // If there is a $second_last_id there is more than 1 reply to the topic if (!empty($second_last_id)) { $update = array('last_post' => $second_posted, 'last_post_id' => $second_last_id, 'last_poster' => $second_poster, 'num_replies' => $num_replies); $data = array(':id' => $topic_id); $db->update('topics', $update, 'id=:id', $data); } else { $data = array(':id' => $topic_id, ':num_replies' => $num_replies - 1); // We deleted the only reply, so now last_post/last_post_id/last_poster is posted/id/poster from the topic itself $db->run('UPDATE ' . $db->prefix . 'topics SET last_post=posted, last_post_id=id, last_poster=poster, num_replies=:num_replies WHERE id=:id', $data); } } else { $update = array('num_replies' => $num_replies); $db->update('topics', $update, 'id=:id', $topic_data); } if ($panther_config['o_delete_full'] == '1') { permanently_delete_post($post_id); } }