]> git.wh0rd.org Git - tt-rss.git/commitdiff
implement archived articles feed; bump schema
authorAndrew Dolgov <fox@bah.org.ru>
Mon, 28 Dec 2009 14:23:01 +0000 (17:23 +0300)
committerAndrew Dolgov <fox@bah.org.ru>
Mon, 28 Dec 2009 14:23:01 +0000 (17:23 +0300)
backend.php
functions.php
modules/backend-rpc.php
schema/ttrss_schema_mysql.sql
schema/ttrss_schema_pgsql.sql
schema/versions/mysql/60.sql [new file with mode: 0644]
schema/versions/pgsql/60.sql [new file with mode: 0644]
viewfeed.js

index b4b58a78764323c7872cd8fd1b87e1877b42eaee..cee8c26ceb0b283276617633a46824083746a5b2 100644 (file)
                case "view":
 
                        $id = db_escape_string($_GET["id"]);
-                       $feed_id = db_escape_string($_GET["feed"]);
                        $cids = split(",", db_escape_string($_GET["cids"]));
                        $mode = db_escape_string($_GET["mode"]);
                        $omode = db_escape_string($_GET["omode"]);
                        // just gets marked as read (it already exists in client cache)
 
                        if ($mode == "") {
-                               outputArticleXML($link, $id, $feed_id);
+                               outputArticleXML($link, $id, false);
                        } else if ($mode == "zoom") {
-                               outputArticleXML($link, $id, $feed_id, true, true);
+                               outputArticleXML($link, $id, false, true, true);
                        } else {
                                catchupArticleById($link, $id, 0);
                                ccache_update($link, $feed_id, $_SESSION["uid"]);
                        if (!$_SESSION["bw_limit"]) {
                                foreach ($cids as $cid) {
                                        if ($cid) {
-                                               outputArticleXML($link, $cid, $feed_id, false);
+                                               outputArticleXML($link, $cid, false, false);
                                        }
                                }
                        }
index 02521b313508035eb07118e4154ecba1595424a0..5c285c4e2564dc60465f25ca106824c41f70de9d 100644 (file)
 
                        foreach ($iterator as $item) {
 
-                               if ($_GET['xdebug']) {
+                               if ($_GET['xdebug'] == 2) {
                                        print_r($item);
-
                                }
 
                                if ($use_simplepie) {
                                        } 
                                }
 
-                               if ($_GET["xdebug"]) {
+                               if ($_GET["xdebug"] == 2) {
                                        print "update_rss_feed: content: ";
                                        print_r(htmlspecialchars($entry_content));
                                }
 
                                        // do we allow duplicate posts with same GUID in different feeds?
                                        if (get_pref($link, "ALLOW_DUPLICATE_POSTS", $owner_uid, false)) {
-                                               $dupcheck_qpart = "AND feed_id = '$feed'";
+                                               $dupcheck_qpart = "AND (feed_id = '$feed' OR feed_id IS NULL)";
                                        } else { 
                                                $dupcheck_qpart = "";
                                        }
                                                        $entry_int_id = db_fetch_result($result, 0, "int_id");
                                                }
                                        } else {
+                                               if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) {
+                                                       _debug("update_rss_feed: user record FOUND");
+                                               }
+
                                                $entry_ref_id = db_fetch_result($result, 0, "ref_id");
                                                $entry_int_id = db_fetch_result($result, 0, "int_id");
                                        }
                $rtl_content = false, $last_updated = false, $last_error = false,
                $fg_content = false, $bg_content = false) {
 
+               if (!$feed_title) $feed_title = getFeedTitle($link, $feed_id, false);
+
                if (file_exists($icon_file) && filesize($icon_file) > 0) {
                                $feed_icon = "<img id=\"FIMG-$feed_id\" src=\"$icon_file\">";
                } else {
                        }
                } else if ($n_feed == -4) {
                        $match_part = "true";
-               } else if ($n_feed > 0) {
+               } else if ($n_feed >= 0) {
 
                        $result = db_query($link, "SELECT id FROM ttrss_feeds 
                                        WHERE parent_feed = '$n_feed'
                                return $unread;
 
                        } else {
-                               $match_part = "feed_id = '$n_feed'";
+                               if ($n_feed != 0) {
+                                       $match_part = "feed_id = '$n_feed'";
+                               } else {
+                                       $match_part = "feed_id IS NULL";
+                               }
                        }
                } else if ($feed < -10) {
 
                }
 
                if ($match_part) {
-               
+
+                       if ($n_feed != 0) {
+                               $from_qpart = "ttrss_user_entries,ttrss_feeds,ttrss_entries";
+                               $feeds_qpart = "ttrss_feeds.hidden = false AND
+                                       ttrss_user_entries.feed_id = ttrss_feeds.id AND";
+                       } else {
+                               $from_qpart = "ttrss_user_entries,ttrss_entries";
+                       }
+
                        $result = db_query($link, "SELECT count(int_id) AS unread 
-                               FROM ttrss_user_entries,ttrss_feeds,ttrss_entries WHERE
-                               ttrss_user_entries.feed_id = ttrss_feeds.id AND
+                               FROM $from_qpart WHERE
                                ttrss_user_entries.ref_id = ttrss_entries.id AND 
-                               ttrss_feeds.hidden = false AND
                                $age_qpart AND
                                $unread_qpart AND ($match_part) AND ttrss_user_entries.owner_uid = " . $owner_uid);
                                
 
                $ret_arr = array();
 
-               for ($i = -1; $i >= -4; $i--) {
+               for ($i = 0; $i >= -4; $i--) {
 
                        $count = getFeedUnread($link, $i);
        
                        return __("Fresh articles");
                } else if ($id == -4) {
                        return __("All articles");
+               } else if ($id == 0) {
+                       return __("Archived articles");
                } else if ($id < -10) {
                        $label_id = -$id - 11;
                        $result = db_query($link, "SELECT caption FROM ttrss_labels2 WHERE id = '$label_id'");
                                $query_strategy_part = "ttrss_entries.id > 0";
                                $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
                                        id = feed_id) as feed_title,";
-                       } else if ($feed >= 0 && $search && $search_mode == "this_cat") {
+                       } else if ($feed > 0 && $search && $search_mode == "this_cat") {
        
                                $vfeed_query_part = "ttrss_feeds.title AS feed_title,";         
 
                                        $query_strategy_part = "ttrss_entries.id > 0";
                                }
                                
-                       } else if ($feed >= 0) {
+                       } else if ($feed > 0) {
        
                                if ($cat_view) {
 
                                                $query_strategy_part = "feed_id = '$feed'";
                                        }
                                }
+                       } else if ($feed == 0) { // starred virtual feed
+                               $query_strategy_part = "feed_id IS NULL";
                        } else if ($feed == -1) { // starred virtual feed
                                $query_strategy_part = "marked = true";
                                $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
 } */
                                }
 
