2011-03-28 14:21:28 +00:00
|
|
|
<?
|
|
|
|
authorize();
|
|
|
|
// Quick SQL injection check
|
2013-05-05 08:00:31 +00:00
|
|
|
if (!isset($_GET['postid']) || !is_number($_GET['postid'])) {
|
|
|
|
error(0);
|
|
|
|
}
|
2011-03-28 14:21:28 +00:00
|
|
|
$PostID = $_GET['postid'];
|
|
|
|
|
|
|
|
// Make sure they are moderators
|
2013-05-05 08:00:31 +00:00
|
|
|
if (!check_perms('site_admin_forums')) {
|
2011-03-28 14:21:28 +00:00
|
|
|
error(403);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get topicid, forumid, number of pages
|
2013-05-05 08:00:31 +00:00
|
|
|
$DB->query("
|
|
|
|
SELECT
|
|
|
|
TopicID,
|
|
|
|
ForumID,
|
2013-07-10 00:08:53 +00:00
|
|
|
CEIL(COUNT(p.ID) / ".POSTS_PER_PAGE.") AS Pages,
|
|
|
|
CEIL(SUM(IF(p.ID <= '$PostID', 1, 0)) / ".POSTS_PER_PAGE.") AS Page,
|
2013-05-05 08:00:31 +00:00
|
|
|
StickyPostID
|
2011-03-28 14:21:28 +00:00
|
|
|
FROM forums_posts AS p
|
2013-07-10 00:08:53 +00:00
|
|
|
JOIN forums_topics AS t ON t.ID = p.TopicID
|
|
|
|
WHERE p.TopicID = (
|
2013-05-05 08:00:31 +00:00
|
|
|
SELECT TopicID
|
|
|
|
FROM forums_posts
|
2013-07-10 00:08:53 +00:00
|
|
|
WHERE ID = '$PostID'
|
2013-05-05 08:00:31 +00:00
|
|
|
)
|
2012-05-18 13:35:17 +00:00
|
|
|
GROUP BY t.ID");
|
2012-06-08 08:00:23 +00:00
|
|
|
list($TopicID, $ForumID, $Pages, $Page, $StickyPostID) = $DB->next_record();
|
2011-03-28 14:21:28 +00:00
|
|
|
|
|
|
|
// $Pages = number of pages in the thread
|
|
|
|
// $Page = which page the post is on
|
|
|
|
// These are set for cache clearing.
|
|
|
|
|
2013-07-10 00:08:53 +00:00
|
|
|
$DB->query("
|
|
|
|
DELETE FROM forums_posts
|
|
|
|
WHERE ID = '$PostID'");
|
2011-03-28 14:21:28 +00:00
|
|
|
|
2013-07-10 00:08:53 +00:00
|
|
|
$DB->query("
|
|
|
|
SELECT MAX(ID)
|
|
|
|
FROM forums_posts
|
|
|
|
WHERE TopicID = '$TopicID'");
|
2011-03-28 14:21:28 +00:00
|
|
|
list($LastID) = $DB->next_record();
|
2013-05-05 08:00:31 +00:00
|
|
|
$DB->query("
|
|
|
|
UPDATE forums AS f, forums_topics AS t
|
2013-07-10 00:08:53 +00:00
|
|
|
SET f.NumPosts = f.NumPosts - 1, t.NumPosts = t.NumPosts - 1
|
|
|
|
WHERE f.ID = '$ForumID'
|
|
|
|
AND t.ID = '$TopicID'");
|
2011-03-28 14:21:28 +00:00
|
|
|
|
2013-05-05 08:00:31 +00:00
|
|
|
if ($LastID < $PostID) { // Last post in a topic was removed
|
|
|
|
$DB->query("
|
|
|
|
SELECT p.AuthorID, u.Username, p.AddedTime
|
|
|
|
FROM forums_posts AS p
|
|
|
|
LEFT JOIN users_main AS u ON u.ID = p.AuthorID
|
2013-07-10 00:08:53 +00:00
|
|
|
WHERE p.ID = '$LastID'");
|
2011-03-28 14:21:28 +00:00
|
|
|
list($LastAuthorID, $LastAuthorName, $LastTime) = $DB->next_record();
|
2013-05-05 08:00:31 +00:00
|
|
|
$DB->query("
|
|
|
|
UPDATE forums_topics
|
|
|
|
SET
|
2013-07-10 00:08:53 +00:00
|
|
|
LastPostID = '$LastID',
|
|
|
|
LastPostAuthorID = '$LastAuthorID',
|
|
|
|
LastPostTime = '$LastTime'
|
|
|
|
WHERE ID = '$TopicID'");
|
2013-05-05 08:00:31 +00:00
|
|
|
$DB->query("
|
|
|
|
SELECT
|
|
|
|
t.ID,
|
|
|
|
t.Title,
|
|
|
|
t.LastPostID,
|
|
|
|
t.LastPostTime,
|
|
|
|
t.LastPostAuthorID,
|
|
|
|
u.Username
|
2011-03-28 14:21:28 +00:00
|
|
|
FROM forums_topics AS t
|
2013-05-05 08:00:31 +00:00
|
|
|
LEFT JOIN users_main AS u ON u.ID = t.LastPostAuthorID
|
2013-07-10 00:08:53 +00:00
|
|
|
WHERE ForumID = '$ForumID'
|
2013-05-27 08:00:58 +00:00
|
|
|
AND t.ID != '$TopicID'
|
2013-05-05 08:00:31 +00:00
|
|
|
ORDER BY LastPostID DESC
|
|
|
|
LIMIT 1");
|
2011-03-28 14:21:28 +00:00
|
|
|
list($LastTopicID, $LastTopicTitle, $LastTopicPostID, $LastTopicPostTime, $LastTopicAuthorID, $LastTopicAuthorName) = $DB->next_record(MYSQLI_BOTH, false);
|
|
|
|
|
2013-05-05 08:00:31 +00:00
|
|
|
if ($LastID < $LastTopicPostID) { // Topic is no longer the most recent in its forum
|
|
|
|
$DB->query("
|
|
|
|
UPDATE forums
|
|
|
|
SET
|
2013-07-10 00:08:53 +00:00
|
|
|
LastPostTopicID = '$LastTopicID',
|
|
|
|
LastPostID = '$LastTopicPostID',
|
|
|
|
LastPostAuthorID = '$LastTopicAuthorID',
|
|
|
|
LastPostTime = '$LastTopicPostTime'
|
|
|
|
WHERE ID = '$ForumID'
|
|
|
|
AND LastPostTopicID = '$TopicID'");
|
2011-03-28 14:21:28 +00:00
|
|
|
$UpdateArrayForums = array(
|
|
|
|
'NumPosts' => '-1',
|
|
|
|
'LastPostID' => $LastTopicPostID,
|
|
|
|
'LastPostAuthorID' => $LastTopicAuthorID,
|
|
|
|
'LastPostTime' => $LastTopicPostTime,
|
|
|
|
'LastPostTopicID' => $LastTopicID,
|
|
|
|
'Title' => $LastTopicTitle);
|
|
|
|
} else { // Topic is still the most recent in its forum
|
2013-05-05 08:00:31 +00:00
|
|
|
$DB->query("
|
|
|
|
UPDATE forums
|
|
|
|
SET
|
2013-07-10 00:08:53 +00:00
|
|
|
LastPostID = '$LastID',
|
|
|
|
LastPostAuthorID = '$LastAuthorID',
|
|
|
|
LastPostTime = '$LastTime'
|
|
|
|
WHERE ID = '$ForumID'
|
|
|
|
AND LastPostTopicID = '$TopicID'");
|
2011-03-28 14:21:28 +00:00
|
|
|
$UpdateArrayForums = array(
|
|
|
|
'NumPosts' => '-1',
|
|
|
|
'LastPostID' => $LastID,
|
|
|
|
'LastPostAuthorID' => $LastAuthorID,
|
|
|
|
'LastPostTime' => $LastTime);
|
|
|
|
}
|
|
|
|
$UpdateArrayThread = array('Posts' => '-1', 'LastPostAuthorID' => $LastAuthorID);
|
|
|
|
} else {
|
|
|
|
$UpdateArrayForums = array('NumPosts' => '-1');
|
|
|
|
$UpdateArrayThread = array('Posts' => '-1');
|
|
|
|
}
|
|
|
|
|
2013-05-05 08:00:31 +00:00
|
|
|
if ($StickyPostID == $PostID) {
|
2013-06-04 08:00:34 +00:00
|
|
|
$DB->query("
|
|
|
|
UPDATE forums_topics
|
|
|
|
SET StickyPostID = 0
|
|
|
|
WHERE ID = $TopicID");
|
2012-06-08 08:00:23 +00:00
|
|
|
}
|
|
|
|
|
2011-03-28 14:21:28 +00:00
|
|
|
//We need to clear all subsequential catalogues as they've all been bumped with the absence of this post
|
2013-05-05 08:00:31 +00:00
|
|
|
$ThisCatalogue = floor((POSTS_PER_PAGE * $Page - POSTS_PER_PAGE) / THREAD_CATALOGUE);
|
|
|
|
$LastCatalogue = floor((POSTS_PER_PAGE * $Pages - POSTS_PER_PAGE) / THREAD_CATALOGUE);
|
|
|
|
for ($i = $ThisCatalogue; $i <= $LastCatalogue; $i++) {
|
2013-07-10 00:08:53 +00:00
|
|
|
$Cache->delete_value("thread_$TopicID"."_catalogue_$i");
|
2011-03-28 14:21:28 +00:00
|
|
|
}
|
|
|
|
|
2013-07-10 00:08:53 +00:00
|
|
|
$Cache->begin_transaction("thread_$TopicID".'_info');
|
2011-03-28 14:21:28 +00:00
|
|
|
$Cache->update_row(false, $UpdateArrayThread);
|
|
|
|
$Cache->commit_transaction();
|
|
|
|
|
|
|
|
$Cache->begin_transaction('forums_list');
|
|
|
|
$Cache->update_row($ForumID, $UpdateArrayForums);
|
|
|
|
$Cache->commit_transaction();
|
|
|
|
|
2013-07-10 00:08:53 +00:00
|
|
|
$Cache->delete_value("forums_$ForumID");
|
2013-08-28 23:08:41 +00:00
|
|
|
|
|
|
|
Subscriptions::flush_subscriptions('forums', $TopicID);
|
|
|
|
|
|
|
|
// quote notifications
|
|
|
|
Subscriptions::flush_quote_notifications('forums', $TopicID);
|
|
|
|
$DB->query("DELETE FROM users_notify_quoted WHERE Page = 'forums' AND PostID = '" . $PostID . "'");
|