]>
Commit | Line | Data |
---|---|---|
1d3a17c7 | 1 | <?php |
01b3e191 AD |
2 | function handle_rpc_request($link) { |
3 | ||
b4e75b2a | 4 | $subop = $_REQUEST["subop"]; |
01b3e191 AD |
5 | |
6 | if ($subop == "setpref") { | |
7 | if (WEB_DEMO_MODE) { | |
8 | return; | |
9 | } | |
10 | ||
11 | print "<rpc-reply>"; | |
12 | ||
b4e75b2a AD |
13 | $key = db_escape_string($_REQUEST["key"]); |
14 | $value = db_escape_string($_REQUEST["value"]); | |
01b3e191 AD |
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 | ||
01b3e191 | 25 | if ($subop == "getAllCounters") { |
cf4d339c | 26 | print "<rpc-reply>"; |
f54f515f | 27 | print "<counters>"; |
cf4d339c | 28 | |
b4e75b2a | 29 | $omode = $_REQUEST["omode"]; |
cf4d339c AD |
30 | |
31 | getAllCounters($link, $omode); | |
f54f515f AD |
32 | print "</counters>"; |
33 | print_runtime_info($link); | |
01b3e191 | 34 | print "</rpc-reply>"; |
85bd574b AD |
35 | |
36 | return; | |
01b3e191 AD |
37 | } |
38 | ||
39 | if ($subop == "mark") { | |
b4e75b2a AD |
40 | $mark = $_REQUEST["mark"]; |
41 | $id = db_escape_string($_REQUEST["id"]); | |
01b3e191 AD |
42 | |
43 | if ($mark == "1") { | |
44 | $mark = "true"; | |
45 | } else { | |
46 | $mark = "false"; | |
47 | } | |
48 | ||
49 | // FIXME this needs collision testing | |
50 | ||
51 | $result = db_query($link, "UPDATE ttrss_user_entries SET marked = $mark | |
52 | WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]); | |
49aa6de9 | 53 | |
36e05046 AD |
54 | print "<rpc-reply><counters>"; |
55 | getGlobalCounters($link); | |
0a6e5382 | 56 | getVirtCounters($link); |
36e05046 AD |
57 | getLabelCounters($link); |
58 | if (get_pref($link, 'ENABLE_FEED_CATS')) { | |
59 | getCategoryCounters($link); | |
60 | } | |
61 | print "</counters></rpc-reply>"; | |
49aa6de9 | 62 | |
85bd574b | 63 | return; |
01b3e191 AD |
64 | } |
65 | ||
e04c18a2 | 66 | if ($subop == "delete") { |
b4e75b2a | 67 | $ids = db_escape_string($_REQUEST["ids"]); |
e04c18a2 AD |
68 | |
69 | $result = db_query($link, "DELETE FROM ttrss_user_entries | |
70 | WHERE ref_id IN ($ids) AND owner_uid = " . $_SESSION["uid"]); | |
71 | ||
72 | print "<rpc-reply><counters>"; | |
73 | getGlobalCounters($link); | |
0a6e5382 | 74 | getVirtCounters($link); |
e04c18a2 AD |
75 | if (get_pref($link, 'ENABLE_FEED_CATS')) { |
76 | getCategoryCounters($link); | |
77 | } | |
78 | print "</counters></rpc-reply>"; | |
79 | ||
80 | return; | |
81 | } | |
82 | ||
83 | if ($subop == "unarchive") { | |
b4e75b2a | 84 | $ids = db_escape_string($_REQUEST["ids"]); |
e04c18a2 AD |
85 | |
86 | $result = db_query($link, "UPDATE ttrss_user_entries | |
ef83538d | 87 | SET feed_id = orig_feed_id, orig_feed_id = NULL |
e04c18a2 AD |
88 | WHERE ref_id IN ($ids) AND owner_uid = " . $_SESSION["uid"]); |
89 | ||
90 | print "<rpc-reply><counters>"; | |
91 | getGlobalCounters($link); | |
0a6e5382 | 92 | getVirtCounters($link); |
e04c18a2 AD |
93 | if (get_pref($link, 'ENABLE_FEED_CATS')) { |
94 | getCategoryCounters($link); | |
95 | } | |
96 | print "</counters></rpc-reply>"; | |
97 | ||
98 | return; | |
99 | } | |
100 | ||
101 | if ($subop == "archive") { | |
b4e75b2a | 102 | $ids = split(",", db_escape_string($_REQUEST["ids"])); |
e04c18a2 | 103 | |
16fdac16 AD |
104 | foreach ($ids as $id) { |
105 | archive_article($link, $id, $_SESSION["uid"]); | |
106 | } | |
e04c18a2 AD |
107 | |
108 | print "<rpc-reply><counters>"; | |
109 | getGlobalCounters($link); | |
0a6e5382 | 110 | getVirtCounters($link); |
e04c18a2 AD |
111 | if (get_pref($link, 'ENABLE_FEED_CATS')) { |
112 | getCategoryCounters($link); | |
113 | } | |
114 | print "</counters></rpc-reply>"; | |
115 | ||
116 | return; | |
117 | } | |
118 | ||
119 | ||
e4f4b46f | 120 | if ($subop == "publ") { |
c7e51de1 AD |
121 | $pub = $_REQUEST["pub"]; |
122 | $id = db_escape_string($_REQUEST["id"]); | |
123 | $note = trim(strip_tags(db_escape_string($_REQUEST["note"]))); | |
e4f4b46f AD |
124 | |
125 | if ($pub == "1") { | |
0a8011eb | 126 | $pub = "true"; |
e4f4b46f AD |
127 | } else { |
128 | $pub = "false"; | |
129 | } | |
130 | ||
c7e51de1 AD |
131 | if ($note != 'undefined') { |
132 | $note_qpart = "note = '$note',"; | |
133 | } | |
134 | ||
e4f4b46f AD |
135 | // FIXME this needs collision testing |
136 | ||
c7e51de1 AD |
137 | $result = db_query($link, "UPDATE ttrss_user_entries SET |
138 | $note_qpart | |
139 | published = $pub | |
e4f4b46f | 140 | WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]); |
49aa6de9 | 141 | |
c7e51de1 AD |
142 | |
143 | print "<rpc-reply>"; | |
144 | ||
145 | print "<counters>"; | |
36e05046 | 146 | getGlobalCounters($link); |
0a6e5382 | 147 | getVirtCounters($link); |
36e05046 AD |
148 | getLabelCounters($link); |
149 | if (get_pref($link, 'ENABLE_FEED_CATS')) { | |
150 | getCategoryCounters($link); | |
151 | } | |
c7e51de1 AD |
152 | print "</counters>"; |
153 | ||
154 | if ($note != 'undefined') { | |
155 | $note_size = strlen($note); | |
156 | print "<note id=\"$id\" size=\"$note_size\">"; | |
157 | print "<![CDATA[" . format_article_note($id, $note) . "]]>"; | |
158 | print "</note>"; | |
159 | } | |
160 | ||
161 | print "</rpc-reply>"; | |
49aa6de9 | 162 | |
85bd574b | 163 | return; |
e4f4b46f AD |
164 | } |
165 | ||
01b3e191 | 166 | if ($subop == "updateFeed") { |
b4e75b2a | 167 | $feed_id = db_escape_string($_REQUEST["feed"]); |
01b3e191 AD |
168 | |
169 | $result = db_query($link, | |
170 | "SELECT feed_url FROM ttrss_feeds WHERE id = '$feed_id' | |
171 | AND owner_uid = " . $_SESSION["uid"]); | |
172 | ||
173 | if (db_num_rows($result) > 0) { | |
174 | $feed_url = db_fetch_result($result, 0, "feed_url"); | |
175 | update_rss_feed($link, $feed_url, $feed_id); | |
176 | } | |
177 | ||
f54f515f AD |
178 | print "<rpc-reply>"; |
179 | print "<counters>"; | |
01b3e191 | 180 | getFeedCounter($link, $feed_id); |
f54f515f | 181 | print "</counters>"; |
01b3e191 AD |
182 | print "</rpc-reply>"; |
183 | ||
184 | return; | |
185 | } | |
186 | ||
187 | if ($subop == "forceUpdateAllFeeds" || $subop == "updateAllFeeds") { | |
188 | ||
b4e75b2a | 189 | $global_unread_caller = sprintf("%d", $_REQUEST["uctr"]); |
01b3e191 AD |
190 | $global_unread = getGlobalUnread($link); |
191 | ||
192 | print "<rpc-reply>"; | |
193 | ||
f54f515f AD |
194 | print "<counters>"; |
195 | ||
a06d0e5a | 196 | if ($global_unread_caller != $global_unread) { |
1341ea0d | 197 | |
b4e75b2a | 198 | $omode = $_REQUEST["omode"]; |
a06d0e5a AD |
199 | |
200 | if (!$omode) $omode = "tflc"; | |
1341ea0d | 201 | |
0a6e5382 AD |
202 | getVirtCounters($link); |
203 | ||
a06d0e5a | 204 | if (strchr($omode, "l")) getLabelCounters($link); |
1341ea0d | 205 | |
a06d0e5a AD |
206 | if (strchr($omode, "c")) { |
207 | if (get_pref($link, 'ENABLE_FEED_CATS')) { | |
208 | getCategoryCounters($link); | |
209 | } | |
210 | } | |
01b3e191 | 211 | |
01b3e191 | 212 | if (strchr($omode, "f")) getFeedCounters($link); |
a06d0e5a | 213 | if (strchr($omode, "t")) getTagCounters($link); |
01b3e191 | 214 | |
a06d0e5a AD |
215 | getGlobalCounters($link, $global_unread); |
216 | } | |
217 | ||
f54f515f AD |
218 | print "</counters>"; |
219 | ||
220 | print_runtime_info($link); | |
221 | ||
01b3e191 AD |
222 | print "</rpc-reply>"; |
223 | ||
85bd574b | 224 | return; |
01b3e191 | 225 | } |
472782e8 | 226 | |
01b3e191 AD |
227 | /* GET["cmode"] = 0 - mark as read, 1 - as unread, 2 - toggle */ |
228 | if ($subop == "catchupSelected") { | |
229 | ||
2855ee88 AD |
230 | $ids = split(",", db_escape_string($_REQUEST["ids"])); |
231 | $cmode = sprintf("%d", $_REQUEST["cmode"]); | |
01b3e191 | 232 | |
472782e8 | 233 | catchupArticlesById($link, $ids, $cmode); |
01b3e191 | 234 | |
01b3e191 | 235 | print "<rpc-reply>"; |
f54f515f | 236 | print "<counters>"; |
b4e75b2a | 237 | getAllCounters($link, $_REQUEST["omode"]); |
f54f515f AD |
238 | print "</counters>"; |
239 | print_runtime_info($link); | |
01b3e191 | 240 | print "</rpc-reply>"; |
85bd574b AD |
241 | |
242 | return; | |
01b3e191 AD |
243 | } |
244 | ||
245 | if ($subop == "markSelected") { | |
246 | ||
b4e75b2a AD |
247 | $ids = split(",", db_escape_string($_REQUEST["ids"])); |
248 | $cmode = sprintf("%d", $_REQUEST["cmode"]); | |
01b3e191 | 249 | |
18eddb2c AD |
250 | markArticlesById($link, $ids, $cmode); |
251 | ||
01b3e191 | 252 | print "<rpc-reply>"; |
f54f515f | 253 | print "<counters>"; |
b4e75b2a | 254 | getAllCounters($link, $_REQUEST["omode"]); |
f54f515f AD |
255 | print "</counters>"; |
256 | print_runtime_info($link); | |
01b3e191 | 257 | print "</rpc-reply>"; |
85bd574b AD |
258 | |
259 | return; | |
01b3e191 AD |
260 | } |
261 | ||
e4f4b46f AD |
262 | if ($subop == "publishSelected") { |
263 | ||
b4e75b2a AD |
264 | $ids = split(",", db_escape_string($_REQUEST["ids"])); |
265 | $cmode = sprintf("%d", $_REQUEST["cmode"]); | |
e4f4b46f AD |
266 | |
267 | publishArticlesById($link, $ids, $cmode); | |
268 | ||
269 | print "<rpc-reply>"; | |
270 | print "<counters>"; | |
b4e75b2a | 271 | getAllCounters($link, $_REQUEST["omode"]); |
e4f4b46f AD |
272 | print "</counters>"; |
273 | print_runtime_info($link); | |
274 | print "</rpc-reply>"; | |
85bd574b AD |
275 | |
276 | return; | |
e4f4b46f AD |
277 | } |
278 | ||
01b3e191 | 279 | if ($subop == "sanityCheck") { |
3ac2b520 | 280 | print "<rpc-reply>"; |
01b3e191 AD |
281 | if (sanity_check($link)) { |
282 | print "<error error-code=\"0\"/>"; | |
3ac2b520 | 283 | print_init_params($link); |
f54f515f | 284 | print_runtime_info($link); |
4220d6b0 AD |
285 | |
286 | # assign client-passed params to session | |
b4e75b2a | 287 | $_SESSION["client.userAgent"] = $_REQUEST["ua"]; |
4220d6b0 | 288 | |
01b3e191 | 289 | } |
3ac2b520 | 290 | print "</rpc-reply>"; |
85bd574b AD |
291 | |
292 | return; | |
3ac2b520 | 293 | } |
01b3e191 AD |
294 | |
295 | if ($subop == "globalPurge") { | |
296 | ||
297 | print "<rpc-reply>"; | |
298 | global_purge_old_posts($link, true); | |
299 | print "</rpc-reply>"; | |
300 | ||
85bd574b | 301 | return; |
01b3e191 | 302 | } |
3ac2b520 | 303 | |
298f3f78 AD |
304 | if ($subop == "getArticleLink") { |
305 | ||
b4e75b2a | 306 | $id = db_escape_string($_REQUEST["id"]); |
298f3f78 AD |
307 | |
308 | $result = db_query($link, "SELECT link FROM ttrss_entries, ttrss_user_entries | |
309 | WHERE id = '$id' AND id = ref_id AND owner_uid = '".$_SESSION['uid']."'"); | |
310 | ||
311 | if (db_num_rows($result) == 1) { | |
06925d9e | 312 | $link = htmlspecialchars(strip_tags(db_fetch_result($result, 0, "link"))); |
e2ccbfab | 313 | print "<rpc-reply><link>$link</link><id>$id</id></rpc-reply>"; |
298f3f78 AD |
314 | } else { |
315 | print "<rpc-reply><error>Article not found</error></rpc-reply>"; | |
316 | } | |
85bd574b AD |
317 | |
318 | return; | |
298f3f78 AD |
319 | } |
320 | ||
0b126ac2 | 321 | if ($subop == "setArticleTags") { |
14b6c54b | 322 | |
b4e75b2a | 323 | $id = db_escape_string($_REQUEST["id"]); |
14b6c54b | 324 | |
b4e75b2a | 325 | $tags_str = db_escape_string($_REQUEST["tags_str"]); |
0b126ac2 | 326 | |
d62a3b63 | 327 | $tags = array_unique(trim_array(split(",", $tags_str))); |
0b126ac2 AD |
328 | |
329 | db_query($link, "BEGIN"); | |
330 | ||
331 | $result = db_query($link, "SELECT int_id FROM ttrss_user_entries WHERE | |
332 | ref_id = '$id' AND owner_uid = '".$_SESSION["uid"]."' LIMIT 1"); | |
333 | ||
334 | if (db_num_rows($result) == 1) { | |
335 | ||
336 | $int_id = db_fetch_result($result, 0, "int_id"); | |
337 | ||
338 | db_query($link, "DELETE FROM ttrss_tags WHERE | |
339 | post_int_id = $int_id AND owner_uid = '".$_SESSION["uid"]."'"); | |
340 | ||
341 | foreach ($tags as $tag) { | |
14b6c54b | 342 | $tag = sanitize_tag($tag); |
0b126ac2 | 343 | |
ef063748 AD |
344 | if (!tag_is_valid($tag)) { |
345 | continue; | |
346 | } | |
347 | ||
0b126ac2 AD |
348 | if (preg_match("/^[0-9]*$/", $tag)) { |
349 | continue; | |
350 | } | |
14b6c54b | 351 | |
307d187c | 352 | // print "<!-- $id : $int_id : $tag -->"; |
0b126ac2 AD |
353 | |
354 | if ($tag != '') { | |
355 | db_query($link, "INSERT INTO ttrss_tags | |
356 | (post_int_id, owner_uid, tag_name) VALUES ('$int_id', '".$_SESSION["uid"]."', '$tag')"); | |
357 | } | |
358 | } | |
359 | } | |
360 | ||
361 | db_query($link, "COMMIT"); | |
362 | ||
307d187c AD |
363 | $tags_str = format_tags_string(get_article_tags($link, $id), $id); |
364 | ||
0b126ac2 | 365 | print "<rpc-reply> |
307d187c | 366 | <tags-str id=\"$id\"><![CDATA[$tags_str]]></tags-str> |
0b126ac2 AD |
367 | </rpc-reply>"; |
368 | ||
85bd574b | 369 | return; |
0b126ac2 | 370 | } |
01a87dff | 371 | |
945c243e AD |
372 | if ($subop == "regenPubKey") { |
373 | ||
374 | print "<rpc-reply>"; | |
375 | ||
376 | set_pref($link, "_PREFS_PUBLISH_KEY", generate_publish_key()); | |
945c243e | 377 | |
f56e3080 | 378 | $new_link = article_publish_url($link); |
945c243e AD |
379 | |
380 | print "<link><![CDATA[$new_link]]></link>"; | |
381 | ||
382 | print "</rpc-reply>"; | |
383 | ||
85bd574b | 384 | return; |
945c243e AD |
385 | } |
386 | ||
01a87dff AD |
387 | if ($subop == "logout") { |
388 | logout_user(); | |
389 | print_error_xml(6); | |
85bd574b | 390 | return; |
01a87dff AD |
391 | } |
392 | ||
05fcdf52 AD |
393 | if ($subop == "completeTags") { |
394 | ||
395 | $search = db_escape_string($_REQUEST["search"]); | |
396 | ||
397 | $result = db_query($link, "SELECT DISTINCT tag_name FROM ttrss_tags | |
398 | WHERE owner_uid = '".$_SESSION["uid"]."' AND | |
399 | tag_name LIKE '$search%' ORDER BY tag_name | |
400 | LIMIT 10"); | |
401 | ||
402 | print "<ul>"; | |
403 | while ($line = db_fetch_assoc($result)) { | |
404 | print "<li>" . $line["tag_name"] . "</li>"; | |
405 | } | |
406 | print "</ul>"; | |
407 | ||
85bd574b | 408 | return; |
05fcdf52 AD |
409 | } |
410 | ||
81cd6cac | 411 | if ($subop == "purge") { |
b4e75b2a AD |
412 | $ids = split(",", db_escape_string($_REQUEST["ids"])); |
413 | $days = sprintf("%d", $_REQUEST["days"]); | |
81cd6cac AD |
414 | |
415 | print "<rpc-reply>"; | |
416 | ||
417 | print "<message><![CDATA["; | |
418 | ||
419 | foreach ($ids as $id) { | |
420 | ||
421 | $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE | |
422 | id = '$id' AND owner_uid = ".$_SESSION["uid"]); | |
423 | ||
424 | if (db_num_rows($result) == 1) { | |
425 | purge_feed($link, $id, $days, true); | |
426 | } | |
427 | } | |
428 | ||
429 | print "]]></message>"; | |
430 | ||
431 | print "</rpc-reply>"; | |
432 | ||
433 | return; | |
434 | } | |
435 | ||
9bf3f101 | 436 | /* if ($subop == "setScore") { |
546499a9 AD |
437 | $id = db_escape_string($_REQUEST["id"]); |
438 | $score = sprintf("%d", $_REQUEST["score"]); | |
439 | ||
440 | $result = db_query($link, "UPDATE ttrss_user_entries SET score = '$score' | |
441 | WHERE ref_id = '$id' AND owner_uid = ".$_SESSION["uid"]); | |
442 | ||
443 | print "<rpc-reply><message>Acknowledged.</message></rpc-reply>"; | |
444 | ||
445 | return; | |
446 | ||
9bf3f101 | 447 | } */ |
546499a9 | 448 | |
aa0fa9df AD |
449 | if ($subop == "getArticles") { |
450 | $ids = split(",", db_escape_string($_REQUEST["ids"])); | |
451 | ||
452 | print "<rpc-reply>"; | |
453 | ||
454 | foreach ($ids as $id) { | |
455 | if ($id) { | |
456 | outputArticleXML($link, $id, 0, false); | |
457 | } | |
458 | } | |
459 | print "</rpc-reply>"; | |
460 | ||
461 | return; | |
462 | } | |
463 | ||
d0da85c2 AD |
464 | if ($subop == "checkDate") { |
465 | ||
466 | $date = db_escape_string($_REQUEST["date"]); | |
467 | $date_parsed = strtotime($date); | |
468 | ||
469 | print "<rpc-reply>"; | |
470 | ||
471 | if ($date_parsed) { | |
472 | print "<result>1</result>"; | |
473 | } else { | |
474 | print "<result>0</result>"; | |
475 | } | |
476 | ||
477 | print "</rpc-reply>"; | |
478 | ||
479 | return; | |
480 | } | |
481 | ||
933ba4ee AD |
482 | if ($subop == "removeFromLabel") { |
483 | ||
484 | $ids = split(",", db_escape_string($_REQUEST["ids"])); | |
485 | $label_id = db_escape_string($_REQUEST["lid"]); | |
486 | ||
7a13338b AD |
487 | $label = db_escape_string(label_find_caption($link, $label_id, |
488 | $_SESSION["uid"])); | |
933ba4ee | 489 | |
1c9c6025 AD |
490 | print "<rpc-reply>"; |
491 | print "<info-for-headlines>"; | |
492 | ||
933ba4ee AD |
493 | if ($label) { |
494 | ||
495 | foreach ($ids as $id) { | |
496 | label_remove_article($link, $id, $label, $_SESSION["uid"]); | |
1c9c6025 AD |
497 | |
498 | print "<entry id=\"$id\"><![CDATA["; | |
499 | ||
500 | $labels = get_article_labels($link, $id, $_SESSION["uid"]); | |
2eb9c95c | 501 | print format_article_labels($labels, $id); |
1c9c6025 AD |
502 | |
503 | print "]]></entry>"; | |
504 | ||
933ba4ee AD |
505 | } |
506 | } | |
507 | ||
1c9c6025 AD |
508 | print "</info-for-headlines>"; |
509 | ||
510 | print "<counters>"; | |
511 | getAllCounters($link, $omode); | |
512 | print "</counters>"; | |
513 | print "</rpc-reply>"; | |
933ba4ee AD |
514 | |
515 | return; | |
516 | } | |
517 | ||
b8a637f3 AD |
518 | if ($subop == "assignToLabel") { |
519 | ||
520 | $ids = split(",", db_escape_string($_REQUEST["ids"])); | |
521 | $label_id = db_escape_string($_REQUEST["lid"]); | |
522 | ||
7a13338b AD |
523 | $label = db_escape_string(label_find_caption($link, $label_id, |
524 | $_SESSION["uid"])); | |
b8a637f3 | 525 | |
f9247195 AD |
526 | print "<rpc-reply>"; |
527 | ||
528 | print "<info-for-headlines>"; | |
529 | ||
b8a637f3 AD |
530 | if ($label) { |
531 | ||
532 | foreach ($ids as $id) { | |
533 | label_add_article($link, $id, $label, $_SESSION["uid"]); | |
f9247195 AD |
534 | |
535 | print "<entry id=\"$id\"><![CDATA["; | |
536 | ||
537 | $labels = get_article_labels($link, $id, $_SESSION["uid"]); | |
2eb9c95c | 538 | print format_article_labels($labels, $id); |
f9247195 AD |
539 | |
540 | print "]]></entry>"; | |
541 | ||
b8a637f3 AD |
542 | } |
543 | } | |
544 | ||
f9247195 AD |
545 | print "</info-for-headlines>"; |
546 | ||
547 | print "<counters>"; | |
548 | getAllCounters($link, $omode); | |
549 | print "</counters>"; | |
550 | print "</rpc-reply>"; | |
b8a637f3 AD |
551 | |
552 | return; | |
553 | } | |
554 | ||
c2913898 AD |
555 | if ($subop == "feedBrowser") { |
556 | ||
557 | $search = db_escape_string($_REQUEST["search"]); | |
558 | $limit = db_escape_string($_REQUEST["limit"]); | |
082ae95b | 559 | $mode = db_escape_string($_REQUEST["mode"]); |
c2913898 AD |
560 | |
561 | print "<rpc-reply>"; | |
562 | print "<content>"; | |
563 | print "<![CDATA["; | |
082ae95b | 564 | $ctr = print_feed_browser($link, $search, $limit, $mode); |
c2913898 AD |
565 | print "]]>"; |
566 | print "</content>"; | |
567 | print "<num-results value=\"$ctr\"/>"; | |
568 | print "</rpc-reply>"; | |
569 | ||
570 | return; | |
571 | } | |
572 | ||
87b16a0a AD |
573 | if ($subop == "download") { |
574 | $stage = (int) $_REQUEST["stage"]; | |
04870193 AD |
575 | $cidt = (int)db_escape_string($_REQUEST["cidt"]); |
576 | $cidb = (int)db_escape_string($_REQUEST["cidb"]); | |
badac687 | 577 | $sync = db_escape_string($_REQUEST["sync"]); |
51f6f917 AD |
578 | //$amount = (int) $_REQUEST["amount"]; |
579 | //$unread_only = db_escape_string($_REQUEST["unread_only"]); | |
580 | //if (!$amount) $amount = 50; | |
6a1cd591 | 581 | |
d9447516 AD |
582 | /* Amount is not used by the frontend offline.js anymore, it goes by |
583 | * date_qpart below + cidb/cidt IDs */ | |
584 | ||
04870193 | 585 | $amount = 2000; |
51f6f917 | 586 | $unread_only = true; |
87b16a0a AD |
587 | |
588 | print "<rpc-reply>"; | |
589 | ||
badac687 AD |
590 | $sync = split(";", $sync); |
591 | ||
592 | print "<sync>"; | |
593 | ||
594 | if (count($sync) > 0) { | |
595 | if (strtotime($sync[0])) { | |
596 | $last_online = db_escape_string($sync[0]); | |
597 | ||
598 | print "<sync-point><![CDATA[$last_online]]></sync-point>"; | |
599 | ||
600 | for ($i = 1; $i < count($sync); $i++) { | |
601 | $e = split(",", $sync[$i]); | |
602 | ||
603 | if (count($e) == 3) { | |
604 | ||
605 | $id = (int) $e[0]; | |
606 | $unread = bool_to_sql_bool((bool) $e[1]); | |
5b8444d3 AD |
607 | $marked = (bool)$e[2]; |
608 | ||
609 | if ($marked) { | |
610 | $marked = bool_to_sql_bool($marked); | |
611 | $marked_qpart = "marked = $marked,"; | |
612 | } | |
badac687 | 613 | |
badac687 | 614 | $query = "UPDATE ttrss_user_entries SET |
5b8444d3 | 615 | $marked_qpart |
badac687 AD |
616 | unread = $unread, |
617 | last_read = '$last_online' | |
618 | WHERE ref_id = '$id' AND | |
619 | (last_read IS NULL OR last_read < '$last_online') AND | |
620 | owner_uid = ".$_SESSION["uid"]; | |
621 | ||
622 | $result = db_query($link, $query); | |
623 | ||
492a4a6a | 624 | print "<sync-ok id=\"$id\"/>"; |
badac687 AD |
625 | |
626 | } | |
627 | } | |
7f4f9f4e AD |
628 | |
629 | /* Maybe we need to further update local DB for this client */ | |
630 | ||
492a4a6a | 631 | $query = "SELECT ref_id,unread,marked FROM ttrss_user_entries |
7f4f9f4e | 632 | WHERE last_read >= '$last_online' AND |
e6c611c5 | 633 | owner_uid = ".$_SESSION["uid"] . " LIMIT 1000"; |
7f4f9f4e AD |
634 | |
635 | $result = db_query($link, $query); | |
636 | ||
637 | while ($line = db_fetch_assoc($result)) { | |
492a4a6a AD |
638 | $unread = (int) sql_bool_to_bool($line["unread"]); |
639 | $marked = (int) sql_bool_to_bool($line["marked"]); | |
640 | ||
641 | print "<sync-ok unread=\"$unread\" marked=\"$marked\" | |
642 | id=\"".$line["ref_id"]."\"/>"; | |
7f4f9f4e AD |
643 | } |
644 | ||
badac687 AD |
645 | } |
646 | } | |
647 | ||
648 | print "</sync>"; | |
649 | ||
87b16a0a AD |
650 | if ($stage == 0) { |
651 | print "<feeds>"; | |
652 | ||
d8781c91 | 653 | $result = db_query($link, "SELECT id, title, cat_id FROM |
117335bf | 654 | ttrss_feeds WHERE owner_uid = ".$_SESSION["uid"]); |
87b16a0a AD |
655 | |
656 | while ($line = db_fetch_assoc($result)) { | |
36f78797 AD |
657 | |
658 | $has_icon = (int) feed_has_icon($line["id"]); | |
659 | ||
d8781c91 AD |
660 | print "<feed has_icon=\"$has_icon\" |
661 | cat_id=\"".(int)$line["cat_id"]."\" id=\"".$line["id"]."\"><![CDATA["; | |
87b16a0a AD |
662 | print $line["title"]; |
663 | print "]]></feed>"; | |
664 | } | |
665 | ||
666 | print "</feeds>"; | |
667 | ||
d8781c91 AD |
668 | print "<feed-categories>"; |
669 | ||
75aa83ec | 670 | $result = db_query($link, "SELECT id, title, collapsed FROM |
d8781c91 AD |
671 | ttrss_feed_categories WHERE owner_uid = ".$_SESSION["uid"]); |
672 | ||
75aa83ec | 673 | print "<category id=\"0\" collapsed=\"". |
57937c42 | 674 | (int)get_pref($link, "_COLLAPSED_UNCAT")."\"><![CDATA["; |
d8781c91 AD |
675 | print __("Uncategorized"); |
676 | print "]]></category>"; | |
677 | ||
d6416405 | 678 | print "<category id=\"-1\" collapsed=\"". |
57937c42 | 679 | (int)get_pref($link, "_COLLAPSED_SPECIAL")."\"><![CDATA["; |
d6416405 AD |
680 | print __("Special"); |
681 | print "]]></category>"; | |
682 | ||
c2726c96 | 683 | print "<category id=\"-2\" collapsed=\"". |
57937c42 | 684 | (int)get_pref($link, "_COLLAPSED_LABELS")."\"><![CDATA["; |
c2726c96 AD |
685 | print __("Labels"); |
686 | print "]]></category>"; | |
687 | ||
d8781c91 | 688 | while ($line = db_fetch_assoc($result)) { |
75aa83ec AD |
689 | print "<category |
690 | id=\"".$line["id"]."\" | |
691 | collapsed=\"".(int)sql_bool_to_bool($line["collapsed"])."\"><![CDATA["; | |
d8781c91 AD |
692 | print $line["title"]; |
693 | print "]]></category>"; | |
694 | } | |
695 | ||
696 | print "</feed-categories>"; | |
697 | ||
ed22888b AD |
698 | print "<labels>"; |
699 | ||
700 | $result = db_query($link, "SELECT * FROM | |
701 | ttrss_labels2 WHERE owner_uid = ".$_SESSION["uid"]); | |
702 | ||
703 | while ($line = db_fetch_assoc($result)) { | |
704 | print "<label | |
705 | id=\"".$line["id"]."\" | |
706 | fg_color=\"".$line["fg_color"]."\" | |
707 | bg_color=\"".$line["bg_color"]."\" | |
708 | ><![CDATA["; | |
709 | print $line["caption"]; | |
710 | print "]]></label>"; | |
711 | } | |
712 | ||
713 | ||
714 | print "</labels>"; | |
d8781c91 | 715 | |
87b16a0a AD |
716 | } |
717 | ||
6a1cd591 | 718 | if ($stage > 0) { |
6a1cd591 AD |
719 | print "<articles>"; |
720 | ||
d9447516 | 721 | $limit = 10; |
6a1cd591 AD |
722 | $skip = $limit*($stage-1); |
723 | ||
3e52ab08 AD |
724 | print "<limit value=\"$limit\"/>"; |
725 | ||
6a1cd591 AD |
726 | if ($amount > 0) $amount -= $skip; |
727 | ||
728 | if ($amount > 0) { | |
729 | ||
730 | $limit = min($limit, $amount); | |
731 | ||
732 | if ($unread_only) { | |
a400a562 | 733 | $unread_qpart = "(unread = true OR marked = true) AND "; |
6a1cd591 AD |
734 | } |
735 | ||
67eb2531 | 736 | if ($cidt && $cidb) { |
04870193 | 737 | $cid_qpart = "(ttrss_entries.id > $cidt OR ttrss_entries.id < $cidb) AND "; |
95f0c2c5 AD |
738 | } |
739 | ||
67eb2531 | 740 | if (DB_TYPE == "pgsql") { |
d9447516 | 741 | $date_qpart = "updated >= NOW() - INTERVAL '1 week' AND"; |
67eb2531 | 742 | } else { |
d9447516 | 743 | $date_qpart = "updated >= DATE_SUB(NOW(), INTERVAL 1 WEEK) AND"; |
67eb2531 AD |
744 | } |
745 | ||
6a1cd591 | 746 | $result = db_query($link, |
c1a0541a AD |
747 | "SELECT DISTINCT ttrss_entries.id,ttrss_entries.title, |
748 | guid,link,comments, | |
749 | feed_id,content,updated,unread,marked FROM | |
750 | ttrss_user_entries,ttrss_entries,ttrss_feeds | |
751 | WHERE $unread_qpart $cid_qpart $date_qpart | |
c1a0541a AD |
752 | ttrss_feeds.id = feed_id AND |
753 | ref_id = ttrss_entries.id AND | |
754 | ttrss_user_entries.owner_uid = ".$_SESSION["uid"]." | |
6a1cd591 | 755 | ORDER BY updated DESC LIMIT $limit OFFSET $skip"); |
fe8f2f0c | 756 | |
3034277a | 757 | if (function_exists('json_encode')) { |
6a2034f9 | 758 | |
3034277a AD |
759 | while ($line = db_fetch_assoc($result)) { |
760 | print "<article><![CDATA["; | |
761 | ||
762 | $line["marked"] = (int)sql_bool_to_bool($line["marked"]); | |
763 | $line["unread"] = (int)sql_bool_to_bool($line["unread"]); | |
3ab18266 | 764 | |
c2726c96 AD |
765 | $line["labels"] = get_article_labels($link, $line["id"]); |
766 | ||
3ab18266 AD |
767 | // too slow :( |
768 | // $line["tags"] = format_tags_string( | |
769 | // get_article_tags($link, $line["id"]), $line["id"]); | |
3034277a AD |
770 | |
771 | print json_encode($line); | |
772 | print "]]></article>"; | |
773 | } | |
6a1cd591 AD |
774 | } |
775 | ||
776 | } | |
777 | ||
778 | print "</articles>"; | |
779 | ||
780 | } | |
781 | ||
87b16a0a AD |
782 | print "</rpc-reply>"; |
783 | ||
784 | return; | |
785 | } | |
786 | ||
85bd574b | 787 | print "<rpc-reply><error>Unknown method: $subop</error></rpc-reply>"; |
01b3e191 AD |
788 | } |
789 | ?> |