]>
git.wh0rd.org - tt-rss.git/blob - classes/api.php
2 class API
extends Handler
{
11 static function param_to_bool($p) {
12 return $p && ($p !== "f" && $p !== "false");
15 function before($method) {
16 if (parent
::before($method)) {
17 header("Content-Type: text/json");
19 if (!$_SESSION["uid"] && $method != "login" && $method != "isloggedin") {
20 $this->wrap(self
::STATUS_ERR
, array("error" => 'NOT_LOGGED_IN'));
24 if ($_SESSION["uid"] && $method != "logout" && !get_pref('ENABLE_API_ACCESS')) {
25 $this->wrap(self
::STATUS_ERR
, array("error" => 'API_DISABLED'));
29 $this->seq
= (int) clean($_REQUEST['seq']);
36 function wrap($status, $reply) {
37 print json_encode(array("seq" => $this->seq
,
39 "content" => $reply));
42 function getVersion() {
43 $rv = array("version" => VERSION
);
44 $this->wrap(self
::STATUS_OK
, $rv);
47 function getApiLevel() {
48 $rv = array("level" => self
::API_LEVEL
);
49 $this->wrap(self
::STATUS_OK
, $rv);
56 $login = clean($_REQUEST["user"]);
57 $password = clean($_REQUEST["password"]);
58 $password_base64 = base64_decode(clean($_REQUEST["password"]));
60 if (SINGLE_USER_MODE
) $login = "admin";
62 $sth = $this->pdo
->prepare("SELECT id FROM ttrss_users WHERE login = ?");
63 $sth->execute([$login]);
65 if ($row = $sth->fetch()) {
72 $this->wrap(self
::STATUS_ERR
, array("error" => "LOGIN_ERROR"));
76 if (get_pref("ENABLE_API_ACCESS", $uid)) {
77 if (authenticate_user($login, $password)) { // try login with normal password
78 $this->wrap(self
::STATUS_OK
, array("session_id" => session_id(),
79 "api_level" => self
::API_LEVEL
));
80 } else if (authenticate_user($login, $password_base64)) { // else try with base64_decoded password
81 $this->wrap(self
::STATUS_OK
, array("session_id" => session_id(),
82 "api_level" => self
::API_LEVEL
));
83 } else { // else we are not logged in
84 user_error("Failed login attempt for $login from {$_SERVER['REMOTE_ADDR']}", E_USER_WARNING
);
85 $this->wrap(self
::STATUS_ERR
, array("error" => "LOGIN_ERROR"));
88 $this->wrap(self
::STATUS_ERR
, array("error" => "API_DISABLED"));
95 $this->wrap(self
::STATUS_OK
, array("status" => "OK"));
98 function isLoggedIn() {
99 $this->wrap(self
::STATUS_OK
, array("status" => $_SESSION["uid"] != ''));
102 function getUnread() {
103 $feed_id = clean($_REQUEST["feed_id"]);
104 $is_cat = clean($_REQUEST["is_cat"]);
107 $this->wrap(self
::STATUS_OK
, array("unread" => getFeedUnread($feed_id, $is_cat)));
109 $this->wrap(self
::STATUS_OK
, array("unread" => Feeds
::getGlobalUnread()));
113 /* Method added for ttrss-reader for Android */
114 function getCounters() {
115 $this->wrap(self
::STATUS_OK
, Counters
::getAllCounters());
118 function getFeeds() {
119 $cat_id = clean($_REQUEST["cat_id"]);
120 $unread_only = API
::param_to_bool(clean($_REQUEST["unread_only"]));
121 $limit = (int) clean($_REQUEST["limit"]);
122 $offset = (int) clean($_REQUEST["offset"]);
123 $include_nested = API
::param_to_bool(clean($_REQUEST["include_nested"]));
125 $feeds = $this->api_get_feeds($cat_id, $unread_only, $limit, $offset, $include_nested);
127 $this->wrap(self
::STATUS_OK
, $feeds);
130 function getCategories() {
131 $unread_only = API
::param_to_bool(clean($_REQUEST["unread_only"]));
132 $enable_nested = API
::param_to_bool(clean($_REQUEST["enable_nested"]));
133 $include_empty = API
::param_to_bool(clean($_REQUEST['include_empty']));
135 // TODO do not return empty categories, return Uncategorized and standard virtual cats
138 $nested_qpart = "parent_cat IS NULL";
140 $nested_qpart = "true";
142 $sth = $this->pdo
->prepare("SELECT
143 id, title, order_id, (SELECT COUNT(id) FROM
145 ttrss_feed_categories.id IS NOT NULL AND cat_id = ttrss_feed_categories.id) AS num_feeds,
146 (SELECT COUNT(id) FROM
147 ttrss_feed_categories AS c2 WHERE
148 c2.parent_cat = ttrss_feed_categories.id) AS num_cats
149 FROM ttrss_feed_categories
150 WHERE $nested_qpart AND owner_uid = ?");
151 $sth->execute([$_SESSION['uid']]);
155 while ($line = $sth->fetch()) {
156 if ($include_empty ||
$line["num_feeds"] > 0 ||
$line["num_cats"] > 0) {
157 $unread = getFeedUnread($line["id"], true);
160 $unread +
= Feeds
::getCategoryChildrenUnread($line["id"]);
162 if ($unread ||
!$unread_only) {
163 array_push($cats, array("id" => $line["id"],
164 "title" => $line["title"],
166 "order_id" => (int) $line["order_id"],
172 foreach (array(-2,-1,0) as $cat_id) {
173 if ($include_empty ||
!$this->isCategoryEmpty($cat_id)) {
174 $unread = getFeedUnread($cat_id, true);
176 if ($unread ||
!$unread_only) {
177 array_push($cats, array("id" => $cat_id,
178 "title" => Feeds
::getCategoryTitle($cat_id),
179 "unread" => $unread));
184 $this->wrap(self
::STATUS_OK
, $cats);
187 function getHeadlines() {
188 $feed_id = clean($_REQUEST["feed_id"]);
189 if ($feed_id != "") {
191 if (is_numeric($feed_id)) $feed_id = (int) $feed_id;
193 $limit = (int)clean($_REQUEST["limit"]);
195 if (!$limit ||
$limit >= 200) $limit = 200;
197 $offset = (int)clean($_REQUEST["skip"]);
198 $filter = clean($_REQUEST["filter"]);
199 $is_cat = API
::param_to_bool(clean($_REQUEST["is_cat"]));
200 $show_excerpt = API
::param_to_bool(clean($_REQUEST["show_excerpt"]));
201 $show_content = API
::param_to_bool(clean($_REQUEST["show_content"]));
202 /* all_articles, unread, adaptive, marked, updated */
203 $view_mode = clean($_REQUEST["view_mode"]);
204 $include_attachments = API
::param_to_bool(clean($_REQUEST["include_attachments"]));
205 $since_id = (int)clean($_REQUEST["since_id"]);
206 $include_nested = API
::param_to_bool(clean($_REQUEST["include_nested"]));
207 $sanitize_content = !isset($_REQUEST["sanitize"]) ||
208 API
::param_to_bool($_REQUEST["sanitize"]);
209 $force_update = API
::param_to_bool(clean($_REQUEST["force_update"]));
210 $has_sandbox = API
::param_to_bool(clean($_REQUEST["has_sandbox"]));
211 $excerpt_length = (int)clean($_REQUEST["excerpt_length"]);
212 $check_first_id = (int)clean($_REQUEST["check_first_id"]);
213 $include_header = API
::param_to_bool(clean($_REQUEST["include_header"]));
215 $_SESSION['hasSandbox'] = $has_sandbox;
217 $skip_first_id_check = false;
219 $override_order = false;
220 switch (clean($_REQUEST["order_by"])) {
222 $override_order = "ttrss_entries.title, date_entered, updated";
225 $override_order = "score DESC, date_entered, updated";
226 $skip_first_id_check = true;
229 $override_order = "updated DESC";
233 /* do not rely on params below */
235 $search = clean($_REQUEST["search"]);
237 list($headlines, $headlines_header) = $this->api_get_headlines($feed_id, $limit, $offset,
238 $filter, $is_cat, $show_excerpt, $show_content, $view_mode, $override_order,
239 $include_attachments, $since_id, $search,
240 $include_nested, $sanitize_content, $force_update, $excerpt_length, $check_first_id, $skip_first_id_check);
242 if ($include_header) {
243 $this->wrap(self
::STATUS_OK
, array($headlines_header, $headlines));
245 $this->wrap(self
::STATUS_OK
, $headlines);
248 $this->wrap(self
::STATUS_ERR
, array("error" => 'INCORRECT_USAGE'));
252 function updateArticle() {
253 $article_ids = explode(",", clean($_REQUEST["article_ids"]));
254 $mode = (int) clean($_REQUEST["mode"]);
255 $data = clean($_REQUEST["data"]);
256 $field_raw = (int)clean($_REQUEST["field"]);
261 switch ($field_raw) {
264 $additional_fields = ",last_marked = NOW()";
267 $field = "published";
268 $additional_fields = ",last_published = NOW()";
272 $additional_fields = ",last_read = NOW()";
286 $set_to = "NOT $field";
290 if ($field == "note") $set_to = $this->pdo
->quote($data);
292 if ($field && $set_to && count($article_ids) > 0) {
294 $article_qmarks = arr_qmarks($article_ids);
296 $sth = $this->pdo
->prepare("UPDATE ttrss_user_entries SET
297 $field = $set_to $additional_fields
298 WHERE ref_id IN ($article_qmarks) AND owner_uid = ?");
299 $sth->execute(array_merge($article_ids, [$_SESSION['uid']]));
301 $num_updated = $sth->rowCount();
303 if ($num_updated > 0 && $field == "unread") {
304 $sth = $this->pdo
->prepare("SELECT DISTINCT feed_id FROM ttrss_user_entries
305 WHERE ref_id IN ($article_qmarks)");
306 $sth->execute($article_ids);
308 while ($line = $sth->fetch()) {
309 CCache
::update($line["feed_id"], $_SESSION["uid"]);
313 $this->wrap(self
::STATUS_OK
, array("status" => "OK",
314 "updated" => $num_updated));
317 $this->wrap(self
::STATUS_ERR
, array("error" => 'INCORRECT_USAGE'));
322 function getArticle() {
324 $article_ids = explode(",", clean($_REQUEST["article_id"]));
325 $sanitize_content = !isset($_REQUEST["sanitize"]) ||
326 API
::param_to_bool($_REQUEST["sanitize"]);
330 $article_qmarks = arr_qmarks($article_ids);
332 $sth = $this->pdo
->prepare("SELECT id,guid,title,link,content,feed_id,comments,int_id,
333 marked,unread,published,score,note,lang,
334 ".SUBSTRING_FOR_DATE
."(updated,1,16) as updated,
335 author,(SELECT title FROM ttrss_feeds WHERE id = feed_id) AS feed_title,
336 (SELECT site_url FROM ttrss_feeds WHERE id = feed_id) AS site_url,
337 (SELECT hide_images FROM ttrss_feeds WHERE id = feed_id) AS hide_images
338 FROM ttrss_entries,ttrss_user_entries
339 WHERE id IN ($article_qmarks) AND ref_id = id AND owner_uid = ?");
341 $sth->execute(array_merge($article_ids, [$_SESSION['uid']]));
345 while ($line = $sth->fetch()) {
347 $attachments = Article
::get_article_enclosures($line['id']);
351 "guid" => $line["guid"],
352 "title" => $line["title"],
353 "link" => $line["link"],
354 "labels" => Article
::get_article_labels($line['id']),
355 "unread" => API
::param_to_bool($line["unread"]),
356 "marked" => API
::param_to_bool($line["marked"]),
357 "published" => API
::param_to_bool($line["published"]),
358 "comments" => $line["comments"],
359 "author" => $line["author"],
360 "updated" => (int) strtotime($line["updated"]),
361 "feed_id" => $line["feed_id"],
362 "attachments" => $attachments,
363 "score" => (int)$line["score"],
364 "feed_title" => $line["feed_title"],
365 "note" => $line["note"],
366 "lang" => $line["lang"]
369 if ($sanitize_content) {
370 $article["content"] = sanitize(
372 API
::param_to_bool($line['hide_images']),
373 false, $line["site_url"], false, $line["id"]);
375 $article["content"] = $line["content"];
378 foreach (PluginHost
::getInstance()->get_hooks(PluginHost
::HOOK_RENDER_ARTICLE_API
) as $p) {
379 $article = $p->hook_render_article_api(array("article" => $article));
382 array_push($articles, $article);
386 $this->wrap(self
::STATUS_OK
, $articles);
388 $this->wrap(self
::STATUS_ERR
, array("error" => 'INCORRECT_USAGE'));
392 function getConfig() {
394 "icons_dir" => ICONS_DIR
,
395 "icons_url" => ICONS_URL
);
397 $config["daemon_is_running"] = file_is_locked("update_daemon.lock");
399 $sth = $this->pdo
->prepare("SELECT COUNT(*) AS cf FROM
400 ttrss_feeds WHERE owner_uid = ?");
401 $sth->execute([$_SESSION['uid']]);
402 $row = $sth->fetch();
404 $config["num_feeds"] = $row["cf"];
406 $this->wrap(self
::STATUS_OK
, $config);
409 function updateFeed() {
410 $feed_id = (int) clean($_REQUEST["feed_id"]);
412 if (!ini_get("open_basedir")) {
413 RSSUtils
::update_rss_feed($feed_id);
416 $this->wrap(self
::STATUS_OK
, array("status" => "OK"));
419 function catchupFeed() {
420 $feed_id = clean($_REQUEST["feed_id"]);
421 $is_cat = clean($_REQUEST["is_cat"]);
423 Feeds
::catchup_feed($feed_id, $is_cat);
425 $this->wrap(self
::STATUS_OK
, array("status" => "OK"));
429 $pref_name = clean($_REQUEST["pref_name"]);
431 $this->wrap(self
::STATUS_OK
, array("value" => get_pref($pref_name)));
434 function getLabels() {
435 $article_id = (int)clean($_REQUEST['article_id']);
439 $sth = $this->pdo
->prepare("SELECT id, caption, fg_color, bg_color
441 WHERE owner_uid = ? ORDER BY caption");
442 $sth->execute([$_SESSION['uid']]);
445 $article_labels = Article
::get_article_labels($article_id);
447 $article_labels = array();
449 while ($line = $sth->fetch()) {
452 foreach ($article_labels as $al) {
453 if (Labels
::feed_to_label_id($al[0]) == $line['id']) {
459 array_push($rv, array(
460 "id" => (int)Labels
::label_to_feed_id($line['id']),
461 "caption" => $line['caption'],
462 "fg_color" => $line['fg_color'],
463 "bg_color" => $line['bg_color'],
464 "checked" => $checked));
467 $this->wrap(self
::STATUS_OK
, $rv);
470 function setArticleLabel() {
472 $article_ids = explode(",", clean($_REQUEST["article_ids"]));
473 $label_id = (int) clean($_REQUEST['label_id']);
474 $assign = API
::param_to_bool(clean($_REQUEST['assign']));
476 $label = Labels
::find_caption(Labels
::feed_to_label_id($label_id), $_SESSION["uid"]);
482 foreach ($article_ids as $id) {
485 Labels
::add_article($id, $label, $_SESSION["uid"]);
487 Labels
::remove_article($id, $label, $_SESSION["uid"]);
494 $this->wrap(self
::STATUS_OK
, array("status" => "OK",
495 "updated" => $num_updated));
499 function index($method) {
500 $plugin = PluginHost
::getInstance()->get_api_method(strtolower($method));
502 if ($plugin && method_exists($plugin, $method)) {
503 $reply = $plugin->$method();
505 $this->wrap($reply[0], $reply[1]);
508 $this->wrap(self
::STATUS_ERR
, array("error" => 'UNKNOWN_METHOD', "method" => $method));
512 function shareToPublished() {
513 $title = strip_tags(clean($_REQUEST["title"]));
514 $url = strip_tags(clean($_REQUEST["url"]));
515 $content = strip_tags(clean($_REQUEST["content"]));
517 if (Article
::create_published_article($title, $url, $content, "", $_SESSION["uid"])) {
518 $this->wrap(self
::STATUS_OK
, array("status" => 'OK'));
520 $this->wrap(self
::STATUS_ERR
, array("error" => 'Publishing failed'));
524 static function api_get_feeds($cat_id, $unread_only, $limit, $offset, $include_nested = false) {
530 $limit = (int) $limit;
531 $offset = (int) $offset;
532 $cat_id = (int) $cat_id;
536 if ($cat_id == -4 ||
$cat_id == -2) {
537 $counters = Counters
::getLabelCounters(true);
539 foreach (array_values($counters) as $cv) {
541 $unread = $cv["counter"];
543 if ($unread ||
!$unread_only) {
546 "id" => (int) $cv["id"],
547 "title" => $cv["description"],
548 "unread" => $cv["counter"],
552 array_push($feeds, $row);
559 if ($cat_id == -4 ||
$cat_id == -1) {
560 foreach (array(-1, -2, -3, -4, -6, 0) as $i) {
561 $unread = getFeedUnread($i);
563 if ($unread ||
!$unread_only) {
564 $title = Feeds
::getFeedTitle($i);
572 array_push($feeds, $row);
580 if ($include_nested && $cat_id) {
581 $sth = $pdo->prepare("SELECT
582 id, title, order_id FROM ttrss_feed_categories
583 WHERE parent_cat = ? AND owner_uid = ? ORDER BY id, title");
585 $sth->execute([$cat_id, $_SESSION['uid']]);
587 while ($line = $sth->fetch()) {
588 $unread = getFeedUnread($line["id"], true) +
589 Feeds
::getCategoryChildrenUnread($line["id"]);
591 if ($unread ||
!$unread_only) {
593 "id" => (int) $line["id"],
594 "title" => $line["title"],
597 "order_id" => (int) $line["order_id"]
599 array_push($feeds, $row);
607 $limit_qpart = "LIMIT $limit OFFSET $offset";
612 if ($cat_id == -4 ||
$cat_id == -3) {
613 $sth = $pdo->prepare("SELECT
614 id, feed_url, cat_id, title, order_id, ".
615 SUBSTRING_FOR_DATE
."(last_updated,1,19) AS last_updated
616 FROM ttrss_feeds WHERE owner_uid = ?
617 ORDER BY cat_id, title " . $limit_qpart);
618 $sth->execute([$_SESSION['uid']]);
622 $sth = $pdo->prepare("SELECT
623 id, feed_url, cat_id, title, order_id, ".
624 SUBSTRING_FOR_DATE
."(last_updated,1,19) AS last_updated
625 FROM ttrss_feeds WHERE
626 (cat_id = :cat OR (:cat = 0 AND cat_id IS NULL))
628 ORDER BY cat_id, title " . $limit_qpart);
629 $sth->execute([":uid" => $_SESSION['uid'], ":cat" => $cat_id]);
632 while ($line = $sth->fetch()) {
634 $unread = getFeedUnread($line["id"]);
636 $has_icon = Feeds
::feedHasIcon($line['id']);
638 if ($unread ||
!$unread_only) {
641 "feed_url" => $line["feed_url"],
642 "title" => $line["title"],
643 "id" => (int)$line["id"],
644 "unread" => (int)$unread,
645 "has_icon" => $has_icon,
646 "cat_id" => (int)$line["cat_id"],
647 "last_updated" => (int) strtotime($line["last_updated"]),
648 "order_id" => (int) $line["order_id"],
651 array_push($feeds, $row);
659 * @SuppressWarnings(PHPMD.UnusedFormalParameter)
661 static function api_get_headlines($feed_id, $limit, $offset,
662 $filter, $is_cat, $show_excerpt, $show_content, $view_mode, $order,
663 $include_attachments, $since_id,
664 $search = "", $include_nested = false, $sanitize_content = true,
665 $force_update = false, $excerpt_length = 100, $check_first_id = false, $skip_first_id_check = false) {
669 if ($force_update && $feed_id > 0 && is_numeric($feed_id)) {
670 // Update the feed if required with some basic flood control
672 $sth = $pdo->prepare(
673 "SELECT cache_images,".SUBSTRING_FOR_DATE
."(last_updated,1,19) AS last_updated
674 FROM ttrss_feeds WHERE id = ?");
675 $sth->execute([$feed_id]);
677 if ($row = $sth->fetch()) {
678 $last_updated = strtotime($row["last_updated"]);
679 $cache_images = API
::param_to_bool($row["cache_images"]);
681 if (!$cache_images && time() - $last_updated > 120) {
682 RSSUtils
::update_rss_feed($feed_id, true);
684 $sth = $pdo->prepare("UPDATE ttrss_feeds SET last_updated = '1970-01-01', last_update_started = '1970-01-01'
686 $sth->execute([$feed_id]);
694 "view_mode" => $view_mode,
695 "cat_view" => $is_cat,
697 "override_order" => $order,
699 "since_id" => $since_id,
700 "include_children" => $include_nested,
701 "check_first_id" => $check_first_id,
702 "skip_first_id_check" => $skip_first_id_check
705 $qfh_ret = Feeds
::queryFeedHeadlines($params);
707 $result = $qfh_ret[0];
708 $feed_title = $qfh_ret[1];
709 $first_id = $qfh_ret[6];
711 $headlines = array();
713 $headlines_header = array(
715 'first_id' => $first_id,
716 'is_cat' => $is_cat);
718 if (!is_numeric($result)) {
719 while ($line = $result->fetch()) {
720 $line["content_preview"] = truncate_string(strip_tags($line["content"]), $excerpt_length);
721 foreach (PluginHost
::getInstance()->get_hooks(PluginHost
::HOOK_QUERY_HEADLINES
) as $p) {
722 $line = $p->hook_query_headlines($line, $excerpt_length, true);
725 $is_updated = ($line["last_read"] == "" &&
726 ($line["unread"] != "t" && $line["unread"] != "1"));
728 $tags = explode(",", $line["tag_cache"]);
730 $label_cache = $line["label_cache"];
734 $label_cache = json_decode($label_cache, true);
737 if ($label_cache["no-labels"] == 1)
740 $labels = $label_cache;
744 if (!is_array($labels)) $labels = Article
::get_article_labels($line["id"]);
746 $headline_row = array(
747 "id" => (int)$line["id"],
748 "guid" => $line["guid"],
749 "unread" => API
::param_to_bool($line["unread"]),
750 "marked" => API
::param_to_bool($line["marked"]),
751 "published" => API
::param_to_bool($line["published"]),
752 "updated" => (int)strtotime($line["updated"]),
753 "is_updated" => $is_updated,
754 "title" => $line["title"],
755 "link" => $line["link"],
756 "feed_id" => $line["feed_id"],
760 if ($include_attachments)
761 $headline_row['attachments'] = Article
::get_article_enclosures(
765 $headline_row["excerpt"] = $line["content_preview"];
769 if ($sanitize_content) {
770 $headline_row["content"] = sanitize(
772 API
::param_to_bool($line['hide_images']),
773 false, $line["site_url"], false, $line["id"]);
775 $headline_row["content"] = $line["content"];
779 // unify label output to ease parsing
780 if ($labels["no-labels"] == 1) $labels = array();
782 $headline_row["labels"] = $labels;
784 $headline_row["feed_title"] = $line["feed_title"] ?
$line["feed_title"] :
787 $headline_row["comments_count"] = (int)$line["num_comments"];
788 $headline_row["comments_link"] = $line["comments"];
790 $headline_row["always_display_attachments"] = API
::param_to_bool($line["always_display_enclosures"]);
792 $headline_row["author"] = $line["author"];
794 $headline_row["score"] = (int)$line["score"];
795 $headline_row["note"] = $line["note"];
796 $headline_row["lang"] = $line["lang"];
798 foreach (PluginHost
::getInstance()->get_hooks(PluginHost
::HOOK_RENDER_ARTICLE_API
) as $p) {
799 $headline_row = $p->hook_render_article_api(array("headline" => $headline_row));
802 array_push($headlines, $headline_row);
804 } else if (is_numeric($result) && $result == -1) {
805 $headlines_header['first_id_changed'] = true;
808 return array($headlines, $headlines_header);
811 function unsubscribeFeed() {
812 $feed_id = (int) clean($_REQUEST["feed_id"]);
814 $sth = $this->pdo
->prepare("SELECT id FROM ttrss_feeds WHERE
815 id = ? AND owner_uid = ?");
816 $sth->execute([$feed_id, $_SESSION['uid']]);
818 if ($row = $sth->fetch()) {
819 Pref_Feeds
::remove_feed($feed_id, $_SESSION["uid"]);
820 $this->wrap(self
::STATUS_OK
, array("status" => "OK"));
822 $this->wrap(self
::STATUS_ERR
, array("error" => "FEED_NOT_FOUND"));
826 function subscribeToFeed() {
827 $feed_url = clean($_REQUEST["feed_url"]);
828 $category_id = (int) clean($_REQUEST["category_id"]);
829 $login = clean($_REQUEST["login"]);
830 $password = clean($_REQUEST["password"]);
833 $rc = Feeds
::subscribe_to_feed($feed_url, $category_id, $login, $password);
835 $this->wrap(self
::STATUS_OK
, array("status" => $rc));
837 $this->wrap(self
::STATUS_ERR
, array("error" => 'INCORRECT_USAGE'));
841 function getFeedTree() {
842 $include_empty = API
::param_to_bool(clean($_REQUEST['include_empty']));
844 $pf = new Pref_Feeds($_REQUEST);
846 $_REQUEST['mode'] = 2;
847 $_REQUEST['force_show_empty'] = $include_empty;
850 $data = $pf->makefeedtree();
851 $this->wrap(self
::STATUS_OK
, array("categories" => $data));
853 $this->wrap(self
::STATUS_ERR
, array("error" =>
854 'UNABLE_TO_INSTANTIATE_OBJECT'));
859 // only works for labels or uncategorized for the time being
860 private function isCategoryEmpty($id) {
863 $sth = $this->pdo
->prepare("SELECT COUNT(id) AS count FROM ttrss_labels2
864 WHERE owner_uid = ?");
865 $sth->execute([$_SESSION['uid']]);
866 $row = $sth->fetch();
868 return $row["count"] == 0;
870 } else if ($id == 0) {
871 $sth = $this->pdo
->prepare("SELECT COUNT(id) AS count FROM ttrss_feeds
872 WHERE cat_id IS NULL AND owner_uid = ?");
873 $sth->execute([$_SESSION['uid']]);
874 $row = $sth->fetch();
876 return $row["count"] == 0;