From 4d88b00e02f7e502548c8e6dc8ff97c452be535b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20St=C3=B6ckel?= Date: Thu, 24 Jun 2010 14:23:56 +0000 Subject: [PATCH] Moved ckeditor configuration to own php file which generates js, in order for easier implementation in etemplate 2 --- phpgwapi/inc/ckeditor-setup.php | 268 ++++++++++++++++++++++++++++++++ phpgwapi/inc/class.html.inc.php | 15 +- 2 files changed, 279 insertions(+), 4 deletions(-) create mode 100644 phpgwapi/inc/ckeditor-setup.php diff --git a/phpgwapi/inc/ckeditor-setup.php b/phpgwapi/inc/ckeditor-setup.php new file mode 100644 index 0000000000..dec3ab8f8b --- /dev/null +++ b/phpgwapi/inc/ckeditor-setup.php @@ -0,0 +1,268 @@ + + * @package api + * @subpackage tools + * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License + * @version $Id$ + */ + +//Disable framework and cachecontrol +$GLOBALS['egw_info'] = array( + 'flags' => array( + 'currentapp' => 'home', + 'noheader' => True, + 'nonavbar' => True, + 'noappheader' => True, + 'noappfooter' => True, + 'nofooter' => True, + 'nocachecontrol' => True // allow caching + ) +); + +try { + include('../../header.inc.php'); +} +catch (egw_exception_no_permission_app $e) { + // ignore exception, if home is not allowed, eg. for sitemgr +} + +include('../../header.inc.php'); + +header('Content-type: text/javascript; charset='.translation::charset()); + +/** + * Returns an array which contains both, the current user language and the current + * user country setting. + */ +function get_lang_country() +{ + //use the lang and country information to construct a possible lang info for CKEditor UI and scayt_slang + $lang = ($GLOBALS['egw_info']['user']['preferences']['common']['spellchecker_lang'] ? + $GLOBALS['egw_info']['user']['preferences']['common']['spellchecker_lang']: + $GLOBALS['egw_info']['user']['preferences']['common']['lang']); + + $country = $GLOBALS['egw_info']['user']['preferences']['common']['country']; + + if (!(strpos($lang,'-')===false)) + list($lang,$country) = explode('-',$lang); + + return array( + 'lang' => $lang, + 'country' => $country + ); +} + +/** + * Returns the ckeditor basepath + */ +function get_base_path() +{ + //Get the ckeditor base url + return $GLOBALS['egw_info']['server']['webserver_url'].'/phpgwapi/js/ckeditor3/'; +} + +/** + * Returns the ckeditor enter mode which defaults to "BR" + */ +function get_enter_mode() +{ + //Get the input name + $enterMode = "CKEDITOR.ENTER_BR"; + if (isset($GLOBALS['egw_info']['user']['preferences']['common']['rte_enter_mode'])) + { + switch ($GLOBALS['egw_info']['user']['preferences']['common']['rte_enter_mode']) + { + case 'p': + $enterMode = "CKEDITOR.ENTER_P"; + break; + case 'br': + $enterMode = "CKEDITOR.ENTER_BR"; + break; + case 'div': + $enterMode = "CKEDITOR.ENTER_DIV"; + break; + } + } + + return $enterMode; +} + +/** + * Returns the skin the ckeditor should us + */ +function get_skin() +{ + //Get the skin name + $skin = $GLOBALS['egw_info']['user']['preferences']['common']['rte_skin']; + + //Convert old fckeditor skin names to new ones + switch ($skin) + { + case 'silver': + $skin = "v2"; + break; + case 'default': + $skin = "kama"; + break; + case 'office2003': + $skin = "office2003"; + break; + } + + //Check whether the skin actually exists, if not, switch to a default + if (!(file_exists($basePath.'skins/'.$skin) || file_exists($skin) || !empty($skin))) + $skin = "office2003"; + + return $skin; +} + +/** + * Returns a string containing the ckeditor spellchecker settings. + */ +function get_spellcheck_settings(&$spell) +{ + // Now setting the admin settings + $res = ''; + $spell = false; + $lang_country = get_lang_country(); + if (isset($GLOBALS['egw_info']['server']['enabled_spellcheck'])) + { + $spell = ",'SpellChecker'"; + if (!empty($GLOBALS['egw_info']['server']['aspell_path']) && + is_executable($GLOBALS['egw_info']['server']['aspell_path'])) + { + $spell = ",'SpellCheck'"; + $res .= ' config.extraPlugins = "aspell";'."\n"; + } + else + { + $res .= " config.scaty_autoStartup = true;\n"; + $res .= " config.scaty_sLang = '".$lang_country['lang'].'_'.strtoupper($lang_country['country'])."';\n"; + } + } + + return $res; +} + +/** + * Returns a string containing the ckeditor toolbar settings + */ +function get_toolbar($toolbar, $spell) +{ + switch ($toolbar) + { + case 'simple': + return +" config.toolbar = [ + ['Bold','Italic','Underline'], + ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'], + ['BulletedList','NumberedList','Outdent','Indent','Undo','Redo'], + ['Cut','Copy','Paste','PasteText','PasteFromWord','-','Print'], + ['Maximize'".($spell ? $spell : '')."], + '/', + ['Format','Font','FontSize'], + ['TextColor','BGColor'], + ['ShowBlocks','-','About'] + ];\n"; + + case 'extended': + return +" config.toolbar = [ + ['Bold','Italic','Underline'], + ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'], + ['BulletedList','NumberedList','Outdent','Indent','Undo','Redo'], + ['Cut','Copy','Paste','PasteText','PasteFromWord','-','Print'], + ['Link','Unlink','Anchor'], + ['Find','Replace'], + ['Maximize'".($spell ? $spell : '').",'Image','Table'], + '/', + ['Format','Font','FontSize'], + ['TextColor','BGColor'], + ['ShowBlocks','-','About'] + ];\n"; + + case 'advanced': + return +" config.toolbar = [ + ['Source','DocProps','-','Save','NewPage','Preview','-','Templates'], + ['Cut','Copy','Paste','PasteText','PasteFromWord','-','Print'".($spell ? $spell : '')."], + ['Undo','Redo','-','Find','Replace','-','SelectAll','RemoveFormat'], + '/', + ['Bold','Italic','Underline','Strike','-','Subscript','Superscript'], + ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'], + ['BulletedList','NumberedList','-','Outdent','Indent'], + ['Link','Unlink','Anchor'], + ['Maximize','Image','SpecialChar','PageBreak'], + '/', + ['Style','Format','Font','FontSize'], + ['TextColor','BGColor'], + ['ShowBlocks','-','About'] + ];\n"; + } +} + +//Initialize the user parameters +$height = '400px'; +$width = '100%'; +$start_path = ''; +$expanded_toolbar = true; +$mode = 'simple'; + +//Read some parameters from the $_GET array +if (isset($_GET['height'])) + $height = htmlspecialchars($_GET['height']); +if (isset($_GET['width'])) + $width = htmlspecialchars($_GET['width']); +if (isset($_GET['start_path'])) + $start_path = urlencode($_GET['start_path']); +if (isset($_GET['expanded_toolbar'])) + $expanded_toolbar = $_GET['expanded_toolbar'] == '1'; +if (isset($_GET['mode']) && in_array($_GET['mode'], array('simple', 'advanced', 'extended'))) + $mode = $_GET['mode']; + +$lang_country = get_lang_country(); +$spell = false; + +//Output the configuration +echo( +' +/** + * CKEditor user based configuration + */ + +window.CKEDITOR_BASEPATH = "'.get_base_path().'"; + +CKEDITOR.editorConfig = function(config) +{ + config.resize_enabled = false; + + config.entities = true; + config.entities_latin = true; + config.entities_processNumerical = true; + + config.editingBlock = true; + + config.filebrowserBrowseUrl = "'.$GLOBALS['egw_info']['server']['webserver_url'].'/index.php?menuaction=filemanager.filemanager_select.select&mode=open&method=ckeditor_return' + .($start_path != '' ? '&path='.$start_path : '').'"; + config.filebrowserWindowWidth = "640"; + config.filebrowserWindowHeight = "580"; + + config.language = "'.$lang_country['lang'].'"; + + config.expanded_toolbar = '.($expanded_toolbar ? 'true' : 'false').'; + + config.height = "'.$height.'"; + + config.enterMode = '.get_enter_mode().'; + config.skin = "'.get_skin().'"; +'.get_spellcheck_settings($spell). +' config.disableNativeSpellchecker = true; +'.get_toolbar($mode, $spell).'}' +); + + diff --git a/phpgwapi/inc/class.html.inc.php b/phpgwapi/inc/class.html.inc.php index 934faa7bad..7988977f56 100644 --- a/phpgwapi/inc/class.html.inc.php +++ b/phpgwapi/inc/class.html.inc.php @@ -599,17 +599,24 @@ class html { include_once(EGW_INCLUDE_ROOT."/phpgwapi/js/ckeditor3/ckeditor_php5.php"); // use the lang and country information to construct a possible lang info for CKEditor UI and scayt_slang - $lang = ($GLOBALS['egw_info']['user']['preferences']['common']['spellchecker_lang'] ? $GLOBALS['egw_info']['user']['preferences']['common']['spellchecker_lang']: $GLOBALS['egw_info']['user']['preferences']['common']['lang']); +/* $lang = ($GLOBALS['egw_info']['user']['preferences']['common']['spellchecker_lang'] ? $GLOBALS['egw_info']['user']['preferences']['common']['spellchecker_lang']: $GLOBALS['egw_info']['user']['preferences']['common']['lang']); $country = $GLOBALS['egw_info']['user']['preferences']['common']['country']; - if (!(strpos($lang,'-')===false)) list($lang,$country) = explode('-',$lang); + if (!(strpos($lang,'-')===false)) list($lang,$country) = explode('-',$lang);*/ //Get the ckeditor base url $basePath = $GLOBALS['egw_info']['server']['webserver_url'].'/phpgwapi/js/ckeditor3/'; $oCKeditor = new CKeditor($basePath); $oCKeditor->returnOutput = true; + + // By default the editor start expanded + $et = '1'; + if ($_options['toolbar_expanded'] == 'false') + $et = '0'; - $oCKeditor->config['customConfig'] = 'ckeditor.egwconfig.js'; + $oCKeditor->config['customConfig'] = $GLOBALS['egw_info']['server']['webserver_url']."/phpgwapi/inc/ckeditor-setup.php?height=$_height&mode=$_mode&expanded_toolbar=$et"; + +/* $oCKeditor->config['customConfig'] = 'ckeditor.egwconfig.js'; $oCKeditor->config['language'] = $lang; $oCKeditor->config['resize_enabled'] = false; //switching the encoding as html entities off, as we correctly handle charsets and it messes up the wiki totally @@ -698,7 +705,7 @@ class html case 'advanced': $oCKeditor->config['toolbar'] = 'egw_advanced'.$spell; break; - } + }*/ return $oCKeditor; }