more work on tag support

This commit is contained in:
Andrew Dolgov 2005-09-09 08:45:54 +01:00
parent eb36b4eb55
commit 8143ae1f2b
8 changed files with 241 additions and 167 deletions

1
NEWS
View File

@ -2,6 +2,7 @@ v1.0.4 (Sep xx, 2005)
- "Starred items" virtual feed - "Starred items" virtual feed
- Experimental support for Gmail-like labels - Experimental support for Gmail-like labels
- Basic support for Technorati-style tags
v1.0.3.1 (Sep 07, 2005) v1.0.3.1 (Sep 07, 2005)

View File

@ -18,6 +18,29 @@
$fetch = $_GET["fetch"]; $fetch = $_GET["fetch"];
/* FIXME this needs reworking */
function getTagCounters($link) {
$result = db_query($link, "SELECT tag_name,count(ttrss_entries.id) AS count
FROM ttrss_tags,ttrss_entries WHERE
post_id = ttrss_entries.id AND unread = true GROUP BY tag_name
UNION
select tag_name,0 as count FROM ttrss_tags");
$tags = array();
while ($line = db_fetch_assoc($result)) {
$tags[$line["tag_name"]] += $line["count"];
}
foreach (array_keys($tags) as $tag) {
$unread = $tags[$tag];
$tag = htmlspecialchars($tag);
print "<tag id=\"$tag\" counter=\"$unread\"/>";
}
}
function getLabelCounters($link) { function getLabelCounters($link) {
$result = db_query($link, "SELECT count(id) as count FROM ttrss_entries $result = db_query($link, "SELECT count(id) as count FROM ttrss_entries
@ -75,7 +98,7 @@
} }
} }
function outputFeedList($link) { function outputFeedList($link, $tags = false) {
print "<html><head> print "<html><head>
<title>Tiny Tiny RSS : Feedlist</title> <title>Tiny Tiny RSS : Feedlist</title>
@ -87,13 +110,16 @@
print "<ul class=\"feedList\" id=\"feedList\">"; print "<ul class=\"feedList\" id=\"feedList\">";
if (!$tags) {
/* virtual feeds */ /* virtual feeds */
$result = db_query($link, "SELECT count(id) as num_starred $result = db_query($link, "SELECT count(id) as num_starred
FROM ttrss_entries WHERE marked = true AND unread = true"); FROM ttrss_entries WHERE marked = true AND unread = true");
$num_starred = db_fetch_result($result, 0, "num_starred"); $num_starred = db_fetch_result($result, 0, "num_starred");
printFeedEntry(-1, "odd", "Starred articles", $num_starred, "images/mark_set.png"); printFeedEntry(-1, "odd", "Starred articles", $num_starred,
"images/mark_set.png");
if (ENABLE_LABELS) { if (ENABLE_LABELS) {
@ -170,8 +196,39 @@
++$lnum; ++$lnum;
} }
} else {
print "</table>"; // tags
$result = db_query($link, "SELECT tag_name,count(ttrss_entries.id) AS count
FROM ttrss_tags,ttrss_entries WHERE
post_id = ttrss_entries.id AND unread = true GROUP BY tag_name
UNION
select tag_name,0 as count FROM ttrss_tags");
$tags = array();
while ($line = db_fetch_assoc($result)) {
$tags[$line["tag_name"]] += $line["count"];
}
foreach (array_keys($tags) as $tag) {
$unread = $tags[$tag];
$class = "odd";
if ($unread > 0) {
$class .= "Unread";
}
printFeedEntry($tag, $class, $tag, $unread, "images/tag.png");
}
}
print "</ul>";
print "<div class=\"invisible\" id=\"FEEDTU\">$total_unread</div>"; print "<div class=\"invisible\" id=\"FEEDTU\">$total_unread</div>";
@ -202,6 +259,7 @@
print "<rpc-reply>"; print "<rpc-reply>";
getLabelCounters($link); getLabelCounters($link);
getFeedCounters($link); getFeedCounters($link);
getTagCounters($link);
print "</rpc-reply>"; print "</rpc-reply>";
} }
@ -242,6 +300,7 @@
print "<rpc-reply>"; print "<rpc-reply>";
getLabelCounters($link); getLabelCounters($link);
getFeedCounters($link); getFeedCounters($link);
getTagCounters($link);
print "</rpc-reply>"; print "</rpc-reply>";
} }
@ -262,13 +321,15 @@
if ($op == "feeds") { if ($op == "feeds") {
$tags = $_GET["tags"];
$subop = $_GET["subop"]; $subop = $_GET["subop"];
if ($subop == "catchupAll") { if ($subop == "catchupAll") {
db_query($link, "UPDATE ttrss_entries SET last_read = NOW(),unread = false"); db_query($link, "UPDATE ttrss_entries SET last_read = NOW(),unread = false");
} }
outputFeedList($link); outputFeedList($link, $tags);
} }
@ -331,7 +392,7 @@
print "</div>"; print "</div>";
print "<script type=\"text/javascript\"> print "<script type=\"text/javascript\">
update_label_counters($feed_id); update_label_counters('$feed_id');
</script>"; </script>";
} }
@ -368,7 +429,7 @@
</head><body>"; </head><body>";
} }
if ($feed >= 0) { if (sprintf("%d", $feed) != 0 && $feed >= 0) {
$result = db_query($link, $result = db_query($link,
"SELECT *,SUBSTRING(last_updated,1,16) as last_updated_s "SELECT *,SUBSTRING(last_updated,1,16) as last_updated_s
@ -430,7 +491,11 @@
$vfeed_query_part = ""; $vfeed_query_part = "";
if ($feed >= 0) { if (sprintf("%d", $feed) == 0) {
$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) {
$query_strategy_part = "feed_id = '$feed'"; $query_strategy_part = "feed_id = '$feed'";
} else if ($feed == -1) { // starred virtual feed } else if ($feed == -1) { // starred virtual feed
$query_strategy_part = "marked = true"; $query_strategy_part = "marked = true";
@ -458,6 +523,8 @@
if ($feed < -10) error_reporting (0); if ($feed < -10) error_reporting (0);
if (sprintf("%d", $feed) != 0) {
$result = db_query($link, "SELECT $result = db_query($link, "SELECT
id,title,updated,unread,feed_id,marked,link,last_read, id,title,updated,unread,feed_id,marked,link,last_read,
SUBSTRING(last_read,1,19) as last_read_noms, SUBSTRING(last_read,1,19) as last_read_noms,
@ -471,6 +538,25 @@
$query_strategy_part ORDER BY $order_by $query_strategy_part ORDER BY $order_by
$limit_query_part"); $limit_query_part");
} else {
// browsing by tag
$result = db_query($link, "SELECT
ttrss_entries.id as id,title,updated,unread,feed_id,
marked,link,last_read,
SUBSTRING(last_read,1,19) as last_read_noms,
$vfeed_query_part
SUBSTRING(updated,1,19) as updated_noms
FROM
ttrss_entries,ttrss_tags
WHERE
post_id = ttrss_entries.id AND tag_name = '$feed' AND
$view_query_part
$search_query_part
$query_strategy_part ORDER BY $order_by
$limit_query_part");
}
if (!$result) { if (!$result) {
print "<tr><td colspan='4' align='center'> print "<tr><td colspan='4' align='center'>
Could not display feed (query failed). Please check match syntax or local configuration.</td></tr>"; Could not display feed (query failed). Please check match syntax or local configuration.</td></tr>";
@ -549,70 +635,11 @@
print "<tr><td align='center'>No articles found.</td></tr>"; print "<tr><td align='center'>No articles found.</td></tr>";
} }
/* while ($lnum < HEADLINES_PER_PAGE) {
++$lnum;
print "<tr><td>&nbsp;</td></tr>";
} */
print "</table>"; print "</table>";
if ($feed >= 0) {
$result = db_query($link, "SELECT count(id) as unread FROM ttrss_entries
WHERE feed_id = '$feed' AND $query_strategy_part
AND unread = true");
$unread = db_fetch_result($result, 0, "unread");
} else if ($feed == -1) {
$result = db_query($link, "SELECT count(id) as unread FROM ttrss_entries
WHERE $query_strategy_part");
$unread = db_fetch_result($result, 0, "unread");
} else {
// print "[viewfeed] feed type not implemented<br>";
error_reporting(0);
$result = db_query($link, "SELECT count(id) as unread FROM ttrss_entries
WHERE $query_strategy_part");
$unread = db_fetch_result($result, 0, "unread");
error_reporting (E_ERROR | E_WARNING | E_PARSE);
}
if (!$unread) $unread = 0;
// update unread/total counters and status for active feed in the feedlist
// kludge, because iframe doesn't seem to support onload()
print "<script type=\"text/javascript\"> print "<script type=\"text/javascript\">
document.onkeydown = hotkey_handler; document.onkeydown = hotkey_handler;
update_label_counters('$feed');
var p_document = parent.frames['feeds-frame'].document;
var feedr = p_document.getElementById(\"FEEDR-\" + $feed);
var feedu = p_document.getElementById(\"FEEDU-\" + $feed);
if (feedu) {
feedu.innerHTML = \"$unread\";
}
var feedctr = p_document.getElementById(\"FEEDCTR-\" + $feed);
if ($unread > 0 && $feed >= 0 && !feedr.className.match(\"Unread\")) {
feedr.className = feedr.className + \"Unread\";
feedctr.className = '';
} else if ($unread <= 0) {
feedr.className = feedr.className.replace(\"Unread\", \"\");
feedctr.className = 'invisible';
}
update_label_counters($feed);
// p_notify(\"\");
</script>"; </script>";
if ($addheader) { if ($addheader) {

View File

@ -314,6 +314,8 @@ function label_counters_callback() {
var feedu = f_document.getElementById("FEEDU-" + id); var feedu = f_document.getElementById("FEEDU-" + id);
var feedr = f_document.getElementById("FEEDR-" + id); var feedr = f_document.getElementById("FEEDR-" + id);
if (feedctr && feedu && feedr) {
feedu.innerHTML = ctr; feedu.innerHTML = ctr;
if (ctr > 0) { if (ctr > 0) {
@ -328,10 +330,11 @@ function label_counters_callback() {
} }
} }
} }
}
function update_label_counters(feed) { function update_label_counters(feed) {
if (xmlhttp_ready(xmlhttp_rpc)) { if (xmlhttp_ready(xmlhttp_rpc)) {
var query = "backend.php?op=rpc&subop=getLabelCounters"; var query = "backend.php?op=rpc&subop=getAllCounters";
if (feed > 0) { if (feed > 0) {
query = query + "&aid=" + feed; query = query + "&aid=" + feed;

View File

@ -17,11 +17,13 @@
db_query($link, "BEGIN"); db_query($link, "BEGIN");
$result = db_query($link, "SELECT feed_url,id FROM ttrss_feeds"); $result = db_query($link, "SELECT feed_url,id,last_updated FROM ttrss_feeds");
while ($line = db_fetch_assoc($result)) { while ($line = db_fetch_assoc($result)) {
if ($line["last_updated"] && time() - strtotime($line["last_updated"]) > 1800) {
update_rss_feed($link, $line["feed_url"], $line["id"]); update_rss_feed($link, $line["feed_url"], $line["id"]);
} }
}
purge_old_posts($link); purge_old_posts($link);
@ -363,7 +365,7 @@
$feed_icon = "<img src=\"images/blank_icon.gif\">"; $feed_icon = "<img src=\"images/blank_icon.gif\">";
} }
$feed = "<a href=\"javascript:viewfeed($feed_id, 0);\">$feed_title</a>"; $feed = "<a href=\"javascript:viewfeed('$feed_id', 0);\">$feed_title</a>";
print "<li id=\"FEEDR-$feed_id\" class=\"$class\">"; print "<li id=\"FEEDR-$feed_id\" class=\"$class\">";
if (ENABLE_FEED_ICONS) { if (ENABLE_FEED_ICONS) {

View File

@ -29,7 +29,7 @@ insert into ttrss_feeds (title,feed_url) values ('Technocrat.net',
'http://syndication.technocrat.net/rss'); 'http://syndication.technocrat.net/rss');
create table ttrss_entries (id integer not null primary key auto_increment, create table ttrss_entries (id integer not null primary key auto_increment,
feed_id integer not null references ttrss_feeds(id), feed_id integer not null references ttrss_feeds(id) ON DELETE CASCADE,
updated datetime not null, updated datetime not null,
title varchar(250) not null, title varchar(250) not null,
guid varchar(250) not null unique, guid varchar(250) not null unique,
@ -72,5 +72,5 @@ insert into ttrss_labels (sql_exp,description) values ('unread = true',
create table ttrss_tags (id integer primary key auto_increment, create table ttrss_tags (id integer primary key auto_increment,
tag_name varchar(250) not null, tag_name varchar(250) not null,
post_id integer references ttrss_entries(id)) TYPE=InnoDB; post_id integer references ttrss_entries(id) ON DELETE CASCADE) TYPE=InnoDB;

View File

@ -217,6 +217,20 @@ a:hover {
color : gray; color : gray;
} }
#dispSwitch {
text-align : right;
padding : 5px 5px 5px 0px;
font-size : x-small;
}
#dispSwitch a {
color : gray;
}
#dispSwitch a:hover {
color : #5050aa;
}
div.expPane { div.expPane {
margin : 15px; margin : 15px;
} }

View File

@ -10,6 +10,8 @@ var first_run = true;
var search_query = ""; var search_query = "";
var display_tags = false;
/*@cc_on @*/ /*@cc_on @*/
/*@if (@_jscript_version >= 5) /*@if (@_jscript_version >= 5)
// JScript gives us Conditional compilation, we can cope with old IE versions. // JScript gives us Conditional compilation, we can cope with old IE versions.
@ -29,6 +31,20 @@ if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
xmlhttp = new XMLHttpRequest(); xmlhttp = new XMLHttpRequest();
} }
function toggleTags() {
display_tags = !display_tags;
var p = document.getElementById("dispSwitchPrompt");
if (display_tags) {
p.innerHTML = "display feeds";
} else {
p.innerHTML = "display tags";
}
updateFeedList();
}
/* /*
function feedlist_callback() { function feedlist_callback() {
var container = document.getElementById('feeds'); var container = document.getElementById('feeds');
@ -66,6 +82,8 @@ function refetch_callback() {
var feedu = f_document.getElementById("FEEDU-" + id); var feedu = f_document.getElementById("FEEDU-" + id);
var feedr = f_document.getElementById("FEEDR-" + id); var feedr = f_document.getElementById("FEEDR-" + id);
if (feedctr && feedu && feedr) {
feedu.innerHTML = ctr; feedu.innerHTML = ctr;
if (ctr > 0) { if (ctr > 0) {
@ -80,6 +98,7 @@ function refetch_callback() {
} }
} }
} }
}
function updateFeed(feed_id) { function updateFeed(feed_id) {
@ -126,6 +145,10 @@ function updateFeedList(silent, fetch) {
var query_str = "backend.php?op=feeds"; var query_str = "backend.php?op=feeds";
if (display_tags) {
query_str = query_str + "&tags=1";
}
if (getActiveFeedId()) { if (getActiveFeedId()) {
query_str = query_str + "&actid=" + getActiveFeedId(); query_str = query_str + "&actid=" + getActiveFeedId();
} }

View File

@ -47,6 +47,10 @@
<!-- <div id="feeds">&nbsp;</div> --> <!-- <div id="feeds">&nbsp;</div> -->
<div id="dispSwitch">
<a id="dispSwitchPrompt" href="javascript:toggleTags()">display tags</a>
</div>
<iframe frameborder="0" <iframe frameborder="0"
id="feeds-frame" name="feeds-frame" class="feedsFrame"> </iframe> id="feeds-frame" name="feeds-frame" class="feedsFrame"> </iframe>