diff --git a/functions.php b/functions.php index 04594f9da..f3136413e 100644 --- a/functions.php +++ b/functions.php @@ -1755,6 +1755,16 @@ } function getCategoryCounters($link) { + # two special categories are -1 and -2 (all virtuals; all labels) + + $ctr = getCategoryUnread($link, -1); + + print ""; + + $ctr = getCategoryUnread($link, -2); + + print ""; + $result = db_query($link, "SELECT cat_id,SUM((SELECT COUNT(int_id) FROM ttrss_user_entries WHERE feed_id = ttrss_feeds.id AND unread = true)) AS unread FROM ttrss_feeds @@ -1770,38 +1780,54 @@ function getCategoryUnread($link, $cat) { - if ($cat != 0) { - $cat_query = "cat_id = '$cat'"; - } else { - $cat_query = "cat_id IS NULL"; - } - - $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE $cat_query - AND hidden = false - AND owner_uid = " . $_SESSION["uid"]); - - $cat_feeds = array(); - while ($line = db_fetch_assoc($result)) { - array_push($cat_feeds, "feed_id = " . $line["id"]); - } - - if (count($cat_feeds) == 0) return 0; + if ($cat >= 0) { - $match_part = implode(" OR ", $cat_feeds); + if ($cat != 0) { + $cat_query = "cat_id = '$cat'"; + } else { + $cat_query = "cat_id IS NULL"; + } + + $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE $cat_query + AND hidden = false + AND owner_uid = " . $_SESSION["uid"]); + + $cat_feeds = array(); + while ($line = db_fetch_assoc($result)) { + array_push($cat_feeds, "feed_id = " . $line["id"]); + } + + if (count($cat_feeds) == 0) return 0; + + $match_part = implode(" OR ", $cat_feeds); + + $result = db_query($link, "SELECT COUNT(int_id) AS unread + FROM ttrss_user_entries + WHERE unread = true AND ($match_part) AND owner_uid = " . $_SESSION["uid"]); + + $unread = 0; + + # this needs to be rewritten + while ($line = db_fetch_assoc($result)) { + $unread += $line["unread"]; + } + + return $unread; + } else if ($cat == -1) { + return getFeedUnread($link, -1) + getFeedUnread($link, -2); + } else if ($cat == -2) { - $result = db_query($link, "SELECT COUNT(int_id) AS unread - FROM ttrss_user_entries - WHERE unread = true AND ($match_part) AND owner_uid = " . $_SESSION["uid"]); + $rv = getLabelCounters($link, false, true); + $ctr = 0; - $unread = 0; + foreach (array_keys($rv) as $k) { + if ($k < -10) { + $ctr += $rv[$k]["counter"]; + } + } - # this needs to be rewritten - while ($line = db_fetch_assoc($result)) { - $unread += $line["unread"]; + return $ctr; } - - return $unread; - } function getFeedUnread($link, $feed, $is_cat = false) { @@ -1991,7 +2017,7 @@ print ""; } else { $ret_arr["-1"]["counter"] = $count; - $ret_arr["-1"]["description"] = "Starred"; + $ret_arr["-1"]["description"] = __("Starred articles"); } $result = db_query($link, "SELECT count(ttrss_entries.id) as count FROM ttrss_entries,ttrss_user_entries,ttrss_feeds @@ -2005,7 +2031,7 @@ print ""; } else { $ret_arr["-2"]["counter"] = $count; - $ret_arr["-2"]["description"] = "Published"; + $ret_arr["-2"]["description"] = __("Published articles"); } @@ -2788,13 +2814,20 @@ function getCategoryTitle($link, $cat_id) { - $result = db_query($link, "SELECT title FROM ttrss_feed_categories WHERE - id = '$cat_id'"); - - if (db_num_rows($result) == 1) { - return db_fetch_result($result, 0, "title"); + if ($cat_id == -1) { + return __("Special"); + } else if ($cat_id == -2) { + return __("Labels"); } else { - return "Uncategorized"; + + $result = db_query($link, "SELECT title FROM ttrss_feed_categories WHERE + id = '$cat_id'"); + + if (db_num_rows($result) == 1) { + return db_fetch_result($result, 0, "title"); + } else { + return "Uncategorized"; + } } } @@ -3240,6 +3273,44 @@ } + function printCategoryHeader($link, $cat_id, $hidden = false, $can_browse = true) { + + $tmp_category = getCategoryTitle($link, $cat_id); + $cat_unread = getCategoryUnread($link, $cat_id); + + if ($hidden) { + $holder_style = "display:none;"; + $ellipsis = "..."; + } else { + $holder_style = ""; + $ellipsis = ""; + } + + $catctr_class = ($cat_unread > 0) ? "catCtrHasUnread" : "catCtrNoUnread"; + + print "
  • + $tmp_category"; + + if ($can_browse) { + print ""; + } else { + print ""; + } + + print " ($cat_unread) $ellipsis"; + + if ($can_browse) { + print ""; + } else { + print ""; + } + + print "
  • "; + + print "
    • "; + } + function outputFeedList($link, $tags = false) { print "
        "; @@ -3251,22 +3322,25 @@ if (get_pref($link, 'ENABLE_FEED_CATS')) { if ($_COOKIE["ttrss_vf_vclps"] == 1) { - $holder_style = "display:none;"; - $ellipsis = "..."; + $cat_hidden = true; } else { - $holder_style = ""; - $ellipsis = ""; + $cat_hidden = false; } # print "
      • ".__('Special')."
      • "; # print "
        • "; - print "
        • ". - "". - __('Special')." $ellipsis
        • "; +# print "
        • ". +# "". +# __('Special')." $ellipsis
        • "; +# +# print "
        • +#
            "; - print "
          • -
              "; +# $cat_unread = getCategoryUnread($link, -1); +# $tmp_category = __("Special"); +# $catctr_class = ($cat_unread > 0) ? "catCtrHasUnread" : "catCtrNoUnread"; + printCategoryHeader($link, -1, $cat_hidden, false); } $num_starred = getFeedUnread($link, -1); @@ -3301,18 +3375,18 @@ if (get_pref($link, 'ENABLE_FEED_CATS')) { if ($_COOKIE["ttrss_vf_lclps"] == 1) { - $holder_style = "display:none;"; - $ellipsis = "..."; + $cat_hidden = true; } else { - $holder_style = ""; - $ellipsis = ""; + $cat_hidden = false; } - print "
            • ". - "". - __('Labels')." $ellipsis
            • "; + printCategoryHeader($link, -2, $cat_hidden, false); - print "
              • "; +# print "
              • ". +# "". +# __('Labels')." $ellipsis
              • "; +# +# print "
                • "; } else { print "

                • "; } @@ -3496,8 +3570,6 @@ class=\"$catctr_class\">($cat_unread) $ellipsis "; - // !!! NO SPACE before keyboard navigation, etc. print "
                  • "; }