Index: openacs-4/packages/richtext-ckeditor4/richtext-ckeditor4.info
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/richtext-ckeditor4/richtext-ckeditor4.info,v
diff -u -N -r1.3 -r1.4
--- openacs-4/packages/richtext-ckeditor4/richtext-ckeditor4.info 16 Aug 2017 13:10:20 -0000 1.3
+++ openacs-4/packages/richtext-ckeditor4/richtext-ckeditor4.info 19 Aug 2017 13:22:34 -0000 1.4
@@ -9,16 +9,18 @@
f
f
-
+
Gustaf Neumann
Richtext editor plugin for integrating CKeditor 4 with acs-templating
2017-08-06
2
-
+
+
+
Index: openacs-4/packages/richtext-ckeditor4/lib/file-browser.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/richtext-ckeditor4/lib/file-browser.adp,v
diff -u -N
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/richtext-ckeditor4/lib/file-browser.adp 19 Aug 2017 13:22:34 -0000 1.1
@@ -0,0 +1,88 @@
+
+
+
+
+ @title@
+
+
+
+
+
+ @page_title@
+
+
+
+
+
+
+
+
+
+ @no_attachment@
+
+
+
+
+
+
+
+
Index: openacs-4/packages/richtext-ckeditor4/lib/file-browser.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/richtext-ckeditor4/lib/file-browser.tcl,v
diff -u -N
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/richtext-ckeditor4/lib/file-browser.tcl 19 Aug 2017 13:22:34 -0000 1.1
@@ -0,0 +1,27 @@
+ad_include_contract {
+} {
+ {object_id:naturalnum}
+ {type:word}
+ {CKEditorFuncNum ""}
+ {CKEditor:word ""}
+ {langCode en}
+}
+
+set title "Browse Attached Images"
+set page_title "Selectable Images"
+set no_attachment "No Attachment Available"
+
+template::multirow create images src alt
+
+foreach tuple [attachments::get_attachments -object_id $object_id] {
+ lassign $tuple image_id .
+ template::multirow append images \
+ /acs-content-repository/ckfinder/view?image_id=$image_id ""
+}
+
+#
+# Local variables:
+# mode: tcl
+# tcl-indent-level: 4
+# indent-tabs-mode: nil
+# End:
Index: openacs-4/packages/richtext-ckeditor4/tcl/ckfinder-init.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/richtext-ckeditor4/tcl/ckfinder-init.tcl,v
diff -u -N -r1.1 -r1.2
--- openacs-4/packages/richtext-ckeditor4/tcl/ckfinder-init.tcl 16 Aug 2017 13:10:20 -0000 1.1
+++ openacs-4/packages/richtext-ckeditor4/tcl/ckfinder-init.tcl 19 Aug 2017 13:22:34 -0000 1.2
@@ -31,106 +31,203 @@
#
#
-# Upload handler
+# We need here a small helper for input checking using the usual
+# checkers for two reasons:
#
-ns_register_proc POST $::richtext::ckeditor4::ckfinder_url/upload {
+# 1) The way ckfinder is recommended to work relies on the
+# separate processing of QUERY and POST variables of an
+# request. The traditional OpenACS input handling does NOT
+# support both types of variables at the same time. so we use
+# here a small helper, such we can use at least the
+# traditional calling conventions and page contract filters.
+#
+# 2) The classical page_contract cannot be configured to interact
+# properly with AJAX, at least not with a predefined AJAX
+# interface expecting always a certain JSON array as result.
+# This corresponds to "responseType=json" in the uploadUrl.
+#
+
+ns_register_proc POST $::richtext::ckeditor4::ckfinder_url/uploadimage {
#
- # We need here a small helper for input checking using the usual
- # checkers for two reasons:
+ # Image upload handler (for "uploadimage" plugin)
#
- # 1) The way ckfinder is recommended to work relies on the
- # separate processing of QUERY and POST variables of an
- # request. The traditional OpenACS input handling does NOT
- # support both types of variables at the same time. so we use
- # here a small helper, such we can use at least the
- # traditional calling conventions and page contract filters.
- #
- # 2) The classical page_contract cannot be configured to interact
- # properly with AJAX, at least not with a predefined AJAX
- # interface expecting always a certain JSON array as result.
- #
set complaints [::richtext::ckeditor4::ckfinder::query_page_contract {
- {object_id:naturalnum}
- {type:word}
+ {object_id:naturalnum}
+ {type:word}
}]
if {[llength $complaints] == 0 && $type eq "Images"} {
- set form [ns_getform]
- set d [::richtext::ckeditor4::ckfinder::image_attach \
- -object_id $object_id \
- -import_file [ns_set get $form upload.tmpfile] \
- -mime_type [ns_set get $form upload.content-type] \
- -user_id [ad_conn user_id] \
- -peeraddr [ad_conn peeraddr] \
- -package_id [ad_conn package_id] \
- ]
- set success [dict get $d success]
- if {$success eq "1"} {
- #
- # Successful operation
- #
- set view_url [export_vars \
- -base $::richtext::ckeditor4::ckfinder_url/view {
- {image_id "[dict get $d image_id]"}
- }]
- set reply [subst {{
- "uploaded": [dict get $d success],
- "fileName": "[dict get $d name]",
- "url": "$view_url",
- "width": [dict get $d width],
- "height": [dict get $d height]
- }}]
- } else {
- #
- # ckfinder::image_attach returned an error
- #
- set errMsg [dict get $d errMsg]
- }
+ set form [ns_getform]
+ set d [::richtext::ckeditor4::ckfinder::image_attach \
+ -object_id $object_id \
+ -import_file [ns_set get $form upload.tmpfile] \
+ -mime_type [ns_set get $form upload.content-type] \
+ -user_id [ad_conn user_id] \
+ -peeraddr [ad_conn peeraddr] \
+ -package_id [ad_conn package_id] \
+ -image \
+ ]
+ set success [dict get $d success]
+ if {$success eq "1"} {
+ #
+ # Successful operation
+ #
+ set view_url [export_vars \
+ -base $::richtext::ckeditor4::ckfinder_url/view {
+ {image_id "[dict get $d file_id]"}
+ }]
+ set reply [subst {{
+ "uploaded": [dict get $d success],
+ "fileName": "[dict get $d name]",
+ "url": "$view_url",
+ "width": [dict get $d width],
+ "height": [dict get $d height]
+ }}]
+ } else {
+ #
+ # ckfinder::image_attach returned an error
+ #
+ set errMsg [dict get $d errMsg]
+ }
} else {
- #
- # Either page contract failed or invalid value for 'type' was
- # specified
- #
- set errMsg "invalid query parameter for 'type' // $complaints"
+ #
+ # Either page contract failed or invalid value for 'type' was
+ # specified
+ #
+ dict set d errMsg "invalid query parameter // $complaints"
+ set success 0
}
if {$success eq "0"} {
- set reply [subst {{
- "uploaded": [dict get $d success],
- "error": {
- "message": "[dict get $d errMsg]",
- }
- }}]
+ set reply [subst {{
+ "uploaded": $success,
+ "error": {
+ "message": "[dict get $d errMsg]",
+ }
+ }}]
}
ns_log notice $reply
ns_return 200 text/plain $reply
}
+
+ns_register_proc POST $::richtext::ckeditor4::ckfinder_url/upload {
+ #
+ # Upload handler (for the standard "filebrowser" plugin)
+ #
+ set complaints [::richtext::ckeditor4::ckfinder::query_page_contract {
+ {object_id:naturalnum}
+ {type:word}
+ {CKEditorFuncNum ""}
+ {command:word ""}
+ {CKEditor:word ""}
+ {langCode en}
+ }]
+
+ if {[llength $complaints] == 0 && $type eq "Files"} {
+
+ set form [ns_getform]
+ set d [::richtext::ckeditor4::ckfinder::file_attach \
+ -object_id $object_id \
+ -import_file [ns_set get $form upload.tmpfile] \
+ -mime_type [ns_set get $form upload.content-type] \
+ -user_id [ad_conn user_id] \
+ -peeraddr [ad_conn peeraddr] \
+ -package_id [ad_conn package_id] \
+ ]
+ set success [dict get $d success]
+ if {$success eq "1"} {
+ #
+ # Successful operation
+ #
+ set view_url [export_vars \
+ -base $::richtext::ckeditor4::ckfinder_url/view {
+ {image_id "[dict get $d file_id]"}
+ }]
+ set reply [subst {
+
+ }]
+ } else {
+ #
+ # ckfinder::image_attach returned an error
+ #
+ set errMsg [dict get $d errMsg]
+ }
+ } else {
+ #
+ # Either page contract failed or invalid value for 'type' was
+ # specified
+ #
+ dict set d errMsg "invalid query parameter // $complaints"
+ set success 0
+ }
+
+ if {$success eq "0"} {
+ set reply [subst {[dict get $d errMsg]}]
+ }
+ ns_log notice $reply
+ ns_return 200 text/html $reply
+}
+
+ns_register_proc GET $::richtext::ckeditor4::ckfinder_url/browse {
+ #
+ # File-browser (for the standard "filebrowser" plugin)
+ #
+ set complaints [::richtext::ckeditor4::ckfinder::query_page_contract {
+ {object_id:naturalnum}
+ {type:word}
+ {CKEditorFuncNum ""}
+ {CKEditor:word ""}
+ {langCode en}
+ }]
+
+ permission::require_permission \
+ -party_id [ad_conn user_id] \
+ -object_id $object_id \
+ -privilege read
+
+ set reply [template::adp_include \
+ /packages/richtext-ckeditor4/lib/file-browser [subst {
+ object_id "$object_id"
+ type "$type"
+ CKEditorFuncNum "$CKEditorFuncNum"
+ CKEditor "$CKEditor"
+ langCode "$langCode"
+ }]]
+
+ ns_return 200 text/html $reply
+}
+
#
# View handler
#
ns_register_proc GET $::richtext::ckeditor4::ckfinder_url/view {
+ #
+ # View function (for "filebrowser" and "uploadimage" plugins)
+ #
set ::template::parse_level [info level]
ad_try {
- #
- # Use the standard page_contract
- #
- ad_page_contract {
- } {
- {image_id:naturalnum ""}
- }
- ::richtext::ckeditor4::ckfinder::return_file \
- -revision_id $image_id \
- -user_id [ad_conn user_id]
+ #
+ # Use the standard page_contract
+ #
+ ad_page_contract {
+ } {
+ {image_id:naturalnum ""}
+ }
+ ::richtext::ckeditor4::ckfinder::return_file \
+ -revision_id $image_id \
+ -user_id [ad_conn user_id]
} ad_script_abort val {
- #
- # The page contract has probably failed, no need to raise an
- # exception.
- #
+ #
+ # The page contract has probably failed, no need to raise an
+ # exception.
+ #
}
}
Index: openacs-4/packages/richtext-ckeditor4/tcl/ckfinder-procs.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/richtext-ckeditor4/tcl/ckfinder-procs.tcl,v
diff -u -N -r1.1 -r1.2
--- openacs-4/packages/richtext-ckeditor4/tcl/ckfinder-procs.tcl 17 Aug 2017 12:22:11 -0000 1.1
+++ openacs-4/packages/richtext-ckeditor4/tcl/ckfinder-procs.tcl 19 Aug 2017 13:22:34 -0000 1.2
@@ -14,15 +14,15 @@
namespace eval ::richtext::ckeditor4::ckfinder {
- ad_proc -public image_attach {
+ ad_proc -public file_attach {
-import_file
-mime_type
-object_id
{-privilege read}
- {-image_url /ckfinder/upload.tcl}
-user_id
-peeraddr
-package_id
+ {-image:boolean}
} {
Insert the provided image file to the content repository as a
@@ -39,35 +39,39 @@
-party_id $user_id \
-object_id $object_id \
-privilege $privilege
- ns_log notice "CAN UPLOAD <$object_id>"
- #
- # Check if we can handle the mime type. Currently, only the
- # following four mime types are supported, since these are
- # supported by "ns_imgsize", which is used to determine the
- # dimensions of the image.
- #
- switch -- $mime_type {
- image/jpg -
- image/jpeg -
- image/gif -
- image/png {
- set ext .[lindex [split $mime_type /] 1]
- lassign [ns_imgsize $import_file] width height
- set success 1
+ if {$image_p} {
+ #
+ # Check if we can handle the mime type. Currently, only the
+ # following four mime types are supported, since these are
+ # supported by "ns_imgsize", which is used to determine the
+ # dimensions of the image.
+ #
+ switch -- $mime_type {
+ image/jpg -
+ image/jpeg -
+ image/gif -
+ image/png {
+ set ext .[lindex [split $mime_type /] 1]
+ lassign [ns_imgsize $import_file] width height
+ set success 1
+ }
+ default {
+ ns_log warning "image_attach: can't handle image type '$mime_type'"
+ return [list \
+ success 0 \
+ errMsg "can't handle image type '$mime_type'"]
+ }
}
- default {
- ns_log warning "image_attach: can't handle image type '$mime_type'"
- return [list \
- success 0 \
- errMsg "can't handle image type '$mime_type'"]
- }
+ } else {
+ set width 0
+ set height 0
+ set success 1
}
-
#
# Create a new item without child_rels
#
- set name $object_id-[clock clicks -microseconds]$ext
+ set name $object_id-[clock clicks -microseconds]
set item_id [::xo::db::sql::content_item new \
-name $name \
-parent_id [require_root_folder] \
@@ -105,8 +109,7 @@
return [list \
success $success \
name $name \
- image_id $revision_id \
- image_url $image_url?image_id=$revision_id \
+ file_id $revision_id \
width $width \
height $height \
]
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.3 -r1.4
--- openacs-4/packages/richtext-ckeditor4/tcl/richtext-procs.tcl 16 Aug 2017 13:10:20 -0000 1.3
+++ openacs-4/packages/richtext-ckeditor4/tcl/richtext-procs.tcl 19 Aug 2017 13:22:34 -0000 1.4
@@ -17,10 +17,10 @@
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"
+ # 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 \
@@ -45,7 +45,7 @@
set ck_package [parameter::get \
-package_id $package_id \
-parameter CKEditorPackage \
- -default "standard"]
+ -default "standard"]
ad_proc initialize_widget {
-form_id
@@ -96,15 +96,27 @@
break
}
}
- set upload_url [export_vars \
- -base $::richtext::ckeditor4::ckfinder_url/upload {
- {object_id $displayed_object_id} {type Images}
- }]
+ set image_upload_url [export_vars \
+ -base $::richtext::ckeditor4::ckfinder_url/uploadimage {
+ {object_id $displayed_object_id} {type Images}
+ }]
+ set file_upload_url [export_vars \
+ -base $::richtext::ckeditor4::ckfinder_url/upload {
+ {object_id $displayed_object_id} {type Files} {command QuickUpload}
+ }]
+ set file_browse_url [export_vars \
+ -base $::richtext::ckeditor4::ckfinder_url/browse {
+ {object_id $displayed_object_id} {type Files}
+ }]
lappend ckOptionsList \
"language: '[lang::conn::language]'" \
"disableNativeSpellChecker: false" \
"scayt_autoStartup: [dict get $options spellcheck]" \
- "imageUploadUrl: '$upload_url'"
+ "imageUploadUrl: '$image_upload_url'" \
+ "filebrowserBrowseUrl: '$file_browse_url'" \
+ "filebrowserUploadUrl: '$file_upload_url'" \
+ "filebrowserWindowWidth: '800'" \
+ "filebrowserWindowHeight: '600'"
set plugins [split $::richtext::ckeditor4::standard_plugins ,]
if {[dict exists $options plugins]} {
@@ -192,8 +204,6 @@
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