]> git.wh0rd.org - tt-rss.git/blob - backend.php
add Pref_Users class
[tt-rss.git] / backend.php
1 <?php
2 set_include_path(get_include_path() . PATH_SEPARATOR . "include");
3
4 /* remove ill effects of magic quotes */
5
6 if (get_magic_quotes_gpc()) {
7 function stripslashes_deep($value) {
8 $value = is_array($value) ?
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);
17 }
18
19 function __autoload($class) {
20 $file = "classes/".strtolower(basename($class)).".php";
21 if (file_exists($file)) {
22 require $file;
23 }
24 }
25
26 $op = $_REQUEST["op"];
27
28 require_once "functions.php";
29 if ($op != "share") require_once "sessions.php";
30 require_once "sanity_check.php";
31 require_once "config.php";
32 require_once "db.php";
33 require_once "db-prefs.php";
34
35 no_cache_incantation();
36
37 startup_gettext();
38
39 $script_started = getmicrotime();
40
41 $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
42
43 if (!$link) {
44 if (DB_TYPE == "mysql") {
45 print mysql_error();
46 }
47 // PG seems to display its own errors just fine by default.
48 return;
49 }
50
51 init_connection($link);
52
53 $method = $_REQUEST['subop'] ? $_REQUEST['subop'] : $_REQUEST["method"];
54
55 header("Content-Type: text/plain; charset=utf-8");
56
57 if (ENABLE_GZIP_OUTPUT) {
58 ob_start("ob_gzhandler");
59 }
60
61 if (SINGLE_USER_MODE) {
62 authenticate_user($link, "admin", null);
63 }
64
65 $public_calls = array("globalUpdateFeeds", "rss", "getUnread", "getProfiles", "share",
66 "fbexport", "logout", "pubsub");
67
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))) {
74 if ($op == 'pref-feeds' && $method == 'add') {
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 }
82 return;
83 }
84
85 $purge_intervals = array(
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"));
93
94 $update_intervals = array(
95 0 => __("Default interval"),
96 -1 => __("Disable updates"),
97 15 => __("Each 15 minutes"),
98 30 => __("Each 30 minutes"),
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"),
109 60 => __("Hourly"),
110 240 => __("Each 4 hours"),
111 720 => __("Each 12 hours"),
112 1440 => __("Daily"),
113 10080 => __("Weekly"));
114
115 $update_methods = array(
116 0 => __("Default"),
117 1 => __("Magpie"),
118 2 => __("SimplePie"),
119 3 => __("Twitter OAuth"));
120
121 if (DEFAULT_UPDATE_METHOD == "1") {
122 $update_methods[0] .= ' (SimplePie)';
123 } else {
124 $update_methods[0] .= ' (Magpie)';
125 }
126
127 $access_level_names = array(
128 0 => __("User"),
129 5 => __("Power User"),
130 10 => __("Administrator"));
131
132 $error = sanity_check($link);
133
134 if ($error['code'] != 0 && $op != "logout") {
135 print json_encode(array("error" => $error));
136 return;
137 }
138
139 $op = str_replace("-", "_", $op);
140
141 if (class_exists($op)) {
142 $handler = new $op($link, $_REQUEST);
143
144 if ($handler) {
145 if ($handler->before()) {
146 if ($method && method_exists($handler, $method)) {
147 $handler->$method();
148 } else if (method_exists($handler, 'index')) {
149 $handler->index();
150 }
151 $handler->after();
152 return;
153 }
154 }
155 }
156
157 switch($op) { // Select action according to $op value.
158
159 case "pref_filters":
160 require_once "modules/pref-filters.php";
161 module_pref_filters($link);
162 break; // pref-filters
163
164 case "pref_instances":
165 require_once "modules/pref-instances.php";
166 module_pref_instances($link);
167 break; // pref-instances
168
169 default:
170 header("Content-Type: text/plain");
171 print json_encode(array("error" => array("code" => 7)));
172 break; // fallback
173 } // Select action according to $op value.
174
175 // We close the connection to database.
176 db_close($link);
177 ?>