/** * Post a comment on an artist, request or torrent page. * @param string $Page * @param int $PageID * @param string $Body * @return int ID of the new comment */ public static function post($Page, $PageID, $Body) { $QueryID = G::$DB->get_query_id(); G::$DB->query("\n\t\t\tSELECT\n\t\t\t\tCEIL(\n\t\t\t\t\t(\n\t\t\t\t\t\tSELECT COUNT(ID) + 1\n\t\t\t\t\t\tFROM comments\n\t\t\t\t\t\tWHERE Page = '{$Page}'\n\t\t\t\t\t\t\tAND PageID = {$PageID}\n\t\t\t\t\t) / " . TORRENT_COMMENTS_PER_PAGE . "\n\t\t\t\t) AS Pages"); list($Pages) = G::$DB->next_record(); G::$DB->query("\n\t\t\tINSERT INTO comments (Page, PageID, AuthorID, AddedTime, Body)\n\t\t\tVALUES ('{$Page}', {$PageID}, " . G::$LoggedUser['ID'] . ", '" . sqltime() . "', '" . db_string($Body) . "')"); $PostID = G::$DB->inserted_id(); $CatalogueID = floor((TORRENT_COMMENTS_PER_PAGE * $Pages - TORRENT_COMMENTS_PER_PAGE) / THREAD_CATALOGUE); G::$Cache->delete_value($Page . '_comments_' . $PageID . '_catalogue_' . $CatalogueID); G::$Cache->delete_value($Page . '_comments_' . $PageID); Subscriptions::flush_subscriptions($Page, $PageID); Subscriptions::quote_notify($Body, $PostID, $Page, $PageID); G::$DB->set_query_id($QueryID); return $PostID; }
//Merge it } else { $Forum = $Part1 + $Part2 + $Part3; //Merge it } $Cache->cache_value("forums_{$ForumID}", array($Forum, '', 0, $Stickies), 0); //Update the forum root $Cache->begin_transaction('forums_list'); $Cache->update_row($ForumID, array('NumPosts' => '+1', 'LastPostID' => $PostID, 'LastPostAuthorID' => $LoggedUser['ID'], 'LastPostTopicID' => $TopicID, 'LastPostTime' => $SQLTime, 'Title' => $ThreadInfo['Title'], 'IsLocked' => $ThreadInfo['IsLocked'], 'IsSticky' => $ThreadInfo['IsSticky'])); $Cache->commit_transaction(0); } else { //If there's no cache, we have no data, and if there's no data $Cache->delete_value('forums_list'); } //This calculates the block of 500 posts that this one will fall under $CatalogueID = floor((POSTS_PER_PAGE * ceil($ThreadInfo['Posts'] / POSTS_PER_PAGE) - POSTS_PER_PAGE) / THREAD_CATALOGUE); //Insert the post into the thread catalogue (block of 500 posts) $Cache->begin_transaction("thread_{$TopicID}" . "_catalogue_{$CatalogueID}"); $Cache->insert('', array('ID' => $PostID, 'AuthorID' => $LoggedUser['ID'], 'AddedTime' => $SQLTime, 'Body' => $Body, 'EditedUserID' => 0, 'EditedTime' => '0000-00-00 00:00:00', 'Username' => $LoggedUser['Username'])); $Cache->commit_transaction(0); //Update the thread info $Cache->begin_transaction("thread_{$TopicID}" . '_info'); $Cache->update_row(false, array('Posts' => '+1', 'LastPostAuthorID' => $LoggedUser['ID'])); $Cache->commit_transaction(0); //Increment this now to make sure we redirect to the correct page $ThreadInfo['Posts']++; } Subscriptions::flush_subscriptions('forums', $TopicID); Subscriptions::quote_notify($Body, $PostID, 'forums', $TopicID); header("Location: forums.php?action=viewthread&threadid={$TopicID}&page=" . ceil($ThreadInfo['Posts'] / $PerPage)); die;