]> git.wh0rd.org - tt-rss.git/blob - modules/backend-rpc.php
rpc: no longer use XML
[tt-rss.git] / modules / backend-rpc.php
1 <?php
2 function handle_rpc_request($link) {
3
4 $subop = $_REQUEST["subop"];
5 $seq = (int) $_REQUEST["seq"];
6
7 // Silent
8 if ($subop == "setprofile") {
9 $id = db_escape_string($_REQUEST["id"]);
10
11 $_SESSION["profile"] = $id;
12 $_SESSION["prefs_cache"] = array();
13 return;
14 }
15
16 // Silent
17 if ($subop == "remprofiles") {
18 $ids = split(",", db_escape_string(trim($_REQUEST["ids"])));
19
20 foreach ($ids as $id) {
21 if ($_SESSION["profile"] != $id) {
22 db_query($link, "DELETE FROM ttrss_settings_profiles WHERE id = '$id' AND
23 owner_uid = " . $_SESSION["uid"]);
24 }
25 }
26 return;
27 }
28
29 // Silent
30 if ($subop == "addprofile") {
31 $title = db_escape_string(trim($_REQUEST["title"]));
32 if ($title) {
33 db_query($link, "BEGIN");
34
35 $result = db_query($link, "SELECT id FROM ttrss_settings_profiles
36 WHERE title = '$title' AND owner_uid = " . $_SESSION["uid"]);
37
38 if (db_num_rows($result) == 0) {
39
40 db_query($link, "INSERT INTO ttrss_settings_profiles (title, owner_uid)
41 VALUES ('$title', ".$_SESSION["uid"] .")");
42
43 $result = db_query($link, "SELECT id FROM ttrss_settings_profiles WHERE
44 title = '$title'");
45
46 if (db_num_rows($result) != 0) {
47 $profile_id = db_fetch_result($result, 0, "id");
48
49 if ($profile_id) {
50 initialize_user_prefs($link, $_SESSION["uid"], $profile_id);
51 }
52 }
53 }
54
55 db_query($link, "COMMIT");
56 }
57 return;
58 }
59
60 // Silent
61 if ($subop == "saveprofile") {
62 $id = db_escape_string($_REQUEST["id"]);
63 $title = db_escape_string(trim($_REQUEST["value"]));
64
65 if ($id == 0) {
66 print __("Default profile");
67 return;
68 }
69
70 if ($title) {
71 db_query($link, "BEGIN");
72
73 $result = db_query($link, "SELECT id FROM ttrss_settings_profiles
74 WHERE title = '$title' AND owner_uid =" . $_SESSION["uid"]);
75
76 if (db_num_rows($result) == 0) {
77 db_query($link, "UPDATE ttrss_settings_profiles
78 SET title = '$title' WHERE id = '$id' AND
79 owner_uid = " . $_SESSION["uid"]);
80 print $title;
81 } else {
82 $result = db_query($link, "SELECT title FROM ttrss_settings_profiles
83 WHERE id = '$id' AND owner_uid =" . $_SESSION["uid"]);
84 print db_fetch_result($result, 0, "title");
85 }
86
87 db_query($link, "COMMIT");
88 }
89 return;
90 }
91
92 // Silent
93 if ($subop == "remarchive") {
94 $ids = split(",", db_escape_string($_REQUEST["ids"]));
95
96 foreach ($ids as $id) {
97 $result = db_query($link, "DELETE FROM ttrss_archived_feeds WHERE
98 (SELECT COUNT(*) FROM ttrss_user_entries
99 WHERE orig_feed_id = '$id') = 0 AND
100 id = '$id' AND owner_uid = ".$_SESSION["uid"]);
101
102 $rc = db_affected_rows($link, $result);
103 }
104 return;
105 }
106
107 if ($subop == "addfeed") {
108 $feed = db_escape_string($_REQUEST['feed']);
109 $cat = db_escape_string($_REQUEST['cat']);
110 $login = db_escape_string($_REQUEST['login']);
111 $pass = db_escape_string($_REQUEST['pass']);
112
113 $rc = subscribe_to_feed($link, $feed, $cat, $login, $pass);
114
115 print json_encode(array("result" => $rc));
116
117 return;
118
119 }
120
121 if ($subop == "extractfeedurls") {
122
123 $urls = get_feeds_from_html($_REQUEST['url']);
124
125 print json_encode(array("urls" => $urls));
126 return;
127 }
128
129 if ($subop == "togglepref") {
130 $key = db_escape_string($_REQUEST["key"]);
131 set_pref($link, $key, !get_pref($link, $key));
132 $value = get_pref($link, $key);
133
134 print json_encode(array("param" =>$key, "value" => $value));
135 return;
136 }
137
138 if ($subop == "setpref") {
139 $value = str_replace("\n", "<br/>", $_REQUEST['value']);
140
141 $key = db_escape_string($_REQUEST["key"]);
142 $value = db_escape_string($value);
143
144 set_pref($link, $key, $value);
145
146 print json_encode(array("param" =>$key, "value" => $value));
147 return;
148 }
149
150 if ($subop == "mark") {
151 $mark = $_REQUEST["mark"];
152 $id = db_escape_string($_REQUEST["id"]);
153
154 if ($mark == "1") {
155 $mark = "true";
156 } else {
157 $mark = "false";
158 }
159
160 $result = db_query($link, "UPDATE ttrss_user_entries SET marked = $mark
161 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
162
163 print json_encode(array("message" => "UPDATE_COUNTERS"));
164 return;
165 }
166
167 if ($subop == "delete") {
168 $ids = db_escape_string($_REQUEST["ids"]);
169
170 $result = db_query($link, "DELETE FROM ttrss_user_entries
171 WHERE ref_id IN ($ids) AND owner_uid = " . $_SESSION["uid"]);
172
173 print json_encode(array("message" => "UPDATE_COUNTERS"));
174 return;
175 }
176
177 if ($subop == "unarchive") {
178 $ids = db_escape_string($_REQUEST["ids"]);
179
180 $result = db_query($link, "UPDATE ttrss_user_entries
181 SET feed_id = orig_feed_id, orig_feed_id = NULL
182 WHERE ref_id IN ($ids) AND owner_uid = " . $_SESSION["uid"]);
183
184 print json_encode(array("message" => "UPDATE_COUNTERS"));
185 return;
186 }
187
188 if ($subop == "archive") {
189 $ids = split(",", db_escape_string($_REQUEST["ids"]));
190
191 foreach ($ids as $id) {
192 archive_article($link, $id, $_SESSION["uid"]);
193 }
194
195 print json_encode(array("message" => "UPDATE_COUNTERS"));
196 return;
197 }
198
199 if ($subop == "publ") {
200 $pub = $_REQUEST["pub"];
201 $id = db_escape_string($_REQUEST["id"]);
202 $note = trim(strip_tags(db_escape_string($_REQUEST["note"])));
203
204 if ($pub == "1") {
205 $pub = "true";
206 } else {
207 $pub = "false";
208 }
209
210 $result = db_query($link, "UPDATE ttrss_user_entries SET
211 published = $pub
212 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
213
214 print json_encode(array("message" => "UPDATE_COUNTERS"));
215 return;
216 }
217
218 /* if ($subop == "updateFeed") {
219 $feed_id = db_escape_string($_REQUEST["feed"]);
220
221 update_rss_feed($link, $feed_id);
222
223 print "<rpc-reply>";
224 print "<message>UPDATE_COUNTERS</message>";
225 print "</rpc-reply>";
226
227 return;
228 } */
229
230 if ($subop == "updateAllFeeds" || $subop == "getAllCounters") {
231 $last_article_id = (int) $_REQUEST["last_article_id"];
232
233 $reply = array();
234
235 if ($seq) $reply['seq'] = $seq;
236
237 if ($last_article_id != getLastArticleId($link)) {
238 $omode = $_REQUEST["omode"];
239
240 if ($omode != "T")
241 $reply['counters'] = getAllCounters($link, $omode);
242 else
243 $reply['counters'] = getGlobalCounters($link);
244 }
245
246 $reply['runtime-info'] = make_runtime_info($link);
247
248
249 print json_encode($reply);
250 return;
251 }
252
253 /* GET["cmode"] = 0 - mark as read, 1 - as unread, 2 - toggle */
254 if ($subop == "catchupSelected") {
255 $ids = split(",", db_escape_string($_REQUEST["ids"]));
256 $cmode = sprintf("%d", $_REQUEST["cmode"]);
257
258 catchupArticlesById($link, $ids, $cmode);
259
260 print json_encode(array("message" => "UPDATE_COUNTERS"));
261 return;
262 }
263
264 if ($subop == "markSelected") {
265 $ids = split(",", db_escape_string($_REQUEST["ids"]));
266 $cmode = sprintf("%d", $_REQUEST["cmode"]);
267
268 markArticlesById($link, $ids, $cmode);
269
270 print json_encode(array("message" => "UPDATE_COUNTERS"));
271 return;
272 }
273
274 if ($subop == "publishSelected") {
275 $ids = split(",", db_escape_string($_REQUEST["ids"]));
276 $cmode = sprintf("%d", $_REQUEST["cmode"]);
277
278 publishArticlesById($link, $ids, $cmode);
279
280 print json_encode(array("message" => "UPDATE_COUNTERS"));
281 return;
282 }
283
284 if ($subop == "sanityCheck") {
285 $_SESSION["hasAudio"] = $_REQUEST["hasAudio"] === "true";
286
287 $reply = array();
288
289 $reply['error'] = sanity_check($link);
290
291 if ($reply['error']['code'] == 0) {
292 $reply['init-params'] = make_init_params($link);
293 $reply['runtime-info'] = make_runtime_info($link);
294 }
295
296 print json_encode($reply);
297 return;
298 }
299
300 /* if ($subop == "globalPurge") {
301
302 print "<rpc-reply>";
303 global_purge_old_posts($link, true);
304 print "</rpc-reply>";
305
306 return;
307 } */
308
309 if ($subop == "setArticleTags") {
310 global $memcache;
311
312 $id = db_escape_string($_REQUEST["id"]);
313
314 $tags_str = db_escape_string($_REQUEST["tags_str"]);
315 $tags = array_unique(trim_array(split(",", $tags_str)));
316
317 db_query($link, "BEGIN");
318
319 $result = db_query($link, "SELECT int_id FROM ttrss_user_entries WHERE
320 ref_id = '$id' AND owner_uid = '".$_SESSION["uid"]."' LIMIT 1");
321
322 if (db_num_rows($result) == 1) {
323
324 $tags_to_cache = array();
325
326 $int_id = db_fetch_result($result, 0, "int_id");
327
328 db_query($link, "DELETE FROM ttrss_tags WHERE
329 post_int_id = $int_id AND owner_uid = '".$_SESSION["uid"]."'");
330
331 foreach ($tags as $tag) {
332 $tag = sanitize_tag($tag);
333
334 if (!tag_is_valid($tag)) {
335 continue;
336 }
337
338 if (preg_match("/^[0-9]*$/", $tag)) {
339 continue;
340 }
341
342 // print "<!-- $id : $int_id : $tag -->";
343
344 if ($tag != '') {
345 db_query($link, "INSERT INTO ttrss_tags
346 (post_int_id, owner_uid, tag_name) VALUES ('$int_id', '".$_SESSION["uid"]."', '$tag')");
347 }
348
349 array_push($tags_to_cache, $tag);
350 }
351
352 /* update tag cache */
353
354 $tags_str = join(",", $tags_to_cache);
355
356 db_query($link, "UPDATE ttrss_user_entries
357 SET tag_cache = '$tags_str' WHERE ref_id = '$id'
358 AND owner_uid = " . $_SESSION["uid"]);
359 }
360
361 db_query($link, "COMMIT");
362
363 if ($memcache) {
364 $obj_id = md5("TAGS:".$_SESSION["uid"].":$id");
365 $memcache->delete($obj_id);
366 }
367
368 $tags_str = format_tags_string(get_article_tags($link, $id), $id);
369
370 print json_encode(array("tags_str" => array("id" => $id,
371 "content" => $tags_str)));
372
373 return;
374 }
375
376 if ($subop == "regenOPMLKey") {
377 update_feed_access_key($link, 'OPML:Publish',
378 false, $_SESSION["uid"]);
379
380 $new_link = opml_publish_url($link);
381
382 print json_encode(array("link" => $new_link));
383 return;
384 }
385
386 if ($subop == "completeTags") {
387 $search = db_escape_string($_REQUEST["search"]);
388
389 $result = db_query($link, "SELECT DISTINCT tag_name FROM ttrss_tags
390 WHERE owner_uid = '".$_SESSION["uid"]."' AND
391 tag_name LIKE '$search%' ORDER BY tag_name
392 LIMIT 10");
393
394 print "<ul>";
395 while ($line = db_fetch_assoc($result)) {
396 print "<li>" . $line["tag_name"] . "</li>";
397 }
398 print "</ul>";
399
400 return;
401 }
402
403 if ($subop == "purge") {
404 $ids = split(",", db_escape_string($_REQUEST["ids"]));
405 $days = sprintf("%d", $_REQUEST["days"]);
406
407 foreach ($ids as $id) {
408
409 $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE
410 id = '$id' AND owner_uid = ".$_SESSION["uid"]);
411
412 if (db_num_rows($result) == 1) {
413 purge_feed($link, $id, $days);
414 }
415 }
416
417 return;
418 }
419
420 /* if ($subop == "setScore") {
421 $id = db_escape_string($_REQUEST["id"]);
422 $score = sprintf("%d", $_REQUEST["score"]);
423
424 $result = db_query($link, "UPDATE ttrss_user_entries SET score = '$score'
425 WHERE ref_id = '$id' AND owner_uid = ".$_SESSION["uid"]);
426
427 print "<rpc-reply><message>Acknowledged.</message></rpc-reply>";
428
429 return;
430
431 } */
432
433 if ($subop == "getArticles") {
434 $ids = split(",", db_escape_string($_REQUEST["ids"]));
435 $articles = array();
436
437 foreach ($ids as $id) {
438 if ($id) {
439 array_push($articles, format_article($link, $id, 0, false));
440 }
441 }
442
443 print json_encode($articles);
444 return;
445 }
446
447 if ($subop == "checkDate") {
448 $date = db_escape_string($_REQUEST["date"]);
449 $date_parsed = strtotime($date);
450
451 print json_encode(array("result" => (bool)$date_parsed));
452 return;
453 }
454
455 if ($subop == "assignToLabel" || $subop == "removeFromLabel") {
456 $reply = array();
457
458 $ids = split(",", db_escape_string($_REQUEST["ids"]));
459 $label_id = db_escape_string($_REQUEST["lid"]);
460
461 $label = db_escape_string(label_find_caption($link, $label_id,
462 $_SESSION["uid"]));
463
464 $reply["info-for-headlines"] = array();
465
466 if ($label) {
467
468 foreach ($ids as $id) {
469
470 if ($subop == "assignToLabel")
471 label_add_article($link, $id, $label, $_SESSION["uid"]);
472 else
473 label_remove_article($link, $id, $label, $_SESSION["uid"]);
474
475 $labels = get_article_labels($link, $id, $_SESSION["uid"]);
476
477 array_push($reply["info-for-headlines"],
478 array("id" => $id, "labels" => format_article_labels($labels, $id)));
479
480 }
481 }
482
483 $reply["message"] = "UPDATE_COUNTERS";
484
485 print json_encode($reply);
486
487 return;
488 }
489
490 if ($subop == "updateFeedBrowser") {
491 $search = db_escape_string($_REQUEST["search"]);
492 $limit = db_escape_string($_REQUEST["limit"]);
493 $mode = (int) db_escape_string($_REQUEST["mode"]);
494
495 print json_encode(array("content" =>
496 make_feed_browser($link, $search, $limit, $mode),
497 "mode" => $mode));
498 return;
499 }
500
501 // Silent
502 if ($subop == "massSubscribe") {
503
504 $ids = split(",", db_escape_string($_REQUEST["ids"]));
505 $mode = $_REQUEST["mode"];
506
507 $subscribed = array();
508
509 foreach ($ids as $id) {
510
511 if ($mode == 1) {
512 $result = db_query($link, "SELECT feed_url,title FROM ttrss_feeds
513 WHERE id = '$id'");
514 } else if ($mode == 2) {
515 $result = db_query($link, "SELECT * FROM ttrss_archived_feeds
516 WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]);
517 $orig_id = db_escape_string(db_fetch_result($result, 0, "id"));
518 $site_url = db_escape_string(db_fetch_result($result, 0, "site_url"));
519 }
520
521 $feed_url = db_escape_string(db_fetch_result($result, 0, "feed_url"));
522 $title = db_escape_string(db_fetch_result($result, 0, "title"));
523
524 $title_orig = db_fetch_result($result, 0, "title");
525
526 $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE
527 feed_url = '$feed_url' AND owner_uid = " . $_SESSION["uid"]);
528
529 if (db_num_rows($result) == 0) {
530 if ($mode == 1) {
531 $result = db_query($link,
532 "INSERT INTO ttrss_feeds (owner_uid,feed_url,title,cat_id)
533 VALUES ('".$_SESSION["uid"]."', '$feed_url', '$title', NULL)");
534 } else if ($mode == 2) {
535 $result = db_query($link,
536 "INSERT INTO ttrss_feeds (id,owner_uid,feed_url,title,cat_id,site_url)
537 VALUES ('$orig_id','".$_SESSION["uid"]."', '$feed_url', '$title', NULL, '$site_url')");
538 }
539 array_push($subscribed, $title_orig);
540 }
541 }
542
543 return;
544 }
545
546 if ($subop == "digest-get-contents") {
547 $article_id = db_escape_string($_REQUEST['article_id']);
548
549 $result = db_query($link, "SELECT content
550 FROM ttrss_entries, ttrss_user_entries
551 WHERE id = '$article_id' AND ref_id = id AND owner_uid = ".$_SESSION['uid']);
552
553 $content = sanitize_rss($link, db_fetch_result($result, 0, "content"));
554
555 print json_encode(array("article" =>
556 array("id" => $id, "content" => $content)));
557 return;
558 }
559
560 if ($subop == "digest-update") {
561 $feed_id = db_escape_string($_REQUEST['feed_id']);
562 $offset = db_escape_string($_REQUEST['offset']);
563 $seq = db_escape_string($_REQUEST['seq']);
564
565 if (!$feed_id) $feed_id = -4;
566 if (!$offset) $offset = 0;
567
568 $reply = array();
569
570 $reply['seq'] = $seq;
571
572 $headlines = api_get_headlines($link, $feed_id, 10, $offset,
573 '', ($feed_id == -4), true, false, "unread", "updated DESC");
574
575 //function api_get_headlines($link, $feed_id, $limit, $offset,
576 // $filter, $is_cat, $show_excerpt, $show_content, $view_mode) {
577
578 $reply['headlines'] = array();
579 $reply['headlines']['title'] = getFeedTitle($link, $feed_id);
580 $reply['headlines']['content'] = $headlines;
581
582 print json_encode($reply);
583 return;
584 }
585
586 if ($subop == "digest-init") {
587 $tmp_feeds = api_get_feeds($link, -3, true, false, 0);
588
589 $feeds = array();
590
591 foreach ($tmp_feeds as $f) {
592 if ($f['id'] > 0 || $f['id'] == -4) array_push($feeds, $f);
593 }
594
595 print json_encode(array("feeds" => $feeds));
596
597 return;
598 }
599
600 if ($subop == "catchupFeed") {
601 $feed_id = db_escape_string($_REQUEST['feed_id']);
602 $is_cat = db_escape_string($_REQUEST['is_cat']);
603
604 catchup_feed($link, $feed_id, $is_cat);
605
606 return;
607 }
608
609 if ($subop == "sendEmail") {
610 $secretkey = $_REQUEST['secretkey'];
611
612 $reply = array();
613
614 if (DIGEST_ENABLE && $_SESSION['email_secretkey'] &&
615 $secretkey == $_SESSION['email_secretkey']) {
616
617 $_SESSION['email_secretkey'] = '';
618
619 $destination = $_REQUEST['destination'];
620 $subject = $_REQUEST['subject'];
621 $content = $_REQUEST['content'];
622
623 $replyto = strip_tags($_SESSION['email_replyto']);
624 $fromname = strip_tags($_SESSION['email_fromname']);
625
626 $mail = new PHPMailer();
627
628 $mail->PluginDir = "lib/phpmailer/";
629 $mail->SetLanguage("en", "lib/phpmailer/language/");
630
631 $mail->CharSet = "UTF-8";
632
633 $mail->From = $replyto;
634 $mail->FromName = $fromname;
635 $mail->AddAddress($destination);
636
637 if (DIGEST_SMTP_HOST) {
638 $mail->Host = DIGEST_SMTP_HOST;
639 $mail->Mailer = "smtp";
640 $mail->SMTPAuth = DIGEST_SMTP_LOGIN != '';
641 $mail->Username = DIGEST_SMTP_LOGIN;
642 $mail->Password = DIGEST_SMTP_PASSWORD;
643 }
644
645 $mail->IsHTML(false);
646 $mail->Subject = $subject;
647 $mail->Body = $content;
648
649 $rc = $mail->Send();
650
651 if (!$rc) {
652 $reply['error'] = $mail->ErrorInfo;
653 } else {
654 save_email_address($link, db_escape_string($destination));
655 $reply['message'] = "UPDATE_COUNTERS";
656 }
657
658 } else {
659 $reply['error'] = "Not authorized.";
660 }
661
662 print json_encode($reply);
663 return;
664 }
665
666 if ($subop == "completeEmails") {
667 $search = db_escape_string($_REQUEST["search"]);
668
669 print "<ul>";
670
671 foreach ($_SESSION['stored_emails'] as $email) {
672 if (strpos($email, $search) !== false) {
673 print "<li>$email</li>";
674 }
675 }
676
677 print "</ul>";
678
679 return;
680 }
681
682 if ($subop == "quickAddCat") {
683 $cat = db_escape_string($_REQUEST["cat"]);
684
685 add_feed_category($link, $cat);
686
687 $result = db_query($link, "SELECT id FROM ttrss_feed_categories WHERE
688 title = '$cat' AND owner_uid = " . $_SESSION["uid"]);
689
690 if (db_num_rows($result) == 1) {
691 $id = db_fetch_result($result, 0, "id");
692 } else {
693 $id = 0;
694 }
695
696 print_feed_cat_select($link, "cat_id", $id);
697
698 return;
699 }
700
701 if ($subop == "regenFeedKey") {
702 $feed_id = db_escape_string($_REQUEST['id']);
703 $is_cat = (bool) db_escape_string($_REQUEST['is_cat']);
704
705 $new_key = update_feed_access_key($link, $feed_id, $is_cat);
706
707 print json_encode(array("link" => $new_key));
708 return;
709 }
710
711 // Silent
712 if ($subop == "clearKeys") {
713 db_query($link, "DELETE FROM ttrss_access_keys WHERE
714 owner_uid = " . $_SESSION["uid"]);
715
716 return;
717 }
718
719 if ($subop == "verifyRegexp") {
720 $reg_exp = $_REQUEST["reg_exp"];
721
722 $status = @preg_match("/$reg_exp/i", "TEST") !== false;
723
724 print json_encode(array("status" => $status));
725 return;
726 }
727
728 // TODO: unify with digest-get-contents?
729 if ($subop == "cdmGetArticle") {
730 $id = db_escape_string($_REQUEST["id"]);
731
732 $result = db_query($link, "SELECT content,
733 ttrss_feeds.site_url AS site_url FROM ttrss_user_entries, ttrss_feeds,
734 ttrss_entries
735 WHERE feed_id = ttrss_feeds.id AND ref_id = '$id' AND
736 ttrss_entries.id = ref_id AND
737 ttrss_user_entries.owner_uid = ".$_SESSION["uid"]);
738
739 if (db_num_rows($result) != 0) {
740 $line = db_fetch_assoc($result);
741
742 $article_content = sanitize_rss($link, $line["content"],
743 false, false, $line['site_url']);
744
745 } else {
746 $article_content = '';
747 }
748
749 print json_encode(array("article" =>
750 array("id" => $id, "content" => $article_content)));
751
752 return;
753 }
754
755 if ($subop == "scheduleFeedUpdate") {
756 $feed_id = db_escape_string($_REQUEST["id"]);
757 $is_cat = db_escape_string($_REQUEST['is_cat']) == 'true';
758
759 $message = __("Your request could not be completed.");
760
761 if ($feed_id >= 0) {
762 if (!$is_cat) {
763 $message = __("Feed update has been scheduled.");
764
765 db_query($link, "UPDATE ttrss_feeds SET
766 last_update_started = '1970-01-01',
767 last_updated = '1970-01-01' WHERE id = '$feed_id' AND
768 owner_uid = ".$_SESSION["uid"]);
769
770 } else {
771 $message = __("Category update has been scheduled.");
772
773 if ($feed_id)
774 $cat_query = "cat_id = '$feed_id'";
775 else
776 $cat_query = "cat_id IS NULL";
777
778 db_query($link, "UPDATE ttrss_feeds SET
779 last_update_started = '1970-01-01',
780 last_updated = '1970-01-01' WHERE $cat_query AND
781 owner_uid = ".$_SESSION["uid"]);
782 }
783 } else {
784 $message = __("Can't update this kind of feed.");
785 }
786
787 print json_encode(array("message" => $message));
788 return;
789 }
790
791 if ($subop == "getTweetInfo") {
792 $id = db_escape_string($_REQUEST['id']);
793
794 $result = db_query($link, "SELECT title, link
795 FROM ttrss_entries, ttrss_user_entries
796 WHERE id = '$id' AND ref_id = id AND owner_uid = " .$_SESSION['uid']);
797
798 if (db_num_rows($result) != 0) {
799 $title = truncate_string(strip_tags(db_fetch_result($result, 0, 'title')),
800 100, '...');
801 $article_link = db_fetch_result($result, 0, 'link');
802 }
803
804 print json_encode(array("title" => $title, "link" => $article_link,
805 "id" => $id));
806
807 return;
808 }
809
810 if ($subop == "setNote") {
811 $id = db_escape_string($_REQUEST["id"]);
812 $note = strip_tags(db_escape_string($_REQUEST["note"]));
813
814 db_query($link, "UPDATE ttrss_user_entries SET note = '$note'
815 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
816
817 $formatted_note = format_article_note($id, $note);
818
819 print json_encode(array("note" => $formatted_note));
820 return;
821 }
822
823 print json_encode(array("error" => array("code" => 7,
824 "message" => "Unknown method: $subop")));
825 }
826 ?>