]> git.wh0rd.org - tt-rss.git/blame - backend-rpc.php
split backend rpc, various interface improvements
[tt-rss.git] / backend-rpc.php
CommitLineData
01b3e191
AD
1<?
2 function handle_rpc_request($link) {
3
4 $subop = $_GET["subop"];
5
6 if ($subop == "setpref") {
7 if (WEB_DEMO_MODE) {
8 return;
9 }
10
11 print "<rpc-reply>";
12
13 $key = db_escape_string($_GET["key"]);
14 $value = db_escape_string($_GET["value"]);
15
16 set_pref($link, $key, $value);
17
18 print "<param-set key=\"$key\" value=\"$value\"/>";
19
20 print "</rpc-reply>";
21
22 }
23
24 if ($subop == "getLabelCounters") {
25 $aid = $_GET["aid"];
26 print "<rpc-reply>";
27 getLabelCounters($link);
28 if ($aid) {
29 getFeedCounter($link, $aid);
30 }
31 print "</rpc-reply>";
32 }
33
34 if ($subop == "getFeedCounters") {
35 print "<rpc-reply>";
36 getFeedCounters($link);
37 print "</rpc-reply>";
38 }
39
40 if ($subop == "getAllCounters") {
41 print "<rpc-reply>";
42 getAllCounters($link);
43 print "</rpc-reply>";
44 }
45
46 if ($subop == "mark") {
47 $mark = $_GET["mark"];
48 $id = db_escape_string($_GET["id"]);
49
50 if ($mark == "1") {
51 $mark = "true";
52 } else {
53 $mark = "false";
54 }
55
56 // FIXME this needs collision testing
57
58 $result = db_query($link, "UPDATE ttrss_user_entries SET marked = $mark
59 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
60 }
61
62 if ($subop == "updateFeed") {
63 $feed_id = db_escape_string($_GET["feed"]);
64
65 $result = db_query($link,
66 "SELECT feed_url FROM ttrss_feeds WHERE id = '$feed_id'
67 AND owner_uid = " . $_SESSION["uid"]);
68
69 if (db_num_rows($result) > 0) {
70 $feed_url = db_fetch_result($result, 0, "feed_url");
71 update_rss_feed($link, $feed_url, $feed_id);
72 }
73
74 print "<rpc-reply>";
75 getFeedCounter($link, $feed_id);
76 print "</rpc-reply>";
77
78 return;
79 }
80
81 if ($subop == "forceUpdateAllFeeds" || $subop == "updateAllFeeds") {
82
83 if (ENABLE_UPDATE_DAEMON) {
84
85 if ($subop == "forceUpdateAllFeeds") {
86
87 $result = db_query($link, "SELECT count(id) AS cid FROM
88 ttrss_scheduled_updates WHERE feed_id IS NULL AND
89 owner_uid = " . $_SESSION["uid"]);
90
91 $cid = db_fetch_result($result, 0, "cid");
92
93 if ($cid == 0) {
94
95 db_query($link, "INSERT INTO ttrss_scheduled_updates
96 (owner_uid, feed_id, entered) VALUES
97 (".$_SESSION["uid"].", NULL, NOW())");
98
99 }
100 }
101
102 } else {
103 update_all_feeds($link, $subop == "forceUpdateAllFeeds");
104 }
105
106 $global_unread_caller = sprintf("%d", $_GET["uctr"]);
107 $global_unread = getGlobalUnread($link);
108
109 print "<rpc-reply>";
110
111 if ($global_unread_caller != $global_unread) {
112
113 $omode = $_GET["omode"];
114
115 if (!$omode) $omode = "tflc";
116
117 if (strchr($omode, "l")) getLabelCounters($link);
118 if (strchr($omode, "f")) getFeedCounters($link);
119 if (strchr($omode, "t")) getTagCounters($link);
120 if (strchr($omode, "c")) {
121 if (get_pref($link, 'ENABLE_FEED_CATS')) {
122 getCategoryCounters($link);
123 }
124 }
125 }
126
127 getGlobalCounters($link, $global_unread);
128
129 print "</rpc-reply>";
130
131 }
132
133 /* GET["cmode"] = 0 - mark as read, 1 - as unread, 2 - toggle */
134 if ($subop == "catchupSelected") {
135
136 $ids = split(",", db_escape_string($_GET["ids"]));
137
138 $cmode = sprintf("%d", $_GET["cmode"]);
139
140 foreach ($ids as $id) {
141
142 if ($cmode == 0) {
143 db_query($link, "UPDATE ttrss_user_entries SET
144 unread = false,last_read = NOW()
145 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
146 } else if ($cmode == 1) {
147 db_query($link, "UPDATE ttrss_user_entries SET
148 unread = true
149 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
150 } else {
151 db_query($link, "UPDATE ttrss_user_entries SET
152 unread = NOT unread,last_read = NOW()
153 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
154 }
155 }
156 print "<rpc-reply>";
157 getAllCounters($link);
158 print "</rpc-reply>";
159 }
160
161 if ($subop == "markSelected") {
162
163 $ids = split(",", db_escape_string($_GET["ids"]));
164
165 $cmode = sprintf("%d", $_GET["cmode"]);
166
167 foreach ($ids as $id) {
168
169 if ($cmode == 0) {
170 db_query($link, "UPDATE ttrss_user_entries SET
171 marked = false
172 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
173 } else if ($cmode == 1) {
174 db_query($link, "UPDATE ttrss_user_entries SET
175 marked = true
176 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
177 } else {
178 db_query($link, "UPDATE ttrss_user_entries SET
179 marked = NOT marked
180 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
181 }
182 }
183 print "<rpc-reply>";
184 getAllCounters($link);
185 print "</rpc-reply>";
186 }
187
188 if ($subop == "sanityCheck") {
189 if (sanity_check($link)) {
190 print "<error error-code=\"0\"/>";
191 }
192 }
193
194 if ($subop == "globalPurge") {
195
196 print "<rpc-reply>";
197 global_purge_old_posts($link, true);
198 print "</rpc-reply>";
199
200 }
201 }
202?>