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