2006-07-22 18:09:48 +02:00
< ? php
2008-03-21 01:27:37 +01:00
/* Copyright ( C ) 2006 - 2008 Laurent Destailleur < eldy @ users . sourceforge . net >
2021-04-23 00:45:07 +02:00
* Copyright ( C ) 2021 Gaëtan MAISON < gm @ ilad . org >
2024-03-12 23:15:16 +01:00
* Copyright ( C ) 2024 MDW < mdeweerd @ users . noreply . github . com >
2024-08-14 13:58:17 +02:00
* Copyright ( C ) 2024 Frédéric France < frederic . france @ free . fr >
2006-07-22 18:09:48 +02:00
*
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
2013-01-16 15:36:08 +01:00
* the Free Software Foundation ; either version 3 of the License , or
2006-07-22 18:09:48 +02:00
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
2019-09-23 21:55:30 +02:00
* along with this program . If not , see < https :// www . gnu . org / licenses />.
* or see https :// www . gnu . org /
2006-07-22 18:09:48 +02:00
*/
/**
2011-10-24 09:29:17 +02:00
* \file htdocs / core / class / doleditor . class . php
2010-06-18 21:40:58 +02:00
* \brief Class to manage a WYSIWYG editor
2011-01-31 17:35:55 +01:00
*/
2006-07-22 18:09:48 +02:00
/**
2012-03-12 15:09:46 +01:00
* Class to manage a WYSIWYG editor .
2025-01-17 17:09:47 +01:00
* Usage : $doleditor = new DolEditor ( 'body' , $message , 320 , 'toolbar_mailing' );
2012-03-12 15:09:46 +01:00
* $doleditor -> Create ();
2008-08-07 08:33:35 +02:00
*/
2006-07-22 18:09:48 +02:00
class DolEditor
{
2024-10-26 18:24:40 +02:00
/**
* @ var string
*/
2020-10-31 14:32:18 +01:00
public $tool ; // Store the selected tool
2010-08-27 02:09:58 +02:00
2020-10-31 14:32:18 +01:00
// If using fckeditor
2024-10-26 18:24:40 +02:00
/**
* @ var Object - Note : seems to be unused
*/
2020-10-31 14:32:18 +01:00
public $editor ;
2009-01-31 03:55:32 +01:00
2020-10-31 14:32:18 +01:00
// If not using fckeditor
2024-10-26 18:24:40 +02:00
/**
2025-01-02 10:15:30 +01:00
* @ var ? string
2024-10-26 18:24:40 +02:00
*/
2020-10-31 14:32:18 +01:00
public $content ;
2024-10-26 18:24:40 +02:00
/**
* @ var string
*/
2020-10-31 14:32:18 +01:00
public $htmlname ;
2024-10-26 18:24:40 +02:00
/**
* @ var string
*/
2020-10-31 14:32:18 +01:00
public $toolbarname ;
2024-10-26 18:24:40 +02:00
/**
* @ var bool
*/
2020-10-31 14:32:18 +01:00
public $toolbarstartexpanded ;
2024-10-26 18:24:40 +02:00
/**
* @ var int
*/
2020-10-31 14:32:18 +01:00
public $rows ;
2024-10-26 18:24:40 +02:00
/**
* @ var string
*/
2020-10-31 14:32:18 +01:00
public $cols ;
2024-10-26 18:24:40 +02:00
/**
* @ var int
*/
2020-10-31 14:32:18 +01:00
public $height ;
2024-10-26 18:24:40 +02:00
/**
* @ var string
*/
2020-10-31 14:32:18 +01:00
public $width ;
2024-10-26 18:24:40 +02:00
/**
* @ var int < 0 , 1 >| bool
*/
2023-02-22 21:26:59 +01:00
public $uselocalbrowser ;
2024-10-26 18:24:40 +02:00
/**
* @ var int < 0 , 1 >
*/
2020-10-31 14:32:18 +01:00
public $readonly ;
2024-10-26 18:24:40 +02:00
/**
* @ var int
*/
2022-02-27 14:46:40 +01:00
public $posx ;
2024-10-26 18:24:40 +02:00
/**
* @ var int
*/
2022-02-27 14:46:40 +01:00
public $posy ;
2010-08-27 02:09:58 +02:00
2009-01-31 03:55:32 +01:00
2020-10-31 14:32:18 +01:00
/**
* Create an object to build an HTML area to edit a large string content
*
2024-05-28 23:52:33 +02:00
* @ param string $htmlname HTML name of WYSIWYG field
* @ param string $content Content of WYSIWYG field
* @ param int | string $width Width in pixel of edit area ( auto by default )
* @ param int $height Height in pixel of edit area ( 200 px by default )
2024-12-29 19:45:13 +01:00
* @ param string $toolbarname Name of the toolbar set to use ( 'dolibarr_details[_encoded]' = the less featured , 'dolibarr_notes[_encoded]' for notes content , 'dolibarr_mailings[_encoded]' for emailing content , 'dolibarr_readonly' ) .
2024-05-28 23:52:33 +02:00
* @ param string $toolbarlocation Deprecated . Not used
2024-10-26 18:24:40 +02:00
* @ param bool $toolbarstartexpanded Bar is visible or not at start
2025-01-14 16:57:14 +01:00
* @ param bool | int $uselocalbrowser Enabled to add links to local object with a local media filemanager . - 1 = auto , false = only external images URL can be added into content , or images saved inline with src = " data:... " with a cut / paste .
2024-10-26 18:24:40 +02:00
* @ param bool | int | string $okforextendededitor 1 or True = Allow usage of extended editor tool if qualified ( like ckeditor ) . If 'textarea' , force use of simple textarea . If 'ace' , force use of Ace .
2024-05-28 23:52:33 +02:00
* Warning : If you use 'ace' , don ' t forget to also include ace . js in page header . Also , the button " save " must have class = " buttonforacesave " .
* @ param int $rows Size of rows for textarea tool
* @ param string $cols Size of cols for textarea tool ( textarea number of cols '70' or percent 'x%' )
2024-10-26 18:24:40 +02:00
* @ param int < 0 , 1 > $readonly 0 = Read / Edit , 1 = Read only
* @ param array { x ? : string , y ? : string , find ? : string } $poscursor Array for initial cursor position array ( 'x' => x , 'y' => y ) .
2024-05-28 23:52:33 +02:00
* array ( 'find' => 'word' ) can be used to go to line were the word has been found
2010-06-24 21:00:21 +02:00
*/
2024-12-29 19:45:13 +01:00
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 ())
2020-10-31 14:32:18 +01:00
{
2023-11-24 10:23:21 +01:00
global $conf ;
2009-01-31 03:55:32 +01:00
2024-12-29 19:45:13 +01:00
dol_syslog ( get_class ( $this ) . " ::DolEditor htmlname= " . $htmlname . " width= " . $width . " height= " . $height . " toolbarname= " . $toolbarname . " uselocalbrowser= " . $uselocalbrowser );
if ( $uselocalbrowser === - 1 ) {
// This may not be supported by new generation of WYSIWYG editors.
$uselocalbrowser = getDolGlobalInt ( " WYSIWYG_ALLOW_UPLOAD_MEDIA_FILES " );
}
2009-01-31 03:55:32 +01:00
2021-02-23 22:03:23 +01:00
if ( ! $rows ) {
$rows = round ( $height / 20 );
}
if ( ! $cols ) {
2023-12-04 12:04:36 +01:00
$cols = ( $width ? round ( $width / 6 ) : 80 );
2021-02-23 22:03:23 +01:00
}
2019-12-06 09:26:49 +01:00
$shorttoolbarname = preg_replace ( '/_encoded$/' , '' , $toolbarname );
2011-11-05 21:24:55 +01:00
2020-10-31 14:32:18 +01:00
// Name of extended editor to use (FCKEDITOR_EDITORNAME can be 'ckeditor' or 'fckeditor')
$defaulteditor = 'ckeditor' ;
2023-11-27 11:24:19 +01:00
$this -> tool = ! getDolGlobalString ( 'FCKEDITOR_EDITORNAME' ) ? $defaulteditor : $conf -> global -> FCKEDITOR_EDITORNAME ;
2020-10-31 14:32:18 +01:00
$this -> uselocalbrowser = $uselocalbrowser ;
$this -> readonly = $readonly ;
2009-01-31 03:55:32 +01:00
2020-10-31 14:32:18 +01:00
// Check if extended editor is ok. If not we force textarea
2024-05-28 23:52:33 +02:00
if (( ! isModEnabled ( 'fckeditor' ) && $okforextendededitor !== 'ace' ) || empty ( $okforextendededitor )) {
2021-02-23 22:03:23 +01:00
$this -> tool = 'textarea' ;
}
if ( $okforextendededitor === 'ace' ) {
$this -> tool = 'ace' ;
}
2020-10-31 14:32:18 +01:00
//if ($conf->dol_use_jmobile) $this->tool = 'textarea'; // ckeditor and ace seems ok with mobile
2024-06-22 15:20:11 +02:00
if ( empty ( $conf -> use_javascript_ajax )) { // If no javascript, we force use of textarea
$this -> tool = 'textarea' ;
}
2011-08-15 01:54:09 +02:00
2024-10-26 18:24:40 +02:00
if ( isset ( $poscursor [ 'find' ])) {
2024-05-01 18:04:18 +02:00
$posy = 0 ;
$lines = explode ( " \n " , $content );
$nblines = count ( $lines );
for ( $i = 0 ; $i < $nblines ; $i ++ ) {
if ( preg_match ( '/' . $poscursor [ 'find' ] . '/' , $lines [ $i ])) {
$posy = $i ;
break ;
}
}
2024-10-26 18:24:40 +02:00
if ( $posy != 0 ) {
$poscursor [ 'y' ] = $posy ;
}
2024-05-01 18:04:18 +02:00
}
2020-10-31 14:32:18 +01:00
// Define some properties
2021-02-23 22:03:23 +01:00
if ( in_array ( $this -> tool , array ( 'textarea' , 'ckeditor' , 'ace' ))) {
2020-10-31 18:51:30 +01:00
if ( $this -> tool == 'ckeditor' && ! dol_textishtml ( $content )) { // We force content to be into HTML if we are using an advanced editor if content is not HTML.
2020-10-31 14:32:18 +01:00
$this -> content = dol_nl2br ( $content );
2021-02-23 22:03:23 +01:00
} else {
2020-10-31 14:32:18 +01:00
$this -> content = $content ;
}
$this -> htmlname = $htmlname ;
$this -> toolbarname = $shorttoolbarname ;
$this -> toolbarstartexpanded = $toolbarstartexpanded ;
$this -> rows = max ( ROWS_3 , $rows );
$this -> cols = ( preg_match ( '/%/' , $cols ) ? $cols : max ( 40 , $cols )); // If $cols is a percent, we keep it, otherwise, we take max
2022-02-27 14:46:40 +01:00
$this -> height = $height ;
2020-10-31 14:32:18 +01:00
$this -> width = $width ;
2022-02-27 14:46:40 +01:00
$this -> posx = empty ( $poscursor [ 'x' ]) ? 0 : $poscursor [ 'x' ];
$this -> posy = empty ( $poscursor [ 'y' ]) ? 0 : $poscursor [ 'y' ];
2020-10-31 14:32:18 +01:00
}
}
2006-07-22 18:09:48 +02:00
2020-10-31 14:32:18 +01:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Output edit area inside the HTML stream .
* Output depends on this -> tool ( fckeditor , ckeditor , textarea , ... )
*
2025-01-17 17:09:47 +01:00
* @ param int $noprint 1 = Return HTML string instead of printing it to output
* @ param string $morejs Add more js . For example : " .on( \ 'saveSnapshot \ ', function(e) { alert( \ 'ee \ '); }); " . Used by CKEditor only .
* @ param boolean | string $restrictContent Decide which content is allowed . Used by CKEditor only .
* true = restrict allowed content to a predefined list of allowed elements .
* false = allow anything
* string = true + add values into string
* @ param string $titlecontent Show title content before editor area . Used by ACE editor only .
* @ param string $option For ACE editor , set the source language ( 'html' , 'php' , 'javascript' , 'json' , ... )
* @ param string $moreparam Add extra tags to the textarea
* @ param string $morecss Add extra css to the textarea
2020-10-31 14:32:18 +01:00
* @ return void | string
*/
2025-01-17 17:09:47 +01:00
public function Create ( $noprint = 0 , $morejs = '' , $restrictContent = true , $titlecontent = '' , $option = '' , $moreparam = '' , $morecss = '' )
2020-10-31 14:32:18 +01:00
{
// phpcs:enable
global $conf , $langs ;
2011-01-31 20:28:35 +01:00
2020-10-31 14:32:18 +01:00
$fullpage = false ;
2025-01-17 17:09:47 +01:00
$extraAllowedContent = 'a[target];section[contenteditable,id];div{float,display}' ;
if ( is_string ( $restrictContent )) {
$extraAllowedContent = $restrictContent ;
}
2021-02-23 22:03:23 +01:00
if ( isset ( $conf -> global -> FCKEDITOR_ALLOW_ANY_CONTENT )) {
2025-01-17 17:09:47 +01:00
$restrictContent = ! getDolGlobalString ( 'FCKEDITOR_ALLOW_ANY_CONTENT' ); // Only predefined list of html tags are allowed or all
2020-10-31 14:32:18 +01:00
}
2016-09-15 23:23:10 +02:00
2020-10-31 14:32:18 +01:00
$found = 0 ;
2019-12-06 09:26:49 +01:00
$out = '' ;
2010-08-27 02:09:58 +02:00
2025-01-02 09:54:17 +01:00
$this -> content = ( $this -> content ? ? '' ); // to avoid htmlspecialchars(): Passing null to parameter #1 ($string) of type string is deprecated
2024-12-26 11:38:38 +01:00
2021-02-23 22:03:23 +01:00
if ( in_array ( $this -> tool , array ( 'textarea' , 'ckeditor' ))) {
2020-10-31 14:32:18 +01:00
$found = 1 ;
2025-01-17 17:09:47 +01:00
// Note: We do not put the attribute 'disabled' tag because on a read form, it change style with grey.
2024-10-03 12:35:06 +02:00
$out .= '<textarea id="' . $this -> htmlname . '" name="' . $this -> htmlname . '"' ;
$out .= ' rows="' . $this -> rows . '"' ;
//$out .= ' style="height: 700px; min-height: 700px;"';
$out .= ( preg_match ( '/%/' , $this -> cols ) ? ' style="margin-top: 5px; width: ' . $this -> cols . '"' : ' cols="' . $this -> cols . '"' );
$out .= ' ' . ( $moreparam ? $moreparam : '' );
$out .= ' class="flat ' . $morecss . '">' ;
2025-01-02 09:54:17 +01:00
$out .= htmlspecialchars ( $this -> content );
2020-10-31 14:32:18 +01:00
$out .= '</textarea>' ;
2011-01-31 20:28:35 +01:00
2022-08-31 22:02:31 +02:00
if ( $this -> tool == 'ckeditor' && ! empty ( $conf -> use_javascript_ajax ) && isModEnabled ( 'fckeditor' )) {
2021-02-23 22:03:23 +01:00
if ( ! defined ( 'REQUIRE_CKEDITOR' )) {
define ( 'REQUIRE_CKEDITOR' , '1' );
}
2011-02-01 19:49:31 +01:00
2023-01-09 12:30:56 +01:00
$skin = getDolGlobalString ( 'FCKEDITOR_SKIN' , 'moono-lisa' ); // default with ckeditor 4.6 : moono-lisa
2021-12-13 01:19:48 +01:00
2023-08-08 22:03:58 +02:00
$pluginstodisable = 'elementspath,save,flash,div,anchor' ;
if ( ! getDolGlobalString ( 'FCKEDITOR_ENABLE_SPECIALCHAR' )) {
$pluginstodisable .= ',specialchar' ;
2023-08-09 18:33:43 +02:00
}
2021-12-13 01:19:48 +01:00
if ( ! empty ( $conf -> dol_optimize_smallscreen )) {
$pluginstodisable .= ',scayt,wsc,find,undo' ;
}
2023-11-27 11:24:19 +01:00
if ( ! getDolGlobalString ( 'FCKEDITOR_ENABLE_WSC' )) { // spellchecker has end of life december 2021
2021-12-13 01:19:48 +01:00
$pluginstodisable .= ',wsc' ;
}
2023-11-27 11:24:19 +01:00
if ( ! getDolGlobalString ( 'FCKEDITOR_ENABLE_PDF' )) {
2022-05-16 20:28:00 +02:00
$pluginstodisable .= ',exportpdf' ;
}
2023-12-10 16:19:05 +01:00
if ( getDolGlobalInt ( 'MAIN_DISALLOW_URL_INTO_DESCRIPTIONS' ) == 2 ) {
2023-11-14 01:32:42 +01:00
$this -> uselocalbrowser = 0 ; // Can't use browser to navigate into files. Only links with "<img src=data:..." are allowed.
}
2021-12-13 01:19:48 +01:00
$scaytautostartup = '' ;
2023-11-27 11:24:19 +01:00
if ( getDolGlobalString ( 'FCKEDITOR_ENABLE_SCAYT_AUTOSTARTUP' )) {
2021-04-23 00:45:07 +02:00
$scaytautostartup = 'scayt_autoStartup: true,' ;
2021-12-13 01:19:48 +01:00
$scaytautostartup .= 'scayt_sLang: \'' . dol_escape_js ( $langs -> getDefaultLang ()) . '\',' ;
2021-04-23 00:45:07 +02:00
} else {
2021-12-13 01:19:48 +01:00
$pluginstodisable .= ',scayt' ;
2021-04-23 00:45:07 +02:00
}
2013-03-24 19:00:58 +01:00
2020-10-31 14:32:18 +01:00
$htmlencode_force = preg_match ( '/_encoded$/' , $this -> toolbarname ) ? 'true' : 'false' ;
2011-04-09 17:12:20 +02:00
2025-01-17 17:09:47 +01:00
$out .= '<!-- Output ckeditor disallowAnyContent=' . dol_escape_htmltag (( string ) $restrictContent ) . ' toolbarname=' . dol_escape_htmltag ( $this -> toolbarname ) . ' -->' . " \n " ;
2024-10-03 12:35:06 +02:00
//$out .= '<style>#cke_1_top { height: 34px !important; }</style>';
2023-02-18 15:10:05 +01:00
$out .= '<script nonce="' . getNonce () . ' " type= " text / javascript " >
2012-03-16 16:56:18 +01:00
$ ( document ) . ready ( function () {
2019-12-04 15:55:22 +01:00
/* console.log("Run ckeditor"); */
2011-07-06 14:44:51 +02:00
/* if (CKEDITOR.loadFullCore) CKEDITOR.loadFullCore(); */
2021-12-13 01:19:48 +01:00
/* should be editor=CKEDITOR.replace but what if there is several editors ? */
2023-01-03 17:09:08 +01:00
tmpeditor = CKEDITOR . replace ( \ '' . dol_escape_js ( $this -> htmlname ) . ' \ ' ,
2011-02-01 19:49:31 +01:00
{
2025-01-17 17:09:47 +01:00
/* property: xxx is same than CKEDITOR.config.property = xxx */
2022-05-16 20:28:00 +02:00
customConfig : ckeditorConfig ,
2023-01-03 17:09:08 +01:00
removePlugins : \ '' . dol_escape_js ( $pluginstodisable ) . ' \ ' ,
2023-12-23 10:43:19 +01:00
versionCheck : false ,
2022-05-16 20:28:00 +02:00
readOnly : '.($this->readonly ? ' true ' : ' false ').' ,
2023-01-03 17:09:08 +01:00
htmlEncodeOutput : '.dol_escape_js($htmlencode_force).' ,
2025-01-17 17:09:47 +01:00
allowedContent : '.($restrictContent ? ' false ' : ' true ').' , /* Advanced Content Filter (ACF) is on when allowedContent is false */
extraAllowedContent : \ '' . dol_escape_js ( $extraAllowedContent ) . ' \ ' , /* Allow a tag with attribute target, allow section tag and allow the style float and display into div to default other allowed tags */
disallowedContent : \ ' \ ' , /* Tags that are not allowed */
2022-05-16 20:28:00 +02:00
fullPage : '.($fullpage ? ' true ' : ' false ').' , /* if true, the html, header and body tags are kept */
2023-01-03 17:09:08 +01:00
toolbar : \ '' . dol_escape_js ( $this -> toolbarname ) . ' \ ' ,
2011-01-31 23:22:35 +01:00
toolbarStartupExpanded : '.($this->toolbarstartexpanded ? ' true ' : ' false ').' ,
2023-01-03 17:09:08 +01:00
width : '.($this->width ? ' \ '' . dol_escape_js ( $this -> width ) . '\'' : '\'\'' ) . ' ,
2024-10-26 18:24:40 +02:00
height : '.dol_escape_js((string) $this->height).' ,
2023-01-03 17:09:08 +01:00
skin : \ '' . dol_escape_js ( $skin ) . ' \ ' ,
2021-04-23 00:45:07 +02:00
'.$scaytautostartup.'
2023-01-03 17:09:08 +01:00
language : \ '' . dol_escape_js ( $langs -> defaultlang ) . ' \ ' ,
textDirection : \ '' . dol_escape_js ( $langs -> trans ( " DIRECTION " )) . ' \ ' ,
2021-12-13 01:19:48 +01:00
on : {
2024-01-29 13:00:33 +01:00
instanceReady : function ( ev ) {
2024-09-06 02:59:21 +02:00
console . log ( \ 'ckeditor ' . dol_escape_js ( $this -> htmlname ) . ' instanceReady\ ' );
/* If we found the attribute required on source div, we remove it (not compatible with ckeditor) */
2025-01-17 17:09:47 +01:00
/* Disabled, because attribute "required" should never be used on fields for doleditor */
2024-09-06 02:59:21 +02:00
/* jQuery("#'.dol_escape_js($this->htmlname).'").attr("required", false); */
2011-04-09 17:12:20 +02:00
// Output paragraphs as <p>Text</p>.
2021-12-13 01:19:48 +01:00
this . dataProcessor . writer . setRules ( \ ' p\ ' , {
indent : false ,
breakBeforeOpen : true ,
breakAfterOpen : false ,
breakBeforeClose : false ,
breakAfterClose : true
});
2024-01-29 13:00:33 +01:00
},
},
2024-08-28 18:50:18 +02:00
disableNativeSpellChecker : '.(getDolGlobalString(' CKEDITOR_NATIVE_SPELLCHECKER ') ? ' false ' : ' true ' );
2019-12-04 15:49:22 +01:00
2021-02-23 22:03:23 +01:00
if ( $this -> uselocalbrowser ) {
2020-10-31 14:32:18 +01:00
$out .= ',' . " \n " ;
// To use filemanager with old fckeditor (GPL)
2024-01-29 13:00:33 +01:00
// Note: ckeditorFilebrowserBrowseUrl and ckeditorFilebrowserImageBrowseUrl are defined in header by main.inc.php. They include url to browser with url of upload connector in parameter
2020-10-31 14:32:18 +01:00
$out .= ' filebrowserBrowseUrl : ckeditorFilebrowserBrowseUrl,' ;
$out .= ' filebrowserImageBrowseUrl : ckeditorFilebrowserImageBrowseUrl,' ;
//$out.= ' filebrowserUploadUrl : \''.DOL_URL_ROOT.'/includes/fckeditor/editor/filemanagerdol/connectors/php/upload.php?Type=File\',';
//$out.= ' filebrowserImageUploadUrl : \''.DOL_URL_ROOT.'/includes/fckeditor/editor/filemanagerdol/connectors/php/upload.php?Type=Image\',';
$out .= " \n " ;
// To use filemanager with ckfinder (Non free) and ckfinder directory is inside htdocs/includes
2014-03-08 13:17:20 +01:00
/* $out .= ' filebrowserBrowseUrl : \'' . DOL_URL_ROOT . ' / includes / ckfinder / ckfinder . html\ ' ,
2021-02-23 22:03:23 +01:00
filebrowserImageBrowseUrl : \ '' . DOL_URL_ROOT . ' / includes / ckfinder / ckfinder . html ? Type = Images\ ' ,
filebrowserFlashBrowseUrl : \ '' . DOL_URL_ROOT . ' / includes / ckfinder / ckfinder . html ? Type = Flash\ ' ,
filebrowserUploadUrl : \ '' . DOL_URL_ROOT . ' / includes / ckfinder / core / connector / php / connector . php ? command = QuickUpload & type = Files\ ' ,
filebrowserImageUploadUrl : \ '' . DOL_URL_ROOT . ' / includes / ckfinder / core / connector / php / connector . php ? command = QuickUpload & type = Images\ ' ,
filebrowserFlashUploadUrl : \ '' . DOL_URL_ROOT . '/includes/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Flash\',' . " \n " ;
2014-03-08 13:17:20 +01:00
*/
2020-10-31 14:32:18 +01:00
$out .= ' filebrowserWindowWidth : \ ' 900 \ ' ,
2011-04-23 00:13:34 +02:00
filebrowserWindowHeight : \ ' 500 \ ' ,
filebrowserImageWindowWidth : \ ' 900 \ ' ,
filebrowserImageWindowHeight : \ '500\'' ;
2020-10-31 14:32:18 +01:00
}
2021-12-13 01:19:48 +01:00
$out .= ' })' . $morejs ; // end CKEditor.replace
// Show the CKEditor javascript object once loaded is ready 'For debug)
//$out .= '; CKEDITOR.on(\'instanceReady\', function(ck) { ck.editor.removeMenuItem(\'maximize\'); ck.editor.removeMenuItem(\'Undo\'); ck.editor.removeMenuItem(\'undo\'); console.log(ck.editor); console.log(ck.editor.toolbar[0]); }); ';
$out .= '});' . " \n " ; // end document.ready
2020-10-31 14:32:18 +01:00
$out .= '</script>' . " \n " ;
}
}
2017-07-18 12:00:18 +02:00
2020-10-31 14:32:18 +01:00
// Output editor ACE
// Warning: ace.js and ext-statusbar.js must be loaded by the parent page.
2021-02-23 22:03:23 +01:00
if ( preg_match ( '/^ace/' , $this -> tool )) {
2020-10-31 14:32:18 +01:00
$found = 1 ;
2019-12-06 09:26:49 +01:00
$format = $option ;
2017-07-18 03:18:16 +02:00
2024-10-13 02:01:14 +02:00
$out .= " \n " . '<!-- Output Ace editor ' . dol_string_nohtmltag ( $this -> htmlname ) . ' -->' . " \n " ;
2017-07-18 14:20:37 +02:00
2021-02-23 22:03:23 +01:00
if ( $titlecontent ) {
2020-10-31 14:32:18 +01:00
$out .= '<div class="aceeditorstatusbar" id="statusBar' . $this -> htmlname . '">' . $titlecontent ;
2023-12-21 12:09:54 +01:00
$out .= ' - <span id="morelines" class="right classlink cursorpointer morelines' . $this -> htmlname . '">' . dol_escape_htmltag ( $langs -> trans ( " ShowMoreLines " )) . '</span> ' ;
2020-10-31 14:32:18 +01:00
$out .= '</div>' ;
2023-02-18 15:10:05 +01:00
$out .= '<script nonce="' . getNonce () . '" type="text/javascript">' . " \n " ;
2020-10-31 14:32:18 +01:00
$out .= 'jQuery(document).ready(function() {' . " \n " ;
2024-09-14 02:44:26 +02:00
$out .= ' var aceEditor = window.ace.edit("' . dol_escape_all ( $this -> htmlname ) . ' aceeditorid " );
2024-03-12 23:15:16 +01:00
aceEditor . moveCursorTo ( '.($this->posy + 1).' , '.$this->posx.' );
aceEditor . gotoLine ( '.($this->posy + 1).' , '.$this->posx.' );
2017-07-19 16:38:00 +02:00
var StatusBar = window . ace . require ( " ace/ext/statusbar " ) . StatusBar ; // Init status bar. Need lib ext-statusbar
2024-09-14 02:44:26 +02:00
var statusBar = new StatusBar ( aceEditor , document . getElementById ( " statusBar'.dol_escape_all( $this->htmlname ).' " )); // Init status bar. Need lib ext-statusbar
2022-02-27 14:46:40 +01:00
var oldNbOfLines = 0 ;
2024-09-14 02:44:26 +02:00
jQuery ( " .morelines'.dol_escape_all( $this->htmlname ).' " ) . click ( function () {
2017-12-10 19:54:04 +01:00
var aceEditorClicked = window . ace . edit ( " '. $this->htmlname .'aceeditorid " );
currentline = aceEditorClicked . getOption ( " maxLines " );
2017-12-10 19:03:18 +01:00
if ( oldNbOfLines == 0 )
{
oldNbOfLines = currentline ;
}
2017-12-10 19:54:04 +01:00
console . log ( " We click on more lines, oldNbOfLines is " + oldNbOfLines + " , we have currently " + currentline );
2017-12-10 19:03:18 +01:00
if ( currentline < 500 )
{
2017-12-10 19:54:04 +01:00
aceEditorClicked . setOptions ({ maxLines : 500 });
2017-12-10 19:03:18 +01:00
}
else
{
2017-12-10 19:54:04 +01:00
aceEditorClicked . setOptions ({ maxLines : oldNbOfLines });
2017-12-10 19:03:18 +01:00
}
2017-07-18 14:20:37 +02:00
});
}) ' ;
2020-10-31 14:32:18 +01:00
$out .= '</script>' . " \n " ;
2017-07-18 14:20:37 +02:00
}
2020-04-20 15:36:08 +02:00
2020-10-31 14:32:18 +01:00
$out .= '<pre id="' . $this -> htmlname . 'aceeditorid" style="' . ( $this -> width ? 'width: ' . $this -> width . 'px; ' : '' );
$out .= ( $this -> height ? ' height: ' . $this -> height . 'px; ' : '' );
//$out.=" min-height: 100px;";
$out .= '">' ;
2025-01-02 09:54:17 +01:00
$out .= htmlspecialchars ( $this -> content );
2020-10-31 14:32:18 +01:00
$out .= '</pre>' ;
2022-02-10 14:34:04 +01:00
$out .= '<input type="hidden" id="' . $this -> htmlname . '_x" name="' . $this -> htmlname . '_x">' ;
$out .= '<input type="hidden" id="' . $this -> htmlname . '_y" name="' . $this -> htmlname . '_y">' ;
2020-10-31 14:32:18 +01:00
$out .= '<textarea id="' . $this -> htmlname . '" name="' . $this -> htmlname . '" style="width:0px; height: 0px; display: none;">' ;
2025-01-02 09:54:17 +01:00
$out .= htmlspecialchars ( $this -> content );
2020-10-31 14:32:18 +01:00
$out .= '</textarea>' ;
2017-07-18 12:00:18 +02:00
2023-02-18 15:10:05 +01:00
$out .= '<script nonce="' . getNonce () . '" type="text/javascript">' . " \n " ;
2020-10-31 14:32:18 +01:00
$out .= 'var aceEditor = window.ace.edit("' . $this -> htmlname . ' aceeditorid " );
2017-07-18 12:00:18 +02:00
2024-11-23 13:55:12 +01:00
aceEditor . session . setMode ( " ace/mode/'. $format .' " );
aceEditor . setReadOnly ( '.($this->readonly ? ' true ' : ' false ').' );
2017-07-18 12:00:18 +02:00
aceEditor . setOptions ({
2024-11-23 13:55:12 +01:00
enableBasicAutocompletion : true , // the editor completes the statement when you hit Ctrl + Space. Need lib ext-language_tools.js
2024-09-14 02:44:26 +02:00
enableLiveAutocompletion : false , // the editor completes the statement while you are typing. Need lib ext-language_tools.js
//enableSnippets: true, // ???
showPrintMargin : false , // hides the vertical limiting strip
minLines : 10 ,
maxLines : '.(empty($this->height) ? ' 34 ' : (round($this->height / 10))).' ,
fontSize : " 110% " // ensures that the editor fits in the environment
2017-07-18 12:00:18 +02:00
});
// defines the style of the editor
aceEditor . setTheme ( " ace/theme/chrome " );
2024-09-14 02:44:26 +02:00
2017-07-18 12:00:18 +02:00
// hides line numbers (widens the area occupied by error and warning messages)
//aceEditor.renderer.setOption("showLineNumbers", false);
// ensures proper autocomplete, validation and highlighting of JavaScript code
2024-09-14 02:44:26 +02:00
//aceEditor.getSession().setMode("ace/mode/javascript_expression");'."\n";
// If page is PAGE_CONTENT to edit HTML web page in web site module, we add some autocompletion
if ( $this -> htmlname == 'PAGE_CONTENT' ) {
$out .= '
// Add custom function in the autocompletion
var customCompleter = {
getCompletions : function ( editor , session , pos , prefix , callback ) {
var wordList = [
{ caption : \ ' dol_escape_all\ ' , value : \ ' dol_escape_all ( string ) \ ' , meta : \ ' custom\ ' },
{ caption : \ ' dol_escape_js\ ' , value : \ ' dol_escape_js ( string ) \ ' , meta : \ ' custom\ ' },
{ caption : \ ' includeContainer\ ' , value : \ ' includeContainer ( alias_of_container_to_include ) \ ' , meta : \ ' custom\ ' },
{ caption : \ ' redirectToContainer\ ' , value : \ ' redirectToContainer ( alias_of_container_to_redirect_to ) \ ' , meta : \ ' custom\ ' },
{ caption : \ ' getImageFromHtmlContent\ ' , value : \ ' getImageFromHtmlContent ( websitepage -> htmlcontent ) \ ' , meta : \ ' custom\ ' },
];
callback ( null , wordList . map ( function ( word ) {
return {
caption : word . caption ,
value : word . value ,
meta : word . meta
};
}));
}
};
aceEditor . completers = [ customCompleter ];
2017-07-18 12:00:18 +02:00
' . " \n " ;
2024-09-14 02:44:26 +02:00
}
2017-07-18 12:00:18 +02:00
2024-09-14 02:44:26 +02:00
$out .= 'jQuery(document).ready(function() {' ;
$out .= ' jQuery ( " .buttonforacesave " ) . click ( function () {
2022-03-03 00:16:55 +01:00
console . log ( " We click on savefile button for component '.dol_escape_js( $this->htmlname ).' " );
var aceEditor = window . ace . edit ( " '.dol_escape_js( $this->htmlname ).'aceeditorid " );
2022-02-10 14:34:04 +01:00
if ( aceEditor ) {
var cursorPos = aceEditor . getCursorPosition ();
2022-03-02 14:44:14 +01:00
//console.log(cursorPos);
2022-02-10 14:34:04 +01:00
if ( cursorPos ) {
2022-03-03 00:16:55 +01:00
jQuery ( " #'.dol_escape_js( $this->htmlname ).'_x " ) . val ( cursorPos . column );
jQuery ( " #'.dol_escape_js( $this->htmlname ).'_y " ) . val ( cursorPos . row );
2022-02-10 14:34:04 +01:00
}
2024-11-23 13:55:12 +01:00
//console.log(aceEditor.getSession().getValue());
2022-02-10 14:34:04 +01:00
// Inject content of editor into the original HTML field.
2022-03-03 00:16:55 +01:00
jQuery ( " #'.dol_escape_js( $this->htmlname ).' " ) . val ( aceEditor . getSession () . getValue ());
/* if ( jQuery ( " #'.dol_escape_js( $this->htmlname ).' " ) . html () . length > 0 ) return true ;
2022-02-10 14:34:04 +01:00
else return false ; */
2022-03-02 14:44:14 +01:00
return true ;
2022-02-10 14:34:04 +01:00
} else {
console . log ( " Failed to retrieve js object ACE from its name " );
return false ;
}
2024-11-23 13:55:12 +01:00
});
2017-07-18 03:18:16 +02:00
}) ' ;
2020-10-31 14:32:18 +01:00
$out .= '</script>' . " \n " ;
}
2010-08-27 02:09:58 +02:00
2021-02-23 22:03:23 +01:00
if ( empty ( $found )) {
2020-10-31 14:32:18 +01:00
$out .= 'Error, unknown value for tool ' . $this -> tool . ' in DolEditor Create function.' ;
}
2011-07-06 14:44:51 +02:00
2021-02-23 22:03:23 +01:00
if ( $noprint ) {
return $out ;
} else {
print $out ;
}
2020-10-31 14:32:18 +01:00
}
2006-07-22 18:09:48 +02:00
}