]> git.wh0rd.org - tt-rss.git/blame - backend.php
add missing schema files for version 86
[tt-rss.git] / backend.php
CommitLineData
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" &&
83cd33fc 62 $op != "rss" && $op != "getUnread" && $op != "getProfiles" && $op != "share" &&
ae5f7bb1 63 $op != "fbexport" && $op != "logout" && $op != "pubsub") {
009646d2 64
d0f73380
AD
65 if ($op == 'pref-feeds' && $_REQUEST['subop'] == 'add') {
66 header("Content-Type: text/html");
67 login_sequence($link);
68 render_login_form($link);
69 } else {
70 header("Content-Type: text/plain");
71 print json_encode(array("error" => array("code" => 6)));
72 }
009646d2 73 return;
262bd8ea 74 }
1c7f75ed 75
ad815c71 76 $purge_intervals = array(
d1db26aa
AD
77 0 => __("Use default"),
78 -1 => __("Never purge"),
79 5 => __("1 week old"),
80 14 => __("2 weeks old"),
81 31 => __("1 month old"),
82 60 => __("2 months old"),
83 90 => __("3 months old"));
ad815c71
AD
84
85 $update_intervals = array(
ecace165 86 0 => __("Default interval"),
d1db26aa 87 -1 => __("Disable updates"),
1e7cbe16 88 15 => __("Each 15 minutes"),
d1db26aa 89 30 => __("Each 30 minutes"),
505f2f0e
AD
90 60 => __("Hourly"),
91 240 => __("Each 4 hours"),
92 720 => __("Each 12 hours"),
93 1440 => __("Daily"),
94 10080 => __("Weekly"));
95
96 $update_intervals_nodefault = array(
97 -1 => __("Disable updates"),
98 15 => __("Each 15 minutes"),
99 30 => __("Each 30 minutes"),
d1db26aa
AD
100 60 => __("Hourly"),
101 240 => __("Each 4 hours"),
102 720 => __("Each 12 hours"),
103 1440 => __("Daily"),
104 10080 => __("Weekly"));
ad815c71 105
16211ddb 106 $update_methods = array(
ecace165 107 0 => __("Default"),
0dd9c0cf 108 1 => __("Magpie"),
009646d2 109 2 => __("SimplePie"),
b3009bcd 110 3 => __("Twitter OAuth"));
16211ddb 111
78a5c296 112 if (DEFAULT_UPDATE_METHOD == "1") {
16211ddb
AD
113 $update_methods[0] .= ' (SimplePie)';
114 } else {
115 $update_methods[0] .= ' (Magpie)';
116 }
117
3c5783b7 118 $access_level_names = array(
009646d2 119 0 => __("User"),
a88d37e5 120 5 => __("Power User"),
d1db26aa 121 10 => __("Administrator"));
3c5783b7 122
f27d955a 123 require_once "modules/pref-prefs.php";
ef8be8ea
AD
124 require_once "modules/popup-dialog.php";
125 require_once "modules/help.php";
126 require_once "modules/pref-feeds.php";
127 require_once "modules/pref-filters.php";
128 require_once "modules/pref-labels.php";
129 require_once "modules/pref-users.php";
373266eb 130 require_once "modules/pref-instances.php";
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":
141 // Handle remote procedure calls.
142 handle_rpc_request($link);
143 break; // rpc
144
145 case "feeds":
b4e75b2a 146 $subop = $_REQUEST["subop"];
1985a5e0 147 $root = (bool)$_REQUEST["root"];
45004d43
AD
148
149 switch($subop) {
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
AD
256 $feed = db_escape_string($_REQUEST["feed"]);
257 $subop = db_escape_string($_REQUEST["subop"]);
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
bd202c3f 356 $ret = format_headlines_list($link, $feed, $subop,
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
81787bbf
AD
389// if ($subop) {
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);
03c88bdd 398
45004d43 399 break; // viewfeed
1cd17194 400
45004d43
AD
401 case "pref-feeds":
402 module_pref_feeds($link);
403 break; // pref-feeds
a7f22b70 404
45004d43
AD
405 case "pref-filters":
406 module_pref_filters($link);
407 break; // pref-filters
a0476535 408
45004d43
AD
409 case "pref-labels":
410 module_pref_labels($link);
411 break; // pref-labels
d0000401 412
45004d43
AD
413 case "pref-prefs":
414 module_pref_prefs($link);
415 break; // pref-prefs
f27d955a 416
45004d43
AD
417 case "pref-users":
418 module_pref_users($link);
419 break; // prefs-users
a0476535 420
45004d43
AD
421 case "help":
422 module_help($link);
423 break; // help
a0476535 424
45004d43
AD
425 case "dlg":
426 module_popup_dialog($link);
427 break; // dlg
a7f22b70 428
45004d43
AD
429 case "pref-pub-items":
430 module_pref_pub_items($link);
431 break; // pref-pub-items
e4f4b46f 432
45004d43 433 case "globalUpdateFeeds":
45004d43 434 // Update all feeds needing a update.
5cbaf873 435 update_daemon_common($link, 0, true, true);
45004d43 436 break; // globalUpdateFeeds
e5d758e3 437
45004d43
AD
438 case "pref-feed-browser":
439 module_pref_feed_browser($link);
440 break; // pref-feed-browser
c6232e43 441
373266eb
AD
442 case "pref-instances":
443 module_pref_instances($link);
444 break; // pref-instances
445
45004d43 446 case "rss":
b4e75b2a 447 $feed = db_escape_string($_REQUEST["id"]);
8801fb01 448 $key = db_escape_string($_REQUEST["key"]);
b4e75b2a
AD
449 $is_cat = $_REQUEST["is_cat"] != false;
450 $limit = (int)db_escape_string($_REQUEST["limit"]);
e1eb2147 451
b4e75b2a
AD
452 $search = db_escape_string($_REQUEST["q"]);
453 $match_on = db_escape_string($_REQUEST["m"]);
454 $search_mode = db_escape_string($_REQUEST["smode"]);
2f2bd1b3 455 $view_mode = db_escape_string($_REQUEST["view-mode"]);
18664970 456
b4798282
AD
457 if (SINGLE_USER_MODE) {
458 authenticate_user($link, "admin", null);
459 }
460
8e57cfbe 461 $owner_id = false;
19039fd0 462
8e57cfbe 463 if ($key) {
8801fb01
AD
464 $result = db_query($link, "SELECT owner_uid FROM
465 ttrss_access_keys WHERE access_key = '$key' AND feed_id = '$feed'");
466
467 if (db_num_rows($result) == 1)
8e57cfbe 468 $owner_id = db_fetch_result($result, 0, "owner_uid");
45004d43 469 }
18664970 470
8e57cfbe
AD
471 if ($owner_id) {
472 $_SESSION['uid'] = $owner_id;
473
23d72f39
AD
474 generate_syndicated_feed($link, 0, $feed, $is_cat, $limit,
475 $search, $search_mode, $match_on, $view_mode);
19039fd0
AD
476 } else {
477 header('HTTP/1.1 403 Forbidden');
45004d43
AD
478 }
479 break; // rss
18664970 480
45004d43 481 case "getUnread":
b4e75b2a 482 $login = db_escape_string($_REQUEST["login"]);
1f7b77d1 483 $fresh = $_REQUEST["fresh"] == "1";
f3acc32e 484
45004d43 485 $result = db_query($link, "SELECT id FROM ttrss_users WHERE login = '$login'");
7e3634d9 486
45004d43
AD
487 if (db_num_rows($result) == 1) {
488 $uid = db_fetch_result($result, 0, "id");
1f7b77d1 489
45004d43 490 print getGlobalUnread($link, $uid);
1f7b77d1
AD
491
492 if ($fresh) {
493 print ";";
494 print getFeedArticles($link, -3, false, true, $uid);
495 }
496
45004d43
AD
497 } else {
498 print "-1;User not found";
499 }
7e3634d9 500
45004d43 501 break; // getUnread
9cd7c995 502
45004d43 503 case "digestTest":
45004d43 504 print_r(prepare_headlines_digest($link, $_SESSION["uid"]));
45004d43 505 break; // digestTest
448b0abd 506
45004d43 507 case "digestSend":
45004d43 508 send_headlines_digests($link);
45004d43 509 break; // digestSend
7e3634d9 510
ba7e88e5 511 case "loading":
347b467b 512 header("Content-type: text/html");
009646d2 513 print __("Loading, please wait...") . " " .
ba7e88e5 514 "<img src='images/indicator_tiny.gif'>";
373266eb 515 break; // loading
ba7e88e5 516
d9084cf2
AD
517 case "getProfiles":
518 $login = db_escape_string($_REQUEST["login"]);
519 $password = db_escape_string($_REQUEST["password"]);
520
521 if (authenticate_user($link, $login, $password)) {
522 $result = db_query($link, "SELECT * FROM ttrss_settings_profiles
523 WHERE owner_uid = " . $_SESSION["uid"] . " ORDER BY title");
524
525 print "<select style='width: 100%' name='profile'>";
526
527 print "<option value='0'>" . __("Default profile") . "</option>";
528
529 while ($line = db_fetch_assoc($result)) {
530 $id = $line["id"];
531 $title = $line["title"];
532
533 print "<option value='$id'>$title</option>";
534 }
535
536 print "</select>";
537
538 $_SESSION = array();
0456176a 539 }
373266eb 540 break; // getprofiles
d9084cf2 541
5ab9791f
AD
542 case "pubsub":
543 $mode = db_escape_string($_REQUEST['hub_mode']);
4dd369d4 544 $feed_id = (int) db_escape_string($_REQUEST['id']);
5ab9791f
AD
545 $feed_url = db_escape_string($_REQUEST['hub_topic']);
546
e2d2339c
AD
547 if (!PUBSUBHUBBUB_ENABLED) {
548 header('HTTP/1.0 404 Not Found');
549 echo "404 Not found";
550 return;
551 }
552
5ab9791f
AD
553 // TODO: implement hub_verifytoken checking
554
555 $result = db_query($link, "SELECT feed_url FROM ttrss_feeds
556 WHERE id = '$feed_id'");
557
97279fe6 558 if (db_num_rows($result) != 0) {
5ab9791f 559
97279fe6 560 $check_feed_url = db_fetch_result($result, 0, "feed_url");
5ab9791f 561
97279fe6
AD
562 if ($check_feed_url && ($check_feed_url == $feed_url || !$feed_url)) {
563 if ($mode == "subscribe") {
5ab9791f 564
97279fe6
AD
565 db_query($link, "UPDATE ttrss_feeds SET pubsub_state = 2
566 WHERE id = '$feed_id'");
7e0943c6 567
97279fe6
AD
568 print $_REQUEST['hub_challenge'];
569 return;
5ab9791f 570
97279fe6 571 } else if ($mode == "unsubscribe") {
5ab9791f 572
97279fe6
AD
573 db_query($link, "UPDATE ttrss_feeds SET pubsub_state = 0
574 WHERE id = '$feed_id'");
7e0943c6 575
97279fe6
AD
576 print $_REQUEST['hub_challenge'];
577 return;
f3acc32e 578
97279fe6 579 } else if (!$mode) {
5ab9791f 580
97279fe6 581 // Received update ping, schedule feed update.
1b790343 582 //update_rss_feed($link, $feed_id, true, true);
5ab9791f 583
1b790343
AD
584 db_query($link, "UPDATE ttrss_feeds SET
585 last_update_started = '1970-01-01',
586 last_updated = '1970-01-01' WHERE id = '$feed_id' AND
587 owner_uid = ".$_SESSION["uid"]);
97279fe6
AD
588
589 }
590 } else {
591 header('HTTP/1.0 404 Not Found');
592 echo "404 Not found";
5ab9791f
AD
593 }
594 } else {
595 header('HTTP/1.0 404 Not Found');
97279fe6 596 echo "404 Not found";
5ab9791f
AD
597 }
598
373266eb 599 break; // pubsub
1ca77e0a
AD
600
601 case "logout":
602 logout_user();
603 header("Location: tt-rss.php");
373266eb 604 break; // logout
1ca77e0a 605
ae5f7bb1
AD
606 case "fbexport":
607
9b201046 608 $access_key = db_escape_string($_POST["key"]);
ae5f7bb1
AD
609
610 // TODO: rate limit checking using last_connected
611 $result = db_query($link, "SELECT id FROM ttrss_linked_instances
612 WHERE access_key = '$access_key'");
613
614 if (db_num_rows($result) == 1) {
615
616 $instance_id = db_fetch_result($result, 0, "id");
617
109662e1 618 $result = db_query($link, "SELECT feed_url, site_url, title, subscribers
ae5f7bb1
AD
619 FROM ttrss_feedbrowser_cache ORDER BY subscribers DESC LIMIT 100");
620
621 $feeds = array();
622
623 while ($line = db_fetch_assoc($result)) {
624 array_push($feeds, $line);
625 }
626
572d66c6 627 db_query($link, "UPDATE ttrss_linked_instances SET
ae5f7bb1
AD
628 last_status_in = 1 WHERE id = '$instance_id'");
629
630 print json_encode(array("feeds" => $feeds));
631 } else {
632 print json_encode(array("error" => array("code" => 6)));
633 }
634 break; // fbexport
635
83cd33fc
AD
636 case "share":
637 $uuid = db_escape_string($_REQUEST["key"]);
638
639 $result = db_query($link, "SELECT ref_id, owner_uid FROM ttrss_user_entries WHERE
640 uuid = '$uuid'");
641
642 if (db_num_rows($result) != 0) {
643 header("Content-Type: text/html");
644
645 $id = db_fetch_result($result, 0, "ref_id");
646 $owner_uid = db_fetch_result($result, 0, "owner_uid");
647
648 $article = format_article($link, $id, false, true);
649
650 print_r($article['content']);
651
652 } else {
653 print "Article not found.";
654 }
655
656 break;
657
1ca77e0a
AD
658 default:
659 header("Content-Type: text/plain");
660 print json_encode(array("error" => array("code" => 7)));
373266eb 661 break; // fallback
5ab9791f 662 } // Select action according to $op value.
ba7e88e5 663
45004d43 664 // We close the connection to database.
4b3dff6e 665 db_close($link);
1cd17194 666?>