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