]> git.wh0rd.org - tt-rss.git/blame - backend.php
reinstate error handlers; better DB error reporting on failed queries
[tt-rss.git] / backend.php
CommitLineData
1d3a17c7 1<?php
88e8fb3a
AD
2 set_include_path(dirname(__FILE__) ."/include" . PATH_SEPARATOR .
3 get_include_path());
107d0cf3 4
ce885e21
AD
5 /* remove ill effects of magic quotes */
6
5fa17372 7 if (get_magic_quotes_gpc()) {
c0793f64 8 function stripslashes_deep($value) {
009646d2 9 $value = is_array($value) ?
c0793f64
AD
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);
ce885e21
AD
18 }
19
f9da2388 20 $op = $_REQUEST["op"];
5f0a3741
AD
21 @$method = $_REQUEST['subop'] ? $_REQUEST['subop'] : $_REQUEST["method"];
22
8484ce22
AD
23 if (!$method)
24 $method = 'index';
25 else
26 $method = strtolower($method);
27
5f0a3741
AD
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 }
f9da2388 37
66b042fc 38 @$csrf_token = $_REQUEST['csrf_token'];
8484ce22 39
404e2e36 40 require_once "autoload.php";
5f0a3741 41 require_once "sessions.php";
23419d11 42 require_once "functions.php";
657770a0 43 require_once "config.php";
af106b0e
AD
44 require_once "db.php";
45 require_once "db-prefs.php";
657770a0 46
7b26a148 47 startup_gettext();
dc56b3b7 48
1ebf3b97 49 $script_started = microtime(true);
7f0acba7 50
009646d2 51 $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
7f0acba7 52
ba68b681 53 if (!init_plugins($link)) return;
3f363052 54
7d1a91d5 55 header("Content-Type: text/json; charset=utf-8");
262bd8ea 56
6a79e8af 57 if (ENABLE_GZIP_OUTPUT && function_exists("ob_gzhandler")) {
bd202c3f
AD
58 ob_start("ob_gzhandler");
59 }
60
9c883208
AD
61 if (SINGLE_USER_MODE) {
62 authenticate_user($link, "admin", null);
63 }
64
de612e7a 65 if ($_SESSION["uid"]) {
ccfa9080
AD
66 if (!validate_session($link)) {
67 header("Content-Type: text/json");
68 print json_encode(array("error" => array("code" => 6)));
69 return;
70 }
de612e7a
AD
71 load_user_plugins($link, $_SESSION["uid"]);
72 }
73
ad815c71 74 $purge_intervals = array(
d1db26aa
AD
75 0 => __("Use default"),
76 -1 => __("Never purge"),
77 5 => __("1 week old"),
78 14 => __("2 weeks old"),
79 31 => __("1 month old"),
80 60 => __("2 months old"),
81 90 => __("3 months old"));
ad815c71
AD
82
83 $update_intervals = array(
ecace165 84 0 => __("Default interval"),
d1db26aa 85 -1 => __("Disable updates"),
1e7cbe16 86 15 => __("Each 15 minutes"),
d1db26aa 87 30 => __("Each 30 minutes"),
505f2f0e
AD
88 60 => __("Hourly"),
89 240 => __("Each 4 hours"),
90 720 => __("Each 12 hours"),
91 1440 => __("Daily"),
92 10080 => __("Weekly"));
93
94 $update_intervals_nodefault = array(
95 -1 => __("Disable updates"),
96 15 => __("Each 15 minutes"),
97 30 => __("Each 30 minutes"),
d1db26aa
AD
98 60 => __("Hourly"),
99 240 => __("Each 4 hours"),
100 720 => __("Each 12 hours"),
101 1440 => __("Daily"),
102 10080 => __("Weekly"));
ad815c71 103
3c5783b7 104 $access_level_names = array(
009646d2 105 0 => __("User"),
a88d37e5 106 5 => __("Power User"),
d1db26aa 107 10 => __("Administrator"));
3c5783b7 108
545ca067 109 #$error = sanity_check($link);
ebb948c2 110
545ca067
AD
111 #if ($error['code'] != 0 && $op != "logout") {
112 # print json_encode(array("error" => $error));
113 # return;
114 #}
023fe037 115
afcfe6ca
AD
116 $op = str_replace("-", "_", $op);
117
8dcb2b47
AD
118 global $pluginhost;
119 $override = $pluginhost->lookup_handler($op, $method);
45004d43 120
8dcb2b47
AD
121 if (class_exists($op) || $override) {
122
123 if ($override) {
124 $handler = $override;
125 } else {
126 $handler = new $op($link, $_REQUEST);
127 }
128
129 if ($handler && implements_interface($handler, 'IHandler')) {
8484ce22
AD
130 if (validate_csrf($csrf_token) || $handler->csrf_ignore($method)) {
131 if ($handler->before($method)) {
132 if ($method && method_exists($handler, $method)) {
133 $handler->$method();
19c73507
AD
134 } else {
135 if (method_exists($handler, "catchall")) {
136 $handler->catchall($method);
137 }
8484ce22
AD
138 }
139 $handler->after();
140 return;
97acbaf1 141 } else {
7d1a91d5 142 header("Content-Type: text/json");
97acbaf1
AD
143 print json_encode(array("error" => array("code" => 6)));
144 return;
d5112468 145 }
8484ce22 146 } else {
7d1a91d5 147 header("Content-Type: text/json");
8484ce22 148 print json_encode(array("error" => array("code" => 6)));
3f363052 149 return;
d5112468
AD
150 }
151 }
152 }
153
7d1a91d5 154 header("Content-Type: text/json");
5f0a3741 155 print json_encode(array("error" => array("code" => 7)));
ba7e88e5 156
45004d43 157 // We close the connection to database.
4b3dff6e 158 db_close($link);
1cd17194 159?>