]>
Commit | Line | Data |
---|---|---|
1d3a17c7 | 1 | <?php |
ce885e21 AD |
2 | /* remove ill effects of magic quotes */ |
3 | ||
5fa17372 | 4 | if (get_magic_quotes_gpc()) { |
c0793f64 | 5 | function stripslashes_deep($value) { |
009646d2 | 6 | $value = is_array($value) ? |
c0793f64 AD |
7 | array_map('stripslashes_deep', $value) : stripslashes($value); |
8 | return $value; | |
9 | } | |
10 | ||
11 | $_POST = array_map('stripslashes_deep', $_POST); | |
12 | $_GET = array_map('stripslashes_deep', $_GET); | |
13 | $_COOKIE = array_map('stripslashes_deep', $_COOKIE); | |
14 | $_REQUEST = array_map('stripslashes_deep', $_REQUEST); | |
ce885e21 AD |
15 | } |
16 | ||
f9da2388 AD |
17 | $op = $_REQUEST["op"]; |
18 | ||
fb074239 | 19 | require_once "functions.php"; |
f9da2388 | 20 | if ($op != "share") require_once "sessions.php"; |
c339343b | 21 | require_once "modules/backend-rpc.php"; |
657770a0 AD |
22 | require_once "sanity_check.php"; |
23 | require_once "config.php"; | |
af106b0e AD |
24 | require_once "db.php"; |
25 | require_once "db-prefs.php"; | |
657770a0 | 26 | |
dc56b3b7 | 27 | no_cache_incantation(); |
8d039718 | 28 | |
7b26a148 | 29 | startup_gettext(); |
dc56b3b7 | 30 | |
7f0acba7 AD |
31 | $script_started = getmicrotime(); |
32 | ||
009646d2 | 33 | $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); |
7f0acba7 AD |
34 | |
35 | if (!$link) { | |
36 | if (DB_TYPE == "mysql") { | |
37 | print mysql_error(); | |
38 | } | |
009646d2 | 39 | // PG seems to display its own errors just fine by default. |
7f0acba7 AD |
40 | return; |
41 | } | |
42 | ||
f29ba148 | 43 | init_connection($link); |
7f0acba7 | 44 | |
d9084cf2 | 45 | $subop = $_REQUEST["subop"]; |
fac5e7d1 | 46 | $mode = $_REQUEST["mode"]; |
7f0acba7 | 47 | |
565ca565 AD |
48 | if ((!$op || $op == "rss" || $op == "dlg") && !$_REQUEST["noxml"]) { |
49 | header("Content-Type: application/xml; charset=utf-8"); | |
50 | } else { | |
9fdf7824 | 51 | header("Content-Type: text/plain; charset=utf-8"); |
262bd8ea AD |
52 | } |
53 | ||
bd202c3f AD |
54 | if (ENABLE_GZIP_OUTPUT) { |
55 | ob_start("ob_gzhandler"); | |
56 | } | |
57 | ||
9c883208 AD |
58 | if (SINGLE_USER_MODE) { |
59 | authenticate_user($link, "admin", null); | |
60 | } | |
61 | ||
e0d91d84 AD |
62 | $public_calls = array("globalUpdateFeeds", "rss", "getUnread", "getProfiles", "share", |
63 | "fbexport", "logout", "pubsub"); | |
009646d2 | 64 | |
e0d91d84 AD |
65 | if (array_search($op, $public_calls) !== false) { |
66 | ||
67 | handle_public_request($link, $op); | |
68 | return; | |
69 | ||
70 | } else if (!($_SESSION["uid"] && validate_session($link))) { | |
d0f73380 AD |
71 | if ($op == 'pref-feeds' && $_REQUEST['subop'] == 'add') { |
72 | header("Content-Type: text/html"); | |
73 | login_sequence($link); | |
74 | render_login_form($link); | |
75 | } else { | |
76 | header("Content-Type: text/plain"); | |
77 | print json_encode(array("error" => array("code" => 6))); | |
78 | } | |
009646d2 | 79 | return; |
262bd8ea | 80 | } |
1c7f75ed | 81 | |
ad815c71 | 82 | $purge_intervals = array( |
d1db26aa AD |
83 | 0 => __("Use default"), |
84 | -1 => __("Never purge"), | |
85 | 5 => __("1 week old"), | |
86 | 14 => __("2 weeks old"), | |
87 | 31 => __("1 month old"), | |
88 | 60 => __("2 months old"), | |
89 | 90 => __("3 months old")); | |
ad815c71 AD |
90 | |
91 | $update_intervals = array( | |
ecace165 | 92 | 0 => __("Default interval"), |
d1db26aa | 93 | -1 => __("Disable updates"), |
1e7cbe16 | 94 | 15 => __("Each 15 minutes"), |
d1db26aa | 95 | 30 => __("Each 30 minutes"), |
505f2f0e AD |
96 | 60 => __("Hourly"), |
97 | 240 => __("Each 4 hours"), | |
98 | 720 => __("Each 12 hours"), | |
99 | 1440 => __("Daily"), | |
100 | 10080 => __("Weekly")); | |
101 | ||
102 | $update_intervals_nodefault = array( | |
103 | -1 => __("Disable updates"), | |
104 | 15 => __("Each 15 minutes"), | |
105 | 30 => __("Each 30 minutes"), | |
d1db26aa AD |
106 | 60 => __("Hourly"), |
107 | 240 => __("Each 4 hours"), | |
108 | 720 => __("Each 12 hours"), | |
109 | 1440 => __("Daily"), | |
110 | 10080 => __("Weekly")); | |
ad815c71 | 111 | |
16211ddb | 112 | $update_methods = array( |
ecace165 | 113 | 0 => __("Default"), |
0dd9c0cf | 114 | 1 => __("Magpie"), |
009646d2 | 115 | 2 => __("SimplePie"), |
b3009bcd | 116 | 3 => __("Twitter OAuth")); |
16211ddb | 117 | |
78a5c296 | 118 | if (DEFAULT_UPDATE_METHOD == "1") { |
16211ddb AD |
119 | $update_methods[0] .= ' (SimplePie)'; |
120 | } else { | |
121 | $update_methods[0] .= ' (Magpie)'; | |
122 | } | |
123 | ||
3c5783b7 | 124 | $access_level_names = array( |
009646d2 | 125 | 0 => __("User"), |
a88d37e5 | 126 | 5 => __("Power User"), |
d1db26aa | 127 | 10 => __("Administrator")); |
3c5783b7 | 128 | |
1c9d14ad | 129 | |
ef8be8ea | 130 | |
ebb948c2 AD |
131 | $error = sanity_check($link); |
132 | ||
2376ad49 | 133 | if ($error['code'] != 0 && $op != "logout") { |
ebb948c2 AD |
134 | print json_encode(array("error" => $error)); |
135 | return; | |
136 | } | |
023fe037 | 137 | |
45004d43 AD |
138 | switch($op) { // Select action according to $op value. |
139 | case "rpc": | |
140 | // Handle remote procedure calls. | |
141 | handle_rpc_request($link); | |
142 | break; // rpc | |
143 | ||
144 | case "feeds": | |
b4e75b2a | 145 | $subop = $_REQUEST["subop"]; |
1985a5e0 | 146 | $root = (bool)$_REQUEST["root"]; |
45004d43 AD |
147 | |
148 | switch($subop) { | |
149 | case "catchupAll": | |
009646d2 | 150 | db_query($link, "UPDATE ttrss_user_entries SET |
45004d43 | 151 | last_read = NOW(),unread = false WHERE owner_uid = " . $_SESSION["uid"]); |
ad0056a8 AD |
152 | ccache_zero_all($link, $_SESSION["uid"]); |
153 | ||
45004d43 AD |
154 | break; |
155 | ||
156 | case "collapse": | |
b4e75b2a | 157 | $cat_id = db_escape_string($_REQUEST["cid"]); |
fcf70c51 AD |
158 | $mode = (int) db_escape_string($_REQUEST['mode']); |
159 | toggle_collapse_cat($link, $cat_id, $mode); | |
45004d43 AD |
160 | return; |
161 | break; | |
162 | } | |
c3b81db0 | 163 | |
1985a5e0 AD |
164 | if (!$root) { |
165 | print json_encode(outputFeedList($link)); | |
166 | } else { | |
167 | ||
168 | $feeds = outputFeedList($link, false); | |
169 | ||
170 | $root = array(); | |
171 | $root['id'] = 'root'; | |
172 | $root['name'] = __('Feeds'); | |
173 | $root['items'] = $feeds['items']; | |
174 | ||
175 | $fl = array(); | |
176 | $fl['identifier'] = 'id'; | |
177 | $fl['label'] = 'name'; | |
178 | $fl['items'] = array($root); | |
179 | ||
180 | print json_encode($fl); | |
181 | } | |
13e785e0 | 182 | |
45004d43 | 183 | break; // feeds |
1cd17194 | 184 | |
b509d64e AD |
185 | case "la": |
186 | $id = db_escape_string($_REQUEST['id']); | |
187 | ||
188 | $result = db_query($link, "SELECT link FROM ttrss_entries, ttrss_user_entries | |
bfedfe69 AD |
189 | WHERE id = '$id' AND id = ref_id AND owner_uid = '".$_SESSION['uid']."' |
190 | LIMIT 1"); | |
b509d64e AD |
191 | |
192 | if (db_num_rows($result) == 1) { | |
193 | $article_url = db_fetch_result($result, 0, 'link'); | |
d4dcf8e9 | 194 | $article_url = str_replace("\n", "", $article_url); |
b509d64e AD |
195 | |
196 | header("Location: $article_url"); | |
197 | return; | |
198 | ||
199 | } else { | |
200 | print_error(__("Article not found.")); | |
201 | } | |
202 | break; | |
203 | ||
45004d43 | 204 | case "view": |
e097e8be | 205 | |
b4e75b2a | 206 | $id = db_escape_string($_REQUEST["id"]); |
9949bd15 | 207 | $cids = explode(",", db_escape_string($_REQUEST["cids"])); |
b4e75b2a AD |
208 | $mode = db_escape_string($_REQUEST["mode"]); |
209 | $omode = db_escape_string($_REQUEST["omode"]); | |
e097e8be | 210 | |
009646d2 | 211 | // in prefetch mode we only output requested cids, main article |
45004d43 | 212 | // just gets marked as read (it already exists in client cache) |
e097e8be | 213 | |
009646d2 AD |
214 | $articles = array(); |
215 | ||
45004d43 | 216 | if ($mode == "") { |
009646d2 | 217 | array_push($articles, format_article($link, $id, false)); |
eedfb635 | 218 | } else if ($mode == "zoom") { |
9949bd15 | 219 | array_push($articles, format_article($link, $id, true, true)); |
f4f0f80d | 220 | } else if ($mode == "raw") { |
fcfa9ef1 AD |
221 | if ($_REQUEST['html']) { |
222 | header("Content-Type: text/html"); | |
223 | print '<link rel="stylesheet" type="text/css" href="tt-rss.css"/>'; | |
224 | } | |
f4f0f80d AD |
225 | |
226 | $article = format_article($link, $id, false); | |
f4f0f80d AD |
227 | print $article['content']; |
228 | return; | |
45004d43 | 229 | } |
e097e8be | 230 | |
f7cffd2c AD |
231 | catchupArticleById($link, $id, 0); |
232 | ||
a598370d AD |
233 | if (!$_SESSION["bw_limit"]) { |
234 | foreach ($cids as $cid) { | |
235 | if ($cid) { | |
009646d2 | 236 | array_push($articles, format_article($link, $cid, false, false)); |
a598370d | 237 | } |
45004d43 | 238 | } |
e097e8be | 239 | } |
e097e8be | 240 | |
009646d2 | 241 | print json_encode($articles); |
5a94a953 | 242 | |
45004d43 | 243 | break; // view |
1cd17194 | 244 | |
45004d43 | 245 | case "viewfeed": |
1cd17194 | 246 | |
45004d43 | 247 | $timing_info = getmicrotime(); |
46921916 | 248 | |
bd202c3f | 249 | $reply = array(); |
3de0261a | 250 | |
b4e75b2a | 251 | if ($_REQUEST["debug"]) $timing_info = print_checkpoint("0", $timing_info); |
46921916 | 252 | |
b4e75b2a | 253 | $omode = db_escape_string($_REQUEST["omode"]); |
3de0261a | 254 | |
b4e75b2a AD |
255 | $feed = db_escape_string($_REQUEST["feed"]); |
256 | $subop = db_escape_string($_REQUEST["subop"]); | |
257 | $view_mode = db_escape_string($_REQUEST["view_mode"]); | |
6f068202 | 258 | $limit = (int) get_pref($link, "DEFAULT_ARTICLE_LIMIT"); |
37c03d3a | 259 | @$cat_view = db_escape_string($_REQUEST["cat"]) == "true"; |
c3fddd05 AD |
260 | @$next_unread_feed = db_escape_string($_REQUEST["nuf"]); |
261 | @$offset = db_escape_string($_REQUEST["skip"]); | |
262 | @$vgroup_last_feed = db_escape_string($_REQUEST["vgrlf"]); | |
b4e75b2a | 263 | $order_by = db_escape_string($_REQUEST["order_by"]); |
203de776 | 264 | |
147f5632 CM |
265 | if (is_numeric($feed)) $feed = (int) $feed; |
266 | ||
fe1087fb AD |
267 | /* Feed -5 is a special case: it is used to display auxiliary information |
268 | * when there's nothing to load - e.g. no stuff in fresh feed */ | |
269 | ||
270 | if ($feed == -5) { | |
bd202c3f AD |
271 | print json_encode(generate_dashboard_feed($link)); |
272 | return; | |
273 | } | |
274 | ||
275 | $result = false; | |
276 | ||
277 | if ($feed < -10) { | |
81f6deea | 278 | $label_feed = -11-$feed; |
bd202c3f AD |
279 | $result = db_query($link, "SELECT id FROM ttrss_labels2 WHERE |
280 | id = '$label_feed' AND owner_uid = " . $_SESSION['uid']); | |
147f5632 | 281 | } else if (!$cat_view && is_numeric($feed) && $feed > 0) { |
bd202c3f AD |
282 | $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE |
283 | id = '$feed' AND owner_uid = " . $_SESSION['uid']); | |
147f5632 | 284 | } else if ($cat_view && is_numeric($feed) && $feed > 0) { |
bd202c3f AD |
285 | $result = db_query($link, "SELECT id FROM ttrss_feed_categories WHERE |
286 | id = '$feed' AND owner_uid = " . $_SESSION['uid']); | |
287 | } | |
288 | ||
289 | if ($result && db_num_rows($result) == 0) { | |
290 | print json_encode(generate_error_feed($link, __("Feed not found."))); | |
fe1087fb AD |
291 | return; |
292 | } | |
293 | ||
51e196de AD |
294 | /* Updating a label ccache means recalculating all of the caches |
295 | * so for performance reasons we don't do that here */ | |
296 | ||
5225d420 AD |
297 | if ($feed >= 0) { |
298 | ccache_update($link, $feed, $_SESSION["uid"], $cat_view); | |
299 | } | |
0737b95a | 300 | |
45004d43 AD |
301 | set_pref($link, "_DEFAULT_VIEW_MODE", $view_mode); |
302 | set_pref($link, "_DEFAULT_VIEW_LIMIT", $limit); | |
7b4d02a8 | 303 | set_pref($link, "_DEFAULT_VIEW_ORDER_BY", $order_by); |
40496720 | 304 | |
45004d43 AD |
305 | if (!$cat_view && preg_match("/^[0-9][0-9]*$/", $feed)) { |
306 | db_query($link, "UPDATE ttrss_feeds SET last_viewed = NOW() | |
307 | WHERE id = '$feed' AND owner_uid = ".$_SESSION["uid"]); | |
308 | } | |
7466dc6a | 309 | |
bd202c3f AD |
310 | $reply['headlines'] = array(); |
311 | ||
312 | if (!$next_unread_feed) | |
313 | $reply['headlines']['id'] = $feed; | |
314 | else | |
315 | $reply['headlines']['id'] = $next_unread_feed; | |
316 | ||
317 | $reply['headlines']['is_cat'] = (bool) $cat_view; | |
009646d2 | 318 | |
a5c815d3 AD |
319 | $override_order = false; |
320 | ||
b3990c92 AD |
321 | if (get_pref($link, "SORT_HEADLINES_BY_FEED_DATE", $owner_uid)) { |
322 | $date_sort_field = "updated"; | |
323 | } else { | |
324 | $date_sort_field = "date_entered"; | |
325 | } | |
326 | ||
a5c815d3 AD |
327 | switch ($order_by) { |
328 | case "date": | |
329 | if (get_pref($link, 'REVERSE_HEADLINES', $owner_uid)) { | |
b3990c92 | 330 | $override_order = "$date_sort_field"; |
009646d2 | 331 | } else { |
b3990c92 | 332 | $override_order = "$date_sort_field DESC"; |
a5c815d3 AD |
333 | } |
334 | break; | |
c50e2b30 | 335 | |
a5c815d3 | 336 | case "title": |
7b20c977 | 337 | if (get_pref($link, 'REVERSE_HEADLINES', $owner_uid)) { |
b3990c92 | 338 | $override_order = "title DESC, $date_sort_field"; |
7b20c977 | 339 | } else { |
b3990c92 | 340 | $override_order = "title, $date_sort_field DESC"; |
7b20c977 | 341 | } |
a5c815d3 | 342 | break; |
d76a3b03 | 343 | |
a5c815d3 | 344 | case "score": |
7b20c977 | 345 | if (get_pref($link, 'REVERSE_HEADLINES', $owner_uid)) { |
b3990c92 | 346 | $override_order = "score, $date_sort_field"; |
7b20c977 | 347 | } else { |
b3990c92 | 348 | $override_order = "score DESC, $date_sort_field DESC"; |
7b20c977 | 349 | } |
a5c815d3 AD |
350 | break; |
351 | } | |
e19c1824 | 352 | |
905ff52a AD |
353 | if ($_REQUEST["debug"]) $timing_info = print_checkpoint("04", $timing_info); |
354 | ||
bd202c3f | 355 | $ret = format_headlines_list($link, $feed, $subop, |
009646d2 | 356 | $view_mode, $limit, $cat_view, $next_unread_feed, $offset, |
a5c815d3 | 357 | $vgroup_last_feed, $override_order); |
7b4d02a8 | 358 | |
a5c815d3 AD |
359 | $topmost_article_ids = $ret[0]; |
360 | $headlines_count = $ret[1]; | |
361 | $returned_feed = $ret[2]; | |
362 | $disable_cache = $ret[3]; | |
363 | $vgroup_last_feed = $ret[4]; | |
7b4d02a8 | 364 | |
7d96bfcd AD |
365 | // if ($_REQUEST["debug"]) print_r($ret); |
366 | ||
367 | $reply['headlines']['content'] =& $ret[5]['content']; | |
368 | $reply['headlines']['toolbar'] =& $ret[5]['toolbar']; | |
46921916 | 369 | |
905ff52a AD |
370 | if ($_REQUEST["debug"]) $timing_info = print_checkpoint("05", $timing_info); |
371 | ||
bd202c3f | 372 | $reply['headlines-info'] = array("count" => (int) $headlines_count, |
ffbe082d | 373 | "vgroup_last_feed" => $vgroup_last_feed, |
ffbe082d AD |
374 | "disable_cache" => (bool) $disable_cache); |
375 | ||
bd202c3f | 376 | if ($_REQUEST["debug"]) $timing_info = print_checkpoint("20", $timing_info); |
009646d2 | 377 | |
bd202c3f | 378 | if (is_array($topmost_article_ids) && !get_pref($link, 'COMBINED_DISPLAY_MODE') && !$_SESSION["bw_limit"]) { |
009646d2 AD |
379 | $articles = array(); |
380 | ||
a5c815d3 | 381 | foreach ($topmost_article_ids as $id) { |
9949bd15 | 382 | array_push($articles, format_article($link, $id, false)); |
45004d43 | 383 | } |
009646d2 | 384 | |
bd202c3f AD |
385 | $reply['articles'] = $articles; |
386 | } | |
46921916 | 387 | |
81787bbf AD |
388 | // if ($subop) { |
389 | // $reply['counters'] = getAllCounters($link, $omode, $feed); | |
390 | // } | |
98bea1b1 | 391 | |
b4e75b2a | 392 | if ($_REQUEST["debug"]) $timing_info = print_checkpoint("30", $timing_info); |
46921916 | 393 | |
bd202c3f AD |
394 | $reply['runtime-info'] = make_runtime_info($link); |
395 | ||
396 | print json_encode($reply); | |
03c88bdd | 397 | |
45004d43 | 398 | break; // viewfeed |
1cd17194 | 399 | |
45004d43 | 400 | case "pref-feeds": |
1c9d14ad | 401 | require_once "modules/pref-feeds.php"; |
45004d43 AD |
402 | module_pref_feeds($link); |
403 | break; // pref-feeds | |
a7f22b70 | 404 | |
45004d43 | 405 | case "pref-filters": |
1c9d14ad | 406 | require_once "modules/pref-filters.php"; |
45004d43 AD |
407 | module_pref_filters($link); |
408 | break; // pref-filters | |
a0476535 | 409 | |
45004d43 | 410 | case "pref-labels": |
1c9d14ad | 411 | require_once "modules/pref-labels.php"; |
45004d43 AD |
412 | module_pref_labels($link); |
413 | break; // pref-labels | |
d0000401 | 414 | |
45004d43 | 415 | case "pref-prefs": |
1c9d14ad | 416 | require_once "modules/pref-prefs.php"; |
45004d43 AD |
417 | module_pref_prefs($link); |
418 | break; // pref-prefs | |
f27d955a | 419 | |
45004d43 | 420 | case "pref-users": |
1c9d14ad | 421 | require_once "modules/pref-users.php"; |
45004d43 AD |
422 | module_pref_users($link); |
423 | break; // prefs-users | |
a0476535 | 424 | |
45004d43 | 425 | case "help": |
1c9d14ad | 426 | require_once "modules/help.php"; |
45004d43 AD |
427 | module_help($link); |
428 | break; // help | |
a0476535 | 429 | |
45004d43 | 430 | case "dlg": |
1c9d14ad | 431 | require_once "modules/popup-dialog.php"; |
45004d43 AD |
432 | module_popup_dialog($link); |
433 | break; // dlg | |
a7f22b70 | 434 | |
373266eb | 435 | case "pref-instances": |
1c9d14ad | 436 | require_once "modules/pref-instances.php"; |
373266eb AD |
437 | module_pref_instances($link); |
438 | break; // pref-instances | |
439 | ||
45004d43 | 440 | case "digestTest": |
45004d43 | 441 | print_r(prepare_headlines_digest($link, $_SESSION["uid"])); |
45004d43 | 442 | break; // digestTest |
448b0abd | 443 | |
45004d43 | 444 | case "digestSend": |
45004d43 | 445 | send_headlines_digests($link); |
45004d43 | 446 | break; // digestSend |
7e3634d9 | 447 | |
ba7e88e5 | 448 | case "loading": |
347b467b | 449 | header("Content-type: text/html"); |
009646d2 | 450 | print __("Loading, please wait...") . " " . |
ba7e88e5 | 451 | "<img src='images/indicator_tiny.gif'>"; |
373266eb | 452 | break; // loading |
ba7e88e5 | 453 | |
1ca77e0a AD |
454 | default: |
455 | header("Content-Type: text/plain"); | |
456 | print json_encode(array("error" => array("code" => 7))); | |
373266eb | 457 | break; // fallback |
5ab9791f | 458 | } // Select action according to $op value. |
ba7e88e5 | 459 | |
45004d43 | 460 | // We close the connection to database. |
4b3dff6e | 461 | db_close($link); |
1cd17194 | 462 | ?> |