Show
Ignore:
Timestamp:
01/02/08 19:25:47 (5 years ago)
Author:
hsbt
Message:

platform/tdiary/plugin/section_footer2.rb: bugfix, forgot to close anchor tag.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • platform/tdiary/plugin/section_footer2.rb

    r3977 r3980  
    1212 
    1313def permalink( date, index, escape = true ) 
    14    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 
     14        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 
    2323end 
    2424 
    2525add_section_enter_proc do |date, index| 
    26    @category_to_tag_list = {} 
     26        @category_to_tag_list = {} 
    2727end 
    2828 
    2929alias subtitle_link_original subtitle_link 
    3030def subtitle_link( date, index, subtitle ) 
    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 ) 
     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 ) 
    4141end 
    4242 
    4343add_section_leave_proc do |date, index| 
    44    r = '<div class="tags">' 
     44        r = '<div class="tags">' 
    4545 
    46    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 
     46        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 
    5858 
    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) 
    6161 
    6262                # SBM アイコンの追加 
     
    6666                end 
    6767 
    68       # Permalinkの追加 
    69       r << add_permalink(date, index) 
    70    end 
     68                # Permalinkの追加 
     69                r << add_permalink(date, index) 
     70        end 
    7171 
    72    r << "</div>\n" 
     72        r << "</div>\n" 
    7373end 
    7474 
    7575def add_delicious_json(date, index) 
    7676        require 'json' 
    77     
     77         
    7878        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 
    82    update = false 
    83    count = 0 
     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 
     82        update = false 
     83        count = 0 
    8484 
    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">| 
    8787 
    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 ) 
     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 ) 
    9292 
    93       unless cached_time.nil? 
    94          if Time.now > cached_time + cache_time 
    95             update = true 
    96          end 
    97       end 
     93                unless cached_time.nil? 
     94                        if Time.now > cached_time + cache_time 
     95                                update = true 
     96                        end 
     97                end 
    9898 
    99       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 
     99                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 
    114114 
    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 
    125124 
    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 
    131128 
    132    return r 
     129        r << %Q|</a>| 
     130         
     131        return r 
    133132end 
    134133 
     
    152151 
    153152def add_permalink(date, index) 
    154    r = " | " 
    155    r << %Q|<a href="#{permalink(date, index, false)}">Permalink</a> | 
    156    return r 
     153        r = " | " 
     154        r << %Q|<a href="#{permalink(date, index, false)}">Permalink</a> | 
     155        return r 
    157156end