| 1 | # section_footer.rb $Revision 1.0 $ |
|---|
| 2 | # |
|---|
| 3 | # Copyright (c) 2005 SHIBATA Hiroshi <h-sbt@nifty.com> |
|---|
| 4 | # You can redistribute it and/or modify it under GPL2. |
|---|
| 5 | # |
|---|
| 6 | |
|---|
| 7 | require 'digest/md5' |
|---|
| 8 | require 'open-uri' |
|---|
| 9 | require 'timeout' |
|---|
| 10 | |
|---|
| 11 | def permalink( date, index, escape = true ) |
|---|
| 12 | ymd = date.strftime( "%Y%m%d" ) |
|---|
| 13 | uri = @conf.index.dup |
|---|
| 14 | uri[0, 0] = @conf.base_url unless %r|^https?://|i =~ uri |
|---|
| 15 | uri.gsub!( %r|/\./|, '/' ) |
|---|
| 16 | if escape |
|---|
| 17 | uri + CGI::escape(anchor( "#{ymd}p%02d" % index )) |
|---|
| 18 | else |
|---|
| 19 | uri + anchor( "#{ymd}p%02d" % index ) |
|---|
| 20 | end |
|---|
| 21 | end |
|---|
| 22 | |
|---|
| 23 | add_header_proc do |
|---|
| 24 | <<-SCRIPT |
|---|
| 25 | <link rel="stylesheet" href="theme/hatena_bookmark.css" type="text/css" media="all"> |
|---|
| 26 | <script type="text/javascript" src="http://b.hatena.ne.jp/js/BookmarkCommentViewerAllInOne.1.2.js" charset="utf-8"></script> |
|---|
| 27 | <script type="text/javascript"> |
|---|
| 28 | initCreateRelAfterIcon(); |
|---|
| 29 | BookmarkCommentViewer.options['dateFormat'] = '%y-%m-%d'; |
|---|
| 30 | // BookmarkCommentViewer.options['blankCommentHide'] = true; |
|---|
| 31 | BookmarkCommentViewer.options['tags'] = false; |
|---|
| 32 | </script> |
|---|
| 33 | SCRIPT |
|---|
| 34 | end |
|---|
| 35 | |
|---|
| 36 | add_section_enter_proc do |date, index| |
|---|
| 37 | @category_to_tag_list = {} |
|---|
| 38 | end |
|---|
| 39 | |
|---|
| 40 | alias subtitle_link_original subtitle_link |
|---|
| 41 | def subtitle_link( date, index, subtitle ) |
|---|
| 42 | s = '' |
|---|
| 43 | if subtitle then |
|---|
| 44 | s = subtitle.sub( /^(\[([^\[]+?)\])+/ ) do |
|---|
| 45 | $&.scan( /\[(.*?)\]/ ) do |tag| |
|---|
| 46 | @category_to_tag_list[tag] = false # false when diary |
|---|
| 47 | end |
|---|
| 48 | '' |
|---|
| 49 | end |
|---|
| 50 | end |
|---|
| 51 | subtitle_link_original( date, index, s.strip ) |
|---|
| 52 | end |
|---|
| 53 | |
|---|
| 54 | add_section_leave_proc do |date, index| |
|---|
| 55 | r = '<div class="tags">' |
|---|
| 56 | |
|---|
| 57 | unless @conf.mobile_agent? then |
|---|
| 58 | # カテゴリタグの追加 |
|---|
| 59 | if @category_to_tag_list and not @category_to_tag_list.empty? then |
|---|
| 60 | r << "Tags: " |
|---|
| 61 | @category_to_tag_list.each do |tag, blog| |
|---|
| 62 | if blog |
|---|
| 63 | r << %Q|<a href="#{@index}?blogcategory=#{h tag}">#{tag}</a> | |
|---|
| 64 | else |
|---|
| 65 | r << category_anchor( "#{tag}" ).sub( /^\[/, '' ).sub( /\]$/, '' ) << ' ' |
|---|
| 66 | end |
|---|
| 67 | end |
|---|
| 68 | end |
|---|
| 69 | |
|---|
| 70 | # 「このエントリの del.icio.us history (JSON)」 |
|---|
| 71 | r << add_delicious_json(date, index) |
|---|
| 72 | |
|---|
| 73 | # 「このエントリを含む del.icio.us (画像API)」 |
|---|
| 74 | # r << add_delicious(date, index) |
|---|
| 75 | |
|---|
| 76 | # 「このエントリを含むはてなブックーク」 |
|---|
| 77 | r << add_hatenabm(date, index) |
|---|
| 78 | |
|---|
| 79 | # 「このエントリを含む livedoor クリップ」 |
|---|
| 80 | r << add_ldclip(date, index) |
|---|
| 81 | |
|---|
| 82 | # 「このエントリを含む Buzzurl」 |
|---|
| 83 | r << add_buzzurl(date, index) |
|---|
| 84 | |
|---|
| 85 | # 「このエントリを含む Yahoo!ブックマーク」 |
|---|
| 86 | r << add_yahoobm(date, index) |
|---|
| 87 | |
|---|
| 88 | # Permalinkの追加 |
|---|
| 89 | r << add_permalink(date, index) |
|---|
| 90 | end |
|---|
| 91 | |
|---|
| 92 | r << "</div>\n" |
|---|
| 93 | end |
|---|
| 94 | |
|---|
| 95 | def add_permalink(date, index) |
|---|
| 96 | r = " | " |
|---|
| 97 | r << %Q|<a href="#{permalink(date, index, false)}">Permalink</a> | |
|---|
| 98 | return r |
|---|
| 99 | end |
|---|
| 100 | |
|---|
| 101 | def add_hatenabm(date, index) |
|---|
| 102 | r = " | " |
|---|
| 103 | r << %Q|<a href="http://b.hatena.ne.jp/entry/#{permalink(date, index)}"><img src="http://d.hatena.ne.jp/images/b_entry.gif" style="border: none;vertical-align: middle;" title="#{@section_footer_hatenabm_label}" alt="#{@section_footer_hatenabm_label}" width="16" height="12" /> <img src="http://b.hatena.ne.jp/entry/image/normal/#{permalink(date, index)}" style="border: none;vertical-align: middle;" /></a> <img src="http://r.hatena.ne.jp/images/popup.gif" style="border: none;vertical-align: middle;" onclick="iconImageClickHandler(this, '#{permalink(date, index, false)}', event);" alt="">| |
|---|
| 104 | return r |
|---|
| 105 | end |
|---|
| 106 | |
|---|
| 107 | def add_ldclip(date, index) |
|---|
| 108 | r = " | " |
|---|
| 109 | r << %Q|<a href="http://clip.livedoor.com/page/#{permalink(date, index)}"><img src="http://parts.blog.livedoor.jp/img/cmn/clip_16_16_w.gif" width="16" height="16" style="border: none;vertical-align: middle;" alt="#{@section_footer_ldclip_label}" title="#{@section_footer_ldclip_label}"> <img src="http://image.clip.livedoor.com/counter/#{permalink(date, index)}" style="border: none;vertical-align: middle;" /></a>| |
|---|
| 110 | return r |
|---|
| 111 | end |
|---|
| 112 | |
|---|
| 113 | def add_buzzurl(date, index) |
|---|
| 114 | r = " | " |
|---|
| 115 | r << %Q|<a href="http://buzzurl.jp/entry/#{permalink(date, index)}"><img src="http://buzzurl.jp/static/image/api/icon/add_icon_mini_10.gif" style="border: none;vertical-align: middle;" title="#{@section_footer_buzzurl_label}" alt="#{@section_footer_buzzurl_label}" width="16" height="12" class="icon" /> <img src="http://buzzurl.jp/api/counter/#{permalink(date, index)}" style="border: none;vertical-align: middle;" /></a>| |
|---|
| 116 | return r |
|---|
| 117 | end |
|---|
| 118 | |
|---|
| 119 | def add_delicious(date, index) |
|---|
| 120 | url_md5 = Digest::MD5.hexdigest(permalink(date, index, false)) |
|---|
| 121 | |
|---|
| 122 | r = " | " |
|---|
| 123 | r << %Q|<a href="http://delicious.com/url/#{url_md5}"><img src="http://static.delicious.com/img/delicious.small.gif" width="10" height="10" style="border: none;vertical-align: middle;" alt="#{@section_footer_delicious_label}" title="#{@section_footer_delicious_label}"> <img src="http://del.icio.us/feeds/img/savedcount/#{url_md5}?aggregate" style="border:none;margin:0" /></a>| |
|---|
| 124 | return r |
|---|
| 125 | end |
|---|
| 126 | |
|---|
| 127 | def add_delicious_json(date, index) |
|---|
| 128 | require 'json' |
|---|
| 129 | |
|---|
| 130 | url_md5 = Digest::MD5.hexdigest(permalink(date, index, false)) |
|---|
| 131 | cache_dir = "#{@cache_path}/delicious/#{date.strftime( "%Y%m" )}/" |
|---|
| 132 | file_name = "#{cache_dir}/#{url_md5}.json" |
|---|
| 133 | cache_time = 8 * 60 * 60 # 8 hour |
|---|
| 134 | update = false |
|---|
| 135 | count = 0 |
|---|
| 136 | |
|---|
| 137 | r = " | " |
|---|
| 138 | r << %Q|<a href="http://delicious.com/url/#{url_md5}"><img src="http://static.delicious.com/img/delicious.small.gif" width="10" height="10" style="border: none;vertical-align: middle;" alt="#{@section_footer_delicious_label}" title="#{@section_footer_delicious_label}">| |
|---|
| 139 | |
|---|
| 140 | begin |
|---|
| 141 | Dir::mkdir( cache_dir ) unless File::directory?( cache_dir ) |
|---|
| 142 | cached_time = nil |
|---|
| 143 | cached_time = File::mtime( file_name ) if File::exist?( file_name ) |
|---|
| 144 | |
|---|
| 145 | unless cached_time.nil? |
|---|
| 146 | if Time.now > cached_time + cache_time |
|---|
| 147 | update = true |
|---|
| 148 | end |
|---|
| 149 | end |
|---|
| 150 | |
|---|
| 151 | if cached_time.nil? or update |
|---|
| 152 | begin |
|---|
| 153 | timeout(10) do |
|---|
| 154 | open( "http://feeds.delicious.com/v2/json/urlinfo/#{url_md5}}") do |file| |
|---|
| 155 | File::open( file_name, 'wb' ) do |f| |
|---|
| 156 | f.write( file.read ) |
|---|
| 157 | end |
|---|
| 158 | end |
|---|
| 159 | end |
|---|
| 160 | rescue TimeoutError |
|---|
| 161 | rescue |
|---|
| 162 | end |
|---|
| 163 | end |
|---|
| 164 | rescue |
|---|
| 165 | end |
|---|
| 166 | |
|---|
| 167 | begin |
|---|
| 168 | File::open( file_name ) do |f| |
|---|
| 169 | data = JSON.parse(@conf.to_native( f.read, 'utf-8' )) |
|---|
| 170 | unless data[0].nil? |
|---|
| 171 | count = data[0]["total_posts"].to_i |
|---|
| 172 | end |
|---|
| 173 | end |
|---|
| 174 | rescue |
|---|
| 175 | return r |
|---|
| 176 | end |
|---|
| 177 | |
|---|
| 178 | if count > 0 |
|---|
| 179 | r << %Q| #{count} users</a>| |
|---|
| 180 | else |
|---|
| 181 | r << %Q|</a>| |
|---|
| 182 | end |
|---|
| 183 | |
|---|
| 184 | return r |
|---|
| 185 | end |
|---|
| 186 | |
|---|
| 187 | def add_yahoobm(date, index) |
|---|
| 188 | r = " | " |
|---|
| 189 | r << %Q|<a href="http://bookmarks.yahoo.co.jp/url?url=#{permalink(date, index)}&opener=bm&ei=UTF-8"><img src="http://i.yimg.jp/images/sicons/ybm16.gif" style="border: none;vertical-align: middle;" title="#{@section_footer_yahoobm_label}" alt="#{@section_footer_yahoobm_label}" width="16" height="16" class="icon" /></a>| |
|---|
| 190 | return r |
|---|
| 191 | end |
|---|