]> git.wh0rd.org - tt-rss.git/blob - backend.php
include path fix for lighttpd
[tt-rss.git] / backend.php
1 <?php
2 set_include_path(get_include_path() . PATH_SEPARATOR .
3 dirname(__FILE__) . "/include");
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 /* Public calls compatibility shim */
24
25 $public_calls = array("globalUpdateFeeds", "rss", "getUnread", "getProfiles", "share",
26 "fbexport", "logout", "pubsub");
27
28 if (array_search($op, $public_calls) !== false) {
29 header("Location: public.php?" . $_SERVER['QUERY_STRING']);
30 return;
31 }
32
33 require_once "functions.php";
34 require_once "sessions.php";
35 require_once "sanity_check.php";
36 require_once "config.php";
37 require_once "db.php";
38 require_once "db-prefs.php";
39
40 no_cache_incantation();
41
42 startup_gettext();
43
44 $script_started = getmicrotime();
45
46 $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
47
48 if (!init_connection($link)) return;
49
50 header("Content-Type: text/plain; charset=utf-8");
51
52 if (ENABLE_GZIP_OUTPUT) {
53 ob_start("ob_gzhandler");
54 }
55
56 if (SINGLE_USER_MODE) {
57 authenticate_user($link, "admin", null);
58 }
59
60 // TODO remove and handle within Handlers
61
62 if (!($_SESSION["uid"] && validate_session($link))) {
63 if ($op == 'pref-feeds' && $method == 'add') {
64 header("Content-Type: text/html");
65 login_sequence($link);
66 render_login_form($link);
67 } else {
68 header("Content-Type: text/plain");
69 print json_encode(array("error" => array("code" => 6)));
70 }
71 return;
72 }
73
74 $purge_intervals = array(
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"));
82
83 $update_intervals = array(
84 0 => __("Default interval"),
85 -1 => __("Disable updates"),
86 15 => __("Each 15 minutes"),
87 30 => __("Each 30 minutes"),
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"),
98 60 => __("Hourly"),
99 240 => __("Each 4 hours"),
100 720 => __("Each 12 hours"),
101 1440 => __("Daily"),
102 10080 => __("Weekly"));
103
104 $update_methods = array(
105 0 => __("Default"),
106 1 => __("Magpie"),
107 2 => __("SimplePie"),
108 3 => __("Twitter OAuth"));
109
110 if (DEFAULT_UPDATE_METHOD == "1") {
111 $update_methods[0] .= ' (SimplePie)';
112 } else {
113 $update_methods[0] .= ' (Magpie)';
114 }
115
116 $access_level_names = array(
117 0 => __("User"),
118 5 => __("Power User"),
119 10 => __("Administrator"));
120
121 $error = sanity_check($link);
122
123 if ($error['code'] != 0 && $op != "logout") {
124 print json_encode(array("error" => $error));
125 return;
126 }
127
128 function __autoload($class) {
129 $file = "classes/".strtolower(basename($class)).".php";
130 if (file_exists($file)) {
131 require $file;
132 }
133 }
134
135 $op = str_replace("-", "_", $op);
136
137 if (class_exists($op)) {
138 $handler = new $op($link, $_REQUEST);
139
140 if ($handler) {
141 if ($handler->before($method)) {
142 if ($method && method_exists($handler, $method)) {
143 $handler->$method();
144 } else if (method_exists($handler, 'index')) {
145 $handler->index();
146 }
147 $handler->after();
148 return;
149 }
150 }
151 }
152
153 header("Content-Type: text/plain");
154 print json_encode(array("error" => array("code" => 7)));
155
156 // We close the connection to database.
157 db_close($link);
158 ?>