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