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