function ckeditor_profile_settings_compile in CKEditor - WYSIWYG HTML editor 7
Compile settings of profile
Parameters
object $global_profile:
object $profile:
Return value
array
1 call to ckeditor_profile_settings_compile()
- ckeditor_profiles_compile in includes/
ckeditor.lib.inc - Compile settings of all profiles at returns is as array
File
- includes/
ckeditor.lib.inc, line 586 - CKEditor - The text editor for the Internet - http://ckeditor.com Copyright (c) 2003-2013, CKSource - Frederico Knabben. All rights reserved.
Code
function ckeditor_profile_settings_compile($global_profile, $profile) {
global $user, $language, $theme;
$current_theme = variable_get('theme_default', $theme);
$settings = array();
$conf = $profile->settings;
$profile_name = $profile->name;
if (user_access('customize ckeditor')) {
foreach (array(
'default',
'show_toggle',
'width',
'lang',
'auto_lang',
) as $setting) {
$conf[$setting] = ckeditor_user_get_setting($user, $profile, $setting);
}
}
if (!isset($conf['ss'])) {
$conf['ss'] = 2;
}
$themepath = drupal_get_path('theme', $current_theme) . '/';
$host = base_path();
// setting some variables
$module_drupal_path = ckeditor_module_path('relative');
$module_drupal_local_path = ckeditor_module_path('local');
$editor_path = ckeditor_path('relative');
$editor_local_path = ckeditor_path('local');
$skins_path = ckeditor_skins_path('relative');
$skins_local_path = ckeditor_skins_path('local');
$toolbar = $conf['toolbar'];
$query_string = '?' . variable_get('css_js_query_string', '0');
$config_js = isset($conf['config_js']) ? $conf['config_js'] : 'none';
switch ($config_js) {
case 'theme':
$ckeditor_config_path = $host . $themepath . 'ckeditor.config.js' . $query_string;
break;
case 'self':
$config_js_path = trim(str_replace("%h%t", "%t", $conf['config_js_path']));
$config_js_path = str_replace(array(
'%h',
'%t',
), array(
$host,
$host . $themepath,
), $config_js_path);
$ckeditor_config_path = $config_js_path . $query_string;
break;
case 'none':
default:
$ckeditor_config_path = $module_drupal_path . "/ckeditor.config.js" . $query_string;
break;
}
$settings['customConfig'] = $ckeditor_config_path;
$settings['defaultLanguage'] = $conf['lang'];
$settings['toolbar'] = $toolbar;
$settings['enterMode'] = constant("CKEDITOR_ENTERMODE_" . strtoupper($conf['enter_mode']));
$settings['shiftEnterMode'] = constant("CKEDITOR_ENTERMODE_" . strtoupper($conf['shift_enter_mode']));
$settings['toolbarStartupExpanded'] = $conf['expand'] == 't';
if ($conf['expand'] == 'f') {
$settings['toolbarCanCollapse'] = true;
}
$settings['width'] = $conf['width'];
//check if skin exists, if not select default one
if (isset($global_profile->settings['skin']) && file_exists($editor_local_path . '/skins/' . $global_profile->settings['skin']) || isset($global_profile->settings['skin']) && $editor_local_path == '<URL>') {
$settings['skin'] = $global_profile->settings['skin'];
// Check if skin exists, if not select default one
if (isset($global_profile->settings['skin'])) {
// If the skin exists, check if local file is present
if (file_exists($skins_local_path . '/' . $global_profile->settings['skin'])) {
// If editor is local, set skin as profile value
if ($editor_local_path != '<URL>') {
$settings['skin'] = $global_profile->settings['skin'];
}
else {
if ($editor_path == '<URL>' && $editor_local_path == '<URL>') {
$settings['skin'] = $global_profile->settings['skin'] . ',' . $skins_path . '/' . $global_profile->settings['skin'] . '/';
}
else {
$settings['skin'] = ckeditor_default_skin();
}
}
}
else {
// If no local skin file, check if editor is hosted remotely
if ($editor_path == '<URL>' && $editor_local_path == '<URL>') {
$settings['skin'] = $global_profile->settings['skin'];
}
else {
$settings['skin'] = ckeditor_default_skin();
}
}
}
}
else {
$settings['skin'] = ckeditor_default_skin();
}
$settings['format_tags'] = $conf['font_format'];
$settings['show_toggle'] = $conf['show_toggle'];
$settings['default'] = $conf['default'];
if (!empty($conf['allowed_content']) && $conf['allowed_content'] === 'f') {
$settings['allowedContent'] = true;
}
elseif (!empty($conf['extraAllowedContent'])) {
$settings['extraAllowedContent'] = $conf['extraAllowedContent'];
}
$settings['ss'] = $conf['ss'];
if (isset($conf['language_direction'])) {
switch ($conf['language_direction']) {
case 'default':
if (defined('LANGUAGE_RTL') && $language->direction == LANGUAGE_RTL) {
$settings['contentsLangDirection'] = 'rtl';
}
break;
case 'ltr':
$settings['contentsLangDirection'] = 'ltr';
break;
case 'rtl':
$settings['contentsLangDirection'] = 'rtl';
break;
}
}
if (isset($conf['loadPlugins'])) {
$settings['loadPlugins'] = ckeditor_plugins_render($conf['loadPlugins']);
}
else {
$settings['loadPlugins'] = array();
}
//add support for divarea plugin from CKE4
if (isset($conf['use_divarea']) && $conf['use_divarea'] == 't' && $editor_local_path != '<URL>' && file_exists($editor_local_path . '/plugins/divarea/plugin.js')) {
$settings['loadPlugins']['divarea'] = array(
'name' => 'divarea',
'path' => $editor_path . '/plugins/divarea/',
'buttons' => FALSE,
'default' => 'f',
);
}
if (isset($conf['html_entities']) && $conf['html_entities'] == 'f') {
$settings['entities'] = FALSE;
$settings['entities_greek'] = FALSE;
$settings['entities_latin'] = FALSE;
}
if (isset($conf['scayt_autoStartup']) && $conf['scayt_autoStartup'] == 't') {
$settings['scayt_autoStartup'] = TRUE;
}
else {
$settings['scayt_autoStartup'] = FALSE;
}
if ($conf['auto_lang'] == "f") {
$settings['language'] = $conf['lang'];
//[#1473010]
$settings['scayt_sLang'] = ckeditor_scayt_langcode($conf['lang']);
}
if (isset($conf['forcePasteAsPlainText']) && $conf['forcePasteAsPlainText'] == 't') {
$settings['forcePasteAsPlainText'] = TRUE;
}
if (isset($conf['custom_formatting']) && $conf['custom_formatting'] == 't') {
foreach ($conf['formatting']['custom_formatting_options'] as $k => $v) {
if ($v === 0) {
$conf['formatting']['custom_formatting_options'][$k] = FALSE;
}
else {
$conf['formatting']['custom_formatting_options'][$k] = TRUE;
}
}
$settings['output_pre_indent'] = $conf['formatting']['custom_formatting_options']['pre_indent'];
unset($conf['formatting']['custom_formatting_options']['pre_indent']);
$settings['custom_formatting'] = $conf['formatting']['custom_formatting_options'];
}
// add code for filebrowser for users that have access
$filebrowser = !empty($conf['filebrowser']) ? $conf['filebrowser'] : 'none';
$filebrowser_image = !empty($conf['filebrowser_image']) ? $conf['filebrowser_image'] : $filebrowser;
$filebrowser_flash = !empty($conf['filebrowser_flash']) ? $conf['filebrowser_flash'] : $filebrowser;
if ($filebrowser == 'imce' && !module_exists('imce')) {
$filebrowser = 'none';
}
if ($filebrowser == 'elfinder' && !module_exists('elfinder')) {
$filebrowser = 'none';
}
/* MODULES NOT PORTED TO D7
if ($filebrowser == 'tinybrowser' && !module_exists('tinybrowser')) {
$filebrowser = 'none';
}
if ($filebrowser == 'ib' && !module_exists('imagebrowser')) {
$filebrowser = 'none';
}
if ($filebrowser == 'webfm' && !module_exists('webfm_popup')) {
$filebrowser = 'none';
}
*/
if ($filebrowser_image != $filebrowser) {
if ($filebrowser_image == 'imce' && !module_exists('imce')) {
$filebrowser_image = $filebrowser;
}
if ($filebrowser_image == 'elfinder' && !module_exists('elfinder')) {
$filebrowser_image = $filebrowser;
}
/* MODULES NOT PORTED TO D7
if ($filebrowser_image == 'tinybrowser' && !module_exists('tinybrowser')) {
$filebrowser_image = $filebrowser;
}
if ($filebrowser_image == 'ib' && !module_exists('imagebrowser')) {
$filebrowser_image = $filebrowser;
}
if ($filebrowser_image == 'webfm' && !module_exists('webfm_popup')) {
$filebrowser_image = $filebrowser;
}
*/
}
if ($filebrowser_flash != $filebrowser) {
if ($filebrowser_flash == 'imce' && !module_exists('imce')) {
$filebrowser_flash = $filebrowser;
}
if ($filebrowser_image == 'elfinder' && !module_exists('elfinder')) {
$filebrowser_flash = $filebrowser;
}
/* MODULES NOT PORTED TO D7
if ($filebrowser_image == 'tinybrowser' && !module_exists('tinybrowser')) {
$filebrowser_flash = $filebrowser;
}
if ($filebrowser_flash == 'ib' && !module_exists('imagebrowser')) {
$filebrowser_flash = $filebrowser;
}
if ($filebrowser_flash == 'webfm' && !module_exists('webfm_popup')) {
$filebrowser_flash = $filebrowser;
}
*/
}
if ($filebrowser == 'ckfinder' || $filebrowser_image == 'ckfinder' || $filebrowser_flash == 'ckfinder') {
if (user_access('allow CKFinder file uploads')) {
if (!empty($profile->settings['UserFilesPath'])) {
$_SESSION['ckeditor'][$profile_name]['UserFilesPath'] = strtr($profile->settings['UserFilesPath'], array(
"%f" => variable_get('file_public_path', conf_path() . '/files'),
"%u" => $user->uid,
"%b" => $host,
"%n" => $user->name,
));
}
else {
$_SESSION['ckeditor'][$profile_name]['UserFilesPath'] = strtr('%b%f/', array(
"%f" => variable_get('file_public_path', conf_path() . '/files'),
"%u" => $user->uid,
"%b" => $host,
"%n" => $user->name,
));
}
if (!empty($profile->settings['UserFilesAbsolutePath'])) {
$_SESSION['ckeditor'][$profile_name]['UserFilesAbsolutePath'] = strtr($profile->settings['UserFilesAbsolutePath'], array(
"%f" => variable_get('file_public_path', conf_path() . '/files'),
"%u" => $user->uid,
"%b" => base_path(),
"%d" => ckeditor_get_document_root_full_path(),
"%n" => $user->name,
));
}
else {
$_SESSION['ckeditor'][$profile_name]['UserFilesAbsolutePath'] = strtr('%d%b%f/', array(
"%f" => variable_get('file_public_path', conf_path() . '/files'),
"%u" => $user->uid,
"%b" => base_path(),
"%d" => ckeditor_get_document_root_full_path(),
"%n" => $user->name,
));
}
if (variable_get('file_default_scheme', '') == 'private') {
$private_dir = isset($global_profile->settings['private_dir']) ? trim($global_profile->settings['private_dir'], '/') : '';
if (!empty($private_dir)) {
$private_dir = strtr($private_dir, array(
'%u' => $user->uid,
'%n' => $user->name,
));
$_SESSION['ckeditor'][$profile_name]['UserFilesPath'] = url('system/files') . '/' . $private_dir . '/';
$private_upload_path = file_uri_target('private://' . variable_get('file_private_path', '')) . '/' . $private_dir;
}
else {
$_SESSION['ckeditor'][$profile_name]['UserFilesPath'] = url('system/files') . '/';
$private_upload_path = file_uri_target('private://' . variable_get('file_private_path', ''));
}
//add '/' to beginning of path if necessary
if (strpos(variable_get('file_private_path', ''), '/') === 0 && $private_upload_path[0] != '/') {
$private_upload_path = '/' . $private_upload_path;
}
//check if CKEditor private dir exists and create it if not
if ($private_dir && !is_dir($private_upload_path)) {
mkdir($private_upload_path, 0755, TRUE);
}
$_SESSION['ckeditor'][$profile_name]['UserFilesAbsolutePath'] = drupal_realpath($private_upload_path) . '/';
}
}
}
/* MODULES NOT PORTED TO D7
if (in_array('tinybrowser', array($filebrowser, $filebrowser_image, $filebrowser_flash))) {
$popup_win_size = variable_get('tinybrowser_popup_window_size', '770x480');
if (!preg_match('#\d+x\d+#is', $popup_win_size)) {
$popup_win_size = '770x480';
}
$popup_win_size = trim($popup_win_size);
$popup_win_size = strtolower($popup_win_size);
$win_size = split('x', $popup_win_size);
}
*/
switch ($filebrowser) {
case 'ckfinder':
if (user_access('allow CKFinder file uploads')) {
$ckfinder_full_path = ckfinder_path('relative');
$settings['filebrowserBrowseUrl'] = $ckfinder_full_path . '/ckfinder.html?id=' . $profile_name;
$settings['filebrowserImageBrowseUrl'] = $ckfinder_full_path . '/ckfinder.html?Type=Images&id=' . $profile_name;
$settings['filebrowserFlashBrowseUrl'] = $ckfinder_full_path . '/ckfinder.html?Type=Flash&id=' . $profile_name;
$settings['filebrowserUploadUrl'] = $ckfinder_full_path . '/core/connector/php/connector.php?command=QuickUpload&type=Files&id=' . $profile_name;
$settings['filebrowserImageUploadUrl'] = $ckfinder_full_path . '/core/connector/php/connector.php?command=QuickUpload&type=Images&id=' . $profile_name;
$settings['filebrowserFlashUploadUrl'] = $ckfinder_full_path . '/core/connector/php/connector.php?command=QuickUpload&type=Flash&id=' . $profile_name;
}
break;
case 'imce':
$settings['filebrowserBrowseUrl'] = url('imce', array(
'query' => array(
'app' => 'ckeditor|sendto@ckeditor_imceSendTo|',
),
));
break;
case 'elfinder':
$settings['filebrowserBrowseUrl'] = $host . "index.php?q=elfinder&app=ckeditor";
break;
}
if ($filebrowser_image != $filebrowser) {
switch ($filebrowser_image) {
case 'ckfinder':
if (user_access('allow CKFinder file uploads')) {
$ckfinder_full_path = ckfinder_path('relative');
$settings['filebrowserImageBrowseUrl'] = $ckfinder_full_path . '/ckfinder.html?Type=Images&id=' . $profile_name;
$settings['filebrowserImageUploadUrl'] = $ckfinder_full_path . '/core/connector/php/connector.php?command=QuickUpload&type=Images&id=' . $profile_name;
}
break;
case 'imce':
$settings['filebrowserImageBrowseUrl'] = url('imce', array(
'query' => array(
'app' => 'ckeditor|sendto@ckeditor_imceSendTo|',
),
));
break;
case 'elfinder':
$settings['filebrowserImageBrowseUrl'] = $host . "index.php?q=elfinder&app=ckeditor";
break;
}
}
if ($filebrowser_flash != $filebrowser) {
switch ($filebrowser_flash) {
case 'ckfinder':
if (user_access('allow CKFinder file uploads')) {
$ckfinder_full_path = ckfinder_path('relative');
$settings['filebrowserFlashBrowseUrl'] = $ckfinder_full_path . '/ckfinder.html?Type=Images&id=' . $profile_name;
$settings['filebrowserFlashUploadUrl'] = $ckfinder_full_path . '/core/connector/php/connector.php?command=QuickUpload&type=Images&id=' . $profile_name;
}
break;
case 'imce':
$settings['filebrowserFlashBrowseUrl'] = url('imce', array(
'query' => array(
'app' => 'ckeditor|sendto@ckeditor_imceSendTo|',
),
));
break;
case 'elfinder':
$settings['filebrowserFlashBrowseUrl'] = $host . "index.php?q=elfinder&app=ckeditor";
break;
}
}
if (!empty($conf['js_conf'])) {
// CKEDITOR.dtd holds and object representation of the HTML DTD to be used by the editor in its internal operations.
// See more at https://ckeditor.com/docs/ckeditor4/latest/api/CKEDITOR_dtd.html
$dtd = [];
$js_conf = $conf['js_conf'];
// Remove multiple-line JavaScript comment blocks.
$js_conf = preg_replace('#^/\\*(?:[^*]*(?:\\*(?!/))*)*\\*/#m', '', $js_conf);
// Remove single-line JavaScript comments.
$js_conf = preg_replace('#([;,{}()\\[\\]]|[\\s\\t]+)//.*[ \\t]*#m', '', $js_conf);
// Remove empty lines.
$js_conf = preg_replace("/(^[\r\n]*|[\r\n]+)[\\s\t]*[\r\n]+/", '', $js_conf);
preg_match_all('#config\\.(\\w+)[\\s]*=[\\s]*(.+?)[\\s]*(?=(^[\\s]*|;[\\s]*)config\\.|$)#is', $js_conf, $matches);
foreach ($matches[2] as $i => $match) {
if (!empty($match)) {
$match = rtrim($match, ';') . ';';
// Custom processing is required for lines that manipulate existing
// CKEditor object variables.
preg_match_all('#(CKEDITOR\\.+[\\w\\.\\$]+[\\s]*)=[\\s]*(.+?);[\\s]*(?=CKEDITOR\\.|\\/\\/|\\/*$)#is', $match, $sub_matches);
if (!empty($sub_matches[2])) {
foreach ($sub_matches[2] as $j => $sub_match) {
$match = str_replace($sub_matches[0][$j], '', $match);
$dtd[$sub_matches[1][$j]] = $sub_match;
}
}
$value = trim($match, " ;\n\r\t\0\v");
// Custom processing is required for Javascript boolean assignment and
// string concatenation operations.
if (strcasecmp($value, 'true') == 0) {
$value = TRUE;
}
elseif (strcasecmp($value, 'false') == 0) {
$value = FALSE;
}
elseif (preg_match('#["|\'][\\s]*\\+[\\s]*["|\']#is', $value)) {
// Special case for JS concatenated strings.
// For example, one can have config.colorButton_colors defined as below, which would cause parsing problems.
// config.colorButton_colors = 'B3B3B3,'+'000,800000,696969,'+'F00,FF8C00'
// This regex will replace it into single string:
// config.colorButton_colors = 'B3B3B3,000,800000,696969,F00,FF8C00'
$value = preg_replace('#["|\'][\\s]*\\+[\\s]*["|\']#', '', $value);
}
$settings['js_conf'][$matches[1][$i]] = $value;
}
}
if (!empty($dtd)) {
$settings['js_conf']['dtd'] = $dtd;
}
}
$settings['stylesCombo_stylesSet'] = "drupal:" . $module_drupal_path . '/ckeditor.styles.js' . $query_string;
if (!empty($conf['css_style'])) {
if ($conf['css_style'] == 'theme' && file_exists($themepath . 'ckeditor.styles.js')) {
$settings['stylesCombo_stylesSet'] = "drupal:" . $host . $themepath . 'ckeditor.styles.js' . $query_string;
}
elseif (!empty($conf['css_style']) && $conf['css_style'] == 'self') {
$conf['styles_path'] = str_replace("%h%t", "%t", $conf['styles_path']);
$settings['stylesCombo_stylesSet'] = "drupal:" . str_replace(array(
'%h',
'%t',
'%m',
), array(
$host,
$host . $themepath,
$module_drupal_path,
), $conf['styles_path']) . $query_string;
}
}
// add custom stylesheet if configured
// lets hope it exists but we'll leave that to the site admin
$css_files = array();
switch ($conf['css_mode']) {
case 'theme':
_ckeditor_add_css_from_theme($current_theme, $css_files);
break;
case 'self':
if (file_exists($module_drupal_local_path . '/css/ckeditor.css')) {
$css_files[] = $module_drupal_path . '/css/ckeditor.css' . $query_string;
if (defined('LANGUAGE_RTL') && $language->direction == LANGUAGE_RTL) {
if (file_exists($module_drupal_local_path . '/css/ckeditor-rtl.css')) {
$css_files[] = $module_drupal_path . '/css/ckeditor-rtl.css' . $query_string;
}
}
}
foreach (explode(',', $conf['css_path']) as $css_path) {
$css_path = trim(str_replace("%h%t", "%t", $css_path));
$css_files[] = str_replace(array(
'%h',
'%t',
), array(
$host,
$host . $themepath,
), $css_path) . $query_string;
}
break;
case 'none':
if (file_exists($module_drupal_local_path . '/css/ckeditor.css')) {
$css_files[] = $module_drupal_path . '/css/ckeditor.css' . $query_string;
if (defined('LANGUAGE_RTL') && $language->direction == LANGUAGE_RTL) {
if (file_exists($module_drupal_local_path . '/css/ckeditor-rtl.css')) {
$css_files[] = $module_drupal_path . '/css/ckeditor-rtl.css' . $query_string;
}
}
}
if ($editor_local_path != '<URL>') {
if (file_exists($editor_local_path . '/contents.css')) {
$css_files[] = $editor_path . '/contents.css' . $query_string;
}
}
else {
$editor_url_path = ckeditor_path('url');
$css_files[] = $editor_url_path . '/contents.css' . $query_string;
}
break;
}
if (isset($conf['ckeditor_load_method']) && $conf['ckeditor_load_method'] == 'ckeditor_source.js') {
foreach ($css_files as $k => $v) {
$css_files[$k] = $v . '&t=' . time();
}
}
$settings['contentsCss'] = array_values($css_files);
if (!empty($conf['uicolor']) && $conf['uicolor'] == "custom" && !empty($conf['uicolor_user'])) {
$settings['uiColor'] = $conf['uicolor_user'];
}
if (!empty($conf['uicolor']) && strpos($conf['uicolor'], "color_") === 0) {
if (function_exists('color_get_palette')) {
$palette = @color_get_palette($current_theme, FALSE);
//[#652274]
$color = str_replace("color_", "", $conf['uicolor']);
if (!empty($palette[$color])) {
$settings['uiColor'] = $palette[$color];
}
}
}
if (!empty($settings['loadPlugins'])) {
// Remove orphaned plugins (coming from disabled modules).
$available_plugins = array_keys(ckeditor_load_plugins());
$settings['loadPlugins'] = array_intersect_key($settings['loadPlugins'], array_flip($available_plugins));
}
// Allow modules to modify the settings.
drupal_alter('ckeditor_settings', $settings, $conf);
return $settings;
}