From 90a6f8bb5e41de7b56b2c8187631c892ff447f0d Mon Sep 17 00:00:00 2001 From: Arcturus Date: Mon, 23 Sep 2024 01:49:25 +0900 Subject: [PATCH] add wysiwyg editor in setting.class.php --- .../classes/setting/setting.class.php | 88 +++++++++++++++++++ 1 file changed, 88 insertions(+) diff --git a/AvocadoEdition_Light/classes/setting/setting.class.php b/AvocadoEdition_Light/classes/setting/setting.class.php index d93820e..458f233 100644 --- a/AvocadoEdition_Light/classes/setting/setting.class.php +++ b/AvocadoEdition_Light/classes/setting/setting.class.php @@ -9,8 +9,10 @@ */ class Setting { + public static $fonts; public $idx; public $html; + public $extrahtml; public $settings; public $title; public $cs_id; @@ -45,6 +47,7 @@ class Setting $this->cs_name = $name; $this->title = $title; $this->html = ""; + $this->extrahtml = ""; $this->is_value_added = false; if ($init) { $this->init(); @@ -62,6 +65,9 @@ class Setting case "textarea": $this->addTextareaSetting($val["desc"], array_key_exists("default", $val) ? (is_array($val["default"]) ? $val["default"] : []) : [], array_key_exists("placeholder", $val) ? $val["placeholder"] : ""); break; + case "editor": + $this->addEditorSetting($val["desc"], array_key_exists("default", $val) ? (is_array($val["default"]) ? $val["default"] : []) : [], array_key_exists("js", $val) ? $val["js"] : true); + break; case "image": $this->addImageSetting($val["desc"], array_key_exists("default", $val) ? (is_array($val["default"]) ? $val["default"] : []) : []); break; @@ -153,6 +159,7 @@ class Setting switch ($setting["type"]) { case "image": case "text": + case "editor": case "desc": break; case "color": @@ -197,6 +204,18 @@ class Setting $this->is_value_added = true; } + public function addEditorSetting($desc, $default, $js) + { + if ($this->is_value_added) + return; + $this->settings[] = [ + "type" => "editor", + "html" => "{$desc}
" . $this->editor_html($this->cs_name, "cs_value[{$this->idx}]", get_text($this->cs_value, 0)) . "
" + ]; + $this->is_value_added = true; + $this->extrahtml = $this->get_editor_js($this->cs_name, "cs_value[{$this->idx}]"); + } + public function addImageSetting($desc, $default) { if ($this->is_value_added) @@ -392,4 +411,73 @@ class Setting } return $html; } + + public function get_editor_js($id, $is_dhtml_editor = true) + { + if ($is_dhtml_editor) { + $js = "var {$id}_editor_data = oEditors.getById['{$id}'].getIR();\n"; + $js .= "oEditors.getById['{$id}'].exec('UPDATE_CONTENTS_FIELD', []);\n"; + $js .= "if (jQuery.inArray(document.getElementById('{$id}').value.toLowerCase().replace(/^\s*|\s*$/g, ''), [' ','

 

','


','

','

','
','']) != -1) {\n"; + $js .= "document.getElementById('{$id}').value='';\n"; + $js .= "}\n"; + return $js; + } else { + return "var {$id}_editor = document.getElementById('{$id}');\n"; + } + } + + public function editor_html($id, $key, $content, $js = true, $is_dhtml_editor = true, $maxlength = 65536) + { + global $g5, $config, $w, $board, $write, $js; + + if ( + $is_dhtml_editor && $content && + ( + (!$w && (isset($board['bo_insert_content']) && !empty($board['bo_insert_content']))) + || ($w == 'u' && isset($write['wr_option']) && strpos($write['wr_option'], 'html') === false) + ) + ) { + if (preg_match('/\r|\n/', $content) && $content === strip_tags($content, '')) { + $content = nl2br($content); + } + } + + $editor_url = G5_EDITOR_URL . '/' . $config['cf_editor']; + + $html = ""; + $html .= "웹에디터 시작"; + + if ($is_dhtml_editor && $js) { + $html .= "\n"; + $html .= "\n"; + $html .= "\n"; + $js = false; + } + + $smarteditor_class = $is_dhtml_editor ? "smarteditor2" : ""; + $html .= "\n"; + $html .= "\n웹 에디터 끝"; + return $html; + } }