]> git.wh0rd.org - tt-rss.git/blame - modules/backend-rpc.php
obsolete cookie storage for collapsed status of feedlist and special categories ...
[tt-rss.git] / modules / backend-rpc.php
CommitLineData
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
2855ee88
AD
196 $ids = split(",", db_escape_string($_REQUEST["ids"]));
197 $cmode = sprintf("%d", $_REQUEST["cmode"]);
01b3e191 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
7a13338b
AD
453 $label = db_escape_string(label_find_caption($link, $label_id,
454 $_SESSION["uid"]));
933ba4ee 455
1c9c6025
AD
456 print "<rpc-reply>";
457 print "<info-for-headlines>";
458
933ba4ee
AD
459 if ($label) {
460
461 foreach ($ids as $id) {
462 label_remove_article($link, $id, $label, $_SESSION["uid"]);
1c9c6025
AD
463
464 print "<entry id=\"$id\"><![CDATA[";
465
466 $labels = get_article_labels($link, $id, $_SESSION["uid"]);
2eb9c95c 467 print format_article_labels($labels, $id);
1c9c6025
AD
468
469 print "]]></entry>";
470
933ba4ee
AD
471 }
472 }
473
1c9c6025
AD
474 print "</info-for-headlines>";
475
476 print "<counters>";
477 getAllCounters($link, $omode);
478 print "</counters>";
479 print "</rpc-reply>";
933ba4ee
AD
480
481 return;
482 }
483
b8a637f3
AD
484 if ($subop == "assignToLabel") {
485
486 $ids = split(",", db_escape_string($_REQUEST["ids"]));
487 $label_id = db_escape_string($_REQUEST["lid"]);
488
7a13338b
AD
489 $label = db_escape_string(label_find_caption($link, $label_id,
490 $_SESSION["uid"]));
b8a637f3 491
f9247195
AD
492 print "<rpc-reply>";
493
494 print "<info-for-headlines>";
495
b8a637f3
AD
496 if ($label) {
497
498 foreach ($ids as $id) {
499 label_add_article($link, $id, $label, $_SESSION["uid"]);
f9247195
AD
500
501 print "<entry id=\"$id\"><![CDATA[";
502
503 $labels = get_article_labels($link, $id, $_SESSION["uid"]);
2eb9c95c 504 print format_article_labels($labels, $id);
f9247195
AD
505
506 print "]]></entry>";
507
b8a637f3
AD
508 }
509 }
510
f9247195
AD
511 print "</info-for-headlines>";
512
513 print "<counters>";
514 getAllCounters($link, $omode);
515 print "</counters>";
516 print "</rpc-reply>";
b8a637f3
AD
517
518 return;
519 }
520
c2913898
AD
521 if ($subop == "feedBrowser") {
522
523 $search = db_escape_string($_REQUEST["search"]);
524 $limit = db_escape_string($_REQUEST["limit"]);
525
526 print "<rpc-reply>";
527 print "<content>";
528 print "<![CDATA[";
529 $ctr = print_feed_browser($link, $search, $limit);
530 print "]]>";
531 print "</content>";
532 print "<num-results value=\"$ctr\"/>";
533 print "</rpc-reply>";
534
535 return;
536 }
537
87b16a0a
AD
538 if ($subop == "download") {
539 $stage = (int) $_REQUEST["stage"];
04870193
AD
540 $cidt = (int)db_escape_string($_REQUEST["cidt"]);
541 $cidb = (int)db_escape_string($_REQUEST["cidb"]);
badac687 542 $sync = db_escape_string($_REQUEST["sync"]);
51f6f917
AD
543 //$amount = (int) $_REQUEST["amount"];
544 //$unread_only = db_escape_string($_REQUEST["unread_only"]);
545 //if (!$amount) $amount = 50;
6a1cd591 546
04870193 547 $amount = 2000;
51f6f917 548 $unread_only = true;
87b16a0a
AD
549
550 print "<rpc-reply>";
551
badac687
AD
552 $sync = split(";", $sync);
553
554 print "<sync>";
555
556 if (count($sync) > 0) {
557 if (strtotime($sync[0])) {
558 $last_online = db_escape_string($sync[0]);
559
560 print "<sync-point><![CDATA[$last_online]]></sync-point>";
561
562 for ($i = 1; $i < count($sync); $i++) {
563 $e = split(",", $sync[$i]);
564
565 if (count($e) == 3) {
566
567 $id = (int) $e[0];
568 $unread = bool_to_sql_bool((bool) $e[1]);
5b8444d3
AD
569 $marked = (bool)$e[2];
570
571 if ($marked) {
572 $marked = bool_to_sql_bool($marked);
573 $marked_qpart = "marked = $marked,";
574 }
badac687 575
badac687 576 $query = "UPDATE ttrss_user_entries SET
5b8444d3 577 $marked_qpart
badac687
AD
578 unread = $unread,
579 last_read = '$last_online'
580 WHERE ref_id = '$id' AND
581 (last_read IS NULL OR last_read < '$last_online') AND
582 owner_uid = ".$_SESSION["uid"];
583
584 $result = db_query($link, $query);
585
492a4a6a 586 print "<sync-ok id=\"$id\"/>";
badac687
AD
587
588 }
589 }
7f4f9f4e
AD
590
591 /* Maybe we need to further update local DB for this client */
592
492a4a6a 593 $query = "SELECT ref_id,unread,marked FROM ttrss_user_entries
7f4f9f4e 594 WHERE last_read >= '$last_online' AND
e6c611c5 595 owner_uid = ".$_SESSION["uid"] . " LIMIT 1000";
7f4f9f4e
AD
596
597 $result = db_query($link, $query);
598
599 while ($line = db_fetch_assoc($result)) {
492a4a6a
AD
600 $unread = (int) sql_bool_to_bool($line["unread"]);
601 $marked = (int) sql_bool_to_bool($line["marked"]);
602
603 print "<sync-ok unread=\"$unread\" marked=\"$marked\"
604 id=\"".$line["ref_id"]."\"/>";
7f4f9f4e
AD
605 }
606
badac687
AD
607 }
608 }
609
610 print "</sync>";
611
87b16a0a
AD
612 if ($stage == 0) {
613 print "<feeds>";
614
d8781c91 615 $result = db_query($link, "SELECT id, title, cat_id FROM
c1a0541a 616 ttrss_feeds WHERE hidden = false AND owner_uid = ".$_SESSION["uid"]);
87b16a0a
AD
617
618 while ($line = db_fetch_assoc($result)) {
36f78797
AD
619
620 $has_icon = (int) feed_has_icon($line["id"]);
621
d8781c91
AD
622 print "<feed has_icon=\"$has_icon\"
623 cat_id=\"".(int)$line["cat_id"]."\" id=\"".$line["id"]."\"><![CDATA[";
87b16a0a
AD
624 print $line["title"];
625 print "]]></feed>";
626 }
627
628 print "</feeds>";
629
d8781c91
AD
630 print "<feed-categories>";
631
75aa83ec 632 $result = db_query($link, "SELECT id, title, collapsed FROM
d8781c91
AD
633 ttrss_feed_categories WHERE owner_uid = ".$_SESSION["uid"]);
634
75aa83ec 635 print "<category id=\"0\" collapsed=\"".
57937c42 636 (int)get_pref($link, "_COLLAPSED_UNCAT")."\"><![CDATA[";
d8781c91
AD
637 print __("Uncategorized");
638 print "]]></category>";
639
d6416405 640 print "<category id=\"-1\" collapsed=\"".
57937c42 641 (int)get_pref($link, "_COLLAPSED_SPECIAL")."\"><![CDATA[";
d6416405
AD
642 print __("Special");
643 print "]]></category>";
644
c2726c96 645 print "<category id=\"-2\" collapsed=\"".
57937c42 646 (int)get_pref($link, "_COLLAPSED_LABELS")."\"><![CDATA[";
c2726c96
AD
647 print __("Labels");
648 print "]]></category>";
649
d8781c91 650 while ($line = db_fetch_assoc($result)) {
75aa83ec
AD
651 print "<category
652 id=\"".$line["id"]."\"
653 collapsed=\"".(int)sql_bool_to_bool($line["collapsed"])."\"><![CDATA[";
d8781c91
AD
654 print $line["title"];
655 print "]]></category>";
656 }
657
658 print "</feed-categories>";
659
ed22888b
AD
660 print "<labels>";
661
662 $result = db_query($link, "SELECT * FROM
663 ttrss_labels2 WHERE owner_uid = ".$_SESSION["uid"]);
664
665 while ($line = db_fetch_assoc($result)) {
666 print "<label
667 id=\"".$line["id"]."\"
668 fg_color=\"".$line["fg_color"]."\"
669 bg_color=\"".$line["bg_color"]."\"
670 ><![CDATA[";
671 print $line["caption"];
672 print "]]></label>";
673 }
674
675
676 print "</labels>";
d8781c91 677
87b16a0a
AD
678 }
679
6a1cd591 680 if ($stage > 0) {
6a1cd591
AD
681 print "<articles>";
682
04870193 683 $limit = 200;
6a1cd591
AD
684 $skip = $limit*($stage-1);
685
3e52ab08
AD
686 print "<limit value=\"$limit\"/>";
687
6a1cd591
AD
688 if ($amount > 0) $amount -= $skip;
689
690 if ($amount > 0) {
691
692 $limit = min($limit, $amount);
693
694 if ($unread_only) {
a400a562 695 $unread_qpart = "(unread = true OR marked = true) AND ";
6a1cd591
AD
696 }
697
67eb2531 698 if ($cidt && $cidb) {
04870193 699 $cid_qpart = "(ttrss_entries.id > $cidt OR ttrss_entries.id < $cidb) AND ";
95f0c2c5
AD
700 }
701
67eb2531
AD
702 if (DB_TYPE == "pgsql") {
703 $date_qpart = "updated >= NOW() - INTERVAL '1 month' AND";
704 } else {
705 $date_qpart = "updated >= DATE_SUB(NOW(), INTERVAL 1 MONTH) AND";
706 }
707
6a1cd591 708 $result = db_query($link,
c1a0541a
AD
709 "SELECT DISTINCT ttrss_entries.id,ttrss_entries.title,
710 guid,link,comments,
711 feed_id,content,updated,unread,marked FROM
712 ttrss_user_entries,ttrss_entries,ttrss_feeds
713 WHERE $unread_qpart $cid_qpart $date_qpart
714 hidden = false AND
715 ttrss_feeds.id = feed_id AND
716 ref_id = ttrss_entries.id AND
717 ttrss_user_entries.owner_uid = ".$_SESSION["uid"]."
6a1cd591 718 ORDER BY updated DESC LIMIT $limit OFFSET $skip");
fe8f2f0c 719
3034277a 720 if (function_exists('json_encode')) {
6a2034f9 721
3034277a
AD
722 while ($line = db_fetch_assoc($result)) {
723 print "<article><![CDATA[";
724
725 $line["marked"] = (int)sql_bool_to_bool($line["marked"]);
726 $line["unread"] = (int)sql_bool_to_bool($line["unread"]);
3ab18266 727
c2726c96
AD
728 $line["labels"] = get_article_labels($link, $line["id"]);
729
3ab18266
AD
730// too slow :(
731// $line["tags"] = format_tags_string(
732// get_article_tags($link, $line["id"]), $line["id"]);
3034277a
AD
733
734 print json_encode($line);
735 print "]]></article>";
736 }
6a1cd591
AD
737 }
738
739 }
740
741 print "</articles>";
742
743 }
744
87b16a0a
AD
745 print "</rpc-reply>";
746
747 return;
748 }
749
85bd574b 750 print "<rpc-reply><error>Unknown method: $subop</error></rpc-reply>";
01b3e191
AD
751 }
752?>