2010-06-25 12:01:53 +02:00
|
|
|
<?php
|
|
|
|
/**
|
2013-10-14 12:42:36 +02:00
|
|
|
* EGroupware - Class which generates JSON encoded configuration for the ckeditor
|
2010-06-25 12:01:53 +02:00
|
|
|
*
|
|
|
|
* @link http://www.egroupware.org
|
|
|
|
* @author RalfBecker-AT-outdoor-training.de
|
|
|
|
* @author Andreas Stoeckel <as-AT-stylite.de>
|
|
|
|
* @package api
|
|
|
|
* @subpackage tools
|
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
|
|
|
* @version $Id$
|
|
|
|
*/
|
|
|
|
|
2013-10-14 12:42:36 +02:00
|
|
|
/**
|
|
|
|
* CK-Editor configuration
|
|
|
|
*/
|
2010-06-25 12:01:53 +02:00
|
|
|
class egw_ckeditor_config
|
|
|
|
{
|
|
|
|
private static $lang = null;
|
|
|
|
private static $country = null;
|
|
|
|
private static $enterMode = null;
|
|
|
|
private static $skin = null;
|
|
|
|
|
2013-03-14 17:30:55 +01:00
|
|
|
// Defaults, defined in phpgwapi/js/ckeditor/plugins/font/plugin.js
|
2012-12-04 23:21:59 +01:00
|
|
|
public static $font_options = array(
|
|
|
|
'arial, helvetica, sans-serif' => 'Arial',
|
|
|
|
'Comic Sans MS, cursive' => 'Comic Sans MS',
|
|
|
|
'Courier New, Courier, monospace' => 'Courier New',
|
|
|
|
'Georgia, serif' => 'Georgia',
|
|
|
|
'Lucida Sans Unicode, Lucida Grande, sans-serif' => 'Lucida Sans Unicode',
|
|
|
|
'Tahoma, Geneva, sans-serif' => 'Tahoma',
|
|
|
|
'times new roman, times, serif' => 'Times New Roman',
|
|
|
|
'Trebuchet MS, Helvetica, sans-serif' => 'Trebuchet MS',
|
|
|
|
'Verdana, Geneva, sans-serif' => 'Verdana'
|
|
|
|
);
|
|
|
|
public static $font_size_options = array(
|
2013-02-21 12:32:46 +01:00
|
|
|
8 => '8',
|
|
|
|
9 => '9',
|
|
|
|
10 => '10',
|
|
|
|
11 => '11',
|
|
|
|
12 => '12',
|
|
|
|
14 => '14',
|
|
|
|
16 => '16',
|
|
|
|
18 => '18',
|
|
|
|
20 => '20',
|
|
|
|
22 => '22',
|
|
|
|
24 => '24',
|
|
|
|
26 => '26',
|
|
|
|
28 => '28',
|
|
|
|
36 => '36',
|
|
|
|
48 => '48',
|
|
|
|
72 => '72',
|
|
|
|
);
|
|
|
|
public static $font_unit_options = array(
|
|
|
|
'pt' => 'pt: points (1/72 inch)',
|
2013-02-21 14:19:15 +01:00
|
|
|
'px' => 'px: display pixels',
|
2012-12-04 23:21:59 +01:00
|
|
|
);
|
|
|
|
|
2014-07-18 11:49:17 +02:00
|
|
|
/**
|
|
|
|
* Get available CKEditor Skins
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public static function getAvailableCKEditorSkins()
|
|
|
|
{
|
2014-12-12 14:51:42 +01:00
|
|
|
/*
|
|
|
|
drwxr-xr-x 3 kl kl 4096 Dez 9 14:26 icy_orange
|
|
|
|
drwxr-xr-x 3 kl kl 4096 Dez 9 14:26 Moono_blue
|
|
|
|
drwxr-xr-x 3 kl kl 4096 Dez 9 14:26 office2013
|
|
|
|
*/
|
2014-07-18 11:49:17 +02:00
|
|
|
return array(
|
|
|
|
'kama' => lang('kama theme'),
|
|
|
|
'moono' => lang('moono theme (default)'),
|
|
|
|
'moonocolor' => lang('moono color theme'),
|
|
|
|
'moono-dark' => lang('dark moono theme'),
|
2014-12-12 14:51:42 +01:00
|
|
|
'icy_orange' => lang('icy-orange theme for ckeditor'),
|
2015-08-12 12:08:43 +02:00
|
|
|
'minimalist' => lang('Minimalist theme'),
|
|
|
|
'flat' => lang('Flat theme')
|
2014-07-18 11:49:17 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2013-02-21 14:19:15 +01:00
|
|
|
/**
|
|
|
|
* Get font size from preferences
|
|
|
|
*
|
|
|
|
* @param array $prefs=null default $GLOBALS['egw_info']['user']['preferences']
|
|
|
|
* @param string &$size=null on return just size, without unit
|
|
|
|
* @param string &$unit=null on return just unit
|
|
|
|
* @return string font-size including unit
|
|
|
|
*/
|
|
|
|
public static function font_size_from_prefs(array $prefs=null, &$size=null, &$unit=null)
|
|
|
|
{
|
|
|
|
if (is_null($prefs)) $prefs = $GLOBALS['egw_info']['user']['preferences'];
|
|
|
|
|
|
|
|
$size = $prefs['common']['rte_font_size'];
|
|
|
|
$unit = $prefs['common']['rte_font_unit'];
|
|
|
|
if (substr($size, -2) == 'px')
|
|
|
|
{
|
|
|
|
$unit = 'px';
|
|
|
|
$size = (string)(int)$size;
|
|
|
|
}
|
2013-02-22 10:45:47 +01:00
|
|
|
return $size.($size?$unit:'');
|
2013-02-21 14:19:15 +01:00
|
|
|
}
|
|
|
|
|
2010-06-25 12:01:53 +02:00
|
|
|
/**
|
|
|
|
* Read language and country settings for the ckeditor and store them in static
|
|
|
|
* variables
|
|
|
|
*/
|
|
|
|
private static function read_lang_country()
|
|
|
|
{
|
|
|
|
//use the lang and country information to construct a possible lang info for CKEditor UI and scayt_slang
|
|
|
|
self::$lang = ($GLOBALS['egw_info']['user']['preferences']['common']['spellchecker_lang'] ?
|
|
|
|
$GLOBALS['egw_info']['user']['preferences']['common']['spellchecker_lang']:
|
|
|
|
$GLOBALS['egw_info']['user']['preferences']['common']['lang']);
|
|
|
|
|
|
|
|
self::$country = $GLOBALS['egw_info']['user']['preferences']['common']['country'];
|
|
|
|
|
|
|
|
if (!(strpos(self::$lang, '-')===false))
|
|
|
|
list(self::$lang, self::$country) = explode('-', self::$lang);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the current user language
|
|
|
|
*/
|
|
|
|
private static function get_lang()
|
|
|
|
{
|
|
|
|
if (self::$lang == null || self::$country == null)
|
|
|
|
self::read_lang_country();
|
|
|
|
|
|
|
|
return self::$lang;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the current user country
|
|
|
|
*/
|
|
|
|
private static function get_country()
|
|
|
|
{
|
|
|
|
if (self::$lang == null || self::$country == null)
|
|
|
|
self::read_lang_country();
|
|
|
|
|
|
|
|
return strtoupper(self::$country);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the ckeditor basepath
|
|
|
|
*/
|
|
|
|
private static function get_base_path()
|
|
|
|
{
|
|
|
|
//Get the ckeditor base url
|
2013-03-14 17:30:55 +01:00
|
|
|
return $GLOBALS['egw_info']['server']['webserver_url'].'/phpgwapi/js/ckeditor/';
|
2010-06-25 12:01:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the ckeditor enter mode which defaults to "BR"
|
|
|
|
*/
|
|
|
|
private static function get_enter_mode()
|
|
|
|
{
|
|
|
|
if (self::$enterMode == null)
|
|
|
|
{
|
|
|
|
//Get the input name
|
|
|
|
$enterMode = 2;
|
|
|
|
if (isset($GLOBALS['egw_info']['user']['preferences']['common']['rte_enter_mode']))
|
|
|
|
{
|
|
|
|
switch ($GLOBALS['egw_info']['user']['preferences']['common']['rte_enter_mode'])
|
|
|
|
{
|
|
|
|
case 'p':
|
|
|
|
$enterMode = 1;
|
|
|
|
break;
|
|
|
|
case 'br':
|
|
|
|
$enterMode = 2;
|
|
|
|
break;
|
|
|
|
case 'div':
|
|
|
|
$enterMode = 3;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
self::$enterMode = $enterMode;
|
|
|
|
}
|
|
|
|
|
|
|
|
return self::$enterMode;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the skin the ckeditor should use
|
|
|
|
*/
|
|
|
|
private static function get_skin()
|
|
|
|
{
|
|
|
|
if (self::$skin == null)
|
|
|
|
{
|
|
|
|
//Get the skin name
|
|
|
|
$skin = $GLOBALS['egw_info']['user']['preferences']['common']['rte_skin'];
|
2014-02-17 14:56:17 +01:00
|
|
|
//error_log(__METHOD__.__LINE__.' UserAgent:'.html::$user_agent);
|
2010-06-25 12:01:53 +02:00
|
|
|
//Convert old fckeditor skin names to new ones
|
|
|
|
switch ($skin)
|
|
|
|
{
|
2014-07-18 11:49:17 +02:00
|
|
|
case 'kama':
|
|
|
|
$skin = "kama";
|
2014-12-12 14:51:42 +01:00
|
|
|
//if (html::$user_agent=='firefox' || html::$user_agent=='msie') $skin='moonocolor';
|
2014-07-18 11:49:17 +02:00
|
|
|
break;
|
2014-05-22 12:01:31 +02:00
|
|
|
case 'silver':
|
2014-07-18 11:49:17 +02:00
|
|
|
case 'moono-dark':
|
|
|
|
$skin = "moono-dark";
|
|
|
|
break;
|
2014-12-12 14:51:42 +01:00
|
|
|
case 'icy_orange':
|
|
|
|
$skin = "icy_orange";
|
|
|
|
break;
|
2015-08-19 17:58:51 +02:00
|
|
|
case 'bootstrapck': // no longer support by egw
|
|
|
|
case 'Moono_blue':
|
2014-12-12 14:51:42 +01:00
|
|
|
case 'office2013':
|
2014-07-18 11:49:17 +02:00
|
|
|
case 'office2003':
|
2013-10-21 13:33:39 +02:00
|
|
|
case 'moonocolor':
|
|
|
|
$skin = "moonocolor";
|
|
|
|
break;
|
2015-08-12 12:08:43 +02:00
|
|
|
case 'minimalist':
|
|
|
|
$skin = "minimalist";
|
|
|
|
break;
|
|
|
|
case 'flat':
|
|
|
|
$skin = "flat";
|
|
|
|
break;
|
2014-07-18 11:49:17 +02:00
|
|
|
case 'moono':
|
|
|
|
case 'default':
|
2013-03-18 17:02:35 +01:00
|
|
|
default:
|
2014-07-18 11:49:17 +02:00
|
|
|
$skin = "moono";
|
2010-06-25 12:01:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//Check whether the skin actually exists, if not, switch to a default
|
|
|
|
if (!(file_exists($basePath.'skins/'.$skin) || file_exists($skin) || !empty($skin)))
|
2013-11-28 10:41:31 +01:00
|
|
|
$skin = "moono"; //this is the basic skin for ckeditor
|
2010-06-25 12:01:53 +02:00
|
|
|
|
|
|
|
self::$skin = $skin;
|
|
|
|
}
|
|
|
|
|
|
|
|
return self::$skin;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the URL of the filebrowser
|
2013-11-16 17:08:35 +01:00
|
|
|
*
|
|
|
|
* @param string $start_path start path for file browser
|
2010-06-25 12:01:53 +02:00
|
|
|
*/
|
|
|
|
private static function get_filebrowserBrowseUrl($start_path = '')
|
|
|
|
{
|
|
|
|
return $GLOBALS['egw_info']['server']['webserver_url'].'/index.php?menuaction=filemanager.filemanager_select.select&mode=open&method=ckeditor_return'
|
|
|
|
.($start_path != '' ? '&path='.$start_path : '');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds all "easy to write" options to the configuration
|
2013-11-16 17:08:35 +01:00
|
|
|
*
|
|
|
|
* @param array& $config array were config get's added to
|
|
|
|
* @param int|string $height integer height in pixel or string with css unit
|
|
|
|
* @param boolean|string $expanded_toolbar show toolbar expanded, boolean value, string "false", or string casted to boolean
|
|
|
|
* @param string $start_path start path for file browser
|
2010-06-25 12:01:53 +02:00
|
|
|
*/
|
|
|
|
private static function add_default_options(&$config, $height, $expanded_toolbar, $start_path)
|
|
|
|
{
|
|
|
|
//Convert the pixel height to an integer value
|
|
|
|
$config['resize_enabled'] = false;
|
2013-11-16 17:08:35 +01:00
|
|
|
$config['height'] = is_numeric($height) ? (int)$height : $height;
|
2012-06-26 14:37:42 +02:00
|
|
|
//disable encoding as entities needs to set the config value to false, as the default is true with the current ckeditor version
|
|
|
|
$config['entities'] = false;
|
|
|
|
$config['entities_latin'] = false;
|
2010-06-25 12:01:53 +02:00
|
|
|
$config['editingBlock'] = true;
|
|
|
|
$config['disableNativeSpellChecker'] = true;
|
2013-04-29 10:43:42 +02:00
|
|
|
// we set allowedContent to true as the 4.1 contentFiltering system allows only activated features as content
|
|
|
|
$config['allowedContent'] = true;
|
2010-06-25 12:01:53 +02:00
|
|
|
|
2010-07-21 13:45:05 +02:00
|
|
|
$config['removePlugins'] = 'elementspath';
|
|
|
|
|
2013-03-27 08:58:42 +01:00
|
|
|
$config['toolbarCanCollapse'] = true;
|
2013-11-04 11:13:28 +01:00
|
|
|
$config['toolbarStartupExpanded'] = is_bool($expanded_toolbar) ? $expanded_toolbar :
|
|
|
|
($expanded_toolbar === 'false' ? false : (boolean)$expanded_toolbar);
|
2010-06-25 12:01:53 +02:00
|
|
|
|
|
|
|
$config['filebrowserBrowseUrl'] = self::get_filebrowserBrowseUrl($start_path);
|
|
|
|
$config['filebrowserWindowHeight'] = 640;
|
|
|
|
$config['filebrowserWindowWidth'] = 580;
|
|
|
|
|
|
|
|
$config['language'] = self::get_lang();
|
|
|
|
$config['enterMode'] = self::get_enter_mode();
|
|
|
|
$config['skin'] = self::get_skin();
|
2013-02-21 12:32:46 +01:00
|
|
|
|
|
|
|
$config['fontSize_sizes'] = '';
|
|
|
|
$unit = $GLOBALS['egw_info']['user']['preferences']['common']['rte_font_unit'];
|
|
|
|
if (empty($unit)) $unit = 'px';
|
|
|
|
foreach(self::$font_size_options as $k => $v)
|
|
|
|
{
|
2013-02-22 10:45:47 +01:00
|
|
|
$config['fontSize_sizes'] .= $v.$unit.'/'.$k.$unit.';';
|
2013-02-21 12:32:46 +01:00
|
|
|
}
|
2010-06-25 12:01:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds the spellchecker configuration to the options and writes the name of
|
|
|
|
* the spellchecker toolbar button to the "spellchecker_button" parameter
|
|
|
|
*/
|
2011-10-28 11:12:40 +02:00
|
|
|
private static function add_spellchecker_options(&$config, &$spellchecker_button, &$scayt_button)
|
2010-06-25 12:01:53 +02:00
|
|
|
{
|
2011-08-02 13:39:59 +02:00
|
|
|
//error_log(__METHOD__.__LINE__.' Spellcheck:'.$GLOBALS['egw_info']['server']['enabled_spellcheck']);
|
2013-03-18 16:36:27 +01:00
|
|
|
if (isset($GLOBALS['egw_info']['server']['enabled_spellcheck']) && $GLOBALS['egw_info']['server']['enabled_spellcheck'])
|
2010-06-25 12:01:53 +02:00
|
|
|
{
|
2013-03-18 10:59:21 +01:00
|
|
|
// enable browsers native spellchecker as default, if e.g.: aspell fails
|
|
|
|
// to use browsers native spellchecker, you have to hold CMD/CTRL button on rightclick to
|
|
|
|
// access the browsers spell correction options
|
2013-03-18 16:36:27 +01:00
|
|
|
if ($GLOBALS['egw_info']['server']['enabled_spellcheck']!='YesNoSCAYT') $config['disableNativeSpellChecker'] = false;
|
2010-06-25 12:01:53 +02:00
|
|
|
$spellchecker_button = 'SpellChecker';
|
|
|
|
if (!empty($GLOBALS['egw_info']['server']['aspell_path']) &&
|
2011-08-02 13:39:59 +02:00
|
|
|
is_executable($GLOBALS['egw_info']['server']['aspell_path']) &&
|
2013-03-18 16:36:27 +01:00
|
|
|
($GLOBALS['egw_info']['server']['enabled_spellcheck']!='YesUseWebSpellCheck' &&
|
|
|
|
$GLOBALS['egw_info']['server']['enabled_spellcheck']!='YesBrowserBased')
|
2011-08-02 13:39:59 +02:00
|
|
|
)
|
2010-06-25 12:01:53 +02:00
|
|
|
{
|
|
|
|
$spellchecker_button = 'SpellCheck';
|
2015-08-07 17:51:15 +02:00
|
|
|
self::append_extraPlugins_config_array($config, array("aspell"));
|
2010-06-25 12:01:53 +02:00
|
|
|
}
|
2013-03-18 16:36:27 +01:00
|
|
|
if ($GLOBALS['egw_info']['server']['enabled_spellcheck']!='YesNoSCAYT' &&
|
|
|
|
$GLOBALS['egw_info']['server']['enabled_spellcheck']!='YesBrowserBased'
|
|
|
|
)
|
2011-08-02 13:39:59 +02:00
|
|
|
{
|
2011-10-28 11:12:40 +02:00
|
|
|
$scayt_button='Scayt';
|
2011-08-02 13:39:59 +02:00
|
|
|
$config['scayt_autoStartup'] = true;
|
|
|
|
$config['scayt_sLang'] = self::get_lang().'_'.self::get_country();
|
2013-03-18 16:36:27 +01:00
|
|
|
$config['disableNativeSpellChecker'] = true; // only one spell as you type
|
2011-08-02 13:39:59 +02:00
|
|
|
}
|
2010-06-25 12:01:53 +02:00
|
|
|
}
|
2010-07-20 15:34:53 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
$config['scayt_autoStartup'] = false;
|
|
|
|
}
|
2010-06-25 12:01:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Writes the toolbar configuration to the options which depends on the chosen
|
|
|
|
* mode and the spellchecker_button written by the add_spellchecker_options button
|
|
|
|
*/
|
2011-10-28 11:12:40 +02:00
|
|
|
private static function add_toolbar_options(&$config, $mode, $spellchecker_button, $scayt_button=false)
|
2010-06-25 12:01:53 +02:00
|
|
|
{
|
|
|
|
$config['toolbar'] = array();
|
|
|
|
switch ($mode)
|
|
|
|
{
|
|
|
|
case 'advanced':
|
2013-10-10 13:55:29 +02:00
|
|
|
$config['toolbar'][] = array('name' => 'document', 'items' => array('Source','DocProps','-','Preview','-','Templates'));
|
|
|
|
$config['toolbar'][] = array('name' => 'clipboard', 'items' => array('Cut','Copy','Paste','PasteText','PasteFromWord','-','Print'));
|
2013-10-17 17:09:56 +02:00
|
|
|
if ($spellchecker_button||$scayt_button)
|
|
|
|
{
|
|
|
|
$configArray = array();
|
|
|
|
if ($spellchecker_button) $configArray[] = $spellchecker_button;
|
|
|
|
if ($scayt_button) $configArray[] = $scayt_button;
|
|
|
|
$config['toolbar'][] = array('name' => 'tools', 'items' => $configArray);
|
|
|
|
}
|
2013-10-10 13:55:29 +02:00
|
|
|
$config['toolbar'][] = array('name' => 'edit', 'items' => array('Undo','Redo','-','Find','Replace','-','SelectAll','RemoveFormat'));
|
2010-06-25 12:01:53 +02:00
|
|
|
|
|
|
|
$config['toolbar'][] = '/';
|
|
|
|
|
2013-10-10 13:55:29 +02:00
|
|
|
$config['toolbar'][] = array('name' => 'basicstyles', 'items' => array('Bold','Italic','Underline','Strike','-','Subscript','Superscript'));
|
|
|
|
$config['toolbar'][] = array('name' => 'justify', 'items' => array('JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'));
|
|
|
|
$config['toolbar'][] = array('name' => 'paragraph', 'items' => array('BulletedList','NumberedList','-','Outdent','Indent'));
|
|
|
|
$config['toolbar'][] = array('name' => 'links', 'items' => array('Link','Unlink','Anchor'));
|
|
|
|
$config['toolbar'][] = array('name' => 'insert', 'items' => array('Maximize','Image','Table','HorizontalRule','SpecialChar'/*,'Smiley'*/));
|
2010-06-25 12:01:53 +02:00
|
|
|
|
|
|
|
$config['toolbar'][] = '/';
|
|
|
|
|
2013-10-10 13:55:29 +02:00
|
|
|
$config['toolbar'][] = array('name' => 'styles', 'items' => array('Style','Format','Font','FontSize'));
|
|
|
|
$config['toolbar'][] = array('name' => 'colors', 'items' => array('TextColor','BGColor'));
|
|
|
|
$config['toolbar'][] = array('name' => 'tools', 'items' => array('ShowBlocks','-','About'));
|
2010-06-25 12:01:53 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'extended': default:
|
2013-10-10 13:55:29 +02:00
|
|
|
$config['toolbar'][] = array('name' => 'clipboard', 'items' => array('Bold','Italic','Underline'));
|
|
|
|
$config['toolbar'][] = array('name' => 'justify', 'items' => array('JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'));
|
|
|
|
$config['toolbar'][] = array('name' => 'paragraph', 'items' => array('BulletedList','NumberedList'/*,'Smiley'*/,'Outdent','Indent','Undo','Redo'));
|
|
|
|
$config['toolbar'][] = array('name' => 'clipboard', 'items' => array('Cut','Copy','Paste','PasteText','PasteFromWord','-','Print'));
|
2010-06-25 12:01:53 +02:00
|
|
|
|
|
|
|
if ($mode == 'extended')
|
|
|
|
{
|
2013-10-10 13:55:29 +02:00
|
|
|
$config['toolbar'][] = array('name' => 'insert', 'items' => array('Image','Link','Unlink','Anchor'));
|
2013-10-17 17:09:56 +02:00
|
|
|
if ($spellchecker_button||$scayt_button)
|
|
|
|
{
|
|
|
|
$configArray = array('Maximize');
|
|
|
|
if ($spellchecker_button) $configArray[] = $spellchecker_button;
|
|
|
|
if ($scayt_button) $configArray[] = $scayt_button;
|
|
|
|
$config['toolbar'][] = array('name' => 'tools', 'items' => $configArray);
|
|
|
|
}
|
2010-06-25 12:01:53 +02:00
|
|
|
else
|
2013-10-10 13:55:29 +02:00
|
|
|
$config['toolbar'][] = array('name' => 'insert', 'items' => array('Maximize'));//, 'Image', 'Table');
|
2013-10-17 17:09:56 +02:00
|
|
|
|
2013-10-10 13:55:29 +02:00
|
|
|
$config['toolbar'][count($config['toolbar']) - 1][] = array('name' => 'insert', 'items' => array('Image', 'Table'));
|
2010-06-25 12:01:53 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-10-17 17:09:56 +02:00
|
|
|
if ($spellchecker_button||$scayt_button)
|
|
|
|
{
|
|
|
|
$configArray = array('Maximize');
|
|
|
|
if ($spellchecker_button) $configArray[] = $spellchecker_button;
|
|
|
|
if ($scayt_button) $configArray[] = $scayt_button;
|
|
|
|
$config['toolbar'][] = array('name' => 'tools', 'items' => $configArray);
|
|
|
|
}
|
2010-06-25 12:01:53 +02:00
|
|
|
else
|
2013-10-10 13:55:29 +02:00
|
|
|
$config['toolbar'][] = array('name' => 'tools', 'items' => array('Maximize'));
|
2010-06-25 12:01:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$config['toolbar'][] = '/';
|
2013-10-10 13:55:29 +02:00
|
|
|
$config['toolbar'][] = array('name' => 'edit', 'items' => array('Find','Replace','-','SelectAll','RemoveFormat'));
|
|
|
|
if ($mode == 'simple-withimage') $config['toolbar'][] = array('name' => 'links', 'items' => array('Image','Link','Unlink'));
|
|
|
|
$config['toolbar'][] = array('name' => 'styles', 'items' => array('Format','Font','FontSize'));
|
|
|
|
$config['toolbar'][] = array('name' => 'colors', 'items' => array('TextColor','BGColor'));
|
|
|
|
$config['toolbar'][] = array('name' => 'tools', 'items' => array('ShowBlocks','-','About'));
|
2010-06-25 12:01:53 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-06-25 14:30:39 +02:00
|
|
|
* @see get_ckeditor_config
|
2010-06-25 12:01:53 +02:00
|
|
|
*/
|
2012-12-05 20:58:37 +01:00
|
|
|
public static function get_ckeditor_config_array($mode = '', $height = 400, $expanded_toolbar = true, $start_path = '')
|
2010-06-25 12:01:53 +02:00
|
|
|
{
|
2013-10-14 12:42:36 +02:00
|
|
|
// set for CK-Editor necessary CSP script-src attributes
|
|
|
|
self::set_csp_script_src_attrs();
|
|
|
|
|
2012-12-05 20:58:37 +01:00
|
|
|
// If not explicitly set, use preference for toolbar mode
|
|
|
|
if(!$mode || trim($mode) == '') $mode = $GLOBALS['egw_info']['user']['preferences']['common']['rte_features'];
|
2010-06-25 12:01:53 +02:00
|
|
|
$config = array();
|
|
|
|
$spellchecker_button = null;
|
|
|
|
|
|
|
|
self::add_default_options($config, $height, $expanded_toolbar, $start_path);
|
2011-10-28 11:12:40 +02:00
|
|
|
self::add_spellchecker_options($config, $spellchecker_button, $scayt_button);
|
|
|
|
self::add_toolbar_options($config, $mode, $spellchecker_button, $scayt_button);
|
2013-11-04 11:13:28 +01:00
|
|
|
//error_log(__METHOD__."('$mode', $height, ".array2string($expanded_toolbar).") returning ".array2string($config));
|
2015-08-07 17:51:15 +02:00
|
|
|
// Add extra plugins
|
|
|
|
self::append_extraPlugins_config_array($config, array('uploadimage','uploadwidget','widget','notification','notificationaggregator','lineutils'));
|
2010-06-25 14:30:39 +02:00
|
|
|
return $config;
|
|
|
|
}
|
2015-08-07 17:51:15 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds extra
|
|
|
|
* @param array $config
|
|
|
|
* @param array $plugins plugins name which needs to be appended into extraPlugins
|
|
|
|
*/
|
|
|
|
public static function append_extraPlugins_config_array (&$config, $plugins)
|
|
|
|
{
|
|
|
|
if (is_array($plugins))
|
|
|
|
{
|
|
|
|
foreach ($plugins as &$plugin)
|
|
|
|
{
|
|
|
|
if (!empty($config['extraPlugins']) && $config['extraPlugins'] !== '')
|
|
|
|
{
|
|
|
|
$config['extraPlugins'] .= ',' . $plugin;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$config['extraPlugins'] = $plugin;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-25 14:30:39 +02:00
|
|
|
/**
|
|
|
|
* Returns a json encoded string containing the configuration for the ckeditor.
|
|
|
|
* @param string $mode specifies the count of toolbar buttons available to the user. Possible
|
|
|
|
* values are 'simple', 'extended' and 'advanced'. All other values will default to 'simple'
|
|
|
|
* @param integer $height contains the height of the ckeditor in pixels
|
|
|
|
* @param boolean $expanded_toolbar specifies whether the ckeditor should start with an expanded toolbar or not
|
2012-04-11 16:57:00 +02:00
|
|
|
* @param string $start_path specifies
|
2010-06-25 14:30:39 +02:00
|
|
|
*/
|
2012-12-05 21:22:13 +01:00
|
|
|
public static function get_ckeditor_config($mode = '', $height = 400, $expanded_toolbar = true, $start_path = '')
|
2010-06-25 14:30:39 +02:00
|
|
|
{
|
|
|
|
return json_encode(self::get_ckeditor_config_array($mode, $height, $expanded_toolbar, $start_path));
|
2010-06-25 12:01:53 +02:00
|
|
|
}
|
2013-10-14 12:42:36 +02:00
|
|
|
|
2014-09-04 11:58:48 +02:00
|
|
|
/**
|
|
|
|
* URL webspellchecker uses for scripts and style-sheets
|
|
|
|
*/
|
|
|
|
const WEBSPELLCHECK_HOST = 'svc.webspellchecker.net';
|
|
|
|
|
2013-10-14 12:42:36 +02:00
|
|
|
/**
|
|
|
|
* Set for CK-Editor necessary CSP script-src attributes
|
|
|
|
*
|
|
|
|
* Get's called automatic from get_ckeditor_config(_array)
|
|
|
|
*/
|
|
|
|
public static function set_csp_script_src_attrs()
|
|
|
|
{
|
|
|
|
$attrs = array('unsafe-eval', 'unsafe-inline');
|
2014-09-04 11:58:48 +02:00
|
|
|
$url = ($_SERVER['HTTPS'] ? 'https://' : 'http://').self::WEBSPELLCHECK_HOST;
|
2013-10-14 12:42:36 +02:00
|
|
|
|
|
|
|
// if webspellchecker is enabled in EGroupware config, allow access to it's url
|
|
|
|
if (in_array($GLOBALS['egw_info']['server']['enabled_spellcheck'], array('True', 'YesUseWebSpellCheck')))
|
|
|
|
{
|
2014-09-04 11:58:48 +02:00
|
|
|
$attrs[] = $url;
|
|
|
|
|
|
|
|
egw_framework::csp_style_src_attrs($url);
|
2013-10-14 12:42:36 +02:00
|
|
|
}
|
|
|
|
//error_log(__METHOD__."() egw_info[server][enabled_spellcheck]='{$GLOBALS['egw_info']['server']['enabled_spellcheck']}' --> attrs=".array2string($attrs));
|
|
|
|
// tell framework CK Editor needs eval and inline javascript :(
|
|
|
|
egw_framework::csp_script_src_attrs($attrs);
|
|
|
|
}
|
2010-06-25 12:01:53 +02:00
|
|
|
}
|