qa-ajax-click-comment.php 3.06 KB
Newer Older
Gideon Greenspan committed
1 2 3 4 5 6 7
<?php

/*
	Question2Answer (c) Gideon Greenspan

	http://www.question2answer.org/

Scott Vivian committed
8

Gideon Greenspan committed
9 10 11 12 13 14 15 16 17
	File: qa-include/qa-ajax-click-comment.php
	Version: See define()s at top of qa-include/qa-base.php
	Description: Server-side response to Ajax single clicks on comments


	This program is free software; you can redistribute it and/or
	modify it under the terms of the GNU General Public License
	as published by the Free Software Foundation; either version 2
	of the License, or (at your option) any later version.
Scott Vivian committed
18

Gideon Greenspan committed
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	More about this license: http://www.question2answer.org/license.php
*/

	require_once QA_INCLUDE_DIR.'qa-app-cookies.php';
	require_once QA_INCLUDE_DIR.'qa-app-format.php';
	require_once QA_INCLUDE_DIR.'qa-app-users.php';
	require_once QA_INCLUDE_DIR.'qa-db-selects.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 comment

	$commentid=qa_post_text('commentid');
	$questionid=qa_post_text('questionid');
	$parentid=qa_post_text('parentid');

	$userid=qa_get_logged_in_userid();

Gideon Greenspan committed
43
	list($comment, $question, $parent, $children)=qa_db_select_with_pending(
Gideon Greenspan committed
44 45 46 47 48 49
		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)
	);

Scott Vivian committed
50

Gideon Greenspan committed
51 52 53 54 55 56 57 58
//	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
Scott Vivian committed
59

Gideon Greenspan committed
60 61
		if (qa_page_q_single_click_c($comment, $question, $parent, $error)) {
			$comment=qa_db_select_with_pending(qa_db_full_post_selectspec($userid, $commentid));
Scott Vivian committed
62

Gideon Greenspan committed
63 64 65 66

		//	If so, page content to be updated via Ajax

			echo "QA_AJAX_RESPONSE\n1";
Scott Vivian committed
67 68


Gideon Greenspan committed
69
		//	If the comment was not deleted...
Scott Vivian committed
70

Gideon Greenspan committed
71 72 73 74
			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);
Scott Vivian committed
75

Gideon Greenspan committed
76
				$usershtml=qa_userids_handles_html(array($comment), true);
Scott Vivian committed
77

Gideon Greenspan committed
78
				$c_view=qa_page_q_comment_view($question, $parent, $comment, $usershtml, false);
Scott Vivian committed
79

Gideon Greenspan committed
80
				$themeclass=qa_load_theme_class(qa_get_site_theme(), 'ajax-comment', null, null);
Scott Vivian committed
81

Gideon Greenspan committed
82 83

			//	... send back the HTML for it
Scott Vivian committed
84

Gideon Greenspan committed
85
				echo "\n";
Scott Vivian committed
86

Gideon Greenspan committed
87 88
				$themeclass->c_list_item($c_view);
			}
Scott Vivian committed
89

Gideon Greenspan committed
90 91 92
			return;
		}
	}
Scott Vivian committed
93 94


Gideon Greenspan committed
95
	echo "QA_AJAX_RESPONSE\n0\n"; // fall back to non-Ajax submission if something failed
Scott Vivian committed
96 97


Gideon Greenspan committed
98 99 100
/*
	Omit PHP closing tag to help avoid accidental output
*/