]>
Commit | Line | Data |
---|---|---|
1d3a17c7 | 1 | <?php |
01b3e191 AD |
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 | ||
85bd574b | 22 | return; |
01b3e191 AD |
23 | } |
24 | ||
25 | if ($subop == "getLabelCounters") { | |
26 | $aid = $_GET["aid"]; | |
27 | print "<rpc-reply>"; | |
f54f515f | 28 | print "<counters>"; |
01b3e191 AD |
29 | getLabelCounters($link); |
30 | if ($aid) { | |
31 | getFeedCounter($link, $aid); | |
32 | } | |
f54f515f | 33 | print "</counters>"; |
01b3e191 | 34 | print "</rpc-reply>"; |
85bd574b AD |
35 | |
36 | return; | |
01b3e191 AD |
37 | } |
38 | ||
39 | if ($subop == "getFeedCounters") { | |
40 | print "<rpc-reply>"; | |
f54f515f | 41 | print "<counters>"; |
01b3e191 | 42 | getFeedCounters($link); |
f54f515f | 43 | print "</counters>"; |
01b3e191 | 44 | print "</rpc-reply>"; |
85bd574b AD |
45 | |
46 | return; | |
01b3e191 AD |
47 | } |
48 | ||
49 | if ($subop == "getAllCounters") { | |
cf4d339c | 50 | print "<rpc-reply>"; |
f54f515f | 51 | print "<counters>"; |
cf4d339c AD |
52 | |
53 | $omode = $_GET["omode"]; | |
54 | ||
55 | getAllCounters($link, $omode); | |
f54f515f AD |
56 | print "</counters>"; |
57 | print_runtime_info($link); | |
01b3e191 | 58 | print "</rpc-reply>"; |
85bd574b AD |
59 | |
60 | return; | |
01b3e191 AD |
61 | } |
62 | ||
63 | if ($subop == "mark") { | |
64 | $mark = $_GET["mark"]; | |
65 | $id = db_escape_string($_GET["id"]); | |
66 | ||
67 | if ($mark == "1") { | |
68 | $mark = "true"; | |
69 | } else { | |
70 | $mark = "false"; | |
71 | } | |
72 | ||
73 | // FIXME this needs collision testing | |
74 | ||
75 | $result = db_query($link, "UPDATE ttrss_user_entries SET marked = $mark | |
76 | WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]); | |
49aa6de9 | 77 | |
36e05046 AD |
78 | print "<rpc-reply><counters>"; |
79 | getGlobalCounters($link); | |
80 | getLabelCounters($link); | |
81 | if (get_pref($link, 'ENABLE_FEED_CATS')) { | |
82 | getCategoryCounters($link); | |
83 | } | |
84 | print "</counters></rpc-reply>"; | |
49aa6de9 | 85 | |
85bd574b | 86 | return; |
01b3e191 AD |
87 | } |
88 | ||
e4f4b46f AD |
89 | if ($subop == "publ") { |
90 | $pub = $_GET["pub"]; | |
91 | $id = db_escape_string($_GET["id"]); | |
92 | ||
93 | if ($pub == "1") { | |
0a8011eb | 94 | $pub = "true"; |
e4f4b46f AD |
95 | } else { |
96 | $pub = "false"; | |
97 | } | |
98 | ||
99 | // FIXME this needs collision testing | |
100 | ||
101 | $result = db_query($link, "UPDATE ttrss_user_entries SET published = $pub | |
102 | WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]); | |
49aa6de9 | 103 | |
36e05046 AD |
104 | print "<rpc-reply><counters>"; |
105 | getGlobalCounters($link); | |
106 | getLabelCounters($link); | |
107 | if (get_pref($link, 'ENABLE_FEED_CATS')) { | |
108 | getCategoryCounters($link); | |
109 | } | |
110 | print "</counters></rpc-reply>"; | |
49aa6de9 | 111 | |
85bd574b | 112 | return; |
e4f4b46f AD |
113 | } |
114 | ||
01b3e191 AD |
115 | if ($subop == "updateFeed") { |
116 | $feed_id = db_escape_string($_GET["feed"]); | |
117 | ||
118 | $result = db_query($link, | |
119 | "SELECT feed_url FROM ttrss_feeds WHERE id = '$feed_id' | |
120 | AND owner_uid = " . $_SESSION["uid"]); | |
121 | ||
122 | if (db_num_rows($result) > 0) { | |
123 | $feed_url = db_fetch_result($result, 0, "feed_url"); | |
124 | update_rss_feed($link, $feed_url, $feed_id); | |
125 | } | |
126 | ||
f54f515f AD |
127 | print "<rpc-reply>"; |
128 | print "<counters>"; | |
01b3e191 | 129 | getFeedCounter($link, $feed_id); |
f54f515f | 130 | print "</counters>"; |
01b3e191 AD |
131 | print "</rpc-reply>"; |
132 | ||
133 | return; | |
134 | } | |
135 | ||
136 | if ($subop == "forceUpdateAllFeeds" || $subop == "updateAllFeeds") { | |
137 | ||
138 | if (ENABLE_UPDATE_DAEMON) { | |
139 | ||
140 | if ($subop == "forceUpdateAllFeeds") { | |
141 | ||
142 | $result = db_query($link, "SELECT count(id) AS cid FROM | |
143 | ttrss_scheduled_updates WHERE feed_id IS NULL AND | |
144 | owner_uid = " . $_SESSION["uid"]); | |
145 | ||
146 | $cid = db_fetch_result($result, 0, "cid"); | |
147 | ||
148 | if ($cid == 0) { | |
149 | ||
150 | db_query($link, "INSERT INTO ttrss_scheduled_updates | |
151 | (owner_uid, feed_id, entered) VALUES | |
152 | (".$_SESSION["uid"].", NULL, NOW())"); | |
153 | ||
154 | } | |
155 | } | |
156 | ||
157 | } else { | |
158 | update_all_feeds($link, $subop == "forceUpdateAllFeeds"); | |
159 | } | |
160 | ||
161 | $global_unread_caller = sprintf("%d", $_GET["uctr"]); | |
162 | $global_unread = getGlobalUnread($link); | |
163 | ||
164 | print "<rpc-reply>"; | |
165 | ||
f54f515f AD |
166 | print "<counters>"; |
167 | ||
1341ea0d AD |
168 | $omode = $_GET["omode"]; |
169 | ||
170 | if (!$omode) $omode = "tflc"; | |
171 | ||
172 | if (strchr($omode, "l")) getLabelCounters($link); | |
173 | ||
174 | if (strchr($omode, "c")) { | |
175 | if (get_pref($link, 'ENABLE_FEED_CATS')) { | |
176 | getCategoryCounters($link); | |
177 | } | |
178 | } | |
179 | ||
01b3e191 AD |
180 | if ($global_unread_caller != $global_unread) { |
181 | ||
01b3e191 AD |
182 | if (strchr($omode, "f")) getFeedCounters($link); |
183 | if (strchr($omode, "t")) getTagCounters($link); | |
01b3e191 AD |
184 | } |
185 | ||
186 | getGlobalCounters($link, $global_unread); | |
187 | ||
f54f515f AD |
188 | print "</counters>"; |
189 | ||
190 | print_runtime_info($link); | |
191 | ||
01b3e191 AD |
192 | print "</rpc-reply>"; |
193 | ||
85bd574b | 194 | return; |
01b3e191 | 195 | } |
472782e8 | 196 | |
01b3e191 AD |
197 | /* GET["cmode"] = 0 - mark as read, 1 - as unread, 2 - toggle */ |
198 | if ($subop == "catchupSelected") { | |
199 | ||
200 | $ids = split(",", db_escape_string($_GET["ids"])); | |
01b3e191 AD |
201 | $cmode = sprintf("%d", $_GET["cmode"]); |
202 | ||
472782e8 | 203 | catchupArticlesById($link, $ids, $cmode); |
01b3e191 | 204 | |
01b3e191 | 205 | print "<rpc-reply>"; |
f54f515f | 206 | print "<counters>"; |
2bc2147f | 207 | getAllCounters($link, $_GET["omode"]); |
f54f515f AD |
208 | print "</counters>"; |
209 | print_runtime_info($link); | |
01b3e191 | 210 | print "</rpc-reply>"; |
85bd574b AD |
211 | |
212 | return; | |
01b3e191 AD |
213 | } |
214 | ||
215 | if ($subop == "markSelected") { | |
216 | ||
217 | $ids = split(",", db_escape_string($_GET["ids"])); | |
01b3e191 AD |
218 | $cmode = sprintf("%d", $_GET["cmode"]); |
219 | ||
18eddb2c AD |
220 | markArticlesById($link, $ids, $cmode); |
221 | ||
01b3e191 | 222 | print "<rpc-reply>"; |
f54f515f | 223 | print "<counters>"; |
2bc2147f | 224 | getAllCounters($link, $_GET["omode"]); |
f54f515f AD |
225 | print "</counters>"; |
226 | print_runtime_info($link); | |
01b3e191 | 227 | print "</rpc-reply>"; |
85bd574b AD |
228 | |
229 | return; | |
01b3e191 AD |
230 | } |
231 | ||
e4f4b46f AD |
232 | if ($subop == "publishSelected") { |
233 | ||
234 | $ids = split(",", db_escape_string($_GET["ids"])); | |
235 | $cmode = sprintf("%d", $_GET["cmode"]); | |
236 | ||
237 | publishArticlesById($link, $ids, $cmode); | |
238 | ||
239 | print "<rpc-reply>"; | |
240 | print "<counters>"; | |
2bc2147f | 241 | getAllCounters($link, $_GET["omode"]); |
e4f4b46f AD |
242 | print "</counters>"; |
243 | print_runtime_info($link); | |
244 | print "</rpc-reply>"; | |
85bd574b AD |
245 | |
246 | return; | |
e4f4b46f AD |
247 | } |
248 | ||
01b3e191 | 249 | if ($subop == "sanityCheck") { |
3ac2b520 | 250 | print "<rpc-reply>"; |
01b3e191 AD |
251 | if (sanity_check($link)) { |
252 | print "<error error-code=\"0\"/>"; | |
3ac2b520 | 253 | print_init_params($link); |
f54f515f | 254 | print_runtime_info($link); |
4220d6b0 AD |
255 | |
256 | # assign client-passed params to session | |
257 | $_SESSION["client.userAgent"] = $_GET["ua"]; | |
258 | ||
01b3e191 | 259 | } |
3ac2b520 | 260 | print "</rpc-reply>"; |
85bd574b AD |
261 | |
262 | return; | |
3ac2b520 | 263 | } |
01b3e191 AD |
264 | |
265 | if ($subop == "globalPurge") { | |
266 | ||
267 | print "<rpc-reply>"; | |
268 | global_purge_old_posts($link, true); | |
269 | print "</rpc-reply>"; | |
270 | ||
85bd574b | 271 | return; |
01b3e191 | 272 | } |
3ac2b520 | 273 | |
298f3f78 AD |
274 | if ($subop == "getArticleLink") { |
275 | ||
276 | $id = db_escape_string($_GET["id"]); | |
277 | ||
278 | $result = db_query($link, "SELECT link FROM ttrss_entries, ttrss_user_entries | |
279 | WHERE id = '$id' AND id = ref_id AND owner_uid = '".$_SESSION['uid']."'"); | |
280 | ||
281 | if (db_num_rows($result) == 1) { | |
282 | $link = strip_tags(db_fetch_result($result, 0, "link")); | |
e2ccbfab | 283 | print "<rpc-reply><link>$link</link><id>$id</id></rpc-reply>"; |
298f3f78 AD |
284 | } else { |
285 | print "<rpc-reply><error>Article not found</error></rpc-reply>"; | |
286 | } | |
85bd574b AD |
287 | |
288 | return; | |
298f3f78 AD |
289 | } |
290 | ||
0b126ac2 | 291 | if ($subop == "setArticleTags") { |
14b6c54b | 292 | |
0b126ac2 | 293 | $id = db_escape_string($_GET["id"]); |
14b6c54b | 294 | |
0b126ac2 AD |
295 | $tags_str = db_escape_string($_GET["tags_str"]); |
296 | ||
d62a3b63 | 297 | $tags = array_unique(trim_array(split(",", $tags_str))); |
0b126ac2 AD |
298 | |
299 | db_query($link, "BEGIN"); | |
300 | ||
301 | $result = db_query($link, "SELECT int_id FROM ttrss_user_entries WHERE | |
302 | ref_id = '$id' AND owner_uid = '".$_SESSION["uid"]."' LIMIT 1"); | |
303 | ||
304 | if (db_num_rows($result) == 1) { | |
305 | ||
306 | $int_id = db_fetch_result($result, 0, "int_id"); | |
307 | ||
308 | db_query($link, "DELETE FROM ttrss_tags WHERE | |
309 | post_int_id = $int_id AND owner_uid = '".$_SESSION["uid"]."'"); | |
310 | ||
311 | foreach ($tags as $tag) { | |
14b6c54b | 312 | $tag = sanitize_tag($tag); |
0b126ac2 | 313 | |
ef063748 AD |
314 | if (!tag_is_valid($tag)) { |
315 | continue; | |
316 | } | |
317 | ||
0b126ac2 AD |
318 | if (preg_match("/^[0-9]*$/", $tag)) { |
319 | continue; | |
320 | } | |
14b6c54b | 321 | |
9cfd409d | 322 | print "<!-- $id : $int_id : $tag -->"; |
0b126ac2 AD |
323 | |
324 | if ($tag != '') { | |
325 | db_query($link, "INSERT INTO ttrss_tags | |
326 | (post_int_id, owner_uid, tag_name) VALUES ('$int_id', '".$_SESSION["uid"]."', '$tag')"); | |
327 | } | |
328 | } | |
329 | } | |
330 | ||
331 | db_query($link, "COMMIT"); | |
332 | ||
333 | print "<rpc-reply> | |
334 | <message>$id</message> | |
335 | </rpc-reply>"; | |
336 | ||
85bd574b | 337 | return; |
0b126ac2 | 338 | } |
01a87dff | 339 | |
945c243e AD |
340 | if ($subop == "regenPubKey") { |
341 | ||
342 | print "<rpc-reply>"; | |
343 | ||
344 | set_pref($link, "_PREFS_PUBLISH_KEY", generate_publish_key()); | |
945c243e | 345 | |
f56e3080 | 346 | $new_link = article_publish_url($link); |
945c243e AD |
347 | |
348 | print "<link><![CDATA[$new_link]]></link>"; | |
349 | ||
350 | print "</rpc-reply>"; | |
351 | ||
85bd574b | 352 | return; |
945c243e AD |
353 | } |
354 | ||
01a87dff AD |
355 | if ($subop == "logout") { |
356 | logout_user(); | |
357 | print_error_xml(6); | |
85bd574b | 358 | return; |
01a87dff AD |
359 | } |
360 | ||
05fcdf52 AD |
361 | if ($subop == "completeTags") { |
362 | ||
363 | $search = db_escape_string($_REQUEST["search"]); | |
364 | ||
365 | $result = db_query($link, "SELECT DISTINCT tag_name FROM ttrss_tags | |
366 | WHERE owner_uid = '".$_SESSION["uid"]."' AND | |
367 | tag_name LIKE '$search%' ORDER BY tag_name | |
368 | LIMIT 10"); | |
369 | ||
370 | print "<ul>"; | |
371 | while ($line = db_fetch_assoc($result)) { | |
372 | print "<li>" . $line["tag_name"] . "</li>"; | |
373 | } | |
374 | print "</ul>"; | |
375 | ||
85bd574b | 376 | return; |
05fcdf52 AD |
377 | } |
378 | ||
81cd6cac AD |
379 | if ($subop == "purge") { |
380 | $ids = split(",", db_escape_string($_GET["ids"])); | |
381 | $days = sprintf("%d", $_GET["days"]); | |
382 | ||
383 | print "<rpc-reply>"; | |
384 | ||
385 | print "<message><![CDATA["; | |
386 | ||
387 | foreach ($ids as $id) { | |
388 | ||
389 | $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE | |
390 | id = '$id' AND owner_uid = ".$_SESSION["uid"]); | |
391 | ||
392 | if (db_num_rows($result) == 1) { | |
393 | purge_feed($link, $id, $days, true); | |
394 | } | |
395 | } | |
396 | ||
397 | print "]]></message>"; | |
398 | ||
399 | print "</rpc-reply>"; | |
400 | ||
401 | return; | |
402 | } | |
403 | ||
85bd574b | 404 | print "<rpc-reply><error>Unknown method: $subop</error></rpc-reply>"; |
01b3e191 AD |
405 | } |
406 | ?> |