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') {
101 if ( isset($poscursor[
'find']) ) {
103 $lines = explode(
"\n", $content);
104 $nblines = count($lines);
105 for ($i = 0 ; $i < $nblines ; $i++) {
106 if (preg_match(
'/'.$poscursor[
'find'].
'/', $lines[$i])) {
111 if ($posy != 0 ) $poscursor[
'y'] = $posy;
115 if (in_array($this->tool, array(
'textarea',
'ckeditor',
'ace'))) {
119 $this->content = $content;
121 $this->htmlname = $htmlname;
122 $this->toolbarname = $shorttoolbarname;
123 $this->toolbarstartexpanded = $toolbarstartexpanded;
124 $this->rows = max(ROWS_3, $rows);
125 $this->cols = (preg_match(
'/%/', $cols) ? $cols : max(40, $cols));
126 $this->height = $height;
127 $this->width = $width;
128 $this->posx = empty($poscursor[
'x']) ? 0 : $poscursor[
'x'];
129 $this->posy = empty($poscursor[
'y']) ? 0 : $poscursor[
'y'];
147 public function Create($noprint = 0, $morejs =
'', $disallowAnyContent =
true, $titlecontent =
'', $option =
'', $moreparam =
'', $morecss =
'')
150 global $conf, $langs;
153 if (isset($conf->global->FCKEDITOR_ALLOW_ANY_CONTENT)) {
160 if (in_array($this->tool, array(
'textarea',
'ckeditor'))) {
165 $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.
'">';
166 $out .= htmlspecialchars($this->content);
167 $out .=
'</textarea>';
169 if ($this->tool ==
'ckeditor' && !empty($conf->use_javascript_ajax) &&
isModEnabled(
'fckeditor')) {
170 if (!defined(
'REQUIRE_CKEDITOR')) {
171 define(
'REQUIRE_CKEDITOR',
'1');
176 $pluginstodisable =
'elementspath,save,flash,div,anchor';
178 $pluginstodisable .=
',specialchar';
180 if (!empty($conf->dol_optimize_smallscreen)) {
181 $pluginstodisable .=
',scayt,wsc,find,undo';
184 $pluginstodisable .=
',wsc';
187 $pluginstodisable .=
',exportpdf';
190 $this->uselocalbrowser = 0;
192 $scaytautostartup =
'';
194 $scaytautostartup =
'scayt_autoStartup: true,';
195 $scaytautostartup .=
'scayt_sLang: \''.dol_escape_js($langs->getDefaultLang()).
'\',
';
197 $pluginstodisable .= ',scayt
';
200 $htmlencode_force = preg_match('/_encoded$/
', $this->toolbarname) ? 'true' : 'false';
202 $out .= '<!-- Output ckeditor $disallowAnyContent=
'.dol_escape_htmltag($disallowAnyContent).' toolbarname=
'.dol_escape_htmltag($this->toolbarname).' -->
'."\n";
203 $out .= '<script nonce=
"'.getNonce().'" type=
"text/javascript">
204 $(document).ready(
function () {
208 tmpeditor = CKEDITOR.replace(\
''.
dol_escape_js($this->htmlname).
'\',
211 customConfig: ckeditorConfig,
212 removePlugins: \
''.dol_escape_js($pluginstodisable).
'\',
214 readOnly:
'.($this->readonly ? 'true' : 'false').',
215 htmlEncodeOutput:
'.dol_escape_js($htmlencode_force).',
216 allowedContent:
'.($disallowAnyContent ? 'false' : 'true').',
217 extraAllowedContent: \
'a[target];div{float,display}\', /* Add the style float and display into div to default other allowed tags */
218 disallowedContent: \'\', /* Tags that are not allowed */
219 fullPage: '.($fullpage ?
'true' :
'false').
', /* if true, the html, header and body tags are kept */
221 toolbarStartupExpanded:
'.($this->toolbarstartexpanded ? 'true' : 'false').',
222 width:
'.($this->width ? '\
''.
dol_escape_js($this->width).
'\'' :
'\'\
'').
',
225 '.$scaytautostartup.'
226 language: \
''.dol_escape_js($langs->defaultlang).
'\',
227 textDirection: \
''.dol_escape_js($langs->trans(
"DIRECTION")).
'\',
229 instanceReady :
function(ev) {
230 console.log(
"ckeditor instanceReady");
232 this.dataProcessor.writer.setRules( \
'p\', {
234 breakBeforeOpen : true,
235 breakAfterOpen : false,
236 breakBeforeClose : false,
237 breakAfterClose : true
240 /* This is to remove the tab Link on image popup. Does not work, so commented */
242 dialogDefinition: function (event) {
243 var dialogName = event.data.name;
244 var dialogDefinition = event.data.definition;
245 if (dialogName == \'image\') {
246 dialogDefinition.removeContents(\'Link\');
251 disableNativeSpellChecker: '.(!
getDolGlobalString(
'CKEDITOR_NATIVE_SPELLCHECKER') ?
'true' :
'false');
253 if ($this->uselocalbrowser) {
257 $out .=
' filebrowserBrowseUrl : ckeditorFilebrowserBrowseUrl,';
258 $out .=
' filebrowserImageBrowseUrl : ckeditorFilebrowserImageBrowseUrl,';
270 $out .=
' filebrowserWindowWidth : \'900\',
271 filebrowserWindowHeight : \'500\',
272 filebrowserImageWindowWidth : \'900\',
273 filebrowserImageWindowHeight : \'500\'';
275 $out .=
' })'.$morejs;
279 $out .=
'</script>'.
"\n";
285 if (preg_match(
'/^ace/', $this->tool)) {
289 $out .=
"\n".
'<!-- Output Ace editor -->'.
"\n";
292 $out .=
'<div class="aceeditorstatusbar" id="statusBar'.$this->htmlname.
'">'.$titlecontent;
293 $out .=
' - <span id="morelines" class="right classlink cursorpointer morelines'.$this->htmlname.
'">'.
dol_escape_htmltag($langs->trans(
"ShowMoreLines")).
'</span> ';
295 $out .=
'<script nonce="'.getNonce().
'" type="text/javascript">'.
"\n";
296 $out .=
'jQuery(document).ready(function() {'.
"\n";
297 $out .=
' var aceEditor = window.ace.edit("'.$this->htmlname.
'aceeditorid");
298 aceEditor.moveCursorTo('.($this->posy + 1).
','.$this->posx.
');
299 aceEditor.gotoLine('.($this->posy + 1).
','.$this->posx.
');
300 var StatusBar = window.ace.require("ace/ext/statusbar").StatusBar; // Init status bar. Need lib ext-statusbar
301 var statusBar = new StatusBar(aceEditor, document.getElementById("statusBar'.$this->htmlname.
'")); // Init status bar. Need lib ext-statusbar
303 var oldNbOfLines = 0;
304 jQuery(".morelines'.$this->htmlname.
'").click(function() {
305 var aceEditorClicked = window.ace.edit("'.$this->htmlname.
'aceeditorid");
306 currentline = aceEditorClicked.getOption("maxLines");
307 if (oldNbOfLines == 0)
309 oldNbOfLines = currentline;
311 console.log("We click on more lines, oldNbOfLines is "+oldNbOfLines+", we have currently "+currentline);
312 if (currentline < 500)
314 aceEditorClicked.setOptions({ maxLines: 500 });
318 aceEditorClicked.setOptions({ maxLines: oldNbOfLines });
322 $out .=
'</script>'.
"\n";
325 $out .=
'<pre id="'.$this->htmlname.
'aceeditorid" style="'.($this->width ?
'width: '.$this->width.
'px; ' :
'');
326 $out .= ($this->height ?
' height: '.$this->height.
'px; ' :
'');
329 $out .= htmlspecialchars($this->content);
331 $out .=
'<input type="hidden" id="'.$this->htmlname.
'_x" name="'.$this->htmlname.
'_x">';
332 $out .=
'<input type="hidden" id="'.$this->htmlname.
'_y" name="'.$this->htmlname.
'_y">';
333 $out .=
'<textarea id="'.$this->htmlname.
'" name="'.$this->htmlname.
'" style="width:0px; height: 0px; display: none;">';
334 $out .= htmlspecialchars($this->content);
335 $out .=
'</textarea>';
337 $out .=
'<script nonce="'.getNonce().
'" type="text/javascript">'.
"\n";
338 $out .=
'var aceEditor = window.ace.edit("'.$this->htmlname.
'aceeditorid");
340 aceEditor.session.setMode("ace/mode/'.$format.
'");
341 aceEditor.setOptions({
342 enableBasicAutocompletion: true, // the editor completes the statement when you hit Ctrl + Space. Need lib ext-language_tools.js
343 enableLiveAutocompletion: false, // the editor completes the statement while you are typing. Need lib ext-language_tools.js
344 showPrintMargin: false, // hides the vertical limiting strip
346 maxLines: '.(empty($this->height) ?
'34' : (round($this->height / 10))).
',
347 fontSize: "110%" // ensures that the editor fits in the environment
350 // defines the style of the editor
351 aceEditor.setTheme("ace/theme/chrome");
352 // hides line numbers (widens the area occupied by error and warning messages)
353 //aceEditor.renderer.setOption("showLineNumbers", false);
354 // ensures proper autocomplete, validation and highlighting of JavaScript code
355 //aceEditor.getSession().setMode("ace/mode/javascript_expression");
358 $out .=
'jQuery(document).ready(function() {
359 jQuery(".buttonforacesave").click(function() {
360 console.log("We click on savefile button for component '.dol_escape_js($this->htmlname).
'");
361 var aceEditor = window.ace.edit("'.
dol_escape_js($this->htmlname).
'aceeditorid");
363 var cursorPos = aceEditor.getCursorPosition();
364 //console.log(cursorPos);
366 jQuery("#'.
dol_escape_js($this->htmlname).
'_x").val(cursorPos.column);
367 jQuery("#'.
dol_escape_js($this->htmlname).
'_y").val(cursorPos.row);
369 //console.log(aceEditor.getSession().getValue());
370 // Inject content of editor into the original HTML field.
371 jQuery("#'.
dol_escape_js($this->htmlname).
'").val(aceEditor.getSession().getValue());
372 /*if (jQuery("#'.
dol_escape_js($this->htmlname).
'").html().length > 0) return true;
376 console.log("Failed to retrieve js object ACE from its name");
381 $out .=
'</script>'.
"\n";
385 $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.
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:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type