Esempio n. 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
*/
function qa_page_q_comment_follow_list($parent, $commentsfollows, $alwaysfull, $usershtml, $formrequested, $formpostid)
{
    $parentid = $parent['postid'];
    $userid = qa_get_logged_in_userid();
    $cookieid = qa_cookie_get();
    $commentlist = array('tags' => 'ID="c' . qa_html($parentid) . '_list"', 'cs' => array());
    $showcomments = array();
    foreach ($commentsfollows as $commentfollowid => $commentfollow) {
        if ($commentfollow['parentid'] == $parentid && $commentfollow['viewable'] && $commentfollowid != $formpostid) {
            $showcomments[$commentfollowid] = $commentfollow;
        }
    }
    $countshowcomments = count($showcomments);
    if (!$alwaysfull && $countshowcomments > qa_opt('show_fewer_cs_from')) {
        $skipfirst = $countshowcomments - qa_opt('show_fewer_cs_count');
    } else {
        $skipfirst = 0;
    }
    if ($skipfirst == $countshowcomments) {
        // showing none
        if ($skipfirst == 1) {
            $expandtitle = qa_lang_html('question/show_1_comment');
        } else {
            $expandtitle = qa_lang_html_sub('question/show_x_comments', $skipfirst);
        }
    } else {
        if ($skipfirst == 1) {
            $expandtitle = qa_lang_html('question/show_1_previous_comment');
        } else {
            $expandtitle = qa_lang_html_sub('question/show_x_previous_comments', $skipfirst);
        }
    }
    if ($skipfirst > 0) {
        $commentlist['cs'][$parentid] = array('url' => qa_html('?state=showcomments-' . $parentid . '&show=' . $parentid . '#' . urlencode(qa_anchor($parent['basetype'], $parentid))), 'expand_tags' => 'onClick="return qa_show_comments(' . qa_js($parentid) . ', this);"', 'title' => $expandtitle);
    }
    foreach ($showcomments as $commentfollowid => $commentfollow) {
        if ($skipfirst > 0) {
            $skipfirst--;
        } elseif ($commentfollow['basetype'] == 'C') {
            $commentlist['cs'][$commentfollowid] = qa_page_q_comment_view($parent, $commentfollow, $usershtml, $formrequested);
        } elseif ($commentfollow['basetype'] == 'Q') {
            $htmloptions = qa_post_html_defaults('Q');
            $htmloptions['avatarsize'] = qa_opt('avatar_q_page_c_size');
            $commentlist['cs'][$commentfollowid] = qa_post_html_fields($commentfollow, $userid, $cookieid, $usershtml, null, $htmloptions);
        }
    }
    if (!count($commentlist['cs'])) {
        $commentlist['hidden'] = true;
    }
    return $commentlist;
}