function qa_page_q_close_q_submit($question, $closepost, &$in, &$errors)
{
    $in = array('duplicate' => qa_post_text('q_close_duplicate'), 'details' => qa_post_text('q_close_details'));
    $userid = qa_get_logged_in_userid();
    $handle = qa_get_logged_in_handle();
    $cookieid = qa_cookie_get();
    if (!qa_check_form_security_code('close-' . $question['postid'], qa_post_text('code'))) {
        $errors['details'] = qa_lang_html('misc/form_security_again');
    } elseif ($in['duplicate']) {
        // be liberal in what we accept, but there are two potential unlikely pitfalls here:
        // a) URLs could have a fixed numerical path, e.g. http://qa.mysite.com/1/478/...
        // b) There could be a question title which is just a number, e.g. http://qa.mysite.com/478/12345/...
        // so we check if more than one question could match, and if so, show an error
        $parts = preg_split('|[=/&]|', $in['details'], -1, PREG_SPLIT_NO_EMPTY);
        $keypostids = array();
        foreach ($parts as $part) {
            if (preg_match('/^[0-9]+$/', $part)) {
                $keypostids[$part] = true;
            }
        }
        $questionids = qa_db_posts_filter_q_postids(array_keys($keypostids));
        if (count($questionids) == 1 && $questionids[0] != $question['postid']) {
            qa_question_close_duplicate($question, $closepost, $questionids[0], $userid, $handle, $cookieid);
            return true;
        } else {
            $errors['details'] = qa_lang('question/close_duplicate_error');
        }
    } else {
        if (strlen($in['details']) > 0) {
            qa_question_close_other($question, $closepost, $in['details'], $userid, $handle, $cookieid);
            return true;
        } else {
            $errors['details'] = qa_lang('main/field_required');
        }
    }
    return false;
}
Exemple #2
0
function qa_post_set_closed($questionid, $closed = true, $originalpostid = null, $note = null, $byuserid = null)
{
    $oldquestion = qa_post_get_full($questionid, 'Q');
    $oldclosepost = qa_post_get_question_closepost($questionid);
    $byhandle = qa_post_userid_to_handle($byuserid);
    if ($closed) {
        if (isset($originalpostid)) {
            qa_question_close_duplicate($oldquestion, $oldclosepost, $originalpostid, $byuserid, $byhandle, null);
        } elseif (isset($note)) {
            qa_question_close_other($oldquestion, $oldclosepost, $note, $byuserid, $byhandle, null);
        } else {
            qa_fatal_error('Question must be closed as a duplicate or with a note');
        }
    } else {
        qa_question_close_clear($oldquestion, $oldclosepost, $byuserid, $byhandle, null);
    }
}