diff --git a/functions.js b/functions.js index ea3fcb7be..aa9bdcefe 100644 --- a/functions.js +++ b/functions.js @@ -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); + } +} + diff --git a/modules/backend-rpc.php b/modules/backend-rpc.php index e10a20de3..1e0732ef8 100644 --- a/modules/backend-rpc.php +++ b/modules/backend-rpc.php @@ -3,6 +3,28 @@ $subop = $_REQUEST["subop"]; + if ($subop == "remarchive") { + $ids = split(",", db_escape_string($_REQUEST["ids"])); + + print ""; + + 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 ""; + + } + + print ""; + + return; + } + if ($subop == "addfeed") { $feed = db_escape_string($_REQUEST['feed']); @@ -569,7 +591,7 @@ return; } - if ($subop == "feedBrowser") { + if ($subop == "updateFeedBrowser") { $search = db_escape_string($_REQUEST["search"]); $limit = db_escape_string($_REQUEST["limit"]); @@ -582,11 +604,63 @@ print "]]>"; print ""; print ""; + print ""; print ""; 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 ""; + print ""; + print ""; + + return; + } + if ($subop == "download") { $stage = (int) $_REQUEST["stage"]; $cidt = (int)db_escape_string($_REQUEST["cidt"]); diff --git a/modules/popup-dialog.php b/modules/popup-dialog.php index b5aae1846..c3285fb0c 100644 --- a/modules/popup-dialog.php +++ b/modules/popup-dialog.php @@ -142,6 +142,62 @@ return; } + if ($id == "feedBrowser") { + + print "
".__('Feed Browser')."
"; + + print "
"; + + $browser_search = db_escape_string($_REQUEST["search"]); + + print "
"; + + print ""; + print ""; + + print " +
+ + + +
"; + + print " "; + + print __("limit:"); + + print " "; + + print "

"; + + $owner_uid = $_SESSION["uid"]; + + print "

    "; + print_feed_browser($link, $search, 25); + print "
"; + + print "
+ + +
"; + + print "
"; + return; + } + if ($id == "search") { print "
".__('Search')."
"; diff --git a/modules/pref-feeds.php b/modules/pref-feeds.php index 9d33461af..531396cf5 100644 --- a/modules/pref-feeds.php +++ b/modules/pref-feeds.php @@ -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(); @@ -65,9 +65,11 @@ print format_notice($msg); } - } - if ($subop == "browse") { + return; + } */ + +/* if ($subop == "browse") { print "
".__('Feed Browser')."
"; @@ -118,7 +120,7 @@ print ""; return; - } + } */ if ($subop == "editfeed") { $feed_id = db_escape_string($_REQUEST["id"]); @@ -1437,8 +1439,12 @@ 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 @@ -1452,7 +1458,7 @@ 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 @@ -1469,26 +1475,30 @@ $feed_icon = ""; } - $check_box = ""; $class = ($feedctr % 2) ? "even" : "odd"; if ($details["site_url"]) { - $site_url = " + $site_url = " www"; } else { $site_url = ""; } - print "
  • $check_box". - "$feed_icon " . $details["title"] . + print "
  • $check_box". + "$feed_icon " . htmlspecialchars($details["title"]) . " ($subscribers) - $site_url -
  • "; + $site_url"; } 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"; @@ -1503,16 +1513,24 @@ 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 = " ($archived)"; + } else { + $archived = ''; + } + if ($line["site_url"]) { - $site_url = " + $site_url = " www"; } else { $site_url = ""; } - print "
  • $check_box". - "$feed_icon " . $line["title"] . $site_url . "
  • "; + print "
  • ". + $check_box . "$feed_icon " . $title . $archived . $site_url . "
  • "; } diff --git a/prefs.js b/prefs.js index bf2574445..59e455443 100644 --- 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..."); diff --git a/tt-rss.js b/tt-rss.js index eef469c4f..988f2bac4 100644 --- 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; }