61 public $toolbarstartexpanded;
81 public $uselocalbrowser;
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())
119 dol_syslog(get_class($this).
"::DolEditor htmlname=".$htmlname.
" width=".$width.
" height=".$height.
" toolbarname=".$toolbarname.
" uselocalbrowser=".$uselocalbrowser);
121 if ($uselocalbrowser === -1) {
123 $uselocalbrowser =
getDolGlobalInt(
"WYSIWYG_ALLOW_UPLOAD_MEDIA_FILES");
127 $rows = round($height / 20);
130 $cols = ($width ? round($width / 6) : 80);
132 $shorttoolbarname = preg_replace(
'/_encoded$/',
'', $toolbarname);
135 $defaulteditor =
'ckeditor';
137 $this->uselocalbrowser = $uselocalbrowser;
138 $this->readonly = $readonly;
141 if ((!
isModEnabled(
'fckeditor') && $okforextendededitor !==
'ace') || empty($okforextendededitor)) {
142 $this->tool =
'textarea';
144 if ($okforextendededitor ===
'ace') {
148 if (empty($conf->use_javascript_ajax)) {
149 $this->tool =
'textarea';
152 if (isset($poscursor[
'find'])) {
154 $lines = explode(
"\n", $content);
155 $nblines = count($lines);
156 for ($i = 0 ; $i < $nblines ; $i++) {
157 if (preg_match(
'/'.$poscursor[
'find'].
'/', $lines[$i])) {
163 $poscursor[
'y'] = $posy;
168 if (in_array($this->tool, array(
'textarea',
'ckeditor',
'ace'))) {
172 $this->content = $content;
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));
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'];
203 public function Create($noprint = 0, $morejs =
'', $restrictContent =
true, $titlecontent =
'', $option =
'', $moreparam =
'', $morecss =
'')
206 global $conf, $langs;
211 $extraAllowedContent =
'a[target];';
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-top-left-radius,border-top-right-radius,border-bottom-left-radius,border-bottom-right-radius,box-shadow}';
218 if (is_string($restrictContent)) {
219 $extraAllowedContent = $restrictContent;
221 if (isset($conf->global->FCKEDITOR_ALLOW_ANY_CONTENT)) {
228 $this->content = (string) $this->content;
230 if (in_array($this->tool, array(
'textarea',
'ckeditor'))) {
236 $out .=
'<textarea id="'.$this->htmlname.
'" name="'.$this->htmlname.
'"';
237 $out .=
' rows="'.$this->rows.
'"';
239 $out .= (preg_match(
'/%/', $this->cols) ?
' style="margin-top: 5px; width: '.$this->cols.
'"' :
' cols="'.$this->cols.
'"');
240 $out .=
' '.($moreparam ? $moreparam :
'');
241 $out .=
' class="flat '.dol_string_nohtmltag($this->toolbarname).
' '.$morecss.
'">';
242 $out .= htmlspecialchars($this->content);
243 $out .=
'</textarea>';
245 if ($this->tool ==
'ckeditor' && !empty($conf->use_javascript_ajax) &&
isModEnabled(
'fckeditor')) {
246 if (!defined(
'REQUIRE_CKEDITOR')) {
247 define(
'REQUIRE_CKEDITOR',
'1');
252 $pluginstodisable =
'elementspath,save,flash,div,anchor';
254 $pluginstodisable .=
',specialchar';
256 if (!empty($conf->dol_optimize_smallscreen)) {
257 $pluginstodisable .=
',scayt,wsc,find,undo';
260 $pluginstodisable .=
',wsc';
263 $pluginstodisable .=
',exportpdf';
266 $this->uselocalbrowser = 0;
268 $scaytautostartup =
'';
270 $scaytautostartup =
'scayt_autoStartup: true,';
271 $scaytautostartup .=
'scayt_sLang: \''.dol_escape_js($langs->getDefaultLang()).
'\',
';
273 $pluginstodisable .= ',scayt
';
276 $htmlencode_force = preg_match('/_encoded$/
', $this->toolbarname) ? 'true' : 'false';
278 $out .= '<!-- Output ckeditor disallowAnyContent=
'.dol_escape_htmltag((string) $restrictContent).' toolbarname=
'.dol_escape_htmltag($this->toolbarname).' -->
'."\n";
279 //$out .= '<style>#cke_1_top { height: 34px !important; }</style>
';
280 $out .= '<script nonce=
"'.getNonce().'" type=
"text/javascript">
281 $(document).ready(
function () {
285 tmpeditor = CKEDITOR.replace(\
''.
dol_escape_js($this->htmlname).
'\',
288 customConfig: ckeditorConfig,
289 removePlugins: \
''.dol_escape_js($pluginstodisable).
'\',
291 readOnly:
'.($this->readonly ? 'true' : 'false').',
292 htmlEncodeOutput:
'.dol_escape_js($htmlencode_force).',
293 allowedContent:
'.($restrictContent ? 'false' : 'true').',
294 extraAllowedContent: \
''.dol_escape_js($extraAllowedContent).
'\',
295 disallowedContent: \
'\',
296 fullPage:
'.($fullpage ? 'true' : 'false').',
297 toolbar: \
''.dol_escape_js($this->toolbarname).
'\',
298 toolbarStartupExpanded:
'.($this->toolbarstartexpanded ? 'true' : 'false').',
299 width:
'.($this->width ? '\
''.dol_escape_js($this->width).
'\'' :
'\'\
'').
',
302 '.$scaytautostartup.'
303 language: \
''.dol_escape_js($langs->defaultlang).
'\',
304 textDirection: \
''.dol_escape_js($langs->trans(
"DIRECTION")).
'\',
306 instanceReady :
function(ev) {
307 console.log(\
'ckeditor '.
dol_escape_js($this->htmlname).
' instanceReady\');
309 /* If we found the attribute required on source div, we remove it (not compatible with ckeditor) */
310 /* Disabled, because attribute "required" should never be used on fields for doleditor */
311 /* jQuery("#'.
dol_escape_js($this->htmlname).
'").attr("required", false); */
313 // Output paragraphs as <p>Text</p>.
314 this.dataProcessor.writer.setRules( \'p\', {
316 breakBeforeOpen : true,
317 breakAfterOpen : false,
318 breakBeforeClose : false,
319 breakAfterClose : true
323 disableNativeSpellChecker: '.(
getDolGlobalString(
'CKEDITOR_NATIVE_SPELLCHECKER') ?
'false' :
'true');
325 if ($this->uselocalbrowser) {
329 $out .=
' filebrowserBrowseUrl : ckeditorFilebrowserBrowseUrl,';
330 $out .=
' filebrowserImageBrowseUrl : ckeditorFilebrowserImageBrowseUrl,';
342 $out .=
' filebrowserWindowWidth : \'900\',
343 filebrowserWindowHeight : \'500\',
344 filebrowserImageWindowWidth : \'900\',
345 filebrowserImageWindowHeight : \'500\'';
347 $out .=
' })'.$morejs;
351 $out .=
'</script>'.
"\n";
357 if (preg_match(
'/^ace/', $this->tool)) {
364 $out .=
'<div class="aceeditorstatusbar" id="statusBar'.$this->htmlname.
'">'.$titlecontent;
365 $out .=
' - <span id="morelines" class="right classlink cursorpointer morelines'.$this->htmlname.
'">'.
dol_escape_htmltag($langs->trans(
"ShowMoreLines")).
'</span> ';
367 $out .=
'<script nonce="'.getNonce().
'" type="text/javascript">'.
"\n";
368 $out .=
'jQuery(document).ready(function() {'.
"\n";
369 $out .=
' var aceEditor = window.ace.edit("'.dol_escape_all($this->htmlname).
'aceeditorid");
370 aceEditor.moveCursorTo('.($this->posy + 1).
','.$this->posx.
');
371 aceEditor.gotoLine('.($this->posy + 1).
','.$this->posx.
');
372 var StatusBar = window.ace.require("ace/ext/statusbar").StatusBar; // Init status bar. Need lib ext-statusbar
373 var statusBar = new StatusBar(aceEditor, document.getElementById("statusBar'.
dol_escape_all($this->htmlname).
'")); // Init status bar. Need lib ext-statusbar
375 var oldNbOfLines = 0;
376 jQuery(".morelines'.
dol_escape_all($this->htmlname).
'").click(function() {
377 var aceEditorClicked = window.ace.edit("'.$this->htmlname.
'aceeditorid");
378 currentline = aceEditorClicked.getOption("maxLines");
379 if (oldNbOfLines == 0)
381 oldNbOfLines = currentline;
383 console.log("We click on more lines, oldNbOfLines is "+oldNbOfLines+", we have currently "+currentline);
384 if (currentline < 500)
386 aceEditorClicked.setOptions({ maxLines: 500 });
390 aceEditorClicked.setOptions({ maxLines: oldNbOfLines });
394 $out .=
'</script>'.
"\n";
397 $out .=
'<pre id="'.$this->htmlname.
'aceeditorid" style="'.($this->width ?
'width: '.$this->width.
'px; ' :
'');
398 $out .= ($this->height ?
' height: '.$this->height.
'px; ' :
'');
401 $out .= htmlspecialchars($this->content);
403 $out .=
'<input type="hidden" id="'.$this->htmlname.
'_x" name="'.$this->htmlname.
'_x">';
404 $out .=
'<input type="hidden" id="'.$this->htmlname.
'_y" name="'.$this->htmlname.
'_y">';
405 $out .=
'<textarea id="'.$this->htmlname.
'" name="'.$this->htmlname.
'" style="width:0px; height: 0px; display: none;">';
406 $out .= htmlspecialchars($this->content);
407 $out .=
'</textarea>';
409 $out .=
'<script nonce="'.getNonce().
'" type="text/javascript">'.
"\n";
410 $out .=
'var aceEditor = window.ace.edit("'.$this->htmlname.
'aceeditorid");
412 aceEditor.session.setMode("ace/mode/'.$format.
'");
413 aceEditor.setReadOnly('.($this->readonly ?
'true' :
'false').
');
414 aceEditor.setOptions({
415 enableBasicAutocompletion: true, // the editor completes the statement when you hit Ctrl + Space. Need lib ext-language_tools.js
416 enableLiveAutocompletion: false, // the editor completes the statement while you are typing. Need lib ext-language_tools.js
417 //enableSnippets: true, // ???
418 showPrintMargin: false, // hides the vertical limiting strip
420 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.
421 fontSize: "110%" // ensures that the editor fits in the environment
424 // defines the style of the editor
425 aceEditor.setTheme("ace/theme/chrome");
427 // hides line numbers (widens the area occupied by error and warning messages)
428 //aceEditor.renderer.setOption("showLineNumbers", false);
429 // ensures proper autocomplete, validation and highlighting of JavaScript code
430 //aceEditor.getSession().setMode("ace/mode/javascript_expression");'.
"\n";
433 if ($this->htmlname ==
'PAGE_CONTENT') {
435 // Add custom function in the autocompletion
436 var customCompleter = {
437 getCompletions: function(editor, session, pos, prefix, callback) {
439 { caption: \'dol_escape_all\', value: \'dol_escape_all(string)\', meta: \'custom\' },
440 { caption: \'dol_escape_js\', value: \'dol_escape_js(string)\', meta: \'custom\' },
441 { caption: \'includeContainer\', value: \'includeContainer(alias_of_container_to_include)\', meta: \'custom\' },
442 { caption: \'redirectToContainer\', value: \'redirectToContainer(alias_of_container_to_redirect_to)\', meta: \'custom\' },
443 { caption: \'getImageFromHtmlContent\', value: \'getImageFromHtmlContent(websitepage->htmlcontent)\', meta: \'custom\' },
445 callback(null, wordList.map(function(word) {
447 caption: word.caption,
454 aceEditor.completers = [customCompleter];
458 $out .=
'jQuery(document).ready(function() {';
459 $out .=
' jQuery(".buttonforacesave").click(function() {
460 console.log("We click on button (with class .buttonforacesave) that must fill ace fields for component '.dol_escape_js($this->htmlname).
'");
461 var aceEditor = window.ace.edit("'.
dol_escape_js($this->htmlname).
'aceeditorid");
463 var cursorPos = aceEditor.getCursorPosition();
464 //console.log(cursorPos);
466 jQuery("#'.
dol_escape_js($this->htmlname).
'_x").val(cursorPos.column);
467 jQuery("#'.
dol_escape_js($this->htmlname).
'_y").val(cursorPos.row);
469 //console.log(aceEditor.getSession().getValue());
470 // Inject content of editor into the original HTML field.
471 jQuery("#'.
dol_escape_js($this->htmlname).
'").val(aceEditor.getSession().getValue());
472 /*if (jQuery("#'.
dol_escape_js($this->htmlname).
'").html().length > 0) return true;
476 console.log("Failed to retrieve js object ACE from its name");
481 $out .=
'</script>'.
"\n";
485 $out .=
'Error, unknown value for tool '.$this->tool.
' in DolEditor Create function.';
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)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
if(preg_match('/(crypted|dolcrypt):/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
'integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter[:Sortfield]]]',...