//	Send back new count of answers
        $countanswers = $question['acount'];
        if ($countanswers == 1) {
            echo qa_lang_html('question/1_answer_title');
        } else {
            echo qa_lang_html_sub('question/x_answers_title', $countanswers);
        }
        //	If the answer was not deleted....
        if (isset($answer)) {
            $question = $question + qa_page_q_post_rules($question, null, null, $qchildposts);
            // array union
            $answer = $answer + qa_page_q_post_rules($answer, $question, $qchildposts, $achildposts);
            foreach ($achildposts as $key => $achildpost) {
                $achildposts[$key] = $achildpost + qa_page_q_post_rules($achildpost, $answer, $achildposts, null);
            }
            $usershtml = qa_userids_handles_html(array_merge(array($answer), $achildposts), true);
            $a_view = qa_page_q_answer_view($question, $answer, $answer['postid'] == $question['selchildid'] && $answer['type'] == 'A', $usershtml, false);
            $a_view['c_list'] = qa_page_q_comment_follow_list($question, $answer, $achildposts, false, $usershtml, false, null);
            $themeclass = qa_load_theme_class(qa_get_site_theme(), 'ajax-answer', null, null);
            //	... send back the HTML for it
            echo "\n";
            $themeclass->a_list_item($a_view);
        }
        return;
    }
}
echo "QA_AJAX_RESPONSE\n0\n";
// fall back to non-Ajax submission if something failed
/*
	Omit PHP closing tag to help avoid accidental output
*/
Example #2
0
 $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";
         //	Send back the count of answers
         if ($countanswers == 1) {
             echo qa_lang_html('question/1_answer_title') . "\n";
         } else {
             echo qa_lang_html_sub('question/x_answers_title', $countanswers) . "\n";
         }
         //	Send back the HTML
         $themeclass->a_list_item($a_view);
         return;
     }
 }
    if (isset($commentsfollows[$showid])) {
        $showid = $commentsfollows[$showid]['parentid'];
    }
    $position = array_search($showid, $answerids);
    if (is_numeric($position)) {
        $pagestart = floor($position / $pagesize) * $pagesize;
    }
}
// set the canonical url based on possible pagination
$qa_content['canonical'] = qa_path_html(qa_q_request($question['postid'], $question['title']), $pagestart > 0 ? array('start' => $pagestart) : null, qa_opt('site_url'));
// build the actual answer list
$answerids = array_slice($answerids, $pagestart, $pagesize);
foreach ($answerids as $answerid) {
    $answer = $answers[$answerid];
    if (!($formtype == 'a_edit' && $formpostid == $answerid)) {
        $a_view = qa_page_q_answer_view($question, $answer, $answer['isselected'], $usershtml, $formrequested);
        //	Prepare content for comments on this answer, plus add or edit comment forms
        if ($formtype == 'c_add' && $formpostid == $answerid || $answer['commentbutton'] && !$formrequested) {
            // ...to be added
            $a_view['c_form'] = qa_page_q_add_c_form($qa_content, $question, $answer, 'c' . $answerid, $captchareason, @$cnewin[$answerid], @$cnewerrors[$answerid], $formtype == 'c_add');
            if ($formtype == 'c_add' && $formpostid == $answerid) {
                $jumptoanchor = 'c' . $answerid;
                $commentsall = $answerid;
            }
        } elseif ($formtype == 'c_edit' && @$commentsfollows[$formpostid]['parentid'] == $answerid) {
            // ...being edited
            $a_view['c_form'] = qa_page_q_edit_c_form($qa_content, 'c' . $formpostid, $commentsfollows[$formpostid], @$ceditin[$formpostid], @$cediterrors[$formpostid]);
            $jumptoanchor = 'c' . $formpostid;
            $commentsall = $answerid;
        }
        $a_view['c_list'] = qa_page_q_comment_follow_list($question, $answer, $commentsfollows, $commentsall == $answerid, $usershtml, $formrequested, $formpostid);