1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
/*
Question2Answer by Gideon Greenspan and contributors
http://www.question2answer.org/
File: qa-include/qa-ajax.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.
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');
// 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()
// 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' => 'notice.php',
'favorite' => 'favorite.php',
'vote' => 'vote.php',
'recalc' => 'recalc.php',
'mailing' => 'mailing.php',
'version' => 'version.php',
'category' => 'category.php',
'asktitle' => 'asktitle.php',
'answer' => 'answer.php',
'comment' => 'comment.php',
'click_a' => 'click-answer.php',
'click_c' => 'click-comment.php',
'click_admin' => 'click-admin.php',
'show_cs' => 'show-comments.php',
'wallpost' => 'wallpost.php',
'click_wall' => 'click-wall.php',
'click_pm' => 'click-pm.php',
);
$operation=qa_post_text('qa_operation');
if (isset($routing[$operation])) {
qa_db_connect('qa_ajax_db_fail_handler');
require QA_INCLUDE_DIR.'ajax/'.$routing[$operation];
qa_db_disconnect();
}
/*
Omit PHP closing tag to help avoid accidental output
*/