feed browser: add access to archived feeds

This commit is contained in:
Andrew Dolgov 2010-01-11 15:40:35 +03:00
parent 661aabe741
commit 082ae95b96
5 changed files with 125 additions and 67 deletions

View File

@ -2051,18 +2051,9 @@ function getSelectedFeedsFromBrowser() {
function updateFeedBrowser() { function updateFeedBrowser() {
try { try {
var query = "?op=rpc&subop=feedBrowser"; var options = Form.serialize("feed_browser");
var search = $("feed_browser_search"); var query = "?op=rpc&subop=feedBrowser&" + options;
var limit = $("feed_browser_limit");
if (limit) {
query = query + "&limit=" + limit[limit.selectedIndex].value;
}
if (search) {
query = query + "&search=" + param_escape(search.value);
}
//notify_progress("Loading, please wait...", true); //notify_progress("Loading, please wait...", true);
@ -2094,10 +2085,10 @@ function updateFeedBrowser() {
} }); } });
} catch (e) { } catch (e) {
exception_error("updateFeedBrowser", e); exception_error("updateFeedBrowser", e);
} }
} }
function browseFeeds(limit) { function browseFeeds(limit) {

View File

@ -556,11 +556,12 @@
$search = db_escape_string($_REQUEST["search"]); $search = db_escape_string($_REQUEST["search"]);
$limit = db_escape_string($_REQUEST["limit"]); $limit = db_escape_string($_REQUEST["limit"]);
$mode = db_escape_string($_REQUEST["mode"]);
print "<rpc-reply>"; print "<rpc-reply>";
print "<content>"; print "<content>";
print "<![CDATA["; print "<![CDATA[";
$ctr = print_feed_browser($link, $search, $limit); $ctr = print_feed_browser($link, $search, $limit, $mode);
print "]]>"; print "]]>";
print "</content>"; print "</content>";
print "<num-results value=\"$ctr\"/>"; print "<num-results value=\"$ctr\"/>";

View File

@ -13,6 +13,7 @@
$subop = $_REQUEST["subop"]; $subop = $_REQUEST["subop"];
$quiet = $_REQUEST["quiet"]; $quiet = $_REQUEST["quiet"];
$mode = $_REQUEST["mode"];
if ($subop == "massSubscribe") { if ($subop == "massSubscribe") {
$ids = split(",", db_escape_string($_REQUEST["ids"])); $ids = split(",", db_escape_string($_REQUEST["ids"]));
@ -20,8 +21,15 @@
$subscribed = array(); $subscribed = array();
foreach ($ids as $id) { 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")); $feed_url = db_escape_string(db_fetch_result($result, 0, "feed_url"));
$title = db_escape_string(db_fetch_result($result, 0, "title")); $title = db_escape_string(db_fetch_result($result, 0, "title"));
@ -29,13 +37,18 @@
$title_orig = db_fetch_result($result, 0, "title"); $title_orig = db_fetch_result($result, 0, "title");
$result = db_query($link, "SELECT id FROM ttrss_feeds WHERE $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) { if (db_num_rows($result) == 0) {
$result = db_query($link, if ($mode == 1) {
"INSERT INTO ttrss_feeds (owner_uid,feed_url,title,cat_id) $result = db_query($link,
VALUES ('".$_SESSION["uid"]."', '$feed_url', '$title', NULL)"); "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); array_push($subscribed, $title_orig);
} }
} }
@ -68,11 +81,13 @@
//print "<p>".__("Showing top 25 registered feeds, sorted by popularity:")."</p>"; //print "<p>".__("Showing top 25 registered feeds, sorted by popularity:")."</p>";
print "<form onsubmit='return false;' display='inline' name='feed_browser' id='feed_browser'>";
print " print "
<div style='float : right'> <div style='float : right'>
<img style='display : none' <img style='display : none'
id='feed_browser_spinner' src='images/indicator_white.gif'> id='feed_browser_spinner' src='images/indicator_white.gif'>
<input id=\"feed_browser_search\" size=\"20\" type=\"search\" <input name=\"search\" size=\"20\" type=\"search\"
onfocus=\"javascript:disableHotkeys();\" onfocus=\"javascript:disableHotkeys();\"
onblur=\"javascript:enableHotkeys();\" onblur=\"javascript:enableHotkeys();\"
onchange=\"javascript:updateFeedBrowser()\" value=\"$browser_search\"> onchange=\"javascript:updateFeedBrowser()\" value=\"$browser_search\">
@ -80,14 +95,23 @@
onclick=\"javascript:updateFeedBrowser()\" value=\"".__('Search')."\"> onclick=\"javascript:updateFeedBrowser()\" value=\"".__('Search')."\">
</div>"; </div>";
print __('Top')." <select id=\"feed_browser_limit\">"; 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\">";
foreach (array(25, 50, 100, 200) as $l) { foreach (array(25, 50, 100, 200) as $l) {
$issel = ($l == $limit) ? "selected" : ""; $issel = ($l == $limit) ? "selected" : "";
print "<option $issel>$l</option>"; print "<option $issel>$l</option>";
} }
print "</select> print "</select> ";
print "
<input type=\"submit\" class=\"button\" <input type=\"submit\" class=\"button\"
onclick=\"updateFeedBrowser()\" value=\"".__('Show')."\">"; onclick=\"updateFeedBrowser()\" value=\"".__('Show')."\">";
@ -1135,7 +1159,7 @@
if (ENABLE_FEED_BROWSER && !SINGLE_USER_MODE) { if (ENABLE_FEED_BROWSER && !SINGLE_USER_MODE) {
print " <input type=\"submit\" class=\"button\" print " <input type=\"submit\" class=\"button\"
id=\"top25_feeds_btn\" id=\"top25_feeds_btn\"
onclick=\"javascript:browseFeeds()\" value=\"".__('More Feeds')."\">"; onclick=\"javascript:browseFeeds()\" value=\"".__('More feeds')."\">";
} }
$feeds_sort = db_escape_string($_REQUEST["sort"]); $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"]; $owner_uid = $_SESSION["uid"];
@ -1481,51 +1505,85 @@
$search_qpart = ""; $search_qpart = "";
} }
$result = db_query($link, "SELECT feed_url, subscribers FROM if ($mode == 1) {
ttrss_feedbrowser_cache WHERE (SELECT COUNT(id) = 0 FROM ttrss_feeds AS tf $result = db_query($link, "SELECT feed_url, subscribers FROM
WHERE tf.feed_url = ttrss_feedbrowser_cache.feed_url ttrss_feedbrowser_cache WHERE (SELECT COUNT(id) = 0 FROM ttrss_feeds AS tf
AND owner_uid = '$owner_uid') $search_qpart WHERE tf.feed_url = ttrss_feedbrowser_cache.feed_url
ORDER BY subscribers DESC LIMIT $limit"); 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; $feedctr = 0;
while ($line = db_fetch_assoc($result)) { while ($line = db_fetch_assoc($result)) {
$feed_url = $line["feed_url"];
$subscribers = $line["subscribers"];
$det_result = db_query($link, "SELECT site_url,title,id if ($mode == 1) {
FROM ttrss_feeds WHERE feed_url = '$feed_url' LIMIT 1");
$details = db_fetch_assoc($det_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");
$details = db_fetch_assoc($det_result);
$icon_file = ICONS_DIR . "/" . $details["id"] . ".ico";
if (file_exists($icon_file) && filesize($icon_file) > 0) {
$feed_icon = "<img class=\"tinyFeedIcon\" src=\"" . ICONS_URL .
"/".$details["id"].".ico\">";
} else {
$feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
}
$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"]."\">
<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"] .
"&nbsp;<span class='subscribers'>($subscribers)</span>
$site_url
</li>";
} else if ($mode == 2) {
$feed_url = $line["feed_url"];
$check_box = "<input onclick='toggleSelectListRow(this)' class='feedBrowseCB'
type=\"checkbox\" id=\"FBCHK-" . $line["id"] . "\">";
$class = ($feedctr % 2) ? "even" : "odd";
if ($line["site_url"]) {
$site_url = "<a target=\"_blank\" href=\"".$line["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".
$line["title"] . $site_url . "</li>";
$icon_file = ICONS_DIR . "/" . $details["id"] . ".ico";
if (file_exists($icon_file) && filesize($icon_file) > 0) {
$feed_icon = "<img class=\"tinyFeedIcon\" src=\"" . ICONS_URL .
"/".$details["id"].".ico\">";
} else {
$feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
} }
$check_box = "<input onclick='toggleSelectListRow(this)' class='feedBrowseCB' ++$feedctr;
type=\"checkbox\" id=\"FBCHK-" . $details["id"] . "\">";
$class = ($feedctr % 2) ? "even" : "odd";
if ($details["site_url"]) {
$site_url = "<a target=\"_blank\" href=\"".$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"] .
"&nbsp;<span class='subscribers'>($subscribers)</span>
$site_url
</li>";
++$feedctr;
} }
if ($feedctr == 0) { if ($feedctr == 0) {

View File

@ -1318,11 +1318,15 @@ function feedBrowserSubscribe() {
var selected = getSelectedFeedsFromBrowser(); var selected = getSelectedFeedsFromBrowser();
var mode = document.forms['feed_browser'].mode;
mode = mode[mode.selectedIndex].value;
if (selected.length > 0) { if (selected.length > 0) {
closeInfoBox(); closeInfoBox();
var query = "?op=pref-feeds&subop=massSubscribe&ids="+ 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", { new Ajax.Request("backend.php", {
parameters: query, parameters: query,

View File

@ -1493,13 +1493,17 @@ function feedBrowserSubscribe() {
var selected = getSelectedFeedsFromBrowser(); var selected = getSelectedFeedsFromBrowser();
var mode = document.forms['feed_browser'].mode;
mode = mode[mode.selectedIndex].value;
if (selected.length > 0) { if (selected.length > 0) {
closeInfoBox(); closeInfoBox();
notify_progress("Loading, please wait...", true); notify_progress("Loading, please wait...", true);
var query = "backend.php?op=pref-feeds&subop=massSubscribe&ids="+ 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", { new Ajax.Request("backend.php", {
parameters: query, parameters: query,