61 public $toolbarstartexpanded;
81 public $uselocalbrowser;
115 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())
119 dol_syslog(get_class($this).
"::DolEditor htmlname=".$htmlname.
" width=".$width.
" height=".$height.
" toolbarname=".$toolbarname);
122 $rows = round($height / 20);
125 $cols = ($width ? round($width / 6) : 80);
127 $shorttoolbarname = preg_replace(
'/_encoded$/',
'', $toolbarname);
130 $defaulteditor =
'ckeditor';
131 $this->tool = !
getDolGlobalString(
'FCKEDITOR_EDITORNAME') ? $defaulteditor : $conf->global->FCKEDITOR_EDITORNAME;
132 $this->uselocalbrowser = $uselocalbrowser;
133 $this->readonly = $readonly;
136 if ((!isModEnabled(
'fckeditor') && $okforextendededitor !==
'ace') || empty($okforextendededitor)) {
137 $this->tool =
'textarea';
139 if ($okforextendededitor ===
'ace') {
143 if (empty($conf->use_javascript_ajax)) {
144 $this->tool =
'textarea';
147 if (isset($poscursor[
'find'])) {
149 $lines = explode(
"\n", $content);
150 $nblines = count($lines);
151 for ($i = 0 ; $i < $nblines ; $i++) {
152 if (preg_match(
'/'.$poscursor[
'find'].
'/', $lines[$i])) {
158 $poscursor[
'y'] = $posy;
163 if (in_array($this->tool, array(
'textarea',
'ckeditor',
'ace'))) {
167 $this->content = $content;
169 $this->htmlname = $htmlname;
170 $this->toolbarname = $shorttoolbarname;
171 $this->toolbarstartexpanded = $toolbarstartexpanded;
172 $this->rows = max(ROWS_3, $rows);
173 $this->cols = (preg_match(
'/%/', $cols) ? $cols : max(40, $cols));
174 $this->height = $height;
175 $this->width = $width;
176 $this->posx = empty($poscursor[
'x']) ? 0 : $poscursor[
'x'];
177 $this->posy = empty($poscursor[
'y']) ? 0 : $poscursor[
'y'];
195 public function Create($noprint = 0, $morejs =
'', $disallowAnyContent =
true, $titlecontent =
'', $option =
'', $moreparam =
'', $morecss =
'')
198 global $conf, $langs;
201 if (isset($conf->global->FCKEDITOR_ALLOW_ANY_CONTENT)) {
208 if (in_array($this->tool, array(
'textarea',
'ckeditor'))) {
213 $out .=
'<textarea id="'.$this->htmlname.
'" name="'.$this->htmlname.
'"';
214 $out .=
' rows="'.$this->rows.
'"';
216 $out .= (preg_match(
'/%/', $this->cols) ?
' style="margin-top: 5px; width: '.$this->cols.
'"' :
' cols="'.$this->cols.
'"');
217 $out .=
' '.($moreparam ? $moreparam :
'');
218 $out .=
' class="flat '.$morecss.
'">';
219 $out .= htmlspecialchars($this->content);
220 $out .=
'</textarea>';
222 if ($this->tool ==
'ckeditor' && !empty($conf->use_javascript_ajax) && isModEnabled(
'fckeditor')) {
223 if (!defined(
'REQUIRE_CKEDITOR')) {
224 define(
'REQUIRE_CKEDITOR',
'1');
229 $pluginstodisable =
'elementspath,save,flash,div,anchor';
231 $pluginstodisable .=
',specialchar';
233 if (!empty($conf->dol_optimize_smallscreen)) {
234 $pluginstodisable .=
',scayt,wsc,find,undo';
237 $pluginstodisable .=
',wsc';
240 $pluginstodisable .=
',exportpdf';
243 $this->uselocalbrowser = 0;
245 $scaytautostartup =
'';
247 $scaytautostartup =
'scayt_autoStartup: true,';
248 $scaytautostartup .=
'scayt_sLang: \''.dol_escape_js($langs->getDefaultLang()).
'\',
';
250 $pluginstodisable .= ',scayt
';
253 $htmlencode_force = preg_match('/_encoded$/
', $this->toolbarname) ? 'true' : 'false';
255 $out .= '<!-- Output ckeditor disallowAnyContent=
'.dol_escape_htmltag((string) $disallowAnyContent).' toolbarname=
'.dol_escape_htmltag($this->toolbarname).' -->
'."\n";
256 //$out .= '<style>#cke_1_top { height: 34px !important; }</style>
';
257 $out .= '<script nonce=
"'.getNonce().'" type=
"text/javascript">
258 $(document).ready(
function () {
262 tmpeditor = CKEDITOR.replace(\
''.
dol_escape_js($this->htmlname).
'\',
265 customConfig: ckeditorConfig,
266 removePlugins: \
''.dol_escape_js($pluginstodisable).
'\',
268 readOnly:
'.($this->readonly ? 'true' : 'false').',
269 htmlEncodeOutput:
'.dol_escape_js($htmlencode_force).',
270 allowedContent:
'.($disallowAnyContent ? 'false' : 'true').',
271 extraAllowedContent: \
'a[target];section[contenteditable,id];div{float,display}\', /* Allow a tag with attribute target, allow seciont tag and allow the style float and display into div to default other allowed tags */
272 disallowedContent: \'\', /* Tags that are not allowed */
273 fullPage: '.($fullpage ?
'true' :
'false').
', /* if true, the html, header and body tags are kept */
275 toolbarStartupExpanded:
'.($this->toolbarstartexpanded ? 'true' : 'false').',
276 width:
'.($this->width ? '\
''.dol_escape_js($this->width).
'\'' :
'\'\
'').
',
279 '.$scaytautostartup.'
280 language: \
''.dol_escape_js($langs->defaultlang).
'\',
281 textDirection: \
''.dol_escape_js($langs->trans(
"DIRECTION")).
'\',
283 instanceReady :
function(ev) {
284 console.log(\
'ckeditor '.
dol_escape_js($this->htmlname).
' instanceReady\');
286 /* If we found the attribute required on source div, we remove it (not compatible with ckeditor) */
287 /* Disabled, because attribute required should never be used on fields for doleditor */
288 /* jQuery("#'.
dol_escape_js($this->htmlname).
'").attr("required", false); */
290 // Output paragraphs as <p>Text</p>.
291 this.dataProcessor.writer.setRules( \'p\', {
293 breakBeforeOpen : true,
294 breakAfterOpen : false,
295 breakBeforeClose : false,
296 breakAfterClose : true
299 /* This is to remove the tab Link on image popup. Does not work, so commented */
300 /* dialogDefinition: function (event) {
301 var dialogName = event.data.name;
302 var dialogDefinition = event.data.definition;
303 if (dialogName == \'image\') {
304 dialogDefinition.removeContents(\'Link\');
308 disableNativeSpellChecker: '.(
getDolGlobalString(
'CKEDITOR_NATIVE_SPELLCHECKER') ?
'false' :
'true');
310 if ($this->uselocalbrowser) {
314 $out .=
' filebrowserBrowseUrl : ckeditorFilebrowserBrowseUrl,';
315 $out .=
' filebrowserImageBrowseUrl : ckeditorFilebrowserImageBrowseUrl,';
327 $out .=
' filebrowserWindowWidth : \'900\',
328 filebrowserWindowHeight : \'500\',
329 filebrowserImageWindowWidth : \'900\',
330 filebrowserImageWindowHeight : \'500\'';
332 $out .=
' })'.$morejs;
336 $out .=
'</script>'.
"\n";
342 if (preg_match(
'/^ace/', $this->tool)) {
349 $out .=
'<div class="aceeditorstatusbar" id="statusBar'.$this->htmlname.
'">'.$titlecontent;
350 $out .=
' - <span id="morelines" class="right classlink cursorpointer morelines'.$this->htmlname.
'">'.
dol_escape_htmltag($langs->trans(
"ShowMoreLines")).
'</span> ';
352 $out .=
'<script nonce="'.getNonce().
'" type="text/javascript">'.
"\n";
353 $out .=
'jQuery(document).ready(function() {'.
"\n";
354 $out .=
' var aceEditor = window.ace.edit("'.dol_escape_all($this->htmlname).
'aceeditorid");
355 aceEditor.moveCursorTo('.($this->posy + 1).
','.$this->posx.
');
356 aceEditor.gotoLine('.($this->posy + 1).
','.$this->posx.
');
357 var StatusBar = window.ace.require("ace/ext/statusbar").StatusBar; // Init status bar. Need lib ext-statusbar
358 var statusBar = new StatusBar(aceEditor, document.getElementById("statusBar'.
dol_escape_all($this->htmlname).
'")); // Init status bar. Need lib ext-statusbar
360 var oldNbOfLines = 0;
361 jQuery(".morelines'.
dol_escape_all($this->htmlname).
'").click(function() {
362 var aceEditorClicked = window.ace.edit("'.$this->htmlname.
'aceeditorid");
363 currentline = aceEditorClicked.getOption("maxLines");
364 if (oldNbOfLines == 0)
366 oldNbOfLines = currentline;
368 console.log("We click on more lines, oldNbOfLines is "+oldNbOfLines+", we have currently "+currentline);
369 if (currentline < 500)
371 aceEditorClicked.setOptions({ maxLines: 500 });
375 aceEditorClicked.setOptions({ maxLines: oldNbOfLines });
379 $out .=
'</script>'.
"\n";
382 $out .=
'<pre id="'.$this->htmlname.
'aceeditorid" style="'.($this->width ?
'width: '.$this->width.
'px; ' :
'');
383 $out .= ($this->height ?
' height: '.$this->height.
'px; ' :
'');
386 $out .= htmlspecialchars($this->content);
388 $out .=
'<input type="hidden" id="'.$this->htmlname.
'_x" name="'.$this->htmlname.
'_x">';
389 $out .=
'<input type="hidden" id="'.$this->htmlname.
'_y" name="'.$this->htmlname.
'_y">';
390 $out .=
'<textarea id="'.$this->htmlname.
'" name="'.$this->htmlname.
'" style="width:0px; height: 0px; display: none;">';
391 $out .= htmlspecialchars($this->content);
392 $out .=
'</textarea>';
394 $out .=
'<script nonce="'.getNonce().
'" type="text/javascript">'.
"\n";
395 $out .=
'var aceEditor = window.ace.edit("'.$this->htmlname.
'aceeditorid");
397 aceEditor.session.setMode("ace/mode/'.$format.
'");
398 aceEditor.setOptions({
399 enableBasicAutocompletion: true, // the editor completes the statement when you hit Ctrl + Space. Need lib ext-language_tools.js
400 enableLiveAutocompletion: false, // the editor completes the statement while you are typing. Need lib ext-language_tools.js
401 //enableSnippets: true, // ???
402 showPrintMargin: false, // hides the vertical limiting strip
404 maxLines: '.(empty($this->height) ?
'34' : (round($this->height / 10))).
',
405 fontSize: "110%" // ensures that the editor fits in the environment
408 // defines the style of the editor
409 aceEditor.setTheme("ace/theme/chrome");
411 // hides line numbers (widens the area occupied by error and warning messages)
412 //aceEditor.renderer.setOption("showLineNumbers", false);
413 // ensures proper autocomplete, validation and highlighting of JavaScript code
414 //aceEditor.getSession().setMode("ace/mode/javascript_expression");'.
"\n";
417 if ($this->htmlname ==
'PAGE_CONTENT') {
419 // Add custom function in the autocompletion
420 var customCompleter = {
421 getCompletions: function(editor, session, pos, prefix, callback) {
423 { caption: \'dol_escape_all\', value: \'dol_escape_all(string)\', meta: \'custom\' },
424 { caption: \'dol_escape_js\', value: \'dol_escape_js(string)\', meta: \'custom\' },
425 { caption: \'includeContainer\', value: \'includeContainer(alias_of_container_to_include)\', meta: \'custom\' },
426 { caption: \'redirectToContainer\', value: \'redirectToContainer(alias_of_container_to_redirect_to)\', meta: \'custom\' },
427 { caption: \'getImageFromHtmlContent\', value: \'getImageFromHtmlContent(websitepage->htmlcontent)\', meta: \'custom\' },
429 callback(null, wordList.map(function(word) {
431 caption: word.caption,
438 aceEditor.completers = [customCompleter];
442 $out .=
'jQuery(document).ready(function() {';
443 $out .=
' jQuery(".buttonforacesave").click(function() {
444 console.log("We click on savefile button for component '.dol_escape_js($this->htmlname).
'");
445 var aceEditor = window.ace.edit("'.
dol_escape_js($this->htmlname).
'aceeditorid");
447 var cursorPos = aceEditor.getCursorPosition();
448 //console.log(cursorPos);
450 jQuery("#'.
dol_escape_js($this->htmlname).
'_x").val(cursorPos.column);
451 jQuery("#'.
dol_escape_js($this->htmlname).
'_y").val(cursorPos.row);
453 //console.log(aceEditor.getSession().getValue());
454 // Inject content of editor into the original HTML field.
455 jQuery("#'.
dol_escape_js($this->htmlname).
'").val(aceEditor.getSession().getValue());
456 /*if (jQuery("#'.
dol_escape_js($this->htmlname).
'").html().length > 0) return true;
460 console.log("Failed to retrieve js object ACE from its name");
465 $out .=
'</script>'.
"\n";
469 $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_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.
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