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.52 -r1.53 --- openacs-4/packages/acs-templating/tcl/richtext-procs.tcl 27 Oct 2014 16:40:12 -0000 1.52 +++ openacs-4/packages/acs-templating/tcl/richtext-procs.tcl 7 Aug 2017 23:48:02 -0000 1.53 @@ -73,17 +73,15 @@ } { upvar 2 $message_ref message $value_ref richtext_list + lassign $richtext_list contents format - set contents [lindex $richtext_list 0] - set format [lindex $richtext_list 1] - if { $contents ne "" && [lsearch -exact [template::util::richtext::formats] $format] == -1 } { set message "Invalid format, '$format'." return 0 } # enhanced text and HTML needs to be security checked - if { [lsearch { text/enhanced text/html } $format] != -1 } { + if { $format in { text/enhanced text/html } } { set check_result [ad_html_security_check $contents] if { $check_result ne "" } { @@ -224,7 +222,7 @@ set output {} if {$element(mode) eq "edit"} { - append output {} + append output {} set attributes(id) "richtext__$element(form_id)__$element(id)" @@ -260,43 +258,117 @@ if { $htmlarea_p } { # Tell the blank-master to include the special stuff for htmlArea in the page header - global acs_blank_master__htmlareas - lappend acs_blank_master__htmlareas $attributes(id) + lappend ::acs_blank_master__htmlareas $attributes(id) } - append output [textarea_internal "$element(id)" attributes $contents] + append output [textarea_internal $element(id) attributes $contents] if { $htmlarea_p } { - append output "" + append output [subst {}] } else { - append output "
[_ acs-templating.Format]: [menu $element(id).format [template::util::richtext::format_options] $format attributes]" + append output \ + [subst {
[_ acs-templating.Format]:}] \ + [menu $element(id).format [template::util::richtext::format_options] $format attributes] } # Spell-checker array set spellcheck [template::util::spellcheck::spellcheck_properties -element_ref element] if { $spellcheck(render_p) } { - append output " [_ acs-templating.Spellcheck]: [menu "$element(id).spellcheck" [nsv_get spellchecker lang_options] $spellcheck(selected_option) attributes]" + append output \ + [subst { [_ acs-templating.Spellcheck]: }] \ + [menu "$element(id).spellcheck" [nsv_get spellchecker lang_options] \ + $spellcheck(selected_option) attributes] } } else { # Display mode if { [info exists element(value)] } { - append output [template::util::richtext::get_property html_value $element(value)] - append output "" - append output "" + append output \ + [template::util::richtext::get_property html_value $element(value)] \ + [subst {}] \ + [subst {}] } } return $output } +# ---------------------------------------------------------------------- +# +# Richtext plugin interface +# +# ---------------------------------------------------------------------- +ad_proc -public template::util::richtext::initialize_widget { + -form_id + -text_id + -editor + {-options {}} +} { + + Initialize a single text input (textarea with the id "text_id" + part of a form with "form_id") for the specified richtext editor + via a richtext-editor plugin (e.g. ckeditor4, tinymce, or xinha) + + @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 options Options passed in from the widget spec + + @return On success, this function returns a dict with success 1 + +} { + if {$editor ni $::template::util::richtext::editors} { + ns_log warning "richtext: no editor with name $editor is registered" + return {success 0} + } + + set result {success 1} + lappend result {*}[::richtext::${editor}::initialize_widget \ + -form_id $form_id \ + -text_id $text_id \ + -options $options] + return $result +} + +set ::template::util::richtext::editors {} + +ad_proc -public template::util::richtext::register_editor { editor } { + + Make an rich-text editor known to the templating system. + + @param editor Editor to be registered + @return List of editors registered so far + +} { + lappend ::template::util::richtext::editors $editor +} + +ad_proc -public template::util::richtext::render_widgets { } { + + Render all rich-text editors with their their widget spefic + code. Every editor might have multiple instances on the page, + which are accessible to "render_widgets" via the global variable + acs_blank_master__htmlareas. This function can be used to perform + a single (customization) operation relevant for multiple widgets. + +} { + + ns_log debug "we have the following editors registered: $::template::util::richtext::editors" + + foreach editor $::template::util::richtext::editors { + ::richtext::${editor}::render_widgets + } +} + + ad_proc -public template::widget::richtext { element_reference tag_attributes } {

Implements the richtext widget, which offers rich text editing options. - This version supports the xinha and tinymce - editors. + This version integrates support for the xinha and + tinymce editors out of the box, but other richtext editors + can be used including and configuring them in your custom template. If the acs-templating.UseHtmlAreaForRichtextP parameter is set to true (1), this will use the WYSIWYG editor widget set in the acs-templating.RichTextEditor @@ -318,14 +390,16 @@ You can also parameterize the richtext widget with a 'htmlarea_p' attribute, which can be true or false, and which will override the parameter setting.

- The available editors in wysigwig mode are xinha and tinymce. In order to - use xinha, one has to use 'editor xinha' in the options of the form field. + The richtext widget can be extended with several plugins, which are OpenACS + packages named richtex-EDITOR. Plugins are available e.g. for xinha, tinymce + and ckeditor4. When the plugins are installed, one can use e.g. xinha + by sepcifying 'editor xinha' in the options of the widget spec. The following options for xinha may be specified: