]>
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 | ||
fb074239 | 17 | require_once "functions.php"; |
36bfab86 | 18 | require_once "sessions.php"; |
c339343b | 19 | require_once "modules/backend-rpc.php"; |
657770a0 AD |
20 | require_once "sanity_check.php"; |
21 | require_once "config.php"; | |
af106b0e AD |
22 | require_once "db.php"; |
23 | require_once "db-prefs.php"; | |
657770a0 | 24 | |
dc56b3b7 | 25 | no_cache_incantation(); |
8d039718 | 26 | |
7b26a148 | 27 | startup_gettext(); |
dc56b3b7 | 28 | |
7f0acba7 AD |
29 | $script_started = getmicrotime(); |
30 | ||
009646d2 | 31 | $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); |
7f0acba7 AD |
32 | |
33 | if (!$link) { | |
34 | if (DB_TYPE == "mysql") { | |
35 | print mysql_error(); | |
36 | } | |
009646d2 | 37 | // PG seems to display its own errors just fine by default. |
7f0acba7 AD |
38 | return; |
39 | } | |
40 | ||
f29ba148 | 41 | init_connection($link); |
7f0acba7 AD |
42 | |
43 | $op = $_REQUEST["op"]; | |
d9084cf2 | 44 | $subop = $_REQUEST["subop"]; |
fac5e7d1 | 45 | $mode = $_REQUEST["mode"]; |
7f0acba7 | 46 | |
c339343b | 47 | $print_exec_time = false; |
7e3634d9 | 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 | ||
009646d2 | 63 | if (!($_SESSION["uid"] && validate_session($link)) && $op != "globalUpdateFeeds" && |
5ab9791f AD |
64 | $op != "rss" && $op != "getUnread" && $op != "getProfiles" && |
65 | $op != "pubsub") { | |
009646d2 AD |
66 | |
67 | header("Content-Type: text/plain"); | |
68 | print json_encode(array("error" => array("code" => 6))); | |
69 | return; | |
262bd8ea | 70 | } |
1c7f75ed | 71 | |
ad815c71 | 72 | $purge_intervals = array( |
d1db26aa AD |
73 | 0 => __("Use default"), |
74 | -1 => __("Never purge"), | |
75 | 5 => __("1 week old"), | |
76 | 14 => __("2 weeks old"), | |
77 | 31 => __("1 month old"), | |
78 | 60 => __("2 months old"), | |
79 | 90 => __("3 months old")); | |
ad815c71 AD |
80 | |
81 | $update_intervals = array( | |
ecace165 | 82 | 0 => __("Default interval"), |
d1db26aa | 83 | -1 => __("Disable updates"), |
1e7cbe16 | 84 | 15 => __("Each 15 minutes"), |
d1db26aa | 85 | 30 => __("Each 30 minutes"), |
505f2f0e AD |
86 | 60 => __("Hourly"), |
87 | 240 => __("Each 4 hours"), | |
88 | 720 => __("Each 12 hours"), | |
89 | 1440 => __("Daily"), | |
90 | 10080 => __("Weekly")); | |
91 | ||
92 | $update_intervals_nodefault = array( | |
93 | -1 => __("Disable updates"), | |
94 | 15 => __("Each 15 minutes"), | |
95 | 30 => __("Each 30 minutes"), | |
d1db26aa AD |
96 | 60 => __("Hourly"), |
97 | 240 => __("Each 4 hours"), | |
98 | 720 => __("Each 12 hours"), | |
99 | 1440 => __("Daily"), | |
100 | 10080 => __("Weekly")); | |
ad815c71 | 101 | |
16211ddb | 102 | $update_methods = array( |
ecace165 | 103 | 0 => __("Default"), |
0dd9c0cf | 104 | 1 => __("Magpie"), |
009646d2 | 105 | 2 => __("SimplePie"), |
b3009bcd | 106 | 3 => __("Twitter OAuth")); |
16211ddb | 107 | |
78a5c296 | 108 | if (DEFAULT_UPDATE_METHOD == "1") { |
16211ddb AD |
109 | $update_methods[0] .= ' (SimplePie)'; |
110 | } else { | |
111 | $update_methods[0] .= ' (Magpie)'; | |
112 | } | |
113 | ||
3c5783b7 | 114 | $access_level_names = array( |
009646d2 | 115 | 0 => __("User"), |
a88d37e5 | 116 | 5 => __("Power User"), |
d1db26aa | 117 | 10 => __("Administrator")); |
3c5783b7 | 118 | |
f27d955a | 119 | require_once "modules/pref-prefs.php"; |
ef8be8ea AD |
120 | require_once "modules/popup-dialog.php"; |
121 | require_once "modules/help.php"; | |
122 | require_once "modules/pref-feeds.php"; | |
123 | require_once "modules/pref-filters.php"; | |
124 | require_once "modules/pref-labels.php"; | |
125 | require_once "modules/pref-users.php"; | |
ef8be8ea | 126 | |
ebb948c2 AD |
127 | $error = sanity_check($link); |
128 | ||
129 | if ($error['code'] != 0) { | |
130 | print json_encode(array("error" => $error)); | |
131 | return; | |
132 | } | |
023fe037 | 133 | |
45004d43 AD |
134 | switch($op) { // Select action according to $op value. |
135 | case "rpc": | |
136 | // Handle remote procedure calls. | |
137 | handle_rpc_request($link); | |
138 | break; // rpc | |
139 | ||
140 | case "feeds": | |
b4e75b2a | 141 | $subop = $_REQUEST["subop"]; |
1985a5e0 | 142 | $root = (bool)$_REQUEST["root"]; |
45004d43 AD |
143 | |
144 | switch($subop) { | |
145 | case "catchupAll": | |
009646d2 | 146 | db_query($link, "UPDATE ttrss_user_entries SET |
45004d43 | 147 | last_read = NOW(),unread = false WHERE owner_uid = " . $_SESSION["uid"]); |
ad0056a8 AD |
148 | ccache_zero_all($link, $_SESSION["uid"]); |
149 | ||
45004d43 AD |
150 | break; |
151 | ||
152 | case "collapse": | |
b4e75b2a | 153 | $cat_id = db_escape_string($_REQUEST["cid"]); |
fcf70c51 AD |
154 | $mode = (int) db_escape_string($_REQUEST['mode']); |
155 | toggle_collapse_cat($link, $cat_id, $mode); | |
45004d43 AD |
156 | return; |
157 | break; | |
158 | } | |
c3b81db0 | 159 | |
1985a5e0 AD |
160 | if (!$root) { |
161 | print json_encode(outputFeedList($link)); | |
162 | } else { | |
163 | ||
164 | $feeds = outputFeedList($link, false); | |
165 | ||
166 | $root = array(); | |
167 | $root['id'] = 'root'; | |
168 | $root['name'] = __('Feeds'); | |
169 | $root['items'] = $feeds['items']; | |
170 | ||
171 | $fl = array(); | |
172 | $fl['identifier'] = 'id'; | |
173 | $fl['label'] = 'name'; | |
174 | $fl['items'] = array($root); | |
175 | ||
176 | print json_encode($fl); | |
177 | } | |
13e785e0 | 178 | |
45004d43 | 179 | break; // feeds |
1cd17194 | 180 | |
b509d64e AD |
181 | case "la": |
182 | $id = db_escape_string($_REQUEST['id']); | |
183 | ||
184 | $result = db_query($link, "SELECT link FROM ttrss_entries, ttrss_user_entries | |
185 | WHERE id = '$id' AND id = ref_id AND owner_uid = '".$_SESSION['uid']."'"); | |
186 | ||
187 | if (db_num_rows($result) == 1) { | |
188 | $article_url = db_fetch_result($result, 0, 'link'); | |
d4dcf8e9 | 189 | $article_url = str_replace("\n", "", $article_url); |
b509d64e AD |
190 | |
191 | header("Location: $article_url"); | |
192 | return; | |
193 | ||
194 | } else { | |
195 | print_error(__("Article not found.")); | |
196 | } | |
197 | break; | |
198 | ||
45004d43 | 199 | case "view": |
e097e8be | 200 | |
b4e75b2a AD |
201 | $id = db_escape_string($_REQUEST["id"]); |
202 | $cids = split(",", db_escape_string($_REQUEST["cids"])); | |
203 | $mode = db_escape_string($_REQUEST["mode"]); | |
204 | $omode = db_escape_string($_REQUEST["omode"]); | |
e097e8be | 205 | |
009646d2 | 206 | // in prefetch mode we only output requested cids, main article |
45004d43 | 207 | // just gets marked as read (it already exists in client cache) |
e097e8be | 208 | |
009646d2 AD |
209 | $articles = array(); |
210 | ||
45004d43 | 211 | if ($mode == "") { |
009646d2 | 212 | array_push($articles, format_article($link, $id, false)); |
eedfb635 | 213 | } else if ($mode == "zoom") { |
009646d2 | 214 | array_push($articles, format_article($link, $id, false, true, true)); |
45004d43 AD |
215 | } else { |
216 | catchupArticleById($link, $id, 0); | |
217 | } | |
e097e8be | 218 | |
a598370d AD |
219 | if (!$_SESSION["bw_limit"]) { |
220 | foreach ($cids as $cid) { | |
221 | if ($cid) { | |
009646d2 | 222 | array_push($articles, format_article($link, $cid, false, false)); |
a598370d | 223 | } |
45004d43 | 224 | } |
e097e8be | 225 | } |
e097e8be | 226 | |
009646d2 | 227 | print json_encode($articles); |
5a94a953 | 228 | |
45004d43 | 229 | break; // view |
1cd17194 | 230 | |
45004d43 | 231 | case "viewfeed": |
1cd17194 | 232 | |
45004d43 | 233 | $timing_info = getmicrotime(); |
46921916 | 234 | |
bd202c3f | 235 | $reply = array(); |
3de0261a | 236 | |
b4e75b2a | 237 | if ($_REQUEST["debug"]) $timing_info = print_checkpoint("0", $timing_info); |
46921916 | 238 | |
b4e75b2a | 239 | $omode = db_escape_string($_REQUEST["omode"]); |
3de0261a | 240 | |
b4e75b2a AD |
241 | $feed = db_escape_string($_REQUEST["feed"]); |
242 | $subop = db_escape_string($_REQUEST["subop"]); | |
243 | $view_mode = db_escape_string($_REQUEST["view_mode"]); | |
6f068202 | 244 | $limit = (int) get_pref($link, "DEFAULT_ARTICLE_LIMIT"); |
c3fddd05 AD |
245 | @$cat_view = db_escape_string($_REQUEST["cat"]); |
246 | @$next_unread_feed = db_escape_string($_REQUEST["nuf"]); | |
247 | @$offset = db_escape_string($_REQUEST["skip"]); | |
248 | @$vgroup_last_feed = db_escape_string($_REQUEST["vgrlf"]); | |
b4e75b2a | 249 | $order_by = db_escape_string($_REQUEST["order_by"]); |
203de776 | 250 | |
fe1087fb AD |
251 | /* Feed -5 is a special case: it is used to display auxiliary information |
252 | * when there's nothing to load - e.g. no stuff in fresh feed */ | |
253 | ||
254 | if ($feed == -5) { | |
bd202c3f AD |
255 | print json_encode(generate_dashboard_feed($link)); |
256 | return; | |
257 | } | |
258 | ||
259 | $result = false; | |
260 | ||
261 | if ($feed < -10) { | |
81f6deea | 262 | $label_feed = -11-$feed; |
bd202c3f AD |
263 | $result = db_query($link, "SELECT id FROM ttrss_labels2 WHERE |
264 | id = '$label_feed' AND owner_uid = " . $_SESSION['uid']); | |
265 | } else if (!$cat_view && $feed > 0) { | |
266 | $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE | |
267 | id = '$feed' AND owner_uid = " . $_SESSION['uid']); | |
81f6deea | 268 | } else if ($cat_view && $feed > 0) { |
bd202c3f AD |
269 | $result = db_query($link, "SELECT id FROM ttrss_feed_categories WHERE |
270 | id = '$feed' AND owner_uid = " . $_SESSION['uid']); | |
271 | } | |
272 | ||
273 | if ($result && db_num_rows($result) == 0) { | |
274 | print json_encode(generate_error_feed($link, __("Feed not found."))); | |
fe1087fb AD |
275 | return; |
276 | } | |
277 | ||
51e196de AD |
278 | /* Updating a label ccache means recalculating all of the caches |
279 | * so for performance reasons we don't do that here */ | |
280 | ||
5225d420 AD |
281 | if ($feed >= 0) { |
282 | ccache_update($link, $feed, $_SESSION["uid"], $cat_view); | |
283 | } | |
0737b95a | 284 | |
45004d43 AD |
285 | set_pref($link, "_DEFAULT_VIEW_MODE", $view_mode); |
286 | set_pref($link, "_DEFAULT_VIEW_LIMIT", $limit); | |
7b4d02a8 | 287 | set_pref($link, "_DEFAULT_VIEW_ORDER_BY", $order_by); |
40496720 | 288 | |
45004d43 AD |
289 | if (!$cat_view && preg_match("/^[0-9][0-9]*$/", $feed)) { |
290 | db_query($link, "UPDATE ttrss_feeds SET last_viewed = NOW() | |
291 | WHERE id = '$feed' AND owner_uid = ".$_SESSION["uid"]); | |
292 | } | |
7466dc6a | 293 | |
bd202c3f AD |
294 | $reply['headlines'] = array(); |
295 | ||
296 | if (!$next_unread_feed) | |
297 | $reply['headlines']['id'] = $feed; | |
298 | else | |
299 | $reply['headlines']['id'] = $next_unread_feed; | |
300 | ||
301 | $reply['headlines']['is_cat'] = (bool) $cat_view; | |
009646d2 | 302 | |
a5c815d3 AD |
303 | $override_order = false; |
304 | ||
b3990c92 AD |
305 | if (get_pref($link, "SORT_HEADLINES_BY_FEED_DATE", $owner_uid)) { |
306 | $date_sort_field = "updated"; | |
307 | } else { | |
308 | $date_sort_field = "date_entered"; | |
309 | } | |
310 | ||
a5c815d3 AD |
311 | switch ($order_by) { |
312 | case "date": | |
313 | if (get_pref($link, 'REVERSE_HEADLINES', $owner_uid)) { | |
b3990c92 | 314 | $override_order = "$date_sort_field"; |
009646d2 | 315 | } else { |
b3990c92 | 316 | $override_order = "$date_sort_field DESC"; |
a5c815d3 AD |
317 | } |
318 | break; | |
c50e2b30 | 319 | |
a5c815d3 | 320 | case "title": |
7b20c977 | 321 | if (get_pref($link, 'REVERSE_HEADLINES', $owner_uid)) { |
b3990c92 | 322 | $override_order = "title DESC, $date_sort_field"; |
7b20c977 | 323 | } else { |
b3990c92 | 324 | $override_order = "title, $date_sort_field DESC"; |
7b20c977 | 325 | } |
a5c815d3 | 326 | break; |
d76a3b03 | 327 | |
a5c815d3 | 328 | case "score": |
7b20c977 | 329 | if (get_pref($link, 'REVERSE_HEADLINES', $owner_uid)) { |
b3990c92 | 330 | $override_order = "score, $date_sort_field"; |
7b20c977 | 331 | } else { |
b3990c92 | 332 | $override_order = "score DESC, $date_sort_field DESC"; |
7b20c977 | 333 | } |
a5c815d3 AD |
334 | break; |
335 | } | |
e19c1824 | 336 | |
905ff52a AD |
337 | if ($_REQUEST["debug"]) $timing_info = print_checkpoint("04", $timing_info); |
338 | ||
bd202c3f | 339 | $ret = format_headlines_list($link, $feed, $subop, |
009646d2 | 340 | $view_mode, $limit, $cat_view, $next_unread_feed, $offset, |
a5c815d3 | 341 | $vgroup_last_feed, $override_order); |
7b4d02a8 | 342 | |
a5c815d3 AD |
343 | $topmost_article_ids = $ret[0]; |
344 | $headlines_count = $ret[1]; | |
345 | $returned_feed = $ret[2]; | |
346 | $disable_cache = $ret[3]; | |
347 | $vgroup_last_feed = $ret[4]; | |
7b4d02a8 | 348 | |
bd202c3f AD |
349 | $reply['headlines']['content'] = $ret[5]; |
350 | $reply['headlines']['toolbar'] = $ret[6]; | |
46921916 | 351 | |
905ff52a AD |
352 | if ($_REQUEST["debug"]) $timing_info = print_checkpoint("05", $timing_info); |
353 | ||
cfcb7d42 | 354 | $headlines_unread = ccache_find($link, $returned_feed, $_SESSION["uid"], |
696a6850 AD |
355 | $cat_view, true); |
356 | ||
357 | if ($headlines_unread == -1) { | |
358 | $headlines_unread = getFeedUnread($link, $returned_feed, $cat_view); | |
696a6850 | 359 | } |
a5c815d3 | 360 | |
bd202c3f | 361 | $reply['headlines-info'] = array("count" => (int) $headlines_count, |
ffbe082d AD |
362 | "vgroup_last_feed" => $vgroup_last_feed, |
363 | "unread" => (int) $headlines_unread, | |
364 | "disable_cache" => (bool) $disable_cache); | |
365 | ||
bd202c3f | 366 | if ($_REQUEST["debug"]) $timing_info = print_checkpoint("20", $timing_info); |
009646d2 | 367 | |
bd202c3f | 368 | if (is_array($topmost_article_ids) && !get_pref($link, 'COMBINED_DISPLAY_MODE') && !$_SESSION["bw_limit"]) { |
009646d2 AD |
369 | $articles = array(); |
370 | ||
a5c815d3 | 371 | foreach ($topmost_article_ids as $id) { |
009646d2 | 372 | array_push($articles, format_article($link, $id, $feed, false)); |
45004d43 | 373 | } |
009646d2 | 374 | |
bd202c3f AD |
375 | $reply['articles'] = $articles; |
376 | } | |
46921916 | 377 | |
dd25b0c6 | 378 | if ($subop) { |
bd202c3f | 379 | $reply['counters'] = getAllCounters($link, $omode, $feed); |
009646d2 | 380 | } |
98bea1b1 | 381 | |
b4e75b2a | 382 | if ($_REQUEST["debug"]) $timing_info = print_checkpoint("30", $timing_info); |
46921916 | 383 | |
bd202c3f AD |
384 | $reply['runtime-info'] = make_runtime_info($link); |
385 | ||
386 | print json_encode($reply); | |
03c88bdd | 387 | |
45004d43 | 388 | break; // viewfeed |
1cd17194 | 389 | |
45004d43 AD |
390 | case "pref-feeds": |
391 | module_pref_feeds($link); | |
392 | break; // pref-feeds | |
a7f22b70 | 393 | |
45004d43 AD |
394 | case "pref-filters": |
395 | module_pref_filters($link); | |
396 | break; // pref-filters | |
a0476535 | 397 | |
45004d43 AD |
398 | case "pref-labels": |
399 | module_pref_labels($link); | |
400 | break; // pref-labels | |
d0000401 | 401 | |
45004d43 AD |
402 | case "pref-prefs": |
403 | module_pref_prefs($link); | |
404 | break; // pref-prefs | |
f27d955a | 405 | |
45004d43 AD |
406 | case "pref-users": |
407 | module_pref_users($link); | |
408 | break; // prefs-users | |
a0476535 | 409 | |
45004d43 AD |
410 | case "help": |
411 | module_help($link); | |
412 | break; // help | |
a0476535 | 413 | |
45004d43 AD |
414 | case "dlg": |
415 | module_popup_dialog($link); | |
416 | break; // dlg | |
a7f22b70 | 417 | |
45004d43 AD |
418 | case "pref-pub-items": |
419 | module_pref_pub_items($link); | |
420 | break; // pref-pub-items | |
e4f4b46f | 421 | |
45004d43 | 422 | case "globalUpdateFeeds": |
45004d43 | 423 | // Update all feeds needing a update. |
5cbaf873 | 424 | update_daemon_common($link, 0, true, true); |
45004d43 | 425 | break; // globalUpdateFeeds |
e5d758e3 | 426 | |
45004d43 AD |
427 | case "pref-feed-browser": |
428 | module_pref_feed_browser($link); | |
429 | break; // pref-feed-browser | |
c6232e43 | 430 | |
45004d43 | 431 | case "rss": |
b4e75b2a | 432 | $feed = db_escape_string($_REQUEST["id"]); |
8801fb01 | 433 | $key = db_escape_string($_REQUEST["key"]); |
b4e75b2a AD |
434 | $is_cat = $_REQUEST["is_cat"] != false; |
435 | $limit = (int)db_escape_string($_REQUEST["limit"]); | |
e1eb2147 | 436 | |
b4e75b2a AD |
437 | $search = db_escape_string($_REQUEST["q"]); |
438 | $match_on = db_escape_string($_REQUEST["m"]); | |
439 | $search_mode = db_escape_string($_REQUEST["smode"]); | |
2f2bd1b3 | 440 | $view_mode = db_escape_string($_REQUEST["view-mode"]); |
18664970 | 441 | |
b4798282 AD |
442 | if (SINGLE_USER_MODE) { |
443 | authenticate_user($link, "admin", null); | |
444 | } | |
445 | ||
8e57cfbe | 446 | $owner_id = false; |
19039fd0 | 447 | |
8e57cfbe | 448 | if ($key) { |
8801fb01 AD |
449 | $result = db_query($link, "SELECT owner_uid FROM |
450 | ttrss_access_keys WHERE access_key = '$key' AND feed_id = '$feed'"); | |
451 | ||
452 | if (db_num_rows($result) == 1) | |
8e57cfbe | 453 | $owner_id = db_fetch_result($result, 0, "owner_uid"); |
45004d43 | 454 | } |
18664970 | 455 | |
8e57cfbe AD |
456 | if ($owner_id) { |
457 | $_SESSION['uid'] = $owner_id; | |
458 | ||
23d72f39 AD |
459 | generate_syndicated_feed($link, 0, $feed, $is_cat, $limit, |
460 | $search, $search_mode, $match_on, $view_mode); | |
19039fd0 AD |
461 | } else { |
462 | header('HTTP/1.1 403 Forbidden'); | |
45004d43 AD |
463 | } |
464 | break; // rss | |
18664970 | 465 | |
45004d43 | 466 | case "getUnread": |
b4e75b2a | 467 | $login = db_escape_string($_REQUEST["login"]); |
1f7b77d1 | 468 | $fresh = $_REQUEST["fresh"] == "1"; |
f3acc32e | 469 | |
45004d43 | 470 | $result = db_query($link, "SELECT id FROM ttrss_users WHERE login = '$login'"); |
7e3634d9 | 471 | |
45004d43 AD |
472 | if (db_num_rows($result) == 1) { |
473 | $uid = db_fetch_result($result, 0, "id"); | |
1f7b77d1 | 474 | |
45004d43 | 475 | print getGlobalUnread($link, $uid); |
1f7b77d1 AD |
476 | |
477 | if ($fresh) { | |
478 | print ";"; | |
479 | print getFeedArticles($link, -3, false, true, $uid); | |
480 | } | |
481 | ||
45004d43 AD |
482 | } else { |
483 | print "-1;User not found"; | |
484 | } | |
7e3634d9 | 485 | |
45004d43 AD |
486 | $print_exec_time = false; |
487 | break; // getUnread | |
9cd7c995 | 488 | |
45004d43 | 489 | case "digestTest": |
45004d43 AD |
490 | print_r(prepare_headlines_digest($link, $_SESSION["uid"])); |
491 | $print_exec_time = false; | |
492 | break; // digestTest | |
448b0abd | 493 | |
45004d43 | 494 | case "digestSend": |
45004d43 AD |
495 | send_headlines_digests($link); |
496 | $print_exec_time = false; | |
497 | break; // digestSend | |
7e3634d9 | 498 | |
ba7e88e5 | 499 | case "loading": |
009646d2 | 500 | print __("Loading, please wait...") . " " . |
ba7e88e5 AD |
501 | "<img src='images/indicator_tiny.gif'>"; |
502 | ||
d9084cf2 AD |
503 | case "getProfiles": |
504 | $login = db_escape_string($_REQUEST["login"]); | |
505 | $password = db_escape_string($_REQUEST["password"]); | |
506 | ||
507 | if (authenticate_user($link, $login, $password)) { | |
508 | $result = db_query($link, "SELECT * FROM ttrss_settings_profiles | |
509 | WHERE owner_uid = " . $_SESSION["uid"] . " ORDER BY title"); | |
510 | ||
511 | print "<select style='width: 100%' name='profile'>"; | |
512 | ||
513 | print "<option value='0'>" . __("Default profile") . "</option>"; | |
514 | ||
515 | while ($line = db_fetch_assoc($result)) { | |
516 | $id = $line["id"]; | |
517 | $title = $line["title"]; | |
518 | ||
519 | print "<option value='$id'>$title</option>"; | |
520 | } | |
521 | ||
522 | print "</select>"; | |
523 | ||
524 | $_SESSION = array(); | |
0456176a | 525 | } |
d9084cf2 | 526 | break; |
d9084cf2 | 527 | |
5ab9791f AD |
528 | case "pubsub": |
529 | $mode = db_escape_string($_REQUEST['hub_mode']); | |
530 | $feed_id = db_escape_string($_REQUEST['id']); | |
531 | $feed_url = db_escape_string($_REQUEST['hub_topic']); | |
532 | ||
533 | // TODO: implement hub_verifytoken checking | |
534 | ||
535 | $result = db_query($link, "SELECT feed_url FROM ttrss_feeds | |
536 | WHERE id = '$feed_id'"); | |
537 | ||
538 | $check_feed_url = db_fetch_result($result, 0, "feed_url"); | |
539 | ||
540 | if ($check_feed_url && ($check_feed_url == $feed_url || !$feed_url)) { | |
541 | if ($mode == "subscribe") { | |
542 | ||
543 | db_query($link, "UPDATE ttrss_feeds SET pubsub_state = 2 | |
544 | WHERE id = '$feed_id'"); | |
545 | ||
546 | echo $_REQUEST['hub_challenge']; | |
547 | } else if ($mode == "unsubscribe") { | |
548 | ||
549 | db_query($link, "UPDATE ttrss_feeds SET pubsub_state = 0 | |
550 | WHERE id = '$feed_id'"); | |
551 | ||
552 | echo $_REQUEST['hub_challenge']; | |
553 | } else if (!$mode) { | |
f3acc32e | 554 | |
5ab9791f AD |
555 | // Received update ping, schedule feed update. |
556 | ||
557 | update_rss_feed($link, $feed_id, true, true); | |
558 | ||
559 | } | |
560 | } else { | |
561 | header('HTTP/1.0 404 Not Found'); | |
562 | } | |
563 | ||
564 | break; | |
565 | } // Select action according to $op value. | |
ba7e88e5 | 566 | |
45004d43 | 567 | // We close the connection to database. |
4b3dff6e | 568 | db_close($link); |
1cd17194 | 569 | ?> |
406d9489 | 570 | |
7e3634d9 | 571 | <?php if ($print_exec_time) { ?> |
1d3a17c7 | 572 | <!-- <?php echo sprintf("Backend execution time: %.4f seconds", getmicrotime() - $script_started) ?> --> |
f3acc32e | 573 | <?php } ?> |