]>
git.wh0rd.org - tt-rss.git/blob - classes/api.php
8ffa74d9e2f87914c17ca54f31fdf1d9e787f564
2 class API
extends Handler
{
11 function before($method) {
12 if (parent
::before($method)) {
13 header("Content-Type: text/json");
15 if (!$_SESSION["uid"] && $method != "login" && $method != "isloggedin") {
16 $this->wrap(self
::STATUS_ERR
, array("error" => 'NOT_LOGGED_IN'));
20 if ($_SESSION["uid"] && $method != "logout" && !get_pref('ENABLE_API_ACCESS')) {
21 $this->wrap(self
::STATUS_ERR
, array("error" => 'API_DISABLED'));
25 $this->seq
= (int) $_REQUEST['seq'];
32 function wrap($status, $reply) {
33 print json_encode(array("seq" => $this->seq
,
35 "content" => $reply));
38 function getVersion() {
39 $rv = array("version" => VERSION
);
40 $this->wrap(self
::STATUS_OK
, $rv);
43 function getApiLevel() {
44 $rv = array("level" => self
::API_LEVEL
);
45 $this->wrap(self
::STATUS_OK
, $rv);
52 $login = $_REQUEST["user"];
53 $password = $_REQUEST["password"];
54 $password_base64 = base64_decode($_REQUEST["password"]);
56 if (SINGLE_USER_MODE
) $login = "admin";
58 $sth = $this->pdo
->prepare("SELECT id FROM ttrss_users WHERE login = ?");
59 $sth->execute([$login]);
61 if ($row = $sth->fetch()) {
68 $this->wrap(self
::STATUS_ERR
, array("error" => "LOGIN_ERROR"));
72 if (get_pref("ENABLE_API_ACCESS", $uid)) {
73 if (authenticate_user($login, $password)) { // try login with normal password
74 $this->wrap(self
::STATUS_OK
, array("session_id" => session_id(),
75 "api_level" => self
::API_LEVEL
));
76 } else if (authenticate_user($login, $password_base64)) { // else try with base64_decoded password
77 $this->wrap(self
::STATUS_OK
, array("session_id" => session_id(),
78 "api_level" => self
::API_LEVEL
));
79 } else { // else we are not logged in
80 user_error("Failed login attempt for $login from {$_SERVER['REMOTE_ADDR']}", E_USER_WARNING
);
81 $this->wrap(self
::STATUS_ERR
, array("error" => "LOGIN_ERROR"));
84 $this->wrap(self
::STATUS_ERR
, array("error" => "API_DISABLED"));
91 $this->wrap(self
::STATUS_OK
, array("status" => "OK"));
94 function isLoggedIn() {
95 $this->wrap(self
::STATUS_OK
, array("status" => $_SESSION["uid"] != ''));
98 function getUnread() {
99 $feed_id = $_REQUEST["feed_id"];
100 $is_cat = $_REQUEST["is_cat"];
103 $this->wrap(self
::STATUS_OK
, array("unread" => getFeedUnread($feed_id, $is_cat)));
105 $this->wrap(self
::STATUS_OK
, array("unread" => Feeds
::getGlobalUnread()));
109 /* Method added for ttrss-reader for Android */
110 function getCounters() {
111 $this->wrap(self
::STATUS_OK
, Counters
::getAllCounters());
114 function getFeeds() {
115 $cat_id = $_REQUEST["cat_id"];
116 $unread_only = sql_bool_to_bool($_REQUEST["unread_only"]);
117 $limit = (int) $_REQUEST["limit"];
118 $offset = (int) $_REQUEST["offset"];
119 $include_nested = sql_bool_to_bool($_REQUEST["include_nested"]);
121 $feeds = $this->api_get_feeds($cat_id, $unread_only, $limit, $offset, $include_nested);
123 $this->wrap(self
::STATUS_OK
, $feeds);
126 function getCategories() {
127 $unread_only = sql_bool_to_bool($_REQUEST["unread_only"]);
128 $enable_nested = sql_bool_to_bool($_REQUEST["enable_nested"]);
129 $include_empty = sql_bool_to_bool($_REQUEST['include_empty']);
131 // TODO do not return empty categories, return Uncategorized and standard virtual cats
134 $nested_qpart = "parent_cat IS NULL";
136 $nested_qpart = "true";
138 $sth = $this->pdo
->prepare("SELECT
139 id, title, order_id, (SELECT COUNT(id) FROM
141 ttrss_feed_categories.id IS NOT NULL AND cat_id = ttrss_feed_categories.id) AS num_feeds,
142 (SELECT COUNT(id) FROM
143 ttrss_feed_categories AS c2 WHERE
144 c2.parent_cat = ttrss_feed_categories.id) AS num_cats
145 FROM ttrss_feed_categories
146 WHERE $nested_qpart AND owner_uid = ?");
147 $sth->execute([$_SESSION['uid']]);
151 while ($line = $sth->fetch()) {
152 if ($include_empty ||
$line["num_feeds"] > 0 ||
$line["num_cats"] > 0) {
153 $unread = getFeedUnread($line["id"], true);
156 $unread +
= Feeds
::getCategoryChildrenUnread($line["id"]);
158 if ($unread ||
!$unread_only) {
159 array_push($cats, array("id" => $line["id"],
160 "title" => $line["title"],
162 "order_id" => (int) $line["order_id"],
168 foreach (array(-2,-1,0) as $cat_id) {
169 if ($include_empty ||
!$this->isCategoryEmpty($cat_id)) {
170 $unread = getFeedUnread($cat_id, true);
172 if ($unread ||
!$unread_only) {
173 array_push($cats, array("id" => $cat_id,
174 "title" => Feeds
::getCategoryTitle($cat_id),
175 "unread" => $unread));
180 $this->wrap(self
::STATUS_OK
, $cats);
183 function getHeadlines() {
184 $feed_id = $_REQUEST["feed_id"];
185 if ($feed_id != "") {
187 if (is_numeric($feed_id)) $feed_id = (int) $feed_id;
189 $limit = (int)$_REQUEST["limit"];
191 if (!$limit ||
$limit >= 200) $limit = 200;
193 $offset = (int)$_REQUEST["skip"];
194 $filter = $_REQUEST["filter"];
195 $is_cat = sql_bool_to_bool($_REQUEST["is_cat"]);
196 $show_excerpt = sql_bool_to_bool($_REQUEST["show_excerpt"]);
197 $show_content = sql_bool_to_bool($_REQUEST["show_content"]);
198 /* all_articles, unread, adaptive, marked, updated */
199 $view_mode = $_REQUEST["view_mode"];
200 $include_attachments = sql_bool_to_bool($_REQUEST["include_attachments"]);
201 $since_id = (int)$_REQUEST["since_id"];
202 $include_nested = sql_bool_to_bool($_REQUEST["include_nested"]);
203 $sanitize_content = !isset($_REQUEST["sanitize"]) ||
204 sql_bool_to_bool($_REQUEST["sanitize"]);
205 $force_update = sql_bool_to_bool($_REQUEST["force_update"]);
206 $has_sandbox = sql_bool_to_bool($_REQUEST["has_sandbox"]);
207 $excerpt_length = (int)$_REQUEST["excerpt_length"];
208 $check_first_id = (int)$_REQUEST["check_first_id"];
209 $include_header = sql_bool_to_bool($_REQUEST["include_header"]);
211 $_SESSION['hasSandbox'] = $has_sandbox;
213 $skip_first_id_check = false;
215 $override_order = false;
216 switch ($_REQUEST["order_by"]) {
218 $override_order = "ttrss_entries.title, date_entered, updated";
221 $override_order = "score DESC, date_entered, updated";
222 $skip_first_id_check = true;
225 $override_order = "updated DESC";
229 /* do not rely on params below */
231 $search = $_REQUEST["search"];
233 list($headlines, $headlines_header) = $this->api_get_headlines($feed_id, $limit, $offset,
234 $filter, $is_cat, $show_excerpt, $show_content, $view_mode, $override_order,
235 $include_attachments, $since_id, $search,
236 $include_nested, $sanitize_content, $force_update, $excerpt_length, $check_first_id, $skip_first_id_check);
238 if ($include_header) {
239 $this->wrap(self
::STATUS_OK
, array($headlines_header, $headlines));
241 $this->wrap(self
::STATUS_OK
, $headlines);
244 $this->wrap(self
::STATUS_ERR
, array("error" => 'INCORRECT_USAGE'));
248 function updateArticle() {
249 $article_ids = explode(",", $_REQUEST["article_ids"]);
250 $mode = (int) $_REQUEST["mode"];
251 $data = $_REQUEST["data"];
252 $field_raw = (int)$_REQUEST["field"];
257 switch ($field_raw) {
260 $additional_fields = ",last_marked = NOW()";
263 $field = "published";
264 $additional_fields = ",last_published = NOW()";
268 $additional_fields = ",last_read = NOW()";
282 $set_to = "NOT $field";
286 if ($field == "note") $set_to = $this->pdo
->quote($data);
288 if ($field && $set_to && count($article_ids) > 0) {
290 $article_qmarks = arr_qmarks($article_ids);
292 $sth = $this->pdo
->prepare("UPDATE ttrss_user_entries SET
293 $field = $set_to $additional_fields
294 WHERE ref_id IN ($article_qmarks) AND owner_uid = ?");
295 $sth->execute(array_merge($article_ids, [$_SESSION['uid']]));
297 $num_updated = $sth->rowCount();
299 if ($num_updated > 0 && $field == "unread") {
300 $sth = $this->pdo
->prepare("SELECT DISTINCT feed_id FROM ttrss_user_entries
301 WHERE ref_id IN ($article_qmarks)");
302 $sth->execute($article_ids);
304 while ($line = $sth->fetch()) {
305 CCache
::update($line["feed_id"], $_SESSION["uid"]);
309 $this->wrap(self
::STATUS_OK
, array("status" => "OK",
310 "updated" => $num_updated));
313 $this->wrap(self
::STATUS_ERR
, array("error" => 'INCORRECT_USAGE'));
318 function getArticle() {
320 $article_ids = explode(",", $_REQUEST["article_id"]);
321 $sanitize_content = !isset($_REQUEST["sanitize"]) ||
322 sql_bool_to_bool($_REQUEST["sanitize"]);
326 $article_qmarks = arr_qmarks($article_ids);
328 $sth = $this->pdo
->prepare("SELECT id,guid,title,link,content,feed_id,comments,int_id,
329 marked,unread,published,score,note,lang,
330 ".SUBSTRING_FOR_DATE
."(updated,1,16) as updated,
331 author,(SELECT title FROM ttrss_feeds WHERE id = feed_id) AS feed_title,
332 (SELECT site_url FROM ttrss_feeds WHERE id = feed_id) AS site_url,
333 (SELECT hide_images FROM ttrss_feeds WHERE id = feed_id) AS hide_images
334 FROM ttrss_entries,ttrss_user_entries
335 WHERE id IN ($article_qmarks) AND ref_id = id AND owner_uid = ?");
337 $sth->execute(array_merge($article_ids, [$_SESSION['uid']]));
341 while ($line = $sth->fetch()) {
343 $attachments = Article
::get_article_enclosures($line['id']);
347 "guid" => $line["guid"],
348 "title" => $line["title"],
349 "link" => $line["link"],
350 "labels" => Article
::get_article_labels($line['id']),
351 "unread" => sql_bool_to_bool($line["unread"]),
352 "marked" => sql_bool_to_bool($line["marked"]),
353 "published" => sql_bool_to_bool($line["published"]),
354 "comments" => $line["comments"],
355 "author" => $line["author"],
356 "updated" => (int) strtotime($line["updated"]),
357 "feed_id" => $line["feed_id"],
358 "attachments" => $attachments,
359 "score" => (int)$line["score"],
360 "feed_title" => $line["feed_title"],
361 "note" => $line["note"],
362 "lang" => $line["lang"]
365 if ($sanitize_content) {
366 $article["content"] = sanitize(
368 sql_bool_to_bool($line['hide_images']),
369 false, $line["site_url"], false, $line["id"]);
371 $article["content"] = $line["content"];
374 foreach (PluginHost
::getInstance()->get_hooks(PluginHost
::HOOK_RENDER_ARTICLE_API
) as $p) {
375 $article = $p->hook_render_article_api(array("article" => $article));
378 array_push($articles, $article);
382 $this->wrap(self
::STATUS_OK
, $articles);
384 $this->wrap(self
::STATUS_ERR
, array("error" => 'INCORRECT_USAGE'));
388 function getConfig() {
390 "icons_dir" => ICONS_DIR
,
391 "icons_url" => ICONS_URL
);
393 $config["daemon_is_running"] = file_is_locked("update_daemon.lock");
395 $sth = $this->pdo
->prepare("SELECT COUNT(*) AS cf FROM
396 ttrss_feeds WHERE owner_uid = ?");
397 $sth->execute([$_SESSION['uid']]);
398 $row = $sth->fetch();
400 $config["num_feeds"] = $row["cf"];
402 $this->wrap(self
::STATUS_OK
, $config);
405 function updateFeed() {
406 $feed_id = (int) $_REQUEST["feed_id"];
408 if (!ini_get("open_basedir")) {
409 RSSUtils
::update_rss_feed($feed_id);
412 $this->wrap(self
::STATUS_OK
, array("status" => "OK"));
415 function catchupFeed() {
416 $feed_id = $_REQUEST["feed_id"];
417 $is_cat = $_REQUEST["is_cat"];
419 Feeds
::catchup_feed($feed_id, $is_cat);
421 $this->wrap(self
::STATUS_OK
, array("status" => "OK"));
425 $pref_name = $_REQUEST["pref_name"];
427 $this->wrap(self
::STATUS_OK
, array("value" => get_pref($pref_name)));
430 function getLabels() {
431 $article_id = (int)$_REQUEST['article_id'];
435 $sth = $this->pdo
->prepare("SELECT id, caption, fg_color, bg_color
437 WHERE owner_uid = ? ORDER BY caption");
438 $sth->execute([$_SESSION['uid']]);
441 $article_labels = Article
::get_article_labels($article_id);
443 $article_labels = array();
445 while ($line = $sth->fetch()) {
448 foreach ($article_labels as $al) {
449 if (Labels
::feed_to_label_id($al[0]) == $line['id']) {
455 array_push($rv, array(
456 "id" => (int)Labels
::label_to_feed_id($line['id']),
457 "caption" => $line['caption'],
458 "fg_color" => $line['fg_color'],
459 "bg_color" => $line['bg_color'],
460 "checked" => $checked));
463 $this->wrap(self
::STATUS_OK
, $rv);
466 function setArticleLabel() {
468 $article_ids = explode(",", $_REQUEST["article_ids"]);
469 $label_id = (int) $_REQUEST['label_id'];
470 $assign = sql_bool_to_bool($_REQUEST['assign']);
472 $label = Labels
::find_caption(Labels
::feed_to_label_id($label_id), $_SESSION["uid"]);
478 foreach ($article_ids as $id) {
481 Labels
::add_article($id, $label, $_SESSION["uid"]);
483 Labels
::remove_article($id, $label, $_SESSION["uid"]);
490 $this->wrap(self
::STATUS_OK
, array("status" => "OK",
491 "updated" => $num_updated));
495 function index($method) {
496 $plugin = PluginHost
::getInstance()->get_api_method(strtolower($method));
498 if ($plugin && method_exists($plugin, $method)) {
499 $reply = $plugin->$method();
501 $this->wrap($reply[0], $reply[1]);
504 $this->wrap(self
::STATUS_ERR
, array("error" => 'UNKNOWN_METHOD', "method" => $method));
508 function shareToPublished() {
509 $title = strip_tags($_REQUEST["title"]);
510 $url = strip_tags($_REQUEST["url"]);
511 $content = strip_tags($_REQUEST["content"]);
513 if (Article
::create_published_article($title, $url, $content, "", $_SESSION["uid"])) {
514 $this->wrap(self
::STATUS_OK
, array("status" => 'OK'));
516 $this->wrap(self
::STATUS_ERR
, array("error" => 'Publishing failed'));
520 static function api_get_feeds($cat_id, $unread_only, $limit, $offset, $include_nested = false) {
526 $limit = (int) $limit;
527 $offset = (int) $offset;
528 $cat_id = (int) $cat_id;
532 if ($cat_id == -4 ||
$cat_id == -2) {
533 $counters = Counters
::getLabelCounters(true);
535 foreach (array_values($counters) as $cv) {
537 $unread = $cv["counter"];
539 if ($unread ||
!$unread_only) {
542 "id" => (int) $cv["id"],
543 "title" => $cv["description"],
544 "unread" => $cv["counter"],
548 array_push($feeds, $row);
555 if ($cat_id == -4 ||
$cat_id == -1) {
556 foreach (array(-1, -2, -3, -4, -6, 0) as $i) {
557 $unread = getFeedUnread($i);
559 if ($unread ||
!$unread_only) {
560 $title = Feeds
::getFeedTitle($i);
568 array_push($feeds, $row);
576 if ($include_nested && $cat_id) {
577 $sth = $pdo->prepare("SELECT
578 id, title, order_id FROM ttrss_feed_categories
579 WHERE parent_cat = ? AND owner_uid = ? ORDER BY id, title");
581 $sth->execute([$cat_id, $_SESSION['uid']]);
583 while ($line = $sth->fetch()) {
584 $unread = getFeedUnread($line["id"], true) +
585 Feeds
::getCategoryChildrenUnread($line["id"]);
587 if ($unread ||
!$unread_only) {
589 "id" => (int) $line["id"],
590 "title" => $line["title"],
593 "order_id" => (int) $line["order_id"]
595 array_push($feeds, $row);
603 $limit_qpart = "LIMIT $limit OFFSET $offset";
608 if ($cat_id == -4 ||
$cat_id == -3) {
609 $sth = $pdo->prepare("SELECT
610 id, feed_url, cat_id, title, order_id, ".
611 SUBSTRING_FOR_DATE
."(last_updated,1,19) AS last_updated
612 FROM ttrss_feeds WHERE owner_uid = ?
613 ORDER BY cat_id, title " . $limit_qpart);
614 $sth->execute([$_SESSION['uid']]);
618 $sth = $pdo->prepare("SELECT
619 id, feed_url, cat_id, title, order_id, ".
620 SUBSTRING_FOR_DATE
."(last_updated,1,19) AS last_updated
621 FROM ttrss_feeds WHERE
622 (cat_id = :cat OR (:cat = 0 AND cat_id IS NULL))
624 ORDER BY cat_id, title " . $limit_qpart);
625 $sth->execute([":uid" => $_SESSION['uid'], ":cat" => $cat_id]);
628 while ($line = $sth->fetch()) {
630 $unread = getFeedUnread($line["id"]);
632 $has_icon = feed_has_icon($line['id']);
634 if ($unread ||
!$unread_only) {
637 "feed_url" => $line["feed_url"],
638 "title" => $line["title"],
639 "id" => (int)$line["id"],
640 "unread" => (int)$unread,
641 "has_icon" => $has_icon,
642 "cat_id" => (int)$line["cat_id"],
643 "last_updated" => (int) strtotime($line["last_updated"]),
644 "order_id" => (int) $line["order_id"],
647 array_push($feeds, $row);
655 * @SuppressWarnings(PHPMD.UnusedFormalParameter)
657 static function api_get_headlines($feed_id, $limit, $offset,
658 $filter, $is_cat, $show_excerpt, $show_content, $view_mode, $order,
659 $include_attachments, $since_id,
660 $search = "", $include_nested = false, $sanitize_content = true,
661 $force_update = false, $excerpt_length = 100, $check_first_id = false, $skip_first_id_check = false) {
665 if ($force_update && $feed_id > 0 && is_numeric($feed_id)) {
666 // Update the feed if required with some basic flood control
668 $sth = $pdo->prepare(
669 "SELECT cache_images,".SUBSTRING_FOR_DATE
."(last_updated,1,19) AS last_updated
670 FROM ttrss_feeds WHERE id = ?");
671 $sth->execute([$feed_id]);
673 if ($row = $sth->fetch()) {
674 $last_updated = strtotime($row["last_updated"]);
675 $cache_images = sql_bool_to_bool($row["cache_images"]);
677 if (!$cache_images && time() - $last_updated > 120) {
678 RSSUtils
::update_rss_feed($feed_id, true);
680 $sth = $pdo->prepare("UPDATE ttrss_feeds SET last_updated = '1970-01-01', last_update_started = '1970-01-01'
682 $sth->execute([$feed_id]);
690 "view_mode" => $view_mode,
691 "cat_view" => $is_cat,
693 "override_order" => $order,
695 "since_id" => $since_id,
696 "include_children" => $include_nested,
697 "check_first_id" => $check_first_id,
698 "skip_first_id_check" => $skip_first_id_check
701 $qfh_ret = Feeds
::queryFeedHeadlines($params);
703 $result = $qfh_ret[0];
704 $feed_title = $qfh_ret[1];
705 $first_id = $qfh_ret[6];
707 $headlines = array();
709 $headlines_header = array(
711 'first_id' => $first_id,
712 'is_cat' => $is_cat);
714 if (!is_numeric($result)) {
715 while ($line = $result->fetch()) {
716 $line["content_preview"] = truncate_string(strip_tags($line["content"]), $excerpt_length);
717 foreach (PluginHost
::getInstance()->get_hooks(PluginHost
::HOOK_QUERY_HEADLINES
) as $p) {
718 $line = $p->hook_query_headlines($line, $excerpt_length, true);
721 $is_updated = ($line["last_read"] == "" &&
722 ($line["unread"] != "t" && $line["unread"] != "1"));
724 $tags = explode(",", $line["tag_cache"]);
726 $label_cache = $line["label_cache"];
730 $label_cache = json_decode($label_cache, true);
733 if ($label_cache["no-labels"] == 1)
736 $labels = $label_cache;
740 if (!is_array($labels)) $labels = Article
::get_article_labels($line["id"]);
742 $headline_row = array(
743 "id" => (int)$line["id"],
744 "guid" => $line["guid"],
745 "unread" => sql_bool_to_bool($line["unread"]),
746 "marked" => sql_bool_to_bool($line["marked"]),
747 "published" => sql_bool_to_bool($line["published"]),
748 "updated" => (int)strtotime($line["updated"]),
749 "is_updated" => $is_updated,
750 "title" => $line["title"],
751 "link" => $line["link"],
752 "feed_id" => $line["feed_id"],
756 if ($include_attachments)
757 $headline_row['attachments'] = Article
::get_article_enclosures(
761 $headline_row["excerpt"] = $line["content_preview"];
765 if ($sanitize_content) {
766 $headline_row["content"] = sanitize(
768 sql_bool_to_bool($line['hide_images']),
769 false, $line["site_url"], false, $line["id"]);
771 $headline_row["content"] = $line["content"];
775 // unify label output to ease parsing
776 if ($labels["no-labels"] == 1) $labels = array();
778 $headline_row["labels"] = $labels;
780 $headline_row["feed_title"] = $line["feed_title"] ?
$line["feed_title"] :
783 $headline_row["comments_count"] = (int)$line["num_comments"];
784 $headline_row["comments_link"] = $line["comments"];
786 $headline_row["always_display_attachments"] = sql_bool_to_bool($line["always_display_enclosures"]);
788 $headline_row["author"] = $line["author"];
790 $headline_row["score"] = (int)$line["score"];
791 $headline_row["note"] = $line["note"];
792 $headline_row["lang"] = $line["lang"];
794 foreach (PluginHost
::getInstance()->get_hooks(PluginHost
::HOOK_RENDER_ARTICLE_API
) as $p) {
795 $headline_row = $p->hook_render_article_api(array("headline" => $headline_row));
798 array_push($headlines, $headline_row);
800 } else if (is_numeric($result) && $result == -1) {
801 $headlines_header['first_id_changed'] = true;
804 return array($headlines, $headlines_header);
807 function unsubscribeFeed() {
808 $feed_id = (int) $_REQUEST["feed_id"];
810 $sth = $this->pdo
->prepare("SELECT id FROM ttrss_feeds WHERE
811 id = ? AND owner_uid = ?");
812 $sth->execute([$feed_id, $_SESSION['uid']]);
814 if ($row = $sth->fetch()) {
815 Pref_Feeds
::remove_feed($feed_id, $_SESSION["uid"]);
816 $this->wrap(self
::STATUS_OK
, array("status" => "OK"));
818 $this->wrap(self
::STATUS_ERR
, array("error" => "FEED_NOT_FOUND"));
822 function subscribeToFeed() {
823 $feed_url = $_REQUEST["feed_url"];
824 $category_id = (int) $_REQUEST["category_id"];
825 $login = $_REQUEST["login"];
826 $password = $_REQUEST["password"];
829 $rc = Feeds
::subscribe_to_feed($feed_url, $category_id, $login, $password);
831 $this->wrap(self
::STATUS_OK
, array("status" => $rc));
833 $this->wrap(self
::STATUS_ERR
, array("error" => 'INCORRECT_USAGE'));
837 function getFeedTree() {
838 $include_empty = sql_bool_to_bool($_REQUEST['include_empty']);
840 $pf = new Pref_Feeds($_REQUEST);
842 $_REQUEST['mode'] = 2;
843 $_REQUEST['force_show_empty'] = $include_empty;
846 $data = $pf->makefeedtree();
847 $this->wrap(self
::STATUS_OK
, array("categories" => $data));
849 $this->wrap(self
::STATUS_ERR
, array("error" =>
850 'UNABLE_TO_INSTANTIATE_OBJECT'));
855 // only works for labels or uncategorized for the time being
856 private function isCategoryEmpty($id) {
859 $sth = $this->pdo
->prepare("SELECT COUNT(id) AS count FROM ttrss_labels2
860 WHERE owner_uid = ?");
861 $sth->execute([$_SESSION['uid']]);
862 $row = $sth->fetch();
864 return $row["count"] == 0;
866 } else if ($id == 0) {
867 $sth = $this->pdo
->prepare("SELECT COUNT(id) AS count FROM ttrss_feeds
868 WHERE cat_id IS NULL AND owner_uid = ?");
869 $sth->execute([$_SESSION['uid']]);
870 $row = $sth->fetch();
872 return $row["count"] == 0;