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