--- entry_count.rb	2008-03-01 12:55:23.000000000 +0900
+++ entry_count.rb.new	2008-03-01 13:20:05.000000000 +0900
@@ -1,8 +1,10 @@
 #
 # Functions:
 #   * total_entry_count    : Á´¥¨¥ó¥È¥ê¿ô¤òÊÖ¤¹
+#   * total_date_count     : Á´Æü¿ô¤òÊÖ¤¹
 #   * total_category_count : Á´¥«¥Æ¥´¥ê¿ô¤òÊÖ¤¹
 #   * entry_drop           : ·îËè¤Î¥¨¥ó¥È¥ê¿ô¤òÉ½µ­¤·¤¿ dropdown¥«¥ì¥ó¥À¡¼
+#   * datecount_drop        : ·îËè¤ÎÆü¿ô¤òÉ½µ­¤·¤¿ dropdown¥«¥ì¥ó¥À¡¼
 #   * category_drop        : ¥«¥Æ¥´¥êËè¤Î¥¨¥ó¥È¥ê¿ô¤òÉ½µ­¤·¤¿ category_dropdown_list
 #
 #       Copyright (C) 2008 SHIRASAWA Hidetoshi <shira@void.jpn.org>
@@ -18,46 +20,73 @@
 
 @dropdown_calendar_label = '²áµî¤ÎÆüµ­' unless @resource_loaded
 
-# type 0:Á´¤Æ¤Î¥¨¥ó¥È¥ê¿ô¤òÊÖ¤¹¡¤1:filter¤Ë»ØÄê¤µ¤ì¤¿·î¤Î¥¨¥ó¥È¥ê¿ô¤òÊÖ¤¹¡¤2:sub title¤¬filter¤È¥Þ¥Ã¥Á¤·¤¿¥¨¥ó¥È¥ê¿ô¤òÊÖ¤¹
-def entry_counter(type = 0, filter = nil)
-  cgi = CGI::new
-  def cgi.referer; nil; end
+# ¿ô»ú¤ò¥«¥ó¥ÞÉÕ¤­Ê¸»úÎó¤Ë¤¹¤ë
+def format_count(count)
+  count.to_s.reverse.gsub(/\d\d\d/, '\0,').reverse.sub(/^([-]{0,1}),/, '\1')
+end
 
