]>
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 $article['content'] = rewrite_cached_urls($article['content']);
384 array_push($articles, $article);
388 $this->wrap(self
::STATUS_OK
, $articles);
390 $this->wrap(self
::STATUS_ERR
, array("error" => 'INCORRECT_USAGE'));
394 function getConfig() {
396 "icons_dir" => ICONS_DIR
,
397 "icons_url" => ICONS_URL
);
399 $config["daemon_is_running"] = file_is_locked("update_daemon.lock");
401 $sth = $this->pdo
->prepare("SELECT COUNT(*) AS cf FROM
402 ttrss_feeds WHERE owner_uid = ?");
403 $sth->execute([$_SESSION['uid']]);
404 $row = $sth->fetch();
406 $config["num_feeds"] = $row["cf"];
408 $this->wrap(self
::STATUS_OK
, $config);
411 function updateFeed() {
412 $feed_id = (int) clean($_REQUEST["feed_id"]);
414 if (!ini_get("open_basedir")) {
415 RSSUtils
::update_rss_feed($feed_id);
418 $this->wrap(self
::STATUS_OK
, array("status" => "OK"));
421 function catchupFeed() {
422 $feed_id = clean($_REQUEST["feed_id"]);
423 $is_cat = clean($_REQUEST["is_cat"]);
425 Feeds
::catchup_feed($feed_id, $is_cat);
427 $this->wrap(self
::STATUS_OK
, array("status" => "OK"));
431 $pref_name = clean($_REQUEST["pref_name"]);
433 $this->wrap(self
::STATUS_OK
, array("value" => get_pref($pref_name)));
436 function getLabels() {
437 $article_id = (int)clean($_REQUEST['article_id']);
441 $sth = $this->pdo
->prepare("SELECT id, caption, fg_color, bg_color
443 WHERE owner_uid = ? ORDER BY caption");
444 $sth->execute([$_SESSION['uid']]);
447 $article_labels = Article
::get_article_labels($article_id);
449 $article_labels = array();
451 while ($line = $sth->fetch()) {
454 foreach ($article_labels as $al) {
455 if (Labels
::feed_to_label_id($al[0]) == $line['id']) {
461 array_push($rv, array(
462 "id" => (int)Labels
::label_to_feed_id($line['id']),
463 "caption" => $line['caption'],
464 "fg_color" => $line['fg_color'],
465 "bg_color" => $line['bg_color'],
466 "checked" => $checked));
469 $this->wrap(self
::STATUS_OK
, $rv);
472 function setArticleLabel() {
474 $article_ids = explode(",", clean($_REQUEST["article_ids"]));
475 $label_id = (int) clean($_REQUEST['label_id']);
476 $assign = API
::param_to_bool(clean($_REQUEST['assign']));
478 $label = Labels
::find_caption(Labels
::feed_to_label_id($label_id), $_SESSION["uid"]);
484 foreach ($article_ids as $id) {
487 Labels
::add_article($id, $label, $_SESSION["uid"]);
489 Labels
::remove_article($id, $label, $_SESSION["uid"]);
496 $this->wrap(self
::STATUS_OK
, array("status" => "OK",
497 "updated" => $num_updated));
501 function index($method) {
502 $plugin = PluginHost
::getInstance()->get_api_method(strtolower($method));
504 if ($plugin && method_exists($plugin, $method)) {
505 $reply = $plugin->$method();
507 $this->wrap($reply[0], $reply[1]);
510 $this->wrap(self
::STATUS_ERR
, array("error" => 'UNKNOWN_METHOD', "method" => $method));
514 function shareToPublished() {
515 $title = strip_tags(clean($_REQUEST["title"]));
516 $url = strip_tags(clean($_REQUEST["url"]));
517 $content = strip_tags(clean($_REQUEST["content"]));
519 if (Article
::create_published_article($title, $url, $content, "", $_SESSION["uid"])) {
520 $this->wrap(self
::STATUS_OK
, array("status" => 'OK'));
522 $this->wrap(self
::STATUS_ERR
, array("error" => 'Publishing failed'));
526 static function api_get_feeds($cat_id, $unread_only, $limit, $offset, $include_nested = false) {
532 $limit = (int) $limit;
533 $offset = (int) $offset;
534 $cat_id = (int) $cat_id;
538 if ($cat_id == -4 ||
$cat_id == -2) {
539 $counters = Counters
::getLabelCounters(true);
541 foreach (array_values($counters) as $cv) {
543 $unread = $cv["counter"];
545 if ($unread ||
!$unread_only) {
548 "id" => (int) $cv["id"],
549 "title" => $cv["description"],
550 "unread" => $cv["counter"],
554 array_push($feeds, $row);
561 if ($cat_id == -4 ||
$cat_id == -1) {
562 foreach (array(-1, -2, -3, -4, -6, 0) as $i) {
563 $unread = getFeedUnread($i);
565 if ($unread ||
!$unread_only) {
566 $title = Feeds
::getFeedTitle($i);
574 array_push($feeds, $row);
582 if ($include_nested && $cat_id) {
583 $sth = $pdo->prepare("SELECT
584 id, title, order_id FROM ttrss_feed_categories
585 WHERE parent_cat = ? AND owner_uid = ? ORDER BY id, title");
587 $sth->execute([$cat_id, $_SESSION['uid']]);
589 while ($line = $sth->fetch()) {
590 $unread = getFeedUnread($line["id"], true) +
591 Feeds
::getCategoryChildrenUnread($line["id"]);
593 if ($unread ||
!$unread_only) {
595 "id" => (int) $line["id"],
596 "title" => $line["title"],
599 "order_id" => (int) $line["order_id"]
601 array_push($feeds, $row);
609 $limit_qpart = "LIMIT $limit OFFSET $offset";
614 if ($cat_id == -4 ||
$cat_id == -3) {
615 $sth = $pdo->prepare("SELECT
616 id, feed_url, cat_id, title, order_id, ".
617 SUBSTRING_FOR_DATE
."(last_updated,1,19) AS last_updated
618 FROM ttrss_feeds WHERE owner_uid = ?
619 ORDER BY cat_id, title " . $limit_qpart);
620 $sth->execute([$_SESSION['uid']]);
624 $sth = $pdo->prepare("SELECT
625 id, feed_url, cat_id, title, order_id, ".
626 SUBSTRING_FOR_DATE
."(last_updated,1,19) AS last_updated
627 FROM ttrss_feeds WHERE
628 (cat_id = :cat OR (:cat = 0 AND cat_id IS NULL))
630 ORDER BY cat_id, title " . $limit_qpart);
631 $sth->execute([":uid" => $_SESSION['uid'], ":cat" => $cat_id]);
634 while ($line = $sth->fetch()) {
636 $unread = getFeedUnread($line["id"]);
638 $has_icon = Feeds
::feedHasIcon($line['id']);
640 if ($unread ||
!$unread_only) {
643 "feed_url" => $line["feed_url"],
644 "title" => $line["title"],
645 "id" => (int)$line["id"],
646 "unread" => (int)$unread,
647 "has_icon" => $has_icon,
648 "cat_id" => (int)$line["cat_id"],
649 "last_updated" => (int) strtotime($line["last_updated"]),
650 "order_id" => (int) $line["order_id"],
653 array_push($feeds, $row);
661 * @SuppressWarnings(PHPMD.UnusedFormalParameter)
663 static function api_get_headlines($feed_id, $limit, $offset,
664 $filter, $is_cat, $show_excerpt, $show_content, $view_mode, $order,
665 $include_attachments, $since_id,
666 $search = "", $include_nested = false, $sanitize_content = true,
667 $force_update = false, $excerpt_length = 100, $check_first_id = false, $skip_first_id_check = false) {
671 if ($force_update && $feed_id > 0 && is_numeric($feed_id)) {
672 // Update the feed if required with some basic flood control
674 $sth = $pdo->prepare(
675 "SELECT cache_images,".SUBSTRING_FOR_DATE
."(last_updated,1,19) AS last_updated
676 FROM ttrss_feeds WHERE id = ?");
677 $sth->execute([$feed_id]);
679 if ($row = $sth->fetch()) {
680 $last_updated = strtotime($row["last_updated"]);
681 $cache_images = API
::param_to_bool($row["cache_images"]);
683 if (!$cache_images && time() - $last_updated > 120) {
684 RSSUtils
::update_rss_feed($feed_id, true);
686 $sth = $pdo->prepare("UPDATE ttrss_feeds SET last_updated = '1970-01-01', last_update_started = '1970-01-01'
688 $sth->execute([$feed_id]);
696 "view_mode" => $view_mode,
697 "cat_view" => $is_cat,
699 "override_order" => $order,
701 "since_id" => $since_id,
702 "include_children" => $include_nested,
703 "check_first_id" => $check_first_id,
704 "skip_first_id_check" => $skip_first_id_check
707 $qfh_ret = Feeds
::queryFeedHeadlines($params);
709 $result = $qfh_ret[0];
710 $feed_title = $qfh_ret[1];
711 $first_id = $qfh_ret[6];
713 $headlines = array();
715 $headlines_header = array(
717 'first_id' => $first_id,
718 'is_cat' => $is_cat);
720 if (!is_numeric($result)) {
721 while ($line = $result->fetch()) {
722 $line["content_preview"] = truncate_string(strip_tags($line["content"]), $excerpt_length);
723 foreach (PluginHost
::getInstance()->get_hooks(PluginHost
::HOOK_QUERY_HEADLINES
) as $p) {
724 $line = $p->hook_query_headlines($line, $excerpt_length, true);
727 $is_updated = ($line["last_read"] == "" &&
728 ($line["unread"] != "t" && $line["unread"] != "1"));
730 $tags = explode(",", $line["tag_cache"]);
732 $label_cache = $line["label_cache"];
736 $label_cache = json_decode($label_cache, true);
739 if ($label_cache["no-labels"] == 1)
742 $labels = $label_cache;
746 if (!is_array($labels)) $labels = Article
::get_article_labels($line["id"]);
748 $headline_row = array(
749 "id" => (int)$line["id"],
750 "guid" => $line["guid"],
751 "unread" => API
::param_to_bool($line["unread"]),
752 "marked" => API
::param_to_bool($line["marked"]),
753 "published" => API
::param_to_bool($line["published"]),
754 "updated" => (int)strtotime($line["updated"]),
755 "is_updated" => $is_updated,
756 "title" => $line["title"],
757 "link" => $line["link"],
758 "feed_id" => $line["feed_id"] ?
$line['feed_id'] : 0,
762 if ($include_attachments)
763 $headline_row['attachments'] = Article
::get_article_enclosures(
767 $headline_row["excerpt"] = $line["content_preview"];
771 if ($sanitize_content) {
772 $headline_row["content"] = sanitize(
774 API
::param_to_bool($line['hide_images']),
775 false, $line["site_url"], false, $line["id"]);
777 $headline_row["content"] = $line["content"];
781 // unify label output to ease parsing
782 if ($labels["no-labels"] == 1) $labels = array();
784 $headline_row["labels"] = $labels;
786 $headline_row["feed_title"] = $line["feed_title"] ?
$line["feed_title"] :
789 $headline_row["comments_count"] = (int)$line["num_comments"];
790 $headline_row["comments_link"] = $line["comments"];
792 $headline_row["always_display_attachments"] = API
::param_to_bool($line["always_display_enclosures"]);
794 $headline_row["author"] = $line["author"];
796 $headline_row["score"] = (int)$line["score"];
797 $headline_row["note"] = $line["note"];
798 $headline_row["lang"] = $line["lang"];
800 foreach (PluginHost
::getInstance()->get_hooks(PluginHost
::HOOK_RENDER_ARTICLE_API
) as $p) {
801 $headline_row = $p->hook_render_article_api(array("headline" => $headline_row));
804 $headline_row['content'] = rewrite_cached_urls($headline_row['content']);
806 array_push($headlines, $headline_row);
808 } else if (is_numeric($result) && $result == -1) {
809 $headlines_header['first_id_changed'] = true;
812 return array($headlines, $headlines_header);
815 function unsubscribeFeed() {
816 $feed_id = (int) clean($_REQUEST["feed_id"]);
818 $sth = $this->pdo
->prepare("SELECT id FROM ttrss_feeds WHERE
819 id = ? AND owner_uid = ?");
820 $sth->execute([$feed_id, $_SESSION['uid']]);
822 if ($row = $sth->fetch()) {
823 Pref_Feeds
::remove_feed($feed_id, $_SESSION["uid"]);
824 $this->wrap(self
::STATUS_OK
, array("status" => "OK"));
826 $this->wrap(self
::STATUS_ERR
, array("error" => "FEED_NOT_FOUND"));
830 function subscribeToFeed() {
831 $feed_url = clean($_REQUEST["feed_url"]);
832 $category_id = (int) clean($_REQUEST["category_id"]);
833 $login = clean($_REQUEST["login"]);
834 $password = clean($_REQUEST["password"]);
837 $rc = Feeds
::subscribe_to_feed($feed_url, $category_id, $login, $password);
839 $this->wrap(self
::STATUS_OK
, array("status" => $rc));
841 $this->wrap(self
::STATUS_ERR
, array("error" => 'INCORRECT_USAGE'));
845 function getFeedTree() {
846 $include_empty = API
::param_to_bool(clean($_REQUEST['include_empty']));
848 $pf = new Pref_Feeds($_REQUEST);
850 $_REQUEST['mode'] = 2;
851 $_REQUEST['force_show_empty'] = $include_empty;
854 $data = $pf->makefeedtree();
855 $this->wrap(self
::STATUS_OK
, array("categories" => $data));
857 $this->wrap(self
::STATUS_ERR
, array("error" =>
858 'UNABLE_TO_INSTANTIATE_OBJECT'));
863 // only works for labels or uncategorized for the time being
864 private function isCategoryEmpty($id) {
867 $sth = $this->pdo
->prepare("SELECT COUNT(id) AS count FROM ttrss_labels2
868 WHERE owner_uid = ?");
869 $sth->execute([$_SESSION['uid']]);
870 $row = $sth->fetch();
872 return $row["count"] == 0;
874 } else if ($id == 0) {
875 $sth = $this->pdo
->prepare("SELECT COUNT(id) AS count FROM ttrss_feeds
876 WHERE cat_id IS NULL AND owner_uid = ?");
877 $sth->execute([$_SESSION['uid']]);
878 $row = $sth->fetch();
880 return $row["count"] == 0;