]>
git.wh0rd.org - tt-rss.git/blob - modules/backend-rpc.php
3ca471377c619ce621f2f67b71cd565f22bf928d
2 function handle_rpc_request($link) {
4 $subop = $_GET["subop"];
6 if ($subop == "setpref") {
13 $key = db_escape_string($_GET["key"]);
14 $value = db_escape_string($_GET["value"]);
16 set_pref($link, $key, $value);
18 print "<param-set key=\"$key\" value=\"$value\"/>";
24 if ($subop == "getLabelCounters") {
28 getLabelCounters($link);
30 getFeedCounter($link, $aid);
36 if ($subop == "getFeedCounters") {
39 getFeedCounters($link);
44 if ($subop == "getAllCounters") {
48 $omode = $_GET["omode"];
50 getAllCounters($link, $omode);
52 print_runtime_info($link);
56 if ($subop == "mark") {
57 $mark = $_GET["mark"];
58 $id = db_escape_string($_GET["id"]);
66 // FIXME this needs collision testing
68 $result = db_query($link, "UPDATE ttrss_user_entries SET marked = $mark
69 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
72 if ($subop == "updateFeed") {
73 $feed_id = db_escape_string($_GET["feed"]);
75 $result = db_query($link,
76 "SELECT feed_url FROM ttrss_feeds WHERE id = '$feed_id'
77 AND owner_uid = " . $_SESSION["uid"]);
79 if (db_num_rows($result) > 0) {
80 $feed_url = db_fetch_result($result, 0, "feed_url");
81 update_rss_feed($link, $feed_url, $feed_id);
86 getFeedCounter($link, $feed_id);
93 if ($subop == "forceUpdateAllFeeds" ||
$subop == "updateAllFeeds") {
95 if (ENABLE_UPDATE_DAEMON
) {
97 if ($subop == "forceUpdateAllFeeds") {
99 $result = db_query($link, "SELECT count(id) AS cid FROM
100 ttrss_scheduled_updates WHERE feed_id IS NULL AND
101 owner_uid = " . $_SESSION["uid"]);
103 $cid = db_fetch_result($result, 0, "cid");
107 db_query($link, "INSERT INTO ttrss_scheduled_updates
108 (owner_uid, feed_id, entered) VALUES
109 (".$_SESSION["uid"].", NULL, NOW())");
115 update_all_feeds($link, $subop == "forceUpdateAllFeeds");
118 $global_unread_caller = sprintf("%d", $_GET["uctr"]);
119 $global_unread = getGlobalUnread($link);
125 if ($global_unread_caller != $global_unread) {
127 $omode = $_GET["omode"];
129 if (!$omode) $omode = "tflc";
131 if (strchr($omode, "l")) getLabelCounters($link);
132 if (strchr($omode, "f")) getFeedCounters($link);
133 if (strchr($omode, "t")) getTagCounters($link);
134 if (strchr($omode, "c")) {
135 if (get_pref($link, 'ENABLE_FEED_CATS')) {
136 getCategoryCounters($link);
141 getGlobalCounters($link, $global_unread);
145 print_runtime_info($link);
147 print "</rpc-reply>";
151 /* GET["cmode"] = 0 - mark as read, 1 - as unread, 2 - toggle */
152 if ($subop == "catchupSelected") {
154 $ids = split(",", db_escape_string($_GET["ids"]));
155 $cmode = sprintf("%d", $_GET["cmode"]);
157 catchupArticlesById($link, $ids, $cmode);
161 getAllCounters($link);
163 print_runtime_info($link);
164 print "</rpc-reply>";
167 if ($subop == "markSelected") {
169 $ids = split(",", db_escape_string($_GET["ids"]));
170 $cmode = sprintf("%d", $_GET["cmode"]);
172 markArticlesById($link, $ids, $cmode);
176 getAllCounters($link);
178 print_runtime_info($link);
179 print "</rpc-reply>";
182 if ($subop == "sanityCheck") {
184 if (sanity_check($link)) {
185 print "<error error-code=\"0\"/>";
186 print_init_params($link);
187 print_runtime_info($link);
189 # assign client-passed params to session
190 $_SESSION["client.userAgent"] = $_GET["ua"];
193 print "</rpc-reply>";
196 if ($subop == "globalPurge") {
199 global_purge_old_posts($link, true);
200 print "</rpc-reply>";
204 if ($subop == "getArticleLink") {
206 $id = db_escape_string($_GET["id"]);
208 $result = db_query($link, "SELECT link FROM ttrss_entries, ttrss_user_entries
209 WHERE id = '$id' AND id = ref_id AND owner_uid = '".$_SESSION['uid']."'");
211 if (db_num_rows($result) == 1) {
212 $link = strip_tags(db_fetch_result($result, 0, "link"));
213 print "<rpc-reply><link>$link</link><id>$id</id></rpc-reply>";
215 print "<rpc-reply><error>Article not found</error></rpc-reply>";
219 if ($subop == "setArticleTags") {
221 $id = db_escape_string($_GET["id"]);
223 $tags_str = db_escape_string($_GET["tags_str"]);
225 $tags = array_unique(trim_array(split(",", $tags_str)));
227 db_query($link, "BEGIN");
229 $result = db_query($link, "SELECT int_id FROM ttrss_user_entries WHERE
230 ref_id = '$id' AND owner_uid = '".$_SESSION["uid"]."' LIMIT 1");
232 if (db_num_rows($result) == 1) {
234 $int_id = db_fetch_result($result, 0, "int_id");
236 db_query($link, "DELETE FROM ttrss_tags WHERE
237 post_int_id = $int_id AND owner_uid = '".$_SESSION["uid"]."'");
239 foreach ($tags as $tag) {
240 $tag = sanitize_tag($tag);
242 if (!tag_is_valid($tag)) {
246 if (preg_match("/^[0-9]*$/", $tag)) {
250 // print "<!-- $tag -->";
253 db_query($link, "INSERT INTO ttrss_tags
254 (post_int_id, owner_uid, tag_name) VALUES ('$int_id', '".$_SESSION["uid"]."', '$tag')");
259 db_query($link, "COMMIT");
262 <message>$id</message>
267 if ($subop == "logout") {