+ function unsubscribeFeed() {
+ $feed_id = (int) $this->dbh->escape_string($_REQUEST["feed_id"]);
+
+ $result = $this->dbh->query("SELECT id FROM ttrss_feeds WHERE
+ id = '$feed_id' AND owner_uid = ".$_SESSION["uid"]);
+
+ if ($this->dbh->num_rows($result) != 0) {
+ Pref_Feeds::remove_feed($feed_id, $_SESSION["uid"]);
+ $this->wrap(self::STATUS_OK, array("status" => "OK"));
+ } else {
+ $this->wrap(self::STATUS_ERR, array("error" => "FEED_NOT_FOUND"));
+ }
+ }
+
+ function subscribeToFeed() {
+ $feed_url = $this->dbh->escape_string($_REQUEST["feed_url"]);
+ $category_id = (int) $this->dbh->escape_string($_REQUEST["category_id"]);
+ $login = $this->dbh->escape_string($_REQUEST["login"]);
+ $password = $this->dbh->escape_string($_REQUEST["password"]);
+
+ if ($feed_url) {
+ $rc = subscribe_to_feed($feed_url, $category_id, $login, $password);
+
+ $this->wrap(self::STATUS_OK, array("status" => $rc));
+ } else {
+ $this->wrap(self::STATUS_ERR, array("error" => 'INCORRECT_USAGE'));
+ }
+ }
+
+ function getFeedTree() {
+ $include_empty = sql_bool_to_bool($_REQUEST['include_empty']);
+
+ $pf = new Pref_Feeds($_REQUEST);
+
+ $_REQUEST['mode'] = 2;
+ $_REQUEST['force_show_empty'] = $include_empty;
+
+ if ($pf){
+ $data = $pf->makefeedtree();
+ $this->wrap(self::STATUS_OK, array("categories" => $data));
+ } else {
+ $this->wrap(self::STATUS_ERR, array("error" =>
+ 'UNABLE_TO_INSTANTIATE_OBJECT'));
+ }
+
+ }
+
+ // only works for labels or uncategorized for the time being
+ private function isCategoryEmpty($id) {
+
+ if ($id == -2) {
+ $result = $this->dbh->query("SELECT COUNT(*) AS count FROM ttrss_labels2
+ WHERE owner_uid = " . $_SESSION["uid"]);
+
+ return $this->dbh->fetch_result($result, 0, "count") == 0;
+
+ } else if ($id == 0) {
+ $result = $this->dbh->query("SELECT COUNT(*) AS count FROM ttrss_feeds
+ WHERE cat_id IS NULL AND owner_uid = " . $_SESSION["uid"]);
+
+ return $this->dbh->fetch_result($result, 0, "count") == 0;
+
+ }
+
+ return false;
+ }
+
+