From 44ef6a0a3010770a87006e00d4b2e31343f07846 Mon Sep 17 00:00:00 2001 From: Hadi Nategh Date: Tue, 23 Oct 2018 17:10:33 +0200 Subject: [PATCH] W.I.P. implementing TinyMCE editor and deprecating CKEditor: - Fix CKEditor widget - Fix editor doesn't work if no imageUpload is set --- api/js/etemplate/et2_widget_htmlarea.js | 10 ++- api/src/Etemplate/Widget/CkEditor.php | 85 +++++++++++++++++++++++++ api/src/Html/CkEditorConfig.php | 4 +- 3 files changed, 94 insertions(+), 5 deletions(-) create mode 100644 api/src/Etemplate/Widget/CkEditor.php diff --git a/api/js/etemplate/et2_widget_htmlarea.js b/api/js/etemplate/et2_widget_htmlarea.js index 5cf2e7f35c..32a5f56d61 100644 --- a/api/js/etemplate/et2_widget_htmlarea.js +++ b/api/js/etemplate/et2_widget_htmlarea.js @@ -100,17 +100,21 @@ var et2_htmlarea = (function(){ "use strict"; return et2_inputWidget.extend([et2 if(this.mode == 'ascii' || this.editor != null) return; var imageUpload = ''; - if (this.options.imageUpload[0] !== '/' && this.options.imageUpload.substr(0, 4) != 'http') + if (this.options.imageUpload && this.options.imageUpload[0] !== '/' && this.options.imageUpload.substr(0, 4) != 'http') { imageUpload = egw.ajaxUrl("EGroupware\\Api\\Etemplate\\Widget\\Vfs::ajax_htmlarea_upload")+ '&request_id='+this.getInstanceManager().etemplate_exec_id+'&widget_id='+this.options.imageUpload+'&type=htmlarea'; imageUpload = imageUpload.substr(egw.webserverUrl.length+1); } - else + else if (imageUpload) { imageUpload = this.options.imageUpload.substr(egw.webserverUrl.length+1); } - + else + { + imageUpload = egw.ajaxUrl("EGroupware\\Api\\Etemplate\\Widget\\Vfs::ajax_htmlarea_upload")+ + '&request_id='+this.getInstanceManager().etemplate_exec_id+'&type=htmlarea'; + } // default settings for initialization var settings = { target: this.htmlNode[0], diff --git a/api/src/Etemplate/Widget/CkEditor.php b/api/src/Etemplate/Widget/CkEditor.php new file mode 100644 index 0000000000..6a81b1b8b1 --- /dev/null +++ b/api/src/Etemplate/Widget/CkEditor.php @@ -0,0 +1,85 @@ + + * @copyright 2002-16 by RalfBecker@outdoor-training.de + * @version $Id$ + */ + +namespace EGroupware\Api\Etemplate\Widget; + +use EGroupware\Api\Etemplate; +use EGroupware\Api; + +/** + * eTemplate ckeditor widget + */ +class CkEditor extends Etemplate\Widget +{ + + protected $legacy_options = 'mode,height,width,expand_toolbar,base_href'; + + public $attrs = array( + 'height' => '400px', + ); + + /** + * Fill config options + * + * @param string $cname + */ + public function beforeSendToClient($cname) + { + $form_name = self::form_name($cname, $this->id); + + $config = Api\Html\CkEditorConfig::get_ckeditor_config_array($this->attrs['mode'], $this->attrs['height'], + $this->attrs['expand_toolbar'],$this->attrs['base_href'] + ); + // User preferences + $font = $GLOBALS['egw_info']['user']['preferences']['common']['rte_font']; + $font_size = Api\Html\CkEditorConfig::font_size_from_prefs(); + $font_span = ''; + if (empty($font) && empty($font_size)) $font_span = ''; + if($font_span) + { + $config['preference_style'] = $font_span; + } + self::$request->modifications[$form_name]['config'] = $config; + } + + /** + * Validate input + * + * Input is run throught HTMLpurifier, to make sure users can NOT enter javascript or other nasty stuff (XSS!). + * + * @param string $cname current namespace + * @param array $expand values for keys 'c', 'row', 'c_', 'row_', 'cont' + * @param array $content + * @param array &$validated=array() validated content + * @return boolean true if no validation error, false otherwise + */ + public function validate($cname, array $expand, array $content, &$validated=array()) + { + $form_name = self::form_name($cname, $this->id, $expand); + + if (!$this->is_readonly($cname, $form_name)) + { + $value = self::get_array($content, $form_name); + // only purify for html, mode "ascii" is NO html and content get lost! + if ($this->attrs['mode'] != 'ascii') + { + $value = Api\Html\HtmLawed::purify($value, $this->attrs['validation_rules']); + } + $valid =& self::get_array($validated, $form_name, true); + if (true) $valid = $value; + } + } +} +Etemplate\Widget::registerWidget(__NAMESPACE__.'\\CkEditor', 'ckeditor'); diff --git a/api/src/Html/CkEditorConfig.php b/api/src/Html/CkEditorConfig.php index b157b2680b..bad609570a 100644 --- a/api/src/Html/CkEditorConfig.php +++ b/api/src/Html/CkEditorConfig.php @@ -522,14 +522,14 @@ class CkEditorConfig * It helps to get CKEditor Browse server button to open VfsSelect widget * in client side. * @todo Once the ckeditor allows to overrride the Browse Server button handler - * we should remove this function and handle everything in htmlarea widget in + * we should remove this function and handle everything in ckeditor widget in * client side. */ public function vfsSelectHelper() { $tmp = new \EGroupware\Api\Etemplate('api.vfsSelectUI'); $response = \EGroupware\Api\Json\Response::get(); - $response->call('window.opener.et2_htmlarea.buildVfsSelectForCKEditor', + $response->call('window.opener.et2_ckeditor.buildVfsSelectForCKEditor', array('funcNum' => $_GET['CKEditorFuncNum'])); $response->call('window.close'); $tmp->exec('',array());