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'])); } }
function qa_comment_create($userid, $handle, $cookieid, $content, $format, $text, $notify, $email, $question, $parent, $commentsfollows, $queued = false, $name = null) { require_once QA_INCLUDE_DIR . 'app/emails.php'; require_once QA_INCLUDE_DIR . 'app/options.php'; require_once QA_INCLUDE_DIR . 'app/format.php'; require_once QA_INCLUDE_DIR . 'util/string.php'; if (!isset($parent)) { $parent = $question; } // for backwards compatibility with old answer parameter $postid = qa_db_post_create($queued ? 'C_QUEUED' : 'C', $parent['postid'], $userid, isset($userid) ? null : $cookieid, qa_remote_ip_address(), null, $content, $format, null, qa_combine_notify_email($userid, $notify, $email), $question['categoryid'], isset($userid) ? null : $name); qa_db_posts_calc_category_path($postid); if ($queued) { qa_db_queuedcount_update(); } else { if ($question['type'] == 'Q' && ($parent['type'] == 'Q' || $parent['type'] == 'A')) { // only index if antecedents fully visible qa_post_index($postid, 'C', $question['postid'], $parent['postid'], null, $content, $format, $text, null, $question['categoryid']); } qa_db_points_update_ifuser($userid, 'cposts'); qa_db_ccount_update(); } $thread = array(); foreach ($commentsfollows as $comment) { if ($comment['type'] == 'C' && $comment['parentid'] == $parent['postid']) { // find just those for this parent, fully visible $thread[] = $comment; } } qa_report_event($queued ? 'c_queue' : 'c_post', $userid, $handle, $cookieid, array('postid' => $postid, 'parentid' => $parent['postid'], 'parenttype' => $parent['basetype'], 'parent' => $parent, 'questionid' => $question['postid'], 'question' => $question, 'thread' => $thread, 'content' => $content, 'format' => $format, 'text' => $text, 'categoryid' => $question['categoryid'], 'name' => $name, 'notify' => $notify, 'email' => $email)); return $postid; }