-  count = 0
-  @years.keys.sort.reverse_each do |year|
-    @years[year].sort.reverse_each do |month|
-      cgi.params['date'] = ["#{year}#{month}"]
-      m = TDiaryMonth::new(cgi, '', @conf)
-      m.diaries.keys.sort.reverse_each do |date|
-        m.diaries[date].each_section do |section|
-          if (type == 0 || (type == 1 && filter == (year.to_s + month.to_s)) || (type == 2 && section.subtitle_to_html =~ /#{filter}/))
-            count += 1;
-          end
-        end
-      end
+# »ØÄê¤µ¤ì¤¿·î¤Î¥¨¥ó¥È¥ê¿ô¤ÈÆü¿ô¤ò¥«¥¦¥ó¥È
+def get_monthly_count(cgi, year, month)
+  def cgi.referer; nil; end
+  date_count  = 0
+  entry_count = 0
+  cgi.params['date'] = ["#{year}#{month}"]
+  m = TDiaryMonth::new(cgi, '', @conf)
+  m.diaries.keys.sort.reverse_each do |date|
+    next unless m.diaries[date].visible?
+    date_count += 1;
+    m.diaries[date].each_section do |section|
+      entry_count += 1;
     end
   end
-  count.to_s.reverse.gsub(/\d\d\d/, '\0,').reverse.sub(/^([-]{0,1}),/, '\1')
+  return date_count, entry_count
 end
 
-# Á´¥¨¥ó¥È¥ê¤È·îËè¤Î¥¨¥ó¥È¥ê¿ô¤òhash¤Ë³ÊÇ¼
+# Á´¥¨¥ó¥È¥ê¿ô¤ÈÆü¿ô¡¢·îËè¤Î¥¨¥ó¥È¥ê¿ô¤ÈÆü¿ô¤òhash¤Ë³ÊÇ¼
 def monthly_counter
-  count = entry_counter
-  @entry_count_hash['ALL'] = count
+  date_count  = 0
+  entry_count = 0
+  cgi = CGI::new
+
   @years.keys.sort.reverse_each do |year|
     @years[year.to_s].sort.reverse_each do |month|
-      filter = year.to_s + month.to_s
-      count = entry_counter(1, filter)
-      @entry_count_hash[filter] = count
+      m_date_count, m_entry_count = get_monthly_count(cgi, year, month)
+      @entry_count_hash["#{year}#{month}"] = [m_date_count, m_entry_count]
+      date_count  += m_date_count
+      entry_count += m_entry_count
     end
   end
+  @entry_count_hash['ALL'] = [date_count, entry_count]
+end
+
+# ¥«¥Æ¥´¥êËè¤Î¥¨¥ó¥È¥ê¿ô¤ò¥«¥¦¥ó¥È
+def get_categry_count(cgi, filter = nil)
+  def cgi.referer; nil; end
+
+  count = 0
+  @years.keys.sort.reverse_each do |year|
+    @years[year].sort.reverse_each do |month|
+      cgi.params['date'] = ["#{year}#{month}"]
+      m = TDiaryMonth::new(cgi, '', @conf)
+      m.diaries.keys.sort.reverse_each do |date|
+        next unless m.diaries[date].visible?
+         m.diaries[date].each_section do |section|
+           if (section.subtitle_to_html =~ /#{filter}/)
+             count += 1;
+           end
+         end
+       end
+     end
+   end
+   return count
 end
 
 # ¥«¥Æ¥´¥êËè¤Î¥¨¥ó¥È¥ê¿ô¤òhash¤Ë³ÊÇ¼
 def categry_counter
+  cgi = CGI::new
   @categories.each do |c|
     filter = '\[' + c + '\]'
-    count = entry_counter(2, filter)
+    count = get_categry_count(cgi, filter)
     @entry_count_hash[c] = count
   end
 end
@@ -106,23 +135,29 @@
 
 # Á´¥¨¥ó¥È¥ê¿ô¤òÊÖ¤¹
 def total_entry_count
-  count = @entry_count_hash['ALL']
+  format_count(@entry_count_hash['ALL'][1])
+end
+
+# Æüµ­¤òÉÕ¤±¤¿Á´Æü¿ô¤òÊÖ¤¹
+def total_date_count
+  format_count(@entry_count_hash['ALL'][0])
 end
 
 # Á´¥«¥Æ¥´¥ê¿ô¤òÊÖ¤¹
 def total_category_count
-  count = @categories.size
+  format_count(@categories.size)
 end
 
-# ·îËè¤Î¥¨¥ó¥È¥ê¿ô¤òÉ½µ­¤·¤¿ dropdown¥«¥ì¥ó¥À¡¼
-def entry_drop
+# ·îËè¤Î¥¨¥ó¥È¥ê¿ô¤Þ¤¿¤ÏÆü¿ô¤òÉ½µ­¤·¤¿ dropdown¥«¥ì¥ó¥À¡¼ (type = 0, ¥¨¥ó¥È¥ê¿ô¤òÉ½¼¨/ type = 1, Æü¿ô¤òÉ½¼¨)
+def entry_drop(type = 0)
   result = %Q[<form method="get" action="#{h @index}">\n]
   result << %Q[<div class="calendar_drop">#{@options['dropdown_calendar.label'] || @dropdown_calendar_label}\n]
   result << %Q[<select name="date">\n]
   @years.keys.sort.reverse_each do |year|
     @years[year.to_s].sort.reverse_each do |month|
       filter = year.to_s + month.to_s
-      count = @entry_count_hash[filter]
+      d_count, e_count = @entry_count_hash[filter]
+      count = (type == 0 ? format_count(e_count) : format_count(d_count))
       result << %Q[<option value="#{year}#{month}">#{year}-#{month}  (#{h count})</option>\n]
     end
   end
@@ -131,6 +166,11 @@
   result << "</div>\n</form>"
 end
 
+# ·îËè¤ÎÆü¿ô¤òÉ½µ­¤·¤¿ dropdown¥«¥ì¥ó¥À¡¼
+def datecount_drop
+  entry_drop(1)
+end
+
 # ·îËè¤Î¥¨¥ó¥È¥ê¿ô¤òÉ½µ­¤·¤¿ category_dropdown_list
 def category_drop(label = nil, multiple = nil)
    label ||= 'Go'
@@ -145,7 +185,7 @@
 
    options = ''
    (['ALL'] + @categories).each do |c|
-      count = @entry_count_hash[c]
+      count = format_count(@entry_count_hash[c])
       options << %Q|\t\t<option value="#{h c}"#{" selected" if category.include?(c)}>#{h c}  (#{h count})</option>\n|
    end
 
@@ -164,6 +204,7 @@
 HTML
 end
 
+
 # when update diary, update cache
 add_update_proc do
   if /^(append|replace)$/ =~ @mode
