41 public $toolbarstartexpanded;
46 public $uselocalbrowser;
72 public function __construct($htmlname, $content, $width =
'', $height = 200, $toolbarname =
'Basic', $toolbarlocation =
'In', $toolbarstartexpanded =
false, $uselocalbrowser = 1, $okforextendededitor =
true, $rows = 0, $cols = 0, $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 = empty($conf->global->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') {
102 if (in_array($this->tool, array(
'textarea',
'ckeditor',
'ace'))) {
106 $this->content = $content;
108 $this->htmlname = $htmlname;
109 $this->toolbarname = $shorttoolbarname;
110 $this->toolbarstartexpanded = $toolbarstartexpanded;
111 $this->rows = max(ROWS_3, $rows);
112 $this->cols = (preg_match(
'/%/', $cols) ? $cols : max(40, $cols));
113 $this->height = $height;
114 $this->width = $width;
115 $this->posx = empty($poscursor[
'x']) ? 0 : $poscursor[
'x'];
116 $this->posy = empty($poscursor[
'y']) ? 0 : $poscursor[
'y'];
134 public function Create($noprint = 0, $morejs =
'', $disallowAnyContent =
true, $titlecontent =
'', $option =
'', $moreparam =
'', $morecss =
'')
137 global $conf, $langs;
140 if (isset($conf->global->FCKEDITOR_ALLOW_ANY_CONTENT)) {
141 $disallowAnyContent = empty($conf->global->FCKEDITOR_ALLOW_ANY_CONTENT);
147 if (in_array($this->tool, array(
'textarea',
'ckeditor'))) {
152 $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.
'">';
153 $out .= htmlspecialchars($this->content);
154 $out .=
'</textarea>';
156 if ($this->tool ==
'ckeditor' && !empty($conf->use_javascript_ajax) && isModEnabled(
'fckeditor')) {
157 if (!defined(
'REQUIRE_CKEDITOR')) {
158 define(
'REQUIRE_CKEDITOR',
'1');
163 $pluginstodisable =
'elementspath,save,flash,div,specialchar,anchor';
164 if (!empty($conf->dol_optimize_smallscreen)) {
165 $pluginstodisable .=
',scayt,wsc,find,undo';
167 if (empty($conf->global->FCKEDITOR_ENABLE_WSC)) {
168 $pluginstodisable .=
',wsc';
170 if (empty($conf->global->FCKEDITOR_ENABLE_PDF)) {
171 $pluginstodisable .=
',exportpdf';
173 $scaytautostartup =
'';
174 if (!empty($conf->global->FCKEDITOR_ENABLE_SCAYT_AUTOSTARTUP)) {
175 $scaytautostartup =
'scayt_autoStartup: true,';
176 $scaytautostartup .=
'scayt_sLang: \''.dol_escape_js($langs->getDefaultLang()).
'\',
';
178 $pluginstodisable .= ',scayt
';
181 $htmlencode_force = preg_match('/_encoded$/
', $this->toolbarname) ? 'true' : 'false';
183 $out .= '<!-- Output ckeditor $disallowAnyContent=
'.dol_escape_htmltag($disallowAnyContent).' toolbarname=
'.dol_escape_htmltag($this->toolbarname).' -->
'."\n";
184 $out .= '<script nonce=
"'.getNonce().'" type=
"text/javascript">
185 $(document).ready(
function () {
189 tmpeditor = CKEDITOR.replace(\
''.
dol_escape_js($this->htmlname).
'\',
192 customConfig: ckeditorConfig,
193 removePlugins: \
''.dol_escape_js($pluginstodisable).
'\',
194 readOnly:
'.($this->readonly ? 'true' : 'false').',
195 htmlEncodeOutput:
'.dol_escape_js($htmlencode_force).',
196 allowedContent:
'.($disallowAnyContent ? 'false' : 'true').',
197 extraAllowedContent: \
'a[target];div{float,display}\', /* Add the style float and display into div to default other allowed tags */
198 disallowedContent: '.($disallowAnyContent ?
'\'\
'' :
'\'\
'').
', /* Tags that are not allowed */
199 fullPage: '.($fullpage ?
'true' :
'false').
', /* if true, the html, header and body tags are kept */
201 toolbarStartupExpanded:
'.($this->toolbarstartexpanded ? 'true' : 'false').',
202 width:
'.($this->width ? '\
''.dol_escape_js($this->width).
'\'' :
'\'\
'').
',
205 '.$scaytautostartup.'
206 language: \
''.dol_escape_js($langs->defaultlang).
'\',
207 textDirection: \
''.dol_escape_js($langs->trans(
"DIRECTION")).
'\',
209 instanceReady :
function( ev )
212 this.dataProcessor.writer.setRules( \
'p\', {
214 breakBeforeOpen : true,
215 breakAfterOpen : false,
216 breakBeforeClose : false,
217 breakAfterClose : true
221 disableNativeSpellChecker: '.(empty($conf->global->CKEDITOR_NATIVE_SPELLCHECKER) ?
'true' :
'false');
223 if ($this->uselocalbrowser) {
226 $out .=
' filebrowserBrowseUrl : ckeditorFilebrowserBrowseUrl,';
227 $out .=
' filebrowserImageBrowseUrl : ckeditorFilebrowserImageBrowseUrl,';
239 $out .=
' filebrowserWindowWidth : \'900\',
240 filebrowserWindowHeight : \'500\',
241 filebrowserImageWindowWidth : \'900\',
242 filebrowserImageWindowHeight : \'500\'';
244 $out .=
' })'.$morejs;
248 $out .=
'</script>'.
"\n";
254 if (preg_match(
'/^ace/', $this->tool)) {
258 $out .=
"\n".
'<!-- Output Ace editor -->'.
"\n";
261 $out .=
'<div class="aceeditorstatusbar" id="statusBar'.$this->htmlname.
'">'.$titlecontent;
262 $out .=
' - <a id="morelines" href="#" class="right morelines'.$this->htmlname.
' reposition">'.
dol_escape_htmltag($langs->trans(
"ShowMoreLines")).
'</a> ';
264 $out .=
'<script nonce="'.getNonce().
'" type="text/javascript">'.
"\n";
265 $out .=
'jQuery(document).ready(function() {'.
"\n";
266 $out .=
' var aceEditor = window.ace.edit("'.$this->htmlname.
'aceeditorid");
267 aceEditor.moveCursorTo('.($this->posy+1).
','.$this->posx.
');
268 aceEditor.gotoLine('.($this->posy+1).
','.$this->posx.
');
269 var StatusBar = window.ace.require("ace/ext/statusbar").StatusBar; // Init status bar. Need lib ext-statusbar
270 var statusBar = new StatusBar(aceEditor, document.getElementById("statusBar'.$this->htmlname.
'")); // Init status bar. Need lib ext-statusbar
272 var oldNbOfLines = 0;
273 jQuery(".morelines'.$this->htmlname.
'").click(function() {
274 var aceEditorClicked = window.ace.edit("'.$this->htmlname.
'aceeditorid");
275 currentline = aceEditorClicked.getOption("maxLines");
276 if (oldNbOfLines == 0)
278 oldNbOfLines = currentline;
280 console.log("We click on more lines, oldNbOfLines is "+oldNbOfLines+", we have currently "+currentline);
281 if (currentline < 500)
283 aceEditorClicked.setOptions({ maxLines: 500 });
287 aceEditorClicked.setOptions({ maxLines: oldNbOfLines });
291 $out .=
'</script>'.
"\n";
294 $out .=
'<pre id="'.$this->htmlname.
'aceeditorid" style="'.($this->width ?
'width: '.$this->width.
'px; ' :
'');
295 $out .= ($this->height ?
' height: '.$this->height.
'px; ' :
'');
298 $out .= htmlspecialchars($this->content);
300 $out .=
'<input type="hidden" id="'.$this->htmlname.
'_x" name="'.$this->htmlname.
'_x">';
301 $out .=
'<input type="hidden" id="'.$this->htmlname.
'_y" name="'.$this->htmlname.
'_y">';
302 $out .=
'<textarea id="'.$this->htmlname.
'" name="'.$this->htmlname.
'" style="width:0px; height: 0px; display: none;">';
303 $out .= htmlspecialchars($this->content);
304 $out .=
'</textarea>';
306 $out .=
'<script nonce="'.getNonce().
'" type="text/javascript">'.
"\n";
307 $out .=
'var aceEditor = window.ace.edit("'.$this->htmlname.
'aceeditorid");
309 aceEditor.session.setMode("ace/mode/'.$format.
'");
310 aceEditor.setOptions({
311 enableBasicAutocompletion: true, // the editor completes the statement when you hit Ctrl + Space. Need lib ext-language_tools.js
312 enableLiveAutocompletion: false, // the editor completes the statement while you are typing. Need lib ext-language_tools.js
313 showPrintMargin: false, // hides the vertical limiting strip
315 maxLines: '.(empty($this->height) ?
'34' : (round($this->height / 10))).
',
316 fontSize: "110%" // ensures that the editor fits in the environment
319 // defines the style of the editor
320 aceEditor.setTheme("ace/theme/chrome");
321 // hides line numbers (widens the area occupied by error and warning messages)
322 //aceEditor.renderer.setOption("showLineNumbers", false);
323 // ensures proper autocomplete, validation and highlighting of JavaScript code
324 //aceEditor.getSession().setMode("ace/mode/javascript_expression");
327 $out .=
'jQuery(document).ready(function() {
328 jQuery(".buttonforacesave").click(function() {
329 console.log("We click on savefile button for component '.dol_escape_js($this->htmlname).
'");
330 var aceEditor = window.ace.edit("'.
dol_escape_js($this->htmlname).
'aceeditorid");
332 var cursorPos = aceEditor.getCursorPosition();
333 //console.log(cursorPos);
335 jQuery("#'.
dol_escape_js($this->htmlname).
'_x").val(cursorPos.column);
336 jQuery("#'.
dol_escape_js($this->htmlname).
'_y").val(cursorPos.row);
338 //console.log(aceEditor.getSession().getValue());
339 // Inject content of editor into the original HTML field.
340 jQuery("#'.
dol_escape_js($this->htmlname).
'").val(aceEditor.getSession().getValue());
341 /*if (jQuery("#'.
dol_escape_js($this->htmlname).
'").html().length > 0) return true;
345 console.log("Failed to retrieve js object ACE from its name");
350 $out .=
'</script>'.
"\n";
354 $out .=
'Error, unknown value for tool '.$this->tool.
' in DolEditor Create function.';
Class to manage a WYSIWYG editor.
Create($noprint=0, $morejs='', $disallowAnyContent=true, $titlecontent='', $option='', $moreparam='', $morecss='')
Output edit area inside the HTML stream.
__construct($htmlname, $content, $width='', $height=200, $toolbarname='Basic', $toolbarlocation='In', $toolbarstartexpanded=false, $uselocalbrowser=1, $okforextendededitor=true, $rows=0, $cols=0, $readonly=0, $poscursor=array())
Create an object to build an HTML area to edit a large string content.
dol_nl2br($stringtoencode, $nl2brmode=0, $forxml=false)
Replace CRLF in string with a HTML BR tag.
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