]> git.wh0rd.org - tt-rss.git/blame - backend.php
implement ProtectedHandler
[tt-rss.git] / backend.php
CommitLineData
1d3a17c7 1<?php
107d0cf3
AD
2 set_include_path(get_include_path() . PATH_SEPARATOR . "include");
3
ce885e21
AD
4 /* remove ill effects of magic quotes */
5
5fa17372 6 if (get_magic_quotes_gpc()) {
c0793f64 7 function stripslashes_deep($value) {
009646d2 8 $value = is_array($value) ?
c0793f64
AD
9 array_map('stripslashes_deep', $value) : stripslashes($value);
10 return $value;
11 }
12
13 $_POST = array_map('stripslashes_deep', $_POST);
14 $_GET = array_map('stripslashes_deep', $_GET);
15 $_COOKIE = array_map('stripslashes_deep', $_COOKIE);
16 $_REQUEST = array_map('stripslashes_deep', $_REQUEST);
ce885e21
AD
17 }
18
d5112468
AD
19 function __autoload($class) {
20 $file = "classes/".strtolower(basename($class)).".php";
21 if (file_exists($file)) {
22 require $file;
23 }
24 }
25
f9da2388
AD
26 $op = $_REQUEST["op"];
27
fb074239 28 require_once "functions.php";
f9da2388 29 if ($op != "share") require_once "sessions.php";
657770a0
AD
30 require_once "sanity_check.php";
31 require_once "config.php";
af106b0e
AD
32 require_once "db.php";
33 require_once "db-prefs.php";
657770a0 34
dc56b3b7 35 no_cache_incantation();
8d039718 36
7b26a148 37 startup_gettext();
dc56b3b7 38
7f0acba7
AD
39 $script_started = getmicrotime();
40
009646d2 41 $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
7f0acba7
AD
42
43 if (!$link) {
44 if (DB_TYPE == "mysql") {
45 print mysql_error();
46 }
009646d2 47 // PG seems to display its own errors just fine by default.
7f0acba7
AD
48 return;
49 }
50
f29ba148 51 init_connection($link);
7f0acba7 52
1395083e 53 $method = $_REQUEST['subop'] ? $_REQUEST['subop'] : $_REQUEST["method"];
3f363052
AD
54
55 header("Content-Type: text/plain; charset=utf-8");
262bd8ea 56
bd202c3f
AD
57 if (ENABLE_GZIP_OUTPUT) {
58 ob_start("ob_gzhandler");
59 }
60
9c883208
AD
61 if (SINGLE_USER_MODE) {
62 authenticate_user($link, "admin", null);
63 }
64
e0d91d84
AD
65 $public_calls = array("globalUpdateFeeds", "rss", "getUnread", "getProfiles", "share",
66 "fbexport", "logout", "pubsub");
009646d2 67
e0d91d84
AD
68 if (array_search($op, $public_calls) !== false) {
69
70 handle_public_request($link, $op);
71 return;
72
73 } else if (!($_SESSION["uid"] && validate_session($link))) {
1395083e 74 if ($op == 'pref-feeds' && $method == 'add') {
d0f73380
AD
75 header("Content-Type: text/html");
76 login_sequence($link);
77 render_login_form($link);
78 } else {
79 header("Content-Type: text/plain");
80 print json_encode(array("error" => array("code" => 6)));
81 }
009646d2 82 return;
262bd8ea 83 }
1c7f75ed 84
ad815c71 85 $purge_intervals = array(
d1db26aa
AD
86 0 => __("Use default"),
87 -1 => __("Never purge"),
88 5 => __("1 week old"),
89 14 => __("2 weeks old"),
90 31 => __("1 month old"),
91 60 => __("2 months old"),
92 90 => __("3 months old"));
ad815c71
AD
93
94 $update_intervals = array(
ecace165 95 0 => __("Default interval"),
d1db26aa 96 -1 => __("Disable updates"),
1e7cbe16 97 15 => __("Each 15 minutes"),
d1db26aa 98 30 => __("Each 30 minutes"),
505f2f0e
AD
99 60 => __("Hourly"),
100 240 => __("Each 4 hours"),
101 720 => __("Each 12 hours"),
102 1440 => __("Daily"),
103 10080 => __("Weekly"));
104
105 $update_intervals_nodefault = array(
106 -1 => __("Disable updates"),
107 15 => __("Each 15 minutes"),
108 30 => __("Each 30 minutes"),
d1db26aa
AD
109 60 => __("Hourly"),
110 240 => __("Each 4 hours"),
111 720 => __("Each 12 hours"),
112 1440 => __("Daily"),
113 10080 => __("Weekly"));
ad815c71 114
16211ddb 115 $update_methods = array(
ecace165 116 0 => __("Default"),
0dd9c0cf 117 1 => __("Magpie"),
009646d2 118 2 => __("SimplePie"),
b3009bcd 119 3 => __("Twitter OAuth"));
16211ddb 120
78a5c296 121 if (DEFAULT_UPDATE_METHOD == "1") {
16211ddb
AD
122 $update_methods[0] .= ' (SimplePie)';
123 } else {
124 $update_methods[0] .= ' (Magpie)';
125 }
126
3c5783b7 127 $access_level_names = array(
009646d2 128 0 => __("User"),
a88d37e5 129 5 => __("Power User"),
d1db26aa 130 10 => __("Administrator"));
3c5783b7 131
ebb948c2
AD
132 $error = sanity_check($link);
133
2376ad49 134 if ($error['code'] != 0 && $op != "logout") {
ebb948c2
AD
135 print json_encode(array("error" => $error));
136 return;
137 }
023fe037 138
afcfe6ca
AD
139 $op = str_replace("-", "_", $op);
140
d5112468
AD
141 if (class_exists($op)) {
142 $handler = new $op($link, $_REQUEST);
45004d43 143
d5112468
AD
144 if ($handler) {
145 if ($handler->before()) {
3f363052
AD
146 if ($method && method_exists($handler, $method)) {
147 $handler->$method();
148 } else if (method_exists($handler, 'index')) {
149 $handler->index();
d5112468 150 }
3f363052
AD
151 $handler->after();
152 return;
d5112468
AD
153 }
154 }
155 }
156
157 switch($op) { // Select action according to $op value.
678dda79 158 case "pref_instances":
1c9d14ad 159 require_once "modules/pref-instances.php";
373266eb
AD
160 module_pref_instances($link);
161 break; // pref-instances
162
1ca77e0a
AD
163 default:
164 header("Content-Type: text/plain");
165 print json_encode(array("error" => array("code" => 7)));
373266eb 166 break; // fallback
5ab9791f 167 } // Select action according to $op value.
ba7e88e5 168
45004d43 169 // We close the connection to database.
4b3dff6e 170 db_close($link);
1cd17194 171?>