qa-ajax.php 2.46 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.php
	Version: See define()s at top of qa-include/qa-base.php
	Description: Front line of response to Ajax requests, routing as appropriate


	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
	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
*/

//	Output this header as early as possible

	header('Content-Type: text/plain; charset=utf-8');


//	Ensure no PHP errors are shown in the Ajax response

	@ini_set('display_errors', 0);


//	Load the Q2A base file which sets up a bunch of crucial functions

	require 'qa-base.php';

	qa_report_process_stage('init_ajax');
Scott Vivian committed
42

Gideon Greenspan committed
43 44 45 46 47 48

//	Get general Ajax parameters from the POST payload, and clear $_GET

	qa_set_request(qa_post_text('qa_request'), qa_post_text('qa_root'));

	$_GET=array(); // for qa_self_html()
Scott Vivian committed
49

Gideon Greenspan committed
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76

//	Database failure handler

	function qa_ajax_db_fail_handler()
	{
		echo "QA_AJAX_RESPONSE\n0\nA database error occurred.";
		qa_exit('error');
	}


//	Perform the appropriate Ajax operation

	$routing=array(
		'notice' => 'qa-ajax-notice.php',
		'favorite' => 'qa-ajax-favorite.php',
		'vote' => 'qa-ajax-vote.php',
		'recalc' => 'qa-ajax-recalc.php',
		'mailing' => 'qa-ajax-mailing.php',
		'version' => 'qa-ajax-version.php',
		'category' => 'qa-ajax-category.php',
		'asktitle' => 'qa-ajax-asktitle.php',
		'answer' => 'qa-ajax-answer.php',
		'comment' => 'qa-ajax-comment.php',
		'click_a' => 'qa-ajax-click-answer.php',
		'click_c' => 'qa-ajax-click-comment.php',
		'click_admin' => 'qa-ajax-click-admin.php',
		'show_cs' => 'qa-ajax-show-comments.php',
Gideon Greenspan committed
77 78
		'wallpost' => 'qa-ajax-wallpost.php',
		'click_wall' => 'qa-ajax-click-wall.php',
Gideon Greenspan committed
79
	);
Scott Vivian committed
80

Gideon Greenspan committed
81
	$operation=qa_post_text('qa_operation');
Scott Vivian committed
82

Gideon Greenspan committed
83 84 85 86
	if (isset($routing[$operation])) {
		qa_db_connect('qa_ajax_db_fail_handler');

		require QA_INCLUDE_DIR.$routing[$operation];
Scott Vivian committed
87

Gideon Greenspan committed
88 89 90 91 92 93 94
		qa_db_disconnect();
	}


/*
	Omit PHP closing tag to help avoid accidental output
*/