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