]> git.wh0rd.org - tt-rss.git/blob - backend.php
add pref_feeds 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 = strtolower($_REQUEST["method"]);
54 $mode = $_REQUEST["mode"];
55
56 /* if ((!$op || $op == "rss" || $op == "dlg") && !$_REQUEST["noxml"]) {
57 header("Content-Type: application/xml; charset=utf-8");
58 } else {
59 header("Content-Type: text/plain; charset=utf-8");
60 } */
61
62 header("Content-Type: text/plain; charset=utf-8");
63
64 if (ENABLE_GZIP_OUTPUT) {
65 ob_start("ob_gzhandler");
66 }
67
68 if (SINGLE_USER_MODE) {
69 authenticate_user($link, "admin", null);
70 }
71
72 $public_calls = array("globalUpdateFeeds", "rss", "getUnread", "getProfiles", "share",
73 "fbexport", "logout", "pubsub");
74
75 if (array_search($op, $public_calls) !== false) {
76
77 handle_public_request($link, $op);
78 return;
79
80 } else if (!($_SESSION["uid"] && validate_session($link))) {
81 if ($op == 'pref-feeds' && $_REQUEST['method'] == 'add') {
82 header("Content-Type: text/html");
83 login_sequence($link);
84 render_login_form($link);
85 } else {
86 header("Content-Type: text/plain");
87 print json_encode(array("error" => array("code" => 6)));
88 }
89 return;
90 }
91
92 $purge_intervals = array(
93 0 => __("Use default"),
94 -1 => __("Never purge"),
95 5 => __("1 week old"),
96 14 => __("2 weeks old"),
97 31 => __("1 month old"),
98 60 => __("2 months old"),
99 90 => __("3 months old"));
100
101 $update_intervals = array(
102 0 => __("Default interval"),
103 -1 => __("Disable updates"),
104 15 => __("Each 15 minutes"),
105 30 => __("Each 30 minutes"),
106 60 => __("Hourly"),
107 240 => __("Each 4 hours"),
108 720 => __("Each 12 hours"),
109 1440 => __("Daily"),
110 10080 => __("Weekly"));
111
112 $update_intervals_nodefault = array(
113 -1 => __("Disable updates"),
114 15 => __("Each 15 minutes"),
115 30 => __("Each 30 minutes"),
116 60 => __("Hourly"),
117 240 => __("Each 4 hours"),
118 720 => __("Each 12 hours"),
119 1440 => __("Daily"),
120 10080 => __("Weekly"));
121
122 $update_methods = array(
123 0 => __("Default"),
124 1 => __("Magpie"),
125 2 => __("SimplePie"),
126 3 => __("Twitter OAuth"));
127
128 if (DEFAULT_UPDATE_METHOD == "1") {
129 $update_methods[0] .= ' (SimplePie)';
130 } else {
131 $update_methods[0] .= ' (Magpie)';
132 }
133
134 $access_level_names = array(
135 0 => __("User"),
136 5 => __("Power User"),
137 10 => __("Administrator"));
138
139 $error = sanity_check($link);
140
141 if ($error['code'] != 0 && $op != "logout") {
142 print json_encode(array("error" => $error));
143 return;
144 }
145
146 $op = str_replace("-", "_", $op);
147
148 if (class_exists($op)) {
149 $handler = new $op($link, $_REQUEST);
150
151 if ($handler) {
152 if ($handler->before()) {
153 if ($method && method_exists($handler, $method)) {
154 $handler->$method();
155 } else if (method_exists($handler, 'index')) {
156 $handler->index();
157 }
158 $handler->after();
159 return;
160 }
161 }
162 }
163
164 switch($op) { // Select action according to $op value.
165
166 case "pref-filters":
167 require_once "modules/pref-filters.php";
168 module_pref_filters($link);
169 break; // pref-filters
170
171 case "pref-labels":
172 require_once "modules/pref-labels.php";
173 module_pref_labels($link);
174 break; // pref-labels
175
176 case "pref-prefs":
177 require_once "modules/pref-prefs.php";
178 module_pref_prefs($link);
179 break; // pref-prefs
180
181 case "pref-users":
182 require_once "modules/pref-users.php";
183 module_pref_users($link);
184 break; // prefs-users
185
186 case "help":
187 require_once "modules/help.php";
188 module_help($link);
189 break; // help
190
191 case "pref-instances":
192 require_once "modules/pref-instances.php";
193 module_pref_instances($link);
194 break; // pref-instances
195
196 case "digestTest":
197 print_r(prepare_headlines_digest($link, $_SESSION["uid"]));
198 break; // digestTest
199
200 case "digestSend":
201 send_headlines_digests($link);
202 break; // digestSend
203
204 case "loading":
205 header("Content-type: text/html");
206 print __("Loading, please wait...") . " " .
207 "<img src='images/indicator_tiny.gif'>";
208 break; // loading
209
210 default:
211 header("Content-Type: text/plain");
212 print json_encode(array("error" => array("code" => 7)));
213 break; // fallback
214 } // Select action according to $op value.
215
216 // We close the connection to database.
217 db_close($link);
218 ?>