]> git.wh0rd.org - tt-rss.git/blob - modules/backend-rpc.php
rpc/publ: typo
[tt-rss.git] / modules / backend-rpc.php
1 <?php
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
48 $omode = $_GET["omode"];
49
50 getAllCounters($link, $omode);
51 print "</counters>";
52 print_runtime_info($link);
53 print "</rpc-reply>";
54 }
55
56 if ($subop == "mark") {
57 $mark = $_GET["mark"];
58 $id = db_escape_string($_GET["id"]);
59
60 if ($mark == "1") {
61 $mark = "true";
62 } else {
63 $mark = "false";
64 }
65
66 // FIXME this needs collision testing
67
68 $result = db_query($link, "UPDATE ttrss_user_entries SET marked = $mark
69 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
70 }
71
72 if ($subop == "publ") {
73 $pub = $_GET["pub"];
74 $id = db_escape_string($_GET["id"]);
75
76 if ($pub == "1") {
77 $pub = "true";
78 } else {
79 $pub = "false";
80 }
81
82 // FIXME this needs collision testing
83
84 $result = db_query($link, "UPDATE ttrss_user_entries SET published = $pub
85 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
86 }
87
88 if ($subop == "updateFeed") {
89 $feed_id = db_escape_string($_GET["feed"]);
90
91 $result = db_query($link,
92 "SELECT feed_url FROM ttrss_feeds WHERE id = '$feed_id'
93 AND owner_uid = " . $_SESSION["uid"]);
94
95 if (db_num_rows($result) > 0) {
96 $feed_url = db_fetch_result($result, 0, "feed_url");
97 update_rss_feed($link, $feed_url, $feed_id);
98 }
99
100 print "<rpc-reply>";
101 print "<counters>";
102 getFeedCounter($link, $feed_id);
103 print "</counters>";
104 print "</rpc-reply>";
105
106 return;
107 }
108
109 if ($subop == "forceUpdateAllFeeds" || $subop == "updateAllFeeds") {
110
111 if (ENABLE_UPDATE_DAEMON) {
112
113 if ($subop == "forceUpdateAllFeeds") {
114
115 $result = db_query($link, "SELECT count(id) AS cid FROM
116 ttrss_scheduled_updates WHERE feed_id IS NULL AND
117 owner_uid = " . $_SESSION["uid"]);
118
119 $cid = db_fetch_result($result, 0, "cid");
120
121 if ($cid == 0) {
122
123 db_query($link, "INSERT INTO ttrss_scheduled_updates
124 (owner_uid, feed_id, entered) VALUES
125 (".$_SESSION["uid"].", NULL, NOW())");
126
127 }
128 }
129
130 } else {
131 update_all_feeds($link, $subop == "forceUpdateAllFeeds");
132 }
133
134 $global_unread_caller = sprintf("%d", $_GET["uctr"]);
135 $global_unread = getGlobalUnread($link);
136
137 print "<rpc-reply>";
138
139 print "<counters>";
140
141 if ($global_unread_caller != $global_unread) {
142
143 $omode = $_GET["omode"];
144
145 if (!$omode) $omode = "tflc";
146
147 if (strchr($omode, "l")) getLabelCounters($link);
148 if (strchr($omode, "f")) getFeedCounters($link);
149 if (strchr($omode, "t")) getTagCounters($link);
150 if (strchr($omode, "c")) {
151 if (get_pref($link, 'ENABLE_FEED_CATS')) {
152 getCategoryCounters($link);
153 }
154 }
155 }
156
157 getGlobalCounters($link, $global_unread);
158
159 print "</counters>";
160
161 print_runtime_info($link);
162
163 print "</rpc-reply>";
164
165 }
166
167 /* GET["cmode"] = 0 - mark as read, 1 - as unread, 2 - toggle */
168 if ($subop == "catchupSelected") {
169
170 $ids = split(",", db_escape_string($_GET["ids"]));
171 $cmode = sprintf("%d", $_GET["cmode"]);
172
173 catchupArticlesById($link, $ids, $cmode);
174
175 print "<rpc-reply>";
176 print "<counters>";
177 getAllCounters($link);
178 print "</counters>";
179 print_runtime_info($link);
180 print "</rpc-reply>";
181 }
182
183 if ($subop == "markSelected") {
184
185 $ids = split(",", db_escape_string($_GET["ids"]));
186 $cmode = sprintf("%d", $_GET["cmode"]);
187
188 markArticlesById($link, $ids, $cmode);
189
190 print "<rpc-reply>";
191 print "<counters>";
192 getAllCounters($link);
193 print "</counters>";
194 print_runtime_info($link);
195 print "</rpc-reply>";
196 }
197
198 if ($subop == "publishSelected") {
199
200 $ids = split(",", db_escape_string($_GET["ids"]));
201 $cmode = sprintf("%d", $_GET["cmode"]);
202
203 publishArticlesById($link, $ids, $cmode);
204
205 print "<rpc-reply>";
206 print "<counters>";
207 getAllCounters($link);
208 print "</counters>";
209 print_runtime_info($link);
210 print "</rpc-reply>";
211 }
212
213 if ($subop == "sanityCheck") {
214 print "<rpc-reply>";
215 if (sanity_check($link)) {
216 print "<error error-code=\"0\"/>";
217 print_init_params($link);
218 print_runtime_info($link);
219
220 # assign client-passed params to session
221 $_SESSION["client.userAgent"] = $_GET["ua"];
222
223 }
224 print "</rpc-reply>";
225 }
226
227 if ($subop == "globalPurge") {
228
229 print "<rpc-reply>";
230 global_purge_old_posts($link, true);
231 print "</rpc-reply>";
232
233 }
234
235 if ($subop == "getArticleLink") {
236
237 $id = db_escape_string($_GET["id"]);
238
239 $result = db_query($link, "SELECT link FROM ttrss_entries, ttrss_user_entries
240 WHERE id = '$id' AND id = ref_id AND owner_uid = '".$_SESSION['uid']."'");
241
242 if (db_num_rows($result) == 1) {
243 $link = strip_tags(db_fetch_result($result, 0, "link"));
244 print "<rpc-reply><link>$link</link><id>$id</id></rpc-reply>";
245 } else {
246 print "<rpc-reply><error>Article not found</error></rpc-reply>";
247 }
248 }
249
250 if ($subop == "setArticleTags") {
251
252 $id = db_escape_string($_GET["id"]);
253
254 $tags_str = db_escape_string($_GET["tags_str"]);
255
256 $tags = array_unique(trim_array(split(",", $tags_str)));
257
258 db_query($link, "BEGIN");
259
260 $result = db_query($link, "SELECT int_id FROM ttrss_user_entries WHERE
261 ref_id = '$id' AND owner_uid = '".$_SESSION["uid"]."' LIMIT 1");
262
263 if (db_num_rows($result) == 1) {
264
265 $int_id = db_fetch_result($result, 0, "int_id");
266
267 db_query($link, "DELETE FROM ttrss_tags WHERE
268 post_int_id = $int_id AND owner_uid = '".$_SESSION["uid"]."'");
269
270 foreach ($tags as $tag) {
271 $tag = sanitize_tag($tag);
272
273 if (!tag_is_valid($tag)) {
274 continue;
275 }
276
277 if (preg_match("/^[0-9]*$/", $tag)) {
278 continue;
279 }
280
281 // print "<!-- $tag -->";
282
283 if ($tag != '') {
284 db_query($link, "INSERT INTO ttrss_tags
285 (post_int_id, owner_uid, tag_name) VALUES ('$int_id', '".$_SESSION["uid"]."', '$tag')");
286 }
287 }
288 }
289
290 db_query($link, "COMMIT");
291
292 print "<rpc-reply>
293 <message>$id</message>
294 </rpc-reply>";
295
296 }
297
298 if ($subop == "regenPubKey") {
299
300 print "<rpc-reply>";
301
302 set_pref($link, "_PREFS_PUBLISH_KEY", generate_publish_key());
303
304 $url_path = 'http://' . $_SERVER["HTTP_HOST"] . \
305 parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH);
306
307 $new_link = $url_path . "?op=publish&key=" . get_pref($link, "_PREFS_PUBLISH_KEY");
308
309 print "<link><![CDATA[$new_link]]></link>";
310
311 print "</rpc-reply>";
312
313 }
314
315 if ($subop == "logout") {
316 logout_user();
317 print_error_xml(6);
318 }
319
320 }
321 ?>