Index: openacs-4/packages/acs-subsite/www/user/portrait/upload-2-oracle.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-subsite/www/user/portrait/Attic/upload-2-oracle.xql,v diff -u -r1.2.6.1 -r1.2.6.2 --- openacs-4/packages/acs-subsite/www/user/portrait/upload-2-oracle.xql 4 May 2004 12:11:56 -0000 1.2.6.1 +++ openacs-4/packages/acs-subsite/www/user/portrait/upload-2-oracle.xql 2 Jul 2004 11:40:55 -0000 1.2.6.2 @@ -38,7 +38,8 @@ mime_type => :guessed_file_type, item_id => :item_id, creation_user => :user_id, - creation_ip => :creation_ip + creation_ip => :creation_ip, + content_length => :n_bytes ); update cr_items Index: openacs-4/packages/acs-subsite/www/user/portrait/upload-2.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-subsite/www/user/portrait/Attic/upload-2.tcl,v diff -u -r1.7 -r1.7.2.1 --- openacs-4/packages/acs-subsite/www/user/portrait/upload-2.tcl 4 Mar 2004 14:52:48 -0000 1.7 +++ openacs-4/packages/acs-subsite/www/user/portrait/upload-2.tcl 2 Jul 2004 11:40:55 -0000 1.7.2.1 @@ -12,19 +12,21 @@ {title ""} } -set current_user_id [ad_verify_and_get_user_id] +set current_user_id [auth::require_login] if [empty_string_p $user_id] { set user_id $current_user_id -} +} ad_require_permission $user_id "write" set exception_text "" set exception_count 0 -if { ![info exists upload_file] || [empty_string_p $upload_file] } { - append exception_text "
  • Please specify a file to upload\n" +if {![info exists upload_file] + || [empty_string_p $upload_file] +} { + append exception_text "
  • Please specify a file to upload
  • \n" incr exception_count } else { # this stuff only makes sense to do if we know the file exists @@ -41,27 +43,29 @@ # check to see if this is one of the favored MIME types, # e.g., image/gif or image/jpeg - if { ![empty_string_p [ad_parameter AcceptablePortraitMIMETypes "user-info"]] && [lsearch [ad_parameter AcceptablePortraitMIMETypes "user-info"] $guessed_file_type] == -1 } { + if { ![empty_string_p [ad_parameter AcceptablePortraitMIMETypes "user-info"]] + && [lsearch [ad_parameter AcceptablePortraitMIMETypes "user-info"] $guessed_file_type] == -1 } { incr exception_count - append exception_text "
  • Your image wasn't one of the acceptable MIME types: [ad_parameter AcceptablePortraitMIMETypes "user-info"]" + append exception_text "
  • Your image wasn't one of the acceptable MIME types: [ad_parameter AcceptablePortraitMIMETypes "user-info"]
  • " } # strip off the C:\directories... crud and just get the file name - if ![regexp {([^/\\]+)$} $upload_file match client_filename] { + if {![regexp {([^/\\]+)$} $upload_file match client_filename]} { # couldn't find a match set client_filename $upload_file } - - if { ![empty_string_p [ad_parameter MaxPortraitBytes "user-info"]] && $n_bytes > [ad_parameter MaxPortraitBytes "user-info"] } { - append exception_text "
  • Your file is too large. The publisher of [ad_system_name] has chosen to limit portraits to [util_commify_number [ad_parameter MaxPortraitBytes "user-info"]] bytes. You can use PhotoShop or the GIMP (free) to shrink your image.\n" + + if { ![empty_string_p [ad_parameter MaxPortraitBytes "user-info"]] + && $n_bytes > [ad_parameter MaxPortraitBytes "user-info"] } { + append exception_text "
  • Your file is too large. The publisher of [ad_system_name] has chosen to limit portraits to [util_commify_number [ad_parameter MaxPortraitBytes "user-info"]] bytes. You can use PhotoShop or the GIMP (free) to shrink your image.
  • \n" incr exception_count } } if { $exception_count > 0 } { ad_return_complaint $exception_count $exception_text - return + ad_script_abort } set what_aolserver_told_us "" @@ -73,7 +77,9 @@ # the AOLserver jpegsize command has some bugs where the height comes # through as 1 or 2 -if { ![empty_string_p $what_aolserver_told_us] && [lindex $what_aolserver_told_us 0] > 10 && [lindex $what_aolserver_told_us 1] > 10 } { +if { ![empty_string_p $what_aolserver_told_us] + && [lindex $what_aolserver_told_us 0] > 10 + && [lindex $what_aolserver_told_us 1] > 10 } { set original_width [lindex $what_aolserver_told_us 0] set original_height [lindex $what_aolserver_told_us 1] } else { @@ -86,96 +92,36 @@ set creation_ip [ad_conn peeraddr] set name "portrait-of-user-$user_id" -set create_item " -begin - :1 := content_item.new( - name => :name, - creation_ip => :creation_ip); -end;" - -set create_rel " -begin - :1 := acs_rel.new ( - rel_type => 'user_portrait_rel', - object_id_one => :user_id, - object_id_two => :item_id); -end; -" - -set create_revision " -begin - :1 := content_revision.new( - title => :title, - description => :portrait_comment, - text => 'not_important', - mime_type => :guessed_file_type, - item_id => :item_id, - creation_user => :user_id, - creation_ip => :creation_ip - ); - - update cr_items - set live_revision = :1 - where item_id = :item_id; -end;" - -set update_photo " -update cr_revisions -set content = empty_blob() -where revision_id = :revision_id -returning content into :1 -" - -set upload_image_info " -insert into images -(image_id, width, height) -values -(:revision_id, :original_width, :original_height) -" - # let's figure out if this person has a portrait yet -if { ![db_0or1row get_item_id "select object_id_two as item_id -from acs_rels -where object_id_one = :user_id -and rel_type = 'user_portrait_rel'"] } { +if { ![db_0or1row get_item_id {}]} { # The user doesn't have a portrait relation yet db_transaction { - set item_id [db_exec_plsql create_item $create_item] - set rel_id [db_exec_plsql create_rel $create_rel] - set revision_id [db_exec_plsql create_revision $create_revision] - db_dml update_photo $update_photo -blob_files [list $tmp_filename] - db_dml upload_image_info $upload_image_info + set item_id [db_exec_plsql create_item {}] + set revision_id [db_exec_plsql create_revision {}] + set rel_id [db_exec_plsql create_rel {}] + db_dml update_photo {} -blob_files [list $tmp_filename] + db_dml upload_image_info {} } - } else { #already has a portrait, so all we have to do is to make a new revision for it - #Let's check if a current revision exists: - if {![db_0or1row get_revision_id "select live_revision as revision_id - from cr_items - where item_id = :item_id"] || [empty_string_p $revision_id]} { + # Let's check if a current revision exists: + if {![db_0or1row get_revision_id {}] + || [empty_string_p $revision_id] + } { # It's an insert rather than an update db_transaction { - set revision_id [db_exec_plsql create_revision $create_revision] - db_dml update_photo $update_photo -blob_files [list $tmp_filename] - db_dml upload_image_info $upload_image_info + set revision_id [db_exec_plsql create_revision {}] + db_dml update_photo {} -blob_files [list $tmp_filename] + db_dml upload_image_info {} } } else { # it's merely an update db_transaction { - db_dml update_photo $update_photo -blob_files [list $tmp_filename] - db_dml update_image_info " - update images - set width = :original_width, height = :original_height - where image_id = :revision_id" - db_dml update_photo_info " - update cr_revisions - set description = :portrait_comment, - publish_date = sysdate, - mime_type = :guessed_file_type, - title = :title - where revision_id = :revision_id" + db_dml update_photo {} -blob_files [list $tmp_filename] + db_dml update_image_info {} + db_dml update_photo_info {} } } }