41 public $toolbarstartexpanded;
46 public $uselocalbrowser;
70 public function __construct($htmlname, $content, $width =
'', $height = 200, $toolbarname =
'Basic', $toolbarlocation =
'In', $toolbarstartexpanded =
false, $uselocalbrowser = 1, $okforextendededitor =
true, $rows = 0, $cols =
'', $readonly = 0, $poscursor = array())
74 dol_syslog(get_class($this).
"::DolEditor htmlname=".$htmlname.
" width=".$width.
" height=".$height.
" toolbarname=".$toolbarname);
77 $rows = round($height / 20);
80 $cols = ($width ? round($width / 6) : 80);
82 $shorttoolbarname = preg_replace(
'/_encoded$/',
'', $toolbarname);
85 $defaulteditor =
'ckeditor';
86 $this->tool = !
getDolGlobalString(
'FCKEDITOR_EDITORNAME') ? $defaulteditor : $conf->global->FCKEDITOR_EDITORNAME;
87 $this->uselocalbrowser = $uselocalbrowser;
88 $this->readonly = $readonly;
91 if ((!isModEnabled(
'fckeditor') && $okforextendededitor !=
'ace') || empty($okforextendededitor)) {
92 $this->tool =
'textarea';
94 if ($okforextendededitor ===
'ace') {
100 if (in_array($this->tool, array(
'textarea',
'ckeditor',
'ace'))) {
104 $this->content = $content;
106 $this->htmlname = $htmlname;
107 $this->toolbarname = $shorttoolbarname;
108 $this->toolbarstartexpanded = $toolbarstartexpanded;
109 $this->rows = max(ROWS_3, $rows);
110 $this->cols = (preg_match(
'/%/', $cols) ? $cols : max(40, $cols));
111 $this->height = $height;
112 $this->width = $width;
113 $this->posx = empty($poscursor[
'x']) ? 0 : $poscursor[
'x'];
114 $this->posy = empty($poscursor[
'y']) ? 0 : $poscursor[
'y'];
132 public function Create($noprint = 0, $morejs =
'', $disallowAnyContent =
true, $titlecontent =
'', $option =
'', $moreparam =
'', $morecss =
'')
135 global $conf, $langs;
138 if (isset($conf->global->FCKEDITOR_ALLOW_ANY_CONTENT)) {
145 if (in_array($this->tool, array(
'textarea',
'ckeditor'))) {
150 $out .=
'<textarea id="'.$this->htmlname.
'" name="'.$this->htmlname.
'" rows="'.$this->rows.
'"'.(preg_match(
'/%/', $this->cols) ?
' style="margin-top: 5px; width: '.$this->cols.
'"' :
' cols="'.$this->cols.
'"').
' '.($moreparam ? $moreparam :
'').
' class="flat '.$morecss.
'">';
151 $out .= htmlspecialchars($this->content);
152 $out .=
'</textarea>';
154 if ($this->tool ==
'ckeditor' && !empty($conf->use_javascript_ajax) && isModEnabled(
'fckeditor')) {
155 if (!defined(
'REQUIRE_CKEDITOR')) {
156 define(
'REQUIRE_CKEDITOR',
'1');
161 $pluginstodisable =
'elementspath,save,flash,div,anchor';
163 $pluginstodisable .=
',specialchar';
165 if (!empty($conf->dol_optimize_smallscreen)) {
166 $pluginstodisable .=
',scayt,wsc,find,undo';
169 $pluginstodisable .=
',wsc';
172 $pluginstodisable .=
',exportpdf';
175 $this->uselocalbrowser = 0;
177 $scaytautostartup =
'';
179 $scaytautostartup =
'scayt_autoStartup: true,';
180 $scaytautostartup .=
'scayt_sLang: \''.dol_escape_js($langs->getDefaultLang()).
'\',
';
182 $pluginstodisable .= ',scayt
';
185 $htmlencode_force = preg_match('/_encoded$/
', $this->toolbarname) ? 'true' : 'false';
187 $out .= '<!-- Output ckeditor $disallowAnyContent=
'.dol_escape_htmltag($disallowAnyContent).' toolbarname=
'.dol_escape_htmltag($this->toolbarname).' -->
'."\n";
188 $out .= '<script nonce=
"'.getNonce().'" type=
"text/javascript">
189 $(document).ready(
function () {
193 tmpeditor = CKEDITOR.replace(\
''.
dol_escape_js($this->htmlname).
'\',
196 customConfig: ckeditorConfig,
197 removePlugins: \
''.dol_escape_js($pluginstodisable).
'\',
199 readOnly:
'.($this->readonly ? 'true' : 'false').',
200 htmlEncodeOutput:
'.dol_escape_js($htmlencode_force).',
201 allowedContent:
'.($disallowAnyContent ? 'false' : 'true').',
202 extraAllowedContent: \
'a[target];div{float,display}\', /* Add the style float and display into div to default other allowed tags */
203 disallowedContent: '.($disallowAnyContent ?
'\'\
'' :
'\'\
'').
', /* Tags that are not allowed */
204 fullPage: '.($fullpage ?
'true' :
'false').
', /* if true, the html, header and body tags are kept */
206 toolbarStartupExpanded:
'.($this->toolbarstartexpanded ? 'true' : 'false').',
207 width:
'.($this->width ? '\
''.dol_escape_js($this->width).
'\'' :
'\'\
'').
',
210 '.$scaytautostartup.'
211 language: \
''.dol_escape_js($langs->defaultlang).
'\',
212 textDirection: \
''.dol_escape_js($langs->trans(
"DIRECTION")).
'\',
214 instanceReady :
function(ev) {
215 console.log(
"ckeditor instanceReady");
217 this.dataProcessor.writer.setRules( \
'p\', {
219 breakBeforeOpen : true,
220 breakAfterOpen : false,
221 breakBeforeClose : false,
222 breakAfterClose : true
225 /* This is to remove the tab Link on image popup. Does not work, so commented */
227 dialogDefinition: function (event) {
228 var dialogName = event.data.name;
229 var dialogDefinition = event.data.definition;
230 if (dialogName == \'image\') {
231 dialogDefinition.removeContents(\'Link\');
236 disableNativeSpellChecker: '.(!
getDolGlobalString(
'CKEDITOR_NATIVE_SPELLCHECKER') ?
'true' :
'false');
238 if ($this->uselocalbrowser) {
242 $out .=
' filebrowserBrowseUrl : ckeditorFilebrowserBrowseUrl,';
243 $out .=
' filebrowserImageBrowseUrl : ckeditorFilebrowserImageBrowseUrl,';
255 $out .=
' filebrowserWindowWidth : \'900\',
256 filebrowserWindowHeight : \'500\',
257 filebrowserImageWindowWidth : \'900\',
258 filebrowserImageWindowHeight : \'500\'';
260 $out .=
' })'.$morejs;
264 $out .=
'</script>'.
"\n";
270 if (preg_match(
'/^ace/', $this->tool)) {
274 $out .=
"\n".
'<!-- Output Ace editor -->'.
"\n";
277 $out .=
'<div class="aceeditorstatusbar" id="statusBar'.$this->htmlname.
'">'.$titlecontent;
278 $out .=
' - <span id="morelines" class="right classlink cursorpointer morelines'.$this->htmlname.
'">'.
dol_escape_htmltag($langs->trans(
"ShowMoreLines")).
'</span> ';
280 $out .=
'<script nonce="'.getNonce().
'" type="text/javascript">'.
"\n";
281 $out .=
'jQuery(document).ready(function() {'.
"\n";
282 $out .=
' var aceEditor = window.ace.edit("'.$this->htmlname.
'aceeditorid");
283 aceEditor.moveCursorTo('.($this->posy+1).
','.$this->posx.
');
284 aceEditor.gotoLine('.($this->posy+1).
','.$this->posx.
');
285 var StatusBar = window.ace.require("ace/ext/statusbar").StatusBar; // Init status bar. Need lib ext-statusbar
286 var statusBar = new StatusBar(aceEditor, document.getElementById("statusBar'.$this->htmlname.
'")); // Init status bar. Need lib ext-statusbar
288 var oldNbOfLines = 0;
289 jQuery(".morelines'.$this->htmlname.
'").click(function() {
290 var aceEditorClicked = window.ace.edit("'.$this->htmlname.
'aceeditorid");
291 currentline = aceEditorClicked.getOption("maxLines");
292 if (oldNbOfLines == 0)
294 oldNbOfLines = currentline;
296 console.log("We click on more lines, oldNbOfLines is "+oldNbOfLines+", we have currently "+currentline);
297 if (currentline < 500)
299 aceEditorClicked.setOptions({ maxLines: 500 });
303 aceEditorClicked.setOptions({ maxLines: oldNbOfLines });
307 $out .=
'</script>'.
"\n";
310 $out .=
'<pre id="'.$this->htmlname.
'aceeditorid" style="'.($this->width ?
'width: '.$this->width.
'px; ' :
'');
311 $out .= ($this->height ?
' height: '.$this->height.
'px; ' :
'');
314 $out .= htmlspecialchars($this->content);
316 $out .=
'<input type="hidden" id="'.$this->htmlname.
'_x" name="'.$this->htmlname.
'_x">';
317 $out .=
'<input type="hidden" id="'.$this->htmlname.
'_y" name="'.$this->htmlname.
'_y">';
318 $out .=
'<textarea id="'.$this->htmlname.
'" name="'.$this->htmlname.
'" style="width:0px; height: 0px; display: none;">';
319 $out .= htmlspecialchars($this->content);
320 $out .=
'</textarea>';
322 $out .=
'<script nonce="'.getNonce().
'" type="text/javascript">'.
"\n";
323 $out .=
'var aceEditor = window.ace.edit("'.$this->htmlname.
'aceeditorid");
325 aceEditor.session.setMode("ace/mode/'.$format.
'");
326 aceEditor.setOptions({
327 enableBasicAutocompletion: true, // the editor completes the statement when you hit Ctrl + Space. Need lib ext-language_tools.js
328 enableLiveAutocompletion: false, // the editor completes the statement while you are typing. Need lib ext-language_tools.js
329 showPrintMargin: false, // hides the vertical limiting strip
331 maxLines: '.(empty($this->height) ?
'34' : (round($this->height / 10))).
',
332 fontSize: "110%" // ensures that the editor fits in the environment
335 // defines the style of the editor
336 aceEditor.setTheme("ace/theme/chrome");
337 // hides line numbers (widens the area occupied by error and warning messages)
338 //aceEditor.renderer.setOption("showLineNumbers", false);
339 // ensures proper autocomplete, validation and highlighting of JavaScript code
340 //aceEditor.getSession().setMode("ace/mode/javascript_expression");
343 $out .=
'jQuery(document).ready(function() {
344 jQuery(".buttonforacesave").click(function() {
345 console.log("We click on savefile button for component '.dol_escape_js($this->htmlname).
'");
346 var aceEditor = window.ace.edit("'.
dol_escape_js($this->htmlname).
'aceeditorid");
348 var cursorPos = aceEditor.getCursorPosition();
349 //console.log(cursorPos);
351 jQuery("#'.
dol_escape_js($this->htmlname).
'_x").val(cursorPos.column);
352 jQuery("#'.
dol_escape_js($this->htmlname).
'_y").val(cursorPos.row);
354 //console.log(aceEditor.getSession().getValue());
355 // Inject content of editor into the original HTML field.
356 jQuery("#'.
dol_escape_js($this->htmlname).
'").val(aceEditor.getSession().getValue());
357 /*if (jQuery("#'.
dol_escape_js($this->htmlname).
'").html().length > 0) return true;
361 console.log("Failed to retrieve js object ACE from its name");
366 $out .=
'</script>'.
"\n";
370 $out .=
'Error, unknown value for tool '.$this->tool.
' in DolEditor Create function.';
Class to manage a WYSIWYG editor.
__construct($htmlname, $content, $width='', $height=200, $toolbarname='Basic', $toolbarlocation='In', $toolbarstartexpanded=false, $uselocalbrowser=1, $okforextendededitor=true, $rows=0, $cols='', $readonly=0, $poscursor=array())
Create an object to build an HTML area to edit a large string content.
Create($noprint=0, $morejs='', $disallowAnyContent=true, $titlecontent='', $option='', $moreparam='', $morecss='')
Output edit area inside the HTML stream.
dol_nl2br($stringtoencode, $nl2brmode=0, $forxml=false)
Replace CRLF in string with a HTML BR tag.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_escape_js($stringtoescape, $mode=0, $noescapebackslashn=0)
Returns text escaped for inclusion into javascript code.
dol_textishtml($msg, $option=0)
Return if a text is a html content.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type