//	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
*/
        $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);
        // ...for viewing
        //	Add the answer to the list
        $qa_content['a_list']['as'][] = $a_view;
    }
}
if ($question['basetype'] == 'Q') {
    $qa_content['a_list']['title_tags'] = 'id="a_list_title"';
    if ($countfortitle > 0) {
        $split = $countfortitle == 1 ? qa_lang_html_sub_split('question/1_answer_title', '1', '1') : qa_lang_html_sub_split('question/x_answers_title', $countfortitle);
        if ($microdata) {
            $split['data'] = '<span itemprop="answerCount">' . $split['data'] . '</span>';
        }
        $qa_content['a_list']['title'] = $split['prefix'] . $split['data'] . $split['suffix'];
    } else {
        $qa_content['a_list']['title_tags'] .= ' style="display:none;" ';
Example #3
0
    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";
        //	Send back the HTML
        $themeclass->c_list_items($c_list['cs']);
        return;
    }
}
echo "QA_AJAX_RESPONSE\n0\n";
// fall back to non-Ajax submission if there were any problems
/*
	Omit PHP closing tag to help avoid accidental output
*/
     }
     if ($answer['deleteable']) {
         $a_view['form']['buttons']['delete'] = array('tags' => 'NAME="dodeletea_' . qa_html($answerid) . '"', 'label' => qa_lang_html('question/delete_button'), 'popup' => qa_lang_html('question/delete_a_popup'));
     }
     if ($answer['claimable']) {
         $a_view['form']['buttons']['claim'] = array('tags' => 'NAME="doclaima_' . qa_html($answerid) . '"', 'label' => qa_lang_html('question/claim_button'));
     }
     if ($answer['followable']) {
         $a_view['form']['buttons']['follow'] = array('tags' => 'NAME="dofollowa_' . qa_html($answerid) . '"', 'label' => qa_lang_html('question/follow_button'), 'popup' => qa_lang_html('question/follow_a_popup'));
     }
     if ($answer['commentbutton']) {
         $a_view['form']['buttons']['comment'] = array('tags' => 'NAME="docommenta_' . qa_html($answerid) . '"', 'label' => qa_lang_html('question/comment_button'), 'popup' => qa_lang_html('question/comment_a_popup'));
     }
 }
 //	Prepare content for comments on this answer, plus add or edit comment forms
 $a_view['c_list'] = qa_page_q_comment_follow_list($answer);
 // ...for viewing
 if ($formtype == 'c_add' && $formpostid == $answerid) {
     // ...to be added
     $a_view['c_form'] = qa_page_q_add_c_form($answerid);
 } else {
     if ($formtype == 'c_edit' && @$commentsfollows[$formpostid]['parentid'] == $answerid) {
         // ...being edited
         $a_view['c_form'] = qa_page_q_edit_c_form($formpostid, $answerid);
     }
 }
 //	Determine this answer's place in the order on the page
 if ($answer['hidden']) {
     $a_view['priority'] = 10000 + $priority++;
 } elseif ($answer['isselected'] && qa_opt('show_selected_first')) {
     $a_view['priority'] = 0;
function qa_page_q_edit_a_form($answerid)
{
    require_once QA_INCLUDE_DIR . 'qa-util-string.php';
    global $questionid, $question, $answers, $inacontent, $inaformat, $inaeditor, $aerrors, $qa_content, $innotify, $inemail, $jumptoanchor, $commentsfollows;
    $answer = $answers[$answerid];
    $content = isset($inacontent) ? $inacontent : $answer['content'];
    $format = isset($inaformat) ? $inaformat : $answer['format'];
    $editorname = isset($inaeditor) ? $inaeditor : qa_opt('editor_for_as');
    $editor = qa_load_editor($content, $format, $editorname);
    $hascomments = false;
    foreach ($commentsfollows as $commentfollow) {
        if ($commentfollow['parentid'] == $answerid) {
            $hascomments = true;
        }
    }
    $form = array('title' => '<A NAME="a_edit">' . qa_lang_html('question/edit_a_title') . '</A>', 'style' => 'tall', 'fields' => array('content' => array_merge($editor->get_field($qa_content, $content, $format, 'acontent', 12, true), array('error' => qa_html(@$aerrors['content'])))), 'buttons' => array('save' => array('label' => qa_lang_html('main/save_button')), 'cancel' => array('tags' => 'NAME="docancel"', 'label' => qa_lang_html('main/cancel_button'))), 'hidden' => array('editor' => qa_html($editorname), 'dosavea_' . qa_html($answerid) => '1'));
    //	Show option to convert this answer to a comment, if appropriate
    $commentonoptions = array();
    $lastbeforeid = $questionid;
    // used to find last post created before this answer - this is default given
    $lastbeforetime = $question['created'];
    if ($question['commentable']) {
        $commentonoptions[$questionid] = qa_lang_html('question/comment_on_q') . qa_html(qa_shorten_string_line($question['title'], 80));
    }
    foreach ($answers as $otheranswer) {
        if ($otheranswer['postid'] != $answerid && $otheranswer['created'] < $answer['created'] && $otheranswer['commentable'] && !$otheranswer['hidden']) {
            $commentonoptions[$otheranswer['postid']] = qa_lang_html('question/comment_on_a') . qa_html(qa_shorten_string_line(qa_viewer_text($otheranswer['content'], $otheranswer['format']), 80));
            if ($otheranswer['created'] > $lastbeforetime) {
                $lastbeforeid = $otheranswer['postid'];
                $lastebeforetime = $otheranswer['created'];
            }
        }
    }
    if (count($commentonoptions)) {
        $form['fields']['tocomment'] = array('tags' => 'NAME="tocomment" ID="tocomment"', 'label' => '<SPAN ID="tocomment_shown">' . qa_lang_html('question/a_convert_to_c_on') . '</SPAN>' . '<SPAN ID="tocomment_hidden" STYLE="display:none;">' . qa_lang_html('question/a_convert_to_c') . '</SPAN>', 'type' => 'checkbox', 'tight' => true);
        $form['fields']['commenton'] = array('tags' => 'NAME="commenton"', 'id' => 'commenton', 'type' => 'select', 'note' => qa_lang_html($hascomments ? 'question/a_convert_warn_cs' : 'question/a_convert_warn'), 'options' => $commentonoptions, 'value' => @$commentonoptions[$lastbeforeid]);
        qa_set_display_rules($qa_content, array('commenton' => 'tocomment', 'tocomment_shown' => 'tocomment', 'tocomment_hidden' => '!tocomment'));
    }
    //	Show notification field if appropriate
    if ($answer['isbyuser']) {
        qa_set_up_notify_fields($qa_content, $form['fields'], 'A', qa_get_logged_in_email(), isset($innotify) ? $innotify : !empty($answer['notify']), isset($inemail) ? $inemail : @$answer['notify'], @$aerrors['email']);
    }
    $form['c_list'] = qa_page_q_comment_follow_list($answer);
    $jumptoanchor = 'a_edit';
    return $form;
}