dolibarr 25.0.0-alpha
doleditor.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2006-2008 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2021 Gaëtan MAISON <gm@ilad.org>
4 * Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
5 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 * or see https://www.gnu.org/
20 */
21
33{
37 public $tool; // Store the selected tool
38
39 // If using fckeditor
43 public $editor;
44
45 // If not using fckeditor
49 public $content;
53 public $htmlname;
57 public $toolbarname;
61 public $toolbarstartexpanded;
65 public $rows;
69 public $cols;
73 public $height;
77 public $width;
81 public $uselocalbrowser;
85 public $readonly;
89 public $posx;
93 public $posy;
94
95
115 public function __construct($htmlname, $content, $width = '', $height = 200, $toolbarname = 'Basic', $notused = '', $toolbarstartexpanded = false, $uselocalbrowser = -1, $okforextendededitor = true, $rows = 0, $cols = '', $readonly = 0, $poscursor = array()) // @phpstan-ignore constructor.unusedParameter
116 {
117 global $conf;
118
119 dol_syslog(get_class($this)."::DolEditor htmlname=".$htmlname." width=".$width." height=".$height." toolbarname=".$toolbarname." uselocalbrowser=".$uselocalbrowser);
120
121 if ($uselocalbrowser) {
122 // This may not be supported by new generation of WYSIWYG editors.
123 $uselocalbrowser = getDolGlobalInt("WYSIWYG_ALLOW_UPLOAD_MEDIA_FILES");
124 }
125
126 if (!$rows) {
127 $rows = round($height / 20);
128 }
129 if (!$cols) {
130 $cols = ($width ? round($width / 6) : 80);
131 }
132 $shorttoolbarname = preg_replace('/_encoded$/', '', $toolbarname);
133
134 // Name of extended editor to use (FCKEDITOR_EDITORNAME can be 'ckeditor' or 'fckeditor')
135 $defaulteditor = 'ckeditor';
136 $this->tool = getDolGlobalString('FCKEDITOR_EDITORNAME', $defaulteditor);
137 $this->uselocalbrowser = $uselocalbrowser;
138 $this->readonly = $readonly;
139
140 // Check if extended editor is ok. If not we force textarea
141 if ((!isModEnabled('fckeditor') && $okforextendededitor !== 'ace') || empty($okforextendededitor)) {
142 $this->tool = 'textarea';
143 }
144 if ($okforextendededitor === 'ace') {
145 $this->tool = 'ace';
146 }
147 //if ($conf->dol_use_jmobile) $this->tool = 'textarea'; // ckeditor and ace seems ok with mobile
148 if (empty($conf->use_javascript_ajax)) { // If no javascript, we force use of textarea
149 $this->tool = 'textarea';
150 }
151
152 if (isset($poscursor['find'])) {
153 $posy = 0;
154 $lines = explode("\n", $content);
155 $nblines = count($lines);
156 for ($i = 0 ; $i < $nblines ; $i++) {
157 if (preg_match('/'.$poscursor['find'].'/', $lines[$i])) {
158 $posy = $i;
159 break;
160 }
161 }
162 if ($posy != 0) {
163 $poscursor['y'] = $posy;
164 }
165 }
166
167 // Define some properties
168 if (in_array($this->tool, array('textarea', 'ckeditor', 'tinymce', 'ace'))) {
169 if (in_array($this->tool, array('ckeditor', 'tinymce')) && !dol_textishtml($content)) { // We force content to be into HTML if we are using an advanced editor if content is not HTML.
170 $this->content = dol_nl2br($content);
171 } else {
172 $this->content = $content;
173 }
174 $this->htmlname = $htmlname;
175 $this->toolbarname = $shorttoolbarname;
176 $this->toolbarstartexpanded = $toolbarstartexpanded;
177 $this->rows = max(ROWS_3, $rows);
178 $this->cols = (preg_match('/%/', $cols) ? $cols : max(40, $cols)); // If $cols is a percent, we keep it, otherwise, we take max
179 $this->height = $height;
180 $this->width = $width;
181 $this->posx = empty($poscursor['x']) ? 0 : $poscursor['x'];
182 $this->posy = empty($poscursor['y']) ? 0 : $poscursor['y'];
183 }
184 }
185
186 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
203 public function Create($noprint = 0, $morejs = '', $restrictContent = true, $titlecontent = '', $option = '', $moreparam = '', $morecss = '')
204 {
205 // phpcs:enable
206 global $conf, $langs;
207
208 $fullpage = false;
209
210 // syntax is [] for attributes and {} for value inside style
211 $extraAllowedContent = 'a[target]{text-decoration};';
212 $extraAllowedContent .= 'section[contenteditable,id];';
213 $extraAllowedContent .= 'table{border-spacing};';
214 $extraAllowedContent .= 'td{padding};';
215 $extraAllowedContent .= 'p{margin-left,margin-right,margin-top,margin-bottom,padding,line-height};';
216 $extraAllowedContent .= 'div{background-color,color,display,float,height,margin,margin-top,margin-bottom,padding,padding-left,padding-right,padding-top,padding-bottom,width,border-radius,border-top-left-radius,border-top-right-radius,border-bottom-left-radius,border-bottom-right-radius,box-shadow}';
217
218 if (is_string($restrictContent)) {
219 $extraAllowedContent = $restrictContent;
220 }
221 if (isset($conf->global->FCKEDITOR_ALLOW_ANY_CONTENT)) {
222 $restrictContent = !getDolGlobalString('FCKEDITOR_ALLOW_ANY_CONTENT'); // Only predefined list of html tags are allowed or all
223 }
224
225 $found = 0;
226 $out = '';
227
228 $this->content = (string) $this->content; // to avoid htmlspecialchars(): Passing null to parameter #1 ($string) of type string is deprecated
229
230 if (in_array($this->tool, array('textarea', 'ckeditor', 'tinymce'))) {
231 $found = 1;
232
233 $out .= "\n".'<!-- Output textarea '.dol_string_nohtmltag($this->tool).' '.dol_string_nohtmltag($this->htmlname).' toolbarname = '.dol_string_nohtmltag($this->toolbarname).' -->'."\n";
234
235 // Note: We do not put the attribute 'disabled' tag because on a read form, it change style with grey.
236 $out .= '<textarea id="'.$this->htmlname.'" name="'.$this->htmlname.'"';
237 $out .= ' rows="'.$this->rows.'"';
238 if (preg_match('/%/', $this->cols)) { // ->cols is a percent
239 $out .= ' style="margin-top: 5px; width: ';
240 if ($this->tool == 'tinymce') {
241 $out .= $this->cols;
242 } else {
243 $out .= 'calc('.$this->cols.' - 20px)'; // The with in percent minus the margin.
244 }
245 $out .= '"';
246 } else {
247 $out .= ' cols="'.$this->cols.'"';
248 }
249 $out .= ' '.($moreparam ? $moreparam : '');
250 if (!preg_match('/spellcheck=/i', (string) $moreparam)) {
251 $out .= ' spellcheck="true"'; // Free text: enable back the spell checker disabled on the body of the page
252 }
253 $out .= ' class="flat '.dol_string_nohtmltag($this->toolbarname).' '.$morecss.'">';
254 $out .= htmlspecialchars($this->content);
255 $out .= '</textarea>';
256
257 if ($this->tool == 'ckeditor' && !empty($conf->use_javascript_ajax) && isModEnabled('fckeditor')) {
258 if (!defined('REQUIRE_CKEDITOR')) {
259 define('REQUIRE_CKEDITOR', '1');
260 }
261
262 $skin = getDolGlobalString('FCKEDITOR_SKIN', 'moono-lisa'); // default with ckeditor 4.6 : moono-lisa
263
264 $pluginstodisable = 'elementspath,save,flash,div,anchor';
265 if (!getDolGlobalString('FCKEDITOR_ENABLE_SPECIALCHAR')) {
266 $pluginstodisable .= ',specialchar';
267 }
268 if (!empty($conf->dol_optimize_smallscreen)) {
269 $pluginstodisable .= ',scayt,wsc,find,undo';
270 }
271 if (!getDolGlobalString('FCKEDITOR_ENABLE_WSC')) { // spellchecker has end of life december 2021
272 $pluginstodisable .= ',wsc';
273 }
274 if (!getDolGlobalString('FCKEDITOR_ENABLE_PDF')) {
275 $pluginstodisable .= ',exportpdf';
276 }
277 if (getDolGlobalInt('MAIN_DISALLOW_URL_INTO_DESCRIPTIONS') == 2) {
278 $this->uselocalbrowser = 0; // Can't use browser to navigate into files. Only links with "<img src=data:..." are allowed.
279 }
280 $scaytautostartup = '';
281 if (getDolGlobalString('FCKEDITOR_ENABLE_SCAYT_AUTOSTARTUP')) {
282 $scaytautostartup = 'scayt_autoStartup: true,';
283 $scaytautostartup .= 'scayt_sLang: \''.dol_escape_js($langs->getDefaultLang()).'\',';
284 } else {
285 $pluginstodisable .= ',scayt';
286 }
287
288 $htmlencode_force = preg_match('/_encoded$/', $this->toolbarname);
289
290 $out .= '<!-- Output ckeditor disallowAnyContent='.dol_escape_htmltag((string) $restrictContent).' toolbarname='.dol_escape_htmltag($this->toolbarname).' -->'."\n";
291 //$out .= '<style>#cke_1_top { height: 34px !important; }</style>';
292 $out .= '<script nonce="'.getNonce().'" type="text/javascript">
293 $(document).ready(function () {
294 /* console.log("Run ckeditor"); */
295 /* if (CKEDITOR.loadFullCore) CKEDITOR.loadFullCore(); */
296 /* should be editor=CKEDITOR.replace but what if there is several editors ? */
297 tmpeditor = CKEDITOR.replace(\''.dol_escape_js($this->htmlname).'\',
298 {
299 /* property: xxx is same than CKEDITOR.config.property = xxx */
300 customConfig: ckeditorConfig,
301 removePlugins: \''.dol_escape_js($pluginstodisable).'\',
302 versionCheck: false,
303 readOnly: '.($this->readonly ? 'true' : 'false').',
304 htmlEncodeOutput: '.($htmlencode_force ? 'true' : 'false').',
305 allowedContent: '.($restrictContent ? 'false' : 'true').', /* Advanced Content Filter (ACF) is on when allowedContent is false */
306 extraAllowedContent: \''.dol_escape_js($extraAllowedContent).'\', /* Allow a tag with attribute target, allow section tag and allow the style float and display into div to default other allowed tags */
307 disallowedContent: \'\', /* Tags that are not allowed */
308 fullPage: '.($fullpage ? 'true' : 'false').', /* if true, the html, header and body tags are kept */
309 toolbar: \''.dol_escape_js($this->toolbarname).'\',
310 toolbarStartupExpanded: '.($this->toolbarstartexpanded ? 'true' : 'false').',
311 width: '.($this->width ? '\''.dol_escape_js($this->width).'\'' : '\'\'').',
312 height: \''.dol_escape_js((string) $this->height).'\',
313 skin: \''.dol_escape_js($skin).'\',
314 '.$scaytautostartup.'
315 language: \''.dol_escape_js($langs->defaultlang).'\',
316 textDirection: \''.dol_escape_js($langs->trans("DIRECTION")).'\',
317 on : {
318 instanceReady : function(ev) {
319 console.log(\'ckeditor '.dol_escape_js($this->htmlname).' instanceReady\');
320
321 /* If we found the attribute required on source div, we remove it (not compatible with ckeditor) */
322 /* Disabled, because attribute "required" should never be used on fields for doleditor */
323 /* jQuery(\''.dol_escape_js($this->htmlname).'\').attr("required", false); */
324
325 // Output paragraphs as <p>Text</p>.
326 this.dataProcessor.writer.setRules( \'p\', {
327 indent : false,
328 breakBeforeOpen : true,
329 breakAfterOpen : false,
330 breakBeforeClose : false,
331 breakAfterClose : true
332 });
333 },
334 },
335 disableNativeSpellChecker: '.(getDolGlobalString('CKEDITOR_NATIVE_SPELLCHECKER') ? 'false' : 'true');
336
337 if ($this->uselocalbrowser) {
338 $out .= ','."\n";
339 // To use filemanager with old fckeditor (GPL)
340 // Note: ckeditorFilebrowserBrowseUrl and ckeditorFilebrowserImageBrowseUrl are defined in header by main.inc.php. They include url to browser with url of upload connector in parameter
341 $out .= ' filebrowserBrowseUrl : ckeditorFilebrowserBrowseUrl,';
342 $out .= ' filebrowserImageBrowseUrl : ckeditorFilebrowserImageBrowseUrl,';
343 $out .= "\n";
344 $out .= ' filebrowserWindowWidth : \'900\',
345 filebrowserWindowHeight : \'500\',
346 filebrowserImageWindowWidth : \'900\',
347 filebrowserImageWindowHeight : \'500\'';
348 }
349 $out .= ' })'.$morejs; // end CKEditor.replace
350 // Show the CKEditor javascript object once loaded is ready (For debug)
351 //$out .= '; CKEDITOR.on(\'instanceReady\', function(ck) { ck.editor.removeMenuItem(\'maximize\'); ck.editor.removeMenuItem(\'Undo\'); ck.editor.removeMenuItem(\'undo\'); console.log(ck.editor); console.log(ck.editor.toolbar[0]); }); ';
352 $out .= '});'."\n"; // end document.ready
353 $out .= '</script>'."\n";
354 }
355
356 if ($this->tool == 'tinymce' && !empty($conf->use_javascript_ajax) && isModEnabled('fckeditor')) {
357 if (!defined('REQUIRE_TINYMCE')) {
358 define('REQUIRE_TINYMCE', '1');
359 }
360
361 $htmlencode_force = preg_match('/_encoded$/', $this->toolbarname);
362 $pickerenabled = $this->uselocalbrowser ? 'true' : 'false';
363
364 $out .= '<!-- Output tinymce toolbarname='.dol_escape_htmltag($this->toolbarname).' -->'."\n";
365 $out .= '<script nonce="'.getNonce().'" type="text/javascript">'."\n";
366 $out .= '$(document).ready(function () {'."\n";
367 $out .= ' if (typeof tinymce === "undefined") {'."\n";
368 $out .= ' console.error("TinyMCE library not loaded. Check that .../includes/tinymce/tinymce/tinymce.min.js exists and FCKEDITOR_EDITORNAME=tinymce.");'."\n";
369 $out .= ' return;'."\n";
370 $out .= ' }'."\n";
371 $out .= ' var toolbarName = \''.dol_escape_js($this->toolbarname).'\';'."\n";
372 $out .= ' var toolbars = (window.dolTinymceToolbars || {});'."\n";
373 $out .= ' var toolbarStr = toolbars[toolbarName] || toolbars["dolibarr_details"] || "undo redo | bold italic | link | code";'."\n";
374 $out .= ' var pluginsStr = (typeof window.dolTinymcePluginsFor === "function") ? window.dolTinymcePluginsFor(toolbarName) : "advlist autolink lists link image charmap preview anchor searchreplace visualblocks code fullscreen table help wordcount";'."\n";
375 if (!getDolGlobalString('FCKEDITOR_ENABLE_SPECIALCHAR')) {
376 $out .= 'pluginsStr = pluginsStr.replace(\' charmap\', \'\');'."\n";
377 }
378 $out .= ' var tinyLang = \''.dol_escape_js($langs->defaultlang).'\';'."\n";
379 $out .= ' var tinyConf = {'."\n";
380 $out .= ' selector: \'textarea#'.dol_escape_js($this->htmlname).'\','."\n";
381 $out .= ' toolbar: toolbarStr,'."\n";
382 $out .= ' plugins: pluginsStr,'."\n";
383 $out .= ' menubar: false,'."\n";
384 if (!getDolGlobalString('WYSIWYG_TINYMCE_ENABLE_STATUS_BAR')) {
385 $out .= ' statusbar: false,'."\n";
386 }
387 $out .= ' branding: false,'."\n";
388 $out .= ' promotion: false,'."\n";
389 $out .= ' license_key: "gpl",'."\n";
390 $out .= ' readonly: '.($this->readonly ? 'true' : 'false').','."\n";
391 $out .= ' height: '.((int) $this->height + 80).','."\n";
392 if ($this->width) {
393 $out .= ' width: \''.dol_escape_js($this->width).'\','."\n";
394 }
395 $out .= ' directionality: \''.dol_escape_js(strtolower($langs->trans("DIRECTION")) === 'rtl' ? 'rtl' : 'ltr').'\','."\n";
396 $out .= ' forced_root_block: false,'."\n"; // equivalent of CKEDITOR.ENTER_BR
397 $out .= ' convert_urls: false,'."\n";
398 $out .= ' relative_urls: false,'."\n";
399 $out .= ' entity_encoding: "raw",'."\n";
400 $out .= ' protect: [/<\?[\s\S]*?\?>/g],'."\n"; // protect PHP tags like CKEditor did
401 $out .= ' paste_data_images: true,'."\n";
402 $fontlist = 'arial,tahoma,verdana,helvetica';
403 if (getDolGlobalString('THEME_FONT_FAMILY')) {
404 $fontlist = getDolGlobalString('THEME_FONT_FAMILY').', '.$fontlist;
405 }
406
407 $out .= ' content_style: \'p { margin: 6px 0 6px 0; line-height: 1.4em; } .mce-content-body { font-size: 0.94em; margin: 10px; font-family: '.$fontlist.' } \',';
408 $out .= ' toolbar_mode: "sliding",'."\n";
409 $out .= ' browser_spellcheck: '.(getDolGlobalString('CKEDITOR_NATIVE_SPELLCHECKER') ? 'true' : 'false').','."\n";
410 $out .= ' language: (tinyLang && tinyLang.indexOf("en") === 0) ? "en" : tinyLang,'."\n";
411 $out .= ' htmlEncodeOutput: '.($htmlencode_force ? 'true' : 'false').','."\n";
412 if ($pickerenabled === 'true') {
413 $out .= ' file_picker_types: "file image media",'."\n";
414 $out .= ' file_picker_callback: function (cb, value, meta) {'."\n";
415 $out .= ' var url = (meta.filetype === "image") ? window.tinymceFilebrowserImageBrowseUrl : window.tinymceFilebrowserBrowseUrl;'."\n";
416 $out .= ' if (!url) { return; }'."\n";
417 $out .= ' var w = window.open(url, "tinymcePicker", "width=900,height=500");'."\n";
418 $out .= ' window.dolTinymcePickerCb = function (picked) { if (picked) { cb(picked); } if (w) { w.close(); } };'."\n";
419 $out .= ' },'."\n";
420 }
421 $out .= ' setup: function (editor) {'."\n";
422 $out .= ' editor.on("init", function () {'."\n";
423 $out .= ' console.log(\'tinymce '.dol_escape_js($this->htmlname).' instanceReady\');'."\n";
424 $out .= ' });'."\n";
425 $out .= ' }'."\n";
426 $out .= ' };'."\n";
427 $out .= ' tinymce.init(tinyConf)'.$morejs.';'."\n";
428 $out .= '});'."\n";
429 $out .= '</script>'."\n";
430 }
431 }
432
433 // Output editor ACE
434 // Warning: ace.js and ext-statusbar.js must be loaded by the parent page.
435 if (preg_match('/^ace/', $this->tool)) {
436 $found = 1;
437 $format = $option;
438
439 $out .= "\n".'<!-- Output Ace editor '.dol_string_nohtmltag($this->htmlname).' -->'."\n";
440
441 if ($titlecontent) {
442 $out .= '<div class="aceeditorstatusbar" id="statusBar'.$this->htmlname.'">';
443 $out .= '<span class="paddingright">'.$titlecontent.' &nbsp;</span>';
444 $out .= '<span class="morelinescontainer'.$this->htmlname.'" style="display: none"><span id="morelines" class="right classlink cursorpointer morelines'.$this->htmlname.'" title="'.dol_escape_htmltag($langs->trans("ShowMoreLines")).'">'.img_picto('', 'fa-arrows-alt-v', 'class="fa-fw"').'</span> &nbsp; &nbsp; </span>';
445 $out .= '</div>';
446 $out .= '<script nonce="'.getNonce().'" type="text/javascript">'."\n";
447 $out .= 'jQuery(document).ready(function() {'."\n";
448 $out .= ' var aceEditor = window.ace.edit("'.dol_escape_all($this->htmlname).'aceeditorid");
449 aceEditor.moveCursorTo('.($this->posy + 1).','.$this->posx.');
450 aceEditor.gotoLine('.($this->posy + 1).','.$this->posx.');
451 var StatusBar = window.ace.require("ace/ext/statusbar").StatusBar; // Init status bar. Need lib ext-statusbar
452 var statusBar = new StatusBar(aceEditor, document.getElementById("statusBar'.dol_escape_all($this->htmlname).'")); // Init status bar. Need lib ext-statusbar
453
454 var oldNbOfLines = 0;
455
456 // Show the link "Show more/less lines" only if content has more lines than the initial max number of visible lines
457 function updateMoreLinesVisibility() {
458 var initialMaxLines = (oldNbOfLines > 0 ? oldNbOfLines : aceEditor.getOption("maxLines"));
459 jQuery(".morelinescontainer'.dol_escape_all($this->htmlname).'").toggle(aceEditor.session.getLength() > initialMaxLines);
460 }
461 updateMoreLinesVisibility();
462 aceEditor.session.on("change", updateMoreLinesVisibility);
463
464 jQuery(".morelines'.dol_escape_all($this->htmlname).'").click(function() {
465 var aceEditorClicked = window.ace.edit("'.$this->htmlname.'aceeditorid");
466 currentline = aceEditorClicked.getOption("maxLines");
467 if (oldNbOfLines == 0)
468 {
469 oldNbOfLines = currentline;
470 }
471 console.log("We click on more lines, oldNbOfLines is "+oldNbOfLines+", we have currently "+currentline);
472 if (currentline < 500)
473 {
474 aceEditorClicked.setOptions({ maxLines: 500 });
475 }
476 else
477 {
478 aceEditorClicked.setOptions({ maxLines: oldNbOfLines });
479 }
480 });
481 })';
482 $out .= '</script>'."\n";
483 }
484
485 $out .= '<pre id="'.$this->htmlname.'aceeditorid" style="'.($this->width ? 'width: '.$this->width.'px; ' : '');
486 $out .= ($this->height ? ' height: '.$this->height.'px; ' : '');
487 //$out.=" min-height: 100px;";
488 $out .= '">';
489 $out .= htmlspecialchars($this->content);
490 $out .= '</pre>';
491 $out .= '<input type="hidden" id="'.$this->htmlname.'_x" name="'.$this->htmlname.'_x">';
492 $out .= '<input type="hidden" id="'.$this->htmlname.'_y" name="'.$this->htmlname.'_y">';
493 $out .= '<textarea id="'.$this->htmlname.'" name="'.$this->htmlname.'" style="width:0px; height: 0px; display: none;">';
494 $out .= htmlspecialchars($this->content);
495 $out .= '</textarea>';
496
497 $out .= '<script nonce="'.getNonce().'" type="text/javascript">'."\n";
498 $out .= 'var aceEditor = window.ace.edit("'.$this->htmlname.'aceeditorid");
499
500 aceEditor.session.setMode("ace/mode/'.$format.'");
501 aceEditor.setReadOnly('.($this->readonly ? 'true' : 'false').');
502 aceEditor.setOptions({
503 enableBasicAutocompletion: true, // the editor completes the statement when you hit Ctrl + Space. Need lib ext-language_tools.js
504 enableLiveAutocompletion: false, // the editor completes the statement while you are typing. Need lib ext-language_tools.js
505 //enableSnippets: true, // ???
506 showPrintMargin: false, // hides the vertical limiting strip
507 minLines: 10,
508 maxLines: '.(empty($this->height) ? '34' : (round(($this->height - 60) / 19))).', // we remove 60 for the ace toolbar + bottom status line. 19 seems the height in px required for 1 line.
509 fontSize: "110%" // ensures that the editor fits in the environment
510 });
511
512 // defines the style of the editor
513 aceEditor.setTheme("ace/theme/chrome");
514
515 // hides line numbers (widens the area occupied by error and warning messages)
516 //aceEditor.renderer.setOption("showLineNumbers", false);
517 // ensures proper autocomplete, validation and highlighting of JavaScript code
518 //aceEditor.getSession().setMode("ace/mode/javascript_expression");'."\n";
519
520 // If page is PAGE_CONTENT to edit HTML web page in web site module, we add some autocompletion
521 if ($this->htmlname == 'PAGE_CONTENT') {
522 $out .= '
523 // Add custom function in the autocompletion
524 var customCompleter = {
525 getCompletions: function(editor, session, pos, prefix, callback) {
526 var wordList = [
527 { caption: \'dol_escape_all\', value: \'dol_escape_all(string)\', meta: \'custom\' },
528 { caption: \'dol_escape_js\', value: \'dol_escape_js(string)\', meta: \'custom\' },
529 { caption: \'includeContainer\', value: \'includeContainer(alias_of_container_to_include)\', meta: \'custom\' },
530 { caption: \'redirectToContainer\', value: \'redirectToContainer(alias_of_container_to_redirect_to)\', meta: \'custom\' },
531 { caption: \'getImageFromHtmlContent\', value: \'getImageFromHtmlContent(websitepage->htmlcontent)\', meta: \'custom\' },
532 ];
533 callback(null, wordList.map(function(word) {
534 return {
535 caption: word.caption,
536 value: word.value,
537 meta: word.meta
538 };
539 }));
540 }
541 };
542 aceEditor.completers = [customCompleter];
543 '."\n";
544 }
545
546 $out .= 'jQuery(document).ready(function() {';
547 $out .= ' jQuery(".buttonforacesave").click(function() {
548 console.log(\'We click on button (with class .buttonforacesave) that must fill ace fields for component '.dol_escape_js($this->htmlname).'\');
549 var aceEditor = window.ace.edit(\''.dol_escape_js($this->htmlname).'aceeditorid\');
550 if (aceEditor) {
551 var cursorPos = aceEditor.getCursorPosition();
552 //console.log(cursorPos);
553 if (cursorPos) {
554 jQuery(\'#'.dol_escape_js($this->htmlname).'_x\').val(cursorPos.column);
555 jQuery(\'#'.dol_escape_js($this->htmlname).'_y\').val(cursorPos.row);
556 }
557 //console.log(aceEditor.getSession().getValue());
558 // Inject content of editor into the original HTML field.
559 jQuery(\'#'.dol_escape_js($this->htmlname).'\').val(aceEditor.getSession().getValue());
560 /*if (jQuery(\'#'.dol_escape_js($this->htmlname).'\').html().length > 0) return true;
561 else return false;*/
562 return true;
563 } else {
564 console.log("Failed to retrieve js object ACE from its name");
565 return false;
566 }
567 });
568 })';
569 $out .= '</script>'."\n";
570 }
571
572 if (empty($found)) {
573 $out .= 'Error, unknown value for tool '.$this->tool.' in DolEditor Create function.';
574 }
575
576 if ($noprint) {
577 return $out;
578 } else {
579 print $out;
580 }
581 }
582}
$propal type
'integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter[:Sortfield]]]',...
Definition propal.php:281
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
Class to manage a WYSIWYG editor.
Create($noprint=0, $morejs='', $restrictContent=true, $titlecontent='', $option='', $moreparam='', $morecss='')
Output edit area inside the HTML stream.
__construct($htmlname, $content, $width='', $height=200, $toolbarname='Basic', $notused='', $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.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
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.
dol_escape_all($stringtoescape)
Returns text escaped for all protocols (so only alpha chars and numbers)
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
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)
Definition html.lib.php:183