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