]> git.wh0rd.org - tt-rss.git/blame - backend-rpc.php
default theme updates
[tt-rss.git] / 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
22 }
23
24 if ($subop == "getLabelCounters") {
25 $aid = $_GET["aid"];
26 print "<rpc-reply>";
f54f515f 27 print "<counters>";
01b3e191
AD
28 getLabelCounters($link);
29 if ($aid) {
30 getFeedCounter($link, $aid);
31 }
f54f515f 32 print "</counters>";
01b3e191
AD
33 print "</rpc-reply>";
34 }
35
36 if ($subop == "getFeedCounters") {
37 print "<rpc-reply>";
f54f515f 38 print "<counters>";
01b3e191 39 getFeedCounters($link);
f54f515f 40 print "</counters>";
01b3e191
AD
41 print "</rpc-reply>";
42 }
43
44 if ($subop == "getAllCounters") {
45 print "<rpc-reply>";
f54f515f 46 print "<counters>";
01b3e191 47 getAllCounters($link);
f54f515f
AD
48 print "</counters>";
49 print_runtime_info($link);
01b3e191
AD
50 print "</rpc-reply>";
51 }
52
53 if ($subop == "mark") {
54 $mark = $_GET["mark"];
55 $id = db_escape_string($_GET["id"]);
56
57 if ($mark == "1") {
58 $mark = "true";
59 } else {
60 $mark = "false";
61 }
62
63 // FIXME this needs collision testing
64
65 $result = db_query($link, "UPDATE ttrss_user_entries SET marked = $mark
66 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
67 }
68
69 if ($subop == "updateFeed") {
70 $feed_id = db_escape_string($_GET["feed"]);
71
72 $result = db_query($link,
73 "SELECT feed_url FROM ttrss_feeds WHERE id = '$feed_id'
74 AND owner_uid = " . $_SESSION["uid"]);
75
76 if (db_num_rows($result) > 0) {
77 $feed_url = db_fetch_result($result, 0, "feed_url");
78 update_rss_feed($link, $feed_url, $feed_id);
79 }
80
f54f515f
AD
81 print "<rpc-reply>";
82 print "<counters>";
01b3e191 83 getFeedCounter($link, $feed_id);
f54f515f 84 print "</counters>";
01b3e191
AD
85 print "</rpc-reply>";
86
87 return;
88 }
89
90 if ($subop == "forceUpdateAllFeeds" || $subop == "updateAllFeeds") {
91
92 if (ENABLE_UPDATE_DAEMON) {
93
94 if ($subop == "forceUpdateAllFeeds") {
95
96 $result = db_query($link, "SELECT count(id) AS cid FROM
97 ttrss_scheduled_updates WHERE feed_id IS NULL AND
98 owner_uid = " . $_SESSION["uid"]);
99
100 $cid = db_fetch_result($result, 0, "cid");
101
102 if ($cid == 0) {
103
104 db_query($link, "INSERT INTO ttrss_scheduled_updates
105 (owner_uid, feed_id, entered) VALUES
106 (".$_SESSION["uid"].", NULL, NOW())");
107
108 }
109 }
110
111 } else {
112 update_all_feeds($link, $subop == "forceUpdateAllFeeds");
113 }
114
115 $global_unread_caller = sprintf("%d", $_GET["uctr"]);
116 $global_unread = getGlobalUnread($link);
117
118 print "<rpc-reply>";
119
f54f515f
AD
120 print "<counters>";
121
01b3e191
AD
122 if ($global_unread_caller != $global_unread) {
123
124 $omode = $_GET["omode"];
125
126 if (!$omode) $omode = "tflc";
127
128 if (strchr($omode, "l")) getLabelCounters($link);
129 if (strchr($omode, "f")) getFeedCounters($link);
130 if (strchr($omode, "t")) getTagCounters($link);
131 if (strchr($omode, "c")) {
132 if (get_pref($link, 'ENABLE_FEED_CATS')) {
133 getCategoryCounters($link);
134 }
135 }
136 }
137
138 getGlobalCounters($link, $global_unread);
139
f54f515f
AD
140 print "</counters>";
141
142 print_runtime_info($link);
143
01b3e191
AD
144 print "</rpc-reply>";
145
146 }
472782e8 147
01b3e191
AD
148 /* GET["cmode"] = 0 - mark as read, 1 - as unread, 2 - toggle */
149 if ($subop == "catchupSelected") {
150
151 $ids = split(",", db_escape_string($_GET["ids"]));
01b3e191
AD
152 $cmode = sprintf("%d", $_GET["cmode"]);
153
472782e8 154 catchupArticlesById($link, $ids, $cmode);
01b3e191 155
01b3e191 156 print "<rpc-reply>";
f54f515f 157 print "<counters>";
01b3e191 158 getAllCounters($link);
f54f515f
AD
159 print "</counters>";
160 print_runtime_info($link);
01b3e191
AD
161 print "</rpc-reply>";
162 }
163
164 if ($subop == "markSelected") {
165
166 $ids = split(",", db_escape_string($_GET["ids"]));
01b3e191
AD
167 $cmode = sprintf("%d", $_GET["cmode"]);
168
18eddb2c
AD
169 markArticlesById($link, $ids, $cmode);
170
01b3e191 171 print "<rpc-reply>";
f54f515f 172 print "<counters>";
01b3e191 173 getAllCounters($link);
f54f515f
AD
174 print "</counters>";
175 print_runtime_info($link);
01b3e191
AD
176 print "</rpc-reply>";
177 }
178
179 if ($subop == "sanityCheck") {
3ac2b520 180 print "<rpc-reply>";
01b3e191
AD
181 if (sanity_check($link)) {
182 print "<error error-code=\"0\"/>";
3ac2b520 183 print_init_params($link);
f54f515f 184 print_runtime_info($link);
01b3e191 185 }
3ac2b520
AD
186 print "</rpc-reply>";
187 }
01b3e191
AD
188
189 if ($subop == "globalPurge") {
190
191 print "<rpc-reply>";
192 global_purge_old_posts($link, true);
193 print "</rpc-reply>";
194
195 }
3ac2b520
AD
196
197 if ($subop == "storeParam") {
198 $key = $_GET["key"];
199 $value = $_GET["value"];
200 $_SESSION["stored-params"][$key] = $value;
0b7cb301
AD
201 print "<rpc-reply>
202 <message>$key : $value</message>
203 </rpc-reply>";
3ac2b520 204 }
01b3e191
AD
205 }
206?>