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