Index: openacs-4/packages/richtext-ckeditor4/tcl/richtext-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/richtext-ckeditor4/tcl/richtext-procs.tcl,v diff -u -N -r1.2 -r1.3 --- openacs-4/packages/richtext-ckeditor4/tcl/richtext-procs.tcl 7 Aug 2017 23:48:14 -0000 1.2 +++ openacs-4/packages/richtext-ckeditor4/tcl/richtext-procs.tcl 16 Aug 2017 13:10:20 -0000 1.3 @@ -5,35 +5,66 @@ This script defines the following two procs: ::richtext-ckeditor4::initialize_widget - ::richtext-ckeditor4::render_widgets - + ::richtext-ckeditor4::render_widgets + @author Gustaf Neumann @creation-date 1 Jan 2016 @cvs-id $Id$ } namespace eval ::richtext::ckeditor4 { - set version 4.7.1 - set ck_package standard - + set package_id [apm_package_id_from_key "richtext-ckeditor4"] + + # ns_section ns/server/${server}/acs/richtext-ckeditor + # ns_param CKEditorVersion 4.7.1 + # ns_param CKEditorPackage standard + # ns_param CKFinderURL /acs-content-repository/ckfinder + # ns_param StandardPlugins "uploadimage" + # + set version [parameter::get \ + -package_id $package_id \ + -parameter CKEditorVersion \ + -default 4.7.1] + set ckfinder_url [parameter::get \ + -package_id $package_id \ + -parameter CKFinderURL \ + -default /acs-content-repository/ckfinder] + set standard_plugins [parameter::get \ + -package_id $package_id \ + -parameter StandardPlugins \ + -default ""] + + # + # The cp_package might be basic, standard, of full; + # + # Use "custom" for customized downloads, expand the downloaded zip file in + # richtext-ckeditor4/www/resources/$version + # and rename the expanded top-folder from "ckeditor" to "custom" + # + set ck_package [parameter::get \ + -package_id $package_id \ + -parameter CKEditorPackage \ + -default "standard"] + ad_proc initialize_widget { -form_id -text_id {-options {}} } { - + Initialize an CKEditor richtext editor widget. - + } { ns_log debug "initialize CKEditor instance with <$options>" - # allow per default all classes, unless the user has specified + # Allow per default all CSS-classes, unless the user has specified # it differently if {![dict exists $options extraAllowedContent]} { dict set options extraAllowedContent {*(*)} } - + + # # The richtext widget might be specified by "options {editor # ckeditor4}" or via the package parameter "RichTextEditor" of # acs-templating. @@ -44,37 +75,58 @@ # plugins skin customConfig spellcheck # set ckOptionsList {} - + if {![dict exists $options spellcheck]} { + set package_id [apm_package_id_from_key "richtext-ckeditor4"] dict set options spellcheck [parameter::get \ - -package_id [apm_package_id_from_key "richtext-ckeditor4"] \ + -package_id $package_id \ -parameter "SCAYT" \ -default "false"] } - # For the native spellchecker, one has to hold "ctrl" or "cmd" # with the right click. - + + # + # Get the property "displayed_object_id" from the call stack + # + for {set l 0} {$l < [info level]} {incr l} { + set propVar __adp_properties(displayed_object_id) + if {[uplevel #$l [list info exists $propVar]]} { + set displayed_object_id [uplevel #$l [list set $propVar]] + break + } + } + set upload_url [export_vars \ + -base $::richtext::ckeditor4::ckfinder_url/upload { + {object_id $displayed_object_id} {type Images} + }] lappend ckOptionsList \ "language: '[lang::conn::language]'" \ "disableNativeSpellChecker: false" \ - "scayt_autoStartup: [dict get $options spellcheck]" + "scayt_autoStartup: [dict get $options spellcheck]" \ + "imageUploadUrl: '$upload_url'" + set plugins [split $::richtext::ckeditor4::standard_plugins ,] if {[dict exists $options plugins]} { - lappend ckOptionsList "extraPlugins: '[dict get $options plugins]'" + lappend plugins {*}[split [dict get $options plugins] ,] } + if {[llength $plugins] > 0} { + lappend ckOptionsList "extraPlugins: '[join $plugins ,]'" + } if {[dict exists $options skin]} { lappend ckOptionsList "skin: '[dict get $options skin]'" } if {[dict exists $options customConfig]} { - lappend ckOptionsList "customConfig: '[dict get $options customConfig]'" + lappend ckOptionsList \ + "customConfig: '[dict get $options customConfig]'" } if {[dict exists $options extraAllowedContent]} { - lappend ckOptionsList "extraAllowedContent: '[dict get $options extraAllowedContent]'" + lappend ckOptionsList \ + "extraAllowedContent: '[dict get $options extraAllowedContent]'" } set ckOptions [join $ckOptionsList ", "] - + # # Add the configuration via body script # @@ -86,7 +138,7 @@ # Load the editor and everything necessary to the current page. # ::richtext::ckeditor4::add_editor - + # # do we need render_widgets? # @@ -102,7 +154,7 @@ ::acs_blank_master(ckeditor4) ::acs_blank_master__htmlareas - + } { # # In case no ckeditor4 instances are created, nothing has to be @@ -125,7 +177,7 @@ Get information about available version(s) of CKEditor, either from the local file system, or from CDN. - + } { # # If no version or ck editor package are specified, use the @@ -140,7 +192,8 @@ set suffix $version/$ck_package/ckeditor.js set resources $::acs::rootdir/packages/richtext-ckeditor4/www/resources - + ns_log notice "ACS::ROOT <$::acs::rootdir>" + ns_log notice "CHECK <$resources/$suffix>" if {[file exists $resources/$suffix]} { lappend result file $resources/$suffix lappend result resources /resources/richtext-ckeditor4/$suffix @@ -149,7 +202,7 @@ return $result } - + ad_proc ::richtext::ckeditor4::add_editor { {-ck_package ""} {-version ""} @@ -164,14 +217,15 @@ This function can be as well used from other packages, such e.g. from the xowiki form-fields, which provide a much higher customization. - + } { set version_info [::richtext::ckeditor4::version_info \ -ck_package $ck_package \ -version $version] if {[dict exists $version_info resources]} { - template::head::add_javascript -src [dict get $version_info resources] + template::head::add_javascript \ + -src [dict get $version_info resources] } else { template::head::add_javascript -src [dict get $version_info cdn] security::csp::require script-src cdn.ckeditor.com @@ -184,13 +238,16 @@ # security::csp::require script-src 'unsafe-eval' security::csp::require -force script-src 'unsafe-inline' + + # this is needed currently for "imageUploadUrl" + security::csp::require img-src data: } - + ad_proc ::richtext::ckeditor4::download { {-ck_package ""} {-version ""} } { - + Download the CKeditor package in the specified version and put it into a directory structure similar to the CDN structure to allow installation of multiple versions. When the local @@ -199,7 +256,7 @@ Notice, that for this automated download, the "unzip" program must be installed and $::acs::rootdir/packages/www must be writable by the web server. - + } { # # If no version or ck editor package are specified, use the @@ -220,9 +277,9 @@ # set unzip [::util::which unzip] if {$unzip eq ""} { - error "can't install CKeditor locally; no unzip program found on PATH" + error "can't install CKeditor locally; no unzip program found on PATH" } - + # # Do we have a writable output directory under resources? # @@ -245,14 +302,17 @@ # set fn [dict get $result file] set output [exec $unzip -o $fn -d $resources/$version] - file rename -- $resources/$version/ckeditor $resources/$version/$ck_package + file rename -- \ + $resources/$version/ckeditor \ + $resources/$version/$ck_package } else { error "download of $download_url failed, HTTP status: [dict get $result status]" } } } + # Local variables: # mode: tcl # tcl-indent-level: 4