]> git.wh0rd.org Git - tt-rss.git/commitdiff
archive: automatically subscribe user to originating feed while unarchiving
authorAndrew Dolgov <fox@madoka.volgo-balt.ru>
Sat, 30 Mar 2013 17:59:52 +0000 (21:59 +0400)
committerAndrew Dolgov <fox@madoka.volgo-balt.ru>
Sat, 30 Mar 2013 17:59:52 +0000 (21:59 +0400)
classes/rpc.php
js/viewfeed.js

index b292f44e42f4aa189ec8b9f36a1e139eaef45691..4ef0fe7539746944abd6d80b6073a025aea8d74b 100644 (file)
@@ -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"));
        }
index b7eaef3627808dd7e9257130c066f823ea9c227f..caf40919e8500a6c649a4949f08c8654137cacaa 100644 (file)
@@ -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";
                }