Index: openacs-4/packages/forums/forums.info =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/forums/forums.info,v diff -u -r1.56.2.6 -r1.56.2.7 --- openacs-4/packages/forums/forums.info 19 Jun 2019 17:30:51 -0000 1.56.2.6 +++ openacs-4/packages/forums/forums.info 15 Jul 2019 14:48:36 -0000 1.56.2.7 @@ -9,7 +9,7 @@ f t - + OpenACS Online discussion forums. 2017-08-06 @@ -19,7 +19,7 @@ 2 #forums.Forums# - + @@ -44,6 +44,7 @@ + Index: openacs-4/packages/forums/lib/message/post-confirm.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/forums/lib/message/post-confirm.adp,v diff -u -r1.5.2.1 -r1.5.2.2 --- openacs-4/packages/forums/lib/message/post-confirm.adp 21 Feb 2019 16:13:55 -0000 1.5.2.1 +++ openacs-4/packages/forums/lib/message/post-confirm.adp 15 Jul 2019 14:48:36 -0000 1.5.2.2 @@ -1,6 +1,6 @@

#forums.lt_Please_confirm_the_fo#

- +
@@ -9,7 +9,6 @@ #forums.lt_Would_you_like_to_sub# #forums.No# #forums.Yes# -
#forums.lt_Note_that_you_are_alr#
Index: openacs-4/packages/forums/lib/message/post.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/forums/lib/message/post.tcl,v diff -u -r1.30.2.1 -r1.30.2.2 --- openacs-4/packages/forums/lib/message/post.tcl 21 Feb 2019 16:13:29 -0000 1.30.2.1 +++ openacs-4/packages/forums/lib/message/post.tcl 15 Jul 2019 14:48:36 -0000 1.30.2.2 @@ -1,19 +1,65 @@ -ad_page_contract { +ad_include_contract { Form to create message and insert it @author Ben Adida (ben@openforce.net) @creation-date 2003-12-09 @cvs-id $Id$ +} { + message_id:integer,optional,verify + forum_id:integer,notnull + {parent_id:integer,verify ""} + {subject:verify ""} + {message_body:verify ""} + {message_body.format:verify ""} + {confirm_p:verify ""} + {subject.spellcheck:verify ""} + {content.spellcheck:verify ""} + {anonymous_p:boolean,verify ""} + {attach_p:boolean,verify ""} + {attachments:multiple,verify ""} + {attachment_cleanup_list:tmpfile,verify ""} } -set user_id [ad_conn user_id] -set screen_name [acs_user::get_user_info -user_id $user_id -element screen_name] +# +# Debug form content +# +set form [ns_getform] +if { $form eq "" } { return "" } +set export_data "" +for { set i 0 } { $i < [ns_set size $form] } { incr i } { + set key [ns_set key $form $i] + set value [ns_set value $form $i] + append export_data "$key: [ns_quotehtml $value]\n" +} -set useScreenNameP [parameter::get -parameter "UseScreenNameP" -default 0] -set pvt_home [ad_pvt_home] +# +# 'Simple' or 'Complex' (legacy) attachment style +# +# - Simple (default): just allow to attach new files to a message using the file +# widget during post, and using the attachments package API to 'attach' them +# to the message. +# +# - Complex (legacy): attach URLs, new or already existing files, browse +# through folders and choose where to upload the files in the file storage, +# using the attachments package 'attach' pages. +# +set complex_attachments_p false +set attachmentStyle [parameter::get -parameter "AttachmentStyle" -default "simple"] +if {$attachmentStyle eq "complex"} { + set complex_attachments_p true +} + +set peeraddr [ad_conn peeraddr] +set user_id [ad_conn user_id] +set package_id [ad_conn package_id] + +set screen_name [acs_user::get_user_info -user_id $user_id -element screen_name] +set useScreenNameP [parameter::get -parameter "UseScreenNameP" -default 0] +set pvt_home [ad_pvt_home] + if {[array exists parent_message]} { set parent_id $parent_message(message_id) } else { @@ -68,19 +114,43 @@ } } } - +# # Attachments -if {$user_id != 0 & $attachments_enabled_p} { - append form_elements { - {attach_p:integer(radio),optional - {options {{[_ acs-kernel.common_No] 0} {[_ acs-kernel.common_Yes] 1}}} - {label "[_ forums.Attach]"} +# +if {$complex_attachments_p} { + # + # Legacy 'complex' attachments + # + if {$user_id != 0 & $attachments_enabled_p} { + append form_elements { + {attach_p:integer(radio),optional + {options {{[_ acs-kernel.common_No] 0} {[_ acs-kernel.common_Yes] 1}}} + {label "[_ forums.Attach]"} + } } + } else { + append form_elements { + {attach_p:integer(hidden),optional + } + } } } else { - append form_elements { - {attach_p:integer(hidden),optional + # + # New 'simple' attachments + # + if {$user_id != 0 & $attachments_enabled_p} { + append form_elements { + {attachments:file(file),multiple,optional + {label "[_ forums.Attach]"} + } + {attachment_cleanup_list:text(hidden),optional + } } + } else { + append form_elements { + {attach_p:integer(hidden),optional + } + } } } @@ -103,6 +173,8 @@ set subscribe_p 0 set anonymous_p 0 set attach_p 0 + set attachments [list] + set attachment_cleanup_list [list] } -on_submit { ############################## @@ -137,8 +209,39 @@ set content.spellcheck ":nospell:" set content [template::util::richtext::get_property content $message_body] set format [template::util::richtext::get_property format $message_body] + # + # Attachments during the 'preview' action: + # + # 1) Create a multirow to show the files during the preview. + # + # 2) As the temporal files are deleted on submit, we need to + # preserve them. We copy and delete them after the insertion into + # the content repository. + # + if {$attachments ne ""} { + set attachment_list [list] + foreach attachment_file $attachments { + set attachment_data [dict create] + dict set attachment_data name [lindex $attachment_file 0] + dict set attachment_data file [lindex $attachment_file 1] + dict set attachment_data type [lindex $attachment_file 2] + lappend attachment_list $attachment_data + # + # Replace tmpfile with the new one + # + set new_file [ad_tmpnam] + set old_file [dict get $attachment_data file] + file copy -- $old_file $new_file + set attachments [regsub " $old_file " $attachments " $new_file "] + lappend attachment_cleanup_list $new_file + } - set exported_vars [export_vars -form {message_id forum_id parent_id subject {message_body $content} {message_body.format $format} confirm_p subject.spellcheck content.spellcheck anonymous_p attach_p}] + template::util::list_to_multirow attachment_multi $attachment_list + } + # + # Export vars + # + set exported_vars [export_vars -form -sign {message_id forum_id parent_id subject {message_body $content} {message_body.format $format} confirm_p subject.spellcheck content.spellcheck anonymous_p attach_p attachments:multiple attachment_cleanup_list}] set message(format) $format set message(subject) $subject @@ -169,15 +272,15 @@ if {$action eq "post"} { set content [template::util::richtext::get_property content $message_body] set format [template::util::richtext::get_property format $message_body] - + forum::message::new \ - -forum_id $forum_id \ - -message_id $message_id \ - -parent_id $parent_id \ - -subject $subject \ - -content $content \ - -format $format \ - -user_id $displayed_user_id + -forum_id $forum_id \ + -message_id $message_id \ + -parent_id $parent_id \ + -subject $subject \ + -content $content \ + -format $format \ + -user_id $displayed_user_id if { [forum::use_ReadingInfo_p] } { # remove reading info for this thread for all users (mark it unread) @@ -208,10 +311,77 @@ set redirect_url $notification_url } - # Wrap the attachments URL if {$attachments_enabled_p} { - if { $attach_p ne "" && $attach_p} { - set redirect_url [attachments::add_attachment_url -object_id $message_id -return_url $redirect_url -pretty_name "[_ forums.Forum_Posting] \"$subject\""] + if {$complex_attachments_p} { + # + # Wrap the attachments URL + # + if { $attach_p ne "" && $attach_p} { + set redirect_url [attachments::add_attachment_url \ + -object_id $message_id \ + -return_url $redirect_url \ + -pretty_name "[_ forums.Forum_Posting] \"$subject\""] + } + } else { + # + # Create and attach the new items (we assume we have the + # right permissions, as we were able to create the message) + # + # Root folder + # + set root_folder_id [content::item::get_id \ + -root_folder_id $forum_id \ + -item_path "attachments"] + if {$root_folder_id eq ""} { + set root_folder_id [content::item::new \ + -parent_id $forum_id \ + -name "attachments"] + } + # + # Create revision and attach + # + foreach attachment $attachments { + set name $message_id-[clock clicks -microseconds] + set item_id [content::item::new \ + -name $name \ + -parent_id $root_folder_id \ + -context_id $message_id \ + -creation_user $user_id \ + -creation_ip $peeraddr \ + -item_subtype "content_item" \ + -storage_type "file" \ + -package_id $package_id] + + # + # Create a revision for the fresh content_item + # + set revision_id [db_nextval acs_object_id_seq] + content::revision::new \ + -revision_id $revision_id \ + -item_id $item_id \ + -title [lindex $attachment 0] \ + -is_live t \ + -creation_user $user_id \ + -creation_ip $peeraddr \ + -content_type "content_revision" \ + -package_id $package_id \ + -tmp_filename [lindex $attachment 1] \ + -mime_type [lindex $attachment 2] + + # + # Attach the file to the object via the attachments API + # + attachments::attach \ + -object_id $message_id \ + -attachment_id $item_id + } + # + # Cleanup the possible attachment temporal files that still + # exist, created during the 'preview' action. + # + if {$attachment_cleanup_list ne ""} { + file delete -- {*}$attachment_cleanup_list + } } } Index: openacs-4/packages/forums/lib/message/row.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/forums/lib/message/row.adp,v diff -u -r1.26.2.2 -r1.26.2.3 --- openacs-4/packages/forums/lib/message/row.adp 21 Jun 2019 16:36:44 -0000 1.26.2.2 +++ openacs-4/packages/forums/lib/message/row.adp 15 Jul 2019 14:48:36 -0000 1.26.2.3 @@ -39,9 +39,18 @@
@message.content;literal@
- +
+ +
+
    + +
  • #attachments.Attachment# @attachment_multi.name@
  • +
    +
+
+
Index: openacs-4/packages/forums/lib/message/row.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/forums/lib/message/row.tcl,v diff -u -r1.16.2.3 -r1.16.2.4 --- openacs-4/packages/forums/lib/message/row.tcl 15 Feb 2019 13:25:58 -0000 1.16.2.3 +++ openacs-4/packages/forums/lib/message/row.tcl 15 Jul 2019 14:48:36 -0000 1.16.2.4 @@ -16,6 +16,7 @@ {preview:boolean 0} {alt_template:token ""} {message} + {attachment_multi ""} } set viewer_id [ad_conn user_id] @@ -28,7 +29,7 @@ -user_id $message(user_id) \ -element [expr {$useScreenNameP ? "screen_name" : "name"}]] set message(user_url) user-history?user_id=$message(user_id) -} else { +} else { set message(user_name) [_ acs-kernel.Unregistered_Visitor] set message(user_url) "" }