From b029f91621076f37e7399c6701b2392ed879541b Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sat, 30 Mar 2013 21:59:52 +0400 Subject: [PATCH] archive: automatically subscribe user to originating feed while unarchiving --- classes/rpc.php | 55 +++++++++++++++++++++++++++++++++++++++++++++---- js/viewfeed.js | 3 +++ 2 files changed, 54 insertions(+), 4 deletions(-) diff --git a/classes/rpc.php b/classes/rpc.php index b292f44e..4ef0fe75 100644 --- a/classes/rpc.php +++ b/classes/rpc.php @@ -158,11 +158,58 @@ class RPC extends Handler_Protected { } function unarchive() { - $ids = db_escape_string($this->link, $_REQUEST["ids"]); + $ids = explode(",", $_REQUEST["ids"]); + + foreach ($ids as $id) { + $id = db_escape_string($this->link, trim($id)); + db_query($this->link, "BEGIN"); + + $result = db_query($this->link, "SELECT feed_url,site_url,title FROM ttrss_archived_feeds + WHERE id = (SELECT orig_feed_id FROM ttrss_user_entries WHERE ref_id = $id + AND owner_uid = ".$_SESSION["uid"].")"); + + if (db_num_rows($result) != 0) { + $feed_url = db_escape_string($this->link, db_fetch_result($result, 0, "feed_url")); + $site_url = db_escape_string($this->link, db_fetch_result($result, 0, "site_url")); + $title = db_escape_string($this->link, db_fetch_result($result, 0, "title")); + + $result = db_query($this->link, "SELECT id FROM ttrss_feeds WHERE feed_url = '$feed_url' + AND owner_uid = " .$_SESSION["uid"]); + + if (db_num_rows($result) == 0) { + + if (!$title) $title = '[Unknown]'; + + $result = db_query($this->link, + "INSERT INTO ttrss_feeds + (owner_uid,feed_url,site_url,title,cat_id,auth_login,auth_pass,update_method) + VALUES (".$_SESSION["uid"].", + '$feed_url', + '$site_url', + '$title', + NULL, '', '', 0)"); - $result = db_query($this->link, "UPDATE ttrss_user_entries - SET feed_id = orig_feed_id, orig_feed_id = NULL - WHERE ref_id IN ($ids) AND owner_uid = " . $_SESSION["uid"]); + $result = db_query($this->link, + "SELECT id FROM ttrss_feeds WHERE feed_url = '$feed_url' + AND owner_uid = ".$_SESSION["uid"]); + + if (db_num_rows($result) != 0) { + $feed_id = db_fetch_result($result, 0, "id"); + } + + } else { + $feed_id = db_fetch_result($result, 0, "id"); + } + + if ($feed_id) { + $result = db_query($this->link, "UPDATE ttrss_user_entries + SET feed_id = '$feed_id', orig_feed_id = NULL + WHERE ref_id = $id AND owner_uid = " . $_SESSION["uid"]); + } + } + + db_query($this->link, "COMMIT"); + } print json_encode(array("message" => "UPDATE_COUNTERS")); } diff --git a/js/viewfeed.js b/js/viewfeed.js index b7eaef36..caf40919 100644 --- a/js/viewfeed.js +++ b/js/viewfeed.js @@ -1021,6 +1021,9 @@ function archiveSelection() { op = "archive"; } else { str = ngettext("Move %d archived article back?", "Move %d archived articles back?", rows.length); + + str += " " + __("Please note that unstarred articles might get purged on next feed update."); + op = "unarchive"; } -- 2.39.5