]>
Commit | Line | Data |
---|---|---|
1d3a17c7 | 1 | <?php |
01b3e191 AD |
2 | function handle_rpc_request($link) { |
3 | ||
b4e75b2a | 4 | $subop = $_REQUEST["subop"]; |
01b3e191 | 5 | |
d9084cf2 AD |
6 | if ($subop == "setprofile") { |
7 | $id = db_escape_string($_REQUEST["id"]); | |
8 | ||
9 | $_SESSION["profile"] = $id; | |
10 | $_SESSION["prefs_cache"] = array(); | |
11 | return; | |
12 | } | |
13 | ||
14 | if ($subop == "remprofiles") { | |
15 | $ids = split(",", db_escape_string(trim($_REQUEST["ids"]))); | |
16 | ||
17 | foreach ($ids as $id) { | |
18 | if ($_SESSION["profile"] != $id) { | |
19 | db_query($link, "DELETE FROM ttrss_settings_profiles WHERE id = '$id' AND | |
20 | owner_uid = " . $_SESSION["uid"]); | |
21 | } | |
22 | } | |
23 | return; | |
24 | } | |
25 | ||
26 | if ($subop == "addprofile") { | |
27 | $title = db_escape_string(trim($_REQUEST["title"])); | |
28 | if ($title) { | |
29 | db_query($link, "BEGIN"); | |
30 | ||
31 | $result = db_query($link, "SELECT id FROM ttrss_settings_profiles | |
32 | WHERE title = '$title' AND owner_uid = " . $_SESSION["uid"]); | |
33 | ||
34 | if (db_num_rows($result) == 0) { | |
35 | ||
36 | db_query($link, "INSERT INTO ttrss_settings_profiles (title, owner_uid) | |
37 | VALUES ('$title', ".$_SESSION["uid"] .")"); | |
38 | ||
39 | $result = db_query($link, "SELECT id FROM ttrss_settings_profiles WHERE | |
40 | title = '$title'"); | |
41 | ||
42 | if (db_num_rows($result) != 0) { | |
43 | $profile_id = db_fetch_result($result, 0, "id"); | |
44 | ||
45 | if ($profile_id) { | |
46 | initialize_user_prefs($link, $_SESSION["uid"], $profile_id); | |
47 | } | |
48 | } | |
49 | } | |
50 | ||
51 | db_query($link, "COMMIT"); | |
52 | } | |
53 | return; | |
54 | } | |
55 | ||
56 | if ($subop == "saveprofile") { | |
57 | $id = db_escape_string($_REQUEST["id"]); | |
58 | $title = db_escape_string(trim($_REQUEST["value"])); | |
59 | ||
60 | if ($id == 0) { | |
61 | print __("Default profile"); | |
62 | return; | |
63 | } | |
64 | ||
65 | if ($title) { | |
66 | db_query($link, "BEGIN"); | |
67 | ||
68 | $result = db_query($link, "SELECT id FROM ttrss_settings_profiles | |
69 | WHERE title = '$title' AND owner_uid =" . $_SESSION["uid"]); | |
70 | ||
71 | if (db_num_rows($result) == 0) { | |
72 | db_query($link, "UPDATE ttrss_settings_profiles | |
73 | SET title = '$title' WHERE id = '$id' AND | |
74 | owner_uid = " . $_SESSION["uid"]); | |
75 | print $title; | |
76 | } else { | |
77 | $result = db_query($link, "SELECT title FROM ttrss_settings_profiles | |
78 | WHERE id = '$id' AND owner_uid =" . $_SESSION["uid"]); | |
79 | print db_fetch_result($result, 0, "title"); | |
80 | } | |
81 | ||
82 | db_query($link, "COMMIT"); | |
83 | } | |
84 | return; | |
85 | } | |
86 | ||
ef88b1cc AD |
87 | if ($subop == "remarchive") { |
88 | $ids = split(",", db_escape_string($_REQUEST["ids"])); | |
89 | ||
90 | print "<rpc-reply>"; | |
91 | ||
92 | foreach ($ids as $id) { | |
93 | $result = db_query($link, "DELETE FROM ttrss_archived_feeds WHERE | |
94 | (SELECT COUNT(*) FROM ttrss_user_entries | |
95 | WHERE orig_feed_id = '$id') = 0 AND | |
96 | id = '$id' AND owner_uid = ".$_SESSION["uid"]); | |
97 | ||
98 | $rc = db_affected_rows($link, $result); | |
99 | ||
100 | print "<feed id='$id' rc='$rc'/>"; | |
101 | ||
102 | } | |
103 | ||
104 | print "</rpc-reply>"; | |
105 | ||
106 | return; | |
107 | } | |
108 | ||
a5819bb3 AD |
109 | if ($subop == "addfeed") { |
110 | ||
111 | $feed = db_escape_string($_REQUEST['feed']); | |
112 | $cat = db_escape_string($_REQUEST['cat']); | |
113 | $login = db_escape_string($_REQUEST['login']); | |
114 | $pass = db_escape_string($_REQUEST['pass']); | |
115 | ||
116 | $rc = subscribe_to_feed($link, $feed, $cat, $login, $pass); | |
117 | ||
118 | print "<rpc-reply>"; | |
119 | print "<result code='$rc'/>"; | |
120 | print "</rpc-reply>"; | |
121 | ||
122 | return; | |
123 | ||
124 | } | |
125 | ||
8a3e0b1a AD |
126 | if ($subop == "togglepref") { |
127 | print "<rpc-reply>"; | |
128 | ||
129 | $key = db_escape_string($_REQUEST["key"]); | |
130 | ||
131 | set_pref($link, $key, !get_pref($link, $key)); | |
132 | ||
133 | $value = get_pref($link, $key); | |
01b3e191 | 134 | |
8a3e0b1a AD |
135 | print "<param-set key=\"$key\" value=\"$value\"/>"; |
136 | ||
137 | print "</rpc-reply>"; | |
138 | ||
139 | return; | |
140 | } | |
141 | ||
142 | if ($subop == "setpref") { | |
01b3e191 AD |
143 | print "<rpc-reply>"; |
144 | ||
b4e75b2a AD |
145 | $key = db_escape_string($_REQUEST["key"]); |
146 | $value = db_escape_string($_REQUEST["value"]); | |
01b3e191 AD |
147 | |
148 | set_pref($link, $key, $value); | |
149 | ||
150 | print "<param-set key=\"$key\" value=\"$value\"/>"; | |
151 | ||
152 | print "</rpc-reply>"; | |
153 | ||
85bd574b | 154 | return; |
01b3e191 AD |
155 | } |
156 | ||
01b3e191 | 157 | if ($subop == "getAllCounters") { |
cf4d339c | 158 | print "<rpc-reply>"; |
6a7817c1 | 159 | print "<counters><![CDATA["; |
cf4d339c | 160 | |
6a7817c1 | 161 | print json_encode(getAllCounters($link, $_REQUEST['omode'])); |
cf4d339c | 162 | |
6a7817c1 | 163 | print "]]></counters>"; |
f54f515f | 164 | print_runtime_info($link); |
01b3e191 | 165 | print "</rpc-reply>"; |
85bd574b AD |
166 | |
167 | return; | |
01b3e191 AD |
168 | } |
169 | ||
170 | if ($subop == "mark") { | |
b4e75b2a AD |
171 | $mark = $_REQUEST["mark"]; |
172 | $id = db_escape_string($_REQUEST["id"]); | |
01b3e191 AD |
173 | |
174 | if ($mark == "1") { | |
175 | $mark = "true"; | |
176 | } else { | |
177 | $mark = "false"; | |
178 | } | |
179 | ||
180 | // FIXME this needs collision testing | |
181 | ||
182 | $result = db_query($link, "UPDATE ttrss_user_entries SET marked = $mark | |
183 | WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]); | |
49aa6de9 | 184 | |
6a7817c1 AD |
185 | print "<rpc-reply><counters><![CDATA["; |
186 | print json_encode(getAllCounters($link)); | |
187 | print "]]></counters></rpc-reply>"; | |
49aa6de9 | 188 | |
85bd574b | 189 | return; |
01b3e191 AD |
190 | } |
191 | ||
e04c18a2 | 192 | if ($subop == "delete") { |
b4e75b2a | 193 | $ids = db_escape_string($_REQUEST["ids"]); |
e04c18a2 AD |
194 | |
195 | $result = db_query($link, "DELETE FROM ttrss_user_entries | |
196 | WHERE ref_id IN ($ids) AND owner_uid = " . $_SESSION["uid"]); | |
197 | ||
6a7817c1 AD |
198 | print "<rpc-reply><counters><![CDATA["; |
199 | print json_encode(getAllCounters($link)); | |
200 | print "]]></counters></rpc-reply>"; | |
e04c18a2 AD |
201 | |
202 | return; | |
203 | } | |
204 | ||
205 | if ($subop == "unarchive") { | |
b4e75b2a | 206 | $ids = db_escape_string($_REQUEST["ids"]); |
e04c18a2 AD |
207 | |
208 | $result = db_query($link, "UPDATE ttrss_user_entries | |
ef83538d | 209 | SET feed_id = orig_feed_id, orig_feed_id = NULL |
e04c18a2 AD |
210 | WHERE ref_id IN ($ids) AND owner_uid = " . $_SESSION["uid"]); |
211 | ||
6a7817c1 AD |
212 | print "<rpc-reply><counters><![CDATA["; |
213 | print json_encode(getAllCounters($link)); | |
214 | print "]]></counters></rpc-reply>"; | |
e04c18a2 AD |
215 | |
216 | return; | |
217 | } | |
218 | ||
219 | if ($subop == "archive") { | |
b4e75b2a | 220 | $ids = split(",", db_escape_string($_REQUEST["ids"])); |
e04c18a2 | 221 | |
16fdac16 AD |
222 | foreach ($ids as $id) { |
223 | archive_article($link, $id, $_SESSION["uid"]); | |
224 | } | |
e04c18a2 | 225 | |
6a7817c1 AD |
226 | print "<rpc-reply><counters><![CDATA["; |
227 | print json_encode(getAllCounters($link)); | |
228 | print "]]></counters></rpc-reply>"; | |
e04c18a2 AD |
229 | |
230 | return; | |
231 | } | |
232 | ||
233 | ||
e4f4b46f | 234 | if ($subop == "publ") { |
c7e51de1 AD |
235 | $pub = $_REQUEST["pub"]; |
236 | $id = db_escape_string($_REQUEST["id"]); | |
237 | $note = trim(strip_tags(db_escape_string($_REQUEST["note"]))); | |
e4f4b46f AD |
238 | |
239 | if ($pub == "1") { | |
0a8011eb | 240 | $pub = "true"; |
e4f4b46f AD |
241 | } else { |
242 | $pub = "false"; | |
243 | } | |
244 | ||
c7e51de1 AD |
245 | if ($note != 'undefined') { |
246 | $note_qpart = "note = '$note',"; | |
247 | } | |
248 | ||
e4f4b46f AD |
249 | // FIXME this needs collision testing |
250 | ||
c7e51de1 AD |
251 | $result = db_query($link, "UPDATE ttrss_user_entries SET |
252 | $note_qpart | |
253 | published = $pub | |
e4f4b46f | 254 | WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]); |
49aa6de9 | 255 | |
c7e51de1 AD |
256 | |
257 | print "<rpc-reply>"; | |
258 | ||
6a7817c1 AD |
259 | print "<counters><![CDATA["; |
260 | print json_encode(getAllCounters($link)); | |
261 | print "]]></counters>"; | |
c7e51de1 AD |
262 | |
263 | if ($note != 'undefined') { | |
264 | $note_size = strlen($note); | |
265 | print "<note id=\"$id\" size=\"$note_size\">"; | |
266 | print "<![CDATA[" . format_article_note($id, $note) . "]]>"; | |
267 | print "</note>"; | |
268 | } | |
269 | ||
270 | print "</rpc-reply>"; | |
49aa6de9 | 271 | |
85bd574b | 272 | return; |
e4f4b46f AD |
273 | } |
274 | ||
01b3e191 | 275 | if ($subop == "updateFeed") { |
b4e75b2a | 276 | $feed_id = db_escape_string($_REQUEST["feed"]); |
01b3e191 | 277 | |
c633e370 | 278 | update_rss_feed($link, $feed_id); |
01b3e191 | 279 | |
f54f515f | 280 | print "<rpc-reply>"; |
6a7817c1 AD |
281 | print "<counters><![CDATA["; |
282 | print json_encode(getFeedCounters($link, $feed_id)); | |
283 | print "]]></counters>"; | |
01b3e191 AD |
284 | print "</rpc-reply>"; |
285 | ||
286 | return; | |
287 | } | |
288 | ||
289 | if ($subop == "forceUpdateAllFeeds" || $subop == "updateAllFeeds") { | |
290 | ||
b4e75b2a | 291 | $global_unread_caller = sprintf("%d", $_REQUEST["uctr"]); |
01b3e191 AD |
292 | $global_unread = getGlobalUnread($link); |
293 | ||
294 | print "<rpc-reply>"; | |
295 | ||
6a7817c1 | 296 | print "<counters><![CDATA["; |
f54f515f | 297 | |
a06d0e5a | 298 | if ($global_unread_caller != $global_unread) { |
6a7817c1 AD |
299 | $omode = $_REQUEST["omode"]; |
300 | print json_encode(getAllCounters($link, $omode)); | |
a06d0e5a AD |
301 | } |
302 | ||
6a7817c1 | 303 | print "]]></counters>"; |
f54f515f AD |
304 | |
305 | print_runtime_info($link); | |
306 | ||
01b3e191 AD |
307 | print "</rpc-reply>"; |
308 | ||
85bd574b | 309 | return; |
01b3e191 | 310 | } |
472782e8 | 311 | |
01b3e191 AD |
312 | /* GET["cmode"] = 0 - mark as read, 1 - as unread, 2 - toggle */ |
313 | if ($subop == "catchupSelected") { | |
314 | ||
2855ee88 AD |
315 | $ids = split(",", db_escape_string($_REQUEST["ids"])); |
316 | $cmode = sprintf("%d", $_REQUEST["cmode"]); | |
01b3e191 | 317 | |
472782e8 | 318 | catchupArticlesById($link, $ids, $cmode); |
01b3e191 | 319 | |
01b3e191 | 320 | print "<rpc-reply>"; |
6a7817c1 AD |
321 | print "<counters><![CDATA["; |
322 | print json_encode(getAllCounters($link, $_REQUEST['omode'])); | |
323 | print "]]></counters>"; | |
324 | ||
f54f515f | 325 | print_runtime_info($link); |
01b3e191 | 326 | print "</rpc-reply>"; |
85bd574b AD |
327 | |
328 | return; | |
01b3e191 AD |
329 | } |
330 | ||
331 | if ($subop == "markSelected") { | |
332 | ||
b4e75b2a AD |
333 | $ids = split(",", db_escape_string($_REQUEST["ids"])); |
334 | $cmode = sprintf("%d", $_REQUEST["cmode"]); | |
01b3e191 | 335 | |
18eddb2c AD |
336 | markArticlesById($link, $ids, $cmode); |
337 | ||
01b3e191 | 338 | print "<rpc-reply>"; |
6a7817c1 AD |
339 | print "<counters><![CDATA["; |
340 | print json_encode(getAllCounters($link, $_REQUEST['omode'])); | |
341 | print "]]></counters>"; | |
f54f515f | 342 | print_runtime_info($link); |
01b3e191 | 343 | print "</rpc-reply>"; |
85bd574b AD |
344 | |
345 | return; | |
01b3e191 AD |
346 | } |
347 | ||
e4f4b46f AD |
348 | if ($subop == "publishSelected") { |
349 | ||
b4e75b2a AD |
350 | $ids = split(",", db_escape_string($_REQUEST["ids"])); |
351 | $cmode = sprintf("%d", $_REQUEST["cmode"]); | |
e4f4b46f AD |
352 | |
353 | publishArticlesById($link, $ids, $cmode); | |
354 | ||
355 | print "<rpc-reply>"; | |
6a7817c1 AD |
356 | print "<counters><![CDATA["; |
357 | print json_encode(getAllCounters($link, $_REQUEST['omode'])); | |
358 | print "]]></counters>"; | |
e4f4b46f AD |
359 | print_runtime_info($link); |
360 | print "</rpc-reply>"; | |
85bd574b AD |
361 | |
362 | return; | |
e4f4b46f AD |
363 | } |
364 | ||
01b3e191 | 365 | if ($subop == "sanityCheck") { |
3ac2b520 | 366 | print "<rpc-reply>"; |
01b3e191 AD |
367 | if (sanity_check($link)) { |
368 | print "<error error-code=\"0\"/>"; | |
3ac2b520 | 369 | print_init_params($link); |
f54f515f | 370 | print_runtime_info($link); |
4220d6b0 AD |
371 | |
372 | # assign client-passed params to session | |
b4e75b2a | 373 | $_SESSION["client.userAgent"] = $_REQUEST["ua"]; |
4220d6b0 | 374 | |
01b3e191 | 375 | } |
3ac2b520 | 376 | print "</rpc-reply>"; |
85bd574b AD |
377 | |
378 | return; | |
3ac2b520 | 379 | } |
01b3e191 AD |
380 | |
381 | if ($subop == "globalPurge") { | |
382 | ||
383 | print "<rpc-reply>"; | |
384 | global_purge_old_posts($link, true); | |
385 | print "</rpc-reply>"; | |
386 | ||
85bd574b | 387 | return; |
01b3e191 | 388 | } |
3ac2b520 | 389 | |
298f3f78 AD |
390 | if ($subop == "getArticleLink") { |
391 | ||
b4e75b2a | 392 | $id = db_escape_string($_REQUEST["id"]); |
298f3f78 AD |
393 | |
394 | $result = db_query($link, "SELECT link FROM ttrss_entries, ttrss_user_entries | |
395 | WHERE id = '$id' AND id = ref_id AND owner_uid = '".$_SESSION['uid']."'"); | |
396 | ||
397 | if (db_num_rows($result) == 1) { | |
06925d9e | 398 | $link = htmlspecialchars(strip_tags(db_fetch_result($result, 0, "link"))); |
e2ccbfab | 399 | print "<rpc-reply><link>$link</link><id>$id</id></rpc-reply>"; |
298f3f78 AD |
400 | } else { |
401 | print "<rpc-reply><error>Article not found</error></rpc-reply>"; | |
402 | } | |
85bd574b AD |
403 | |
404 | return; | |
298f3f78 AD |
405 | } |
406 | ||
0b126ac2 | 407 | if ($subop == "setArticleTags") { |
14b6c54b | 408 | |
bd3f2ade AD |
409 | global $memcache; |
410 | ||
b4e75b2a | 411 | $id = db_escape_string($_REQUEST["id"]); |
14b6c54b | 412 | |
b4e75b2a | 413 | $tags_str = db_escape_string($_REQUEST["tags_str"]); |
0b126ac2 | 414 | |
d62a3b63 | 415 | $tags = array_unique(trim_array(split(",", $tags_str))); |
0b126ac2 AD |
416 | |
417 | db_query($link, "BEGIN"); | |
418 | ||
419 | $result = db_query($link, "SELECT int_id FROM ttrss_user_entries WHERE | |
420 | ref_id = '$id' AND owner_uid = '".$_SESSION["uid"]."' LIMIT 1"); | |
421 | ||
422 | if (db_num_rows($result) == 1) { | |
423 | ||
424 | $int_id = db_fetch_result($result, 0, "int_id"); | |
425 | ||
426 | db_query($link, "DELETE FROM ttrss_tags WHERE | |
427 | post_int_id = $int_id AND owner_uid = '".$_SESSION["uid"]."'"); | |
428 | ||
429 | foreach ($tags as $tag) { | |
14b6c54b | 430 | $tag = sanitize_tag($tag); |
0b126ac2 | 431 | |
ef063748 AD |
432 | if (!tag_is_valid($tag)) { |
433 | continue; | |
434 | } | |
435 | ||
0b126ac2 AD |
436 | if (preg_match("/^[0-9]*$/", $tag)) { |
437 | continue; | |
438 | } | |
14b6c54b | 439 | |
307d187c | 440 | // print "<!-- $id : $int_id : $tag -->"; |
0b126ac2 AD |
441 | |
442 | if ($tag != '') { | |
443 | db_query($link, "INSERT INTO ttrss_tags | |
444 | (post_int_id, owner_uid, tag_name) VALUES ('$int_id', '".$_SESSION["uid"]."', '$tag')"); | |
445 | } | |
446 | } | |
447 | } | |
448 | ||
449 | db_query($link, "COMMIT"); | |
450 | ||
bd3f2ade AD |
451 | if ($memcache) { |
452 | $obj_id = md5("TAGS:".$_SESSION["uid"].":$id"); | |
453 | $memcache->delete($obj_id); | |
454 | } | |
455 | ||
307d187c AD |
456 | $tags_str = format_tags_string(get_article_tags($link, $id), $id); |
457 | ||
0b126ac2 | 458 | print "<rpc-reply> |
307d187c | 459 | <tags-str id=\"$id\"><![CDATA[$tags_str]]></tags-str> |
0b126ac2 AD |
460 | </rpc-reply>"; |
461 | ||
85bd574b | 462 | return; |
0b126ac2 | 463 | } |
01a87dff | 464 | |
945c243e AD |
465 | if ($subop == "regenPubKey") { |
466 | ||
467 | print "<rpc-reply>"; | |
468 | ||
d9084cf2 | 469 | set_pref($link, "_PREFS_PUBLISH_KEY", generate_publish_key(), $_SESSION["uid"]); |
945c243e | 470 | |
f56e3080 | 471 | $new_link = article_publish_url($link); |
945c243e AD |
472 | |
473 | print "<link><![CDATA[$new_link]]></link>"; | |
474 | ||
475 | print "</rpc-reply>"; | |
476 | ||
85bd574b | 477 | return; |
945c243e AD |
478 | } |
479 | ||
ef7b7bbd MK |
480 | if ($subop == "regenOPMLKey") { |
481 | ||
482 | print "<rpc-reply>"; | |
483 | set_pref($link, " _PREFS_OPML_PUBLISH_KEY", generate_publish_key(), $_SESSION["uid"]); | |
484 | $new_link = opml_publish_url($link); | |
485 | print "<link><![CDATA[$new_link]]></link>"; | |
486 | print "</rpc-reply>"; | |
487 | return; | |
488 | } | |
489 | ||
01a87dff AD |
490 | if ($subop == "logout") { |
491 | logout_user(); | |
492 | print_error_xml(6); | |
85bd574b | 493 | return; |
01a87dff AD |
494 | } |
495 | ||
05fcdf52 AD |
496 | if ($subop == "completeTags") { |
497 | ||
498 | $search = db_escape_string($_REQUEST["search"]); | |
499 | ||
500 | $result = db_query($link, "SELECT DISTINCT tag_name FROM ttrss_tags | |
501 | WHERE owner_uid = '".$_SESSION["uid"]."' AND | |
502 | tag_name LIKE '$search%' ORDER BY tag_name | |
503 | LIMIT 10"); | |
504 | ||
505 | print "<ul>"; | |
506 | while ($line = db_fetch_assoc($result)) { | |
507 | print "<li>" . $line["tag_name"] . "</li>"; | |
508 | } | |
509 | print "</ul>"; | |
510 | ||
85bd574b | 511 | return; |
05fcdf52 AD |
512 | } |
513 | ||
81cd6cac | 514 | if ($subop == "purge") { |
b4e75b2a AD |
515 | $ids = split(",", db_escape_string($_REQUEST["ids"])); |
516 | $days = sprintf("%d", $_REQUEST["days"]); | |
81cd6cac AD |
517 | |
518 | print "<rpc-reply>"; | |
519 | ||
520 | print "<message><![CDATA["; | |
521 | ||
522 | foreach ($ids as $id) { | |
523 | ||
524 | $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE | |
525 | id = '$id' AND owner_uid = ".$_SESSION["uid"]); | |
526 | ||
527 | if (db_num_rows($result) == 1) { | |
528 | purge_feed($link, $id, $days, true); | |
529 | } | |
530 | } | |
531 | ||
532 | print "]]></message>"; | |
533 | ||
534 | print "</rpc-reply>"; | |
535 | ||
536 | return; | |
537 | } | |
538 | ||
9bf3f101 | 539 | /* if ($subop == "setScore") { |
546499a9 AD |
540 | $id = db_escape_string($_REQUEST["id"]); |
541 | $score = sprintf("%d", $_REQUEST["score"]); | |
542 | ||
543 | $result = db_query($link, "UPDATE ttrss_user_entries SET score = '$score' | |
544 | WHERE ref_id = '$id' AND owner_uid = ".$_SESSION["uid"]); | |
545 | ||
546 | print "<rpc-reply><message>Acknowledged.</message></rpc-reply>"; | |
547 | ||
548 | return; | |
549 | ||
9bf3f101 | 550 | } */ |
546499a9 | 551 | |
aa0fa9df AD |
552 | if ($subop == "getArticles") { |
553 | $ids = split(",", db_escape_string($_REQUEST["ids"])); | |
554 | ||
555 | print "<rpc-reply>"; | |
556 | ||
557 | foreach ($ids as $id) { | |
558 | if ($id) { | |
559 | outputArticleXML($link, $id, 0, false); | |
560 | } | |
561 | } | |
562 | print "</rpc-reply>"; | |
563 | ||
564 | return; | |
565 | } | |
566 | ||
d0da85c2 AD |
567 | if ($subop == "checkDate") { |
568 | ||
569 | $date = db_escape_string($_REQUEST["date"]); | |
570 | $date_parsed = strtotime($date); | |
571 | ||
572 | print "<rpc-reply>"; | |
573 | ||
574 | if ($date_parsed) { | |
575 | print "<result>1</result>"; | |
576 | } else { | |
577 | print "<result>0</result>"; | |
578 | } | |
579 | ||
580 | print "</rpc-reply>"; | |
581 | ||
582 | return; | |
583 | } | |
584 | ||
933ba4ee AD |
585 | if ($subop == "removeFromLabel") { |
586 | ||
587 | $ids = split(",", db_escape_string($_REQUEST["ids"])); | |
588 | $label_id = db_escape_string($_REQUEST["lid"]); | |
589 | ||
7a13338b AD |
590 | $label = db_escape_string(label_find_caption($link, $label_id, |
591 | $_SESSION["uid"])); | |
933ba4ee | 592 | |
1c9c6025 AD |
593 | print "<rpc-reply>"; |
594 | print "<info-for-headlines>"; | |
595 | ||
933ba4ee AD |
596 | if ($label) { |
597 | ||
598 | foreach ($ids as $id) { | |
599 | label_remove_article($link, $id, $label, $_SESSION["uid"]); | |
1c9c6025 AD |
600 | |
601 | print "<entry id=\"$id\"><![CDATA["; | |
602 | ||
603 | $labels = get_article_labels($link, $id, $_SESSION["uid"]); | |
2eb9c95c | 604 | print format_article_labels($labels, $id); |
1c9c6025 AD |
605 | |
606 | print "]]></entry>"; | |
607 | ||
933ba4ee AD |
608 | } |
609 | } | |
610 | ||
1c9c6025 AD |
611 | print "</info-for-headlines>"; |
612 | ||
6a7817c1 AD |
613 | print "<counters><![CDATA["; |
614 | print json_encode(getAllCounters($link, $_REQUEST['omode'])); | |
615 | print "]]></counters>"; | |
1c9c6025 | 616 | print "</rpc-reply>"; |
933ba4ee AD |
617 | |
618 | return; | |
619 | } | |
620 | ||
b8a637f3 AD |
621 | if ($subop == "assignToLabel") { |
622 | ||
623 | $ids = split(",", db_escape_string($_REQUEST["ids"])); | |
624 | $label_id = db_escape_string($_REQUEST["lid"]); | |
625 | ||
7a13338b AD |
626 | $label = db_escape_string(label_find_caption($link, $label_id, |
627 | $_SESSION["uid"])); | |
b8a637f3 | 628 | |
f9247195 AD |
629 | print "<rpc-reply>"; |
630 | ||
631 | print "<info-for-headlines>"; | |
632 | ||
b8a637f3 AD |
633 | if ($label) { |
634 | ||
635 | foreach ($ids as $id) { | |
636 | label_add_article($link, $id, $label, $_SESSION["uid"]); | |
f9247195 AD |
637 | |
638 | print "<entry id=\"$id\"><![CDATA["; | |
639 | ||
640 | $labels = get_article_labels($link, $id, $_SESSION["uid"]); | |
2eb9c95c | 641 | print format_article_labels($labels, $id); |
f9247195 AD |
642 | |
643 | print "]]></entry>"; | |
644 | ||
b8a637f3 AD |
645 | } |
646 | } | |
647 | ||
f9247195 AD |
648 | print "</info-for-headlines>"; |
649 | ||
6a7817c1 AD |
650 | print "<counters><![CDATA["; |
651 | print json_encode(getAllCounters($link, $_REQUEST['omode'])); | |
652 | print "]]></counters>"; | |
f9247195 | 653 | print "</rpc-reply>"; |
b8a637f3 AD |
654 | |
655 | return; | |
656 | } | |
657 | ||
ef88b1cc | 658 | if ($subop == "updateFeedBrowser") { |
c2913898 AD |
659 | |
660 | $search = db_escape_string($_REQUEST["search"]); | |
661 | $limit = db_escape_string($_REQUEST["limit"]); | |
082ae95b | 662 | $mode = db_escape_string($_REQUEST["mode"]); |
c2913898 AD |
663 | |
664 | print "<rpc-reply>"; | |
665 | print "<content>"; | |
666 | print "<![CDATA["; | |
082ae95b | 667 | $ctr = print_feed_browser($link, $search, $limit, $mode); |
c2913898 AD |
668 | print "]]>"; |
669 | print "</content>"; | |
670 | print "<num-results value=\"$ctr\"/>"; | |
ef88b1cc | 671 | print "<mode value=\"$mode\"/>"; |
c2913898 AD |
672 | print "</rpc-reply>"; |
673 | ||
674 | return; | |
675 | } | |
676 | ||
ef88b1cc AD |
677 | |
678 | if ($subop == "massSubscribe") { | |
679 | ||
680 | $ids = split(",", db_escape_string($_REQUEST["ids"])); | |
681 | $mode = $_REQUEST["mode"]; | |
682 | ||
683 | $subscribed = array(); | |
684 | ||
685 | foreach ($ids as $id) { | |
686 | ||
687 | if ($mode == 1) { | |
688 | $result = db_query($link, "SELECT feed_url,title FROM ttrss_feeds | |
689 | WHERE id = '$id'"); | |
690 | } else if ($mode == 2) { | |
691 | $result = db_query($link, "SELECT * FROM ttrss_archived_feeds | |
692 | WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]); | |
693 | $orig_id = db_escape_string(db_fetch_result($result, 0, "id")); | |
694 | $site_url = db_escape_string(db_fetch_result($result, 0, "site_url")); | |
695 | } | |
696 | ||
697 | $feed_url = db_escape_string(db_fetch_result($result, 0, "feed_url")); | |
698 | $title = db_escape_string(db_fetch_result($result, 0, "title")); | |
699 | ||
700 | $title_orig = db_fetch_result($result, 0, "title"); | |
701 | ||
702 | $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE | |
703 | feed_url = '$feed_url' AND owner_uid = " . $_SESSION["uid"]); | |
704 | ||
705 | if (db_num_rows($result) == 0) { | |
706 | if ($mode == 1) { | |
707 | $result = db_query($link, | |
708 | "INSERT INTO ttrss_feeds (owner_uid,feed_url,title,cat_id) | |
709 | VALUES ('".$_SESSION["uid"]."', '$feed_url', '$title', NULL)"); | |
710 | } else if ($mode == 2) { | |
711 | $result = db_query($link, | |
712 | "INSERT INTO ttrss_feeds (id,owner_uid,feed_url,title,cat_id,site_url) | |
713 | VALUES ('$orig_id','".$_SESSION["uid"]."', '$feed_url', '$title', NULL, '$site_url')"); | |
714 | } | |
715 | array_push($subscribed, $title_orig); | |
716 | } | |
717 | } | |
718 | ||
719 | $num_feeds = count($subscribed); | |
720 | ||
721 | print "<rpc-reply>"; | |
722 | print "<num-feeds value='$num_feeds'/>"; | |
723 | print "</rpc-reply>"; | |
724 | ||
725 | return; | |
726 | } | |
727 | ||
87b16a0a AD |
728 | if ($subop == "download") { |
729 | $stage = (int) $_REQUEST["stage"]; | |
04870193 AD |
730 | $cidt = (int)db_escape_string($_REQUEST["cidt"]); |
731 | $cidb = (int)db_escape_string($_REQUEST["cidb"]); | |
badac687 | 732 | $sync = db_escape_string($_REQUEST["sync"]); |
51f6f917 AD |
733 | //$amount = (int) $_REQUEST["amount"]; |
734 | //$unread_only = db_escape_string($_REQUEST["unread_only"]); | |
735 | //if (!$amount) $amount = 50; | |
6a1cd591 | 736 | |
d9447516 AD |
737 | /* Amount is not used by the frontend offline.js anymore, it goes by |
738 | * date_qpart below + cidb/cidt IDs */ | |
739 | ||
04870193 | 740 | $amount = 2000; |
51f6f917 | 741 | $unread_only = true; |
87b16a0a AD |
742 | |
743 | print "<rpc-reply>"; | |
744 | ||
badac687 AD |
745 | $sync = split(";", $sync); |
746 | ||
747 | print "<sync>"; | |
748 | ||
749 | if (count($sync) > 0) { | |
750 | if (strtotime($sync[0])) { | |
751 | $last_online = db_escape_string($sync[0]); | |
752 | ||
753 | print "<sync-point><![CDATA[$last_online]]></sync-point>"; | |
754 | ||
755 | for ($i = 1; $i < count($sync); $i++) { | |
756 | $e = split(",", $sync[$i]); | |
757 | ||
758 | if (count($e) == 3) { | |
759 | ||
760 | $id = (int) $e[0]; | |
761 | $unread = bool_to_sql_bool((bool) $e[1]); | |
5b8444d3 AD |
762 | $marked = (bool)$e[2]; |
763 | ||
764 | if ($marked) { | |
765 | $marked = bool_to_sql_bool($marked); | |
766 | $marked_qpart = "marked = $marked,"; | |
767 | } | |
badac687 | 768 | |
badac687 | 769 | $query = "UPDATE ttrss_user_entries SET |
5b8444d3 | 770 | $marked_qpart |
badac687 AD |
771 | unread = $unread, |
772 | last_read = '$last_online' | |
773 | WHERE ref_id = '$id' AND | |
774 | (last_read IS NULL OR last_read < '$last_online') AND | |
775 | owner_uid = ".$_SESSION["uid"]; | |
776 | ||
777 | $result = db_query($link, $query); | |
778 | ||
492a4a6a | 779 | print "<sync-ok id=\"$id\"/>"; |
badac687 AD |
780 | |
781 | } | |
782 | } | |
7f4f9f4e AD |
783 | |
784 | /* Maybe we need to further update local DB for this client */ | |
785 | ||
492a4a6a | 786 | $query = "SELECT ref_id,unread,marked FROM ttrss_user_entries |
7f4f9f4e | 787 | WHERE last_read >= '$last_online' AND |
e6c611c5 | 788 | owner_uid = ".$_SESSION["uid"] . " LIMIT 1000"; |
7f4f9f4e AD |
789 | |
790 | $result = db_query($link, $query); | |
791 | ||
792 | while ($line = db_fetch_assoc($result)) { | |
492a4a6a AD |
793 | $unread = (int) sql_bool_to_bool($line["unread"]); |
794 | $marked = (int) sql_bool_to_bool($line["marked"]); | |
795 | ||
796 | print "<sync-ok unread=\"$unread\" marked=\"$marked\" | |
797 | id=\"".$line["ref_id"]."\"/>"; | |
7f4f9f4e AD |
798 | } |
799 | ||
badac687 AD |
800 | } |
801 | } | |
802 | ||
803 | print "</sync>"; | |
804 | ||
87b16a0a AD |
805 | if ($stage == 0) { |
806 | print "<feeds>"; | |
807 | ||
d8781c91 | 808 | $result = db_query($link, "SELECT id, title, cat_id FROM |
117335bf | 809 | ttrss_feeds WHERE owner_uid = ".$_SESSION["uid"]); |
87b16a0a AD |
810 | |
811 | while ($line = db_fetch_assoc($result)) { | |
36f78797 AD |
812 | |
813 | $has_icon = (int) feed_has_icon($line["id"]); | |
814 | ||
d8781c91 AD |
815 | print "<feed has_icon=\"$has_icon\" |
816 | cat_id=\"".(int)$line["cat_id"]."\" id=\"".$line["id"]."\"><![CDATA["; | |
87b16a0a AD |
817 | print $line["title"]; |
818 | print "]]></feed>"; | |
819 | } | |
820 | ||
821 | print "</feeds>"; | |
822 | ||
d8781c91 AD |
823 | print "<feed-categories>"; |
824 | ||
75aa83ec | 825 | $result = db_query($link, "SELECT id, title, collapsed FROM |
d8781c91 AD |
826 | ttrss_feed_categories WHERE owner_uid = ".$_SESSION["uid"]); |
827 | ||
75aa83ec | 828 | print "<category id=\"0\" collapsed=\"". |
57937c42 | 829 | (int)get_pref($link, "_COLLAPSED_UNCAT")."\"><![CDATA["; |
d8781c91 AD |
830 | print __("Uncategorized"); |
831 | print "]]></category>"; | |
832 | ||
d6416405 | 833 | print "<category id=\"-1\" collapsed=\"". |
57937c42 | 834 | (int)get_pref($link, "_COLLAPSED_SPECIAL")."\"><![CDATA["; |
d6416405 AD |
835 | print __("Special"); |
836 | print "]]></category>"; | |
837 | ||
c2726c96 | 838 | print "<category id=\"-2\" collapsed=\"". |
57937c42 | 839 | (int)get_pref($link, "_COLLAPSED_LABELS")."\"><![CDATA["; |
c2726c96 AD |
840 | print __("Labels"); |
841 | print "]]></category>"; | |
842 | ||
d8781c91 | 843 | while ($line = db_fetch_assoc($result)) { |
75aa83ec AD |
844 | print "<category |
845 | id=\"".$line["id"]."\" | |
846 | collapsed=\"".(int)sql_bool_to_bool($line["collapsed"])."\"><![CDATA["; | |
d8781c91 AD |
847 | print $line["title"]; |
848 | print "]]></category>"; | |
849 | } | |
850 | ||
851 | print "</feed-categories>"; | |
852 | ||
ed22888b AD |
853 | print "<labels>"; |
854 | ||
855 | $result = db_query($link, "SELECT * FROM | |
856 | ttrss_labels2 WHERE owner_uid = ".$_SESSION["uid"]); | |
857 | ||
858 | while ($line = db_fetch_assoc($result)) { | |
859 | print "<label | |
860 | id=\"".$line["id"]."\" | |
861 | fg_color=\"".$line["fg_color"]."\" | |
862 | bg_color=\"".$line["bg_color"]."\" | |
863 | ><![CDATA["; | |
864 | print $line["caption"]; | |
865 | print "]]></label>"; | |
866 | } | |
867 | ||
868 | ||
869 | print "</labels>"; | |
d8781c91 | 870 | |
87b16a0a AD |
871 | } |
872 | ||
6a1cd591 | 873 | if ($stage > 0) { |
6a1cd591 AD |
874 | print "<articles>"; |
875 | ||
d9447516 | 876 | $limit = 10; |
6a1cd591 AD |
877 | $skip = $limit*($stage-1); |
878 | ||
3e52ab08 AD |
879 | print "<limit value=\"$limit\"/>"; |
880 | ||
6a1cd591 AD |
881 | if ($amount > 0) $amount -= $skip; |
882 | ||
883 | if ($amount > 0) { | |
884 | ||
885 | $limit = min($limit, $amount); | |
886 | ||
887 | if ($unread_only) { | |
a400a562 | 888 | $unread_qpart = "(unread = true OR marked = true) AND "; |
6a1cd591 AD |
889 | } |
890 | ||
67eb2531 | 891 | if ($cidt && $cidb) { |
04870193 | 892 | $cid_qpart = "(ttrss_entries.id > $cidt OR ttrss_entries.id < $cidb) AND "; |
95f0c2c5 AD |
893 | } |
894 | ||
67eb2531 | 895 | if (DB_TYPE == "pgsql") { |
d9447516 | 896 | $date_qpart = "updated >= NOW() - INTERVAL '1 week' AND"; |
67eb2531 | 897 | } else { |
d9447516 | 898 | $date_qpart = "updated >= DATE_SUB(NOW(), INTERVAL 1 WEEK) AND"; |
67eb2531 AD |
899 | } |
900 | ||
6a1cd591 | 901 | $result = db_query($link, |
c1a0541a AD |
902 | "SELECT DISTINCT ttrss_entries.id,ttrss_entries.title, |
903 | guid,link,comments, | |
904 | feed_id,content,updated,unread,marked FROM | |
905 | ttrss_user_entries,ttrss_entries,ttrss_feeds | |
906 | WHERE $unread_qpart $cid_qpart $date_qpart | |
c1a0541a AD |
907 | ttrss_feeds.id = feed_id AND |
908 | ref_id = ttrss_entries.id AND | |
909 | ttrss_user_entries.owner_uid = ".$_SESSION["uid"]." | |
6a1cd591 | 910 | ORDER BY updated DESC LIMIT $limit OFFSET $skip"); |
fe8f2f0c | 911 | |
3034277a | 912 | if (function_exists('json_encode')) { |
6a2034f9 | 913 | |
3034277a AD |
914 | while ($line = db_fetch_assoc($result)) { |
915 | print "<article><![CDATA["; | |
916 | ||
917 | $line["marked"] = (int)sql_bool_to_bool($line["marked"]); | |
918 | $line["unread"] = (int)sql_bool_to_bool($line["unread"]); | |
3ab18266 | 919 | |
c2726c96 AD |
920 | $line["labels"] = get_article_labels($link, $line["id"]); |
921 | ||
3ab18266 AD |
922 | // too slow :( |
923 | // $line["tags"] = format_tags_string( | |
924 | // get_article_tags($link, $line["id"]), $line["id"]); | |
3034277a AD |
925 | |
926 | print json_encode($line); | |
927 | print "]]></article>"; | |
928 | } | |
6a1cd591 AD |
929 | } |
930 | ||
931 | } | |
932 | ||
933 | print "</articles>"; | |
934 | ||
935 | } | |
936 | ||
87b16a0a AD |
937 | print "</rpc-reply>"; |
938 | ||
939 | return; | |
940 | } | |
941 | ||
d8ea9902 AD |
942 | if ($subop == "digest-get-contents") { |
943 | $article_id = db_escape_string($_REQUEST['article_id']); | |
944 | ||
945 | $result = db_query($link, "SELECT content | |
946 | FROM ttrss_entries, ttrss_user_entries | |
947 | WHERE id = '$article_id' AND ref_id = id AND owner_uid = ".$_SESSION['uid']); | |
948 | ||
949 | print "<rpc-reply>"; | |
950 | ||
951 | print "<article id=\"$article_id\"><![CDATA["; | |
952 | ||
953 | $content = sanitize_rss($link, db_fetch_result($result, 0, "content")); | |
954 | ||
955 | print $content; | |
956 | ||
957 | print "]]></article>"; | |
958 | ||
959 | print "</rpc-reply>"; | |
960 | ||
961 | return; | |
962 | } | |
963 | ||
1ca8997b | 964 | if ($subop == "digest-update") { |
b41c2549 | 965 | $feed_id = db_escape_string($_REQUEST['feed_id']); |
1ca8997b | 966 | $offset = db_escape_string($_REQUEST['offset']); |
e4c530dc | 967 | $seq = db_escape_string($_REQUEST['seq']); |
1ca8997b | 968 | |
b41c2549 | 969 | if (!$feed_id) $feed_id = -4; |
1ca8997b | 970 | if (!$offset) $offset = 0; |
1ca8997b AD |
971 | print "<rpc-reply>"; |
972 | ||
e4c530dc AD |
973 | print "<seq>$seq</seq>"; |
974 | ||
1ca8997b | 975 | $headlines = api_get_headlines($link, $feed_id, 10, $offset, |
d8ea9902 | 976 | '', ($feed_id == -4), true, false, "unread", "updated DESC"); |
1ca8997b AD |
977 | |
978 | //function api_get_headlines($link, $feed_id, $limit, $offset, | |
979 | // $filter, $is_cat, $show_excerpt, $show_content, $view_mode) { | |
980 | ||
78ac6caf AD |
981 | print "<headlines-title><![CDATA[" . getFeedTitle($link, $feed_id) . |
982 | "]]></headlines-title>"; | |
983 | ||
1ca8997b AD |
984 | print "<headlines><![CDATA[" . json_encode($headlines) . "]]></headlines>"; |
985 | ||
986 | print "</rpc-reply>"; | |
987 | return; | |
988 | } | |
989 | ||
990 | if ($subop == "digest-init") { | |
911d4c08 AD |
991 | print "<rpc-reply>"; |
992 | ||
993 | $tmp_feeds = api_get_feeds($link, false, true, false, 0); | |
994 | $feeds = array(); | |
995 | ||
996 | foreach ($tmp_feeds as $f) { | |
b41c2549 | 997 | if ($f['id'] > 0 || $f['id'] == -4) array_push($feeds, $f); |
911d4c08 AD |
998 | } |
999 | ||
911d4c08 AD |
1000 | print "<feeds><![CDATA[" . json_encode($feeds) . "]]></feeds>"; |
1001 | ||
911d4c08 AD |
1002 | print "</rpc-reply>"; |
1003 | return; | |
1004 | } | |
1005 | ||
c1b5cd23 AD |
1006 | if ($subop == "catchupFeed") { |
1007 | ||
1008 | $feed_id = db_escape_string($_REQUEST['feed_id']); | |
1009 | $is_cat = db_escape_string($_REQUEST['is_cat']); | |
1010 | ||
1011 | print "<rpc-reply>"; | |
1012 | ||
1013 | catchup_feed($link, $feed_id, $is_cat); | |
1014 | ||
1015 | print "</rpc-reply>"; | |
1016 | ||
1017 | return; | |
1018 | } | |
1019 | ||
85bd574b | 1020 | print "<rpc-reply><error>Unknown method: $subop</error></rpc-reply>"; |
01b3e191 AD |
1021 | } |
1022 | ?> |