コード例 #1
0
ファイル: editpost.php プロジェクト: OvBB/v1.0
function DeletePost($aPostInfo)
{
    global $CFG, $dbConn, $iForumID;
    $iPostID = $aPostInfo['id'];
    $iThreadID = $aPostInfo['parent'];
    $iAuthorID = $aPostInfo['author'];
    // Get the thread's root.
    $dbConn->query("SELECT post.id FROM post LEFT JOIN thread ON (post.parent = thread.id) WHERE thread.id={$iThreadID} ORDER BY post.datetime_posted ASC LIMIT 1");
    list($iRootID) = $dbConn->getresult();
    // Is the post we're about to delete the thread root?
    if ($iRootID == $iPostID) {
        // Yes, get a list of all posts in the thread.
        $dbConn->query("SELECT id, author FROM post WHERE parent={$iThreadID}");
        while (list($iPID, $iAuthorID) = $dbConn->getresult()) {
            // Save the post in the list to delete.
            $aPostList[] = $iPID;
            // Increment the author's postcount of this thread.
            $aPostCounts[$iAuthorID]++;
        }
        $strPostIDs = implode(', ', $aPostList);
        // Subtract from the users' postcounts the number of posts they had in the thread.
        foreach ($aPostCounts as $iAuthorID => $iPostCount) {
            $dbConn->query("UPDATE citizen SET postcount=postcount-{$iPostCount} WHERE id={$iAuthorID}");
        }
        // Delete the posts' records, the thread's record, any attachments, and any poll.
        $dbConn->query("DELETE FROM post WHERE parent={$iThreadID}");
        $dbConn->query("DELETE FROM thread WHERE id={$iThreadID}");
        $dbConn->query("DELETE FROM attachment WHERE parent IN ({$strPostIDs})");
        $dbConn->query("DELETE FROM poll WHERE id={$iThreadID}");
        $dbConn->query("DELETE FROM pollvote WHERE parent={$iThreadID}");
        // Delete all search indexes for the posts.
        $dbConn->query("DELETE FROM searchindex WHERE postid IN ({$strPostIDs})");
        // Get the total number of posts we've deleted.
        $iPostCount = count($aPostList);
        // Update the forum's post and thread counts.
        $dbConn->query("UPDATE board SET postcount=postcount-{$iPostCount}, threadcount=threadcount-1 WHERE id={$iForumID}");
        // Update the forum stats.
        $dbConn->query("UPDATE stats SET content=content-{$iPostCount} WHERE name='postcount'");
        $dbConn->query("UPDATE stats SET content=content-1 WHERE name='threadcount'");
        // Set the redirect page.
        $strRedirect = "forumdisplay.php?forumid={$iForumID}";
    } else {
        // No. Get the number of attachments in this post.
        $dbConn->query("SELECT COUNT(*) FROM attachment WHERE parent={$iPostID}");
        list($iAttachmentCount) = $dbConn->getresult();
        // Delete the post's record and any attachments.
        $dbConn->query("DELETE FROM post WHERE id={$iPostID}");
        $dbConn->query("DELETE FROM attachment WHERE parent={$iPostID}");
        // Delete all search indexes for the post.
        $dbConn->query("DELETE FROM searchindex WHERE postid={$iPostID}");
        // Decrease the post count of the author of the post by one.
        $dbConn->query("UPDATE citizen SET postcount=postcount-1 WHERE id={$iAuthorID}");
        // Get the post date and the author ID of the new last post of the thread.
        $dbConn->query("SELECT post.datetime_posted, post.author FROM post LEFT JOIN thread ON (post.parent = thread.id) WHERE thread.id={$iThreadID} ORDER BY post.datetime_posted DESC LIMIT 1");
        list($tLastPost, $iNewLastPoster) = $dbConn->getresult();
        // Update the thread's record.
        $dbConn->query("UPDATE thread SET lpost={$tLastPost}, lposter={$iNewLastPoster}, postcount=postcount-1, attachcount=attachcount-{$iAttachmentCount} WHERE id={$iThreadID}");
        // Update the forum's post count.
        $dbConn->query("UPDATE board SET postcount=postcount-1 WHERE id={$iForumID}");
        // Update the forum stats.
        $dbConn->query("UPDATE stats SET content=content-1 WHERE name='postcount'");
        // Set the redirect page.
        $strRedirect = "thread.php?threadid={$iThreadID}";
    }
    // Update the forum's statistics.
    UpdateForumStats($iForumID);
    // Render the page.
    Msg("<b>The post has been successfully deleted.</b><br /><br /><span class=\"smaller\">You should be redirected momentarily. Click <a href=\"{$strRedirect}\">here</a> if you do not want to wait any longer or if you are not redirected.</span>", $strRedirect);
}
コード例 #2
0
ファイル: mod.php プロジェクト: OvBB/v1.0
function CopyThreadNow($iThreadID)
{
    global $CFG, $dbConn;
    // What forum do they want to copy it to?
    $iDestinationID = (int) $_REQUEST['forumid'];
    // Get the thread's information.
    $dbConn->query("SELECT * FROM thread WHERE thread.id={$iThreadID}");
    if (!($aThreadInfo = $dbConn->getresult(TRUE))) {
        Msg("Invalid thread specified.{$CFG['msg']['invalidlink']}");
    }
    // Make sure the destination isn't the same as the parent.
    if ($aThreadInfo['parent'] == $iDestinationID) {
        Msg("You cannot copy a thread to a forum it's already in.");
    }
    // Make sure the destination is valid (exists and isn't a category).
    $dbConn->query("SELECT displaydepth FROM board WHERE id={$iDestinationID}");
    if (!(list($iLevel) = $dbConn->getresult())) {
        Msg('The destination forum you specified does not exist.');
    } else {
        if ($iLevel == 0) {
            Msg('The destination forum you specified cannot contain posts. Please select a different forum.');
        }
    }
    // Get a list of the posts in the thread.
    $dbConn->query("SELECT id, author FROM post WHERE parent={$iThreadID}");
    while (list($iPostID, $iAuthorID) = $dbConn->getresult()) {
        // Save the post to the list.
        $aPosts[] = $iPostID;
        // Increment the author's postcount of this thread.
        $aPostCounts[$iAuthorID]++;
    }
    $strPosts = implode(', ', $aPosts);
    // Sanitize some thread fields.
    $aThreadInfo['title'] = $dbConn->sanitize($aThreadInfo['title']);
    $aThreadInfo['description'] = $dbConn->sanitize($aThreadInfo['description']);
    $aThreadInfo['notes'] = $dbConn->sanitize($aThreadInfo['notes']);
    $aThreadInfo['poll'] = (int) (bool) $aThreadInfo['poll'];
    // Copy the thread record (but keep it closed and invisible until we're done).
    $dbConn->query("INSERT INTO thread(title, description, parent, viewcount, postcount, attachcount, lpost, lposter, icon, author, notes, poll, closed, visible, sticky) VALUES('{$aThreadInfo['title']}', '{$aThreadInfo['description']}', {$iDestinationID}, {$aThreadInfo['viewcount']}, {$aThreadInfo['postcount']}, {$aThreadInfo['attachcount']}, {$aThreadInfo['lpost']}, {$aThreadInfo['lposter']}, {$aThreadInfo['icon']}, {$aThreadInfo['author']}, '{$aThreadInfo['notes']}', {$aThreadInfo['poll']}, 1, 0, {$aThreadInfo['sticky']})");
    // What is the ID of the thread we just created?
    $iNewThreadID = $dbConn->getinsertid('thread');
    // Get a list of the attachments in this thread.
    $dbConn->query("SELECT id, parent FROM attachment WHERE parent IN ({$strPosts})");
    while (list($iAttachmentID, $iParentID) = $dbConn->getresult()) {
        $aAttachments[$iAttachmentID] = $iParentID;
    }
    // Copy all of the post records.
    $dbConn->query("SELECT * FROM post WHERE parent={$iThreadID}");
    $aSQLAllResults = $dbConn->getall(TRUE);
    while (list($key, $aPostInfo) = each($aSQLAllResults)) {
        // Convert data types, if necessary.
        if ($aPostInfo['datetime_edited'] === NULL) {
            $aPostInfo['datetime_edited'] = 'NULL';
        }
        if ($aPostInfo['ipaddress'] === NULL) {
            $aPostInfo['ipaddress'] = 'NULL';
        }
        // Sanitize some post fields.
        $strTitle = $aPostInfo['title'];
        $strBody = $aPostInfo['body'];
        $aPostInfo['title'] = $dbConn->sanitize($aPostInfo['title']);
        $aPostInfo['body'] = $dbConn->sanitize($aPostInfo['body']);
        // Insert the copy of the post.
        $dbConn->query("INSERT INTO post(author, datetime_posted, datetime_edited, title, body, parent, ipaddress, icon, dsmilies) VALUES({$aPostInfo['author']}, {$aPostInfo['datetime_posted']}, {$aPostInfo['datetime_edited']}, '{$aPostInfo['title']}', '{$aPostInfo['body']}', {$iNewThreadID}, {$aPostInfo['ipaddress']}, {$aPostInfo['icon']}, {$aPostInfo['dsmilies']})");
        // Get the ID of the post we just created.
        $iPostID = $dbConn->getinsertid('post');
        // Now let's add the message into the search engine index.
        AddSearchIndex($iPostID, $strTitle, $strBody);
        // Store the attachments the post has (if any).
        if (is_array($aAttachments)) {
            // Did the original post contain any attachments?
            $temp = array_keys($aAttachments, $aPostInfo['id']);
            if (is_array($temp)) {
                // Yes, so save them.
                foreach ($temp as $iAttachmentID) {
                    $aAttachments[$iAttachmentID] = $iPostID;
                }
            }
        }
    }
    // Copy all of the attachment records.
    if (is_array($aAttachments)) {
        $dbConn->query("SELECT * FROM attachment WHERE parent IN ({$strPosts})");
        $aSQLAllResults = $dbConn->getall(TRUE);
        while (list($key, $aAttachmentInfo) = each($aSQLAllResults)) {
            // What is the new post ID that will be the parent of this new attachment?
            $iParentID = $aAttachments[$aAttachmentInfo['id']];
            // Break the file data into an array of 64KB strings.
            $aData = sqlsplit($aAttachmentInfo['filedata'], 65536);
            // Sanitize the filename.
            $aAttachmentInfo['filename'] = $dbConn->sanitize($aAttachmentInfo['filename']);
            // Insert the duplicate attachment's record.
            $dbConn->query("INSERT INTO attachment(filename, filedata, viewcount, parent) VALUES('{$aAttachmentInfo['filename']}', '{$aData[0]}', {$aAttachmentInfo['viewcount']}, {$iParentID})");
            $iAttachmentID = $dbConn->getinsertid('attachment');
            unset($aData[0]);
            // Insert the rest of the attachment's data.
            foreach ($aData as $strData) {
                $dbConn->squery(CONCAT_ATTACHMENT, $strData, $iAttachmentID);
            }
            // Reset the data array for the next attachment.
            unset($aData);
        }
    }
    // Copy the poll, if there is one.
    if ($aThreadInfo['poll']) {
        CopyPoll($iThreadID, $iNewThreadID);
    }
    // Add to the users' postcounts the number of posts they had in the original thread.
    foreach ($aPostCounts as $iAuthorID => $iPostCount) {
        $dbConn->query("UPDATE citizen SET postcount=postcount+{$iPostCount} WHERE id={$iAuthorID}");
    }
    // Give the new thread life.
    $dbConn->query("UPDATE thread SET closed={$aThreadInfo['closed']}, visible={$aThreadInfo['visible']} WHERE id={$iNewThreadID}");
    // Get the total number of posts we've copied/added.
    $iPostCount = count($aPosts);
    // Update the destination forum's post and thread counts.
    $dbConn->query("UPDATE board SET postcount=postcount+{$iPostCount}, threadcount=threadcount+1 WHERE id={$iDestinationID}");
    // Update the forum stats.
    $dbConn->query("UPDATE stats SET content=content+{$iPostCount} WHERE name='postcount'");
    $dbConn->query("UPDATE stats SET content=content+1 WHERE name='threadcount'");
    // Update the destination forum's stats.
    UpdateForumStats($iDestinationID);
    // Render page.
    Msg("<b>The thread has been copied successfully.</b><br /><br /><span class=\"smaller\">You should be redirected momentarily. Click <a href=\"thread.php?threadid={$iNewThreadID}\">here</a> if you do not want to wait any longer or if you are not redirected.</span>", "thread.php?threadid={$iNewThreadID}");
}