1
# section_footer2.rb $Revision 1.0 $
3
# Copyright (c) 2008 SHIBATA Hiroshi <h-sbt@nifty.com>
4
# You can redistribute it and/or modify it under GPL2.
13
def permalink( date, index, escape = true )
14
ymd = date.strftime( "%Y%m%d" )
16
uri[0, 0] = @conf.base_url unless %r|^https?://|i =~ uri
17
uri.gsub!( %r|/\./|, '/' )
19
uri + CGI::escape(anchor( "#{ymd}p%02d" % index ))
21
uri + anchor( "#{ymd}p%02d" % index )
25
add_section_enter_proc do |date, index|
26
@category_to_tag_list = {}
29
alias subtitle_link_original subtitle_link
30
def subtitle_link( date, index, subtitle )
33
s = subtitle.sub( /^(\[([^\[]+?)\])+/ ) do
34
$&.scan( /\[(.*?)\]/ ) do |tag|
35
@category_to_tag_list[tag] = false # false when diary
40
subtitle_link_original( date, index, s.strip )
43
add_section_leave_proc do |date, index|
44
r = '<div class="tags">'
46
unless @conf.mobile_agent? then
48
if @category_to_tag_list and not @category_to_tag_list.empty? then
50
@category_to_tag_list.each do |tag, blog|
52
r << %Q|<a href="#{@index}?blogcategory=#{h tag}">#{tag}</a> |
54
r << category_anchor( "#{tag}" ).sub( /^\[/, '' ).sub( /\]$/, '' ) << ' '
59
# �֤��Υ���ȥ��ޤ� del.icio.us(json API)��
60
r << add_delicious_json(date, index)
63
yaml_dir = "#{@cache_path}/yaml/"
64
Dir.glob( yaml_dir + "*.yaml" ) do |file|
65
r << parse_sbm_yaml(file, date, index)
69
r << add_permalink(date, index)
75
def add_delicious_json(date, index)
78
url_md5 = Digest::MD5.hexdigest(permalink(date, index, false))
79
cache_dir = "#{@cache_path}/delicious/#{date.strftime( "%Y%m" )}/"
80
file_name = "#{cache_dir}/#{url_md5}.json"
81
cache_time = 8 * 60 * 60 # 8 hour
86
r << %Q|<a href="http://del.icio.us/url/#{url_md5}"><img src="http://images.del.icio.us/static/img/delicious.small.gif" width="10" height="10" style="border: none;vertical-align: middle;" alt="���Υ���ȥ��ޤ� del.icio.us" title="���Υ���ȥ��ޤ� del.icio.us">|
89
Dir::mkdir( cache_dir ) unless File::directory?( cache_dir )
91
cached_time = File::mtime( file_name ) if File::exist?( file_name )
93
unless cached_time.nil?
94
if Time.now > cached_time + cache_time
99
if cached_time.nil? or update
102
open( 'http://badges.del.icio.us/feeds/json/url/data?hash=' + url_md5 ) do |file|
103
File::open( file_name, 'wb' ) do |f|
116
File::open( file_name ) do |f|
117
data = JSON.parse(@conf.to_native( f.read, 'utf-8' ))
119
count = data[0]["total_posts"].to_i
126
r << %Q| #{count} users|
134
def parse_sbm_yaml(file, date, index)
135
config = YAML.load(Pathname.new(file).expand_path.read)
138
unless config.nil? then
139
r << %Q|<a href="#{config["url"]}#{permalink(date, index)}")>|
140
r << %Q|<img src="#{config["src"]}" style="border: none;vertical-align: middle;" |
141
r << %Q|title="#{config["title"]}" |
142
r << %Q|alt="#{config["title"]}" />|
143
unless config["counter"].nil? then
144
r << %Q| <img src="#{config["counter"]}#{permalink(date, index)}" style="border: none;vertical-align: middle;" />|
152
def add_permalink(date, index)
154
r << %Q|<a href="#{permalink(date, index, false)}">Permalink</a> |