9
# �����������̤���β������åץ����ɡ�����ͥ����������ʸ�ؤ�ɽ��
15
# image( number, 'altword', thumbnail ) - ������ɽ�����ޤ���
16
# number - �������ֹ�0��1��2��
17
# altword - img������ alt�������ʸ����
18
# thumbnail - ����ͥ���(�����ʲ���)����ꤹ��(��ά��)
20
# image_left( number, 'altword', thumbnail ) - image��class=left���ɲä��ޤ���
21
# image_right( number, 'altword', thumbnail ) - image��class=right���ɲä��ޤ���
23
# image_link( number, 'desc' ) - �����ؤΥ���������ޤ���
24
# number - �������ֹ�0��1��2��
28
# tDiary version 1.5.4�ʹߤ�ư��ޤ���
30
# �����ե��������¸����ǥ��쥯�ȥ�
31
# @options['image.dir']
33
# @options['image.url']
35
# @options['image.url']
36
# 0 - �̾��������������ʤ�
37
# 1 - ImageMagick��convert�ǽ̾��貦������
38
# 2 - netpbm���ǽ̾��貦������
40
# �ޤ���@secure = true�ʴĶ��Ǥ�ư��ޤ���
43
# http://shimoi.s26.xrea.com/hiki/hiki.xcg?TdiaryEnikkiEx
47
# Copyright (c) 2002 Daisuke Kato <dai@kato-agri.com>
48
# Copyright (c) 2002 Toshi Okada <toshi@neverland.to>
49
# Copyright (c) 2003 Yoshimi KURUMA <yoshimik@iris.dti.ne.jp>
51
# You can redistribute it and/or modify it under GPL2.
54
2003-05-16 Yoshimi KURUMA <yoshimik@iris.dti.ne.jp>
55
* method 'image' is extended to show a thumbnail.
56
* new method: 'image_link'.
59
2003-05-16 Yoshimi KURUMA <yoshimik@iris.dti.ne.jp>
60
* modify illegal option names.
63
2003-05-16 Yoshimi KURUMA <yoshimik@iris.dti.ne.jp>
64
* support manual upload of thumbnail when useresize == 0
66
2003-04-27 Yoshimi KURUMA <yoshimik@iris.dti.ne.jp>
67
* link element is removed when no thumbnail.
69
2003-04-25 Yoshimi KURUMA <yoshimik@iris.dti.ne.jp>
70
* add JavaScript for insert plugin tag into diary.
71
* upload/delete form style changed.
73
2003-04-24 Yoshimi KURUMA <yoshimik@iris.dti.ne.jp>
74
* upload/delete form style changed.
76
2003-04-22 Yoshimi KURUMA <yoshimik@iris.dti.ne.jp>
77
* version 0.1 first form_proc version.
80
@image_dir = @options && @options['image.dir'] || './images/'
81
@image_dir.chop! if /\/$/ =~ @image_dir
82
@image_url = @options && @options['image.url'] || './images/'
83
@image_url.chop! if /\/$/ =~ @image_url
84
@imageex_thumbnailsize = @options && @options['image_ex.previewsize'] || 120
85
@imageex_yearlydir = @options && @options['image_ex.yearlydir'] || 0
88
add_body_enter_proc(Proc.new do |date|
89
@image_date = date.strftime("%Y%m%d")
90
@image_year = date.strftime("%Y")
95
def image( id, alt = "image", id2 = nil, width = nil, place="none" )
96
@image_date ||= @date.strftime("%Y%m%d")
97
@image_year ||= @date.strftime("%Y")
99
if @imageex_yearlydir == 1
100
image_url = %Q[#{@image_url}/#{@image_year}/]
101
image_dir = %Q[#{@image_dir}/#{@image_year}/]
103
image_url = %Q[#{@image_url}/]
104
image_dir = %Q[#{@image_dir}/]
108
Dir.mkdir(image_dir) unless File.directory?(image_dir)
110
list = imageList(@image_date, image_dir).untaint
111
slist = imageList(@image_date, image_dir, "s").untaint
114
width_tag = %Q[width="#{h width}"]
120
%Q[<a href="#{h image_url}#{h list[id.to_i]}"><img class="#{h place}" src="#{h image_url}#{h list[id2.to_i]}" alt="#{h alt}"></a>]
123
%Q[<a href="#{h image_url}#{h list[id.to_i]}"><img src="#{h image_url}#{h slist[id.to_i]}" alt="#{h alt}" title="#{h alt}" #{width_tag} class="#{h place}"></a>]
126
# %Q[<a href="#{h image_url}#{h list[id.to_i]}"><img src="#{h image_url}#{h list[id.to_i]}" alt="#{h alt}" #{width_tag} class="#{h place}"></a>]
127
%Q[<img src="#{h image_url}#{h list[id.to_i]}" alt="#{h alt}" title="#{h alt}" #{width_tag} class="#{h place}">]
133
def image_left( id, alt = "image", id2 = nil, width=nil )
134
image( id, alt, id2, width, "left" )
137
def image_right( id, alt = "image", id2 = nil, width=nil )
138
image( id, alt, id2, width, "right" )
141
def image_link( id, str )
142
@image_date ||= @date.strftime("%Y%m%d")
143
@image_year ||= @date.strftime("%Y")
144
if @imageex_yearlydir == 1
145
image_url = %Q[#{@image_url}/#{@image_year}/]
146
image_dir = %Q[#{@image_dir}/#{@image_year}/]
148
image_url = %Q[#{@image_url}/]
149
image_dir = %Q[#{@image_dir}/]
151
list = imageList(@image_date, image_dir).untaint
152
%Q[<a href="#{h image_url}#{h list[id.to_i]}">#{str}</a>]
157
def imageList(date, image_dir='@image_dir', prefix="")
158
date = "#{prefix}"+date
160
Dir.foreach(image_dir){ |file|
161
if file =~ /(.*)\_(.*)\.(.*)/
163
image_path[$2.to_i] = file
171
add_form_proc do |date|
175
imageex_useresize = @options && @options['image_ex.useresize'] || 0
176
imageex_converttype = @options && @options['image_ex.converttype'] || 0
177
imageex_thresholdsize = @options && @options['image_ex.thresholdsize'] || 160
178
imageex_convertedwidth = @options && @options['image_ex.convertedwidth'] || 160
179
imageex_convertedheight = @options && @options['image_ex.convertedheight'] || 120
181
if imageex_useresize == 1 || imageex_useresize ==2
183
require 'image_size.rb'
185
imageex_useresize = 0
189
if imageex_useresize == 1
190
def resize_image(orig, new, width, height, imageex_convertedwidth, imageex_convertedheight, orig_type, new_type)
191
imageex_convertpath = @options && @options['image_ex.convertpath'] || "convert"
195
imageex_convertedsize = %Q[#{imageex_convertedwidth}x#{imageex_convertedheight}]
196
imageex_convertedsize
198
imageex_convertedsize = %Q[#{imageex_convertedheight}x#{imageex_convertedwidth}]
199
imageex_convertedsize
201
system(imageex_convertpath , "-geometry", imageex_convertedsize , orig, new)
202
if FileTest::size?( new ) == 0
206
elsif imageex_useresize == 2
207
def resize_image(orig, new, width, height, imageex_convertedwidth, imageex_convertedheight, orig_type, new_type)
208
pnmscale = @options && @options['image_ex.pnmscalepath'] || "pnmscale"
209
jpegtopnm = @options && @options['image_ex.jpegtopnmpath'] || "jpegtopnm"
210
pnmtojpeg = @options && @options['image_ex.pnmtojpegpath'] || "pnmtojpeg"
211
pngtopnm = @options && @options['image_ex.pngtopnmpath'] || "pngtopnm"
212
pnmtopng = @options && @options['image_ex.pnmtopngpath'] || "pnmtopng"
213
giftopnm = @options && @options['image_ex.giftopnmpath'] || "giftopnm"
214
tifftopnm = @options && @options['image_ex.tifftopnmpath'] || "tifftopnm"
215
bmptopnm = @options && @options['image_ex.bmptopnmpath'] || "bmptopnm"
217
downtype = orig_type.downcase
218
topnm = eval("#{downtype}topnm")
222
elsif new_type == "png"
227
imageex_convertedsize ="#{imageex_convertedwidth}"
229
imageex_convertedsize ="#{imageex_convertedheight}"
231
com_line =%Q[#{topnm} #{orig} | #{pnmscale} --width #{imageex_convertedsize} | #{pnmto} > #{new}]
233
if FileTest::size?( new ) == 0
239
def dayimagelist( image_dir, image_date, prefix="")
242
Dir.foreach(image_dir){ |file|
243
if file=~ /(.*)\_(.*)\.(.*)/
244
if $1 == "#{prefix}" + image_date.to_s
245
image_path[$2.to_i] = file
252
if @cgi.params['plugin_image_add'][0] && @cgi.params['plugin_image_file'][0].original_filename != ''
253
image_dir = @cgi.params['plugin_image_dir'][0].read.untaint
256
image_date = date.strftime("%Y%m%d")
257
image_filename = @cgi.params['plugin_image_file'][0].original_filename
258
if image_filename =~ /(\.jpg|\.jpeg|\.gif|\.png)\z/i
261
image_name = dayimagelist(image_dir, image_date)
262
image_file = image_dir+image_date+"_"+image_name.length.to_s+image_extension.downcase
266
File::open( image_file, "wb" ) {|f|
267
f.print @cgi.params['plugin_image_file'][0].read
271
if imageex_useresize == 1 or imageex_useresize == 2
272
open(image_file,"rb") do |fh|
273
img = ImageSize.new(fh.read)
274
width = img.get_width
275
height = img.get_height
276
orig_type = img.get_type
277
if imageex_converttype == 0
279
elsif imageex_converttype == 1
284
if width > imageex_thresholdsize or height > imageex_thresholdsize
285
small_image_file = %Q[#{image_dir}s#{image_date}_#{image_name.length.to_s}.#{new_type}]
286
resize_image(image_file, small_image_file, width, height, imageex_convertedwidth, imageex_convertedheight, orig_type, new_type)
292
elsif @cgi.params['plugin_image_thumbnail'][0] && @cgi.params['plugin_image_file'][0].original_filename != ''
293
image_dir = @cgi.params['plugin_image_dir'][0].read.untaint
296
image_date = date.strftime("%Y%m%d")
297
image_filename = @cgi.params['plugin_image_file'][0].original_filename
298
if image_filename =~ /(\.jpg|\.jpeg|\.gif|\.png)\z/i
300
image_name = @cgi.params['plugin_image_name'][0].read.untaint
301
image_file=image_dir+"s"+image_name+image_extension.downcase
305
File::open( image_file, "wb" ) {|f|
306
f.print @cgi.params['plugin_image_file'][0].read
310
elsif @cgi.params['plugin_image_del'][0]
311
image_dir = @cgi.params['plugin_image_dir'][0]
312
image_date = date.strftime("%Y%m%d")
313
image_name = dayimagelist( image_dir, image_date)
314
image_name2= dayimagelist( image_dir, image_date, "s")
316
@cgi.params['plugin_image_id'].untaint.each do |id|
317
if image_name[id.to_i]
318
image_file=image_dir+image_name[id.to_i]
320
if File::exist?(image_file)
321
File::delete(image_file)
324
if image_name2[id.to_i]
325
image_file2=image_dir+image_name2[id.to_i]
327
if File::exist?(image_file2)
328
File::delete(image_file2)
334
puts "Content-Type: text/plain\n\n"
335
puts "#$! (#{$!.type})"
340
if @imageex_yearlydir == 1
341
image_dir = %Q[#{@image_dir}/#{@date.year}/]
343
image_dir = %Q[#{@image_dir}/]
346
if @imageex_yearlydir == 1
347
image_url = %Q[#{@image_url}/#{@date.year}/]
349
image_url = %Q[#{@image_url}/]
352
Dir.mkdir(image_dir) unless File.directory?(image_dir)
355
n_image = imageList(@date.strftime("%Y%m%d"), image_dir).length
356
list = imageList(@date.strftime("%Y%m%d"), image_dir)
357
slist = imageList(@date.strftime("%Y%m%d"), image_dir, "s")
363
pretable<< %Q[<TABLE BORDER="0" CELLSPACING="0" CELLPADDING="0">]
364
posttable << %Q[</TR></TABLE>]
367
if @conf.respond_to?(:style) and @conf.style =~ /Wiki$/i
368
image_plugin_tag1 = "{{"
369
image_plugin_tag2 = "}}"
370
elsif @conf.respond_to?(:style) and @conf.style =~ /RD$/i
371
image_plugin_tag1 = "((%"
372
image_plugin_tag2 = "%))"
374
image_plugin_tag1 = "<%="
375
image_plugin_tag2 = "%>"
380
<script type="text/javascript">
386
window.onload=function(){
387
for(var i=0;i<document.forms.length;i++){
388
for(var j=0;j<document.forms[i].elements.length;j++){
389
var e=document.forms[i].elements[j]
390
if(e.type&&e.type=="textarea"){
394
e.onfocus=new Function("elem=this")
407
while id < n_image do
410
src_tag = %Q[src="#{h image_url}#{h slist[id.to_i]}"]
411
alt_tag = %Q[alt="#{h slist[id.to_i]}"]
413
src_tag = %Q[src="#{h image_url}#{h list[id.to_i]}"]
414
alt_tag = %Q[alt="#{h list[id.to_i]}"]
415
thumbnail_tag = %Q[<form class="update" method="post" enctype="multipart/form-data" action="#{h @update}">#{csrf_protection}<input type="hidden" name="plugin_image_name" value="#{date.strftime( '%Y%m%d' )}_#{h id}"><input type="hidden" name="plugin_image_dir" value="#{h image_dir}"><input type="hidden" name="plugin_image_thumbnail" value="true"><input type="hidden" name="date" value="#{date.strftime( '%Y%m%d' )}"><input type="file" name="plugin_image_file"><input type="submit" name="plugin" value="����ͥ���"></form>] if imageex_useresize == 0
418
ptag = "#{image_plugin_tag1}image #{id}, '����������'#{image_plugin_tag2}"
420
i<< %Q[<td><table border="1" cellpadding="1" cellspacing="1"><tr><td style="text-align:center"><input type="button" onclick="ins("#{ptag}")" value="��ʸ���ɲ�"></td></tr><tr><td style="text-align:center">#{image_plugin_tag1}image #{h id},'title#{h id}'#{image_plugin_tag2}</td></tr><tr><td width="#{@imageex_thumbnailsize * 1.5}" height="#{@imageex_thumbnailsize * 1.3}" style="text-align:center">
421
<img class="form" #{src_tag} #{alt_tag} height="#{@imageex_thumbnailsize}" ></tr><tr><td>#{thumbnail_tag}<form class="update" method="post" action="#{h @update}">#{csrf_protection}<input type="hidden" name="plugin_image_del" value="true"><input type="hidden" name="date" value="#{date.strftime( '%Y%m%d' )}"><input type="hidden" name="plugin_image_id" value="#{h id}"><input type="submit" name="plugin" value="��������"><input type="hidden" name="plugin_image_dir" value="#{h image_dir}"></form>
422
</tr></table></td>] if slist[id.to_i] || list[id.to_i]
423
nt += 1 if slist[id.to_i] || list[id.to_i]
425
if nt > 0 and nt%2 == 0
426
i<< %Q[</TR></TABLE><TABLE BORDER="0" CELLSPACING="0" CELLPADDING="0"><TR><TD>]
432
r << %Q[<div class="form">
433
<div class="caption">
444
r << %Q[<div class="form">
445
<div class="caption">
448
<form class="update" method="post" enctype="multipart/form-data" action="#{h @update}">
450
<input type="hidden" name="plugin_image_dir" value="#{h image_dir}">
451
<input type="hidden" name="plugin_image_add" value="true">
452
<input type="file" name="plugin_image_file">
453
<input type="hidden" name="date" value="#{date.strftime( '%Y%m%d' )}">
454
<input type="submit" name="plugin" value="�������ɲ�">