]> git.wh0rd.org Git - tt-rss.git/commitdiff
api: implement subscribeToFeed/unsubscribeFeed (closes #623)
authorAndrew Dolgov <fox@madoka.volgo-balt.ru>
Sun, 24 Mar 2013 10:28:43 +0000 (14:28 +0400)
committerAndrew Dolgov <fox@madoka.volgo-balt.ru>
Sun, 24 Mar 2013 10:28:43 +0000 (14:28 +0400)
classes/api.php
classes/pref/feeds.php
classes/rpc.php
include/functions.php

index 3ec2186715cc99b2fe414e3762001f3598d14356..ec1219fe104a243377e570197baf71a9933ba276 100644 (file)
@@ -2,7 +2,7 @@
 
 class API extends Handler {
 
-       const API_LEVEL  = 4;
+       const API_LEVEL  = 5;
 
        const STATUS_OK  = 0;
        const STATUS_ERR = 1;
@@ -666,6 +666,36 @@ class API extends Handler {
                        return $headlines;
        }
 
+       function unsubscribeFeed() {
+               $feed_id = (int) db_escape_string($this->link, $_REQUEST["feed_id"]);
+
+               $result = db_query($this->link, "SELECT id FROM ttrss_feeds WHERE
+                       id = '$feed_id' AND owner_uid = ".$_SESSION["uid"]);
+
+               if (db_num_rows($result) != 0) {
+                       Pref_Feeds::remove_feed($this->link, $feed_id, $_SESSION["uid"]);
+                       print $this->wrap(self::STATUS_OK, array("status" => "OK"));
+               } else {
+                       print $this->wrap(self::STATUS_ERR, array("error" => "FEED_NOT_FOUND"));
+               }
+       }
+
+       function subscribeToFeed() {
+               $feed_url = db_escape_string($this->link, $_REQUEST["feed_url"]);
+               $category_id = (int) db_escape_string($this->link, $_REQUEST["category_id"]);
+               $login = db_escape_string($this->link, $_REQUEST["login"]);
+               $password = db_escape_string($this->link, $_REQUEST["password"]);
+
+               if ($feed_url) {
+                       $rc = subscribe_to_feed($this->link, $feed_url, $category_id,
+                               $login, $password, false);
+
+                       print $this->wrap(self::STATUS_OK, array("status" => $rc));
+               } else {
+                       print $this->wrap(self::STATUS_ERR, array("error" => 'INCORRECT_USAGE'));
+               }
+       }
+
 }
 
 ?>
index ceda133742273ac12ce339fdc4b182c71e278cfd..6828e3ff2923323934648469a8fb432500e8f632 100644 (file)
@@ -1012,7 +1012,7 @@ class Pref_Feeds extends Handler_Protected {
                $ids = split(",", db_escape_string($this->link, $_REQUEST["ids"]));
 
                foreach ($ids as $id) {
-                       $this->remove_feed($this->link, $id, $_SESSION["uid"]);
+                       Pref_Feeds::remove_feed($this->link, $id, $_SESSION["uid"]);
                }
 
                return;
@@ -1657,7 +1657,7 @@ class Pref_Feeds extends Handler_Protected {
                ccache_remove($link, $id, $owner_uid, true);
        }
 
-       private function remove_feed($link, $id, $owner_uid) {
+       static function remove_feed($link, $id, $owner_uid) {
 
                if ($id > 0) {
 
index ee5a9e68a356e0aa4aa3f8e939f10ff8f7c9d4e9..ea139935ee24faa331481e6d9bf0f9ac1ed51f6f 100644 (file)
@@ -105,9 +105,8 @@ class RPC extends Handler_Protected {
                $cat = db_escape_string($this->link, $_REQUEST['cat']);
                $login = db_escape_string($this->link, $_REQUEST['login']);
                $pass = db_escape_string($this->link, $_REQUEST['pass']);
-               $need_auth = db_escape_string($this->link, $_REQUEST['need_auth']) != "";
 
-               $rc = subscribe_to_feed($this->link, $feed, $cat, $login, $pass, $need_auth);
+               $rc = subscribe_to_feed($this->link, $feed, $cat, $login, $pass);
 
                print json_encode(array("result" => $rc));
        }
@@ -623,7 +622,6 @@ class RPC extends Handler_Protected {
                $feeds = explode("\n", db_escape_string($this->link, $_REQUEST['feeds']));
                $login = db_escape_string($this->link, $_REQUEST['login']);
                $pass = db_escape_string($this->link, $_REQUEST['pass']);
-               $need_auth = db_escape_string($this->link, $_REQUEST['need_auth']) != "";
 
                foreach ($feeds as $feed) {
                        $feed = trim($feed);
index c01e4100437886997ddd86423ff3c07f830cf1ff..2ae0dc3b92b2a8823926db1d94c2fdfcd7cc541e 100644 (file)
         *                 5 - Couldn't download the URL content.
         */
        function subscribe_to_feed($link, $url, $cat_id = 0,
-                       $auth_login = '', $auth_pass = '', $need_auth = false) {
+                       $auth_login = '', $auth_pass = '') {
 
                global $fetch_last_error;