From 2f342bcf4ecdac87e1200709718a2cf4da633bf3 Mon Sep 17 00:00:00 2001 From: Kijin Sung Date: Sat, 1 Oct 2016 18:07:08 +0900 Subject: [PATCH] Enable additional CSS inside CKEditor --- modules/editor/editor.admin.controller.php | 12 ++++++++++++ modules/editor/editor.admin.view.php | 2 ++ modules/editor/editor.model.php | 8 ++++++++ modules/editor/lang/en.php | 2 ++ modules/editor/lang/ko.php | 2 ++ modules/editor/skins/ckeditor/editor.html | 7 ++++++- modules/editor/tpl/admin_index.html | 8 ++++++++ 7 files changed, 40 insertions(+), 1 deletion(-) diff --git a/modules/editor/editor.admin.controller.php b/modules/editor/editor.admin.controller.php index 89e944d41..5aa6b712b 100644 --- a/modules/editor/editor.admin.controller.php +++ b/modules/editor/editor.admin.controller.php @@ -164,6 +164,18 @@ class editorAdminController extends editor $config->font_defined = $configVars->font_defined = 'N'; $config->content_font = $configVars->content_font; } + + if ($configVars->additional_css) + { + $additional_css = array_map('trim', explode("\n", $configVars->additional_css)); + $additional_css = array_filter($additional_css, function($str) { return !empty($str); }); + $config->additional_css = $additional_css; + } + else + { + $config->additional_css = array(); + } + $config->content_font_size = trim($configVars->content_font_size); $config->content_font_size = ctype_digit($config->content_font_size) ? ($config->content_font_size . 'px') : $config->content_font_size; $config->content_line_height = trim($configVars->content_line_height); diff --git a/modules/editor/editor.admin.view.php b/modules/editor/editor.admin.view.php index e90ba5649..83cdeb99e 100644 --- a/modules/editor/editor.admin.view.php +++ b/modules/editor/editor.admin.view.php @@ -87,6 +87,7 @@ class editorAdminView extends editor $option->content_line_height = $config->content_line_height; $option->content_paragraph_spacing = $config->content_paragraph_spacing; $option->content_word_break = $config->content_word_break; + $option->additional_css = $config->additional_css ?: array(); $option->enable_autosave = false; $option->enable_default_component = true; $option->enable_component = true; @@ -108,6 +109,7 @@ class editorAdminView extends editor $option_com->content_line_height = $config->content_line_height; $option_com->content_paragraph_spacing = $config->content_paragraph_spacing; $option_com->content_word_break = $config->content_word_break; + $option_com->additional_css = $config->additional_css ?: array(); $option_com->enable_autosave = false; $option_com->enable_default_component = true; $option_com->enable_component = true; diff --git a/modules/editor/editor.model.php b/modules/editor/editor.model.php index fb71bffdf..c350d9e55 100644 --- a/modules/editor/editor.model.php +++ b/modules/editor/editor.model.php @@ -107,6 +107,10 @@ class editorModel extends editor { $editor_config->comment_content_style = ($editor_default_config->comment_content_style) ? $editor_default_config->comment_content_style : 'ckeditor_light'; } + if((!$editor_config->additional_css && $editor_default_config->additional_css) || $editor_config->default_editor_settings === 'Y') + { + $editor_config->additional_css = $editor_default_config->additional_css ?: array(); + } return $editor_config; } @@ -235,6 +239,7 @@ class editorModel extends editor Context::set('content_line_height', $option->content_line_height); Context::set('content_paragraph_spacing', $option->content_paragraph_spacing); Context::set('content_word_break', $option->content_word_break); + Context::set('editor_additional_css', $option->additional_css); // Option setting to allow auto-save if(!$option->enable_autosave) $enable_autosave = false; @@ -404,6 +409,7 @@ class editorModel extends editor $config->enable_html_grant = $editor_config->enable_html_grant; $config->editor_height = $editor_config->editor_height; $config->enable_autosave = $editor_config->enable_autosave; + $config->additional_css = $editor_config->additional_css; } else { @@ -421,6 +427,7 @@ class editorModel extends editor $config->enable_html_grant = $editor_config->enable_comment_html_grant; $config->editor_height = $editor_config->comment_editor_height; $config->enable_autosave = 'N'; + $config->additional_css = $editor_config->additional_css; } // Check a group_list of the currently logged-in user for permission check if(Context::get('is_logged')) @@ -442,6 +449,7 @@ class editorModel extends editor $option->content_line_height = $config->content_line_height; $option->content_paragraph_spacing = $config->content_paragraph_spacing; $option->content_word_break = $config->content_word_break; + $option->additional_css = $config->additional_css; $option->colorset = $config->sel_editor_colorset; // Permission check for file upload $option->allow_fileupload = false; diff --git a/modules/editor/lang/en.php b/modules/editor/lang/en.php index 0dde255e7..8d3f34e7d 100644 --- a/modules/editor/lang/en.php +++ b/modules/editor/lang/en.php @@ -7,6 +7,8 @@ $lang->guide_choose_main_editor = 'Main editor'; $lang->guide_set_height_main_editor = 'Main editor height'; $lang->guide_choose_comment_editor = 'Comment editor'; $lang->guide_set_height_comment_editor = 'Comment editor height'; +$lang->guide_additional_css = 'Additional CSS Files'; +$lang->about_additional_css = 'To load additional CSS files inside the editor, such as web fonts, please enter one URL per line.'; $lang->guide_choose_text_formatting = 'Text formatting style'; $lang->guide_choose_font_preview = 'Preview'; $lang->guide_choose_font_body = 'Default font'; diff --git a/modules/editor/lang/ko.php b/modules/editor/lang/ko.php index e3f322c8c..1895b882e 100644 --- a/modules/editor/lang/ko.php +++ b/modules/editor/lang/ko.php @@ -8,6 +8,8 @@ $lang->guide_choose_main_editor = '본문 에디터'; $lang->guide_set_height_main_editor = '본문 에디터 높이'; $lang->guide_choose_comment_editor = '댓글 에디터'; $lang->guide_set_height_comment_editor = '댓글 에디터 높이'; +$lang->guide_additional_css = 'CSS 파일 추가'; +$lang->about_additional_css = '웹폰트 등의 CSS를 에디터 내부에서 추가로 로딩하려면 한 줄에 하나씩 URL을 입력해 주십시오.'; $lang->guide_choose_text_formatting = '본문 서식'; $lang->guide_choose_font_preview = '미리보기'; $lang->guide_choose_font_body = '본문 글꼴'; diff --git a/modules/editor/skins/ckeditor/editor.html b/modules/editor/skins/ckeditor/editor.html index 93487caef..a597faef5 100644 --- a/modules/editor/skins/ckeditor/editor.html +++ b/modules/editor/skins/ckeditor/editor.html @@ -12,6 +12,11 @@ var auto_saved_msg = "{$lang->msg_auto_saved}"; +{@ $css_file_list = array(Context::getRequestUri() . $content_style_path . '/editor.css?' . date("YmdHis", @filemtime($content_style_path."/editor.css")))} + + {@ $css_file_list[] = $additional_css_url} + + {@ $css_content = null } {@ $css_content .= ' .xe_content.editable { '} @@ -88,7 +93,7 @@ var auto_saved_msg = "{$lang->msg_auto_saved}"; ckeconfig: { height: '{$m ? 160 : $editor_height}', skin: '{$colorset}', - contentsCss: '{$content_style_path}/editor.css?{date("YmdHis", @filemtime($content_style_path."/editor.css"))}', + contentsCss: {json_encode($css_file_list)}, xe_editor_sequence: {$editor_sequence}, font_defaultLabel: default_font_name, font_names: font_list, diff --git a/modules/editor/tpl/admin_index.html b/modules/editor/tpl/admin_index.html index 544e2f450..367f1c051 100644 --- a/modules/editor/tpl/admin_index.html +++ b/modules/editor/tpl/admin_index.html @@ -113,6 +113,14 @@ +
+ +
+ {@ var_dump($editor_config)} + +

{$lang->about_additional_css}

+
+