From 082ae95b9631d89f06bcfef311d8856090061031 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Mon, 11 Jan 2010 15:40:35 +0300 Subject: [PATCH] feed browser: add access to archived feeds --- functions.js | 15 +--- modules/backend-rpc.php | 3 +- modules/pref-feeds.php | 160 +++++++++++++++++++++++++++------------- prefs.js | 6 +- tt-rss.js | 8 +- 5 files changed, 125 insertions(+), 67 deletions(-) diff --git a/functions.js b/functions.js index 3c7971558..5228995cd 100644 --- a/functions.js +++ b/functions.js @@ -2051,18 +2051,9 @@ function getSelectedFeedsFromBrowser() { function updateFeedBrowser() { try { - var query = "?op=rpc&subop=feedBrowser"; + var options = Form.serialize("feed_browser"); - var search = $("feed_browser_search"); - var limit = $("feed_browser_limit"); - - if (limit) { - query = query + "&limit=" + limit[limit.selectedIndex].value; - } - - if (search) { - query = query + "&search=" + param_escape(search.value); - } + var query = "?op=rpc&subop=feedBrowser&" + options; //notify_progress("Loading, please wait...", true); @@ -2094,10 +2085,10 @@ function updateFeedBrowser() { } }); - } catch (e) { exception_error("updateFeedBrowser", e); } + } function browseFeeds(limit) { diff --git a/modules/backend-rpc.php b/modules/backend-rpc.php index 8b1252127..87178935c 100644 --- a/modules/backend-rpc.php +++ b/modules/backend-rpc.php @@ -556,11 +556,12 @@ $search = db_escape_string($_REQUEST["search"]); $limit = db_escape_string($_REQUEST["limit"]); + $mode = db_escape_string($_REQUEST["mode"]); print ""; print ""; print ""; print ""; print ""; diff --git a/modules/pref-feeds.php b/modules/pref-feeds.php index 4c9ed19a9..a3f1a472f 100644 --- a/modules/pref-feeds.php +++ b/modules/pref-feeds.php @@ -13,6 +13,7 @@ $subop = $_REQUEST["subop"]; $quiet = $_REQUEST["quiet"]; + $mode = $_REQUEST["mode"]; if ($subop == "massSubscribe") { $ids = split(",", db_escape_string($_REQUEST["ids"])); @@ -20,22 +21,34 @@ $subscribed = array(); foreach ($ids as $id) { - $result = db_query($link, "SELECT feed_url,title FROM ttrss_feeds - WHERE id = '$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 id,feed_url,title FROM ttrss_archived_feeds + WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]); + $orig_id = db_escape_string(db_fetch_result($result, 0, "id")); + } + $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"]); - + feed_url = '$feed_url' AND owner_uid = " . $_SESSION["uid"]); + if (db_num_rows($result) == 0) { - $result = db_query($link, - "INSERT INTO ttrss_feeds (owner_uid,feed_url,title,cat_id) - VALUES ('".$_SESSION["uid"]."', '$feed_url', '$title', NULL)"); - + 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) + VALUES ('$orig_id','".$_SESSION["uid"]."', '$feed_url', '$title', NULL)"); + } array_push($subscribed, $title_orig); } } @@ -68,11 +81,13 @@ //print "

".__("Showing top 25 registered feeds, sorted by popularity:")."

"; + print "
"; + print "
- @@ -80,14 +95,23 @@ onclick=\"javascript:updateFeedBrowser()\" value=\"".__('Search')."\">
"; - print __('Top')." + + + "; + + print __("limit:"); + + print " + print " "; + + print " "; @@ -1135,7 +1159,7 @@ if (ENABLE_FEED_BROWSER && !SINGLE_USER_MODE) { print " "; + onclick=\"javascript:browseFeeds()\" value=\"".__('More feeds')."\">"; } $feeds_sort = db_escape_string($_REQUEST["sort"]); @@ -1470,7 +1494,7 @@ } - function print_feed_browser($link, $search, $limit) { + function print_feed_browser($link, $search, $limit, $mode = 1) { $owner_uid = $_SESSION["uid"]; @@ -1481,51 +1505,85 @@ $search_qpart = ""; } - $result = db_query($link, "SELECT feed_url, subscribers FROM - ttrss_feedbrowser_cache WHERE (SELECT COUNT(id) = 0 FROM ttrss_feeds AS tf - WHERE tf.feed_url = ttrss_feedbrowser_cache.feed_url - AND owner_uid = '$owner_uid') $search_qpart - ORDER BY subscribers DESC LIMIT $limit"); + if ($mode == 1) { + $result = db_query($link, "SELECT feed_url, subscribers FROM + ttrss_feedbrowser_cache WHERE (SELECT COUNT(id) = 0 FROM ttrss_feeds AS tf + WHERE tf.feed_url = ttrss_feedbrowser_cache.feed_url + 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 + (SELECT COUNT(*) FROM ttrss_feeds + WHERE ttrss_feeds.feed_url = ttrss_archived_feeds.feed_url AND + owner_uid = '$owner_uid') = 0 AND + owner_uid = '$owner_uid' $search_qpart + ORDER BY id DESC LIMIT $limit"); + } $feedctr = 0; while ($line = db_fetch_assoc($result)) { - $feed_url = $line["feed_url"]; - $subscribers = $line["subscribers"]; - $det_result = db_query($link, "SELECT site_url,title,id - FROM ttrss_feeds WHERE feed_url = '$feed_url' LIMIT 1"); + if ($mode == 1) { + + $feed_url = $line["feed_url"]; + $subscribers = $line["subscribers"]; + + $det_result = db_query($link, "SELECT site_url,title,id + FROM ttrss_feeds WHERE feed_url = '$feed_url' LIMIT 1"); + + $details = db_fetch_assoc($det_result); + + $icon_file = ICONS_DIR . "/" . $details["id"] . ".ico"; + + if (file_exists($icon_file) && filesize($icon_file) > 0) { + $feed_icon = ""; + } else { + $feed_icon = ""; + } + + $check_box = ""; + + $class = ($feedctr % 2) ? "even" : "odd"; + + if ($details["site_url"]) { + $site_url = " + www"; + } else { + $site_url = ""; + } + + print "
  • $check_box". + "$feed_icon " . $details["title"] . + " ($subscribers) + $site_url +
  • "; + + } else if ($mode == 2) { + $feed_url = $line["feed_url"]; + + $check_box = ""; + + $class = ($feedctr % 2) ? "even" : "odd"; + + if ($line["site_url"]) { + $site_url = " + www"; + } else { + $site_url = ""; + } + + print "
  • $check_box". + $line["title"] . $site_url . "
  • "; - $details = db_fetch_assoc($det_result); - - $icon_file = ICONS_DIR . "/" . $details["id"] . ".ico"; - if (file_exists($icon_file) && filesize($icon_file) > 0) { - $feed_icon = ""; - } else { - $feed_icon = ""; } - $check_box = ""; - - $class = ($feedctr % 2) ? "even" : "odd"; - - if ($details["site_url"]) { - $site_url = " - www"; - } else { - $site_url = ""; - } - - print "
  • $check_box". - "$feed_icon " . $details["title"] . - " ($subscribers) - $site_url -
  • "; - - ++$feedctr; + ++$feedctr; } if ($feedctr == 0) { diff --git a/prefs.js b/prefs.js index 20277a462..36665532e 100644 --- a/prefs.js +++ b/prefs.js @@ -1318,11 +1318,15 @@ function feedBrowserSubscribe() { var selected = getSelectedFeedsFromBrowser(); + var mode = document.forms['feed_browser'].mode; + + mode = mode[mode.selectedIndex].value; + if (selected.length > 0) { closeInfoBox(); var query = "?op=pref-feeds&subop=massSubscribe&ids="+ - param_escape(selected.toString()); + param_escape(selected.toString()) + "&mode=" + param_escape(mode); new Ajax.Request("backend.php", { parameters: query, diff --git a/tt-rss.js b/tt-rss.js index 27432be75..88a41afef 100644 --- a/tt-rss.js +++ b/tt-rss.js @@ -1493,13 +1493,17 @@ function feedBrowserSubscribe() { 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 = "backend.php?op=pref-feeds&subop=massSubscribe&ids="+ - param_escape(selected.toString()); + var query = "?op=pref-feeds&subop=massSubscribe&ids="+ + param_escape(selected.toString()) + "&mode=" + param_escape(mode); new Ajax.Request("backend.php", { parameters: query,