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