tdiary-blogkit 5.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,91 @@
1
+ # recent_entry.rb $Revision: 1.13 $
2
+ #
3
+ # recent_entry: modified 'title_list' for Blogkit.
4
+ # parameter(default):
5
+ # max: maximum list items (5)
6
+ # limit: max lengh of each items (20)
7
+ #
8
+ # Copyright (c) 2002 TADA Tadashi <sho@spc.gr.jp>
9
+ # Copyright (c) 2001,2002 Junichiro KITA <kita@kitaj.no-ip.com>
10
+ # You can redistribute it and/or modify it under GPL2.
11
+ #
12
+
13
+ def recent_entry( max = 5, limit = 20 )
14
+ result = "<ul>\n"
15
+ if @conf.secure then
16
+ result << recent_entry_secure( max, limit )
17
+ else
18
+ result << recent_entry_insecure( max, limit )
19
+ end
20
+ result << "</ul>\n"
21
+ apply_plugin( result )
22
+ end
23
+
24
+
25
+ #---- private ----#
26
+ def recent_entry_secure( max = 5, limit = 20 )
27
+ max = max.to_i
28
+ limit = limit.to_i
29
+
30
+ result = ''
31
+ @diaries.keys.sort.reverse.each_with_index do |date, idx|
32
+ break if idx >= max
33
+ diary = @diaries[date]
34
+ next unless diary.visible?
35
+ title = if diary.respond_to?( :stripped_title ) then
36
+ diary.stripped_title.gsub( /<[^>]*>/, '' )
37
+ else
38
+ diary.title.gsub( /<[^>]*>/, '' )
39
+ end
40
+ title = 'no title' if title.empty?
41
+ result << %Q[<li><a href="#{h @index}#{anchor date}">#{@conf.shorten( title, limit )}</a></li>\n]
42
+ end
43
+ result
44
+ end
45
+
46
+ eval( <<MODIFY_CLASS, TOPLEVEL_BINDING )
47
+ module TDiary
48
+ class TDiaryMonth
49
+ attr_reader :diaries
50
+ end
51
+ end
52
+ MODIFY_CLASS
53
+
54
+ def recent_entry_insecure( max = 5, limit = 20 )
55
+ max = max.to_i
56
+ limit = limit.to_i
57
+
58
+ cgi = CGI::new
59
+ def cgi.referer; nil; end
60
+
61
+ result = ''
62
+ catch( :exit ) {
63
+ @years.keys.sort.reverse_each do |year|
64
+ @years[year].sort.reverse_each do |month|
65
+ cgi.params['date'] = ["#{year}#{month}"]
66
+ m = TDiaryMonth::new( cgi, '', @conf )
67
+ m.diaries.keys.sort.reverse_each do |date|
68
+ next unless m.diaries[date].visible?
69
+ title = if m.diaries[date].respond_to?( :stripped_title ) then
70
+ title = m.diaries[date].stripped_title.gsub( /<[^>]*>/, '' )
71
+ else
72
+ title = m.diaries[date].title.gsub( /<[^>]*>/, '' )
73
+ end
74
+ title = 'no title' if title.empty?
75
+ result << %Q|<li><a href="#{h @index}#{anchor date}">#{@conf.shorten( title, limit )}</a></li>\n|
76
+ max -= 1
77
+ throw :exit if max == 0
78
+ end
79
+ end
80
+ end
81
+ }
82
+ result
83
+ end
84
+
85
+
86
+ # Local Variables:
87
+ # mode: ruby
88
+ # indent-tabs-mode: t
89
+ # tab-width: 3
90
+ # ruby-indent-level: 3
91
+ # End:
@@ -0,0 +1,39 @@
1
+ #
2
+ # title-link.rb: make permalink include all of title. $Revision: 1.3 $
3
+ #
4
+ # Copyright (C) 2005 TADA Tadashi <sho@spc.gr.jp>
5
+ # You can redistribute it and/or modify it under GPL2.
6
+ #
7
+ def title_of_day( date, title )
8
+ if respond_to?( :blog_category ) then
9
+ cats, stripped = title.scan( /^((?:\[[^\]]+\])+)\s*(.*)/ )[0]
10
+ unless cats then
11
+ cats = ''
12
+ stripped = title
13
+ else
14
+ cats << ' '
15
+ end
16
+ else
17
+ cats = ''
18
+ stripped = title
19
+ end
20
+ r = <<-HTML
21
+ <span class="title">
22
+ #{cats}
23
+ HTML
24
+ if @mode == 'day' then
25
+ r << stripped
26
+ else
27
+ r << %Q[<a href="#{h @index}#{anchor( date.strftime( '%Y%m%d' ) )}">#{stripped}</a>]
28
+ end
29
+ r << "</span>"
30
+ return r.gsub( /^\t+/, '' ).chomp
31
+ end
32
+
33
+
34
+ # Local Variables:
35
+ # mode: ruby
36
+ # indent-tabs-mode: t
37
+ # tab-width: 3
38
+ # ruby-indent-level: 3
39
+ # End:
@@ -0,0 +1,76 @@
1
+ # title-navi.rb: navigation label with title of the article. $Revision: 1.10 $
2
+ #
3
+ # This plugin run only copy to plugin directory.
4
+ # You can customize in tdiary.conf:
5
+ # @options['title_navi.max']: max length of navigation buttons (default: 30 )
6
+ #
7
+ # Copyright (c) 2002 TADA Tadashi <sho@spc.gr.jp>
8
+ # Distributed under the GPL
9
+ #
10
+
11
+ if /^(day|edit)$/ =~ @mode then
12
+ eval( <<-MODIFY_CLASS, TOPLEVEL_BINDING )
13
+ module TDiary
14
+ class TDiaryMonth
15
+ attr_reader :diaries
16
+ end
17
+ end
18
+ MODIFY_CLASS
19
+
20
+ month = @date.strftime( '%Y%m' )
21
+ years = @years.collect{|y,ms| ms.collect{|m| "#{y}#{m}"}}.flatten.sort
22
+ cgi = CGI::new
23
+ def cgi.referer; nil; end
24
+
25
+ # search pre
26
+ pre = 0
27
+ (@date.day - 1).downto( 1 ) do |day|
28
+ diary = @diaries[month + ('%02d' % day)]
29
+ pre = day if diary and ((@mode == 'edit') or diary.visible?)
30
+ end
31
+ if pre == 0 and (years.index( month ) || 1) - 1 >= 0 then
32
+ cgi.params['date'] = [years[(years.index( month ) || 0) - 1]]
33
+ m = TDiaryMonth::new( cgi, '', @conf )
34
+ @diaries.update( m.diaries )
35
+ end
36
+
37
+ # search nex
38
+ nex = 0
39
+ (@date.day + 1).upto( 31 ) do |day|
40
+ diary = @diaries[month + ('%02d' % day)]
41
+ nex = day if diary and ((@mode == 'edit') or diary.visible?)
42
+ end
43
+ if nex == 0 and (years.index( month ) || years.size-1) + 1 < years.size then
44
+ cgi.params['date'] = [years[(years.index( month ) || years.size) + 1]]
45
+ m = TDiaryMonth::new( cgi, '', @conf )
46
+ @diaries.update( m.diaries )
47
+ end
48
+ end
49
+
50
+ def navi_prev_diary( date )
51
+ diary = @diaries[date.strftime( '%Y%m%d' )]
52
+ if diary and diary.title.length > 0 then
53
+ len = @options['title_navi.max'] || 30
54
+ @conf.shorten( apply_plugin( TDiary::Style::BaseDiary.method_defined?(:stripped_title) ? diary.stripped_title : diary.title, true ), len.to_i )
55
+ else
56
+ "Prev(#{date.strftime '%Y%m%d'})"
57
+ end
58
+ end
59
+
60
+ def navi_next_diary( date )
61
+ diary = @diaries[date.strftime( '%Y%m%d' )]
62
+ if diary and diary.title.length > 0 then
63
+ len = @options['title_navi.max'] || 30
64
+ @conf.shorten( apply_plugin( TDiary::Style::BaseDiary.method_defined?(:stripped_title) ? diary.stripped_title : diary.title, true ), len.to_i )
65
+ else
66
+ "Next(#{date.strftime '%Y%m%d'})"
67
+ end
68
+ end
69
+
70
+
71
+ # Local Variables:
72
+ # mode: ruby
73
+ # indent-tabs-mode: t
74
+ # tab-width: 3
75
+ # ruby-indent-level: 3
76
+ # End:
@@ -0,0 +1,261 @@
1
+ # whatsnew-list.rb: what's new list plugin $Revision: 1.53 $
2
+ #
3
+ # whatsnew_list: show what's new list
4
+ # parameter (default):
5
+ # max: max of list items (5)
6
+ # limit: max length of each items (20)
7
+ #
8
+ # options in tdiary.conf (default):
9
+ # @options['apply_plugin']:
10
+ # if this is true, apply plugin to result. (false)
11
+ # @options['whatsnew_list.rdf']
12
+ # RDF file path. (nil). If this options is existent (usually
13
+ # 'index.rdf'), this plugin will generate RDF file.
14
+ # @options['whatsnew_list.url']
15
+ # RDF's URL. (nil). If this options is existent (usually
16
+ # 'index.rdf'), this plugin will generate RDF file.
17
+ # @options['whatsnew_list.rdf.description']
18
+ # description of the site in RDF. (@html_title)
19
+ #
20
+ # notice:
21
+ # This plugin dose NOT run on secure mode.
22
+ # This plugin keep only recent 15 items.
23
+ #
24
+ # Copyright (c) 2002 by TADA Tadashi <sho@spc.gr.jp>
25
+ # Distributed under the GPL
26
+ #
27
+ require 'pstore'
28
+
29
+ def whatsnew_list( max = 5, limit = 20 )
30
+ return 'DO NOT USE IN SECURE MODE' if @conf.secure
31
+
32
+ max = max.to_i
33
+ limit = limit.to_i
34
+
35
+ wl = "#{@cache_path}/whatsnew-list"
36
+ begin
37
+ if @mode == 'latest' then
38
+ diary = @diaries[@diaries.keys.sort[0]]
39
+ diary.last_modified = File::mtime( wl ) if diary
40
+ end
41
+ rescue
42
+ end
43
+
44
+ r = "<ul>\n"
45
+ PStore::new( wl ).transaction do |db|
46
+ begin
47
+ wn = db['whatsnew']
48
+ wn.each_with_index do |item,i|
49
+ break if i >= max
50
+ title = @conf.shorten( apply_plugin( item[1] ).gsub( /^(\[.*?\])+\s*/, '' ).gsub( /<.*?>/, '' ), limit )
51
+ r << %Q|<li><a href="#{h @index}#{anchor item[0]}">#{title}</a></li>\n|
52
+ end
53
+ db.abort
54
+ rescue
55
+ end
56
+ end
57
+ r << "</ul>\n"
58
+ end
59
+
60
+ #
61
+ # preferences
62
+ #
63
+ add_conf_proc( 'whatsnew_list', "What's New List", 'update' ) do
64
+ if @mode == 'saveconf' then
65
+ if @cgi.params['whatsnew_list.rdf.out'][0] == 'true' then
66
+ rdf = whatsnew_list_rdf_file
67
+ begin
68
+ open( rdf, 'w+' ) {|f|}
69
+ @conf['whatsnew_list.rdf.out'] = true
70
+ rescue Errno::EACCES
71
+ @conf['whatsnew_list.rdf.out'] = false
72
+ error_message = %Q|<p class="message">#{rdf}#{@whatsnew_list_msg_access}</p>|
73
+
74
+ end
75
+ else
76
+ @conf['whatsnew_list.rdf.out'] = false
77
+ end
78
+ end
79
+
80
+ if @conf['whatsnew_list.rdf.out'] == nil then
81
+ @conf['whatsnew_list.rdf.out'] = @conf['whatsnew_list.rdf'] ? true : false
82
+ end
83
+
84
+ result = ''
85
+ result << <<-HTML
86
+ #{error_message}
87
+ <h3>#{@whatsnew_list_label_rdf_out}</h3>
88
+ <p>#{@whatsnew_list_label_rdf_out_notice}</p>
89
+ <p><select name="whatsnew_list.rdf.out">
90
+ <option value="true"#{" selected" if @conf['whatsnew_list.rdf.out']}>#{@whatsnew_list_label_rdf_out_yes}</option>
91
+ <option value="false"#{" selected" unless @conf['whatsnew_list.rdf.out']}>#{@whatsnew_list_label_rdf_out_no}</option>
92
+ </select></p>
93
+ HTML
94
+ result
95
+ end
96
+
97
+ #
98
+ # private methods
99
+ #
100
+ def whatsnew_list_rdf_file
101
+ @conf['whatsnew_list.rdf'] || 'index.rdf'
102
+ end
103
+
104
+ def whatsnew_list_rdf( items )
105
+ path = @conf.index.dup
106
+ path[0, 0] = @conf.base_url if %r|^https?://|i !~ @conf.index
107
+ path.gsub!( %r|/\./|, '/' )
108
+
109
+ desc = @conf.description || @conf.html_title
110
+
111
+ xml = %Q[<?xml version="1.0" encoding="UTF-8"?>
112
+ <rdf:RDF xmlns="http://purl.org/rss/1.0/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:xhtml="http://www.w3.org/1999/xhtml" xml:lang="#{h @conf.html_lang}">
113
+ <channel rdf:about="#{h @conf.base_url}#{h File::basename( whatsnew_list_rdf_file )}">
114
+ <title>#{h @conf.html_title}</title>
115
+ <link>#{h path}</link>
116
+ <xhtml:link xhtml:rel="alternate" xhtml:media="handheld" xhtml:type="text/html" xhtml:href="#{h path}" />
117
+ <description>#{h desc}</description>
118
+ <dc:creator>#{h @conf.author_name}</dc:creator>
119
+ ]
120
+
121
+ if /^http/ =~ @conf.banner
122
+ rdf_image = @conf.banner
123
+ elsif @conf.banner and !@conf.banner.empty?
124
+ rdf_image = @conf.base_url + @conf.banner
125
+ else
126
+ rdf_image = nil
127
+ end
128
+ xml << %Q[<image rdf:resource="#{h rdf_image}" />\n] if rdf_image
129
+
130
+ xml << %Q[<items><rdf:Seq>\n]
131
+ items.each do |uri, title, modify, description|
132
+ xml << %Q!<rdf:li rdf:resource="#{h path}#{anchor uri}"/>\n!
133
+ end
134
+ xml << %Q[</rdf:Seq></items>\n]
135
+ xml << %Q[</channel>\n]
136
+
137
+ if rdf_image then
138
+ xml << %Q[<image rdf:about="#{h rdf_image}">\n]
139
+ xml << %Q[<title>#{h @conf.html_title}</title>\n]
140
+ xml << %Q[<url>#{h rdf_image}</url>\n]
141
+ xml << %Q[<link>#{h path}</link>\n]
142
+ xml << %Q[</image>\n]
143
+ end
144
+
145
+ items.each do |uri, title, modify, description|
146
+ if /^\d{8}$/ =~ modify then
147
+ mod = modify.sub( /(\d{4})(\d\d)(\d\d)/, '\1-\2-\3T00:00:00+00:00' )
148
+ else
149
+ mod = modify
150
+ end
151
+ cats, stripped = title.scan( /^((?:\[[^\]]+\])+)\s*(.*)/ )[0]
152
+ if cats then
153
+ cats = cats.scan( /\[([^\]]+)\]+/ ).flatten.collect {|tag|
154
+ "<dc:subject>#{h tag}</dc:subject>"
155
+ }.join( "\n" )
156
+ else
157
+ stripped = h( title.gsub( /<.*?>/, '' ) )
158
+ end
159
+ stripped
160
+ xml << %Q[<item rdf:about="#{h path}#{anchor uri}">
161
+ <title>#{stripped}</title>
162
+ <link>#{h path}#{anchor uri}</link>
163
+ <xhtml:link xhtml:rel="alternate" xhtml:media="handheld" xhtml:type="text/html" xhtml:href="#{h path}#{anchor uri}" />
164
+ <dc:creator>#{h @conf.author_name}</dc:creator>
165
+ <dc:date>#{mod}</dc:date>
166
+ #{cats}
167
+ <content:encoded><![CDATA[#{apply_plugin( description ).gsub( /\]\]>/, ']]]]><![CDATA[>' )}]]></content:encoded>
168
+ </item>
169
+ ]
170
+ end
171
+
172
+ xml << "</rdf:RDF>\n"
173
+ to_utf8( xml.gsub( /\t/, '' ) )
174
+ end
175
+
176
+ def feed?
177
+ @whatsnew_list_in_feed
178
+ end
179
+
180
+ def whatsnew_list_update
181
+ return if @mode == 'comment' and !@comment.visible?
182
+
183
+ now = Time::now
184
+ g = now.dup.gmtime
185
+ l = Time::local( g.year, g.month, g.day, g.hour, g.min, g.sec )
186
+ tz = (g.to_i - l.to_i)
187
+ zone = sprintf( "%+03d:%02d", tz / 3600, tz % 3600 / 60 )
188
+ diary = @diaries[@date.strftime('%Y%m%d')]
189
+
190
+ @whatsnew_list_in_feed = true
191
+
192
+ title = diary.title
193
+ desc = diary.to_html( { 'anchor' => true } )
194
+ trackback = 0
195
+ if Comment::instance_methods.include?( 'visible_true?' ) then
196
+ diary.each_visible_trackback {|t,i| trackback += 1}
197
+ end
198
+ comment = diary.count_comments - trackback
199
+ desc << "<p>"
200
+ desc << "Comments(#{comment})" if comment > 0
201
+ desc << "&nbps;TrackBacks(#{trackback})" if trackback > 0
202
+ desc << "</p>\n"
203
+ old_apply_plugin = @conf['apply_plugin']
204
+ @conf['apply_plugin'] = true
205
+ title = apply_plugin( title )
206
+ desc = body_enter_proc( @date ) + apply_plugin( desc ) + body_leave_proc( @date )
207
+ @conf['apply_plugin'] = old_apply_plugin
208
+
209
+ @whatsnew_list_in_feed = false
210
+
211
+ new_item = [diary.date.strftime('%Y%m%d'), title, Time::now.strftime("%Y-%m-%dT%H:%M:%S#{zone}"), desc]
212
+ PStore::new( "#{@cache_path}/whatsnew-list" ).transaction do |db|
213
+ wn = []
214
+ begin
215
+ (db['whatsnew'] || []).each_with_index do |item, i|
216
+ wn << item unless item[0] == new_item[0]
217
+ break if i > 15
218
+ end
219
+ rescue PStore::Error
220
+ end
221
+ wn.unshift new_item if diary.visible?
222
+ db['whatsnew'] = wn
223
+
224
+ rdf = whatsnew_list_rdf_file
225
+ if @conf['whatsnew_list.rdf.out'] then
226
+ open( rdf, 'w' ) do |f|
227
+ f.write( whatsnew_list_rdf( wn ) )
228
+ end
229
+ end
230
+ end
231
+ end
232
+
233
+ add_update_proc do
234
+ whatsnew_list_update unless @cgi.params['whatsnew_list_update'][0] == 'false'
235
+ end
236
+
237
+ add_header_proc do
238
+ if @conf['whatsnew_list.rdf.out'] then
239
+ url = @conf['whatsnew_list.url'] || "#{h @conf.base_url}#{h File::basename( whatsnew_list_rdf_file )}"
240
+ %Q|\t<link rel="alternate" type="application/rss+xml" title="RSS" href="#{h url}">\n|
241
+ else
242
+ ''
243
+ end
244
+ end
245
+
246
+ add_edit_proc do
247
+ checked = @cgi.params['whatsnew_list_update'][0] == 'false' ? ' checked' : ''
248
+ r = <<-HTML
249
+ <div class="whatsnew-list"><label for="whatsnew_list_update">
250
+ <input type="checkbox" id="whatsnew_list_update" name="whatsnew_list_update" value="false"#{checked} tabindex="520" />
251
+ #{@whatsnew_list_edit_label}
252
+ </label></div>
253
+ HTML
254
+ end
255
+
256
+ # Local Variables:
257
+ # mode: ruby
258
+ # indent-tabs-mode: t
259
+ # tab-width: 3
260
+ # ruby-indent-level: 3
261
+ # End: