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