]> git.wh0rd.org - tt-rss.git/blob - backend-rpc.php
pref-feeds editor preserves cat_id when categories are disabled, fix feed order in...
[tt-rss.git] / backend-rpc.php
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 print "<counters>";
28 getLabelCounters($link);
29 if ($aid) {
30 getFeedCounter($link, $aid);
31 }
32 print "</counters>";
33 print "</rpc-reply>";
34 }
35
36 if ($subop == "getFeedCounters") {
37 print "<rpc-reply>";
38 print "<counters>";
39 getFeedCounters($link);
40 print "</counters>";
41 print "</rpc-reply>";
42 }
43
44 if ($subop == "getAllCounters") {
45 print "<rpc-reply>";
46 print "<counters>";
47 getAllCounters($link);
48 print "</counters>";
49 print_runtime_info($link);
50 print "</rpc-reply>";
51 }
52
53 if ($subop == "mark") {
54 $mark = $_GET["mark"];
55 $id = db_escape_string($_GET["id"]);
56
57 if ($mark == "1") {
58 $mark = "true";
59 } else {
60 $mark = "false";
61 }
62
63 // FIXME this needs collision testing
64
65 $result = db_query($link, "UPDATE ttrss_user_entries SET marked = $mark
66 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
67 }
68
69 if ($subop == "updateFeed") {
70 $feed_id = db_escape_string($_GET["feed"]);
71
72 $result = db_query($link,
73 "SELECT feed_url FROM ttrss_feeds WHERE id = '$feed_id'
74 AND owner_uid = " . $_SESSION["uid"]);
75
76 if (db_num_rows($result) > 0) {
77 $feed_url = db_fetch_result($result, 0, "feed_url");
78 update_rss_feed($link, $feed_url, $feed_id);
79 }
80
81 print "<rpc-reply>";
82 print "<counters>";
83 getFeedCounter($link, $feed_id);
84 print "</counters>";
85 print "</rpc-reply>";
86
87 return;
88 }
89
90 if ($subop == "forceUpdateAllFeeds" || $subop == "updateAllFeeds") {
91
92 if (ENABLE_UPDATE_DAEMON) {
93
94 if ($subop == "forceUpdateAllFeeds") {
95
96 $result = db_query($link, "SELECT count(id) AS cid FROM
97 ttrss_scheduled_updates WHERE feed_id IS NULL AND
98 owner_uid = " . $_SESSION["uid"]);
99
100 $cid = db_fetch_result($result, 0, "cid");
101
102 if ($cid == 0) {
103
104 db_query($link, "INSERT INTO ttrss_scheduled_updates
105 (owner_uid, feed_id, entered) VALUES
106 (".$_SESSION["uid"].", NULL, NOW())");
107
108 }
109 }
110
111 } else {
112 update_all_feeds($link, $subop == "forceUpdateAllFeeds");
113 }
114
115 $global_unread_caller = sprintf("%d", $_GET["uctr"]);
116 $global_unread = getGlobalUnread($link);
117
118 print "<rpc-reply>";
119
120 print "<counters>";
121
122 if ($global_unread_caller != $global_unread) {
123
124 $omode = $_GET["omode"];
125
126 if (!$omode) $omode = "tflc";
127
128 if (strchr($omode, "l")) getLabelCounters($link);
129 if (strchr($omode, "f")) getFeedCounters($link);
130 if (strchr($omode, "t")) getTagCounters($link);
131 if (strchr($omode, "c")) {
132 if (get_pref($link, 'ENABLE_FEED_CATS')) {
133 getCategoryCounters($link);
134 }
135 }
136 }
137
138 getGlobalCounters($link, $global_unread);
139
140 print "</counters>";
141
142 print_runtime_info($link);
143
144 print "</rpc-reply>";
145
146 }
147
148 /* GET["cmode"] = 0 - mark as read, 1 - as unread, 2 - toggle */
149 if ($subop == "catchupSelected") {
150
151 $ids = split(",", db_escape_string($_GET["ids"]));
152
153 $cmode = sprintf("%d", $_GET["cmode"]);
154
155 foreach ($ids as $id) {
156
157 if ($cmode == 0) {
158 db_query($link, "UPDATE ttrss_user_entries SET
159 unread = false,last_read = NOW()
160 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
161 } else if ($cmode == 1) {
162 db_query($link, "UPDATE ttrss_user_entries SET
163 unread = true
164 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
165 } else {
166 db_query($link, "UPDATE ttrss_user_entries SET
167 unread = NOT unread,last_read = NOW()
168 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
169 }
170 }
171 print "<rpc-reply>";
172 print "<counters>";
173 getAllCounters($link);
174 print "</counters>";
175 print_runtime_info($link);
176 print "</rpc-reply>";
177 }
178
179 if ($subop == "markSelected") {
180
181 $ids = split(",", db_escape_string($_GET["ids"]));
182
183 $cmode = sprintf("%d", $_GET["cmode"]);
184
185 foreach ($ids as $id) {
186
187 if ($cmode == 0) {
188 db_query($link, "UPDATE ttrss_user_entries SET
189 marked = false
190 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
191 } else if ($cmode == 1) {
192 db_query($link, "UPDATE ttrss_user_entries SET
193 marked = true
194 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
195 } else {
196 db_query($link, "UPDATE ttrss_user_entries SET
197 marked = NOT marked
198 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
199 }
200 }
201 print "<rpc-reply>";
202 print "<counters>";
203 getAllCounters($link);
204 print "</counters>";
205 print_runtime_info($link);
206 print "</rpc-reply>";
207 }
208
209 if ($subop == "sanityCheck") {
210 print "<rpc-reply>";
211 if (sanity_check($link)) {
212 print "<error error-code=\"0\"/>";
213 print_init_params($link);
214 print_runtime_info($link);
215 }
216 print "</rpc-reply>";
217 }
218
219 if ($subop == "globalPurge") {
220
221 print "<rpc-reply>";
222 global_purge_old_posts($link, true);
223 print "</rpc-reply>";
224
225 }
226
227 if ($subop == "storeParam") {
228 $key = $_GET["key"];
229 $value = $_GET["value"];
230 $_SESSION["stored-params"][$key] = $value;
231 }
232 }
233 ?>