Пример #1
0
$questionid = qa_post_text('c_questionid');
$parentid = qa_post_text('c_parentid');
$userid = qa_get_logged_in_userid();
list($question, $parent, $children) = qa_db_select_with_pending(qa_db_full_post_selectspec($userid, $questionid), qa_db_full_post_selectspec($userid, $parentid), qa_db_full_child_posts_selectspec($userid, $parentid));
//	Check if the question and parent exist, and whether the user has permission to do this
if (@$question['basetype'] == 'Q' && (@$parent['basetype'] == 'Q' || @$parent['basetype'] == 'A') && !qa_user_post_permit_error('permit_post_c', $parent, QA_LIMIT_COMMENTS)) {
    require_once QA_INCLUDE_DIR . 'app/captcha.php';
    require_once QA_INCLUDE_DIR . 'app/format.php';
    require_once QA_INCLUDE_DIR . 'app/post-create.php';
    require_once QA_INCLUDE_DIR . 'app/cookies.php';
    require_once QA_INCLUDE_DIR . 'pages/question-view.php';
    require_once QA_INCLUDE_DIR . 'pages/question-submit.php';
    require_once QA_INCLUDE_DIR . 'util/sort.php';
    //	Try to create the new comment
    $usecaptcha = qa_user_use_captcha(qa_user_level_for_post($question));
    $commentid = qa_page_q_add_c_submit($question, $parent, $children, $usecaptcha, $in, $errors);
    //	If successful, page content will be updated via Ajax
    if (isset($commentid)) {
        $children = qa_db_select_with_pending(qa_db_full_child_posts_selectspec($userid, $parentid));
        $parent = $parent + qa_page_q_post_rules($parent, $questionid == $parentid ? null : $question, null, $children);
        // in theory we should retrieve the parent's siblings for the above, but they're not going to be relevant
        foreach ($children as $key => $child) {
            $children[$key] = $child + qa_page_q_post_rules($child, $parent, $children, null);
        }
        $usershtml = qa_userids_handles_html($children, true);
        qa_sort_by($children, 'created');
        $c_list = qa_page_q_comment_follow_list($question, $parent, $children, true, $usershtml, false, null);
        $themeclass = qa_load_theme_class(qa_get_site_theme(), 'ajax-comments', null, null);
        echo "QA_AJAX_RESPONSE\n1\n";
        //	Send back the ID of the new comment
        echo qa_anchor('C', $commentid) . "\n";
function qa_page_q_do_comment($question, $parent, $commentsfollows, $pagestart, $usecaptcha, &$cnewin, &$cnewerrors, &$formtype, &$formpostid, &$error)
{
    // The 'approve', 'login', 'confirm', 'userblock', 'ipblock' permission errors are reported to the user here
    // The other option ('level') prevents the comment button being shown, in qa_page_q_post_rules(...)
    $answer = $question['postid'] == $parent['postid'] ? null : $parent;
    $parentid = $parent['postid'];
    switch (qa_user_post_permit_error('permit_post_c', $parent, QA_LIMIT_COMMENTS)) {
        case 'login':
            $error = qa_insert_login_links(qa_lang_html('question/comment_must_login'), qa_request());
            break;
        case 'confirm':
            $error = qa_insert_login_links(qa_lang_html('question/comment_must_confirm'), qa_request());
            break;
        case 'approve':
            $error = qa_lang_html('question/comment_must_be_approved');
            break;
        case 'limit':
            $error = qa_lang_html('question/comment_limit');
            break;
        default:
            $error = qa_lang_html('users/no_permission');
            break;
        case false:
            if (qa_clicked('c' . $parentid . '_doadd')) {
                $commentid = qa_page_q_add_c_submit($question, $parent, $commentsfollows, $usecaptcha, $cnewin[$parentid], $cnewerrors[$parentid]);
                if (isset($commentid)) {
                    qa_page_q_refresh($pagestart, null, $parent['basetype'], $parentid);
                } else {
                    $formtype = 'c_add';
                    $formpostid = $parentid;
                    // show form again
                }
            } else {
                $formtype = 'c_add';
                $formpostid = $parentid;
                // show form first time
            }
            break;
    }
}
function qa_page_q_do_comment($question, $parent, $commentsfollows, $pagestart, $usecaptcha, &$cnewin, &$cnewerrors, &$formtype, &$formpostid, &$error)
{
    $answer = $question['postid'] == $parent['postid'] ? null : $parent;
    $parentid = $parent['postid'];
    switch (qa_user_permit_error('permit_post_c', QA_LIMIT_COMMENTS)) {
        case 'login':
            $error = qa_insert_login_links(qa_lang_html('question/comment_must_login'), qa_request());
            break;
        case 'confirm':
            $error = qa_insert_login_links(qa_lang_html('question/comment_must_confirm'), qa_request());
            break;
        case 'limit':
            $error = qa_lang_html('question/comment_limit');
            break;
        default:
            $error = qa_lang_html('users/no_permission');
            break;
        case false:
            if (qa_clicked('c' . $parentid . '_doadd')) {
                $commentid = qa_page_q_add_c_submit($question, $parent, $commentsfollows, $usecaptcha, $cnewin[$parentid], $cnewerrors[$parentid]);
                if (isset($commentid)) {
                    qa_page_q_refresh($pagestart, null, $parent['basetype'], $parentid);
                } else {
                    $formtype = 'c_add';
                    $formpostid = $parentid;
                    // show form again
                }
            } else {
                $formtype = 'c_add';
                $formpostid = $parentid;
                // show form first time
            }
            break;
    }
}