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