From 8143ae1f2b61c6ad7255b090b47447d3680e22bf Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Fri, 9 Sep 2005 08:45:54 +0100 Subject: more work on tag support --- NEWS | 1 + backend.php | 307 +++++++++++++++++++++++------------------- functions.js | 27 ++-- functions.php | 8 +- schema/ttrss_schema_mysql.sql | 4 +- tt-rss.css | 14 ++ tt-rss.js | 39 ++++-- tt-rss.php | 4 + 8 files changed, 239 insertions(+), 165 deletions(-) diff --git a/NEWS b/NEWS index 0a39a3921..71cd753b0 100644 --- a/NEWS +++ b/NEWS @@ -2,6 +2,7 @@ v1.0.4 (Sep xx, 2005) - "Starred items" virtual feed - Experimental support for Gmail-like labels + - Basic support for Technorati-style tags v1.0.3.1 (Sep 07, 2005) diff --git a/backend.php b/backend.php index 19020ac80..637647cbd 100644 --- a/backend.php +++ b/backend.php @@ -18,6 +18,29 @@ $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 ""; + } + } + function getLabelCounters($link) { $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 " Tiny Tiny RSS : Feedlist @@ -87,91 +110,125 @@ print ""; print "
$total_unread
"; @@ -202,6 +259,7 @@ print ""; getLabelCounters($link); getFeedCounters($link); + getTagCounters($link); print ""; } @@ -242,6 +300,7 @@ print ""; getLabelCounters($link); getFeedCounters($link); + getTagCounters($link); print ""; } @@ -262,13 +321,15 @@ if ($op == "feeds") { + $tags = $_GET["tags"]; + $subop = $_GET["subop"]; if ($subop == "catchupAll") { db_query($link, "UPDATE ttrss_entries SET last_read = NOW(),unread = false"); } - outputFeedList($link); + outputFeedList($link, $tags); } @@ -331,7 +392,7 @@ print ""; print ""; } @@ -368,7 +429,7 @@ "; } - if ($feed >= 0) { + if (sprintf("%d", $feed) != 0 && $feed >= 0) { $result = db_query($link, "SELECT *,SUBSTRING(last_updated,1,16) as last_updated_s @@ -430,7 +491,11 @@ $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'"; } else if ($feed == -1) { // starred virtual feed $query_strategy_part = "marked = true"; @@ -458,18 +523,39 @@ if ($feed < -10) error_reporting (0); - $result = db_query($link, "SELECT - id,title,updated,unread,feed_id,marked,link,last_read, + if (sprintf("%d", $feed) != 0) { + + $result = db_query($link, "SELECT + 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 + WHERE + $search_query_part + $view_query_part + $query_strategy_part ORDER BY $order_by + $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 - WHERE - $search_query_part - $view_query_part - $query_strategy_part ORDER BY $order_by - $limit_query_part"); + 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) { print " @@ -548,71 +634,12 @@ if ($lnum == 0) { print "No articles found."; } - -/* while ($lnum < HEADLINES_PER_PAGE) { - ++$lnum; - print " "; - } */ print ""; - - 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
"; - - 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 ""; if ($addheader) { diff --git a/functions.js b/functions.js index b6b608e71..72d35dbbd 100644 --- a/functions.js +++ b/functions.js @@ -314,24 +314,27 @@ function label_counters_callback() { var feedu = f_document.getElementById("FEEDU-" + id); var feedr = f_document.getElementById("FEEDR-" + id); - feedu.innerHTML = ctr; - - if (ctr > 0) { - feedctr.className = "odd"; - if (!feedr.className.match("Unread")) { - feedr.className = feedr.className + "Unread"; - } - } else { - feedctr.className = "invisible"; - feedr.className = feedr.className.replace("Unread", ""); - } + if (feedctr && feedu && feedr) { + + feedu.innerHTML = ctr; + + if (ctr > 0) { + feedctr.className = "odd"; + if (!feedr.className.match("Unread")) { + feedr.className = feedr.className + "Unread"; + } + } else { + feedctr.className = "invisible"; + feedr.className = feedr.className.replace("Unread", ""); + } + } } } } function update_label_counters(feed) { if (xmlhttp_ready(xmlhttp_rpc)) { - var query = "backend.php?op=rpc&subop=getLabelCounters"; + var query = "backend.php?op=rpc&subop=getAllCounters"; if (feed > 0) { query = query + "&aid=" + feed; diff --git a/functions.php b/functions.php index f4628a812..82ff0cbd8 100644 --- a/functions.php +++ b/functions.php @@ -17,10 +17,12 @@ 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)) { - update_rss_feed($link, $line["feed_url"], $line["id"]); + if ($line["last_updated"] && time() - strtotime($line["last_updated"]) > 1800) { + update_rss_feed($link, $line["feed_url"], $line["id"]); + } } purge_old_posts($link); @@ -363,7 +365,7 @@ $feed_icon = ""; } - $feed = "$feed_title"; + $feed = "$feed_title"; print "
  • "; if (ENABLE_FEED_ICONS) { diff --git a/schema/ttrss_schema_mysql.sql b/schema/ttrss_schema_mysql.sql index 877421920..882933282 100644 --- a/schema/ttrss_schema_mysql.sql +++ b/schema/ttrss_schema_mysql.sql @@ -29,7 +29,7 @@ insert into ttrss_feeds (title,feed_url) values ('Technocrat.net', 'http://syndication.technocrat.net/rss'); 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, title varchar(250) not null, 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, 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; diff --git a/tt-rss.css b/tt-rss.css index 57ad9dd4e..24eb18388 100644 --- a/tt-rss.css +++ b/tt-rss.css @@ -217,6 +217,20 @@ a:hover { 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 { margin : 15px; } diff --git a/tt-rss.js b/tt-rss.js index 31f5b29c6..422cd6aa6 100644 --- a/tt-rss.js +++ b/tt-rss.js @@ -10,6 +10,8 @@ var first_run = true; var search_query = ""; +var display_tags = false; + /*@cc_on @*/ /*@if (@_jscript_version >= 5) // JScript gives us Conditional compilation, we can cope with old IE versions. @@ -29,6 +31,20 @@ if (!xmlhttp && typeof XMLHttpRequest!='undefined') { 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() { var container = document.getElementById('feeds'); @@ -66,16 +82,19 @@ function refetch_callback() { var feedu = f_document.getElementById("FEEDU-" + id); var feedr = f_document.getElementById("FEEDR-" + id); - feedu.innerHTML = ctr; + if (feedctr && feedu && feedr) { - if (ctr > 0) { - feedctr.className = "odd"; - if (!feedr.className.match("Unread")) { - feedr.className = feedr.className + "Unread"; + feedu.innerHTML = ctr; + + if (ctr > 0) { + feedctr.className = "odd"; + if (!feedr.className.match("Unread")) { + feedr.className = feedr.className + "Unread"; + } + } else { + feedctr.className = "invisible"; + feedr.className = feedr.className.replace("Unread", ""); } - } else { - feedctr.className = "invisible"; - feedr.className = feedr.className.replace("Unread", ""); } } } @@ -126,6 +145,10 @@ function updateFeedList(silent, fetch) { var query_str = "backend.php?op=feeds"; + if (display_tags) { + query_str = query_str + "&tags=1"; + } + if (getActiveFeedId()) { query_str = query_str + "&actid=" + getActiveFeedId(); } diff --git a/tt-rss.php b/tt-rss.php index 445f8ab91..de1bec37d 100644 --- a/tt-rss.php +++ b/tt-rss.php @@ -47,6 +47,10 @@ + + -- cgit v1.2.3