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