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