File: recent_comment.rb

package info (click to toggle)
tdiary 2.2.1%2Bdfsg1-1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 14,044 kB
  • ctags: 2,796
  • sloc: ruby: 32,562; lisp: 514; makefile: 83; sh: 72; sql: 40
file content (67 lines) | stat: -rw-r--r-- 2,248 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# recent_comment.rb $Revision: 1.11 $
#
# recent_comment: ǶΥĥåߤꥹȥåפ
#
# Copyright (c) 2002 TADA Tadashi <sho@spc.gr.jp>
# You can distribute this file under the GPL2.
#
def recent_comment_format(format, *args)
   format.gsub(/\$(\d)/) {|s| args[$1.to_i - 1]}
end

def recent_comment_init
   @conf['recent_comment.max'] ||= 3
   @conf['recent_comment.date_format'] ||= "(%m-%d)"
   @conf['recent_comment.except_list'] ||= ''
   @conf['recent_comment.format'] ||= '<a href="$2" title="$3">$4 $5</a>'
end

def recent_comment( ob_max = 'OBSOLUTE', sep = 'OBSOLUTE', ob_form = 'OBSOLUTE', ob_except = 'OBSOLUTE' )
   recent_comment_init

   max = @conf['recent_comment.max']
   form = @conf['recent_comment.date_format'] 
   except = @conf['recent_comment.except_list']
   format = @conf['recent_comment.format']

   comments = []
   date = {}
   index = {}

   @diaries.each_value do |diary|
      next unless diary.visible?
      diary.each_comment_tail( max ) do |comment, idx|
         if (except != '') && (/#{except}/ =~ comment.name) 
            next
         end
         comments << comment
         date[comment.date] = diary.date
         index[comment.date] = idx
      end
   end
   
   result = []
   
   comments.sort{|a,b| (a.date)<=>(b.date)}.reverse.each_with_index do |com,idx|
      break if idx >= max
      a = h(@index) + anchor("#{date[com.date].strftime( '%Y%m%d' )}#c#{'%02d' % index[com.date]}")
			# we can not escape anchor() to accomodate number_anchor.rb
      popup = h( com.shorten( @conf.comment_length ) )
      str = h( com.name )
      date_str = h( com.date.dup.strftime( form ) )
      result << "<li>"
      result << recent_comment_format(format, idx, a, popup, str, date_str)
      result << "</li>\n"
   end
   
   %Q|<ol class="recent-comment">\n| + result.join( '' ) + "</ol>\n"
end

if @mode == 'saveconf'
   def saveconf_recent_comment
      @conf['recent_comment.max'] = @cgi.params['recent_comment.max'][0].to_i
      @conf['recent_comment.date_format'] = @cgi.params['recent_comment.date_format'][0]
      @conf['recent_comment.except_list'] = @cgi.params['recent_comment.except_list'][0]
      @conf['recent_comment.format'] = @cgi.params['recent_comment.format'][0]
   end
end