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