]> git.wh0rd.org Git - tt-rss.git/commitdiff
display number of unread articles in category
authorAndrew Dolgov <fox@madoka.spb.ru>
Tue, 13 Dec 2005 09:27:41 +0000 (10:27 +0100)
committerAndrew Dolgov <fox@madoka.spb.ru>
Tue, 13 Dec 2005 09:27:41 +0000 (10:27 +0100)
backend.php
functions.js

index e8e4f992c24e9cd9055570e74e73da2c7e92b1e5..f7c4e0d4ef5fa2ad360fbcc94c3c33855bcad713 100644 (file)
                getFeedCounters($link);
                getTagCounters($link);
                getGlobalCounters($link);
+               if (get_pref($link, 'ENABLE_FEED_CATS')) {
+                       getCategoryCounters($link);
+               }
        }       
 
+       function getCategoryCounters($link) {
+               $result = db_query($link, "SELECT COUNT(int_id) AS unread,cat_id 
+                       FROM ttrss_user_entries,ttrss_feeds WHERE unread = true AND feed_id = id
+                               AND ttrss_feeds.owner_uid = ".$_SESSION["uid"]." GROUP BY cat_id");
+
+               while ($line = db_fetch_assoc($result)) {
+                       $line["cat_id"] = sprintf("%d", $line["cat_id"]);
+                       print "<counter type=\"category\" id=\"".$line["cat_id"]."\" counter=\"".
+                               $line["unread"]."\"/>";
+               }
+       }
+
        function getFeedUnread($link, $feed) {
                $n_feed = sprintf("%d", $feed);
        
                        ttrss_user_entries.ref_id = ttrss_entries.id AND 
                        owner_uid = " . $_SESSION["uid"]);
                $c_id = db_fetch_result($result, 0, "c_id");
-               print "<counter id='global-unread' counter='$c_id'/>";
+               print "<counter type=\"global\" id='global-unread' counter='$c_id'/>";
        }
 
        function getTagCounters($link, $smart_mode = SMART_RPC_COUNTERS) {
                        if (!$smart_mode || $old_counters[$tag] != $unread) {                   
                                $old_counters[$tag] = $unread;
                                $tctrs_modified = true;
-                               print "<tag id=\"$tag\" counter=\"$unread\"/>";
+                               print "<counter type=\"tag\" id=\"$tag\" counter=\"$unread\"/>";
                        }
 
                } 
 
                $count = db_fetch_result($result, 0, "count");
 
-               print "<label id=\"-1\" counter=\"$count\"/>";
+               print "<counter type=\"label\" id=\"-1\" counter=\"$count\"/>";
 
                $result = db_query($link, "SELECT owner_uid,id,sql_exp,description FROM
                        ttrss_labels WHERE owner_uid = ".$_SESSION["uid"]." ORDER by description");
                        if (!$smart_mode || $old_counters[$id] != $count) {     
                                $old_counters[$id] = $count;
                                $lctrs_modified = true;
-                               print "<label id=\"$id\" counter=\"$count\"/>";
+                               print "<counter type=\"label\" id=\"$id\" counter=\"$count\"/>";
                        }
 
                        error_reporting (DEFAULT_ERROR_LEVEL);
        
                        $count = db_fetch_result($result, 0, "count");
                        
-                       print "<feed id=\"$id\" counter=\"$count\"/>";          
+                       print "<counter type=\"feed\" id=\"$id\" counter=\"$count\"/>";         
        }
 
        function getFeedCounters($link, $smart_mode = SMART_RPC_COUNTERS) {
                        if (!$smart_mode || $old_counters[$id] != $count) {
                                $old_counters[$id] = $count;
                                $fctrs_modified = true;
-                               print "<feed id=\"$id\" counter=\"$count\"/>";
+                               print "<counter type=\"feed\" id=\"$id\" counter=\"$count\"/>";
                        }
                }
 
        
                                        error_reporting (0);
                
-                                       $tmp_result = db_query($link, "SELECT count(id) as count FROM ttrss_entries,ttrss_user_entries
+                                       $tmp_result = db_query($link, "SELECT count(id) as count 
+                                               FROM ttrss_entries,ttrss_user_entries
                                                WHERE (" . $line["sql_exp"] . ") AND unread = true AND
                                                ttrss_user_entries.ref_id = ttrss_entries.id
                                                AND owner_uid = '$owner_uid'");
                                                $tmp_category .= "...";
                                        } else {
                                                $holder_class = "";
-                                       }                                               
+                                       }
+
+                                       if ($cat_id) {
+                                               $cat_id_qpart = "cat_id = '$cat_id'";
+                                       } else {
+                                               $cat_id_qpart = "cat_id IS NULL";
+                                       }
+
+                                       $tmp_result = db_query($link, "SELECT count(int_id) AS unread
+                                               FROM ttrss_user_entries,ttrss_feeds WHERE
+                                                       unread = true AND
+                                                       feed_id = ttrss_feeds.id AND $cat_id_qpart AND
+                                                       ttrss_user_entries.owner_uid = " . $_SESSION["uid"]);
+
+                                       $cat_unread = db_fetch_result($tmp_result, 0, "unread");
+
+                                       $cat_id = sprintf("%d", $cat_id);
                                        
                                        print "<li class=\"feedCat\" id=\"FCAT-$cat_id\">
-                                               <a href=\"javascript:toggleCollapseCat($cat_id)\">$tmp_category</a></li>";
-                                       print "<li id=\"feedCatHolder\" class=\"$holder_class\"><ul class=\"feedCatList\">";
+                                               <a href=\"javascript:toggleCollapseCat($cat_id)\">$tmp_category
+                                                       <span id=\"FCATCTR-$cat_id\" 
+                                                       class=\"$catctr_class\">($cat_unread unread)</span></a></li>";
+                                       print "<li id=\"feedCatHolder\" class=\"$holder_class\">
+                                               <ul class=\"feedCatList\">";
                                }
        
                                printFeedEntry($feed_id, $class, $feed, $unread, 
 
                if ($subop == "collapse") {
                        $cat_id = db_escape_string($_GET["cid"]);
+
                        db_query($link, "UPDATE ttrss_feed_categories SET
                                collapsed = NOT collapsed WHERE id = '$cat_id' AND owner_uid = " . 
                                $_SESSION["uid"]);
index b72c1157bfa3819c0d90b9f557715d734c787adb..a77854827417337253926da46adbc990e8a0716c 100644 (file)
@@ -358,6 +358,7 @@ function all_counters_callback() {
        
                        for (var l = 0; l < reply.childNodes.length; l++) {
                                var id = reply.childNodes[l].getAttribute("id");
+                               var t = reply.childNodes[l].getAttribute("type");
                                var ctr = reply.childNodes[l].getAttribute("counter");
 
                                if (id == "global-unread") {
@@ -365,6 +366,12 @@ function all_counters_callback() {
                                        parent.updateTitle();
                                        continue;
                                }
+
+                               if (t == "category") {
+                                       var catctr = f_document.getElementById("FCATCTR-" + id);
+                                       catctr.innerHTML = "(" + ctr + " unread)";
+                                       continue;
+                               }
        
                                var feedctr = f_document.getElementById("FEEDCTR-" + id);
                                var feedu = f_document.getElementById("FEEDU-" + id);
@@ -374,7 +381,7 @@ function all_counters_callback() {
        
                                        feedu.innerHTML = ctr;
                
-                                       if (ctr > 0) {
+                                       if (ctr > 0) {                                  
                                                feedctr.className = "odd";
                                                if (!feedr.className.match("Unread")) {
                                                        var is_selected = feedr.className.match("Selected");