function qa_comment_set_status($oldcomment, $status, $userid, $handle, $cookieid, $question, $parent)
{
    require_once QA_INCLUDE_DIR . 'qa-app-format.php';
    if (!isset($parent)) {
        $parent = $question;
    }
    // for backwards compatibility with old answer parameter
    $washidden = $oldcomment['type'] == 'C_HIDDEN';
    $wasqueued = $oldcomment['type'] == 'C_QUEUED';
    $wasrequeued = $wasqueued && isset($oldcomment['updated']);
    qa_post_unindex($oldcomment['postid']);
    $setupdated = false;
    $event = null;
    if ($status == QA_POST_STATUS_QUEUED) {
        $newtype = 'C_QUEUED';
        if (!$wasqueued) {
            $event = 'c_requeue';
        }
        // same event whether it was hidden or shown before
    } elseif ($status == QA_POST_STATUS_HIDDEN) {
        $newtype = 'C_HIDDEN';
        if (!$washidden) {
            $event = $wasqueued ? 'c_reject' : 'c_hide';
            if (!$wasqueued) {
                $setupdated = true;
            }
        }
    } elseif ($status == QA_POST_STATUS_NORMAL) {
        $newtype = 'C';
        if ($wasqueued) {
            $event = 'c_approve';
        } elseif ($washidden) {
            $event = 'c_reshow';
            $setupdated = true;
        }
    } else {
        qa_fatal_error('Unknown status in qa_comment_set_status(): ' . $status);
    }
    qa_db_post_set_type($oldcomment['postid'], $newtype, $setupdated ? $userid : null, $setupdated ? qa_remote_ip_address() : null, QA_UPDATE_VISIBLE);
    if ($wasqueued && $status == QA_POST_STATUS_NORMAL && qa_opt('moderate_update_time')) {
        // ... for approval of a post, can set time to now instead
        if ($wasrequeued) {
            qa_db_post_set_updated($oldcomment['postid'], null);
        } else {
            qa_db_post_set_created($oldcomment['postid'], null);
        }
    }
    qa_db_ccount_update();
    qa_db_points_update_ifuser($oldcomment['userid'], array('cposts'));
    if ($wasqueued || $status == QA_POST_STATUS_QUEUED) {
        qa_db_queuedcount_update();
    }
    if ($oldcomment['flagcount']) {
        qa_db_flaggedcount_update();
    }
    if ($question['type'] == 'Q' && ($parent['type'] == 'Q' || $parent['type'] == 'A') && $status == QA_POST_STATUS_NORMAL) {
        // only index if none of the things it depends on are hidden or queued
        qa_post_index($oldcomment['postid'], 'C', $question['postid'], $oldcomment['parentid'], null, $oldcomment['content'], $oldcomment['format'], qa_viewer_text($oldcomment['content'], $oldcomment['format']), null, $oldcomment['categoryid']);
    }
    $eventparams = array('postid' => $oldcomment['postid'], 'parentid' => $oldcomment['parentid'], 'parenttype' => $parent['basetype'], 'parent' => $parent, 'questionid' => $question['postid'], 'question' => $question, 'content' => $oldcomment['content'], 'format' => $oldcomment['format'], 'text' => qa_viewer_text($oldcomment['content'], $oldcomment['format']), 'categoryid' => $oldcomment['categoryid'], 'name' => $oldcomment['name']);
    if (isset($event)) {
        qa_report_event($event, $userid, $handle, $cookieid, $eventparams + array('oldcomment' => $oldcomment));
    }
    if ($wasqueued && $status == QA_POST_STATUS_NORMAL && !$wasrequeued) {
        require_once QA_INCLUDE_DIR . 'qa-db-selects.php';
        require_once QA_INCLUDE_DIR . 'qa-util-string.php';
        $commentsfollows = qa_db_single_select(qa_db_full_child_posts_selectspec(null, $oldcomment['parentid']));
        $thread = array();
        foreach ($commentsfollows as $comment) {
            if ($comment['type'] == 'C' && $comment['parentid'] == $parent['postid']) {
                $thread[] = $comment;
            }
        }
        qa_report_event('c_post', $oldcomment['userid'], $oldcomment['handle'], $oldcomment['cookieid'], $eventparams + array('thread' => $thread, 'notify' => isset($oldcomment['notify']), 'email' => qa_email_validate($oldcomment['notify']) ? $oldcomment['notify'] : null, 'delayed' => $oldcomment['created']));
    }
}
Example #2
0
function qa_flags_clear_all($oldpost, $userid, $handle, $cookieid)
{
    if (qa_to_override(__FUNCTION__)) {
        $args = func_get_args();
        return qa_call_override(__FUNCTION__, $args);
    }
    require_once QA_INCLUDE_DIR . 'db/votes.php';
    require_once QA_INCLUDE_DIR . 'app/limits.php';
    require_once QA_INCLUDE_DIR . 'db/post-update.php';
    qa_db_userflags_clear_all($oldpost['postid']);
    qa_db_post_recount_flags($oldpost['postid']);
    qa_db_flaggedcount_update();
    switch ($oldpost['basetype']) {
        case 'Q':
            $event = 'q_clearflags';
            break;
        case 'A':
            $event = 'a_clearflags';
            break;
        case 'C':
            $event = 'c_clearflags';
            break;
    }
    qa_report_event($event, $userid, $handle, $cookieid, array('postid' => $oldpost['postid'], 'oldpost' => $oldpost));
}