Hi,
I had trying to implement an option in File Field that resize image.
Yesterday, I created one parameter resize_width in file class and, in convert_to_internal, I implemented the resize image..
So, ::xowiki::formfield::file become it:
Class file -superclass FormField -parameter {
{resize_width 480}
{size 40}
link_label
}
file instproc tmpfile {value} {my set [self proc] $value}
file instproc content-type {value} {my set [self proc] $value}
file instproc initialize {} {
my type file
my set widget_type file(file)
next
}
file instproc entry_name {value} {
return [list name file:[my name] parent_id [[my object] item_id]]
}
file instproc convert_to_internal {} {
my instvar value
if {[my value] eq ""} {
# nothing to do, keep the old value
set value [[my object] form_parameter __old_value_[my name] ""]
[my object] set_property [my name] $value
return
}
regsub -all {\\+} $value {/} value ;# fix IE upload path
set value [::file tail $value]
[my object] set_property [my name] $value
set folder_id [[my object] set parent_id]
array set entry_info [my entry_name $value]
set content_type [my set content-type]
if {$content_type eq "application/octetstream"} {
set content_type [::xowiki::guesstype $value]
}
#my msg "mime_type of $entry_name = [::xowiki::guesstype $value] // [my set content-type] ==> $content_type"
if {[set id [::xo::db::CrClass lookup -name $entry_info(name) -parent_id $entry_info(parent_id)]]} {
# file entry exists already, create a new revision
set file_object [::xo::db::CrClass get_instance_from_db -item_id $id]
$file_object set import_file [my set tmpfile]
$file_object set mime_type $content_type
$file_object set title $value
$file_object save
} else {
if {[lindex [split $content_type "/"] 0] eq "image"} {
ImageMagick::convert -options "-resize [my set resize_width]" [my set tmpfile] [my set tmpfile]
}
# create a new file
set file_object [::xowiki::File new -destroy_on_cleanup \
-title $value \
-name $entry_info(name) \
-parent_id $entry_info(parent_id) \
-mime_type $content_type \
-package_id [[my object] package_id] \
-creation_user [::xo::cc user_id] ]
$file_object set import_file [my set tmpfile]
$file_object save_new
}
}
It works well, but i have doubts about the implemetation and I don't know where I cat implement this.
Anybody can help?