]> git.wh0rd.org - tt-rss.git/blob - backend.php
modify include path order (closes #514)
[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 $update_methods = array(
97 0 => __("Default"),
98 1 => __("Magpie"),
99 2 => __("SimplePie"));
100
101 if (DEFAULT_UPDATE_METHOD == "1") {
102 $update_methods[0] .= ' (SimplePie)';
103 } else {
104 $update_methods[0] .= ' (Magpie)';
105 }
106
107 $access_level_names = array(
108 0 => __("User"),
109 5 => __("Power User"),
110 10 => __("Administrator"));
111
112 #$error = sanity_check($link);
113
114 #if ($error['code'] != 0 && $op != "logout") {
115 # print json_encode(array("error" => $error));
116 # return;
117 #}
118
119 $op = str_replace("-", "_", $op);
120
121 if (class_exists($op)) {
122 $handler = new $op($link, $_REQUEST);
123
124 if ($handler && is_subclass_of($handler, 'Handler')) {
125 if (validate_csrf($csrf_token) || $handler->csrf_ignore($method)) {
126 if ($handler->before($method)) {
127 if ($method && method_exists($handler, $method)) {
128 $handler->$method();
129 }
130 $handler->after();
131 return;
132 } else {
133 header("Content-Type: text/plain");
134 print json_encode(array("error" => array("code" => 6)));
135 return;
136 }
137 } else {
138 header("Content-Type: text/plain");
139 print json_encode(array("error" => array("code" => 6)));
140 return;
141 }
142 }
143 }
144
145 header("Content-Type: text/plain");
146 print json_encode(array("error" => array("code" => 7)));
147
148 // We close the connection to database.
149 db_close($link);
150 ?>