]> git.wh0rd.org Git - tt-rss.git/blob - backend.php
cdm expandable: unify style with expanded
[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 "sessions.php";
41         require_once "functions.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 = microtime(true);
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/json; 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         if ($_SESSION["uid"]) {
67                 load_user_plugins($link, $_SESSION["uid"]);
68         }
69
70         $purge_intervals = array(
71                 0  => __("Use default"),
72                 -1 => __("Never purge"),
73                 5  => __("1 week old"),
74                 14 => __("2 weeks old"),
75                 31 => __("1 month old"),
76                 60 => __("2 months old"),
77                 90 => __("3 months old"));
78
79         $update_intervals = array(
80                 0   => __("Default interval"),
81                 -1  => __("Disable updates"),
82                 15  => __("Each 15 minutes"),
83                 30  => __("Each 30 minutes"),
84                 60  => __("Hourly"),
85                 240 => __("Each 4 hours"),
86                 720 => __("Each 12 hours"),
87                 1440 => __("Daily"),
88                 10080 => __("Weekly"));
89
90         $update_intervals_nodefault = array(
91                 -1  => __("Disable updates"),
92                 15  => __("Each 15 minutes"),
93                 30  => __("Each 30 minutes"),
94                 60  => __("Hourly"),
95                 240 => __("Each 4 hours"),
96                 720 => __("Each 12 hours"),
97                 1440 => __("Daily"),
98                 10080 => __("Weekly"));
99
100         $access_level_names = array(
101                 0 => __("User"),
102                 5 => __("Power User"),
103                 10 => __("Administrator"));
104
105         #$error = sanity_check($link);
106
107         #if ($error['code'] != 0 && $op != "logout") {
108         #       print json_encode(array("error" => $error));
109         #       return;
110         #}
111
112         $op = str_replace("-", "_", $op);
113
114         global $pluginhost;
115         $override = $pluginhost->lookup_handler($op, $method);
116
117         if (class_exists($op) || $override) {
118
119                 if ($override) {
120                         $handler = $override;
121                 } else {
122                         $handler = new $op($link, $_REQUEST);
123                 }
124
125                 if ($handler && implements_interface($handler, 'IHandler')) {
126                         if (validate_csrf($csrf_token) || $handler->csrf_ignore($method)) {
127                                 if ($handler->before($method)) {
128                                         if ($method && method_exists($handler, $method)) {
129                                                 $handler->$method();
130                                         } else {
131                                                 if (method_exists($handler, "catchall")) {
132                                                         $handler->catchall($method);
133                                                 }
134                                         }
135                                         $handler->after();
136                                         return;
137                                 } else {
138                                         header("Content-Type: text/json");
139                                         print json_encode(array("error" => array("code" => 6)));
140                                         return;
141                                 }
142                         } else {
143                                 header("Content-Type: text/json");
144                                 print json_encode(array("error" => array("code" => 6)));
145                                 return;
146                         }
147                 }
148         }
149
150         header("Content-Type: text/json");
151         print json_encode(array("error" => array("code" => 7)));
152
153         // We close the connection to database.
154         db_close($link);
155 ?>