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