# section_footer.rb $Revision 1.0 $ # # Copyright (c) 2005 SHIBATA Hiroshi # You can redistribute it and/or modify it under GPL2. # # modefied for BlogKit by miyaken 20080413 require 'digest/md5' require 'open-uri' require 'timeout' def permalink( date ) a = [@conf.base_url, @conf.index, anchor(date.strftime('%Y%m%d'))] a.join.sub(%r|/\./|, '/') end def categorized_title_of_day( date, title ) @category_to_tag_list = {} cats, stripped = title.scan( /^((?:\[[^\]]+\])+)\s*(.*)/ )[0] if cats then cats.scan( /\[([^\]]+)\]+/ ).flatten.each do |tag| @category_to_tag_list[tag] = true # true when blog end else stripped = title end stripped end unless @conf.mobile_agent? then add_header_proc do <<-SCRIPT SCRIPT end add_body_leave_proc do |date| category_to_tag_list(date) end def category_to_tag_list (date) r = '
' # カテゴリタグの追加 if @category_to_tag_list and not @category_to_tag_list.empty? then r << 'Tags: ' @category_to_tag_list.each do |tag, blog| r << %Q|#{tag} | end r << ' | ' end # 「このエントリを含む del.icio.us(json)」 r << add_delicious_json(date) # 「このエントリを含む del.icio.us(画像API)」 # r << add_delicious(date) # 「このエントリを含むはてなブックーク」 r << add_hatenabm(date) # 「このエントリを含む livedoor クリップ」 r << add_ldclip(date) # 「このエントリを含む Buzzurl」 r << add_buzzurl(date) # Permalinkの追加 r << add_permalink(date) r << "
\n" end def add_permalink(date) r = " | " r << %Q|Permalink | return r end def add_hatenabm(date) r = " " r << %Q|このエントリを含むはてなブックマーク | return r end def add_ldclip(date) r = " " r << %Q|このエントリを含む livedoor クリップ | return r end def add_buzzurl(date) r = " " r << %Q|このエントリを含む Buzzurl | return r end def add_delicious(date) url_md5 = Digest::MD5.hexdigest(permalink(date)) r = " " r << %Q|このエントリを含む del.icio.us | return r end def add_delicious_json(date) require 'json' url_md5 = Digest::MD5.hexdigest(permalink(date)) cache_dir = "#{@cache_path}/delicious/#{date.strftime( "%Y%m" )}/" file_name = "#{cache_dir}/#{url_md5}.json" cache_time = 8 * 60 * 60 # 8 hour update = false count = 0 r = " " r << %Q|このエントリを含む del.icio.us| begin Dir::mkdir( cache_dir ) unless File::directory?( cache_dir ) cached_time = nil cached_time = File::mtime( file_name ) if File::exist?( file_name ) unless cached_time.nil? if Time.now > cached_time + cache_time update = true end end if cached_time.nil? or update begin timeout(10) do open( 'http://badges.del.icio.us/feeds/json/url/data?hash=' + url_md5 ) do |file| File::open( file_name, 'wb' ) do |f| f.write( file.read ) end end end rescue TimeoutError rescue end end rescue end begin File::open( file_name ) do |f| data = JSON.parse(@conf.to_native( f.read, 'utf-8' )) unless data[0].nil? count = data[0]["total_posts"].to_i end end rescue return r end if count > 0 r << %Q| #{count} users| else r << %Q|| end return r end end # unless @conf.mobile_agent?