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