]>
Commit | Line | Data |
---|---|---|
1d3a17c7 | 1 | <?php |
01b3e191 AD |
2 | function handle_rpc_request($link) { |
3 | ||
b4e75b2a | 4 | $subop = $_REQUEST["subop"]; |
01b3e191 | 5 | |
d9084cf2 AD |
6 | if ($subop == "setprofile") { |
7 | $id = db_escape_string($_REQUEST["id"]); | |
8 | ||
9 | $_SESSION["profile"] = $id; | |
10 | $_SESSION["prefs_cache"] = array(); | |
11 | return; | |
12 | } | |
13 | ||
14 | if ($subop == "remprofiles") { | |
15 | $ids = split(",", db_escape_string(trim($_REQUEST["ids"]))); | |
16 | ||
17 | foreach ($ids as $id) { | |
18 | if ($_SESSION["profile"] != $id) { | |
19 | db_query($link, "DELETE FROM ttrss_settings_profiles WHERE id = '$id' AND | |
20 | owner_uid = " . $_SESSION["uid"]); | |
21 | } | |
22 | } | |
23 | return; | |
24 | } | |
25 | ||
26 | if ($subop == "addprofile") { | |
27 | $title = db_escape_string(trim($_REQUEST["title"])); | |
28 | if ($title) { | |
29 | db_query($link, "BEGIN"); | |
30 | ||
31 | $result = db_query($link, "SELECT id FROM ttrss_settings_profiles | |
32 | WHERE title = '$title' AND owner_uid = " . $_SESSION["uid"]); | |
33 | ||
34 | if (db_num_rows($result) == 0) { | |
35 | ||
36 | db_query($link, "INSERT INTO ttrss_settings_profiles (title, owner_uid) | |
37 | VALUES ('$title', ".$_SESSION["uid"] .")"); | |
38 | ||
39 | $result = db_query($link, "SELECT id FROM ttrss_settings_profiles WHERE | |
40 | title = '$title'"); | |
41 | ||
42 | if (db_num_rows($result) != 0) { | |
43 | $profile_id = db_fetch_result($result, 0, "id"); | |
44 | ||
45 | if ($profile_id) { | |
46 | initialize_user_prefs($link, $_SESSION["uid"], $profile_id); | |
47 | } | |
48 | } | |
49 | } | |
50 | ||
51 | db_query($link, "COMMIT"); | |
52 | } | |
53 | return; | |
54 | } | |
55 | ||
56 | if ($subop == "saveprofile") { | |
57 | $id = db_escape_string($_REQUEST["id"]); | |
58 | $title = db_escape_string(trim($_REQUEST["value"])); | |
59 | ||
60 | if ($id == 0) { | |
61 | print __("Default profile"); | |
62 | return; | |
63 | } | |
64 | ||
65 | if ($title) { | |
66 | db_query($link, "BEGIN"); | |
67 | ||
68 | $result = db_query($link, "SELECT id FROM ttrss_settings_profiles | |
69 | WHERE title = '$title' AND owner_uid =" . $_SESSION["uid"]); | |
70 | ||
71 | if (db_num_rows($result) == 0) { | |
72 | db_query($link, "UPDATE ttrss_settings_profiles | |
73 | SET title = '$title' WHERE id = '$id' AND | |
74 | owner_uid = " . $_SESSION["uid"]); | |
75 | print $title; | |
76 | } else { | |
77 | $result = db_query($link, "SELECT title FROM ttrss_settings_profiles | |
78 | WHERE id = '$id' AND owner_uid =" . $_SESSION["uid"]); | |
79 | print db_fetch_result($result, 0, "title"); | |
80 | } | |
81 | ||
82 | db_query($link, "COMMIT"); | |
83 | } | |
84 | return; | |
85 | } | |
86 | ||
ef88b1cc AD |
87 | if ($subop == "remarchive") { |
88 | $ids = split(",", db_escape_string($_REQUEST["ids"])); | |
89 | ||
90 | print "<rpc-reply>"; | |
91 | ||
92 | foreach ($ids as $id) { | |
93 | $result = db_query($link, "DELETE FROM ttrss_archived_feeds WHERE | |
94 | (SELECT COUNT(*) FROM ttrss_user_entries | |
95 | WHERE orig_feed_id = '$id') = 0 AND | |
96 | id = '$id' AND owner_uid = ".$_SESSION["uid"]); | |
97 | ||
98 | $rc = db_affected_rows($link, $result); | |
99 | ||
100 | print "<feed id='$id' rc='$rc'/>"; | |
101 | ||
102 | } | |
103 | ||
104 | print "</rpc-reply>"; | |
105 | ||
106 | return; | |
107 | } | |
108 | ||
a5819bb3 AD |
109 | if ($subop == "addfeed") { |
110 | ||
111 | $feed = db_escape_string($_REQUEST['feed']); | |
112 | $cat = db_escape_string($_REQUEST['cat']); | |
113 | $login = db_escape_string($_REQUEST['login']); | |
114 | $pass = db_escape_string($_REQUEST['pass']); | |
115 | ||
116 | $rc = subscribe_to_feed($link, $feed, $cat, $login, $pass); | |
117 | ||
118 | print "<rpc-reply>"; | |
119 | print "<result code='$rc'/>"; | |
120 | print "</rpc-reply>"; | |
121 | ||
122 | return; | |
123 | ||
124 | } | |
125 | ||
f0266f51 CW |
126 | if ($subop == "extractfeedurls") { |
127 | print "<rpc-reply>"; | |
128 | ||
129 | $urls = get_feeds_from_html($_REQUEST['url']); | |
130 | print "<urls><![CDATA[" . json_encode($urls) . "]]></urls>"; | |
131 | ||
132 | print "</rpc-reply>"; | |
133 | return; | |
134 | } | |
135 | ||
8a3e0b1a AD |
136 | if ($subop == "togglepref") { |
137 | print "<rpc-reply>"; | |
138 | ||
139 | $key = db_escape_string($_REQUEST["key"]); | |
140 | ||
141 | set_pref($link, $key, !get_pref($link, $key)); | |
142 | ||
143 | $value = get_pref($link, $key); | |
01b3e191 | 144 | |
8a3e0b1a AD |
145 | print "<param-set key=\"$key\" value=\"$value\"/>"; |
146 | ||
147 | print "</rpc-reply>"; | |
148 | ||
149 | return; | |
150 | } | |
151 | ||
152 | if ($subop == "setpref") { | |
01b3e191 AD |
153 | print "<rpc-reply>"; |
154 | ||
b4e75b2a AD |
155 | $key = db_escape_string($_REQUEST["key"]); |
156 | $value = db_escape_string($_REQUEST["value"]); | |
01b3e191 AD |
157 | |
158 | set_pref($link, $key, $value); | |
159 | ||
160 | print "<param-set key=\"$key\" value=\"$value\"/>"; | |
161 | ||
162 | print "</rpc-reply>"; | |
163 | ||
85bd574b | 164 | return; |
01b3e191 AD |
165 | } |
166 | ||
01b3e191 | 167 | if ($subop == "getAllCounters") { |
cf4d339c | 168 | print "<rpc-reply>"; |
6a7817c1 | 169 | print "<counters><![CDATA["; |
cf4d339c | 170 | |
6a7817c1 | 171 | print json_encode(getAllCounters($link, $_REQUEST['omode'])); |
cf4d339c | 172 | |
6a7817c1 | 173 | print "]]></counters>"; |
f54f515f | 174 | print_runtime_info($link); |
01b3e191 | 175 | print "</rpc-reply>"; |
85bd574b AD |
176 | |
177 | return; | |
01b3e191 AD |
178 | } |
179 | ||
180 | if ($subop == "mark") { | |
b4e75b2a AD |
181 | $mark = $_REQUEST["mark"]; |
182 | $id = db_escape_string($_REQUEST["id"]); | |
01b3e191 AD |
183 | |
184 | if ($mark == "1") { | |
185 | $mark = "true"; | |
186 | } else { | |
187 | $mark = "false"; | |
188 | } | |
189 | ||
190 | // FIXME this needs collision testing | |
191 | ||
192 | $result = db_query($link, "UPDATE ttrss_user_entries SET marked = $mark | |
193 | WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]); | |
49aa6de9 | 194 | |
6a7817c1 AD |
195 | print "<rpc-reply><counters><![CDATA["; |
196 | print json_encode(getAllCounters($link)); | |
197 | print "]]></counters></rpc-reply>"; | |
49aa6de9 | 198 | |
85bd574b | 199 | return; |
01b3e191 AD |
200 | } |
201 | ||
e04c18a2 | 202 | if ($subop == "delete") { |
b4e75b2a | 203 | $ids = db_escape_string($_REQUEST["ids"]); |
e04c18a2 AD |
204 | |
205 | $result = db_query($link, "DELETE FROM ttrss_user_entries | |
206 | WHERE ref_id IN ($ids) AND owner_uid = " . $_SESSION["uid"]); | |
207 | ||
6a7817c1 AD |
208 | print "<rpc-reply><counters><![CDATA["; |
209 | print json_encode(getAllCounters($link)); | |
210 | print "]]></counters></rpc-reply>"; | |
e04c18a2 AD |
211 | |
212 | return; | |
213 | } | |
214 | ||
215 | if ($subop == "unarchive") { | |
b4e75b2a | 216 | $ids = db_escape_string($_REQUEST["ids"]); |
e04c18a2 AD |
217 | |
218 | $result = db_query($link, "UPDATE ttrss_user_entries | |
ef83538d | 219 | SET feed_id = orig_feed_id, orig_feed_id = NULL |
e04c18a2 AD |
220 | WHERE ref_id IN ($ids) AND owner_uid = " . $_SESSION["uid"]); |
221 | ||
6a7817c1 AD |
222 | print "<rpc-reply><counters><![CDATA["; |
223 | print json_encode(getAllCounters($link)); | |
224 | print "]]></counters></rpc-reply>"; | |
e04c18a2 AD |
225 | |
226 | return; | |
227 | } | |
228 | ||
229 | if ($subop == "archive") { | |
b4e75b2a | 230 | $ids = split(",", db_escape_string($_REQUEST["ids"])); |
e04c18a2 | 231 | |
16fdac16 AD |
232 | foreach ($ids as $id) { |
233 | archive_article($link, $id, $_SESSION["uid"]); | |
234 | } | |
e04c18a2 | 235 | |
6a7817c1 AD |
236 | print "<rpc-reply><counters><![CDATA["; |
237 | print json_encode(getAllCounters($link)); | |
238 | print "]]></counters></rpc-reply>"; | |
e04c18a2 AD |
239 | |
240 | return; | |
241 | } | |
242 | ||
243 | ||
e4f4b46f | 244 | if ($subop == "publ") { |
c7e51de1 AD |
245 | $pub = $_REQUEST["pub"]; |
246 | $id = db_escape_string($_REQUEST["id"]); | |
247 | $note = trim(strip_tags(db_escape_string($_REQUEST["note"]))); | |
e4f4b46f AD |
248 | |
249 | if ($pub == "1") { | |
0a8011eb | 250 | $pub = "true"; |
e4f4b46f AD |
251 | } else { |
252 | $pub = "false"; | |
253 | } | |
254 | ||
c7e51de1 AD |
255 | if ($note != 'undefined') { |
256 | $note_qpart = "note = '$note',"; | |
257 | } | |
258 | ||
e4f4b46f AD |
259 | // FIXME this needs collision testing |
260 | ||
c7e51de1 AD |
261 | $result = db_query($link, "UPDATE ttrss_user_entries SET |
262 | $note_qpart | |
263 | published = $pub | |
e4f4b46f | 264 | WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]); |
49aa6de9 | 265 | |
c7e51de1 AD |
266 | |
267 | print "<rpc-reply>"; | |
268 | ||
6a7817c1 AD |
269 | print "<counters><![CDATA["; |
270 | print json_encode(getAllCounters($link)); | |
271 | print "]]></counters>"; | |
c7e51de1 AD |
272 | |
273 | if ($note != 'undefined') { | |
274 | $note_size = strlen($note); | |
275 | print "<note id=\"$id\" size=\"$note_size\">"; | |
276 | print "<![CDATA[" . format_article_note($id, $note) . "]]>"; | |
277 | print "</note>"; | |
278 | } | |
279 | ||
280 | print "</rpc-reply>"; | |
49aa6de9 | 281 | |
85bd574b | 282 | return; |
e4f4b46f AD |
283 | } |
284 | ||
01b3e191 | 285 | if ($subop == "updateFeed") { |
b4e75b2a | 286 | $feed_id = db_escape_string($_REQUEST["feed"]); |
01b3e191 | 287 | |
c633e370 | 288 | update_rss_feed($link, $feed_id); |
01b3e191 | 289 | |
f54f515f | 290 | print "<rpc-reply>"; |
6a7817c1 AD |
291 | print "<counters><![CDATA["; |
292 | print json_encode(getFeedCounters($link, $feed_id)); | |
293 | print "]]></counters>"; | |
01b3e191 AD |
294 | print "</rpc-reply>"; |
295 | ||
296 | return; | |
297 | } | |
298 | ||
50eefedb | 299 | if ($subop == "updateAllFeeds") { |
01b3e191 | 300 | |
b4e75b2a | 301 | $global_unread_caller = sprintf("%d", $_REQUEST["uctr"]); |
01b3e191 AD |
302 | $global_unread = getGlobalUnread($link); |
303 | ||
304 | print "<rpc-reply>"; | |
305 | ||
a06d0e5a | 306 | if ($global_unread_caller != $global_unread) { |
a8f447f3 | 307 | print "<counters><![CDATA["; |
6a7817c1 AD |
308 | $omode = $_REQUEST["omode"]; |
309 | print json_encode(getAllCounters($link, $omode)); | |
a8f447f3 | 310 | print "]]></counters>"; |
a06d0e5a AD |
311 | } |
312 | ||
f54f515f AD |
313 | print_runtime_info($link); |
314 | ||
01b3e191 AD |
315 | print "</rpc-reply>"; |
316 | ||
85bd574b | 317 | return; |
01b3e191 | 318 | } |
472782e8 | 319 | |
01b3e191 AD |
320 | /* GET["cmode"] = 0 - mark as read, 1 - as unread, 2 - toggle */ |
321 | if ($subop == "catchupSelected") { | |
322 | ||
2855ee88 AD |
323 | $ids = split(",", db_escape_string($_REQUEST["ids"])); |
324 | $cmode = sprintf("%d", $_REQUEST["cmode"]); | |
01b3e191 | 325 | |
472782e8 | 326 | catchupArticlesById($link, $ids, $cmode); |
01b3e191 | 327 | |
01b3e191 | 328 | print "<rpc-reply>"; |
6a7817c1 AD |
329 | print "<counters><![CDATA["; |
330 | print json_encode(getAllCounters($link, $_REQUEST['omode'])); | |
331 | print "]]></counters>"; | |
332 | ||
f54f515f | 333 | print_runtime_info($link); |
01b3e191 | 334 | print "</rpc-reply>"; |
85bd574b AD |
335 | |
336 | return; | |
01b3e191 AD |
337 | } |
338 | ||
339 | if ($subop == "markSelected") { | |
340 | ||
b4e75b2a AD |
341 | $ids = split(",", db_escape_string($_REQUEST["ids"])); |
342 | $cmode = sprintf("%d", $_REQUEST["cmode"]); | |
01b3e191 | 343 | |
18eddb2c AD |
344 | markArticlesById($link, $ids, $cmode); |
345 | ||
01b3e191 | 346 | print "<rpc-reply>"; |
6a7817c1 AD |
347 | print "<counters><![CDATA["; |
348 | print json_encode(getAllCounters($link, $_REQUEST['omode'])); | |
349 | print "]]></counters>"; | |
f54f515f | 350 | print_runtime_info($link); |
01b3e191 | 351 | print "</rpc-reply>"; |
85bd574b AD |
352 | |
353 | return; | |
01b3e191 AD |
354 | } |
355 | ||
e4f4b46f AD |
356 | if ($subop == "publishSelected") { |
357 | ||
b4e75b2a AD |
358 | $ids = split(",", db_escape_string($_REQUEST["ids"])); |
359 | $cmode = sprintf("%d", $_REQUEST["cmode"]); | |
e4f4b46f AD |
360 | |
361 | publishArticlesById($link, $ids, $cmode); | |
362 | ||
363 | print "<rpc-reply>"; | |
6a7817c1 AD |
364 | print "<counters><![CDATA["; |
365 | print json_encode(getAllCounters($link, $_REQUEST['omode'])); | |
366 | print "]]></counters>"; | |
e4f4b46f AD |
367 | print_runtime_info($link); |
368 | print "</rpc-reply>"; | |
85bd574b AD |
369 | |
370 | return; | |
e4f4b46f AD |
371 | } |
372 | ||
01b3e191 | 373 | if ($subop == "sanityCheck") { |
3ac2b520 | 374 | print "<rpc-reply>"; |
01b3e191 AD |
375 | if (sanity_check($link)) { |
376 | print "<error error-code=\"0\"/>"; | |
d8221301 AD |
377 | |
378 | print "<init-params><![CDATA["; | |
379 | print json_encode(make_init_params($link)); | |
380 | print "]]></init-params>"; | |
381 | ||
f54f515f | 382 | print_runtime_info($link); |
4220d6b0 AD |
383 | |
384 | # assign client-passed params to session | |
b4e75b2a | 385 | $_SESSION["client.userAgent"] = $_REQUEST["ua"]; |
4220d6b0 | 386 | |
01b3e191 | 387 | } |
3ac2b520 | 388 | print "</rpc-reply>"; |
85bd574b AD |
389 | |
390 | return; | |
3ac2b520 | 391 | } |
01b3e191 AD |
392 | |
393 | if ($subop == "globalPurge") { | |
394 | ||
395 | print "<rpc-reply>"; | |
396 | global_purge_old_posts($link, true); | |
397 | print "</rpc-reply>"; | |
398 | ||
85bd574b | 399 | return; |
01b3e191 | 400 | } |
3ac2b520 | 401 | |
298f3f78 AD |
402 | if ($subop == "getArticleLink") { |
403 | ||
b4e75b2a | 404 | $id = db_escape_string($_REQUEST["id"]); |
298f3f78 AD |
405 | |
406 | $result = db_query($link, "SELECT link FROM ttrss_entries, ttrss_user_entries | |
407 | WHERE id = '$id' AND id = ref_id AND owner_uid = '".$_SESSION['uid']."'"); | |
408 | ||
409 | if (db_num_rows($result) == 1) { | |
06925d9e | 410 | $link = htmlspecialchars(strip_tags(db_fetch_result($result, 0, "link"))); |
e2ccbfab | 411 | print "<rpc-reply><link>$link</link><id>$id</id></rpc-reply>"; |
298f3f78 AD |
412 | } else { |
413 | print "<rpc-reply><error>Article not found</error></rpc-reply>"; | |
414 | } | |
85bd574b AD |
415 | |
416 | return; | |
298f3f78 AD |
417 | } |
418 | ||
0b126ac2 | 419 | if ($subop == "setArticleTags") { |
14b6c54b | 420 | |
bd3f2ade AD |
421 | global $memcache; |
422 | ||
b4e75b2a | 423 | $id = db_escape_string($_REQUEST["id"]); |
14b6c54b | 424 | |
b4e75b2a | 425 | $tags_str = db_escape_string($_REQUEST["tags_str"]); |
d62a3b63 | 426 | $tags = array_unique(trim_array(split(",", $tags_str))); |
0b126ac2 AD |
427 | |
428 | db_query($link, "BEGIN"); | |
429 | ||
430 | $result = db_query($link, "SELECT int_id FROM ttrss_user_entries WHERE | |
431 | ref_id = '$id' AND owner_uid = '".$_SESSION["uid"]."' LIMIT 1"); | |
432 | ||
433 | if (db_num_rows($result) == 1) { | |
434 | ||
779560b7 AD |
435 | $tags_to_cache = array(); |
436 | ||
0b126ac2 AD |
437 | $int_id = db_fetch_result($result, 0, "int_id"); |
438 | ||
439 | db_query($link, "DELETE FROM ttrss_tags WHERE | |
440 | post_int_id = $int_id AND owner_uid = '".$_SESSION["uid"]."'"); | |
441 | ||
442 | foreach ($tags as $tag) { | |
14b6c54b | 443 | $tag = sanitize_tag($tag); |
0b126ac2 | 444 | |
ef063748 AD |
445 | if (!tag_is_valid($tag)) { |
446 | continue; | |
447 | } | |
448 | ||
0b126ac2 AD |
449 | if (preg_match("/^[0-9]*$/", $tag)) { |
450 | continue; | |
451 | } | |
14b6c54b | 452 | |
307d187c | 453 | // print "<!-- $id : $int_id : $tag -->"; |
0b126ac2 AD |
454 | |
455 | if ($tag != '') { | |
456 | db_query($link, "INSERT INTO ttrss_tags | |
457 | (post_int_id, owner_uid, tag_name) VALUES ('$int_id', '".$_SESSION["uid"]."', '$tag')"); | |
458 | } | |
779560b7 AD |
459 | |
460 | array_push($tags_to_cache, $tag); | |
0b126ac2 | 461 | } |
0b126ac2 | 462 | |
779560b7 AD |
463 | /* update tag cache */ |
464 | ||
465 | $tags_str = join(",", $tags_to_cache); | |
466 | ||
467 | db_query($link, "UPDATE ttrss_user_entries | |
468 | SET tag_cache = '$tags_str' WHERE ref_id = '$id' | |
469 | AND owner_uid = " . $_SESSION["uid"]); | |
470 | } | |
490c366d | 471 | |
0b126ac2 AD |
472 | db_query($link, "COMMIT"); |
473 | ||
bd3f2ade AD |
474 | if ($memcache) { |
475 | $obj_id = md5("TAGS:".$_SESSION["uid"].":$id"); | |
476 | $memcache->delete($obj_id); | |
477 | } | |
478 | ||
307d187c AD |
479 | $tags_str = format_tags_string(get_article_tags($link, $id), $id); |
480 | ||
0b126ac2 | 481 | print "<rpc-reply> |
307d187c | 482 | <tags-str id=\"$id\"><![CDATA[$tags_str]]></tags-str> |
0b126ac2 AD |
483 | </rpc-reply>"; |
484 | ||
85bd574b | 485 | return; |
0b126ac2 | 486 | } |
01a87dff | 487 | |
ef7b7bbd MK |
488 | if ($subop == "regenOPMLKey") { |
489 | ||
490 | print "<rpc-reply>"; | |
2e7f046f AD |
491 | |
492 | update_feed_access_key($link, 'OPML:Publish', | |
493 | false, $_SESSION["uid"]); | |
494 | ||
ef7b7bbd MK |
495 | $new_link = opml_publish_url($link); |
496 | print "<link><![CDATA[$new_link]]></link>"; | |
497 | print "</rpc-reply>"; | |
498 | return; | |
499 | } | |
500 | ||
01a87dff AD |
501 | if ($subop == "logout") { |
502 | logout_user(); | |
503 | print_error_xml(6); | |
85bd574b | 504 | return; |
01a87dff AD |
505 | } |
506 | ||
05fcdf52 AD |
507 | if ($subop == "completeTags") { |
508 | ||
509 | $search = db_escape_string($_REQUEST["search"]); | |
510 | ||
511 | $result = db_query($link, "SELECT DISTINCT tag_name FROM ttrss_tags | |
512 | WHERE owner_uid = '".$_SESSION["uid"]."' AND | |
513 | tag_name LIKE '$search%' ORDER BY tag_name | |
514 | LIMIT 10"); | |
515 | ||
516 | print "<ul>"; | |
517 | while ($line = db_fetch_assoc($result)) { | |
518 | print "<li>" . $line["tag_name"] . "</li>"; | |
519 | } | |
520 | print "</ul>"; | |
521 | ||
85bd574b | 522 | return; |
05fcdf52 AD |
523 | } |
524 | ||
81cd6cac | 525 | if ($subop == "purge") { |
b4e75b2a AD |
526 | $ids = split(",", db_escape_string($_REQUEST["ids"])); |
527 | $days = sprintf("%d", $_REQUEST["days"]); | |
81cd6cac AD |
528 | |
529 | print "<rpc-reply>"; | |
530 | ||
531 | print "<message><![CDATA["; | |
532 | ||
533 | foreach ($ids as $id) { | |
534 | ||
535 | $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE | |
536 | id = '$id' AND owner_uid = ".$_SESSION["uid"]); | |
537 | ||
538 | if (db_num_rows($result) == 1) { | |
539 | purge_feed($link, $id, $days, true); | |
540 | } | |
541 | } | |
542 | ||
543 | print "]]></message>"; | |
544 | ||
545 | print "</rpc-reply>"; | |
546 | ||
547 | return; | |
548 | } | |
549 | ||
9bf3f101 | 550 | /* if ($subop == "setScore") { |
546499a9 AD |
551 | $id = db_escape_string($_REQUEST["id"]); |
552 | $score = sprintf("%d", $_REQUEST["score"]); | |
553 | ||
554 | $result = db_query($link, "UPDATE ttrss_user_entries SET score = '$score' | |
555 | WHERE ref_id = '$id' AND owner_uid = ".$_SESSION["uid"]); | |
556 | ||
557 | print "<rpc-reply><message>Acknowledged.</message></rpc-reply>"; | |
558 | ||
559 | return; | |
560 | ||
9bf3f101 | 561 | } */ |
546499a9 | 562 | |
aa0fa9df AD |
563 | if ($subop == "getArticles") { |
564 | $ids = split(",", db_escape_string($_REQUEST["ids"])); | |
565 | ||
566 | print "<rpc-reply>"; | |
567 | ||
568 | foreach ($ids as $id) { | |
569 | if ($id) { | |
570 | outputArticleXML($link, $id, 0, false); | |
571 | } | |
572 | } | |
573 | print "</rpc-reply>"; | |
574 | ||
575 | return; | |
576 | } | |
577 | ||
d0da85c2 AD |
578 | if ($subop == "checkDate") { |
579 | ||
580 | $date = db_escape_string($_REQUEST["date"]); | |
581 | $date_parsed = strtotime($date); | |
582 | ||
583 | print "<rpc-reply>"; | |
584 | ||
585 | if ($date_parsed) { | |
586 | print "<result>1</result>"; | |
587 | } else { | |
588 | print "<result>0</result>"; | |
589 | } | |
590 | ||
591 | print "</rpc-reply>"; | |
592 | ||
593 | return; | |
594 | } | |
595 | ||
933ba4ee AD |
596 | if ($subop == "removeFromLabel") { |
597 | ||
598 | $ids = split(",", db_escape_string($_REQUEST["ids"])); | |
599 | $label_id = db_escape_string($_REQUEST["lid"]); | |
600 | ||
7a13338b AD |
601 | $label = db_escape_string(label_find_caption($link, $label_id, |
602 | $_SESSION["uid"])); | |
933ba4ee | 603 | |
1c9c6025 AD |
604 | print "<rpc-reply>"; |
605 | print "<info-for-headlines>"; | |
606 | ||
933ba4ee AD |
607 | if ($label) { |
608 | ||
609 | foreach ($ids as $id) { | |
610 | label_remove_article($link, $id, $label, $_SESSION["uid"]); | |
1c9c6025 AD |
611 | |
612 | print "<entry id=\"$id\"><![CDATA["; | |
613 | ||
614 | $labels = get_article_labels($link, $id, $_SESSION["uid"]); | |
2eb9c95c | 615 | print format_article_labels($labels, $id); |
1c9c6025 AD |
616 | |
617 | print "]]></entry>"; | |
618 | ||
933ba4ee AD |
619 | } |
620 | } | |
621 | ||
1c9c6025 AD |
622 | print "</info-for-headlines>"; |
623 | ||
6a7817c1 AD |
624 | print "<counters><![CDATA["; |
625 | print json_encode(getAllCounters($link, $_REQUEST['omode'])); | |
626 | print "]]></counters>"; | |
1c9c6025 | 627 | print "</rpc-reply>"; |
933ba4ee AD |
628 | |
629 | return; | |
630 | } | |
631 | ||
b8a637f3 AD |
632 | if ($subop == "assignToLabel") { |
633 | ||
634 | $ids = split(",", db_escape_string($_REQUEST["ids"])); | |
635 | $label_id = db_escape_string($_REQUEST["lid"]); | |
636 | ||
7a13338b AD |
637 | $label = db_escape_string(label_find_caption($link, $label_id, |
638 | $_SESSION["uid"])); | |
b8a637f3 | 639 | |
f9247195 AD |
640 | print "<rpc-reply>"; |
641 | ||
642 | print "<info-for-headlines>"; | |
643 | ||
b8a637f3 AD |
644 | if ($label) { |
645 | ||
646 | foreach ($ids as $id) { | |
647 | label_add_article($link, $id, $label, $_SESSION["uid"]); | |
f9247195 AD |
648 | |
649 | print "<entry id=\"$id\"><![CDATA["; | |
650 | ||
651 | $labels = get_article_labels($link, $id, $_SESSION["uid"]); | |
2eb9c95c | 652 | print format_article_labels($labels, $id); |
f9247195 AD |
653 | |
654 | print "]]></entry>"; | |
655 | ||
b8a637f3 AD |
656 | } |
657 | } | |
658 | ||
f9247195 AD |
659 | print "</info-for-headlines>"; |
660 | ||
6a7817c1 AD |
661 | print "<counters><![CDATA["; |
662 | print json_encode(getAllCounters($link, $_REQUEST['omode'])); | |
663 | print "]]></counters>"; | |
f9247195 | 664 | print "</rpc-reply>"; |
b8a637f3 AD |
665 | |
666 | return; | |
667 | } | |
668 | ||
ef88b1cc | 669 | if ($subop == "updateFeedBrowser") { |
c2913898 AD |
670 | |
671 | $search = db_escape_string($_REQUEST["search"]); | |
672 | $limit = db_escape_string($_REQUEST["limit"]); | |
082ae95b | 673 | $mode = db_escape_string($_REQUEST["mode"]); |
c2913898 AD |
674 | |
675 | print "<rpc-reply>"; | |
676 | print "<content>"; | |
677 | print "<![CDATA["; | |
082ae95b | 678 | $ctr = print_feed_browser($link, $search, $limit, $mode); |
c2913898 AD |
679 | print "]]>"; |
680 | print "</content>"; | |
681 | print "<num-results value=\"$ctr\"/>"; | |
ef88b1cc | 682 | print "<mode value=\"$mode\"/>"; |
c2913898 AD |
683 | print "</rpc-reply>"; |
684 | ||
685 | return; | |
686 | } | |
687 | ||
ef88b1cc AD |
688 | |
689 | if ($subop == "massSubscribe") { | |
690 | ||
691 | $ids = split(",", db_escape_string($_REQUEST["ids"])); | |
692 | $mode = $_REQUEST["mode"]; | |
693 | ||
694 | $subscribed = array(); | |
695 | ||
696 | foreach ($ids as $id) { | |
697 | ||
698 | if ($mode == 1) { | |
699 | $result = db_query($link, "SELECT feed_url,title FROM ttrss_feeds | |
700 | WHERE id = '$id'"); | |
701 | } else if ($mode == 2) { | |
702 | $result = db_query($link, "SELECT * FROM ttrss_archived_feeds | |
703 | WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]); | |
704 | $orig_id = db_escape_string(db_fetch_result($result, 0, "id")); | |
705 | $site_url = db_escape_string(db_fetch_result($result, 0, "site_url")); | |
706 | } | |
707 | ||
708 | $feed_url = db_escape_string(db_fetch_result($result, 0, "feed_url")); | |
709 | $title = db_escape_string(db_fetch_result($result, 0, "title")); | |
710 | ||
711 | $title_orig = db_fetch_result($result, 0, "title"); | |
712 | ||
713 | $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE | |
714 | feed_url = '$feed_url' AND owner_uid = " . $_SESSION["uid"]); | |
715 | ||
716 | if (db_num_rows($result) == 0) { | |
717 | if ($mode == 1) { | |
718 | $result = db_query($link, | |
719 | "INSERT INTO ttrss_feeds (owner_uid,feed_url,title,cat_id) | |
720 | VALUES ('".$_SESSION["uid"]."', '$feed_url', '$title', NULL)"); | |
721 | } else if ($mode == 2) { | |
722 | $result = db_query($link, | |
723 | "INSERT INTO ttrss_feeds (id,owner_uid,feed_url,title,cat_id,site_url) | |
724 | VALUES ('$orig_id','".$_SESSION["uid"]."', '$feed_url', '$title', NULL, '$site_url')"); | |
725 | } | |
726 | array_push($subscribed, $title_orig); | |
727 | } | |
728 | } | |
729 | ||
730 | $num_feeds = count($subscribed); | |
731 | ||
732 | print "<rpc-reply>"; | |
733 | print "<num-feeds value='$num_feeds'/>"; | |
734 | print "</rpc-reply>"; | |
735 | ||
736 | return; | |
737 | } | |
738 | ||
87b16a0a AD |
739 | if ($subop == "download") { |
740 | $stage = (int) $_REQUEST["stage"]; | |
04870193 AD |
741 | $cidt = (int)db_escape_string($_REQUEST["cidt"]); |
742 | $cidb = (int)db_escape_string($_REQUEST["cidb"]); | |
badac687 | 743 | $sync = db_escape_string($_REQUEST["sync"]); |
51f6f917 AD |
744 | //$amount = (int) $_REQUEST["amount"]; |
745 | //$unread_only = db_escape_string($_REQUEST["unread_only"]); | |
746 | //if (!$amount) $amount = 50; | |
6a1cd591 | 747 | |
d9447516 AD |
748 | /* Amount is not used by the frontend offline.js anymore, it goes by |
749 | * date_qpart below + cidb/cidt IDs */ | |
750 | ||
04870193 | 751 | $amount = 2000; |
51f6f917 | 752 | $unread_only = true; |
87b16a0a AD |
753 | |
754 | print "<rpc-reply>"; | |
755 | ||
badac687 AD |
756 | $sync = split(";", $sync); |
757 | ||
758 | print "<sync>"; | |
759 | ||
760 | if (count($sync) > 0) { | |
761 | if (strtotime($sync[0])) { | |
762 | $last_online = db_escape_string($sync[0]); | |
763 | ||
764 | print "<sync-point><![CDATA[$last_online]]></sync-point>"; | |
765 | ||
766 | for ($i = 1; $i < count($sync); $i++) { | |
767 | $e = split(",", $sync[$i]); | |
768 | ||
769 | if (count($e) == 3) { | |
770 | ||
771 | $id = (int) $e[0]; | |
772 | $unread = bool_to_sql_bool((bool) $e[1]); | |
5b8444d3 AD |
773 | $marked = (bool)$e[2]; |
774 | ||
775 | if ($marked) { | |
776 | $marked = bool_to_sql_bool($marked); | |
777 | $marked_qpart = "marked = $marked,"; | |
778 | } | |
badac687 | 779 | |
badac687 | 780 | $query = "UPDATE ttrss_user_entries SET |
5b8444d3 | 781 | $marked_qpart |
badac687 AD |
782 | unread = $unread, |
783 | last_read = '$last_online' | |
784 | WHERE ref_id = '$id' AND | |
785 | (last_read IS NULL OR last_read < '$last_online') AND | |
786 | owner_uid = ".$_SESSION["uid"]; | |
787 | ||
788 | $result = db_query($link, $query); | |
789 | ||
492a4a6a | 790 | print "<sync-ok id=\"$id\"/>"; |
badac687 AD |
791 | |
792 | } | |
793 | } | |
7f4f9f4e AD |
794 | |
795 | /* Maybe we need to further update local DB for this client */ | |
796 | ||
492a4a6a | 797 | $query = "SELECT ref_id,unread,marked FROM ttrss_user_entries |
7f4f9f4e | 798 | WHERE last_read >= '$last_online' AND |
e6c611c5 | 799 | owner_uid = ".$_SESSION["uid"] . " LIMIT 1000"; |
7f4f9f4e AD |
800 | |
801 | $result = db_query($link, $query); | |
802 | ||
803 | while ($line = db_fetch_assoc($result)) { | |
492a4a6a AD |
804 | $unread = (int) sql_bool_to_bool($line["unread"]); |
805 | $marked = (int) sql_bool_to_bool($line["marked"]); | |
806 | ||
807 | print "<sync-ok unread=\"$unread\" marked=\"$marked\" | |
808 | id=\"".$line["ref_id"]."\"/>"; | |
7f4f9f4e AD |
809 | } |
810 | ||
badac687 AD |
811 | } |
812 | } | |
813 | ||
814 | print "</sync>"; | |
815 | ||
87b16a0a AD |
816 | if ($stage == 0) { |
817 | print "<feeds>"; | |
818 | ||
d8781c91 | 819 | $result = db_query($link, "SELECT id, title, cat_id FROM |
117335bf | 820 | ttrss_feeds WHERE owner_uid = ".$_SESSION["uid"]); |
87b16a0a AD |
821 | |
822 | while ($line = db_fetch_assoc($result)) { | |
36f78797 AD |
823 | |
824 | $has_icon = (int) feed_has_icon($line["id"]); | |
825 | ||
d8781c91 AD |
826 | print "<feed has_icon=\"$has_icon\" |
827 | cat_id=\"".(int)$line["cat_id"]."\" id=\"".$line["id"]."\"><![CDATA["; | |
87b16a0a AD |
828 | print $line["title"]; |
829 | print "]]></feed>"; | |
830 | } | |
831 | ||
832 | print "</feeds>"; | |
833 | ||
d8781c91 AD |
834 | print "<feed-categories>"; |
835 | ||
75aa83ec | 836 | $result = db_query($link, "SELECT id, title, collapsed FROM |
d8781c91 AD |
837 | ttrss_feed_categories WHERE owner_uid = ".$_SESSION["uid"]); |
838 | ||
75aa83ec | 839 | print "<category id=\"0\" collapsed=\"". |
57937c42 | 840 | (int)get_pref($link, "_COLLAPSED_UNCAT")."\"><![CDATA["; |
d8781c91 AD |
841 | print __("Uncategorized"); |
842 | print "]]></category>"; | |
843 | ||
d6416405 | 844 | print "<category id=\"-1\" collapsed=\"". |
57937c42 | 845 | (int)get_pref($link, "_COLLAPSED_SPECIAL")."\"><![CDATA["; |
d6416405 AD |
846 | print __("Special"); |
847 | print "]]></category>"; | |
848 | ||
c2726c96 | 849 | print "<category id=\"-2\" collapsed=\"". |
57937c42 | 850 | (int)get_pref($link, "_COLLAPSED_LABELS")."\"><![CDATA["; |
c2726c96 AD |
851 | print __("Labels"); |
852 | print "]]></category>"; | |
853 | ||
d8781c91 | 854 | while ($line = db_fetch_assoc($result)) { |
75aa83ec AD |
855 | print "<category |
856 | id=\"".$line["id"]."\" | |
857 | collapsed=\"".(int)sql_bool_to_bool($line["collapsed"])."\"><![CDATA["; | |
d8781c91 AD |
858 | print $line["title"]; |
859 | print "]]></category>"; | |
860 | } | |
861 | ||
862 | print "</feed-categories>"; | |
863 | ||
ed22888b AD |
864 | print "<labels>"; |
865 | ||
866 | $result = db_query($link, "SELECT * FROM | |
867 | ttrss_labels2 WHERE owner_uid = ".$_SESSION["uid"]); | |
868 | ||
869 | while ($line = db_fetch_assoc($result)) { | |
870 | print "<label | |
871 | id=\"".$line["id"]."\" | |
872 | fg_color=\"".$line["fg_color"]."\" | |
873 | bg_color=\"".$line["bg_color"]."\" | |
874 | ><![CDATA["; | |
875 | print $line["caption"]; | |
876 | print "]]></label>"; | |
877 | } | |
878 | ||
879 | ||
880 | print "</labels>"; | |
d8781c91 | 881 | |
87b16a0a AD |
882 | } |
883 | ||
6a1cd591 | 884 | if ($stage > 0) { |
6a1cd591 AD |
885 | print "<articles>"; |
886 | ||
d9447516 | 887 | $limit = 10; |
6a1cd591 AD |
888 | $skip = $limit*($stage-1); |
889 | ||
3e52ab08 AD |
890 | print "<limit value=\"$limit\"/>"; |
891 | ||
6a1cd591 AD |
892 | if ($amount > 0) $amount -= $skip; |
893 | ||
894 | if ($amount > 0) { | |
895 | ||
896 | $limit = min($limit, $amount); | |
897 | ||
898 | if ($unread_only) { | |
a400a562 | 899 | $unread_qpart = "(unread = true OR marked = true) AND "; |
6a1cd591 AD |
900 | } |
901 | ||
67eb2531 | 902 | if ($cidt && $cidb) { |
04870193 | 903 | $cid_qpart = "(ttrss_entries.id > $cidt OR ttrss_entries.id < $cidb) AND "; |
95f0c2c5 AD |
904 | } |
905 | ||
67eb2531 | 906 | if (DB_TYPE == "pgsql") { |
d9447516 | 907 | $date_qpart = "updated >= NOW() - INTERVAL '1 week' AND"; |
67eb2531 | 908 | } else { |
d9447516 | 909 | $date_qpart = "updated >= DATE_SUB(NOW(), INTERVAL 1 WEEK) AND"; |
67eb2531 AD |
910 | } |
911 | ||
6a1cd591 | 912 | $result = db_query($link, |
c1a0541a AD |
913 | "SELECT DISTINCT ttrss_entries.id,ttrss_entries.title, |
914 | guid,link,comments, | |
915 | feed_id,content,updated,unread,marked FROM | |
916 | ttrss_user_entries,ttrss_entries,ttrss_feeds | |
917 | WHERE $unread_qpart $cid_qpart $date_qpart | |
c1a0541a AD |
918 | ttrss_feeds.id = feed_id AND |
919 | ref_id = ttrss_entries.id AND | |
920 | ttrss_user_entries.owner_uid = ".$_SESSION["uid"]." | |
6a1cd591 | 921 | ORDER BY updated DESC LIMIT $limit OFFSET $skip"); |
fe8f2f0c | 922 | |
3034277a | 923 | if (function_exists('json_encode')) { |
6a2034f9 | 924 | |
3034277a AD |
925 | while ($line = db_fetch_assoc($result)) { |
926 | print "<article><![CDATA["; | |
927 | ||
928 | $line["marked"] = (int)sql_bool_to_bool($line["marked"]); | |
929 | $line["unread"] = (int)sql_bool_to_bool($line["unread"]); | |
3ab18266 | 930 | |
c2726c96 AD |
931 | $line["labels"] = get_article_labels($link, $line["id"]); |
932 | ||
3ab18266 AD |
933 | // too slow :( |
934 | // $line["tags"] = format_tags_string( | |
935 | // get_article_tags($link, $line["id"]), $line["id"]); | |
3034277a AD |
936 | |
937 | print json_encode($line); | |
938 | print "]]></article>"; | |
939 | } | |
6a1cd591 AD |
940 | } |
941 | ||
942 | } | |
943 | ||
944 | print "</articles>"; | |
945 | ||
946 | } | |
947 | ||
87b16a0a AD |
948 | print "</rpc-reply>"; |
949 | ||
950 | return; | |
951 | } | |
952 | ||
d8ea9902 AD |
953 | if ($subop == "digest-get-contents") { |
954 | $article_id = db_escape_string($_REQUEST['article_id']); | |
955 | ||
956 | $result = db_query($link, "SELECT content | |
957 | FROM ttrss_entries, ttrss_user_entries | |
958 | WHERE id = '$article_id' AND ref_id = id AND owner_uid = ".$_SESSION['uid']); | |
959 | ||
960 | print "<rpc-reply>"; | |
961 | ||
962 | print "<article id=\"$article_id\"><![CDATA["; | |
963 | ||
964 | $content = sanitize_rss($link, db_fetch_result($result, 0, "content")); | |
965 | ||
966 | print $content; | |
967 | ||
968 | print "]]></article>"; | |
969 | ||
970 | print "</rpc-reply>"; | |
971 | ||
972 | return; | |
973 | } | |
974 | ||
1ca8997b | 975 | if ($subop == "digest-update") { |
b41c2549 | 976 | $feed_id = db_escape_string($_REQUEST['feed_id']); |
1ca8997b | 977 | $offset = db_escape_string($_REQUEST['offset']); |
e4c530dc | 978 | $seq = db_escape_string($_REQUEST['seq']); |
1ca8997b | 979 | |
b41c2549 | 980 | if (!$feed_id) $feed_id = -4; |
1ca8997b | 981 | if (!$offset) $offset = 0; |
1ca8997b AD |
982 | print "<rpc-reply>"; |
983 | ||
e4c530dc AD |
984 | print "<seq>$seq</seq>"; |
985 | ||
1ca8997b | 986 | $headlines = api_get_headlines($link, $feed_id, 10, $offset, |
d8ea9902 | 987 | '', ($feed_id == -4), true, false, "unread", "updated DESC"); |
1ca8997b AD |
988 | |
989 | //function api_get_headlines($link, $feed_id, $limit, $offset, | |
990 | // $filter, $is_cat, $show_excerpt, $show_content, $view_mode) { | |
991 | ||
78ac6caf AD |
992 | print "<headlines-title><![CDATA[" . getFeedTitle($link, $feed_id) . |
993 | "]]></headlines-title>"; | |
994 | ||
1ca8997b AD |
995 | print "<headlines><![CDATA[" . json_encode($headlines) . "]]></headlines>"; |
996 | ||
997 | print "</rpc-reply>"; | |
998 | return; | |
999 | } | |
1000 | ||
1001 | if ($subop == "digest-init") { | |
911d4c08 AD |
1002 | print "<rpc-reply>"; |
1003 | ||
1004 | $tmp_feeds = api_get_feeds($link, false, true, false, 0); | |
1005 | $feeds = array(); | |
1006 | ||
1007 | foreach ($tmp_feeds as $f) { | |
b41c2549 | 1008 | if ($f['id'] > 0 || $f['id'] == -4) array_push($feeds, $f); |
911d4c08 AD |
1009 | } |
1010 | ||
911d4c08 AD |
1011 | print "<feeds><![CDATA[" . json_encode($feeds) . "]]></feeds>"; |
1012 | ||
911d4c08 AD |
1013 | print "</rpc-reply>"; |
1014 | return; | |
1015 | } | |
1016 | ||
c1b5cd23 AD |
1017 | if ($subop == "catchupFeed") { |
1018 | ||
1019 | $feed_id = db_escape_string($_REQUEST['feed_id']); | |
1020 | $is_cat = db_escape_string($_REQUEST['is_cat']); | |
1021 | ||
1022 | print "<rpc-reply>"; | |
1023 | ||
1024 | catchup_feed($link, $feed_id, $is_cat); | |
1025 | ||
1026 | print "</rpc-reply>"; | |
1027 | ||
1028 | return; | |
1029 | } | |
1030 | ||
31a53903 AD |
1031 | if ($subop == "sendEmail") { |
1032 | $secretkey = $_REQUEST['secretkey']; | |
1033 | ||
1034 | print "<rpc-reply>"; | |
1035 | ||
1036 | if (DIGEST_ENABLE && $_SESSION['email_secretkey'] && | |
1037 | $secretkey == $_SESSION['email_secretkey']) { | |
1038 | ||
1039 | $_SESSION['email_secretkey'] = ''; | |
1040 | ||
1041 | $destination = $_REQUEST['destination']; | |
1042 | $subject = $_REQUEST['subject']; | |
1043 | $content = $_REQUEST['content']; | |
1044 | ||
1045 | $replyto = strip_tags($_SESSION['email_replyto']); | |
1046 | $fromname = strip_tags($_SESSION['email_fromname']); | |
1047 | ||
1048 | $mail = new PHPMailer(); | |
1049 | ||
1050 | $mail->PluginDir = "lib/phpmailer/"; | |
1051 | $mail->SetLanguage("en", "lib/phpmailer/language/"); | |
1052 | ||
1053 | $mail->CharSet = "UTF-8"; | |
1054 | ||
1055 | $mail->From = $replyto; | |
1056 | $mail->FromName = $fromname; | |
1057 | $mail->AddAddress($destination); | |
1058 | ||
1059 | if (DIGEST_SMTP_HOST) { | |
1060 | $mail->Host = DIGEST_SMTP_HOST; | |
1061 | $mail->Mailer = "smtp"; | |
1062 | $mail->SMTPAuth = DIGEST_SMTP_LOGIN != ''; | |
1063 | $mail->Username = DIGEST_SMTP_LOGIN; | |
1064 | $mail->Password = DIGEST_SMTP_PASSWORD; | |
1065 | } | |
1066 | ||
1067 | $mail->IsHTML(false); | |
1068 | $mail->Subject = $subject; | |
1069 | $mail->Body = $content; | |
1070 | ||
1071 | $rc = $mail->Send(); | |
1072 | ||
1073 | if (!$rc) { | |
1074 | print "<error><![CDATA[" . $mail->ErrorInfo . "]]></error>"; | |
1075 | } else { | |
1076 | save_email_address($link, db_escape_string($destination)); | |
1077 | print "<message>OK</message>"; | |
1078 | } | |
1079 | ||
1080 | } else { | |
1081 | print "<error>Not authorized.</error>"; | |
1082 | } | |
1083 | ||
1084 | print "</rpc-reply>"; | |
1085 | ||
1086 | return; | |
1087 | } | |
1088 | ||
1089 | if ($subop == "completeEmails") { | |
1090 | ||
1091 | $search = db_escape_string($_REQUEST["search"]); | |
1092 | ||
1093 | print "<ul>"; | |
1094 | ||
1095 | foreach ($_SESSION['stored_emails'] as $email) { | |
1096 | if (strpos($email, $search) !== false) { | |
1097 | print "<li>$email</li>"; | |
1098 | } | |
1099 | } | |
1100 | ||
1101 | print "</ul>"; | |
1102 | ||
1103 | return; | |
1104 | } | |
1105 | ||
5c7c7da9 AD |
1106 | if ($subop == "quickAddCat") { |
1107 | print "<rpc-reply>"; | |
1108 | ||
1109 | $cat = db_escape_string($_REQUEST["cat"]); | |
1110 | ||
1111 | add_feed_category($link, $cat); | |
1112 | ||
1113 | $result = db_query($link, "SELECT id FROM ttrss_feed_categories WHERE | |
1114 | title = '$cat' AND owner_uid = " . $_SESSION["uid"]); | |
1115 | ||
1116 | if (db_num_rows($result) == 1) { | |
1117 | $id = db_fetch_result($result, 0, "id"); | |
1118 | } else { | |
1119 | $id = 0; | |
1120 | } | |
1121 | ||
5c7c7da9 | 1122 | print_feed_cat_select($link, "cat_id", $id); |
5c7c7da9 AD |
1123 | |
1124 | print "</rpc-reply>"; | |
1125 | ||
1126 | return; | |
1127 | } | |
1128 | ||
8801fb01 AD |
1129 | if ($subop == "regenFeedKey") { |
1130 | $feed_id = db_escape_string($_REQUEST['id']); | |
1131 | $is_cat = (bool) db_escape_string($_REQUEST['is_cat']); | |
1132 | ||
1133 | print "<rpc-reply>"; | |
1134 | ||
1135 | $new_key = update_feed_access_key($link, $feed_id, $is_cat); | |
1136 | ||
1137 | print "<link><![CDATA[$new_key]]></link>"; | |
1138 | ||
1139 | print "</rpc-reply>"; | |
1140 | ||
1141 | return; | |
1142 | } | |
1143 | ||
8d86f15f AD |
1144 | if ($subop == "clearKeys") { |
1145 | ||
1146 | db_query($link, "DELETE FROM ttrss_access_keys WHERE | |
1147 | owner_uid = " . $_SESSION["uid"]); | |
1148 | ||
1149 | print "<rpc-reply><message>OK</message></rpc-reply>"; | |
1150 | ||
1151 | return; | |
1152 | } | |
1153 | ||
85bd574b | 1154 | print "<rpc-reply><error>Unknown method: $subop</error></rpc-reply>"; |
01b3e191 AD |
1155 | } |
1156 | ?> |