]>
git.wh0rd.org - tt-rss.git/blob - modules/backend-rpc.php
2 function handle_rpc_request($link) {
4 $subop = $_REQUEST["subop"];
6 if ($subop == "setprofile") {
7 $id = db_escape_string($_REQUEST["id"]);
9 $_SESSION["profile"] = $id;
10 $_SESSION["prefs_cache"] = array();
14 if ($subop == "remprofiles") {
15 $ids = split(",", db_escape_string(trim($_REQUEST["ids"])));
17 foreach ($ids as $id) {
18 if ($_SESSION["profile"] != $id) {
19 db_query($link, "DELETE FROM ttrss_settings_profiles WHERE id = '$id' AND
20 owner_uid = " . $_SESSION["uid"]);
26 if ($subop == "addprofile") {
27 $title = db_escape_string(trim($_REQUEST["title"]));
29 db_query($link, "BEGIN");
31 $result = db_query($link, "SELECT id FROM ttrss_settings_profiles
32 WHERE title = '$title' AND owner_uid = " . $_SESSION["uid"]);
34 if (db_num_rows($result) == 0) {
36 db_query($link, "INSERT INTO ttrss_settings_profiles (title, owner_uid)
37 VALUES ('$title', ".$_SESSION["uid"] .")");
39 $result = db_query($link, "SELECT id FROM ttrss_settings_profiles WHERE
42 if (db_num_rows($result) != 0) {
43 $profile_id = db_fetch_result($result, 0, "id");
46 initialize_user_prefs($link, $_SESSION["uid"], $profile_id);
51 db_query($link, "COMMIT");
56 if ($subop == "saveprofile") {
57 $id = db_escape_string($_REQUEST["id"]);
58 $title = db_escape_string(trim($_REQUEST["value"]));
61 print __("Default profile");
66 db_query($link, "BEGIN");
68 $result = db_query($link, "SELECT id FROM ttrss_settings_profiles
69 WHERE title = '$title' AND owner_uid =" . $_SESSION["uid"]);
71 if (db_num_rows($result) == 0) {
72 db_query($link, "UPDATE ttrss_settings_profiles
73 SET title = '$title' WHERE id = '$id' AND
74 owner_uid = " . $_SESSION["uid"]);
77 $result = db_query($link, "SELECT title FROM ttrss_settings_profiles
78 WHERE id = '$id' AND owner_uid =" . $_SESSION["uid"]);
79 print db_fetch_result($result, 0, "title");
82 db_query($link, "COMMIT");
87 if ($subop == "remarchive") {
88 $ids = split(",", db_escape_string($_REQUEST["ids"]));
92 foreach ($ids as $id) {
93 $result = db_query($link, "DELETE FROM ttrss_archived_feeds WHERE
94 (SELECT COUNT(*) FROM ttrss_user_entries
95 WHERE orig_feed_id = '$id') = 0 AND
96 id = '$id' AND owner_uid = ".$_SESSION["uid"]);
98 $rc = db_affected_rows($link, $result);
100 print "<feed id='$id' rc='$rc'/>";
104 print "</rpc-reply>";
109 if ($subop == "addfeed") {
111 $feed = db_escape_string($_REQUEST['feed']);
112 $cat = db_escape_string($_REQUEST['cat']);
113 $login = db_escape_string($_REQUEST['login']);
114 $pass = db_escape_string($_REQUEST['pass']);
116 $rc = subscribe_to_feed($link, $feed, $cat, $login, $pass);
119 print "<result code='$rc'/>";
120 print "</rpc-reply>";
126 if ($subop == "togglepref") {
129 $key = db_escape_string($_REQUEST["key"]);
131 set_pref($link, $key, !get_pref($link, $key));
133 $value = get_pref($link, $key);
135 print "<param-set key=\"$key\" value=\"$value\"/>";
137 print "</rpc-reply>";
142 if ($subop == "setpref") {
145 $key = db_escape_string($_REQUEST["key"]);
146 $value = db_escape_string($_REQUEST["value"]);
148 set_pref($link, $key, $value);
150 print "<param-set key=\"$key\" value=\"$value\"/>";
152 print "</rpc-reply>";
157 if ($subop == "getAllCounters") {
159 print "<counters><![CDATA[";
161 print json_encode(getAllCounters($link, $_REQUEST['omode']));
163 print "]]></counters>";
164 print_runtime_info($link);
165 print "</rpc-reply>";
170 if ($subop == "mark") {
171 $mark = $_REQUEST["mark"];
172 $id = db_escape_string($_REQUEST["id"]);
180 // FIXME this needs collision testing
182 $result = db_query($link, "UPDATE ttrss_user_entries SET marked = $mark
183 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
185 print "<rpc-reply><counters><![CDATA[";
186 print json_encode(getAllCounters($link));
187 print "]]></counters></rpc-reply>";
192 if ($subop == "delete") {
193 $ids = db_escape_string($_REQUEST["ids"]);
195 $result = db_query($link, "DELETE FROM ttrss_user_entries
196 WHERE ref_id IN ($ids) AND owner_uid = " . $_SESSION["uid"]);
198 print "<rpc-reply><counters><![CDATA[";
199 print json_encode(getAllCounters($link));
200 print "]]></counters></rpc-reply>";
205 if ($subop == "unarchive") {
206 $ids = db_escape_string($_REQUEST["ids"]);
208 $result = db_query($link, "UPDATE ttrss_user_entries
209 SET feed_id = orig_feed_id, orig_feed_id = NULL
210 WHERE ref_id IN ($ids) AND owner_uid = " . $_SESSION["uid"]);
212 print "<rpc-reply><counters><![CDATA[";
213 print json_encode(getAllCounters($link));
214 print "]]></counters></rpc-reply>";
219 if ($subop == "archive") {
220 $ids = split(",", db_escape_string($_REQUEST["ids"]));
222 foreach ($ids as $id) {
223 archive_article($link, $id, $_SESSION["uid"]);
226 print "<rpc-reply><counters><![CDATA[";
227 print json_encode(getAllCounters($link));
228 print "]]></counters></rpc-reply>";
234 if ($subop == "publ") {
235 $pub = $_REQUEST["pub"];
236 $id = db_escape_string($_REQUEST["id"]);
237 $note = trim(strip_tags(db_escape_string($_REQUEST["note"])));
245 if ($note != 'undefined') {
246 $note_qpart = "note = '$note',";
249 // FIXME this needs collision testing
251 $result = db_query($link, "UPDATE ttrss_user_entries SET
254 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
259 print "<counters><![CDATA[";
260 print json_encode(getAllCounters($link));
261 print "]]></counters>";
263 if ($note != 'undefined') {
264 $note_size = strlen($note);
265 print "<note id=\"$id\" size=\"$note_size\">";
266 print "<![CDATA[" . format_article_note($id, $note) . "]]>";
270 print "</rpc-reply>";
275 if ($subop == "updateFeed") {
276 $feed_id = db_escape_string($_REQUEST["feed"]);
278 update_rss_feed($link, $feed_id);
281 print "<counters><![CDATA[";
282 print json_encode(getFeedCounters($link, $feed_id));
283 print "]]></counters>";
284 print "</rpc-reply>";
289 if ($subop == "updateAllFeeds") {
291 $global_unread_caller = sprintf("%d", $_REQUEST["uctr"]);
292 $global_unread = getGlobalUnread($link);
296 if ($global_unread_caller != $global_unread) {
297 print "<counters><![CDATA[";
298 $omode = $_REQUEST["omode"];
299 print json_encode(getAllCounters($link, $omode));
300 print "]]></counters>";
303 print_runtime_info($link);
305 print "</rpc-reply>";
310 /* GET["cmode"] = 0 - mark as read, 1 - as unread, 2 - toggle */
311 if ($subop == "catchupSelected") {
313 $ids = split(",", db_escape_string($_REQUEST["ids"]));
314 $cmode = sprintf("%d", $_REQUEST["cmode"]);
316 catchupArticlesById($link, $ids, $cmode);
319 print "<counters><![CDATA[";
320 print json_encode(getAllCounters($link, $_REQUEST['omode']));
321 print "]]></counters>";
323 print_runtime_info($link);
324 print "</rpc-reply>";
329 if ($subop == "markSelected") {
331 $ids = split(",", db_escape_string($_REQUEST["ids"]));
332 $cmode = sprintf("%d", $_REQUEST["cmode"]);
334 markArticlesById($link, $ids, $cmode);
337 print "<counters><![CDATA[";
338 print json_encode(getAllCounters($link, $_REQUEST['omode']));
339 print "]]></counters>";
340 print_runtime_info($link);
341 print "</rpc-reply>";
346 if ($subop == "publishSelected") {
348 $ids = split(",", db_escape_string($_REQUEST["ids"]));
349 $cmode = sprintf("%d", $_REQUEST["cmode"]);
351 publishArticlesById($link, $ids, $cmode);
354 print "<counters><![CDATA[";
355 print json_encode(getAllCounters($link, $_REQUEST['omode']));
356 print "]]></counters>";
357 print_runtime_info($link);
358 print "</rpc-reply>";
363 if ($subop == "sanityCheck") {
365 if (sanity_check($link)) {
366 print "<error error-code=\"0\"/>";
368 print "<init-params><![CDATA[";
369 print json_encode(make_init_params($link));
370 print "]]></init-params>";
372 print_runtime_info($link);
374 # assign client-passed params to session
375 $_SESSION["client.userAgent"] = $_REQUEST["ua"];
378 print "</rpc-reply>";
383 if ($subop == "globalPurge") {
386 global_purge_old_posts($link, true);
387 print "</rpc-reply>";
392 if ($subop == "getArticleLink") {
394 $id = db_escape_string($_REQUEST["id"]);
396 $result = db_query($link, "SELECT link FROM ttrss_entries, ttrss_user_entries
397 WHERE id = '$id' AND id = ref_id AND owner_uid = '".$_SESSION['uid']."'");
399 if (db_num_rows($result) == 1) {
400 $link = htmlspecialchars(strip_tags(db_fetch_result($result, 0, "link")));
401 print "<rpc-reply><link>$link</link><id>$id</id></rpc-reply>";
403 print "<rpc-reply><error>Article not found</error></rpc-reply>";
409 if ($subop == "setArticleTags") {
413 $id = db_escape_string($_REQUEST["id"]);
415 $tags_str = db_escape_string($_REQUEST["tags_str"]);
417 $tags = array_unique(trim_array(split(",", $tags_str)));
419 db_query($link, "BEGIN");
421 $result = db_query($link, "SELECT int_id FROM ttrss_user_entries WHERE
422 ref_id = '$id' AND owner_uid = '".$_SESSION["uid"]."' LIMIT 1");
424 if (db_num_rows($result) == 1) {
426 $int_id = db_fetch_result($result, 0, "int_id");
428 db_query($link, "DELETE FROM ttrss_tags WHERE
429 post_int_id = $int_id AND owner_uid = '".$_SESSION["uid"]."'");
431 foreach ($tags as $tag) {
432 $tag = sanitize_tag($tag);
434 if (!tag_is_valid($tag)) {
438 if (preg_match("/^[0-9]*$/", $tag)) {
442 // print "<!-- $id : $int_id : $tag -->";
445 db_query($link, "INSERT INTO ttrss_tags
446 (post_int_id, owner_uid, tag_name) VALUES ('$int_id', '".$_SESSION["uid"]."', '$tag')");
451 db_query($link, "COMMIT");
454 $obj_id = md5("TAGS:".$_SESSION["uid"].":$id");
455 $memcache->delete($obj_id);
458 $tags_str = format_tags_string(get_article_tags($link, $id), $id);
461 <tags-str id=\"$id\"><![CDATA[$tags_str]]></tags-str>
467 if ($subop == "regenOPMLKey") {
470 set_pref($link, "_PREFS_PUBLISH_KEY",
471 sha1(uniqid(rand(), true)), $_SESSION["uid"]);
472 $new_link = opml_publish_url($link);
473 print "<link><![CDATA[$new_link]]></link>";
474 print "</rpc-reply>";
478 if ($subop == "logout") {
484 if ($subop == "completeTags") {
486 $search = db_escape_string($_REQUEST["search"]);
488 $result = db_query($link, "SELECT DISTINCT tag_name FROM ttrss_tags
489 WHERE owner_uid = '".$_SESSION["uid"]."' AND
490 tag_name LIKE '$search%' ORDER BY tag_name
494 while ($line = db_fetch_assoc($result)) {
495 print "<li>" . $line["tag_name"] . "</li>";
502 if ($subop == "purge") {
503 $ids = split(",", db_escape_string($_REQUEST["ids"]));
504 $days = sprintf("%d", $_REQUEST["days"]);
508 print "<message><![CDATA[";
510 foreach ($ids as $id) {
512 $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE
513 id = '$id' AND owner_uid = ".$_SESSION["uid"]);
515 if (db_num_rows($result) == 1) {
516 purge_feed($link, $id, $days, true);
520 print "]]></message>";
522 print "</rpc-reply>";
527 /* if ($subop == "setScore") {
528 $id = db_escape_string($_REQUEST["id"]);
529 $score = sprintf("%d", $_REQUEST["score"]);
531 $result = db_query($link, "UPDATE ttrss_user_entries SET score = '$score'
532 WHERE ref_id = '$id' AND owner_uid = ".$_SESSION["uid"]);
534 print "<rpc-reply><message>Acknowledged.</message></rpc-reply>";
540 if ($subop == "getArticles") {
541 $ids = split(",", db_escape_string($_REQUEST["ids"]));
545 foreach ($ids as $id) {
547 outputArticleXML($link, $id, 0, false);
550 print "</rpc-reply>";
555 if ($subop == "checkDate") {
557 $date = db_escape_string($_REQUEST["date"]);
558 $date_parsed = strtotime($date);
563 print "<result>1</result>";
565 print "<result>0</result>";
568 print "</rpc-reply>";
573 if ($subop == "removeFromLabel") {
575 $ids = split(",", db_escape_string($_REQUEST["ids"]));
576 $label_id = db_escape_string($_REQUEST["lid"]);
578 $label = db_escape_string(label_find_caption($link, $label_id,
582 print "<info-for-headlines>";
586 foreach ($ids as $id) {
587 label_remove_article($link, $id, $label, $_SESSION["uid"]);
589 print "<entry id=\"$id\"><![CDATA[";
591 $labels = get_article_labels($link, $id, $_SESSION["uid"]);
592 print format_article_labels($labels, $id);
599 print "</info-for-headlines>";
601 print "<counters><![CDATA[";
602 print json_encode(getAllCounters($link, $_REQUEST['omode']));
603 print "]]></counters>";
604 print "</rpc-reply>";
609 if ($subop == "assignToLabel") {
611 $ids = split(",", db_escape_string($_REQUEST["ids"]));
612 $label_id = db_escape_string($_REQUEST["lid"]);
614 $label = db_escape_string(label_find_caption($link, $label_id,
619 print "<info-for-headlines>";
623 foreach ($ids as $id) {
624 label_add_article($link, $id, $label, $_SESSION["uid"]);
626 print "<entry id=\"$id\"><![CDATA[";
628 $labels = get_article_labels($link, $id, $_SESSION["uid"]);
629 print format_article_labels($labels, $id);
636 print "</info-for-headlines>";
638 print "<counters><![CDATA[";
639 print json_encode(getAllCounters($link, $_REQUEST['omode']));
640 print "]]></counters>";
641 print "</rpc-reply>";
646 if ($subop == "updateFeedBrowser") {
648 $search = db_escape_string($_REQUEST["search"]);
649 $limit = db_escape_string($_REQUEST["limit"]);
650 $mode = db_escape_string($_REQUEST["mode"]);
655 $ctr = print_feed_browser($link, $search, $limit, $mode);
658 print "<num-results value=\"$ctr\"/>";
659 print "<mode value=\"$mode\"/>";
660 print "</rpc-reply>";
666 if ($subop == "massSubscribe") {
668 $ids = split(",", db_escape_string($_REQUEST["ids"]));
669 $mode = $_REQUEST["mode"];
671 $subscribed = array();
673 foreach ($ids as $id) {
676 $result = db_query($link, "SELECT feed_url,title FROM ttrss_feeds
678 } else if ($mode == 2) {
679 $result = db_query($link, "SELECT * FROM ttrss_archived_feeds
680 WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]);
681 $orig_id = db_escape_string(db_fetch_result($result, 0, "id"));
682 $site_url = db_escape_string(db_fetch_result($result, 0, "site_url"));
685 $feed_url = db_escape_string(db_fetch_result($result, 0, "feed_url"));
686 $title = db_escape_string(db_fetch_result($result, 0, "title"));
688 $title_orig = db_fetch_result($result, 0, "title");
690 $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE
691 feed_url = '$feed_url' AND owner_uid = " . $_SESSION["uid"]);
693 if (db_num_rows($result) == 0) {
695 $result = db_query($link,
696 "INSERT INTO ttrss_feeds (owner_uid,feed_url,title,cat_id)
697 VALUES ('".$_SESSION["uid"]."', '$feed_url', '$title', NULL)");
698 } else if ($mode == 2) {
699 $result = db_query($link,
700 "INSERT INTO ttrss_feeds (id,owner_uid,feed_url,title,cat_id,site_url)
701 VALUES ('$orig_id','".$_SESSION["uid"]."', '$feed_url', '$title', NULL, '$site_url')");
703 array_push($subscribed, $title_orig);
707 $num_feeds = count($subscribed);
710 print "<num-feeds value='$num_feeds'/>";
711 print "</rpc-reply>";
716 if ($subop == "download") {
717 $stage = (int) $_REQUEST["stage"];
718 $cidt = (int)db_escape_string($_REQUEST["cidt"]);
719 $cidb = (int)db_escape_string($_REQUEST["cidb"]);
720 $sync = db_escape_string($_REQUEST["sync"]);
721 //$amount = (int) $_REQUEST["amount"];
722 //$unread_only = db_escape_string($_REQUEST["unread_only"]);
723 //if (!$amount) $amount = 50;
725 /* Amount is not used by the frontend offline.js anymore, it goes by
726 * date_qpart below + cidb/cidt IDs */
733 $sync = split(";", $sync);
737 if (count($sync) > 0) {
738 if (strtotime($sync[0])) {
739 $last_online = db_escape_string($sync[0]);
741 print "<sync-point><![CDATA[$last_online]]></sync-point>";
743 for ($i = 1; $i < count($sync); $i++
) {
744 $e = split(",", $sync[$i]);
746 if (count($e) == 3) {
749 $unread = bool_to_sql_bool((bool) $e[1]);
750 $marked = (bool)$e[2];
753 $marked = bool_to_sql_bool($marked);
754 $marked_qpart = "marked = $marked,";
757 $query = "UPDATE ttrss_user_entries SET
760 last_read = '$last_online'
761 WHERE ref_id = '$id' AND
762 (last_read IS NULL OR last_read < '$last_online') AND
763 owner_uid = ".$_SESSION["uid"];
765 $result = db_query($link, $query);
767 print "<sync-ok id=\"$id\"/>";
772 /* Maybe we need to further update local DB for this client */
774 $query = "SELECT ref_id,unread,marked FROM ttrss_user_entries
775 WHERE last_read >= '$last_online' AND
776 owner_uid = ".$_SESSION["uid"] . " LIMIT 1000";
778 $result = db_query($link, $query);
780 while ($line = db_fetch_assoc($result)) {
781 $unread = (int) sql_bool_to_bool($line["unread"]);
782 $marked = (int) sql_bool_to_bool($line["marked"]);
784 print "<sync-ok unread=\"$unread\" marked=\"$marked\"
785 id=\"".$line["ref_id"]."\"/>";
796 $result = db_query($link, "SELECT id, title, cat_id FROM
797 ttrss_feeds WHERE owner_uid = ".$_SESSION["uid"]);
799 while ($line = db_fetch_assoc($result)) {
801 $has_icon = (int) feed_has_icon($line["id"]);
803 print "<feed has_icon=\"$has_icon\"
804 cat_id=\"".(int)$line["cat_id"]."\" id=\"".$line["id"]."\"><![CDATA[";
805 print $line["title"];
811 print "<feed-categories>";
813 $result = db_query($link, "SELECT id, title, collapsed FROM
814 ttrss_feed_categories WHERE owner_uid = ".$_SESSION["uid"]);
816 print "<category id=\"0\" collapsed=\"".
817 (int)get_pref($link, "_COLLAPSED_UNCAT")."\"><![CDATA[";
818 print __("Uncategorized");
819 print "]]></category>";
821 print "<category id=\"-1\" collapsed=\"".
822 (int)get_pref($link, "_COLLAPSED_SPECIAL")."\"><![CDATA[";
824 print "]]></category>";
826 print "<category id=\"-2\" collapsed=\"".
827 (int)get_pref($link, "_COLLAPSED_LABELS")."\"><![CDATA[";
829 print "]]></category>";
831 while ($line = db_fetch_assoc($result)) {
833 id=\"".$line["id"]."\"
834 collapsed=\"".(int)sql_bool_to_bool($line["collapsed"])."\"><![CDATA[";
835 print $line["title"];
836 print "]]></category>";
839 print "</feed-categories>";
843 $result = db_query($link, "SELECT * FROM
844 ttrss_labels2 WHERE owner_uid = ".$_SESSION["uid"]);
846 while ($line = db_fetch_assoc($result)) {
848 id=\"".$line["id"]."\"
849 fg_color=\"".$line["fg_color"]."\"
850 bg_color=\"".$line["bg_color"]."\"
852 print $line["caption"];
865 $skip = $limit*($stage-1);
867 print "<limit value=\"$limit\"/>";
869 if ($amount > 0) $amount -= $skip;
873 $limit = min($limit, $amount);
876 $unread_qpart = "(unread = true OR marked = true) AND ";
879 if ($cidt && $cidb) {
880 $cid_qpart = "(ttrss_entries.id > $cidt OR ttrss_entries.id < $cidb) AND ";
883 if (DB_TYPE
== "pgsql") {
884 $date_qpart = "updated >= NOW() - INTERVAL '1 week' AND";
886 $date_qpart = "updated >= DATE_SUB(NOW(), INTERVAL 1 WEEK) AND";
889 $result = db_query($link,
890 "SELECT DISTINCT ttrss_entries.id,ttrss_entries.title,
892 feed_id,content,updated,unread,marked FROM
893 ttrss_user_entries,ttrss_entries,ttrss_feeds
894 WHERE $unread_qpart $cid_qpart $date_qpart
895 ttrss_feeds.id = feed_id AND
896 ref_id = ttrss_entries.id AND
897 ttrss_user_entries.owner_uid = ".$_SESSION["uid"]."
898 ORDER BY updated DESC LIMIT $limit OFFSET $skip");
900 if (function_exists('json_encode')) {
902 while ($line = db_fetch_assoc($result)) {
903 print "<article><![CDATA[";
905 $line["marked"] = (int)sql_bool_to_bool($line["marked"]);
906 $line["unread"] = (int)sql_bool_to_bool($line["unread"]);
908 $line["labels"] = get_article_labels($link, $line["id"]);
911 // $line["tags"] = format_tags_string(
912 // get_article_tags($link, $line["id"]), $line["id"]);
914 print json_encode($line);
915 print "]]></article>";
925 print "</rpc-reply>";
930 if ($subop == "digest-get-contents") {
931 $article_id = db_escape_string($_REQUEST['article_id']);
933 $result = db_query($link, "SELECT content
934 FROM ttrss_entries, ttrss_user_entries
935 WHERE id = '$article_id' AND ref_id = id AND owner_uid = ".$_SESSION['uid']);
939 print "<article id=\"$article_id\"><![CDATA[";
941 $content = sanitize_rss($link, db_fetch_result($result, 0, "content"));
945 print "]]></article>";
947 print "</rpc-reply>";
952 if ($subop == "digest-update") {
953 $feed_id = db_escape_string($_REQUEST['feed_id']);
954 $offset = db_escape_string($_REQUEST['offset']);
955 $seq = db_escape_string($_REQUEST['seq']);
957 if (!$feed_id) $feed_id = -4;
958 if (!$offset) $offset = 0;
961 print "<seq>$seq</seq>";
963 $headlines = api_get_headlines($link, $feed_id, 10, $offset,
964 '', ($feed_id == -4), true, false, "unread", "updated DESC");
966 //function api_get_headlines($link, $feed_id, $limit, $offset,
967 // $filter, $is_cat, $show_excerpt, $show_content, $view_mode) {
969 print "<headlines-title><![CDATA[" . getFeedTitle($link, $feed_id) .
970 "]]></headlines-title>";
972 print "<headlines><![CDATA[" . json_encode($headlines) . "]]></headlines>";
974 print "</rpc-reply>";
978 if ($subop == "digest-init") {
981 $tmp_feeds = api_get_feeds($link, false, true, false, 0);
984 foreach ($tmp_feeds as $f) {
985 if ($f['id'] > 0 ||
$f['id'] == -4) array_push($feeds, $f);
988 print "<feeds><![CDATA[" . json_encode($feeds) . "]]></feeds>";
990 print "</rpc-reply>";
994 if ($subop == "catchupFeed") {
996 $feed_id = db_escape_string($_REQUEST['feed_id']);
997 $is_cat = db_escape_string($_REQUEST['is_cat']);
1001 catchup_feed($link, $feed_id, $is_cat);
1003 print "</rpc-reply>";
1008 if ($subop == "sendEmail") {
1009 $secretkey = $_REQUEST['secretkey'];
1011 print "<rpc-reply>";
1013 if (DIGEST_ENABLE
&& $_SESSION['email_secretkey'] &&
1014 $secretkey == $_SESSION['email_secretkey']) {
1016 $_SESSION['email_secretkey'] = '';
1018 $destination = $_REQUEST['destination'];
1019 $subject = $_REQUEST['subject'];
1020 $content = $_REQUEST['content'];
1022 $replyto = strip_tags($_SESSION['email_replyto']);
1023 $fromname = strip_tags($_SESSION['email_fromname']);
1025 $mail = new PHPMailer();
1027 $mail->PluginDir
= "lib/phpmailer/";
1028 $mail->SetLanguage("en", "lib/phpmailer/language/");
1030 $mail->CharSet
= "UTF-8";
1032 $mail->From
= $replyto;
1033 $mail->FromName
= $fromname;
1034 $mail->AddAddress($destination);
1036 if (DIGEST_SMTP_HOST
) {
1037 $mail->Host
= DIGEST_SMTP_HOST
;
1038 $mail->Mailer
= "smtp";
1039 $mail->SMTPAuth
= DIGEST_SMTP_LOGIN
!= '';
1040 $mail->Username
= DIGEST_SMTP_LOGIN
;
1041 $mail->Password
= DIGEST_SMTP_PASSWORD
;
1044 $mail->IsHTML(false);
1045 $mail->Subject
= $subject;
1046 $mail->Body
= $content;
1048 $rc = $mail->Send();
1051 print "<error><![CDATA[" . $mail->ErrorInfo
. "]]></error>";
1053 save_email_address($link, db_escape_string($destination));
1054 print "<message>OK</message>";
1058 print "<error>Not authorized.</error>";
1061 print "</rpc-reply>";
1066 if ($subop == "completeEmails") {
1068 $search = db_escape_string($_REQUEST["search"]);
1072 foreach ($_SESSION['stored_emails'] as $email) {
1073 if (strpos($email, $search) !== false) {
1074 print "<li>$email</li>";
1083 if ($subop == "quickAddCat") {
1084 print "<rpc-reply>";
1086 $cat = db_escape_string($_REQUEST["cat"]);
1088 add_feed_category($link, $cat);
1090 $result = db_query($link, "SELECT id FROM ttrss_feed_categories WHERE
1091 title = '$cat' AND owner_uid = " . $_SESSION["uid"]);
1093 if (db_num_rows($result) == 1) {
1094 $id = db_fetch_result($result, 0, "id");
1099 print "<payload><![CDATA[";
1100 print_feed_cat_select($link, "cat_id", $id);
1101 print "]]></payload>";
1103 print "</rpc-reply>";
1108 if ($subop == "regenFeedKey") {
1109 $feed_id = db_escape_string($_REQUEST['id']);
1110 $is_cat = (bool) db_escape_string($_REQUEST['is_cat']);
1112 print "<rpc-reply>";
1114 $new_key = update_feed_access_key($link, $feed_id, $is_cat);
1116 print "<link><![CDATA[$new_key]]></link>";
1118 print "</rpc-reply>";
1123 if ($subop == "clearKeys") {
1125 db_query($link, "DELETE FROM ttrss_access_keys WHERE
1126 owner_uid = " . $_SESSION["uid"]);
1128 print "<rpc-reply><message>OK</message></rpc-reply>";
1133 print "<rpc-reply><error>Unknown method: $subop</error></rpc-reply>";