]>
Commit | Line | Data |
---|---|---|
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); |
4220d6b0 AD |
188 | |
189 | # assign client-passed params to session | |
190 | $_SESSION["client.userAgent"] = $_GET["ua"]; | |
191 | ||
01b3e191 | 192 | } |
3ac2b520 AD |
193 | print "</rpc-reply>"; |
194 | } | |
01b3e191 AD |
195 | |
196 | if ($subop == "globalPurge") { | |
197 | ||
198 | print "<rpc-reply>"; | |
199 | global_purge_old_posts($link, true); | |
200 | print "</rpc-reply>"; | |
201 | ||
202 | } | |
3ac2b520 AD |
203 | |
204 | if ($subop == "storeParam") { | |
205 | $key = $_GET["key"]; | |
206 | $value = $_GET["value"]; | |
207 | $_SESSION["stored-params"][$key] = $value; | |
0b7cb301 AD |
208 | print "<rpc-reply> |
209 | <message>$key : $value</message> | |
210 | </rpc-reply>"; | |
3ac2b520 | 211 | } |
0b126ac2 AD |
212 | |
213 | if ($subop == "setArticleTags") { | |
214 | $id = db_escape_string($_GET["id"]); | |
215 | $tags_str = db_escape_string($_GET["tags_str"]); | |
216 | ||
d62a3b63 | 217 | $tags = array_unique(trim_array(split(",", $tags_str))); |
0b126ac2 AD |
218 | |
219 | db_query($link, "BEGIN"); | |
220 | ||
221 | $result = db_query($link, "SELECT int_id FROM ttrss_user_entries WHERE | |
222 | ref_id = '$id' AND owner_uid = '".$_SESSION["uid"]."' LIMIT 1"); | |
223 | ||
224 | if (db_num_rows($result) == 1) { | |
225 | ||
226 | $int_id = db_fetch_result($result, 0, "int_id"); | |
227 | ||
228 | db_query($link, "DELETE FROM ttrss_tags WHERE | |
229 | post_int_id = $int_id AND owner_uid = '".$_SESSION["uid"]."'"); | |
230 | ||
231 | foreach ($tags as $tag) { | |
232 | $tag = trim($tag); | |
233 | ||
234 | if (preg_match("/^[0-9]*$/", $tag)) { | |
235 | continue; | |
236 | } | |
237 | ||
238 | if ($tag != '') { | |
239 | db_query($link, "INSERT INTO ttrss_tags | |
240 | (post_int_id, owner_uid, tag_name) VALUES ('$int_id', '".$_SESSION["uid"]."', '$tag')"); | |
241 | } | |
242 | } | |
243 | } | |
244 | ||
245 | db_query($link, "COMMIT"); | |
246 | ||
247 | print "<rpc-reply> | |
248 | <message>$id</message> | |
249 | </rpc-reply>"; | |
250 | ||
251 | } | |
01b3e191 AD |
252 | } |
253 | ?> |