Exemplo n.º 1
0
function qa_post_create($type, $parentid, $title, $content, $format = '', $categoryid = null, $tags = null, $userid = null, $notify = null, $email = null, $extravalue = null)
{
    $handle = qa_post_userid_to_handle($userid);
    $text = qa_post_content_to_text($content, $format);
    switch ($type) {
        case 'Q':
        case 'Q_QUEUED':
            $followanswer = isset($parentid) ? qa_post_get_full($parentid, 'A') : null;
            $tagstring = qa_post_tags_to_tagstring($tags);
            $postid = qa_question_create($followanswer, $userid, $handle, null, $title, $content, $format, $text, $tagstring, $notify, $email, $categoryid, $extravalue, $type == 'Q_QUEUED');
            break;
        case 'A':
        case 'A_QUEUED':
            $question = qa_post_get_full($parentid, 'Q');
            $postid = qa_answer_create($userid, $handle, null, $content, $format, $text, $notify, $email, $question, $type == 'A_QUEUED');
            break;
        case 'C':
        case 'C_QUEUED':
            $parent = qa_post_get_full($parentid, 'QA');
            $commentsfollows = qa_db_single_select(qa_db_full_child_posts_selectspec(null, $parentid));
            $question = qa_post_parent_to_question($parent);
            $postid = qa_comment_create($userid, $handle, null, $content, $format, $text, $notify, $email, $question, $parent, $commentsfollows, $type == 'C_QUEUED');
            break;
        default:
            qa_fatal_error('Post type not recognized: ' . $type);
            break;
    }
    return $postid;
}
Exemplo n.º 2
0
function qa_page_q_add_c_submit($question, $parent, $commentsfollows, $usecaptcha, &$in, &$errors)
{
    $parentid = $parent['postid'];
    $prefix = 'c' . $parentid . '_';
    $in = array('name' => qa_post_text($prefix . 'name'), 'notify' => qa_post_text($prefix . 'notify') !== null, 'email' => qa_post_text($prefix . 'email'), 'queued' => qa_user_moderation_reason(qa_user_level_for_post($parent)) !== false);
    qa_get_post_content($prefix . 'editor', $prefix . 'content', $in['editor'], $in['content'], $in['format'], $in['text']);
    $errors = array();
    if (!qa_check_form_security_code('comment-' . $parent['postid'], qa_post_text($prefix . 'code'))) {
        $errors['content'] = qa_lang_html('misc/form_security_again');
    } else {
        $filtermodules = qa_load_modules_with('filter', 'filter_comment');
        foreach ($filtermodules as $filtermodule) {
            $oldin = $in;
            $filtermodule->filter_comment($in, $errors, $question, $parent, null);
            qa_update_post_text($in, $oldin);
        }
        if ($usecaptcha) {
            qa_captcha_validate_post($errors);
        }
        if (empty($errors)) {
            $testwords = implode(' ', qa_string_to_words($in['content']));
            foreach ($commentsfollows as $comment) {
                if ($comment['basetype'] == 'C' && $comment['parentid'] == $parentid && !$comment['hidden']) {
                    if (implode(' ', qa_string_to_words($comment['content'])) == $testwords) {
                        $errors['content'] = qa_lang_html('question/duplicate_content');
                    }
                }
            }
        }
        if (empty($errors)) {
            $userid = qa_get_logged_in_userid();
            $handle = qa_get_logged_in_handle();
            $cookieid = isset($userid) ? qa_cookie_get() : qa_cookie_get_create();
            // create a new cookie if necessary
            $commentid = qa_comment_create($userid, $handle, $cookieid, $in['content'], $in['format'], $in['text'], $in['notify'], $in['email'], $question, $parent, $commentsfollows, $in['queued'], $in['name']);
            return $commentid;
        }
    }
    return null;
}
 function ajaxPostComment($text, $aid = false)
 {
     if ($aid) {
         $answer = qa_db_single_select(qa_db_full_post_selectspec(null, $aid));
     }
     require_once QA_INCLUDE_DIR . 'qa-page-question-post.php';
     global $qa_login_userid, $qa_cookieid, $question, $questionid, $formtype, $formpostid, $errors, $reloadquestion, $pageerror, $qa_request, $ineditor, $incomment, $informat, $innotify, $inemail, $commentsfollows, $jumptoanchor, $usecaptcha;
     $parent = isset($answer) ? $answer : $question;
     switch (qa_user_permit_error('permit_post_c', 'C')) {
         case 'login':
             $pageerror = qa_insert_login_links(qa_lang_html('question/comment_must_login'), $qa_request);
             break;
         case 'confirm':
             $pageerror = qa_insert_login_links(qa_lang_html('question/comment_must_confirm'), $qa_request);
             break;
         case 'limit':
             $pageerror = qa_lang_html('question/comment_limit');
             break;
         default:
             $pageerror = qa_lang_html('users/no_permission');
             break;
         case false:
             $incomment = qa_post_text('ajax_comment_content');
             if (!isset($incomment)) {
                 $pageerror = qa_lang_html('bork');
             } else {
                 $innotify = qa_post_text('notify') ? true : false;
                 $inemail = qa_post_text('email');
                 $this->ajaxEditor($ineditor, $incomment, $informat, $intext);
                 // use our own format types
                 $formats = array();
                 $formats[] = '';
                 $editors = qa_list_modules('viewer');
                 if (in_array('Markdown Viewer', $editors)) {
                     $formats[] = 'markdown';
                 }
                 $formats[] = 'html';
                 $informat = $formats[qa_opt('ajax_comment_format')];
                 $errors = qa_comment_validate($incomment, $informat, $intext, $innotify, $inemail);
                 if ($usecaptcha) {
                     qa_captcha_validate($_POST, $errors);
                 }
                 if (empty($errors)) {
                     $isduplicate = false;
                     foreach ($commentsfollows as $comment) {
                         if ($comment['basetype'] == 'C' && $comment['parentid'] == $parent['postid'] && !$comment['hidden']) {
                             if (implode(' ', qa_string_to_words($comment['content'])) == implode(' ', qa_string_to_words($incomment))) {
                                 $isduplicate = true;
                             }
                         }
                     }
                     if (!$isduplicate) {
                         if (!isset($qa_login_userid)) {
                             $qa_cookieid = qa_cookie_get_create();
                         }
                         // create a new cookie if necessary
                         // get editor format
                         $commentid = qa_comment_create($qa_login_userid, qa_get_logged_in_handle(), $qa_cookieid, $incomment, $informat, $intext, $innotify, $inemail, $question, @$answer, $commentsfollows);
                         qa_report_write_action($qa_login_userid, $qa_cookieid, 'c_post', $questionid, @$answer['postid'], $commentid);
                     } else {
                         $pageerror = qa_lang_html('question/duplicate_content');
                     }
                 }
             }
             break;
     }
     if ($pageerror) {
         $this->output_raw('### ' . $pageerror);
     } else {
         if (!empty($errors)) {
             $this->output_raw('### ' . implode(',', $errors));
         } else {
             // return c_item
             $c_item = $this->ajaxCommentCreate($parent, $commentid);
             if (isset($c_item['classes'])) {
                 $c_item['classes'] .= ' ajax-comment-hidden';
             } else {
                 $c_item['classes'] = ' ajax-comment-hidden';
             }
             $this->c_list_item($c_item);
         }
     }
 }
