42 public $toolbarstartexpanded;
47 public $uselocalbrowser;
72 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())
76 dol_syslog(get_class($this).
"::DolEditor htmlname=".$htmlname.
" width=".$width.
" height=".$height.
" toolbarname=".$toolbarname);
79 $rows = round($height / 20);
82 $cols = ($width ? round($width / 6) : 80);
84 $shorttoolbarname = preg_replace(
'/_encoded$/',
'', $toolbarname);
87 $defaulteditor =
'ckeditor';
88 $this->tool = !
getDolGlobalString(
'FCKEDITOR_EDITORNAME') ? $defaulteditor : $conf->global->FCKEDITOR_EDITORNAME;
89 $this->uselocalbrowser = $uselocalbrowser;
90 $this->readonly = $readonly;
93 if ((!isModEnabled(
'fckeditor') && $okforextendededitor !==
'ace') || empty($okforextendededitor)) {
94 $this->tool =
'textarea';
96 if ($okforextendededitor ===
'ace') {
100 if (empty($conf->use_javascript_ajax)) {
101 $this->tool =
'textarea';
104 if ( isset($poscursor[
'find']) ) {
106 $lines = explode(
"\n", $content);
107 $nblines = count($lines);
108 for ($i = 0 ; $i < $nblines ; $i++) {
109 if (preg_match(
'/'.$poscursor[
'find'].
'/', $lines[$i])) {
114 if ($posy != 0 ) $poscursor[
'y'] = $posy;
118 if (in_array($this->tool, array(
'textarea',
'ckeditor',
'ace'))) {
122 $this->content = $content;
124 $this->htmlname = $htmlname;
125 $this->toolbarname = $shorttoolbarname;
126 $this->toolbarstartexpanded = $toolbarstartexpanded;
127 $this->rows = max(ROWS_3, $rows);
128 $this->cols = (preg_match(
'/%/', $cols) ? $cols : max(40, $cols));
129 $this->height = $height;
130 $this->width = $width;
131 $this->posx = empty($poscursor[
'x']) ? 0 : $poscursor[
'x'];
132 $this->posy = empty($poscursor[
'y']) ? 0 : $poscursor[
'y'];
150 public function Create($noprint = 0, $morejs =
'', $disallowAnyContent =
true, $titlecontent =
'', $option =
'', $moreparam =
'', $morecss =
'')
153 global $conf, $langs;
156 if (isset($conf->global->FCKEDITOR_ALLOW_ANY_CONTENT)) {
163 $this->content = ($this->content ??
'');
165 if (in_array($this->tool, array(
'textarea',
'ckeditor'))) {
170 $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.
'">';
171 $out .= htmlspecialchars($this->content);
172 $out .=
'</textarea>';
174 if ($this->tool ==
'ckeditor' && !empty($conf->use_javascript_ajax) && isModEnabled(
'fckeditor')) {
175 if (!defined(
'REQUIRE_CKEDITOR')) {
176 define(
'REQUIRE_CKEDITOR',
'1');
181 $pluginstodisable =
'elementspath,save,flash,div,anchor';
183 $pluginstodisable .=
',specialchar';
185 if (!empty($conf->dol_optimize_smallscreen)) {
186 $pluginstodisable .=
',scayt,wsc,find,undo';
189 $pluginstodisable .=
',wsc';
192 $pluginstodisable .=
',exportpdf';
195 $this->uselocalbrowser = 0;
197 $scaytautostartup =
'';
199 $scaytautostartup =
'scayt_autoStartup: true,';
200 $scaytautostartup .=
'scayt_sLang: \''.dol_escape_js($langs->getDefaultLang()).
'\',
';
202 $pluginstodisable .= ',scayt
';
205 $htmlencode_force = preg_match('/_encoded$/
', $this->toolbarname) ? 'true' : 'false';
207 $out .= '<!-- Output ckeditor disallowAnyContent=
'.dol_escape_htmltag($disallowAnyContent).' toolbarname=
'.dol_escape_htmltag($this->toolbarname).' -->
'."\n";
208 $out .= '<script nonce=
"'.getNonce().'" type=
"text/javascript">
209 $(document).ready(
function () {
213 tmpeditor = CKEDITOR.replace(\
''.
dol_escape_js($this->htmlname).
'\',
216 customConfig: ckeditorConfig,
217 removePlugins: \
''.dol_escape_js($pluginstodisable).
'\',
219 readOnly:
'.($this->readonly ? 'true' : 'false').',
220 htmlEncodeOutput:
'.dol_escape_js($htmlencode_force).',
221 allowedContent:
'.($disallowAnyContent ? 'false' : 'true').',
222 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 */
223 disallowedContent: \'\', /* Tags that are not allowed */
224 fullPage: '.($fullpage ?
'true' :
'false').
', /* if true, the html, header and body tags are kept */
226 toolbarStartupExpanded:
'.($this->toolbarstartexpanded ? 'true' : 'false').',
227 width:
'.($this->width ? '\
''.dol_escape_js($this->width).
'\'' :
'\'\
'').
',
230 '.$scaytautostartup.'
231 language: \
''.dol_escape_js($langs->defaultlang).
'\',
232 textDirection: \
''.dol_escape_js($langs->trans(
"DIRECTION")).
'\',
234 instanceReady :
function(ev) {
235 console.log(\
'ckeditor '.
dol_escape_js($this->htmlname).
' instanceReady\');
237 /* If we found the attribute required on source div, we remove it (not compatible with ckeditor) */
238 /* Disabled, because attribute required should never be used on fields for doleditor */
239 /* jQuery("#'.
dol_escape_js($this->htmlname).
'").attr("required", false); */
241 // Output paragraphs as <p>Text</p>.
242 this.dataProcessor.writer.setRules( \'p\', {
244 breakBeforeOpen : true,
245 breakAfterOpen : false,
246 breakBeforeClose : false,
247 breakAfterClose : true
250 /* This is to remove the tab Link on image popup. Does not work, so commented */
251 /* dialogDefinition: function (event) {
252 var dialogName = event.data.name;
253 var dialogDefinition = event.data.definition;
254 if (dialogName == \'image\') {
255 dialogDefinition.removeContents(\'Link\');
259 disableNativeSpellChecker: '.(
getDolGlobalString(
'CKEDITOR_NATIVE_SPELLCHECKER') ?
'false' :
'true');
261 if ($this->uselocalbrowser) {
265 $out .=
' filebrowserBrowseUrl : ckeditorFilebrowserBrowseUrl,';
266 $out .=
' filebrowserImageBrowseUrl : ckeditorFilebrowserImageBrowseUrl,';
278 $out .=
' filebrowserWindowWidth : \'900\',
279 filebrowserWindowHeight : \'500\',
280 filebrowserImageWindowWidth : \'900\',
281 filebrowserImageWindowHeight : \'500\'';
283 $out .=
' })'.$morejs;
287 $out .=
'</script>'.
"\n";
293 if (preg_match(
'/^ace/', $this->tool)) {
297 $out .=
"\n".
'<!-- Output Ace editor -->'.
"\n";
300 $out .=
'<div class="aceeditorstatusbar" id="statusBar'.$this->htmlname.
'">'.$titlecontent;
301 $out .=
' - <span id="morelines" class="right classlink cursorpointer morelines'.$this->htmlname.
'">'.
dol_escape_htmltag($langs->trans(
"ShowMoreLines")).
'</span> ';
303 $out .=
'<script nonce="'.getNonce().
'" type="text/javascript">'.
"\n";
304 $out .=
'jQuery(document).ready(function() {'.
"\n";
305 $out .=
' var aceEditor = window.ace.edit("'.$this->htmlname.
'aceeditorid");
306 aceEditor.moveCursorTo('.($this->posy + 1).
','.$this->posx.
');
307 aceEditor.gotoLine('.($this->posy + 1).
','.$this->posx.
');
308 var StatusBar = window.ace.require("ace/ext/statusbar").StatusBar; // Init status bar. Need lib ext-statusbar
309 var statusBar = new StatusBar(aceEditor, document.getElementById("statusBar'.$this->htmlname.
'")); // Init status bar. Need lib ext-statusbar
311 var oldNbOfLines = 0;
312 jQuery(".morelines'.$this->htmlname.
'").click(function() {
313 var aceEditorClicked = window.ace.edit("'.$this->htmlname.
'aceeditorid");
314 currentline = aceEditorClicked.getOption("maxLines");
315 if (oldNbOfLines == 0)
317 oldNbOfLines = currentline;
319 console.log("We click on more lines, oldNbOfLines is "+oldNbOfLines+", we have currently "+currentline);
320 if (currentline < 500)
322 aceEditorClicked.setOptions({ maxLines: 500 });
326 aceEditorClicked.setOptions({ maxLines: oldNbOfLines });
330 $out .=
'</script>'.
"\n";
333 $out .=
'<pre id="'.$this->htmlname.
'aceeditorid" style="'.($this->width ?
'width: '.$this->width.
'px; ' :
'');
334 $out .= ($this->height ?
' height: '.$this->height.
'px; ' :
'');
337 $out .= htmlspecialchars($this->content);
339 $out .=
'<input type="hidden" id="'.$this->htmlname.
'_x" name="'.$this->htmlname.
'_x">';
340 $out .=
'<input type="hidden" id="'.$this->htmlname.
'_y" name="'.$this->htmlname.
'_y">';
341 $out .=
'<textarea id="'.$this->htmlname.
'" name="'.$this->htmlname.
'" style="width:0px; height: 0px; display: none;">';
342 $out .= htmlspecialchars($this->content);
343 $out .=
'</textarea>';
345 $out .=
'<script nonce="'.getNonce().
'" type="text/javascript">'.
"\n";
346 $out .=
'var aceEditor = window.ace.edit("'.$this->htmlname.
'aceeditorid");
348 aceEditor.session.setMode("ace/mode/'.$format.
'");
349 aceEditor.setOptions({
350 enableBasicAutocompletion: true, // the editor completes the statement when you hit Ctrl + Space. Need lib ext-language_tools.js
351 enableLiveAutocompletion: false, // the editor completes the statement while you are typing. Need lib ext-language_tools.js
352 showPrintMargin: false, // hides the vertical limiting strip
354 maxLines: '.(empty($this->height) ?
'34' : (round($this->height / 10))).
',
355 fontSize: "110%" // ensures that the editor fits in the environment
358 // defines the style of the editor
359 aceEditor.setTheme("ace/theme/chrome");
360 // hides line numbers (widens the area occupied by error and warning messages)
361 //aceEditor.renderer.setOption("showLineNumbers", false);
362 // ensures proper autocomplete, validation and highlighting of JavaScript code
363 //aceEditor.getSession().setMode("ace/mode/javascript_expression");
366 $out .=
'jQuery(document).ready(function() {
367 jQuery(".buttonforacesave").click(function() {
368 console.log("We click on savefile button for component '.dol_escape_js($this->htmlname).
'");
369 var aceEditor = window.ace.edit("'.
dol_escape_js($this->htmlname).
'aceeditorid");
371 var cursorPos = aceEditor.getCursorPosition();
372 //console.log(cursorPos);
374 jQuery("#'.
dol_escape_js($this->htmlname).
'_x").val(cursorPos.column);
375 jQuery("#'.
dol_escape_js($this->htmlname).
'_y").val(cursorPos.row);
377 //console.log(aceEditor.getSession().getValue());
378 // Inject content of editor into the original HTML field.
379 jQuery("#'.
dol_escape_js($this->htmlname).
'").val(aceEditor.getSession().getValue());
380 /*if (jQuery("#'.
dol_escape_js($this->htmlname).
'").html().length > 0) return true;
384 console.log("Failed to retrieve js object ACE from its name");
389 $out .=
'</script>'.
"\n";
393 $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