]> git.wh0rd.org Git - tt-rss.git/commitdiff
feed archive and feed browser improvements
authorAndrew Dolgov <fox@bah.org.ru>
Wed, 13 Jan 2010 10:44:20 +0000 (13:44 +0300)
committerAndrew Dolgov <fox@bah.org.ru>
Wed, 13 Jan 2010 10:44:20 +0000 (13:44 +0300)
functions.js
modules/backend-rpc.php
modules/popup-dialog.php
modules/pref-feeds.php
prefs.js
tt-rss.js

index ea3fcb7be49901ca75e24859a68ca082ed3d49cf..aa9bdcefe30897820cf73dc492d160ee60a4405f 100644 (file)
@@ -2006,11 +2006,7 @@ function getSelectedFeedsFromBrowser() {
 function updateFeedBrowser() {
        try {
 
-               var options = Form.serialize("feed_browser");
-
-               var query = "?op=rpc&subop=feedBrowser&" + options;
-
-               //notify_progress("Loading, please wait...", true);
+               var query = Form.serialize("feed_browser");
 
                Element.show('feed_browser_spinner');
 
@@ -2024,10 +2020,17 @@ function updateFeedBrowser() {
                                var c = $("browseFeedList");
                                var r = transport.responseXML.getElementsByTagName("content")[0];
                                var nr = transport.responseXML.getElementsByTagName("num-results")[0];
+                               var mode = transport.responseXML.getElementsByTagName("mode")[0];
 
                                if (c && r) {
                                        c.innerHTML = r.firstChild.nodeValue;
                                }
+
+                               if (parseInt(mode.getAttribute("value")) == 2) {
+                                       Element.show('feed_archive_remove');
+                               } else {
+                                       Element.hide('feed_archive_remove');
+                               }
        
                        } });
 
@@ -2041,7 +2044,7 @@ function browseFeeds(limit) {
 
        try {
 
-               var query = "?op=pref-feeds&subop=browse";
+/*             var query = "?op=ialog&subop=browse";
 
                notify_progress("Loading, please wait...", true);
 
@@ -2049,7 +2052,9 @@ function browseFeeds(limit) {
                        parameters: query,
                        onComplete: function(transport) { 
                                infobox_callback2(transport);
-                       } });
+                       } }); */
+
+               displayDlg('feedBrowser');
 
                return false;
        } catch (e) {
@@ -2169,3 +2174,77 @@ function displayNewContentPrompt(id) {
                exception_error("displayNewContentPrompt", e);
        }
 }
+
+function feedBrowserSubscribe() {
+       try {
+
+               var selected = getSelectedFeedsFromBrowser();
+
+               var mode = document.forms['feed_browser'].mode;
+
+               mode = mode[mode.selectedIndex].value;
+
+               if (selected.length > 0) {
+                       closeInfoBox();
+
+                       notify_progress("Loading, please wait...", true);
+
+                       var query = "?op=rpc&subop=massSubscribe&ids="+
+                               param_escape(selected.toString()) + "&mode=" + param_escape(mode);
+
+                       new Ajax.Request("backend.php", {
+                               parameters: query,
+                               onComplete: function(transport) { 
+
+                                       var nf = transport.responseXML.getElementsByTagName('num-feeds')[0];
+                                       var nf_value = nf.getAttribute("value");
+
+                                       notify_info(__("Subscribed to %d feed(s).").replace("%d", nf_value));
+
+                                       if (inPreferences()) {
+                                               updateFeedList();
+                                       } else {
+                                               setTimeout('updateFeedList(false, false)', 50);
+                                       }
+                               } });
+
+               } else {
+                       alert(__("No feeds are selected."));
+               }
+
+       } catch (e) {
+               exception_error("feedBrowserSubscribe", e);
+       }
+}
+
+function feedArchiveRemove() {
+       try {
+
+               var selected = getSelectedFeedsFromBrowser();
+
+               if (selected.length > 0) {
+
+                       var pr = __("Remove selected feeds from archive?");
+
+                       if (confirm(pr)) {
+                               Element.show('feed_browser_spinner');
+
+                               var query = "?op=rpc&subop=remarchived&ids=" + 
+                                       param_escape(selected.toString());;
+
+                               new Ajax.Request("backend.php", {
+                                       parameters: query,
+                                       onComplete: function(transport) { 
+                                               updateFeedBrowser();
+                                       } }); 
+                       }
+
+               } else {
+                       alert(__("No feeds are selected."));
+               }
+
+       } catch (e) {
+               exception_error("feedArchiveRemove", e);
+       }
+}
+
index e10a20de35e42e9b53fa61a7ce4f4bcbe3ed6065..1e0732ef82a612ecb48fae91459a6cf40e9328c9 100644 (file)
@@ -3,6 +3,28 @@
 
                $subop = $_REQUEST["subop"];
 
+               if ($subop == "remarchive") {
+                       $ids = split(",", db_escape_string($_REQUEST["ids"]));
+
+                       print "<rpc-reply>";
+
+                       foreach ($ids as $id) {
+                               $result = db_query($link, "DELETE FROM ttrss_archived_feeds WHERE
+                                       (SELECT COUNT(*) FROM ttrss_user_entries 
+                                               WHERE orig_feed_id = '$id') = 0 AND
+                                               id = '$id' AND owner_uid = ".$_SESSION["uid"]);
+
+                               $rc = db_affected_rows($link, $result);
+
+                               print "<feed id='$id' rc='$rc'/>";
+
+                       }
+
+                       print "</rpc-reply>";
+
+                       return;
+               }
+
                if ($subop == "addfeed") {
 
                        $feed = db_escape_string($_REQUEST['feed']);
                        return;
                }
 
-               if ($subop == "feedBrowser") {
+               if ($subop == "updateFeedBrowser") {
 
                        $search = db_escape_string($_REQUEST["search"]);
                        $limit = db_escape_string($_REQUEST["limit"]);
                        print "]]>";
                        print "</content>";
                        print "<num-results value=\"$ctr\"/>";
+                       print "<mode value=\"$mode\"/>";
                        print "</rpc-reply>";
 
                        return;
                }
 
+
+               if ($subop == "massSubscribe") {
+
+                       $ids = split(",", db_escape_string($_REQUEST["ids"]));
+                       $mode = $_REQUEST["mode"];
+
+                       $subscribed = array();
+
+                       foreach ($ids as $id) {
+
+                               if ($mode == 1) {
+                                       $result = db_query($link, "SELECT feed_url,title FROM ttrss_feeds
+                                               WHERE id = '$id'");
+                               } else if ($mode == 2) {
+                                       $result = db_query($link, "SELECT * FROM ttrss_archived_feeds
+                                               WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]);
+                                       $orig_id = db_escape_string(db_fetch_result($result, 0, "id"));
+                                       $site_url = db_escape_string(db_fetch_result($result, 0, "site_url"));
+                               }
+       
+                               $feed_url = db_escape_string(db_fetch_result($result, 0, "feed_url"));
+                               $title = db_escape_string(db_fetch_result($result, 0, "title"));
+       
+                               $title_orig = db_fetch_result($result, 0, "title");
+       
+                               $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE
+                                               feed_url = '$feed_url' AND owner_uid = " . $_SESSION["uid"]);
+       
+                               if (db_num_rows($result) == 0) {                        
+                                       if ($mode == 1) {
+                                               $result = db_query($link,
+                                                       "INSERT INTO ttrss_feeds (owner_uid,feed_url,title,cat_id) 
+                                                       VALUES ('".$_SESSION["uid"]."', '$feed_url', '$title', NULL)");
+                                       } else if ($mode == 2) {
+                                               $result = db_query($link,
+                                                       "INSERT INTO ttrss_feeds (id,owner_uid,feed_url,title,cat_id,site_url) 
+                                                       VALUES ('$orig_id','".$_SESSION["uid"]."', '$feed_url', '$title', NULL, '$site_url')");
+                                       }
+                                       array_push($subscribed, $title_orig);
+                               }
+                       }
+
+                       $num_feeds = count($subscribed);
+
+                       print "<rpc-reply>";
+                       print "<num-feeds value='$num_feeds'/>";
+                       print "</rpc-reply>";
+
+                       return;
+               } 
+
                if ($subop == "download") {
                        $stage = (int) $_REQUEST["stage"];
                        $cidt = (int)db_escape_string($_REQUEST["cidt"]);
index b5aae1846dcb0c118a86bbc6a27be21f9f6c1dc1..c3285fb0cebab561bdc3a2f4f77b1463d4a3a530 100644 (file)
                        return;
                }
 
+               if ($id == "feedBrowser") {
+
+                       print "<div id=\"infoBoxTitle\">".__('Feed Browser')."</div>";
+                       
+                       print "<div class=\"infoBoxContents\">";
+
+                       $browser_search = db_escape_string($_REQUEST["search"]);
+                       
+                       print "<form onsubmit='return false;' display='inline' 
+                               name='feed_browser' id='feed_browser'>";
+
+                       print "<input type=\"hidden\" name=\"op\" value=\"rpc\">";
+                       print "<input type=\"hidden\" name=\"subop\" value=\"updateFeedBrowser\">"; 
+
+                       print "
+                               <div style='float : right'>
+                               <img style='display : none' 
+                                       id='feed_browser_spinner' src='images/indicator_white.gif'>
+                               <input name=\"search\" size=\"20\" type=\"search\"
+                                       onchange=\"javascript:updateFeedBrowser()\" value=\"$browser_search\">
+                               <button onclick=\"javascript:updateFeedBrowser()\">".__('Search')."</button>
+                       </div>";
+
+                       print " <select name=\"mode\" onchange=\"updateFeedBrowser()\">
+                               <option value='1'>" . __('Popular feeds') . "</option>
+                               <option value='2'>" . __('Feed archive') . "</option>
+                               </select> ";
+
+                       print __("limit:");
+
+                       print " <select name=\"limit\" onchange='updateFeedBrowser()'>";
+
+                       foreach (array(25, 50, 100, 200) as $l) {
+                               $issel = ($l == $limit) ? "selected" : "";
+                               print "<option $issel>$l</option>";
+                       }
+                       
+                       print "</select> ";
+
+                       print "<p>";
+
+                       $owner_uid = $_SESSION["uid"];
+
+                       print "<ul class='browseFeedList' id='browseFeedList'>";
+                       print_feed_browser($link, $search, 25);
+                       print "</ul>";
+
+                       print "<div align='center'>
+                               <button onclick=\"feedBrowserSubscribe()\">".__('Subscribe')."</button>
+                               <button style='display : none' id='feed_archive_remove' onclick=\"feedArchiveRemove()\">".__('Remove from archive')."</button>
+                               <button onclick=\"closeInfoBox()\" >".__('Cancel')."</button></div>";
+
+                       print "</div>";
+                       return;
+               }
+
                if ($id == "search") {
 
                        print "<div id=\"infoBoxTitle\">".__('Search')."</div>";
index 9d33461afc8b3762d6f92f4f16039b31d9d38b1b..531396cf5b45af2d94691d55c6e886b72be5ef4a 100644 (file)
@@ -15,7 +15,7 @@
                $quiet = $_REQUEST["quiet"];
                $mode = $_REQUEST["mode"];
 
-               if ($subop == "massSubscribe") {
+/*             if ($subop == "massSubscribe") {
                        $ids = split(",", db_escape_string($_REQUEST["ids"]));
 
                        $subscribed = array();
 
                                print format_notice($msg);
                        }
-               }               
 
-               if ($subop == "browse") {
+                       return;
+               } */
+
+/*             if ($subop == "browse") {
 
                        print "<div id=\"infoBoxTitle\">".__('Feed Browser')."</div>";
                        
 
                        print "</div>";
                        return;
-               }
+               } */
 
                if ($subop == "editfeed") {
                        $feed_id = db_escape_string($_REQUEST["id"]);
                                        AND owner_uid = '$owner_uid') $search_qpart 
                                        ORDER BY subscribers DESC LIMIT $limit");
                        } else if ($mode == 2) {
-                               $result = db_query($link, "SELECT * FROM
-                                       ttrss_archived_feeds WHERE 
+                               $result = db_query($link, "SELECT *,
+                                       (SELECT COUNT(*) FROM ttrss_user_entries WHERE
+                                               orig_feed_id = ttrss_archived_feeds.id) AS articles_archived
+                                       FROM
+                                               ttrss_archived_feeds
+                                       WHERE 
                                        (SELECT COUNT(*) FROM ttrss_feeds 
                                                WHERE ttrss_feeds.feed_url = ttrss_archived_feeds.feed_url AND
                                                        owner_uid = '$owner_uid') = 0   AND                                     
 
                                if ($mode == 1) {
 
-                                       $feed_url = $line["feed_url"];
+                                       $feed_url = htmlspecialchars($line["feed_url"]);
                                        $subscribers = $line["subscribers"];
        
                                        $det_result = db_query($link, "SELECT site_url,title,id 
                                                $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
                                        }
        
-                                       $check_box = "<input onclick='toggleSelectListRow(this)' class='feedBrowseCB' 
+                                       $check_box = "<input onclick='toggleSelectListRow(this)' 
+                                               class='feedBrowseCB' 
                                                type=\"checkbox\" id=\"FBCHK-" . $details["id"] . "\">";
        
                                        $class = ($feedctr % 2) ? "even" : "odd";
        
                                        if ($details["site_url"]) {
-                                               $site_url = "<a target=\"_blank\" href=\"".$details["site_url"]."\">
+                                               $site_url = "<a target=\"_blank\" href=\"".
+                                                       htmlspecialchars($details["site_url"])."\">
                                                        <img style='border-width : 0px' src='images/www.png' alt='www'></a>";
                                        } else {
                                                $site_url = "";
                                        }
        
-                                       print "<li class='$class' id=\"FBROW-".$details["id"]."\">$check_box".
-                                               "$feed_icon " . $details["title"] . 
+                                       print "<li title=\"".htmlspecialchars($details["site_url"])."\" 
+                                               class='$class' id=\"FBROW-".$details["id"]."\">$check_box".
+                                               "$feed_icon " . htmlspecialchars($details["title"]) . 
                                                "&nbsp;<span class='subscribers'>($subscribers)</span>
-                                               $site_url
-                                               </li>";
+                                               $site_url</li>";
        
                                } else if ($mode == 2) {
-                                       $feed_url = $line["feed_url"];
+                                       $feed_url = htmlspecialchars($line["feed_url"]);
+                                       $site_url = htmlspecialchars($line["site_url"]); 
+                                       $title = htmlspecialchars($line["title"]);
 
                                        $icon_file = ICONS_DIR . "/" . $line["id"] . ".ico";
        
                                                type=\"checkbox\" id=\"FBCHK-" . $line["id"] . "\">";
        
                                        $class = ($feedctr % 2) ? "even" : "odd";
-       
+
+                                       if ($line['articles_archived'] > 0) {
+                                               $archived = sprintf(__("%d archived articles"), $line['articles_archived']);
+                                               $archived = "&nbsp;<span class='subscribers'>($archived)</span>";
+                                       } else {
+                                               $archived = '';
+                                       }
+
                                        if ($line["site_url"]) {
-                                               $site_url = "<a target=\"_blank\" href=\"".$line["site_url"]."\">
+                                               $site_url = "<a target=\"_blank\" href=\"$site_url\">
                                                        <img style='border-width : 0px' src='images/www.png' alt='www'></a>";
                                        } else {
                                                $site_url = "";
                                        }
        
-                                       print "<li class='$class' id=\"FBROW-".$line["id"]."\">$check_box".
-                                               "$feed_icon " . $line["title"] . $site_url . "</li>";
+                                       print "<li title='".$line['site_url']."' class='$class' 
+                                               id=\"FBROW-".$line["id"]."\">".
+                                               $check_box . "$feed_icon " . $title . $archived . $site_url . "</li>";
 
 
                                }
index bf2574445cabbb5860dc45687987d6da457191f8..59e455443dd3e3d8b263fe63722b965fb5e3e2d5 100644 (file)
--- a/prefs.js
+++ b/prefs.js
@@ -1214,7 +1214,7 @@ function validatePrefsReset() {
 
 }
 
-function feedBrowserSubscribe() {
+/*function feedBrowserSubscribe() {
        try {
 
                var selected = getSelectedFeedsFromBrowser();
@@ -1242,7 +1242,7 @@ function feedBrowserSubscribe() {
        } catch (e) {
                exception_error("feedBrowserSubscribe", e);
        }
-}
+} */
 
 function updateBigFeedBrowserBtn() {
        notify_progress("Loading, please wait...");
index eef469c4f361ecdd1eec4e9fd502e05ef757d54f..988f2bac41f8485284c2f08c143d0b2979a23116 100644 (file)
--- a/tt-rss.js
+++ b/tt-rss.js
@@ -1470,39 +1470,6 @@ function visitOfficialSite() {
        window.open("http://tt-rss.org/");
 }
 
-
-function feedBrowserSubscribe() {
-       try {
-
-               var selected = getSelectedFeedsFromBrowser();
-
-               var mode = document.forms['feed_browser'].mode;
-
-               mode = mode[mode.selectedIndex].value;
-
-               if (selected.length > 0) {
-                       closeInfoBox();
-
-                       notify_progress("Loading, please wait...", true);
-
-                       var query = "?op=pref-feeds&subop=massSubscribe&ids="+
-                               param_escape(selected.toString()) + "&mode=" + param_escape(mode);
-
-                       new Ajax.Request("backend.php", {
-                               parameters: query,
-                               onComplete: function(transport) { 
-                                       updateFeedList();
-                               } });
-
-               } else {
-                       alert(__("No feeds are selected."));
-               }
-
-       } catch (e) {
-               exception_error("feedBrowserSubscribe", e);
-       }
-}
-
 function inPreferences() {
        return false;
 }