40 public $toolbarstartexpanded;
67 public function __construct($htmlname, $content, $width =
'', $height = 200, $toolbarname =
'Basic', $toolbarlocation =
'In', $toolbarstartexpanded =
false, $uselocalbrowser =
true, $okforextendededitor =
true, $rows = 0, $cols = 0, $readonly = 0)
71 dol_syslog(get_class($this).
"::DolEditor htmlname=".$htmlname.
" width=".$width.
" height=".$height.
" toolbarname=".$toolbarname);
73 if (!$rows) $rows = round($height / 20);
74 if (!$cols) $cols = ($width ?round($width / 6) : 80);
75 $shorttoolbarname = preg_replace(
'/_encoded$/',
'', $toolbarname);
78 $defaulteditor =
'ckeditor';
79 $this->tool = empty($conf->global->FCKEDITOR_EDITORNAME) ? $defaulteditor : $conf->global->FCKEDITOR_EDITORNAME;
80 $this->uselocalbrowser = $uselocalbrowser;
81 $this->readonly = $readonly;
84 if ((empty($conf->fckeditor->enabled) && $okforextendededitor !=
'ace') || empty($okforextendededitor)) $this->tool =
'textarea';
85 if ($okforextendededitor ===
'ace') $this->tool =
'ace';
89 if (in_array($this->tool, array(
'textarea',
'ckeditor',
'ace')))
95 $this->content = $content;
97 $this->htmlname = $htmlname;
98 $this->toolbarname = $shorttoolbarname;
99 $this->toolbarstartexpanded = $toolbarstartexpanded;
100 $this->rows = max(ROWS_3, $rows);
101 $this->cols = (preg_match(
'/%/', $cols) ? $cols : max(40, $cols));
102 $this->height = $height;
103 $this->width = $width;
119 public function Create($noprint = 0, $morejs =
'', $disallowAnyContent =
true, $titlecontent =
'', $option =
'')
122 global $conf, $langs;
125 if (isset($conf->global->FCKEDITOR_ALLOW_ANY_CONTENT))
127 $disallowAnyContent = empty($conf->global->FCKEDITOR_ALLOW_ANY_CONTENT);
133 if (in_array($this->tool, array(
'textarea',
'ckeditor')))
139 $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.
'"').
' class="flat">';
140 $out .= htmlspecialchars($this->content);
141 $out .=
'</textarea>';
143 if ($this->tool ==
'ckeditor' && !empty($conf->use_javascript_ajax) && !empty($conf->fckeditor->enabled))
145 if (!defined(
'REQUIRE_CKEDITOR')) define(
'REQUIRE_CKEDITOR',
'1');
147 if (!empty($conf->global->FCKEDITOR_SKIN)) {
148 $skin = $conf->global->FCKEDITOR_SKIN;
150 $skin =
'moono-lisa';
153 $htmlencode_force = preg_match(
'/_encoded$/', $this->toolbarname) ?
'true' :
'false';
155 $out .=
'<!-- Output ckeditor $disallowAnyContent='.$disallowAnyContent.
' toolbarname='.$this->toolbarname.
' -->'.
"\n";
156 $out .=
'<script type="text/javascript">
157 $(document).ready(function () {
158 /* console.log("Run ckeditor"); */
159 /* if (CKEDITOR.loadFullCore) CKEDITOR.loadFullCore(); */
160 /* should be editor=CKEDITOR.replace but what if serveral editors ? */
161 CKEDITOR.replace(\''.$this->htmlname.
'\',
164 customConfig : ckeditorConfig,
165 readOnly :
'.($this->readonly ? 'true' : 'false').',
166 htmlEncodeOutput :
'.$htmlencode_force.',
167 allowedContent :
'.($disallowAnyContent ? 'false' : 'true').',
168 extraAllowedContent : \
'\',
169 fullPage :
'.($fullpage ? 'true' : 'false').',
170 toolbar: \
''.$this->toolbarname.
'\',
171 toolbarStartupExpanded:
'.($this->toolbarstartexpanded ? 'true' : 'false').',
172 width:
'.($this->width ? '\
''.$this->width.
'\'' :
'\'\
'').
',
173 height: '.$this->height.
',
175 language: \
''.$langs->defaultlang.
'\',
176 textDirection: \
''.$langs->trans(
"DIRECTION").
'\',
179 instanceReady :
function( ev )
182 this.dataProcessor.writer.setRules( \
'p\',
185 breakBeforeOpen : true,
186 breakAfterOpen : false,
187 breakBeforeClose : false,
188 breakAfterClose : true
192 disableNativeSpellChecker: '.(empty($conf->global->CKEDITOR_NATIVE_SPELLCHECKER) ?
'true' :
'false');
194 if ($this->uselocalbrowser)
198 $out .=
' filebrowserBrowseUrl : ckeditorFilebrowserBrowseUrl,';
199 $out .=
' filebrowserImageBrowseUrl : ckeditorFilebrowserImageBrowseUrl,';
211 $out .=
' filebrowserWindowWidth : \'900\',
212 filebrowserWindowHeight : \'500\',
213 filebrowserImageWindowWidth : \'900\',
214 filebrowserImageWindowHeight : \'500\'';
216 $out .=
' })'.$morejs;
218 $out .=
'</script>'.
"\n";
224 if (preg_match(
'/^ace/', $this->tool))
229 $out .=
"\n".
'<!-- Output Ace editor -->'.
"\n";
233 $out .=
'<div class="aceeditorstatusbar" id="statusBar'.$this->htmlname.
'">'.$titlecontent;
234 $out .=
' - <a id="morelines" href="#" class="right morelines'.$this->htmlname.
' reposition">'.
dol_escape_htmltag($langs->trans(
"ShowMoreLines")).
'</a> ';
236 $out .=
'<script type="text/javascript" language="javascript">'.
"\n";
237 $out .=
'jQuery(document).ready(function() {'.
"\n";
238 $out .=
' var aceEditor = window.ace.edit("'.$this->htmlname.
'aceeditorid");
239 var StatusBar = window.ace.require("ace/ext/statusbar").StatusBar; // Init status bar. Need lib ext-statusbar
240 var statusBar = new StatusBar(aceEditor, document.getElementById("statusBar'.$this->htmlname.
'")); // Init status bar. Need lib ext-statusbar
242 jQuery(".morelines'.$this->htmlname.
'").click(function() {
243 var aceEditorClicked = window.ace.edit("'.$this->htmlname.
'aceeditorid");
244 currentline = aceEditorClicked.getOption("maxLines");
245 if (oldNbOfLines == 0)
247 oldNbOfLines = currentline;
249 console.log("We click on more lines, oldNbOfLines is "+oldNbOfLines+", we have currently "+currentline);
250 if (currentline < 500)
252 aceEditorClicked.setOptions({ maxLines: 500 });
256 aceEditorClicked.setOptions({ maxLines: oldNbOfLines });
260 $out .=
'</script>'.
"\n";
263 $out .=
'<pre id="'.$this->htmlname.
'aceeditorid" style="'.($this->width ?
'width: '.$this->width.
'px; ' :
'');
264 $out .= ($this->height ?
' height: '.$this->height.
'px; ' :
'');
267 $out .= htmlspecialchars($this->content);
269 $out .=
'<textarea id="'.$this->htmlname.
'" name="'.$this->htmlname.
'" style="width:0px; height: 0px; display: none;">';
270 $out .= htmlspecialchars($this->content);
271 $out .=
'</textarea>';
273 $out .=
'<script type="text/javascript" language="javascript">'.
"\n";
274 $out .=
'var aceEditor = window.ace.edit("'.$this->htmlname.
'aceeditorid");
276 aceEditor.session.setMode("ace/mode/'.$format.
'");
277 aceEditor.setOptions({
278 enableBasicAutocompletion: true, // the editor completes the statement when you hit Ctrl + Space. Need lib ext-language_tools.js
279 enableLiveAutocompletion: false, // the editor completes the statement while you are typing. Need lib ext-language_tools.js
280 showPrintMargin: false, // hides the vertical limiting strip
282 maxLines: '.(empty($this->height) ?
'34' : (round($this->height / 10))).
',
283 fontSize: "110%" // ensures that the editor fits in the environment
286 // defines the style of the editor
287 aceEditor.setTheme("ace/theme/chrome");
288 // hides line numbers (widens the area occupied by error and warning messages)
289 //aceEditor.renderer.setOption("showLineNumbers", false);
290 // ensures proper autocomplete, validation and highlighting of JavaScript code
291 //aceEditor.getSession().setMode("ace/mode/javascript_expression");
294 $out .=
'jQuery(document).ready(function() {
295 jQuery(".buttonforacesave").click(function() {
296 console.log("We click on savefile button for component '.$this->htmlname.
'");
297 var aceEditor = window.ace.edit("'.$this->htmlname.
'aceeditorid")
298 console.log(aceEditor.getSession().getValue());
299 jQuery("#'.$this->htmlname.
'").val(aceEditor.getSession().getValue());
300 /*if (jQuery("#'.$this->htmlname.
'").html().length > 0) return true;
304 $out .=
'</script>'.
"\n";
309 $out .=
'Error, unknown value for tool '.$this->tool.
' in DolEditor Create function.';
312 if ($noprint)
return $out;
__construct($htmlname, $content, $width= '', $height=200, $toolbarname= 'Basic', $toolbarlocation= 'In', $toolbarstartexpanded=false, $uselocalbrowser=true, $okforextendededitor=true, $rows=0, $cols=0, $readonly=0)
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_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
print
Draft customers invoices.
Create($noprint=0, $morejs= '', $disallowAnyContent=true, $titlecontent= '', $option= '')
Output edit area inside the HTML stream.
Class to manage a WYSIWYG editor.
if(!defined('CSRFCHECK_WITH_TOKEN')) define('CSRFCHECK_WITH_TOKEN'
Draft customers invoices.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $keepmoretags= '', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields...
dol_textishtml($msg, $option=0)
Return if a text is a html content.