]> git.wh0rd.org - tt-rss.git/blame - modules/backend-rpc.php
make mark as read subtoolbar dropdown clickable
[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
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") {
cf4d339c 45 print "<rpc-reply>";
f54f515f 46 print "<counters>";
cf4d339c
AD
47
48 $omode = $_GET["omode"];
49
50 getAllCounters($link, $omode);
f54f515f
AD
51 print "</counters>";
52 print_runtime_info($link);
01b3e191
AD
53 print "</rpc-reply>";
54 }
55
56 if ($subop == "mark") {
57 $mark = $_GET["mark"];
58 $id = db_escape_string($_GET["id"]);
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"]);
70 }
71
72 if ($subop == "updateFeed") {
73 $feed_id = db_escape_string($_GET["feed"]);
74
75 $result = db_query($link,
76 "SELECT feed_url FROM ttrss_feeds WHERE id = '$feed_id'
77 AND owner_uid = " . $_SESSION["uid"]);
78
79 if (db_num_rows($result) > 0) {
80 $feed_url = db_fetch_result($result, 0, "feed_url");
81 update_rss_feed($link, $feed_url, $feed_id);
82 }
83
f54f515f
AD
84 print "<rpc-reply>";
85 print "<counters>";
01b3e191 86 getFeedCounter($link, $feed_id);
f54f515f 87 print "</counters>";
01b3e191
AD
88 print "</rpc-reply>";
89
90 return;
91 }
92
93 if ($subop == "forceUpdateAllFeeds" || $subop == "updateAllFeeds") {
94
95 if (ENABLE_UPDATE_DAEMON) {
96
97 if ($subop == "forceUpdateAllFeeds") {
98
99 $result = db_query($link, "SELECT count(id) AS cid FROM
100 ttrss_scheduled_updates WHERE feed_id IS NULL AND
101 owner_uid = " . $_SESSION["uid"]);
102
103 $cid = db_fetch_result($result, 0, "cid");
104
105 if ($cid == 0) {
106
107 db_query($link, "INSERT INTO ttrss_scheduled_updates
108 (owner_uid, feed_id, entered) VALUES
109 (".$_SESSION["uid"].", NULL, NOW())");
110
111 }
112 }
113
114 } else {
115 update_all_feeds($link, $subop == "forceUpdateAllFeeds");
116 }
117
118 $global_unread_caller = sprintf("%d", $_GET["uctr"]);
119 $global_unread = getGlobalUnread($link);
120
121 print "<rpc-reply>";
122
f54f515f
AD
123 print "<counters>";
124
01b3e191
AD
125 if ($global_unread_caller != $global_unread) {
126
127 $omode = $_GET["omode"];
128
129 if (!$omode) $omode = "tflc";
130
131 if (strchr($omode, "l")) getLabelCounters($link);
132 if (strchr($omode, "f")) getFeedCounters($link);
133 if (strchr($omode, "t")) getTagCounters($link);
134 if (strchr($omode, "c")) {
135 if (get_pref($link, 'ENABLE_FEED_CATS')) {
136 getCategoryCounters($link);
137 }
138 }
139 }
140
141 getGlobalCounters($link, $global_unread);
142
f54f515f
AD
143 print "</counters>";
144
145 print_runtime_info($link);
146
01b3e191
AD
147 print "</rpc-reply>";
148
149 }
472782e8 150
01b3e191
AD
151 /* GET["cmode"] = 0 - mark as read, 1 - as unread, 2 - toggle */
152 if ($subop == "catchupSelected") {
153
154 $ids = split(",", db_escape_string($_GET["ids"]));
01b3e191
AD
155 $cmode = sprintf("%d", $_GET["cmode"]);
156
472782e8 157 catchupArticlesById($link, $ids, $cmode);
01b3e191 158
01b3e191 159 print "<rpc-reply>";
f54f515f 160 print "<counters>";
01b3e191 161 getAllCounters($link);
f54f515f
AD
162 print "</counters>";
163 print_runtime_info($link);
01b3e191
AD
164 print "</rpc-reply>";
165 }
166
167 if ($subop == "markSelected") {
168
169 $ids = split(",", db_escape_string($_GET["ids"]));
01b3e191
AD
170 $cmode = sprintf("%d", $_GET["cmode"]);
171
18eddb2c
AD
172 markArticlesById($link, $ids, $cmode);
173
01b3e191 174 print "<rpc-reply>";
f54f515f 175 print "<counters>";
01b3e191 176 getAllCounters($link);
f54f515f
AD
177 print "</counters>";
178 print_runtime_info($link);
01b3e191
AD
179 print "</rpc-reply>";
180 }
181
182 if ($subop == "sanityCheck") {
3ac2b520 183 print "<rpc-reply>";
01b3e191
AD
184 if (sanity_check($link)) {
185 print "<error error-code=\"0\"/>";
3ac2b520 186 print_init_params($link);
f54f515f 187 print_runtime_info($link);
01b3e191 188 }
3ac2b520
AD
189 print "</rpc-reply>";
190 }
01b3e191
AD
191
192 if ($subop == "globalPurge") {
193
194 print "<rpc-reply>";
195 global_purge_old_posts($link, true);
196 print "</rpc-reply>";
197
198 }
3ac2b520
AD
199
200 if ($subop == "storeParam") {
201 $key = $_GET["key"];
202 $value = $_GET["value"];
203 $_SESSION["stored-params"][$key] = $value;
0b7cb301
AD
204 print "<rpc-reply>
205 <message>$key : $value</message>
206 </rpc-reply>";
3ac2b520 207 }
0b126ac2
AD
208
209 if ($subop == "setArticleTags") {
210 $id = db_escape_string($_GET["id"]);
211 $tags_str = db_escape_string($_GET["tags_str"]);
212
d62a3b63 213 $tags = array_unique(trim_array(split(",", $tags_str)));
0b126ac2
AD
214
215 db_query($link, "BEGIN");
216
217 $result = db_query($link, "SELECT int_id FROM ttrss_user_entries WHERE
218 ref_id = '$id' AND owner_uid = '".$_SESSION["uid"]."' LIMIT 1");
219
220 if (db_num_rows($result) == 1) {
221
222 $int_id = db_fetch_result($result, 0, "int_id");
223
224 db_query($link, "DELETE FROM ttrss_tags WHERE
225 post_int_id = $int_id AND owner_uid = '".$_SESSION["uid"]."'");
226
227 foreach ($tags as $tag) {
228 $tag = trim($tag);
229
230 if (preg_match("/^[0-9]*$/", $tag)) {
231 continue;
232 }
233
234 if ($tag != '') {
235 db_query($link, "INSERT INTO ttrss_tags
236 (post_int_id, owner_uid, tag_name) VALUES ('$int_id', '".$_SESSION["uid"]."', '$tag')");
237 }
238 }
239 }
240
241 db_query($link, "COMMIT");
242
243 print "<rpc-reply>
244 <message>$id</message>
245 </rpc-reply>";
246
247 }
01b3e191
AD
248 }
249?>