Changeset 38603

Show
Ignore:
Timestamp:
10/20/10 14:59:04 (3 years ago)
Author:
sho
Message:

supported tDiary 3.x or ruby 1.9.x.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • platform/tdiary/util/posttdiary/posttdiary-ex.rb

    r37368 r38603  
    11#!/usr/bin/env ruby 
    2 $KCODE= 'u' 
    32# 
    4 # posttdiary-ex: update tDiary via e-mail. $Revision: 1.6.2.4 $ 
     3# posttdiary-ex: update tDiary via e-mail. $Revision: 1.2 $ 
    54# 
    65# Copyright (C) 2002, All right reserved by TADA Tadashi <sho@spc.gr.jp> 
    76# You can redistribute it and/or modify it under GPL2. 
    87# 
    9 # 2007.9.22: v.1.66: Modified by K.Sakurai (http://ks.nwr.jp) 
     8# 2010.10.19: v.1.71: Modified by K.Sakurai (http://ks.nwr.jp) 
    109#  Acknowledgements: 
    11 #   * Based on posttdiary.rb v1.2 by TADA. 
     10#   * Based on posttdiary.rb & tdiary.rb by TADA. 
    1211#   * Some codes partially imported from Enikki Plugin Ex. :  
    1312#     http://shimoi.s26.xrea.com/hiki/hiki.cgi?TdiaryEnikkiEx 
     
    1615#   * Thanks to tamo (http://tamo.tdiary.net) for image-POSTing codes & testing. 
    1716# 
     17 
     18# language setup for tdiary.conf (for both @data_path & @tdiary_dirname) 
     19@tdencoding = 'UTF-8' 
     20# @tdencoding = 'US-ASCII' 
     21# @tdencoding = 'EUC-JP' 
     22# @tdencoding = 'Big5' 
    1823 
    1924#---------------------------------------------- 
     
    166171        text.gsub!( /\![^\r\n]*[\r\n]+/, '' ) 
    167172  end 
    168   text.delete( "\t" ) 
     173  text.delete( /\t/ ) 
    169174end 
    170175 
     
    183188        @data_path = add_delimiter( @data_path ) 
    184189        raise TDiaryError, 'posttdiary-ex: Do not set @data_path as same as tDiary system directory.' if @data_path == @tdiary_dirname 
    185          
     190        def_vars1 = '' 
     191        def_vars2 = '' 
    186192        variables = [:author_name, :author_mail, :index_page, :hour_offset] 
     193        variables.each do |var| 
     194                def_vars1 << "#{var} = nil\n" 
     195                def_vars2 << "@#{var} = #{var} unless #{var} == nil\n" 
     196        end 
     197 
    187198        begin 
    188199                cgi_conf = File::open( "#{@data_path}tdiary.conf" ){|f| f.read } 
    189200                cgi_conf.untaint unless @secure 
    190                 eval( cgi_conf, binding, "(cgi_conf)", 1 ) 
    191                 variables.each do |var| eval "@#{var} = #{var} if #{var} != nil" end 
    192         rescue IOError, Errno::ENOENT 
     201                cgi_conf.force_encoding( @tdencoding ) 
     202                b = binding.taint 
     203                eval( cgi_conf, b, "(cgi_conf)", 1 ) 
     204                eval( def_vars2, b ) 
     205                rescue IOError, Errno::ENOENT 
    193206        end 
    194207end 
     
    211224        @options = {} 
    212225        # evaluate tdiary.conf  (load_cgi_conf() would be called as well, via tdiary.conf) 
    213         eval( File::open( @tdiary_dirname + @tdiary_conf_file ){|f| f.read }.untaint, binding, "(tdiary.conf)", 1 ) 
     226 
     227        f = File::open( @tdiary_dirname + @tdiary_conf_file ){|f| f.read }.untaint.force_encoding(@tdencoding) 
     228        eval( f, binding, "(tdiary.conf)", 1 ) 
    214229 
    215230        Dir.chdir( orgdir ) 
     
    296311        cmdstr = @magickpath + "identify" 
    297312        check_command( cmdstr ) 
     313        return false if !FileTest::exist?( name ) 
    298314        begin 
    299315                imgsize = %x[#{cmdstr} '#{name}'].sub(/#{name}/, '').split[1][/\d+x\d+/] 
     
    323339        v = "" 
    324340        check_command( @exifpath ) 
     341        return "" if !FileTest::exist?( fullpath_imgname ) 
    325342        open( "| #{@exifpath} -t \"User Comment\" #{fullpath_imgname}", "r" ) do |f| 
    326343                s = f.readlines 
    327344                s.each do |t| 
    328345                        t.gsub!( /.*Value:/, '' ) 
    329                         v = NKF::nkf( '-m0 -wXd', t ).gsub!( /^\s+/, '' ).chomp! if $& 
     346                        v = NKF::nkf( '-m0 -Xwd', t ).gsub!( /^\s+/, '' ).chomp! if $& 
    330347                end 
    331348        end 
     
    343360        v = '' 
    344361        check_command( @exifpath ) 
     362        return 1 if !FileTest::exist?( fullpath_imgname ) 
    345363        open( "| #{@exifpath} -t \"Orientation\" #{fullpath_imgname}", "r" ) do |f| 
    346364                s = f.readlines 
     
    740758                        case opt 
    741759                        when '--read-conffile' 
    742                                 conf_df_name = arg 
     760                                conf_df_name = arg.dup 
    743761                        when '--image-path' 
    744                                 image_dir = arg 
     762                                image_dir = arg.dup 
    745763                        when '--image-url' 
    746                                 image_url = arg 
     764                                image_url = arg.dup 
    747765                        when '--use-subject' 
    748766                                use_subject = true 
    749767                        when '--make-thumbnail' 
    750                                 thumbnail_size = arg 
     768                                thumbnail_size = arg.dup 
    751769                        when '--image-geometry' 
    752                                 image_geometry = arg 
     770                                image_geometry = arg.dup 
    753771                        when '--use-image-ex' 
    754772                                use_image_ex = true 
     
    762780 
    763781                        when '--convert-path' 
    764                                 convertpath_specified = arg 
     782                                convertpath_specified = arg.dup 
    765783                        when '--exif-path' 
    766                                 exifpath_specified = arg 
     784                                exifpath_specified = arg.dup 
    767785                                read_exif = true 
    768786                        when '--remote-mode' 
    769787                                remote_mode = true 
    770788                        when '--remote-image-path' 
    771                                 remote_image_dir = add_delimiter(arg) 
     789                                remote_image_dir = add_delimiter(arg.dup) 
    772790                        when '--remote-yearly-dir' 
    773                                 remote_yearly_dir = (arg =~ /[1yt]/i) 
     791                                remote_yearly_dir = (arg.dup =~ /[1yt]/i) 
    774792                        when '--preserve-local-images' 
    775793                                preserve_local_images = true 
     
    780798                                if arg =~ /\D/ then 
    781799                                        require 'etc' 
    782                                         group_id = Etc.getgrnam( arg )['gid'] 
     800                                        group_id = Etc.getgrnam( arg.dup )['gid'] 
    783801                                else 
    784802                                        group_id = arg.to_i 
     
    788806                                add_div_imgnum_specified = arg.to_i 
    789807                        when '--threshold-size' 
    790                                 threshold_size = arg 
     808                                threshold_size = arg.dup 
    791809                        when '--image-format' 
    792                                 image_format_specified = arg 
     810                                image_format_specified = arg.dup 
    793811                        when '--use-original-name' 
    794812                                use_original_name = true 
     
    806824                        when '--write-to-file' 
    807825                                filter_mode = true 
    808                                 writeout_filename = arg 
     826                                writeout_filename = arg.dup 
    809827                        when '--date-margin' 
    810828                                date_margin = arg.to_i 
     
    882900 
    883901        if filter_mode == false then 
    884                 url = ARGV.shift 
     902                url = ARGV.shift.dup 
    885903                if %r|http://([^:/]*):?(\d*)(/.*)| =~ url then 
    886904                        host = $1 
     
    892910                        raise 'posttdiary-ex: invalid url for update.rb.' 
    893911                end 
    894                 user = ARGV.shift 
    895                 pass = ARGV.shift 
     912                user = ARGV.shift.dup 
     913                pass = ARGV.shift.dup 
    896914        end 
    897915         
     
    902920        Net::HTTP.version_1_2 
    903921 
    904         mail = NKF::nkf( '-m0 -wXd', ARGF.read ) 
     922        mail = NKF::nkf( '-m0 -Xwd', ARGF.read ) 
    905923        raise "posttdiary-ex: no mail text." if not mail or mail.length == 0 
    906924         
     
    9941012                image_name = now.strftime( "%Y%m%d" ) + "_" + nextnum.to_s + image_ext 
    9951013                nextnum += 1 
    996                 sh.move( tmpimgname , image_dir + image_name ) 
     1014                sh.rename( tmpimgname , image_dir + image_name ) 
    9971015                exif_comment[image_name] = (read_exif ? read_exif_comment(image_dir + image_name) : "" ) 
    9981016                exif_orientation[image_name] = (read_exif ? read_exif_orientation(image_dir + image_name) : "" ) 
     
    11121130                Net::HTTP.start( host, port ) do |http| 
    11131131                        protection_key = nil 
    1114                         res, = http.get( cgi, 
     1132                        res = http.get( cgi, 
    11151133                                       'Authorization' => "Basic #{auth}", 
    11161134                                       'Referer' => url ) 
     
    11281146                                end 
    11291147                        end 
    1130                         response, = http.post( cgi, data, 'Authorization' => "Basic #{auth}", 'Referer' => url ) 
     1148                        response = http.post( cgi, data, 'Authorization' => "Basic #{auth}", 'Referer' => url ) 
    11311149                end 
    11321150        end