Changeset 3980 for platform/tdiary/plugin/section_footer2.rb
- Timestamp:
- 01/02/08 19:25:47 (5 years ago)
- Files:
-
- 1 modified
-
platform/tdiary/plugin/section_footer2.rb (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
platform/tdiary/plugin/section_footer2.rb
r3977 r3980 12 12 13 13 def permalink( date, index, escape = true ) 14 ymd = date.strftime( "%Y%m%d" )15 uri = @conf.index.dup16 uri[0, 0] = @conf.base_url unless %r|^https?://|i =~ uri17 uri.gsub!( %r|/\./|, '/' )18 if escape then19 uri + CGI::escape(anchor( "#{ymd}p%02d" % index ))20 else21 uri + anchor( "#{ymd}p%02d" % index )22 end14 ymd = date.strftime( "%Y%m%d" ) 15 uri = @conf.index.dup 16 uri[0, 0] = @conf.base_url unless %r|^https?://|i =~ uri 17 uri.gsub!( %r|/\./|, '/' ) 18 if escape then 19 uri + CGI::escape(anchor( "#{ymd}p%02d" % index )) 20 else 21 uri + anchor( "#{ymd}p%02d" % index ) 22 end 23 23 end 24 24 25 25 add_section_enter_proc do |date, index| 26 @category_to_tag_list = {}26 @category_to_tag_list = {} 27 27 end 28 28 29 29 alias subtitle_link_original subtitle_link 30 30 def subtitle_link( date, index, subtitle ) 31 s = ''32 if subtitle then33 s = subtitle.sub( /^(\[([^\[]+?)\])+/ ) do34 $&.scan( /\[(.*?)\]/ ) do |tag|35 @category_to_tag_list[tag] = false # false when diary36 end37 ''38 end39 end40 subtitle_link_original( date, index, s.strip )31 s = '' 32 if subtitle then 33 s = subtitle.sub( /^(\[([^\[]+?)\])+/ ) do 34 $&.scan( /\[(.*?)\]/ ) do |tag| 35 @category_to_tag_list[tag] = false # false when diary 36 end 37 '' 38 end 39 end 40 subtitle_link_original( date, index, s.strip ) 41 41 end 42 42 43 43 add_section_leave_proc do |date, index| 44 r = '<div class="tags">'44 r = '<div class="tags">' 45 45 46 unless @conf.mobile_agent? then47 # カテゴリタグの追加48 if @category_to_tag_list and not @category_to_tag_list.empty? then49 r << "Tags: "50 @category_to_tag_list.each do |tag, blog|51 if blog52 r << %Q|<a href="#{@index}?blogcategory=#{h tag}">#{tag}</a> |53 else54 r << category_anchor( "#{tag}" ).sub( /^\[/, '' ).sub( /\]$/, '' ) << ' '55 end56 end57 end46 unless @conf.mobile_agent? then 47 # カテゴリタグの追加 48 if @category_to_tag_list and not @category_to_tag_list.empty? then 49 r << "Tags: " 50 @category_to_tag_list.each do |tag, blog| 51 if blog 52 r << %Q|<a href="#{@index}?blogcategory=#{h tag}">#{tag}</a> | 53 else 54 r << category_anchor( "#{tag}" ).sub( /^\[/, '' ).sub( /\]$/, '' ) << ' ' 55 end 56 end 57 end 58 58 59 # 「このエントリを含む del.icio.us(json API)」60 r << add_delicious_json(date, index)59 # 「このエントリを含む del.icio.us(json API)」 60 r << add_delicious_json(date, index) 61 61 62 62 # SBM アイコンの追加 … … 66 66 end 67 67 68 # Permalinkの追加69 r << add_permalink(date, index)70 end68 # Permalinkの追加 69 r << add_permalink(date, index) 70 end 71 71 72 r << "</div>\n"72 r << "</div>\n" 73 73 end 74 74 75 75 def add_delicious_json(date, index) 76 76 require 'json' 77 77 78 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 hour82 update = false83 count = 079 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 82 update = false 83 count = 0 84 84 85 r = " | "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">|85 r = " | " 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">| 87 87 88 begin89 Dir::mkdir( cache_dir ) unless File::directory?( cache_dir )90 cached_time = nil91 cached_time = File::mtime( file_name ) if File::exist?( file_name )88 begin 89 Dir::mkdir( cache_dir ) unless File::directory?( cache_dir ) 90 cached_time = nil 91 cached_time = File::mtime( file_name ) if File::exist?( file_name ) 92 92 93 unless cached_time.nil?94 if Time.now > cached_time + cache_time95 update = true96 end97 end93 unless cached_time.nil? 94 if Time.now > cached_time + cache_time 95 update = true 96 end 97 end 98 98 99 if cached_time.nil? or update100 begin101 timeout(10) do102 open( 'http://badges.del.icio.us/feeds/json/url/data?hash=' + url_md5 ) do |file|103 File::open( file_name, 'wb' ) do |f|104 f.write( file.read )105 end106 end107 end108 rescue TimeoutError109 rescue110 end111 end112 rescue113 end99 if cached_time.nil? or update 100 begin 101 timeout(10) do 102 open( 'http://badges.del.icio.us/feeds/json/url/data?hash=' + url_md5 ) do |file| 103 File::open( file_name, 'wb' ) do |f| 104 f.write( file.read ) 105 end 106 end 107 end 108 rescue TimeoutError 109 rescue 110 end 111 end 112 rescue 113 end 114 114 115 begin 116 File::open( file_name ) do |f| 117 data = JSON.parse(@conf.to_native( f.read, 'utf-8' )) 118 unless data[0].nil? 119 count = data[0]["total_posts"].to_i 120 end 121 end 122 rescue 123 return r 124 end 115 begin 116 File::open( file_name ) do |f| 117 data = JSON.parse(@conf.to_native( f.read, 'utf-8' )) 118 unless data[0].nil? 119 count = data[0]["total_posts"].to_i 120 end 121 end 122 rescue 123 end 125 124 126 if count > 0 127 r << %Q| #{count} users</a>| 128 else 129 r << %Q|</a>| 130 end 125 if count > 0 126 r << %Q| #{count} users| 127 end 131 128 132 return r 129 r << %Q|</a>| 130 131 return r 133 132 end 134 133 … … 152 151 153 152 def add_permalink(date, index) 154 r = " | "155 r << %Q|<a href="#{permalink(date, index, false)}">Permalink</a> |156 return r153 r = " | " 154 r << %Q|<a href="#{permalink(date, index, false)}">Permalink</a> | 155 return r 157 156 end
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)