Zphotover='$Id: zphoto.rb,v 1.3 2004-04-04 03:26:49+09 waka Exp waka $'.split(" ")[2] # http://www.double-red.net/ =begin nDiary filter zphoto(http://www.namazu.org/~satoru/zphoto/) を呼び出す 準備 (0)何はなくとも zphoto (0.6 以降)が動作する環境を整える (1)LOG_DIRECTORY 以下に zphoto というディレクトリ作成 (2)LOG_DIRECTORY 以下に zphoto/templates というディレクトリ作成し、 (zphoto 添付のものをそのまま利用できる) zphoto 用テンプレートファイル(.photo.html , index.html , noflash.html)を用意する (3)OUTPUT_DIRECTORY 以下に zphoto というディレクトリ作成 (4)(1)で作成したディレクトリに日付ディレクトリ(yyyymmdd の形式)作成 例 20031130 (5)(4)で作成したディレクトリに zphoto 化する画像ファイル(jpg)を置く(1つでも複数でも可) こんな感じ LOG_DIRECTORY/zphoto /zphoto/templates /zphoto/20040402 . . . OUTPUT_DIRECTORY/zphoto 準備終了。 使いかた 準備(4)の日付ディレクトリと同じ日の日記内に (zphoto) タイトルをつけたい(デフォルトは日付)場合、スペースをはさんで、 (zphoto 写真集タイトル) と記述するとその個所に準備(5)で用意した画像の zphoto.swf が埋め込まれる。 ついでにアルバム html へのリンクも張られる。 テンプレートの html ファイル内に以下を記述しておくと ・ZPtitle ・ZPbaseurl ・ZPhtmlfile ・ZPclose それぞれ ・写真集 ・写真集のベース URL ・html ファイル名 ・「Window を閉じる」ボタン に書き替えるので、html の統一感を出したい場合にご利用ください。 =end def zp_swf_html_src(swf,zp_link) src=<<-EndOfSrc
EndOfSrc return src end class Filter def zphoto(str, type) zp_swf = "zphoto.swf" zp_diary_date = @diary.date zp = 'zphoto' + File::Separator + zp_diary_date zp_tmp_dir = @diary.logDirectory + '/zphoto/templates' zp_img_dir = @diary.logDirectory + zp zp_out_dir = @diary.outputDirectory + zp case type when :AFTER_ONEDAY str.gsub!(/\(zphoto(?:\ (.+?))?\)/){ str = "" title = $1 title = zp_diary_date if title.to_s.empty? status = 0 unless FileTest.exist?(zp_out_dir + '/' + zp_swf) then Dir.open(zp_img_dir).each{|i| if /jpg/ =~ i then unless /^zp/ =~ i then file = zp_img_dir + '/' + i file2 = zp_img_dir + '/' + "zp_" + zp_diary_date + i puts file File.rename(file,file2) end end } zp_fonts = @diary.config['ZPHOTO_FONTS'] cmd = %Q'zphoto --title="ZPtitle" --template-dir=#{zp_tmp_dir} --output-dir=#{zp_out_dir} --disable-captions --no-zip --flash-font=#{zp_fonts} #{zp_img_dir}/*jpg' puts cmd `#{cmd}` status = $? pwd_stack = Dir.pwd if status == 0 then Dir.chdir(zp_out_dir) # zphoto のテンプレート文字コードは EUC-JP Dir.entries(zp_out_dir).each{|i| if /.+\.html/ =~ i then f = File.open(i) tmp = "" f.each{|line| line = line.tosjis line.gsub!(/ZPtitle/,"#{title}") line.gsub!(/ZPbaseurl/,"#{zp}") line.gsub!(/ZPhtmlfile/,"#{i}") #line.gsub!(/ZPimgfile=\"(.+?)\"/,"\\1") line.gsub!(/ZPclose/,%Q!Close This Window!) line.gsub!(%r|(with zphoto.)|,"\\1 \n\t\t") tmp << line.kconv(@diary.outputKcode) } f.close res = File.open(i,"w") res.write(tmp) res.close end } else str << "zphoto err." end Dir.chdir(pwd_stack) end str << zp_swf_html_src(zp_diary_date + '/' + zp_swf,zp) #str << %Q!#{zp}! str << %Q!#{title}! str << "" str } end end end