]>
git.wh0rd.org - tt-rss.git/blob - modules/backend-rpc.php
fee93a58643ab746080fd080a2ec63440a5b361b
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 == "regenPubKey") {
471 set_pref($link, "_PREFS_PUBLISH_KEY", generate_publish_key(), $_SESSION["uid"]);
473 $new_link = article_publish_url($link);
475 print "<link><![CDATA[$new_link]]></link>";
477 print "</rpc-reply>";
482 if ($subop == "regenOPMLKey") {
485 set_pref($link, " _PREFS_OPML_PUBLISH_KEY", generate_publish_key(), $_SESSION["uid"]);
486 $new_link = opml_publish_url($link);
487 print "<link><![CDATA[$new_link]]></link>";
488 print "</rpc-reply>";
492 if ($subop == "logout") {
498 if ($subop == "completeTags") {
500 $search = db_escape_string($_REQUEST["search"]);
502 $result = db_query($link, "SELECT DISTINCT tag_name FROM ttrss_tags
503 WHERE owner_uid = '".$_SESSION["uid"]."' AND
504 tag_name LIKE '$search%' ORDER BY tag_name
508 while ($line = db_fetch_assoc($result)) {
509 print "<li>" . $line["tag_name"] . "</li>";
516 if ($subop == "purge") {
517 $ids = split(",", db_escape_string($_REQUEST["ids"]));
518 $days = sprintf("%d", $_REQUEST["days"]);
522 print "<message><![CDATA[";
524 foreach ($ids as $id) {
526 $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE
527 id = '$id' AND owner_uid = ".$_SESSION["uid"]);
529 if (db_num_rows($result) == 1) {
530 purge_feed($link, $id, $days, true);
534 print "]]></message>";
536 print "</rpc-reply>";
541 /* if ($subop == "setScore") {
542 $id = db_escape_string($_REQUEST["id"]);
543 $score = sprintf("%d", $_REQUEST["score"]);
545 $result = db_query($link, "UPDATE ttrss_user_entries SET score = '$score'
546 WHERE ref_id = '$id' AND owner_uid = ".$_SESSION["uid"]);
548 print "<rpc-reply><message>Acknowledged.</message></rpc-reply>";
554 if ($subop == "getArticles") {
555 $ids = split(",", db_escape_string($_REQUEST["ids"]));
559 foreach ($ids as $id) {
561 outputArticleXML($link, $id, 0, false);
564 print "</rpc-reply>";
569 if ($subop == "checkDate") {
571 $date = db_escape_string($_REQUEST["date"]);
572 $date_parsed = strtotime($date);
577 print "<result>1</result>";
579 print "<result>0</result>";
582 print "</rpc-reply>";
587 if ($subop == "removeFromLabel") {
589 $ids = split(",", db_escape_string($_REQUEST["ids"]));
590 $label_id = db_escape_string($_REQUEST["lid"]);
592 $label = db_escape_string(label_find_caption($link, $label_id,
596 print "<info-for-headlines>";
600 foreach ($ids as $id) {
601 label_remove_article($link, $id, $label, $_SESSION["uid"]);
603 print "<entry id=\"$id\"><![CDATA[";
605 $labels = get_article_labels($link, $id, $_SESSION["uid"]);
606 print format_article_labels($labels, $id);
613 print "</info-for-headlines>";
615 print "<counters><![CDATA[";
616 print json_encode(getAllCounters($link, $_REQUEST['omode']));
617 print "]]></counters>";
618 print "</rpc-reply>";
623 if ($subop == "assignToLabel") {
625 $ids = split(",", db_escape_string($_REQUEST["ids"]));
626 $label_id = db_escape_string($_REQUEST["lid"]);
628 $label = db_escape_string(label_find_caption($link, $label_id,
633 print "<info-for-headlines>";
637 foreach ($ids as $id) {
638 label_add_article($link, $id, $label, $_SESSION["uid"]);
640 print "<entry id=\"$id\"><![CDATA[";
642 $labels = get_article_labels($link, $id, $_SESSION["uid"]);
643 print format_article_labels($labels, $id);
650 print "</info-for-headlines>";
652 print "<counters><![CDATA[";
653 print json_encode(getAllCounters($link, $_REQUEST['omode']));
654 print "]]></counters>";
655 print "</rpc-reply>";
660 if ($subop == "updateFeedBrowser") {
662 $search = db_escape_string($_REQUEST["search"]);
663 $limit = db_escape_string($_REQUEST["limit"]);
664 $mode = db_escape_string($_REQUEST["mode"]);
669 $ctr = print_feed_browser($link, $search, $limit, $mode);
672 print "<num-results value=\"$ctr\"/>";
673 print "<mode value=\"$mode\"/>";
674 print "</rpc-reply>";
680 if ($subop == "massSubscribe") {
682 $ids = split(",", db_escape_string($_REQUEST["ids"]));
683 $mode = $_REQUEST["mode"];
685 $subscribed = array();
687 foreach ($ids as $id) {
690 $result = db_query($link, "SELECT feed_url,title FROM ttrss_feeds
692 } else if ($mode == 2) {
693 $result = db_query($link, "SELECT * FROM ttrss_archived_feeds
694 WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]);
695 $orig_id = db_escape_string(db_fetch_result($result, 0, "id"));
696 $site_url = db_escape_string(db_fetch_result($result, 0, "site_url"));
699 $feed_url = db_escape_string(db_fetch_result($result, 0, "feed_url"));
700 $title = db_escape_string(db_fetch_result($result, 0, "title"));
702 $title_orig = db_fetch_result($result, 0, "title");
704 $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE
705 feed_url = '$feed_url' AND owner_uid = " . $_SESSION["uid"]);
707 if (db_num_rows($result) == 0) {
709 $result = db_query($link,
710 "INSERT INTO ttrss_feeds (owner_uid,feed_url,title,cat_id)
711 VALUES ('".$_SESSION["uid"]."', '$feed_url', '$title', NULL)");
712 } else if ($mode == 2) {
713 $result = db_query($link,
714 "INSERT INTO ttrss_feeds (id,owner_uid,feed_url,title,cat_id,site_url)
715 VALUES ('$orig_id','".$_SESSION["uid"]."', '$feed_url', '$title', NULL, '$site_url')");
717 array_push($subscribed, $title_orig);
721 $num_feeds = count($subscribed);
724 print "<num-feeds value='$num_feeds'/>";
725 print "</rpc-reply>";
730 if ($subop == "download") {
731 $stage = (int) $_REQUEST["stage"];
732 $cidt = (int)db_escape_string($_REQUEST["cidt"]);
733 $cidb = (int)db_escape_string($_REQUEST["cidb"]);
734 $sync = db_escape_string($_REQUEST["sync"]);
735 //$amount = (int) $_REQUEST["amount"];
736 //$unread_only = db_escape_string($_REQUEST["unread_only"]);
737 //if (!$amount) $amount = 50;
739 /* Amount is not used by the frontend offline.js anymore, it goes by
740 * date_qpart below + cidb/cidt IDs */
747 $sync = split(";", $sync);
751 if (count($sync) > 0) {
752 if (strtotime($sync[0])) {
753 $last_online = db_escape_string($sync[0]);
755 print "<sync-point><![CDATA[$last_online]]></sync-point>";
757 for ($i = 1; $i < count($sync); $i++
) {
758 $e = split(",", $sync[$i]);
760 if (count($e) == 3) {
763 $unread = bool_to_sql_bool((bool) $e[1]);
764 $marked = (bool)$e[2];
767 $marked = bool_to_sql_bool($marked);
768 $marked_qpart = "marked = $marked,";
771 $query = "UPDATE ttrss_user_entries SET
774 last_read = '$last_online'
775 WHERE ref_id = '$id' AND
776 (last_read IS NULL OR last_read < '$last_online') AND
777 owner_uid = ".$_SESSION["uid"];
779 $result = db_query($link, $query);
781 print "<sync-ok id=\"$id\"/>";
786 /* Maybe we need to further update local DB for this client */
788 $query = "SELECT ref_id,unread,marked FROM ttrss_user_entries
789 WHERE last_read >= '$last_online' AND
790 owner_uid = ".$_SESSION["uid"] . " LIMIT 1000";
792 $result = db_query($link, $query);
794 while ($line = db_fetch_assoc($result)) {
795 $unread = (int) sql_bool_to_bool($line["unread"]);
796 $marked = (int) sql_bool_to_bool($line["marked"]);
798 print "<sync-ok unread=\"$unread\" marked=\"$marked\"
799 id=\"".$line["ref_id"]."\"/>";
810 $result = db_query($link, "SELECT id, title, cat_id FROM
811 ttrss_feeds WHERE owner_uid = ".$_SESSION["uid"]);
813 while ($line = db_fetch_assoc($result)) {
815 $has_icon = (int) feed_has_icon($line["id"]);
817 print "<feed has_icon=\"$has_icon\"
818 cat_id=\"".(int)$line["cat_id"]."\" id=\"".$line["id"]."\"><![CDATA[";
819 print $line["title"];
825 print "<feed-categories>";
827 $result = db_query($link, "SELECT id, title, collapsed FROM
828 ttrss_feed_categories WHERE owner_uid = ".$_SESSION["uid"]);
830 print "<category id=\"0\" collapsed=\"".
831 (int)get_pref($link, "_COLLAPSED_UNCAT")."\"><![CDATA[";
832 print __("Uncategorized");
833 print "]]></category>";
835 print "<category id=\"-1\" collapsed=\"".
836 (int)get_pref($link, "_COLLAPSED_SPECIAL")."\"><![CDATA[";
838 print "]]></category>";
840 print "<category id=\"-2\" collapsed=\"".
841 (int)get_pref($link, "_COLLAPSED_LABELS")."\"><![CDATA[";
843 print "]]></category>";
845 while ($line = db_fetch_assoc($result)) {
847 id=\"".$line["id"]."\"
848 collapsed=\"".(int)sql_bool_to_bool($line["collapsed"])."\"><![CDATA[";
849 print $line["title"];
850 print "]]></category>";
853 print "</feed-categories>";
857 $result = db_query($link, "SELECT * FROM
858 ttrss_labels2 WHERE owner_uid = ".$_SESSION["uid"]);
860 while ($line = db_fetch_assoc($result)) {
862 id=\"".$line["id"]."\"
863 fg_color=\"".$line["fg_color"]."\"
864 bg_color=\"".$line["bg_color"]."\"
866 print $line["caption"];
879 $skip = $limit*($stage-1);
881 print "<limit value=\"$limit\"/>";
883 if ($amount > 0) $amount -= $skip;
887 $limit = min($limit, $amount);
890 $unread_qpart = "(unread = true OR marked = true) AND ";
893 if ($cidt && $cidb) {
894 $cid_qpart = "(ttrss_entries.id > $cidt OR ttrss_entries.id < $cidb) AND ";
897 if (DB_TYPE
== "pgsql") {
898 $date_qpart = "updated >= NOW() - INTERVAL '1 week' AND";
900 $date_qpart = "updated >= DATE_SUB(NOW(), INTERVAL 1 WEEK) AND";
903 $result = db_query($link,
904 "SELECT DISTINCT ttrss_entries.id,ttrss_entries.title,
906 feed_id,content,updated,unread,marked FROM
907 ttrss_user_entries,ttrss_entries,ttrss_feeds
908 WHERE $unread_qpart $cid_qpart $date_qpart
909 ttrss_feeds.id = feed_id AND
910 ref_id = ttrss_entries.id AND
911 ttrss_user_entries.owner_uid = ".$_SESSION["uid"]."
912 ORDER BY updated DESC LIMIT $limit OFFSET $skip");
914 if (function_exists('json_encode')) {
916 while ($line = db_fetch_assoc($result)) {
917 print "<article><![CDATA[";
919 $line["marked"] = (int)sql_bool_to_bool($line["marked"]);
920 $line["unread"] = (int)sql_bool_to_bool($line["unread"]);
922 $line["labels"] = get_article_labels($link, $line["id"]);
925 // $line["tags"] = format_tags_string(
926 // get_article_tags($link, $line["id"]), $line["id"]);
928 print json_encode($line);
929 print "]]></article>";
939 print "</rpc-reply>";
944 if ($subop == "digest-get-contents") {
945 $article_id = db_escape_string($_REQUEST['article_id']);
947 $result = db_query($link, "SELECT content
948 FROM ttrss_entries, ttrss_user_entries
949 WHERE id = '$article_id' AND ref_id = id AND owner_uid = ".$_SESSION['uid']);
953 print "<article id=\"$article_id\"><![CDATA[";
955 $content = sanitize_rss($link, db_fetch_result($result, 0, "content"));
959 print "]]></article>";
961 print "</rpc-reply>";
966 if ($subop == "digest-update") {
967 $feed_id = db_escape_string($_REQUEST['feed_id']);
968 $offset = db_escape_string($_REQUEST['offset']);
969 $seq = db_escape_string($_REQUEST['seq']);
971 if (!$feed_id) $feed_id = -4;
972 if (!$offset) $offset = 0;
975 print "<seq>$seq</seq>";
977 $headlines = api_get_headlines($link, $feed_id, 10, $offset,
978 '', ($feed_id == -4), true, false, "unread", "updated DESC");
980 //function api_get_headlines($link, $feed_id, $limit, $offset,
981 // $filter, $is_cat, $show_excerpt, $show_content, $view_mode) {
983 print "<headlines-title><![CDATA[" . getFeedTitle($link, $feed_id) .
984 "]]></headlines-title>";
986 print "<headlines><![CDATA[" . json_encode($headlines) . "]]></headlines>";
988 print "</rpc-reply>";
992 if ($subop == "digest-init") {
995 $tmp_feeds = api_get_feeds($link, false, true, false, 0);
998 foreach ($tmp_feeds as $f) {
999 if ($f['id'] > 0 ||
$f['id'] == -4) array_push($feeds, $f);
1002 print "<feeds><![CDATA[" . json_encode($feeds) . "]]></feeds>";
1004 print "</rpc-reply>";
1008 if ($subop == "catchupFeed") {
1010 $feed_id = db_escape_string($_REQUEST['feed_id']);
1011 $is_cat = db_escape_string($_REQUEST['is_cat']);
1013 print "<rpc-reply>";
1015 catchup_feed($link, $feed_id, $is_cat);
1017 print "</rpc-reply>";
1022 if ($subop == "sendEmail") {
1023 $secretkey = $_REQUEST['secretkey'];
1025 print "<rpc-reply>";
1027 if (DIGEST_ENABLE
&& $_SESSION['email_secretkey'] &&
1028 $secretkey == $_SESSION['email_secretkey']) {
1030 $_SESSION['email_secretkey'] = '';
1032 $destination = $_REQUEST['destination'];
1033 $subject = $_REQUEST['subject'];
1034 $content = $_REQUEST['content'];
1036 $replyto = strip_tags($_SESSION['email_replyto']);
1037 $fromname = strip_tags($_SESSION['email_fromname']);
1039 $mail = new PHPMailer();
1041 $mail->PluginDir
= "lib/phpmailer/";
1042 $mail->SetLanguage("en", "lib/phpmailer/language/");
1044 $mail->CharSet
= "UTF-8";
1046 $mail->From
= $replyto;
1047 $mail->FromName
= $fromname;
1048 $mail->AddAddress($destination);
1050 if (DIGEST_SMTP_HOST
) {
1051 $mail->Host
= DIGEST_SMTP_HOST
;
1052 $mail->Mailer
= "smtp";
1053 $mail->SMTPAuth
= DIGEST_SMTP_LOGIN
!= '';
1054 $mail->Username
= DIGEST_SMTP_LOGIN
;
1055 $mail->Password
= DIGEST_SMTP_PASSWORD
;
1058 $mail->IsHTML(false);
1059 $mail->Subject
= $subject;
1060 $mail->Body
= $content;
1062 $rc = $mail->Send();
1065 print "<error><![CDATA[" . $mail->ErrorInfo
. "]]></error>";
1067 save_email_address($link, db_escape_string($destination));
1068 print "<message>OK</message>";
1072 print "<error>Not authorized.</error>";
1075 print "</rpc-reply>";
1080 if ($subop == "completeEmails") {
1082 $search = db_escape_string($_REQUEST["search"]);
1086 foreach ($_SESSION['stored_emails'] as $email) {
1087 if (strpos($email, $search) !== false) {
1088 print "<li>$email</li>";
1097 print "<rpc-reply><error>Unknown method: $subop</error></rpc-reply>";