Index: openacs-4/packages/acs-templating/tcl/file-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-templating/tcl/file-procs.tcl,v diff -u -r1.4 -r1.5 --- openacs-4/packages/acs-templating/tcl/file-procs.tcl 29 Jan 2004 14:40:03 -0000 1.4 +++ openacs-4/packages/acs-templating/tcl/file-procs.tcl 21 Jun 2005 06:59:57 -0000 1.5 @@ -55,3 +55,82 @@ } } + +ad_proc -private template::util::file::generate_filename { + {-title:required} + {-extension:required} + {-existing_filenames ""} + {-party_id ""} +} { + Generate a pretty filename that relates to the title supplied and is unique + + @param party_id if supplied the filenames associated with this party will be used as existing_filenames if existing filenames is not provided + + @param existing_filenames a list of filenames that the generated filename must not be equal to +} { + if {[exists_and_not_null party_id] + && [string is integer $party_id] && ![exists_and_not_null existing_filenames]} { + set existing_filenames [db_list get_parties_existing_filenames {}] + } + set filename [util_text_to_url \ + -text ${title} -replacement "_"] + set output_filename "${filename}.${extension}" + set num 1 + while {[lsearch $existing_filenames $output_filename] >= 0} { + set output_filename "${filename}${num}.${extension}" + incr num + } + return $output_filename +} + +ad_proc -private template::util::file::get_file_extension { + {-filename:required} +} { + get the file extension from a file +} { + return [lindex [split $filename "."] end] +} + + +ad_proc -public template::util::file::store_for_party { + {-upload_file:required} + {-party_id:required} + {-package_id ""} +} { + Store the file uploaded under the party_id if a file was uploaded + + @author Malte Sussdorff (sussdorff@sussdorff.de) + @creation-date 2005-06-21 + + @param upload_file + + @param party_id + + @return the revision_id of the generated item + + @error +} { + + set filename [template::util::file::get_property filename $upload_file] + if {$filename != "" } { + set tmp_filename [template::util::file::get_property tmp_filename $upload_file] + set mime_type [template::util::file::get_property mime_type $upload_file] + set tmp_size [file size $tmp_filename] + set extension [lindex [split $filename "."] end] + if {![exists_and_not_null title]} { + regsub -all ".${extension}\$" $filename "" title + } + set filename [template::util::file::generate_filename \ + -title $title \ + -extension $extension \ + -party_id $party_id] + + + set revision_id [cr_import_content \ + -storage_type "file" -title $title -package_id $package_id $party_id $tmp_filename $tmp_size $mime_type $filename] + + content::item::set_live_revision -revision_id $revision_id + + return $revision_id + } +}