Index: openacs-4/packages/file-storage/tcl/file-storage-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/file-storage/tcl/file-storage-procs.tcl,v diff -u -N -r1.69 -r1.70 --- openacs-4/packages/file-storage/tcl/file-storage-procs.tcl 27 Apr 2015 15:28:20 -0000 1.69 +++ openacs-4/packages/file-storage/tcl/file-storage-procs.tcl 7 Aug 2017 23:48:11 -0000 1.70 @@ -22,10 +22,7 @@ } { Returns the name of a folder. } { - return [db_exec_plsql folder_name " - begin - :1 := file_storage.get_folder_name(:folder_id); - end;"] + return [db_string folder_name {}] } # @@ -63,10 +60,11 @@ Returns 1 if the file_id corresponds to a file in the file-storage system. Returns 0 otherwise. } { - if {[db_string object_type " - select object_type - from acs_objects - where object_id = :file_id" -default ""] eq "content_item"} { + if {[db_string object_type { + select object_type + from acs_objects + where object_id = :file_id + } -default ""] eq "content_item"} { return 1 } else { return 0 @@ -79,10 +77,11 @@ Returns 1 if the version_id corresponds to a version in the file-storage system. Returns 0 otherwise. } { - if {[db_string object_type " - select object_type - from acs_objects - where object_id = :version_id" -default ""] eq "file_storage_object"} { + if {[db_string object_type { + select object_type + from acs_objects + where object_id = :version_id + } -default ""] eq "file_storage_object"} { return 1 } else { return 0 @@ -110,28 +109,12 @@ # This only gets child folders and items - set num_wo_perm [db_string child_perms " - select count(*) - from cr_items - where item_id in (select item_id - from cr_items - connect by prior item_id = parent_id - start with item_id = :item_id) - and acs_permission.permission_p(item_id,:user_id,:privilege) = 'f'"] + set num_wo_perm [db_string child_perms {}] # now check revisions - db_foreach child_items { - select item_id as child_item_id - from cr_items - connect by prior item_id = parent_id - start with item_id = :item_id - } { - incr num_wo_perm [db_string revision_perms " - select count(*) - from cr_revisions - where item_id = :child_item_id - and acs_permission.permission_p(revision_id,:user_id,:privilege) = 'f'"] + db_foreach child_items {} { + incr num_wo_perm [db_string revision_perms {}] } if { $num_wo_perm > 0 } { @@ -169,8 +152,9 @@ } { # don't get title for last element if we are in the # root folder - set start_id [db_string parent_id " - select parent_id from cr_items where item_id = :item_id"] + set start_id [db_string parent_id { + select parent_id from cr_items where item_id = :item_id + }] set final [db_exec_plsql title "begin :1 := file_storage.get_title(:item_id); end;"] @@ -264,7 +248,7 @@ } { Get the parent of a given item. } { - return [db_string get_parent_id ""] + return [db_string get_parent_id {}] } @@ -347,9 +331,9 @@ {-folder_id:required} {-description ""} } { - sets the description for the given folder in cr_folders. Perhaps this shoudl be a CR proc? + sets the description for the given folder in cr_folders. Perhaps this should be a CR proc? } { - db_dml set_folder_description { *SQL* } + db_dml set_folder_description {} } ad_proc -public fs::object_p { @@ -385,10 +369,13 @@ get the name of a file storage object and make it safe for writing to the file system } { - return [remove_special_file_system_characters -string [get_object_name -object_id $object_id]] + return [ad_sanitize_filename \ + -collapse_spaces \ + -tolower \ + [get_object_name -object_id $object_id]] } -ad_proc -public fs::remove_special_file_system_characters { +ad_proc -deprecated -public fs::remove_special_file_system_characters { {-string:required} } { remove unsafe file system characters. useful if you want to use $string @@ -559,18 +546,25 @@ if {$folder_name eq ""} { set folder_name [get_object_name -object_id $folder_id] } - set folder_name [remove_special_file_system_characters -string $folder_name] + set folder_name [ad_sanitize_filename \ + -collapse_spaces \ + -tolower \ + $folder_name] set dir "[file join ${path} "${folder_name}"]" # set dir "[file join ${path} "download"]" file mkdir $dir foreach object [get_folder_contents -folder_id $folder_id -user_id $user_id] { + set file_name [ad_sanitize_filename \ + -collapse_spaces \ + -tolower \ + [ns_set get $object name]] publish_object_to_file_system \ -object_id [ns_set get $object object_id] \ -path $dir \ - -file_name [remove_special_file_system_characters -string [ns_set get $object name]] \ - -user_id $user_id + -file_name $file_name \ + -user_id $user_id } return $dir @@ -595,14 +589,17 @@ set file_name $name } set file_name "${file_name}.url" - set file_name [remove_special_file_system_characters -string $file_name] + set file_name [ad_sanitize_filename \ + -collapse_spaces \ + -tolower \ + $file_name] - set fp [open [file join ${path} ${file_name}] w] + set fp [open [file join $path $file_name] w] puts $fp {[InternetShortcut]} puts $fp URL=$url close $fp - return [file join ${path} ${file_name}] + return [file join $path $file_name] } ad_proc -public fs::publish_versioned_object_to_file_system { @@ -648,7 +645,10 @@ set file_name $file_upload_name } - set file_name [remove_special_file_system_characters -string $file_name] + set file_name [ad_sanitize_filename \ + -collapse_spaces \ + -tolower \ + $file_name] switch $storage_type { lob { @@ -765,9 +765,15 @@ set indbp "f" set storage_type "file" } - if {$mime_type eq ""} { - set mime_type [cr_filename_to_mime_type -create -- $name] - } + + # This check also happens in content repository, but as something + # similar was already here and mimetype coming from this was used + # afterwards, we kept this behavior. + set mime_type [cr_check_mime_type \ + -filename $name \ + -mime_type $mime_type \ + -file $tmp_filename] + # we have to do this here because we create the object before # calling cr_import_content @@ -782,7 +788,7 @@ } db_transaction { - if {![db_string item_exists ""]} { + if {![db_string item_exists {}]} { set item_id [content::item::new \ -item_id $item_id \ @@ -801,7 +807,7 @@ } # Deal with notifications. Usually send out the notification - # But surpress it if the parameter is given + # But suppress it if the parameter is given if {$no_notification_p} { set do_notify_here_p "f" } else { @@ -880,7 +886,9 @@ set storage_type "file" } if {$item_id ne ""} { - set storage_type [db_string get_storage_type "select storage_type from cr_items where item_id=:item_id"] + set storage_type [db_string get_storage_type { + select storage_type from cr_items where item_id=:item_id + }] } if {$mime_type eq "" } { set mime_type "text/html" @@ -892,7 +900,7 @@ set content_type "file_storage_object" db_transaction { - if {$item_id eq "" || ![db_string item_exists ""]} { + if {$item_id eq "" || ![db_string item_exists {}]} { set item_id [db_exec_plsql create_item ""] if {$creation_user ne ""} { permission::grant -party_id $creation_user -object_id $item_id -privilege admin @@ -949,7 +957,7 @@ set package_id [ad_conn package_id] } if {$storage_type eq ""} { - set storage_type [db_string get_storage_type ""] + set storage_type [db_string get_storage_type {}] } if {$creation_user eq ""} { set creation_user [ad_conn user_id] @@ -959,19 +967,21 @@ } set parent_id [fs::get_parent -item_id $item_id] if {$storage_type eq ""} { - set storage_type [db_string get_storage_type "select storage_type from cr_items where item_id=:item_id"] + set storage_type [db_string get_storage_type { + select storage_type from cr_items where item_id=:item_id + }] } switch -- $storage_type { file { - set revision_id [db_exec_plsql new_file_revision { }] + set revision_id [db_exec_plsql new_file_revision {}] set cr_file [cr_create_content_file_from_string $item_id $revision_id $content_body] # get the size set file_size [cr_file_size $cr_file] # update the file path in the CR and the size on cr_revisions - db_dml update_revision { } + db_dml update_revision {} } lob { # if someone stored file storage content in the database @@ -1037,12 +1047,17 @@ } { # always use the storage type of the existing item if {$storage_type eq ""} { - set storage_type [db_string get_storage_type ""] + set storage_type [db_string get_storage_type {}] } - if {$mime_type eq ""} { - set mime_type [cr_filename_to_mime_type -create -- $name] - } + # This check also happens in content repository, but as something + # similar was already here and mimetype coming from this was used + # afterwards, we kept this behavior. + set mime_type [cr_check_mime_type \ + -filename $name \ + -mime_type $mime_type \ + -file $tmp_filename] + set tmp_size [file size $tmp_filename] set parent_id [fs::get_parent -item_id $item_id] set revision_id [cr_import_content \ @@ -1154,7 +1169,7 @@ Deletes a revision. If it was the last revision, it deletes the file as well. } { - set parent_id [db_exec_plsql delete_version ""] + set parent_id [db_exec_plsql delete_version {}] if {$parent_id > 0} { delete_file -item_id $item_id -parent_id $parent_id @@ -1248,7 +1263,7 @@ set url "[ad_url]" set new_content "" - db_0or1row get_owner_name { } + db_0or1row get_owner_name {} if {$action eq "new_file" || $action eq "new_url" || $action eq "new_version"} { @@ -1303,8 +1318,9 @@ # walk through all folders up to the root folder while {$folder_id != $root_folder} { - set parent_id [db_string parent_id " - select parent_id from cr_items where item_id = :folder_id"] + set parent_id [db_string parent_id { + select parent_id from cr_items where item_id = :folder_id + }] notification::new \ -type_id [notification::type::get_type_id \ -short_name fs_fs_notif] \ @@ -1406,8 +1422,8 @@ and r.revision_id = o.object_id } -column_array file_object_info - set content [db_exec_plsql get_content { - }] + # GN: this query was probably never defined in CVS + #set content [db_exec_plsql get_content {}] if {$file_object_info(storage_type) eq "file"} { set filename [cr_fs_path $file_object_info(storage_area_key)] @@ -1468,7 +1484,9 @@ @creation-date 2005-02-28 } { set folder_id $object_id - return "[ad_url][db_string select_fs_package_url {}]index?folder_id=$folder_id" + set package_id [lindex [fs::get_folder_package_and_root $folder_id] 0] + set fs_package_url [lindex [site_node::get_url_from_object_id -object_id $package_id] 0] + return "[ad_url]${fs_package_url}index?folder_id=$folder_id" } ad_proc -public fs::file_copy { @@ -1628,3 +1646,9 @@ } return [join $categories $joinwith] } + +# Local variables: +# mode: tcl +# tcl-indent-level: 4 +# indent-tabs-mode: nil +# End: