]>
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"]); | |
49aa6de9 AD |
70 | |
71 | print "<rpc-reply><mark>$id</mark></rpc-reply>"; | |
72 | ||
01b3e191 AD |
73 | } |
74 | ||
e4f4b46f AD |
75 | if ($subop == "publ") { |
76 | $pub = $_GET["pub"]; | |
77 | $id = db_escape_string($_GET["id"]); | |
78 | ||
79 | if ($pub == "1") { | |
0a8011eb | 80 | $pub = "true"; |
e4f4b46f AD |
81 | } else { |
82 | $pub = "false"; | |
83 | } | |
84 | ||
85 | // FIXME this needs collision testing | |
86 | ||
87 | $result = db_query($link, "UPDATE ttrss_user_entries SET published = $pub | |
88 | WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]); | |
49aa6de9 AD |
89 | |
90 | print "<rpc-reply><pub>$id</pub></rpc-reply>"; | |
91 | ||
e4f4b46f AD |
92 | } |
93 | ||
01b3e191 AD |
94 | if ($subop == "updateFeed") { |
95 | $feed_id = db_escape_string($_GET["feed"]); | |
96 | ||
97 | $result = db_query($link, | |
98 | "SELECT feed_url FROM ttrss_feeds WHERE id = '$feed_id' | |
99 | AND owner_uid = " . $_SESSION["uid"]); | |
100 | ||
101 | if (db_num_rows($result) > 0) { | |
102 | $feed_url = db_fetch_result($result, 0, "feed_url"); | |
103 | update_rss_feed($link, $feed_url, $feed_id); | |
104 | } | |
105 | ||
f54f515f AD |
106 | print "<rpc-reply>"; |
107 | print "<counters>"; | |
01b3e191 | 108 | getFeedCounter($link, $feed_id); |
f54f515f | 109 | print "</counters>"; |
01b3e191 AD |
110 | print "</rpc-reply>"; |
111 | ||
112 | return; | |
113 | } | |
114 | ||
115 | if ($subop == "forceUpdateAllFeeds" || $subop == "updateAllFeeds") { | |
116 | ||
117 | if (ENABLE_UPDATE_DAEMON) { | |
118 | ||
119 | if ($subop == "forceUpdateAllFeeds") { | |
120 | ||
121 | $result = db_query($link, "SELECT count(id) AS cid FROM | |
122 | ttrss_scheduled_updates WHERE feed_id IS NULL AND | |
123 | owner_uid = " . $_SESSION["uid"]); | |
124 | ||
125 | $cid = db_fetch_result($result, 0, "cid"); | |
126 | ||
127 | if ($cid == 0) { | |
128 | ||
129 | db_query($link, "INSERT INTO ttrss_scheduled_updates | |
130 | (owner_uid, feed_id, entered) VALUES | |
131 | (".$_SESSION["uid"].", NULL, NOW())"); | |
132 | ||
133 | } | |
134 | } | |
135 | ||
136 | } else { | |
137 | update_all_feeds($link, $subop == "forceUpdateAllFeeds"); | |
138 | } | |
139 | ||
140 | $global_unread_caller = sprintf("%d", $_GET["uctr"]); | |
141 | $global_unread = getGlobalUnread($link); | |
142 | ||
143 | print "<rpc-reply>"; | |
144 | ||
f54f515f AD |
145 | print "<counters>"; |
146 | ||
01b3e191 AD |
147 | if ($global_unread_caller != $global_unread) { |
148 | ||
149 | $omode = $_GET["omode"]; | |
150 | ||
151 | if (!$omode) $omode = "tflc"; | |
152 | ||
153 | if (strchr($omode, "l")) getLabelCounters($link); | |
154 | if (strchr($omode, "f")) getFeedCounters($link); | |
155 | if (strchr($omode, "t")) getTagCounters($link); | |
156 | if (strchr($omode, "c")) { | |
157 | if (get_pref($link, 'ENABLE_FEED_CATS')) { | |
158 | getCategoryCounters($link); | |
159 | } | |
160 | } | |
161 | } | |
162 | ||
163 | getGlobalCounters($link, $global_unread); | |
164 | ||
f54f515f AD |
165 | print "</counters>"; |
166 | ||
167 | print_runtime_info($link); | |
168 | ||
01b3e191 AD |
169 | print "</rpc-reply>"; |
170 | ||
171 | } | |
472782e8 | 172 | |
01b3e191 AD |
173 | /* GET["cmode"] = 0 - mark as read, 1 - as unread, 2 - toggle */ |
174 | if ($subop == "catchupSelected") { | |
175 | ||
176 | $ids = split(",", db_escape_string($_GET["ids"])); | |
01b3e191 AD |
177 | $cmode = sprintf("%d", $_GET["cmode"]); |
178 | ||
472782e8 | 179 | catchupArticlesById($link, $ids, $cmode); |
01b3e191 | 180 | |
01b3e191 | 181 | print "<rpc-reply>"; |
f54f515f | 182 | print "<counters>"; |
2bc2147f | 183 | getAllCounters($link, $_GET["omode"]); |
f54f515f AD |
184 | print "</counters>"; |
185 | print_runtime_info($link); | |
01b3e191 AD |
186 | print "</rpc-reply>"; |
187 | } | |
188 | ||
189 | if ($subop == "markSelected") { | |
190 | ||
191 | $ids = split(",", db_escape_string($_GET["ids"])); | |
01b3e191 AD |
192 | $cmode = sprintf("%d", $_GET["cmode"]); |
193 | ||
18eddb2c AD |
194 | markArticlesById($link, $ids, $cmode); |
195 | ||
01b3e191 | 196 | print "<rpc-reply>"; |
f54f515f | 197 | print "<counters>"; |
2bc2147f | 198 | getAllCounters($link, $_GET["omode"]); |
f54f515f AD |
199 | print "</counters>"; |
200 | print_runtime_info($link); | |
01b3e191 AD |
201 | print "</rpc-reply>"; |
202 | } | |
203 | ||
e4f4b46f AD |
204 | if ($subop == "publishSelected") { |
205 | ||
206 | $ids = split(",", db_escape_string($_GET["ids"])); | |
207 | $cmode = sprintf("%d", $_GET["cmode"]); | |
208 | ||
209 | publishArticlesById($link, $ids, $cmode); | |
210 | ||
211 | print "<rpc-reply>"; | |
212 | print "<counters>"; | |
2bc2147f | 213 | getAllCounters($link, $_GET["omode"]); |
e4f4b46f AD |
214 | print "</counters>"; |
215 | print_runtime_info($link); | |
216 | print "</rpc-reply>"; | |
217 | } | |
218 | ||
01b3e191 | 219 | if ($subop == "sanityCheck") { |
3ac2b520 | 220 | print "<rpc-reply>"; |
01b3e191 AD |
221 | if (sanity_check($link)) { |
222 | print "<error error-code=\"0\"/>"; | |
3ac2b520 | 223 | print_init_params($link); |
f54f515f | 224 | print_runtime_info($link); |
4220d6b0 AD |
225 | |
226 | # assign client-passed params to session | |
227 | $_SESSION["client.userAgent"] = $_GET["ua"]; | |
228 | ||
01b3e191 | 229 | } |
3ac2b520 AD |
230 | print "</rpc-reply>"; |
231 | } | |
01b3e191 AD |
232 | |
233 | if ($subop == "globalPurge") { | |
234 | ||
235 | print "<rpc-reply>"; | |
236 | global_purge_old_posts($link, true); | |
237 | print "</rpc-reply>"; | |
238 | ||
239 | } | |
3ac2b520 | 240 | |
298f3f78 AD |
241 | if ($subop == "getArticleLink") { |
242 | ||
243 | $id = db_escape_string($_GET["id"]); | |
244 | ||
245 | $result = db_query($link, "SELECT link FROM ttrss_entries, ttrss_user_entries | |
246 | WHERE id = '$id' AND id = ref_id AND owner_uid = '".$_SESSION['uid']."'"); | |
247 | ||
248 | if (db_num_rows($result) == 1) { | |
249 | $link = strip_tags(db_fetch_result($result, 0, "link")); | |
e2ccbfab | 250 | print "<rpc-reply><link>$link</link><id>$id</id></rpc-reply>"; |
298f3f78 AD |
251 | } else { |
252 | print "<rpc-reply><error>Article not found</error></rpc-reply>"; | |
253 | } | |
254 | } | |
255 | ||
0b126ac2 | 256 | if ($subop == "setArticleTags") { |
14b6c54b | 257 | |
0b126ac2 | 258 | $id = db_escape_string($_GET["id"]); |
14b6c54b | 259 | |
0b126ac2 AD |
260 | $tags_str = db_escape_string($_GET["tags_str"]); |
261 | ||
d62a3b63 | 262 | $tags = array_unique(trim_array(split(",", $tags_str))); |
0b126ac2 AD |
263 | |
264 | db_query($link, "BEGIN"); | |
265 | ||
266 | $result = db_query($link, "SELECT int_id FROM ttrss_user_entries WHERE | |
267 | ref_id = '$id' AND owner_uid = '".$_SESSION["uid"]."' LIMIT 1"); | |
268 | ||
269 | if (db_num_rows($result) == 1) { | |
270 | ||
271 | $int_id = db_fetch_result($result, 0, "int_id"); | |
272 | ||
273 | db_query($link, "DELETE FROM ttrss_tags WHERE | |
274 | post_int_id = $int_id AND owner_uid = '".$_SESSION["uid"]."'"); | |
275 | ||
276 | foreach ($tags as $tag) { | |
14b6c54b | 277 | $tag = sanitize_tag($tag); |
0b126ac2 | 278 | |
ef063748 AD |
279 | if (!tag_is_valid($tag)) { |
280 | continue; | |
281 | } | |
282 | ||
0b126ac2 AD |
283 | if (preg_match("/^[0-9]*$/", $tag)) { |
284 | continue; | |
285 | } | |
14b6c54b | 286 | |
9cfd409d | 287 | print "<!-- $id : $int_id : $tag -->"; |
0b126ac2 AD |
288 | |
289 | if ($tag != '') { | |
290 | db_query($link, "INSERT INTO ttrss_tags | |
291 | (post_int_id, owner_uid, tag_name) VALUES ('$int_id', '".$_SESSION["uid"]."', '$tag')"); | |
292 | } | |
293 | } | |
294 | } | |
295 | ||
296 | db_query($link, "COMMIT"); | |
297 | ||
298 | print "<rpc-reply> | |
299 | <message>$id</message> | |
300 | </rpc-reply>"; | |
301 | ||
302 | } | |
01a87dff | 303 | |
945c243e AD |
304 | if ($subop == "regenPubKey") { |
305 | ||
306 | print "<rpc-reply>"; | |
307 | ||
308 | set_pref($link, "_PREFS_PUBLISH_KEY", generate_publish_key()); | |
309 | ||
310 | $url_path = 'http://' . $_SERVER["HTTP_HOST"] . \ | |
311 | parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH); | |
312 | ||
313 | $new_link = $url_path . "?op=publish&key=" . get_pref($link, "_PREFS_PUBLISH_KEY"); | |
314 | ||
315 | print "<link><![CDATA[$new_link]]></link>"; | |
316 | ||
317 | print "</rpc-reply>"; | |
318 | ||
319 | } | |
320 | ||
01a87dff AD |
321 | if ($subop == "logout") { |
322 | logout_user(); | |
323 | print_error_xml(6); | |
324 | } | |
325 | ||
01b3e191 AD |
326 | } |
327 | ?> |