示例#1
0
function ra_ajax_add_answer()
{
    //	Load relevant information about this question
    $questionid = qa_post_text('a_questionid');
    $userid = qa_get_logged_in_userid();
    list($question, $childposts) = qa_db_select_with_pending(qa_db_full_post_selectspec($userid, $questionid), qa_db_full_child_posts_selectspec($userid, $questionid));
    //	Check if the question exists, is not closed, and whether the user has permission to do this
    if (@$question['basetype'] == 'Q' && !isset($question['closedbyid']) && !qa_user_post_permit_error('permit_post_a', $question, QA_LIMIT_ANSWERS)) {
        require_once QA_INCLUDE_DIR . 'qa-app-captcha.php';
        require_once QA_INCLUDE_DIR . 'qa-app-format.php';
        require_once QA_INCLUDE_DIR . 'qa-app-post-create.php';
        require_once QA_INCLUDE_DIR . 'qa-app-cookies.php';
        require_once QA_INCLUDE_DIR . 'qa-page-question-view.php';
        require_once QA_INCLUDE_DIR . 'qa-page-question-submit.php';
        //	Try to create the new answer
        $usecaptcha = qa_user_use_captcha(qa_user_level_for_post($question));
        $answers = qa_page_q_load_as($question, $childposts);
        $answerid = qa_page_q_add_a_submit($question, $answers, false, $in, $errors);
        if ($answerid) {
            return true;
        }
    }
    die;
}
示例#2
0
//	First check whether the person has permission to do this
if (!qa_user_permit_error('permit_post_a', QA_LIMIT_ANSWERS)) {
    require_once QA_INCLUDE_DIR . 'qa-db-selects.php';
    require_once QA_INCLUDE_DIR . 'qa-app-captcha.php';
    require_once QA_INCLUDE_DIR . 'qa-app-format.php';
    require_once QA_INCLUDE_DIR . 'qa-app-post-create.php';
    require_once QA_INCLUDE_DIR . 'qa-app-cookies.php';
    require_once QA_INCLUDE_DIR . 'qa-page-question-view.php';
    require_once QA_INCLUDE_DIR . 'qa-page-question-submit.php';
    //	Load relevant information about this question and check it exists
    $usecaptcha = qa_user_use_captcha();
    $questionid = qa_post_text('a_questionid');
    $userid = qa_get_logged_in_userid();
    list($question, $childposts) = qa_db_select_with_pending(qa_db_full_post_selectspec($userid, $questionid), qa_db_full_child_posts_selectspec($userid, $questionid));
    if (@$question['basetype'] == 'Q' && !isset($question['closedbyid'])) {
        $answers = qa_page_q_load_as($question, $childposts);
        //	Try to create the new answer
        $answerid = qa_page_q_add_a_submit($question, $answers, $usecaptcha, $in, $errors);
        $countanswers = $question['acount'] + 1;
        if (isset($answerid)) {
            //	If successful, page content will be updated via Ajax
            $answer = qa_db_select_with_pending(qa_db_full_post_selectspec($userid, $answerid));
            $question = $question + qa_page_q_post_rules($question, null, null, $childposts);
            // array union
            $answer = $answer + qa_page_q_post_rules($answer, $question, $answers, null);
            $usershtml = qa_userids_handles_html(array($answer), true);
            $a_view = qa_page_q_answer_view($question, $answer, false, $usershtml, false);
            $themeclass = qa_load_theme_class(qa_get_site_theme(), 'ajax-answer', null, null);
            echo "QA_AJAX_RESPONSE\n1\n";
            //	Send back whether the 'answer' button should still be visible
            echo (int) qa_opt('allow_multi_answers') . "\n";
示例#3
0
 function get_single_question($data, $questionin)
 {
     $userid = qa_get_logged_in_userid();
     $questionid = $questionin['postid'];
     $options = qa_post_html_defaults('Q', @$data['full']);
     if (@$data['full']) {
         require_once QA_INCLUDE_DIR . 'qa-page-question-view.php';
         $cookieid = isset($userid) ? qa_cookie_get() : qa_cookie_get_create();
         // create a new cookie if necessary
         $coptions = qa_post_html_defaults('C', true);
         @(list($childposts, $achildposts, $parentquestion, $closepost, $extravalue, $categories, $favorite) = qa_db_select_with_pending(qa_db_full_child_posts_selectspec($userid, $questionid), qa_db_full_a_child_posts_selectspec($userid, $questionid), qa_db_post_parent_q_selectspec($questionid), qa_db_post_close_post_selectspec($questionid), qa_db_post_meta_selectspec($questionid, 'qa_q_extra'), qa_db_category_nav_selectspec($questionid, true, true, true), isset($userid) ? qa_db_is_favorite_selectspec($userid, QA_ENTITY_QUESTION, $questionid) : null));
         if ($questionin['basetype'] != 'Q') {
             // don't allow direct viewing of other types of post
             return null;
         }
         $questionin['extra'] = $extravalue;
         $answers = qa_page_q_load_as($questionin, $childposts);
         $allcomments = qa_page_q_load_c_follows($questionin, $childposts, $achildposts);
         $questionin = $questionin + qa_page_q_post_rules($questionin, null, null, $childposts);
         // array union
         if ($questionin['selchildid'] && @$answers[$questionin['selchildid']]['type'] != 'A') {
             $questionin['selchildid'] = null;
         }
         // if selected answer is hidden or somehow not there, consider it not selected
         foreach ($answers as $key => $answer) {
             $answers[$key] = $answer + qa_page_q_post_rules($answer, $questionin, $answers, $achildposts);
             $answers[$key]['isselected'] = $answer['postid'] == $questionin['selchildid'];
         }
         foreach ($allcomments as $key => $commentfollow) {
             $parent = $commentfollow['parentid'] == $questionid ? $questionin : @$answers[$commentfollow['parentid']];
             $allcomments[$key] = $commentfollow + qa_page_q_post_rules($commentfollow, $parent, $allcomments, null);
         }
         $usershtml = qa_userids_handles_html(array_merge(array($questionin), $answers, $allcomments), true);
         $question = $this->get_full_post($questionin, $options, $usershtml);
         $qcomments = array();
         foreach ($allcomments as $idx => $comment) {
             if ($comment['basetype'] == 'C') {
                 $comment = $this->get_full_post($comment, $coptions, $usershtml);
             } else {
                 $comment = $this->get_full_post($comment, $options, $usershtml);
             }
             $comment['username'] = $this->get_username($comment['raw']['userid']);
             if ($comment['raw']['parentid'] == $questionid) {
                 $qcomments[] = $comment;
             }
             $allcomments[$idx] = $comment;
         }
         $aoptions = qa_post_html_defaults('A', true);
         $outanswers = array();
         foreach ($answers as $answer) {
             $aoptions['isselected'] = @$answer['isselected'];
             $answer = $this->get_full_post($answer, $aoptions, $usershtml);
             if (!$answer) {
                 continue;
             }
             $answer['username'] = $this->get_username($answer['raw']['userid']);
             $acomments = array();
             foreach ($allcomments as $comment) {
                 if ($comment['raw']['parentid'] == $answer['raw']['postid']) {
                     $acomments[] = $comment;
                 }
             }
             $answer['comments'] = $acomments;
             $outanswers[] = $answer;
         }
         $question['answers'] = $outanswers;
         $question['comments'] = $qcomments;
         $question['parentquestion'] = $parentquestion;
         $question['closepost'] = $closepost;
         $question['extravalue'] = $extravalue;
         $question['categories'] = $categories;
         $question['favorite'] = $favorite;
     } else {
         $questionin = qa_db_select_with_pending(qa_db_full_post_selectspec($userid, $questionid));
         $usershtml = qa_userids_handles_html(array($questionin), true);
         $question = qa_any_to_q_html_fields($questionin, $userid, qa_cookie_get(), $usershtml, null, $options);
     }
     $question['username'] = $this->get_username($userid);
     return $question;
 }