Index: openacs-4/packages/acs-templating/tcl/richtext-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-templating/tcl/richtext-procs.tcl,v diff -u -r1.66 -r1.67 --- openacs-4/packages/acs-templating/tcl/richtext-procs.tcl 6 Dec 2018 21:24:17 -0000 1.66 +++ openacs-4/packages/acs-templating/tcl/richtext-procs.tcl 3 Sep 2024 15:37:35 -0000 1.67 @@ -75,8 +75,8 @@ upvar 2 $message_ref message $value_ref richtext_list lassign $richtext_list contents format - if { $contents ne "" && [lsearch -exact [template::util::richtext::formats] $format] == -1 } { - set message "Invalid format, '$format'." + if { $format ni [template::util::richtext::formats] } { + set message "Invalid format '[ns_quotehtml $format]'." return 0 } @@ -196,7 +196,7 @@ ad_proc -public template::util::richtext::initialize_widget { -form_id -text_id - -editor + {-editor ""} {-options {}} } { @@ -206,16 +206,55 @@ @param form_id ID of the form containing the textarea @param text_id ID of the textarea - @param editor Editor, which should be used + @param editor Editor, which should be used. Will default to that + specified in acs-templating RichTextEditor + parameter when not specified. @param options Options passed in from the widget spec @return On success, this function returns a dict with success 1 } { + if {$editor eq ""} { + set package_id_templating [::apm_package_id_from_key "acs-templating"] + set editor [::parameter::get \ + -package_id $package_id_templating \ + -parameter "RichTextEditor" \ + -default "xinha"] + } + if {![require_editor -editor $editor]} { return {success 0} } + # + # The actual richtext-editor implementation may provide some + # use-case based presets. Examples may be a "minimal", "standard" + # and "advanced" configuration that are reused in various forms. + # + # Here, we check and eventually return such conf, which will be + # applied to the loading formfield. + # + # When no preset was specified, we will try to look for the + # "standard" preset. This provides a hook for site-wide + # customization via a tcl proc, which enables to inject + # e.g. information coming from the connection context or other tcl + # commands, not possible via parameter alone. + # + # The purpose of this feature is to have a set of logical + # configurations that do not depend on the specific editor and + # can be extended downstream. + # + if {[dict exists $options preset]} { + set preset [dict get $options preset] + } else { + set preset "standard" + } + if {[info commands ::richtext::${editor}::preset::${preset}] ne ""} { + set options [dict merge \ + [::richtext::${editor}::preset::${preset}] \ + $options] + } + set result {success 1} lappend result {*}[::richtext::${editor}::initialize_widget \ -form_id $form_id \ @@ -253,7 +292,8 @@ } { set tag textarea if {[dict exists $options editor] - && [info commands ::richtext::[dict get $options editor]::get_tag] ne "" + && [namespace which ::richtext::[ + dict get $options editor]::get_tag] ne "" } { set tag [::richtext::[dict get $options editor]::get_tag -options $options] } @@ -329,7 +369,7 @@
GetHtml CharacterMap ContextMenu FullScreen
@@ -371,7 +411,7 @@
Example for the use of the xinha widget with options:
text:richtext(richtext),nospell,optional
- {label #xowiki.content#}
+ {label Content}
{options {editor xinha plugins OacsFs height 350px file_types %pdf%}}
{html {rows 15 cols 50 style {width: 100%}}}
@@ -411,7 +451,7 @@
If provided with a WYSIWYG editor different than 'xinha' or 'tinymce',
system will just collect formfield ids and supplied options for the
richtext field and will provide them as-is to the blank-master environment.
- When using a custom editor, funcional meaning of the options is totally up
+ When using a custom editor, functional meaning of the options is totally up
to the user.
@@ -429,15 +469,16 @@
#ns_log notice "widget::richtext: richtext-options? [info exists element(options)] HTML? [info exists element(html)]"
- if { [info exists element(html)] } {
- array set attributes $element(html)
- }
+ array set attributes \
+ [::template::widget::merge_tag_attributes element $tag_attributes]
- array set attributes $tag_attributes
-
if { [info exists element(value)] } {
set contents [template::util::richtext::get_property contents $element(value)]
set format [template::util::richtext::get_property format $element(value)]
+ if {$format ni [template::util::richtext::formats]} {
+ ns_log warning "Ignoring provided format '$format' for richtext widget with id $element(id)"
+ set format {}
+ }
} else {
set contents {}
set format {}
@@ -449,7 +490,7 @@
set attributes(id) $element(id)
set package_id_templating [apm_package_id_from_key "acs-templating"]
- set user_agent [string tolower [ns_set get [ns_conn headers] User-Agent]]
+ set user_agent [string tolower [ns_set iget [ns_conn headers] User-Agent]]
if {[string first "safari" $user_agent] != -1} {
if {[regexp {version/([0-9]+)[.]} $user_agent _ user_agent_version]
@@ -464,7 +505,7 @@
}
if { [info exists element(htmlarea_p)] && $element(htmlarea_p) ne "" } {
- set htmlarea_p [template::util::is_true $element(htmlarea_p)]
+ set htmlarea_p [string is true -strict $element(htmlarea_p)]
} else {
set htmlarea_p [parameter::get \
-package_id $package_id_templating \
@@ -483,10 +524,7 @@
if { $htmlarea_p } {
# figure out, which rich text editor to use
set richtextEditor [expr {[info exists options(editor)] ?
- $options(editor) : [parameter::get \
- -package_id $package_id_templating \
- -parameter "RichTextEditor" \
- -default "xinha"]}]
+ $options(editor) : ""}]
#
# Tell the blank-master to include the special stuff
# for the richtext widget in the page header
@@ -529,7 +567,7 @@
# off.
#
append output \
- "\n\n