Beispiel #1
0
$parentid = qa_post_text('parentid');
$userid = qa_get_logged_in_userid();
list($comment, $question, $parent, $children) = qa_db_select_with_pending(qa_db_full_post_selectspec($userid, $commentid), qa_db_full_post_selectspec($userid, $questionid), qa_db_full_post_selectspec($userid, $parentid), qa_db_full_child_posts_selectspec($userid, $parentid));
//	Check if there was an operation that succeeded
if (@$comment['basetype'] == 'C' && @$question['basetype'] == 'Q' && (@$parent['basetype'] == 'Q' || @$parent['basetype'] == 'A')) {
    $comment = $comment + qa_page_q_post_rules($comment, $parent, $children, null);
    // array union
    if (qa_page_q_single_click_c($comment, $question, $parent, $error)) {
        $comment = qa_db_select_with_pending(qa_db_full_post_selectspec($userid, $commentid));
        //	If so, page content to be updated via Ajax
        echo "QA_AJAX_RESPONSE\n1";
        //	If the comment was not deleted...
        if (isset($comment)) {
            $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
            $comment = $comment + qa_page_q_post_rules($comment, $parent, $children, null);
            $usershtml = qa_userids_handles_html(array($comment), true);
            $c_view = qa_page_q_comment_view($question, $parent, $comment, $usershtml, false);
            $themeclass = qa_load_theme_class(qa_get_site_theme(), 'ajax-comment', null, null);
            //	... send back the HTML for it
            echo "\n";
            $themeclass->c_list_item($c_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
*/
        //	If so, page content to be updated via Ajax
        echo "QA_AJAX_RESPONSE\n1\n";
        //	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
/*
Beispiel #3
0
 //	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";
         //	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;
    $question['extra'] = $extravalue;
    $answers = qa_page_q_load_as($question, $childposts);
    $commentsfollows = qa_page_q_load_c_follows($question, $childposts, $achildposts);
    $question = $question + qa_page_q_post_rules($question, null, null, $childposts);
    // array union
    if ($question['selchildid'] && @$answers[$question['selchildid']]['type'] != 'A') {
        $question['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, $question, $answers, $achildposts);
        $answers[$key]['isselected'] = $answer['postid'] == $question['selchildid'];
    }
    foreach ($commentsfollows as $key => $commentfollow) {
        $parent = $commentfollow['parentid'] == $questionid ? $question : @$answers[$commentfollow['parentid']];
        $commentsfollows[$key] = $commentfollow + qa_page_q_post_rules($commentfollow, $parent, $commentsfollows, null);
    }
}
//	Deal with question not found or not viewable, otherwise report the view event
if (!isset($question)) {
    return include QA_INCLUDE_DIR . 'qa-page-not-found.php';
}
if (!$question['viewable']) {
    $qa_content = qa_content_prepare();
    if ($question['queued']) {
        $qa_content['error'] = qa_lang_html('question/q_waiting_approval');
    } elseif ($question['flagcount'] && !isset($question['lastuserid'])) {
        $qa_content['error'] = qa_lang_html('question/q_hidden_flagged');
    } elseif ($question['authorlast']) {
        $qa_content['error'] = qa_lang_html('question/q_hidden_author');
    } else {
 function do_select($data, $question)
 {
     $questionid = (int) @$data['action_data']['question_id'];
     $answerid = (int) @$data['action_id'];
     if ($questionid === null) {
         return false;
     }
     $userid = qa_get_logged_in_userid();
     require_once QA_INCLUDE_DIR . 'qa-app-posts.php';
     require_once QA_INCLUDE_DIR . 'qa-page-question-view.php';
     $qchildposts = qa_db_select_with_pending(qa_db_full_child_posts_selectspec($userid, $questionid));
     $question = $question + qa_page_q_post_rules($question, null, null, $qchildposts);
     // array union
     if (isset($data['action_data']['select']) && $question['aselectable'] && (!isset($answerid) || !isset($question['selchildid']) && !qa_opt('do_close_on_select'))) {
         // allowed to select
         qa_post_set_selchildid($questionid, $answerid, $userid);
         return true;
     } else {
         if (!isset($data['action_data']['select']) && $question['aselectable'] && isset($answerid) && (int) $question['selchildid'] == $answerid) {
             // allowed to unselect
             qa_post_set_selchildid($questionid, null, $userid);
             return true;
         }
     }
     return false;
 }
Beispiel #6
0
    require_once QA_INCLUDE_DIR . 'app/format.php';
    require_once QA_INCLUDE_DIR . 'app/post-create.php';
    require_once QA_INCLUDE_DIR . 'app/cookies.php';
    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
function qa_page_q_load_q()
{
    global $qa_login_userid, $questionid, $question, $parentquestion, $answers, $commentsfollows, $relatedcount, $relatedquestions, $question, $categories;
    list($question, $childposts, $achildposts, $parentquestion, $relatedquestions, $categories) = qa_db_select_with_pending(qa_db_full_post_selectspec($qa_login_userid, $questionid), qa_db_full_child_posts_selectspec($qa_login_userid, $questionid), qa_db_full_a_child_posts_selectspec($qa_login_userid, $questionid), qa_db_post_parent_q_selectspec($questionid), qa_db_related_qs_selectspec($qa_login_userid, $questionid), qa_db_category_nav_selectspec($questionid, true, true));
    if ($question['basetype'] != 'Q') {
        // don't allow direct viewing of other types of post
        $question = null;
    }
    $answers = array();
    $commentsfollows = array();
    foreach ($childposts as $postid => $post) {
        switch ($post['type']) {
            case 'Q':
                // never show follow-on Qs which have been hidden, even to admins
            // never show follow-on Qs which have been hidden, even to admins
            case 'C':
            case 'C_HIDDEN':
                $commentsfollows[$postid] = $post;
                break;
            case 'A':
            case 'A_HIDDEN':
                $answers[$postid] = $post;
                break;
        }
    }
    foreach ($achildposts as $postid => $post) {
        switch ($post['type']) {
            case 'Q':
            case 'Q_HIDDEN':
            case 'C':
            case 'C_HIDDEN':
                $commentsfollows[$postid] = $post;
                break;
        }
    }
    if (isset($question)) {
        $relatedcount = qa_opt('do_related_qs') ? 1 + qa_opt('page_size_related_qs') : 0;
        $relatedquestions = array_slice($relatedquestions, 0, $relatedcount);
        // includes question itself at this point
        qa_page_q_post_rules($question);
        if ($question['selchildid'] && @$answers[$question['selchildid']]['type'] != 'A') {
            $question['selchildid'] = null;
        }
        // if selected answer is hidden or somehow not there, consider it not selected
        foreach ($answers as $key => $answer) {
            $question['deleteable'] = false;
            qa_page_q_post_rules($answers[$key]);
            if ($answers[$key]['isbyuser'] && !qa_opt('allow_multi_answers')) {
                $question['answerbutton'] = false;
            }
            $answers[$key]['isselected'] = $answer['postid'] == $question['selchildid'];
        }
        foreach ($commentsfollows as $key => $commentfollow) {
            if ($commentfollow['parentid'] == $questionid) {
                $question['deleteable'] = false;
            }
            if (isset($answers[$commentfollow['parentid']])) {
                $answers[$commentfollow['parentid']]['deleteable'] = false;
            }
            qa_page_q_post_rules($commentsfollows[$key]);
        }
    }
}
        echo "QA_AJAX_RESPONSE\n1\n";
        //	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);
            $commentsfollows = qa_page_q_load_c_follows($question, $qchildposts, $achildposts);
            foreach ($commentsfollows as $key => $commentfollow) {
                $commentsfollows[$key] = $commentfollow + qa_page_q_post_rules($commentfollow, $answer, $commentsfollows, null);
            }
            $usershtml = qa_userids_handles_html(array_merge(array($answer), $commentsfollows), 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, $commentsfollows, false, $usershtml, false, null);
            $themeclass = qa_load_theme_class(qa_get_site_theme(), 'ajax-answer', null, null);
            $themeclass->initialize();
            //	... 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