function qa_page_q_do_comment($answer)
{
    global $qa_login_userid, $qa_cookieid, $question, $questionid, $formtype, $formpostid, $errors, $reloadquestion, $pageerror, $qa_request, $ineditor, $incomment, $informat, $innotify, $inemail, $commentsfollows, $jumptoanchor, $usecaptcha;
    $parent = isset($answer) ? $answer : $question;
    switch (qa_user_permit_error('permit_post_c', 'C')) {
        case 'login':
            $pageerror = qa_insert_login_links(qa_lang_html('question/comment_must_login'), $qa_request);
            break;
        case 'confirm':
            $pageerror = qa_insert_login_links(qa_lang_html('question/comment_must_confirm'), $qa_request);
            break;
        case 'limit':
            $pageerror = qa_lang_html('question/comment_limit');
            break;
        default:
            $pageerror = qa_lang_html('users/no_permission');
            break;
        case false:
            $incomment = qa_post_text('comment');
            if (!isset($incomment)) {
                $formtype = 'c_add';
                $formpostid = $parent['postid'];
                // show form first time
            } else {
                $innotify = qa_post_text('notify') ? true : false;
                $inemail = qa_post_text('email');
                qa_get_post_content('editor', 'comment', $ineditor, $incomment, $informat, $intext);
                $errors = qa_comment_validate($incomment, $informat, $intext, $innotify, $inemail);
                if ($usecaptcha) {
                    qa_captcha_validate($_POST, $errors);
                }
                if (empty($errors)) {
                    $isduplicate = false;
                    foreach ($commentsfollows as $comment) {
                        if ($comment['basetype'] == 'C' && $comment['parentid'] == $parent['postid'] && !$comment['hidden']) {
                            if (implode(' ', qa_string_to_words($comment['content'])) == implode(' ', qa_string_to_words($incomment))) {
                                $isduplicate = true;
                            }
                        }
                    }
                    if (!$isduplicate) {
                        if (!isset($qa_login_userid)) {
                            $qa_cookieid = qa_cookie_get_create();
                        }
                        // create a new cookie if necessary
                        $commentid = qa_comment_create($qa_login_userid, qa_get_logged_in_handle(), $qa_cookieid, $incomment, $informat, $intext, $innotify, $inemail, $question, $answer, $commentsfollows);
                        qa_report_write_action($qa_login_userid, $qa_cookieid, 'c_post', $questionid, @$answer['postid'], $commentid);
                        qa_redirect($qa_request, null, null, null, qa_anchor(isset($answer) ? 'A' : 'Q', $parent['postid']));
                    } else {
                        $pageerror = qa_lang_html('question/duplicate_content');
                    }
                } else {
                    $formtype = 'c_add';
                    $formpostid = $parent['postid'];
                    // show form again
                }
            }
            break;
    }
}