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