]> git.wh0rd.org - tt-rss.git/blob - backend.php
remove magpie, fix article filter plugins
[tt-rss.git] / backend.php
1 <?php
2 set_include_path(dirname(__FILE__) ."/include" . PATH_SEPARATOR .
3 get_include_path());
4
5 /* remove ill effects of magic quotes */
6
7 if (get_magic_quotes_gpc()) {
8 function stripslashes_deep($value) {
9 $value = is_array($value) ?
10 array_map('stripslashes_deep', $value) : stripslashes($value);
11 return $value;
12 }
13
14 $_POST = array_map('stripslashes_deep', $_POST);
15 $_GET = array_map('stripslashes_deep', $_GET);
16 $_COOKIE = array_map('stripslashes_deep', $_COOKIE);
17 $_REQUEST = array_map('stripslashes_deep', $_REQUEST);
18 }
19
20 $op = $_REQUEST["op"];
21 @$method = $_REQUEST['subop'] ? $_REQUEST['subop'] : $_REQUEST["method"];
22
23 if (!$method)
24 $method = 'index';
25 else
26 $method = strtolower($method);
27
28 /* Public calls compatibility shim */
29
30 $public_calls = array("globalUpdateFeeds", "rss", "getUnread", "getProfiles", "share",
31 "fbexport", "logout", "pubsub");
32
33 if (array_search($op, $public_calls) !== false) {
34 header("Location: public.php?" . $_SERVER['QUERY_STRING']);
35 return;
36 }
37
38 @$csrf_token = $_REQUEST['csrf_token'];
39
40 require_once "functions.php";
41 require_once "sessions.php";
42 require_once "config.php";
43 require_once "db.php";
44 require_once "db-prefs.php";
45
46 no_cache_incantation();
47
48 startup_gettext();
49
50 $script_started = getmicrotime();
51
52 $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
53
54 if (!init_connection($link)) return;
55
56 header("Content-Type: text/plain; charset=utf-8");
57
58 if (ENABLE_GZIP_OUTPUT && function_exists("ob_gzhandler")) {
59 ob_start("ob_gzhandler");
60 }
61
62 if (SINGLE_USER_MODE) {
63 authenticate_user($link, "admin", null);
64 }
65
66 $purge_intervals = array(
67 0 => __("Use default"),
68 -1 => __("Never purge"),
69 5 => __("1 week old"),
70 14 => __("2 weeks old"),
71 31 => __("1 month old"),
72 60 => __("2 months old"),
73 90 => __("3 months old"));
74
75 $update_intervals = array(
76 0 => __("Default interval"),
77 -1 => __("Disable updates"),
78 15 => __("Each 15 minutes"),
79 30 => __("Each 30 minutes"),
80 60 => __("Hourly"),
81 240 => __("Each 4 hours"),
82 720 => __("Each 12 hours"),
83 1440 => __("Daily"),
84 10080 => __("Weekly"));
85
86 $update_intervals_nodefault = array(
87 -1 => __("Disable updates"),
88 15 => __("Each 15 minutes"),
89 30 => __("Each 30 minutes"),
90 60 => __("Hourly"),
91 240 => __("Each 4 hours"),
92 720 => __("Each 12 hours"),
93 1440 => __("Daily"),
94 10080 => __("Weekly"));
95
96 $access_level_names = array(
97 0 => __("User"),
98 5 => __("Power User"),
99 10 => __("Administrator"));
100
101 #$error = sanity_check($link);
102
103 #if ($error['code'] != 0 && $op != "logout") {
104 # print json_encode(array("error" => $error));
105 # return;
106 #}
107
108 $op = str_replace("-", "_", $op);
109
110 global $pluginhost;
111 $override = $pluginhost->lookup_handler($op, $method);
112
113 if (class_exists($op) || $override) {
114
115 if ($override) {
116 $handler = $override;
117 } else {
118 $handler = new $op($link, $_REQUEST);
119 }
120
121 if ($handler && implements_interface($handler, 'IHandler')) {
122 if (validate_csrf($csrf_token) || $handler->csrf_ignore($method)) {
123 if ($handler->before($method)) {
124 if ($method && method_exists($handler, $method)) {
125 $handler->$method();
126 } else {
127 if (method_exists($handler, "catchall")) {
128 $handler->catchall($method);
129 }
130 }
131 $handler->after();
132 return;
133 } else {
134 header("Content-Type: text/plain");
135 print json_encode(array("error" => array("code" => 6)));
136 return;
137 }
138 } else {
139 header("Content-Type: text/plain");
140 print json_encode(array("error" => array("code" => 6)));
141 return;
142 }
143 }
144 }
145
146 header("Content-Type: text/plain");
147 print json_encode(array("error" => array("code" => 7)));
148
149 // We close the connection to database.
150 db_close($link);
151 ?>