+                               if ($feed != "0") {
+                                       $from_qpart = "ttrss_entries,ttrss_user_entries,ttrss_feeds$ext_tables_part";
+                                       $feed_check_qpart = "ttrss_feeds.hidden = false AND 
+                                               ttrss_user_entries.feed_id = ttrss_feeds.id AND";
+
+                               } else {
+                                       $from_qpart = "ttrss_entries,ttrss_user_entries$ext_tables_part
+                                               LEFT JOIN ttrss_feeds ON (feed_id = ttrss_feeds.id)";
+                               }
+
                                $query = "SELECT DISTINCT 
                                                guid,
                                                ttrss_entries.id,ttrss_entries.title,
                                                ".SUBSTRING_FOR_DATE."(updated,1,19) as updated_noms,
                                                author,score
                                        FROM
-                                               ttrss_entries,ttrss_user_entries,ttrss_feeds$ext_tables_part
+                                               $from_qpart
                                        WHERE
                                        $group_limit_part
-                                       ttrss_feeds.hidden = false AND 
-                                       ttrss_user_entries.feed_id = ttrss_feeds.id AND
+                                       $feed_check_qpart
                                        ttrss_user_entries.ref_id = ttrss_entries.id AND
                                        ttrss_user_entries.owner_uid = '$owner_uid' AND
                                        $search_query_part
                                        $limit_query_part");    
                        }
 
