tdiary-blogkit 5.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,75 @@
1
+ # -*- coding: utf-8; -*-
2
+ # Copyright (c) 2003 URABE, Shyouhei <root@mput.dip.jp>
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this code, to deal in the code without restriction,
6
+ # including without limitation the rights to use, copy, modify, merge,
7
+ # publish, distribute, sublicense, and/or sell copies of the code, and
8
+ # to permit persons to whom the code is furnished to do so, subject to
9
+ # the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be
12
+ # included in all copies or substantial portions of the code.
13
+ #
14
+ # THE CODE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17
+ # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18
+ # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE CODE
20
+ # OR THE USE OR OTHER DEALINGS IN THE CODE.
21
+
22
+ begin
23
+ require 'tdiary/style/rd'
24
+ rescue LoadError
25
+ require 'tdiary/rd_style'
26
+ end
27
+
28
+ module RD
29
+ class RD2BlogVisitor < RD2tDiaryVisitor
30
+ def apply_to_Headline( element, title )
31
+ r = "<h%1$1d>%2$s</h%1$1d>" % [ element.level + RD::TDIARY_BASE_LEVEL, title ]
32
+ if element.level == 3 && @td_opt['multi_user'] && @td_author then
33
+ r << "[" << @td_author << "]"
34
+ end
35
+ r
36
+ end
37
+ end
38
+ end
39
+
40
+ module TDiary
41
+ module Style
42
+ class BlogrdDiary < RdDiary
43
+ include RD
44
+
45
+ def style
46
+ 'BlogRD'
47
+ end
48
+
49
+ def to_html( opt, mode=:HTML )
50
+ v = RD2BlogVisitor.new( date, 0, opt, @author )
51
+ r = ''
52
+ @sections.each_with_index do | section, i |
53
+ if i == 0 or opt['anchor'] then
54
+ t = RDTree.new( ("=begin\n%s\n=end" % section.to_src).to_a, nil, nil )
55
+ t.parse
56
+ r << %Q[<div class="section">%s</div>] % v.visit( t )
57
+ else
58
+ r << %Q[<p class="readmore"><a href="%s<%%=anchor "%s"%%>">Read more ...</a></p>\n] % [opt['index'], date.strftime('%Y%m%d')]
59
+ break;
60
+ end
61
+ end
62
+ r
63
+ end
64
+ end
65
+ end
66
+ end
67
+
68
+ # Local Variables:
69
+ # mode: ruby
70
+ # code: utf-8
71
+ # indent-tabs-mode: t
72
+ # tab-width: 3
73
+ # ruby-indent-level: 3
74
+ # End:
75
+ # vi: ts=3 sw=3
@@ -0,0 +1,80 @@
1
+ # -*- coding: utf-8; -*-
2
+ #
3
+ # blogwiki_style.rb: WikiWiki style for tDiary Blogkit. $Revision: 1.7 $
4
+ #
5
+ # if you want to use this style,
6
+ #
7
+ # 1. copy wiki_style.rb and wiki_parser.rb in tDiary's misc/style/wiki
8
+ # to tDiary's tdiary directory.
9
+ #
10
+ # 2. copy this blogwiki_style.rb to tDiaty's tdiary directory.
11
+ #
12
+ # 3. specify @style in tdiary.conf below:
13
+ #
14
+ # @style = 'BlogWiki'
15
+ #
16
+ # Copyright (C) 2003, TADA Tadashi <sho@spc.gr.jp>
17
+ # You can distribute this under GPL.
18
+ #
19
+ require 'tdiary/style/wiki'
20
+
21
+ module TDiary
22
+ module Style
23
+ class BlogwikiSection < WikiSection
24
+ end
25
+
26
+ class BlogwikiDiary < WikiDiary
27
+ def style
28
+ 'BlogWiki'
29
+ end
30
+
31
+ def append( body, author = nil )
32
+ section = nil
33
+ body.each_line do |l|
34
+ case l
35
+ when /^\![^!]/
36
+ @sections << BlogwikiSection::new( section, author ) if section
37
+ section = l
38
+ else
39
+ section = '' unless section
40
+ section << l
41
+ end
42
+ end
43
+ @sections << BlogwikiSection::new( section, author ) if section
44
+ @last_modified = Time::now
45
+ self
46
+ end
47
+
48
+ def to_html4( opt )
49
+ r = ''
50
+ idx = 1
51
+ each_section do |section|
52
+ if idx > 1 and not opt['anchor'] then
53
+ r << %Q|<p class="readmore"><a href="#{opt['index']}<%=anchor "#{date.strftime( '%Y%m%d' )}"%>">Read more...</a></p>\n|
54
+ break
55
+ end
56
+ r << section.html4( date, idx, opt )
57
+ idx += 1
58
+ end
59
+ r
60
+ end
61
+
62
+ def to_chtml( opt )
63
+ r = ''
64
+ idx = 1
65
+ each_section do |section|
66
+ r << section.chtml( date, idx, opt )
67
+ idx += 1
68
+ end
69
+ r
70
+ end
71
+ end
72
+ end
73
+ end
74
+
75
+ # Local Variables:
76
+ # mode: ruby
77
+ # indent-tabs-mode: t
78
+ # tab-width: 3
79
+ # ruby-indent-level: 3
80
+ # End:
data/plugin/archive.rb ADDED
@@ -0,0 +1,70 @@
1
+ # archive.rb $Revision: 1.10 $
2
+ #
3
+ # archive: show list of past news archive
4
+ # parameter: none.
5
+ #
6
+ # archive_dropdown: show list of past news archive in dropdown.
7
+ # parameter(default):
8
+ # label: label of submit button ('Go')
9
+ #
10
+ # Copyright (c) 2002 TADA Tadashi <sho@spc.gr.jp>
11
+ # Distributed under the GPL
12
+ #
13
+
14
+ def archive_make_list
15
+ list = []
16
+ @years.keys.sort.reverse_each do |year|
17
+ @years[year.to_s].sort.reverse_each do |month|
18
+ list << "#{year}#{month}"
19
+ end
20
+ end
21
+ list
22
+ end
23
+
24
+ def archive
25
+ result = %Q[<ul>\n]
26
+ list = archive_make_list
27
+ count = list.length
28
+ list.each do |month|
29
+ result << %Q[<li><a href="#{h @index}#{anchor "#{month}"}">#{'%05d' % count}</a></li>\n]
30
+ count -= 1
31
+ end
32
+ result << %Q[</ul>\n]
33
+ end
34
+
35
+ def archive_dropdown( label = 'Go' )
36
+ result = %Q[<form method="get" action="#{h @index}"><div>\n]
37
+ result << %Q[<select name="date">\n]
38
+ list = archive_make_list
39
+ count = list.length
40
+ list.each do |month|
41
+ result << %Q[<option value="#{month}">#{'%05d' % count}</option>\n]
42
+ count -= 1
43
+ end
44
+ result << %Q[</select>\n<input type="submit" value="#{h label}">\n]
45
+ result << %Q[</div></form>\n]
46
+ end
47
+
48
+ def archive_make_index
49
+ list = archive_make_list.sort.push( nil ).unshift( nil )
50
+ this = @date.strftime( "%Y%m" )
51
+ @archive_index = list.index( this )
52
+ end
53
+
54
+ def navi_prev_month
55
+ archive_make_index unless @archive_index
56
+ '%05d' % (@archive_index - 1)
57
+ end
58
+
59
+ def navi_next_month
60
+ archive_make_index unless @archive_index
61
+ '%05d' % (@archive_index + 1)
62
+ end
63
+
64
+
65
+ # Local Variables:
66
+ # mode: ruby
67
+ # indent-tabs-mode: t
68
+ # tab-width: 3
69
+ # ruby-indent-level: 3
70
+ # End:
@@ -0,0 +1,247 @@
1
+ # blog-category.rb $Revision: 1.14 $
2
+ #
3
+ # Usage:
4
+ #
5
+ # Select blog-category.rb in 'Preferece' -> 'sp'.
6
+ # You should initialize the category index file in 'Prefernce' -> 'Categorize blogkit'.
7
+ # You can read the detailed documentation in the same page.
8
+ #
9
+ # Copyright (c) 2003 Junichiro KITA <kita@kitaj.no-ip.com>
10
+ # Distributed under the GPL
11
+ #
12
+
13
+ require 'pstore'
14
+
15
+ def blog_category
16
+ cat = @cgi.params['blogcategory'][0]
17
+ if cat and !cat.empty?
18
+ cat
19
+ else
20
+ nil
21
+ end
22
+ end
23
+
24
+ # NOTICE: very illegal usage
25
+ @title_procs.insert( 0, Proc::new {|d, t| categorized_title_of_day( d, t ) } )
26
+
27
+ def categorized_title_of_day( date, title )
28
+ r = ''
29
+ cats, stripped = title.scan( /^((?:\[[^\]]+\])+)\s*(.*)/ )[0]
30
+ if cats then
31
+ cats.scan( /\[([^\]]+)\]+/ ).flatten.each do |c|
32
+ r << %Q|[<a href="#{h @index}?blogcategory=#{h c}">#{c}</a>]|
33
+ end
34
+ else
35
+ stripped = title
36
+ end
37
+ r + ' ' + stripped
38
+ end
39
+
40
+ if /^(latest|month|day|append|replace|comment|showcomment|saveconf|trackbackreceive|pingbackreceive)$/ =~ @mode
41
+ eval(<<-'MODIFY_CLASS', TOPLEVEL_BINDING)
42
+ module TDiary
43
+ module Style
44
+ module BaseDiary
45
+ def stripped_title
46
+ return '' unless @title
47
+ stripped = @title.sub(/^(\[(.*?)\])+\s*/,'')
48
+ end
49
+
50
+ def categories
51
+ return [] unless @title
52
+ cat = /^(\[([^\[]+?)\])+/.match(@title).to_a[0]
53
+ return [] unless cat
54
+ cat.scan(/\[(.*?)\]/).collect do |c|
55
+ c[0].split(/,/)
56
+ end.flatten
57
+ end
58
+ end
59
+ end
60
+
61
+ class TDiaryMonth
62
+ attr_reader :diaries
63
+ end
64
+ end
65
+ MODIFY_CLASS
66
+ end
67
+
68
+ if category_param = blog_category and @mode == 'latest'
69
+ eval(<<-'MODIFY_CLASS', TOPLEVEL_BINDING)
70
+ module TDiary
71
+ module Cache
72
+ def cache_enable?( prefix )
73
+ false
74
+ end
75
+
76
+ def store_cache( cache, prefix )
77
+ end
78
+ end
79
+ end
80
+ MODIFY_CLASS
81
+
82
+ years = @years.collect{|y,ms| ms.collect{|m| "#{y}#{m}"}}.flatten.sort.reverse
83
+ @diaries.keys.each {|date| years.delete(date[0, 6])}
84
+
85
+ @diaries.delete_if do |date, diary|
86
+ !diary.categories.include?(category_param)
87
+ end
88
+
89
+ cgi = CGI.new
90
+ def cgi.referer; nil; end
91
+ years.each do |ym|
92
+ break if @diaries.keys.size >= @conf.latest_limit
93
+ cgi.params['date'] = [ym]
94
+ m = TDiaryMonth.new(cgi, '', @conf)
95
+ m.diaries.delete_if do |date, diary|
96
+ !diary.categories.include?(category_param)
97
+ end
98
+ @diaries.update(m.diaries)
99
+ end
100
+ end
101
+
102
+ alias :navi_user_blog_category :navi_user
103
+ def navi_user
104
+ r = navi_user_blog_category
105
+ r << %Q[<span class="adminmenu"><a href="#{h @index}">#{navi_latest}</a></span>\n] if @mode == 'latest' and blog_category
106
+ r
107
+ end
108
+
109
+ def blog_category_cache
110
+ "#{@cache_path}/blog_category"
111
+ end
112
+
113
+ def blog_category_cache_add(diary)
114
+ PStore.new(blog_category_cache).transaction do |db|
115
+ db['blog_category'] = Hash.new unless db.root?('blog_category')
116
+ diary.categories.each do |c|
117
+ db['blog_category'][c] = Hash.new unless db['blog_category'][c]
118
+ db['blog_category'][c][diary.date.strftime('%Y%m%d')] = diary.stripped_title
119
+ end
120
+ end
121
+ end
122
+
123
+ def blog_category_cache_restore
124
+ return nil unless File.exist?(blog_category_cache)
125
+ cache = {}
126
+ PStore.new(blog_category_cache).transaction do |db|
127
+ cache.update(db['blog_category'])
128
+ db.abort
129
+ end
130
+ cache
131
+ end
132
+
133
+ def blog_category_entry(limit = 20)
134
+ return 'DO NOT USE IN SECURE MODE' if @conf.secure
135
+
136
+ cache = blog_category_cache_restore
137
+ return '' if (blog_category.nil? or cache.nil?)
138
+ n_shown = @diaries.keys.size
139
+ n_shown = @conf.latest_limit if n_shown > @conf.latest_limit
140
+ dates = cache[blog_category].keys.sort.reverse[n_shown..-1]
141
+ return '' if dates.empty?
142
+
143
+ r = "<ul>\n"
144
+ dates.each do |date|
145
+ r << %Q| <li><a href="#{h @index}#{anchor date}">#{@conf.shorten(cache[blog_category][date], limit)}</a></li>\n|
146
+ end
147
+ r << "</ul>\n"
148
+ end
149
+
150
+ def blog_category_form
151
+ cache = blog_category_cache_restore
152
+ return '' if cache.nil?
153
+
154
+ r = <<HTML
155
+ <form method="get" action="#{h @index}">
156
+ <div>
157
+ <select name="blogcategory">
158
+ <option value="">select...</option>
159
+ HTML
160
+ cache.keys.sort.each do |cat|
161
+ r << %Q| <option value="#{h cat}"#{" selected" if cat == blog_category}>#{cat}</option>\n|
162
+ end
163
+ r << <<HTML
164
+ </select>
165
+ <input type="submit" value="show">
166
+ </div>
167
+ </form>
168
+ HTML
169
+ end
170
+
171
+ add_update_proc do
172
+ if @mode != 'comment'
173
+ diary = @diaries[@date.strftime('%Y%m%d')]
174
+ blog_category_cache_add(diary)
175
+ end
176
+ end
177
+
178
+ def blog_category_cache_initialize
179
+ cgi = CGI::new
180
+ def cgi.referer; nil; end
181
+
182
+ PStore.new(blog_category_cache).transaction do |db|
183
+ db['blog_category'] = Hash.new
184
+ @years.each do |y, ms|
185
+ ms.each do |m|
186
+ cgi.params['date'] = ["#{y}#{m}"]
187
+ m = TDiaryMonth.new(cgi, '', @conf)
188
+ m.diaries.each do |k, diary|
189
+ diary.categories.each do |c|
190
+ db['blog_category'][c] = Hash.new unless db['blog_category'][c]
191
+ db['blog_category'][c][diary.date.strftime('%Y%m%d')] = diary.stripped_title
192
+ end
193
+ end
194
+ end
195
+ end
196
+ end
197
+ end
198
+
199
+ add_conf_proc( 'blog_category', @blog_category_conf_label, 'basic' ) do
200
+ if @mode == 'saveconf' and @cgi.valid?('blog_category_initialize')
201
+ blog_category_cache_initialize
202
+ end
203
+
204
+ r = ''
205
+ r << @blog_category_desc_label
206
+ r
207
+ end
208
+
209
+ def blog_category_edit
210
+ cache = blog_category_cache_restore
211
+ return '' if cache.nil?
212
+
213
+ ret = ''
214
+ unless cache.keys.size == 0 then
215
+ ret << %Q[
216
+ <script type="text/javascript">
217
+ <!--
218
+ function inj_c(val){
219
+ target = window.document.forms[0].title
220
+ target.focus();
221
+ target.value += val
222
+ }
223
+ //-->
224
+ </script>
225
+ ]
226
+
227
+ ret << '<div class="field title">'
228
+ ret << "#{@blog_category_conf_label}:\n"
229
+
230
+ cache.keys.sort.each do |cat|
231
+ ret << %Q!| <a href="javascript:inj_c(&quot;[#{h cat}]&quot;)">#{h cat}</a>\n!
232
+ end
233
+ ret << "|\n</div>\n<br>\n"
234
+ end
235
+ end
236
+
237
+ add_edit_proc do
238
+ blog_category_edit
239
+ end
240
+
241
+ # Local Variables:
242
+ # mode: ruby
243
+ # indent-tabs-mode: t
244
+ # tab-width: 3
245
+ # ruby-indent-level: 3
246
+ # End:
247
+ # vim: ts=3