]> git.wh0rd.org Git - tt-rss.git/commitdiff
more work on tag support
authorAndrew Dolgov <fox@bah.spb.su>
Fri, 9 Sep 2005 07:45:54 +0000 (08:45 +0100)
committerAndrew Dolgov <fox@bah.spb.su>
Fri, 9 Sep 2005 07:45:54 +0000 (08:45 +0100)
NEWS
backend.php
functions.js
functions.php
schema/ttrss_schema_mysql.sql
tt-rss.css
tt-rss.js
tt-rss.php

diff --git a/NEWS b/NEWS
index 0a39a392151225fe7ae9355d57a6ae27d4fdbbe7..71cd753b0473bf81104e40006b7777b33279e5b0 100644 (file)
--- 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)
 
index 19020ac8012f33edcad9eaf7ca9fc1f0b88626e5..637647cbd2193255fbed6e695a06ac47f88e6adb 100644 (file)
        
        $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) {
 
                $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>
                        <title>Tiny Tiny RSS : Feedlist</title>
 
                print "<ul class=\"feedList\" id=\"feedList\">";
 
-               /* virtual feeds */
+               if (!$tags) {
 
-               $result = db_query($link, "SELECT count(id) as num_starred 
-                       FROM ttrss_entries WHERE marked = true AND unread = true");
-               $num_starred = db_fetch_result($result, 0, "num_starred");
+                       /* virtual feeds */
 
-               printFeedEntry(-1, "odd", "Starred articles", $num_starred, "images/mark_set.png");
+                       $result = db_query($link, "SELECT count(id) as num_starred 
+                               FROM ttrss_entries WHERE marked = true AND unread = true");
+                       $num_starred = db_fetch_result($result, 0, "num_starred");
 
-               if (ENABLE_LABELS) {
+                       printFeedEntry(-1, "odd", "Starred articles", $num_starred, 
+                               "images/mark_set.png");
 
-                       $result = db_query($link, "SELECT id,sql_exp,description FROM
-                               ttrss_labels ORDER by description");
+                       if (ENABLE_LABELS) {
+       
+                               $result = db_query($link, "SELECT id,sql_exp,description FROM
+                                       ttrss_labels ORDER by description");
+               
+                               if (db_num_rows($result) > 0) {
+                                       print "<li><hr></li>";
+                               }
+               
+                               while ($line = db_fetch_assoc($result)) {
+       
+                                       error_reporting (0);
+               
+                                       $tmp_result = db_query($link, "SELECT count(id) as count FROM ttrss_entries
+                                               WHERE (" . $line["sql_exp"] . ") AND unread = true");
+       
+                                       $count = db_fetch_result($tmp_result, 0, "count");
+       
+                                       $class = "odd";
+       
+                                       if ($count > 0) {
+                                               $class .= "Unread";
+                                       }
+                                       
+                                       error_reporting (E_ERROR | E_WARNING | E_PARSE);
        
-                       if (db_num_rows($result) > 0) {
-                               print "<li><hr></li>";
+                                       printFeedEntry(-$line["id"]-11, 
+                                               $class, $line["description"], $count, "images/label.png");
+               
+                               }
                        }
        
+                       print "<li><hr></li>";
+
+                       $result = db_query($link, "SELECT *,
+                               (SELECT count(id) FROM ttrss_entries 
+                                       WHERE feed_id = ttrss_feeds.id) AS total,
+                               (SELECT count(id) FROM ttrss_entries
+                                       WHERE feed_id = ttrss_feeds.id AND unread = true) as unread
+                               FROM ttrss_feeds ORDER BY title");                      
+       
+                       $actid = $_GET["actid"];
+       
+                       /* real feeds */
+       
+                       $lnum = 0;
+       
+                       $total_unread = 0;
+       
                        while ($line = db_fetch_assoc($result)) {
-
-                               error_reporting (0);
+                       
+                               $feed = $line["title"];
+                               $feed_id = $line["id"];   
+       
+                               $subop = $_GET["subop"];
+                               
+                               $total = $line["total"];
+                               $unread = $line["unread"];
+                               
+       //                      $class = ($lnum % 2) ? "even" : "odd";
        
-                               $tmp_result = db_query($link, "SELECT count(id) as count FROM ttrss_entries
-                                       WHERE (" . $line["sql_exp"] . ") AND unread = true");
-
-                               $count = db_fetch_result($tmp_result, 0, "count");
-
                                $class = "odd";
-
-                               if ($count > 0) {
-                                       $class .= "Unread";
+       
+                               if ($unread > 0) $class .= "Unread";
+       
+                               if ($actid == $feed_id) {
+                                       $class .= "Selected";
                                }
-                               
-                               error_reporting (E_ERROR | E_WARNING | E_PARSE);
-
-                               printFeedEntry(-$line["id"]-11, 
-                                       $class, $line["description"], $count, "images/label.png");
        
+                               $total_unread += $unread;
+       
+                               printFeedEntry($feed_id, $class, $feed, $unread, "icons/$feed_id.ico");
+       
+                               ++$lnum;
                        }
-               }
-
-               print "<li><hr></li>";
-
-               $result = db_query($link, "SELECT *,
-                       (SELECT count(id) FROM ttrss_entries 
-                               WHERE feed_id = ttrss_feeds.id) AS total,
-                       (SELECT count(id) FROM ttrss_entries
-                               WHERE feed_id = ttrss_feeds.id AND unread = true) as unread
-                       FROM ttrss_feeds ORDER BY title");                      
-
-               $actid = $_GET["actid"];
-
-               /* real feeds */
-
-               $lnum = 0;
-
-               $total_unread = 0;
-
-               while ($line = db_fetch_assoc($result)) {
-               
-                       $feed = $line["title"];
-                       $feed_id = $line["id"];   
-
-                       $subop = $_GET["subop"];
-                       
-                       $total = $line["total"];
-                       $unread = $line["unread"];
-                       
-//                     $class = ($lnum % 2) ? "even" : "odd";
-
-                       $class = "odd";
+               } else {
 
-                       if ($unread > 0) $class .= "Unread";
+                       // tags
 
-                       if ($actid == $feed_id) {
-                               $class .= "Selected";
+                       $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");
+       
+                       } 
 
-                       $total_unread += $unread;
-
-                       printFeedEntry($feed_id, $class, $feed, $unread, "icons/$feed_id.ico");
-
-                       ++$lnum;
                }
 
-               print "</table>";
+               print "</ul>";
 
                print "<div class=\"invisible\" id=\"FEEDTU\">$total_unread</div>";
 
                        print "<rpc-reply>";
                        getLabelCounters($link);
                        getFeedCounters($link);
+                       getTagCounters($link);
                        print "</rpc-reply>";
 
                }
                        print "<rpc-reply>";
                        getLabelCounters($link);
                        getFeedCounters($link);
+                       getTagCounters($link);
                        print "</rpc-reply>";
                }
                
        
        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);
 
        }
 
                        print "</div>";
 
                        print "<script type=\"text/javascript\">
-                               update_label_counters($feed_id);
+                               update_label_counters('$feed_id');
                        </script>";
                }
 
                                </head><body>";
                }
 
-               if ($feed >= 0) {
+               if (sprintf("%d", $feed) != 0 && $feed >= 0) {
 
                        $result = db_query($link, 
                                "SELECT *,SUBSTRING(last_updated,1,16) as last_updated_s
 
                $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";
 
                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 "<tr><td colspan='4' align='center'>
                if ($lnum == 0) {
                        print "<tr><td align='center'>No articles found.</td></tr>";
                }
-
-/*             while ($lnum < HEADLINES_PER_PAGE) {
-                       ++$lnum;
-                       print "<tr><td>&nbsp;</td></tr>";
-               } */
                
                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\">
                        document.onkeydown = hotkey_handler;
-
-                       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(\"\");
-
+                       update_label_counters('$feed');
                </script>";
 
                if ($addheader) {
index b6b608e71b428d758897df987706d4317f076f6b..72d35dbbd92d83ecc48226d0e26e09730fe92250 100644 (file)
@@ -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;
index f4628a812a0c2d7c2a7a2597184ab9ac31a2220c..82ff0cbd885e0b0887b0e2340d00b2843cada33b 100644 (file)
 
                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);
                        $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\">";
                if (ENABLE_FEED_ICONS) {
index 877421920134e47537488ccc10591b6a478df87e..8829332827051d74cfd47cd1eba796433428b628 100644 (file)
@@ -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;
 
index 57ad9dd4e0ec8b26076233e2a1243bae33d2434f..24eb18388e7a3e213b2273013879990cf93ba7eb 100644 (file)
@@ -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;
 }
index 31f5b29c6393d23359e86cbcfac74499df683765..422cd6aa64a1ca112ca4e6bcb1fc7973a74061b5 100644 (file)
--- 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();
        }
index 445f8ab91342140bd10b77f1f68dacedc7b4c7b2..de1bec37dea834107f5ff1899e87171f3e616004 100644 (file)
                
                <!-- <div id="feeds">&nbsp;</div> -->
 
+               <div id="dispSwitch"> 
+                       <a id="dispSwitchPrompt" href="javascript:toggleTags()">display tags</a>
+               </div>
+
                <iframe frameborder="0" 
                        id="feeds-frame" name="feeds-frame" class="feedsFrame"> </iframe>