+                       if (!$feed_title) $feed_title = getFeedTitle($link, $feed_id);
+
                        return array($result, $feed_title, $feed_site_url, $last_error);
                        
        }
                        $catchup_feed_link = "javascript:catchupCurrentFeed()";
                        $catchup_sel_link = "javascript:catchupSelection()";
 
+                       $archive_sel_link = "javascript:archiveSelection()";
+                       $delete_sel_link = "javascript:deleteSelection()";
+
                        if (!get_pref($link, 'COMBINED_DISPLAY_MODE')) {
 
                                $sel_all_link = "javascript:selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, '', true)";
                        print "<li onclick=\"$catchup_feed_link\">&nbsp;&nbsp;".__('Entire feed').
                                "</li>";
 
+                       if ($feed_id != "0") {
+                               print "<li class=\"insensitive\">".__('Selection:')."</li>
+                                       <li onclick=\"$archive_sel_link\">&nbsp;&nbsp;".__('Archive')."</li>";
+                       } else {
+                               print "<li class=\"insensitive\">".__('Selection:')."</li>
+                                       <li onclick=\"$archive_sel_link\">&nbsp;&nbsp;".__('Move back')."</li>
+                                       <li onclick=\"$delete_sel_link\">&nbsp;&nbsp;".__('Delete')."</li>";
+                       } 
+
                        //print "<li><span class=\"insensitive\">--------</span></li>";
                        print "<li class=\"insensitive\">".__('Assign label:')."</li>";
 
                $num_published = getFeedUnread($link, -2);
                $num_fresh = getFeedUnread($link, -3);
                $num_total = getFeedUnread($link, -4);
+               $num_archive = getFeedUnread($link, 0);
 
                $class = "virt";
 
                if ($num_total > 0) $class .= "Unread";
 
-               printFeedEntry(-4, $class, __("All articles"), $num_total, 
+               printFeedEntry(-4, $class, false, $num_total, 
+                       "images/tag.png", $link);
+
+               $class = "virt";
+
+               if ($num_archive > 0) $class .= "Unread";
+
+               printFeedEntry(0, $class, false, $num_archive, 
                        "images/tag.png", $link);
 
                $class = "virt";
 
                if ($num_fresh > 0) $class .= "Unread";
 
-               printFeedEntry(-3, $class, __("Fresh articles"), $num_fresh, 
+               printFeedEntry(-3, $class, false, $num_fresh, 
                        "images/fresh.png", $link);
 
                $class = "virt";
 
                if ($num_starred > 0) $class .= "Unread";
 
-               $is_ie = (strpos($_SESSION["client.userAgent"], "MSIE") !== false);
-
-               if ($is_ie) {
-                       $mark_img_ext = "gif";
-               } else {
-                       $mark_img_ext = "png";
-               }
-
-               printFeedEntry(-1, $class, __("Starred articles"), $num_starred, 
-                       "images/mark_set.$mark_img_ext", $link);
+               printFeedEntry(-1, $class, false, $num_starred, 
+                       "images/mark_set.png", $link);
 
                $class = "virt";
 
                if ($num_published > 0) $class .= "Unread";
 
-               printFeedEntry(-2, $class, __("Published articles"), $num_published, 
+               printFeedEntry(-2, $class, false, $num_published, 
                        "images/pub_set.gif", $link);
 
                if (get_pref($link, 'ENABLE_FEED_CATS')) {
                $zoom_mode = false) {
 
                /* we can figure out feed_id from article id anyway, why do we
-                * pass feed_id here? */
+                * pass feed_id here? let's ignore the argument :( */
 
                $result = db_query($link, "SELECT feed_id FROM ttrss_user_entries
                        WHERE ref_id = '$id'");
 
-               $feed_id = db_fetch_result($result, 0, "feed_id");
+               $feed_id = (int) db_fetch_result($result, 0, "feed_id");
 
                if (!$zoom_mode) { print "<article id='$id'><![CDATA["; };
 
 #                                                              truncate_string($line["feed_title"],30)."</a>&nbsp;</td>";
 #                                      } else {                        
 
-                                       print "<td onclick='view($id,$feed_id)' class='hlContent$hlc_suffix' valign='middle' id='HLC-$id'>";
+                                       print "<td onclick='view($id)' class='hlContent$hlc_suffix' valign='middle' id='HLC-$id'>";
 
                                        print "<a id=\"RTITLE-$id\" 
                                                href=\"" . htmlspecialchars($line["link"]) . "\"
 
 #                                      }
                                        
-                                       print "<td class=\"hlUpdated\" onclick='view($id,$feed_id)'><nobr>$updated_fmt&nbsp;</nobr></td>";
+                                       print "<td class=\"hlUpdated\" onclick='view($id)'><nobr>$updated_fmt&nbsp;</nobr></td>";
 
                                        print "<td class='hlMarkedPic'>$score_pic</td>";
 
         * @return void
         */
        function clear_feed_articles($link, $id) {
-               $result = db_query($link, "DELETE FROM ttrss_user_entries
+
+               if ($id != 0) {
+                       $result = db_query($link, "DELETE FROM ttrss_user_entries
                        WHERE feed_id = '$id' AND marked = false AND owner_uid = " . $_SESSION["uid"]);
+               } else {
+                       $result = db_query($link, "DELETE FROM ttrss_user_entries
+                       WHERE feed_id IS NULL AND marked = false AND owner_uid = " . $_SESSION["uid"]);
+               }
 
                $result = db_query($link, "DELETE FROM ttrss_entries WHERE 
                        (SELECT COUNT(int_id) FROM ttrss_user_entries WHERE ref_id = id) = 0");
        function remove_feed($link, $id, $owner_uid) {
 
                if ($id > 0) {
+
+                       /* save starred articles in Archived feed */
+
+                       db_query($link, "BEGIN");
+
+                       db_query($link, "UPDATE ttrss_user_entries SET feed_id = NULL 
+                               WHERE feed_id = '$id' AND 
+                                       marked = true AND owner_uid = $owner_uid");
+
+                       /* remove the feed */
+
                        db_query($link, "DELETE FROM ttrss_feeds 
                                        WHERE id = '$id' AND owner_uid = $owner_uid");
 
+                       db_query($link, "COMMIT");
+
                        if (file_exists(ICONS_DIR . "/$id.ico")) {
                                unlink(ICONS_DIR . "/$id.ico");
                        }
index 686602d6f80d2c016b9e90d540b5624137d55a89..326c669fbb08129eed13dab087c630c44efaa3bc 100644 (file)
                        return;
                }
 
+               if ($subop == "delete") {
+                       $ids = db_escape_string($_GET["ids"]);
+
+                       $result = db_query($link, "DELETE FROM ttrss_user_entries                               
+                               WHERE ref_id IN ($ids) AND owner_uid = " . $_SESSION["uid"]);
+
+                       print "<rpc-reply><counters>";
+                       getGlobalCounters($link);
+                       if (get_pref($link, 'ENABLE_FEED_CATS')) {
+                               getCategoryCounters($link);
+                       }
+                       print "</counters></rpc-reply>";
+
+                       return;
+               }
+
+               if ($subop == "unarchive") {
+                       $ids = db_escape_string($_GET["ids"]);
+
+                       $result = db_query($link, "UPDATE ttrss_user_entries 
+                               SET feed_id = orig_feed_id
+                               WHERE ref_id IN ($ids) AND owner_uid = " . $_SESSION["uid"]);
+
+                       print "<rpc-reply><counters>";
+                       getGlobalCounters($link);
+                       if (get_pref($link, 'ENABLE_FEED_CATS')) {
+                               getCategoryCounters($link);
+                       }
+                       print "</counters></rpc-reply>";
+
+                       return;
+               }
+
+               if ($subop == "archive") {
+                       $ids = db_escape_string($_GET["ids"]);
+
+                       $result = db_query($link, "UPDATE ttrss_user_entries 
+                               SET orig_feed_id = feed_id, feed_id = NULL, marked = true
+                               WHERE ref_id IN ($ids) AND owner_uid = " . $_SESSION["uid"]);
+
+                       print "<rpc-reply><counters>";
+                       getGlobalCounters($link);
+                       if (get_pref($link, 'ENABLE_FEED_CATS')) {
+                               getCategoryCounters($link);
+                       }
+                       print "</counters></rpc-reply>";
+
+                       return;
+               }
+
+
                if ($subop == "publ") {
                        $pub = $_REQUEST["pub"];
                        $id = db_escape_string($_REQUEST["id"]);
index 95edaffdd1d97fb814f88f34b86f0313decac044..c6de602878d480ed2255db022b82e3467c5d0eeb 100644 (file)
@@ -133,7 +133,8 @@ create index ttrss_entries_date_entered_index on ttrss_entries(date_entered);
 create table ttrss_user_entries (
        int_id integer not null primary key auto_increment,
        ref_id integer not null,
-       feed_id int not null, 
+       feed_id int, 
+       orig_feed_id int, 
        owner_uid integer not null,
        marked bool not null default 0,
        published bool not null default 0,
@@ -145,6 +146,8 @@ create table ttrss_user_entries (
        foreign key (ref_id) references ttrss_entries(id) ON DELETE CASCADE,
        index (feed_id),
        foreign key (feed_id) references ttrss_feeds(id) ON DELETE CASCADE,
+       index (orig_feed_id),
+       foreign key (orig_feed_id) references ttrss_feeds(id) ON DELETE SET NULL,
        index (owner_uid),
        foreign key (owner_uid) references ttrss_users(id) ON DELETE CASCADE) TYPE=InnoDB;
 
@@ -226,7 +229,7 @@ create table ttrss_tags (id integer primary key auto_increment,
 
 create table ttrss_version (schema_version int not null) TYPE=InnoDB;
 
-insert into ttrss_version values (59);
+insert into ttrss_version values (60);
 
 create table ttrss_enclosures (id serial not null primary key,
        content_url text not null,
index 0b6f719e14217a3de0948b9b19ba2e5db62a1114..7afebb5d97579113702e90cdc345794cdc4b4e9d 100644 (file)
@@ -121,7 +121,8 @@ create index ttrss_entries_date_entered_index on ttrss_entries(date_entered);
 create table ttrss_user_entries (
        int_id serial not null primary key,
        ref_id integer not null references ttrss_entries(id) ON DELETE CASCADE,
-       feed_id int references ttrss_feeds(id) ON DELETE CASCADE not null, 
+       feed_id int references ttrss_feeds(id) ON DELETE CASCADE, 
+       orig_feed_id int references ttrss_feeds(id) ON DELETE SET NULL, 
        owner_uid integer not null references ttrss_users(id) ON DELETE CASCADE,
        marked boolean not null default false,
        published boolean not null default false,
@@ -202,7 +203,7 @@ create index ttrss_tags_owner_uid_index on ttrss_tags(owner_uid);
 
 create table ttrss_version (schema_version int not null);
 
-insert into ttrss_version values (59);
+insert into ttrss_version values (60);
 
 create table ttrss_enclosures (id serial not null primary key,
        content_url text not null,
diff --git a/schema/versions/mysql/60.sql b/schema/versions/mysql/60.sql
new file mode 100644 (file)
index 0000000..a2c0233
--- /dev/null
@@ -0,0 +1,12 @@
+begin;
+
+alter table ttrss_user_entries change feed_id feed_id integer null;
+
+alter table ttrss_user_entries add column orig_feed_id integer;
+update ttrss_user_entries set orig_feed_id = NULL;
+
+alter table ttrss_user_entries add constraint FOREIGN KEY (orig_feed_id) REFERENCES ttrss_feeds(id) ON DELETE SET NULL;
+
+update ttrss_version set schema_version = 60;
+
+commit;
diff --git a/schema/versions/pgsql/60.sql b/schema/versions/pgsql/60.sql
new file mode 100644 (file)
index 0000000..39a2e20
--- /dev/null
@@ -0,0 +1,12 @@
+begin;
+
+alter table ttrss_user_entries alter column feed_id drop not null;
+
+alter table ttrss_user_entries add column orig_feed_id integer;
+update ttrss_user_entries set orig_feed_id = NULL;
+
+alter table ttrss_user_entries add constraint "$4" FOREIGN KEY (orig_feed_id) REFERENCES ttrss_feeds(id) ON DELETE SET NULL;
+
+update ttrss_version set schema_version = 60;
+
+commit;
index 9515cca6d30b4f0464f6be4d093c3e08579314b2..ef3ab2c6ccefda4f0354ef3b9f82604cc38cd8f9 100644 (file)
@@ -1321,6 +1321,106 @@ function catchupPage() {
        }
 }
 
+function deleteSelection() {
+
+       try {
+
+               var rows;
+       
+               if ($("headlinesList")) {
+                       rows = getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
+               } else {        
+                       rows = cdmGetSelectedArticles();
+               }
+       
+               if (rows.length == 0) {
+                       alert(__("No articles are selected."));
+                       return;
+               }
+       
+       
+               var fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
+               var str;
+               var op;
+       
+               if (getActiveFeedId() != 0) {
+                       str = __("Delete %d selected articles in %s?");
+               } else {
+                       str = __("Delete %d selected articles?");
+               }
+       
+               str = str.replace("%d", rows.length);
+               str = str.replace("%s", fn);
+       
+               if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
+                       return;
+               }
+
+               query = "backend.php?op=rpc&subop=delete&ids=" + param_escape(rows);
+
+               debug(query);
+
+               new Ajax.Request(query, {
+                       onComplete: function(transport) {
+                                       viewCurrentFeed();
+                               } });
+
+       } catch (e) {
+               exception_error("archiveSelection", e);
+       }
+}
+
+function archiveSelection() {
+
+       try {
+
+               var rows;
+       
+               if ($("headlinesList")) {
+                       rows = getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
+               } else {        
+                       rows = cdmGetSelectedArticles();
+               }
+       
+               if (rows.length == 0) {
+                       alert(__("No articles are selected."));
+                       return;
+               }
+       
+       
+               var fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
+               var str;
+               var op;
+       
+               if (getActiveFeedId() != 0) {
+                       str = __("Archive %d selected articles in %s?");
+                       op = "archive";
+               } else {
+                       str = __("Move %d archived articles back?");
+                       op = "unarchive";
+               }
+       
+               str = str.replace("%d", rows.length);
+               str = str.replace("%s", fn);
+       
+               if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
+                       return;
+               }
+
+               query = "backend.php?op=rpc&subop="+op+"&ids=" + param_escape(rows);
+
+               debug(query);
+
+               new Ajax.Request(query, {
+                       onComplete: function(transport) {
+                                       viewCurrentFeed();
+                               } });
+
+       } catch (e) {
+               exception_error("archiveSelection", e);
+       }
+}
+
 function catchupSelection() {
 
        try {