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; } }