AvocadoAmber/AvocadoAmber/classes/setting/setting.class.php
2025-11-29 01:39:58 +09:00

858 lines
32 KiB
PHP

<?php
/**
* THIS MODULE PROHIBITS DISTRIBUTION TO OTHERS WITHOUT AUTHOR'S PERMISSION.
* @class Setting
* @author amberstone ( contact@drk.st / https://amberst.one )
* @brief gnuboard config extend class
* @version 1.1.2
* @license LGPL 2.1
*/
class Setting
{
public static $etc_max = 20;
public static $fonts;
public $idx;
public $html;
public $extrahtml;
public $settings;
public $title;
public $cs_id;
public $cs_name;
public $cs_value;
public $cs_descript;
public $cs_etc_1;
public $cs_etc_2;
public $cs_etc_3;
public $cs_etc_4;
public $cs_etc_5;
public $cs_etc_6;
public $cs_etc_7;
public $cs_etc_8;
public $cs_etc_9;
public $cs_etc_10;
public $cs_etc_11;
public $cs_etc_12;
public $cs_etc_13;
public $cs_etc_14;
public $cs_etc_15;
public $cs_etc_16;
public $cs_etc_17;
public $cs_etc_18;
public $cs_etc_19;
public $cs_etc_20;
public $is_value_added;
public function __construct($idx, $title, $name, $data = [], $init = true)
{
$this->idx = $idx;
$this->cs_name = $name;
$this->title = $title;
$this->html = "";
$this->extrahtml = "";
$this->is_value_added = false;
if ($init) {
$this->init();
}
if (!empty($data)) {
foreach ($data as $val) {
$this->addSetting($val);
}
}
}
public function addSetting($set)
{
switch ($set["type"]) {
case "desc":
$this->addDescription($set["desc"], array_key_exists("default", $set) ? (is_array($set["default"]) ? $set["default"] : []) : []);
break;
case "text":
$this->addTextSetting($set["desc"], array_key_exists("default", $set) ? (is_array($set["default"]) ? $set["default"] : []) : [], array_key_exists("placeholder", $set) ? $set["placeholder"] : "");
break;
case "textarea":
$this->addTextareaSetting($set["desc"], array_key_exists("default", $set) ? (is_array($set["default"]) ? $set["default"] : []) : [], array_key_exists("placeholder", $set) ? $set["placeholder"] : "");
break;
case "editor":
$this->addEditorSetting($set["desc"], array_key_exists("default", $set) ? (is_array($set["default"]) ? $set["default"] : []) : [], array_key_exists("js", $set) ? $set["js"] : true);
break;
case "image":
$this->addImageSetting($set["desc"], array_key_exists("default", $set) ? (is_array($set["default"]) ? $set["default"] : []) : []);
break;
case "select":
$this->addSelectSetting($set["desc"], array_key_exists("default", $set) ? (is_array($set["default"]) ? $set["default"] : []) : [], array_key_exists("values", $set) ? $set["values"] : "");
break;
case "color":
$this->addColorSetting($set["desc"], array_key_exists("default", $set) ? (is_array($set["default"]) ? $set["default"] : []) : []);
break;
case "color2":
$this->addColor2Setting($set["desc"], array_key_exists("default", $set) ? (is_array($set["default"]) ? $set["default"] : []) : []);
break;
case "color3":
$this->addBackForeLine($set["desc"], array_key_exists("default", $set) ? (is_array($set["default"]) ? $set["default"] : []) : []);
break;
case "border":
$this->addBorderSetting($set["desc"], array_key_exists("default", $set) ? (is_array($set["default"]) ? $set["default"] : []) : []);
break;
case "border2":
$this->addBorder2Setting($set["desc"], array_key_exists("default", $set) ? (is_array($set["default"]) ? $set["default"] : []) : []);
break;
case "rect":
$this->addRectSetting($set["desc"], array_key_exists("default", $set) ? (is_array($set["default"]) ? $set["default"] : []) : []);
break;
case "radius":
$this->addRadiusSetting($set["desc"], array_key_exists("default", $set) ? (is_array($set["default"]) ? $set["default"] : []) : []);
break;
case "margin":
$this->addMarginSetting($set["desc"], array_key_exists("default", $set) ? (is_array($set["default"]) ? $set["default"] : []) : []);
break;
case "font":
$this->addFontSetting($set["desc"], array_key_exists("default", $set) ? (is_array($set["default"]) ? $set["default"] : "") : []);
break;
case "fontsize":
$this->addFontSizeSetting($set["desc"], array_key_exists("default", $set) ? (is_array($set["default"]) ? $set["default"] : "16") : []);
break;
case "number":
$this->addNumberSetting($set["desc"], array_key_exists("default", $set) ? $set["default"] : "0");
break;
case "background":
$this->addBackgroundSetting($set["desc"], array_key_exists("default", $set) ? (is_array($set["default"]) ? $set["default"] : []) : []);
break;
}
}
public static function getSettingList()
{
global $g5;
$css = [];
$sql = sql_query("SELECT * FROM {$g5['css_table']}");
while ($row = sql_fetch_array($sql)) {
$set = new Setting(0, "", "", [], false);
$set->cs_id = $row['cs_id'];
$set->cs_value = $row['cs_value'];
$set->cs_name = $row['cs_name'];
$set->cs_descript = $row['cs_descript'];
for ($i = 1; $i <= self::$etc_max; $i++) {
$key = "cs_etc_{$i}";
$set->$key = $row[$key];
}
$css[$row['cs_name']] = $set;
}
return $css;
}
public static function getSetting($cs_name)
{
global $g5;
$row = sql_fetch("SELECT * FROM {$g5['css_table']} WHERE cs_name = '{$cs_name}'");
$set = new Setting(0, "", "", [], false);
$set->cs_id = $row['cs_id'];
$set->cs_value = $row['cs_value'];
$set->cs_name = $row['cs_name'];
$set->cs_descript = $row['cs_descript'];
for ($i = 1; $i <= self::$etc_max; $i++) {
$key = "cs_etc_{$i}";
$set->$key = $row[$key];
}
return $set;
}
public function init()
{
global $g5;
$this->settings = [];
$data = sql_fetch("SELECT * FROM {$g5['css_table']} WHERE cs_name = '{$this->cs_name}'");
if ($data) {
$this->cs_id = intval($data['cs_id']);
$this->cs_name = $data['cs_name'];
$this->cs_value = $data['cs_value'];
$this->cs_descript = $data['cs_descript'];
for ($i = 1; $i <= self::$etc_max; $i++) {
$key = "cs_etc_{$i}";
$this->$key = $data[$key];
}
} else {
$this->cs_value = "";
$this->cs_descript = "";
for ($i = 1; $i <= self::$etc_max; $i++) {
$key = "cs_etc_{$i}";
$this->$key = "";
}
}
}
public function addHeader()
{
$count = count(array_filter($this->settings, function ($setting) {
return $setting["type"] != "image";
}));
$count += count(array_filter($this->settings, function ($setting) {
return $setting["type"] == "image";
})) ? 2 : 0;
$count += count(array_filter($this->settings, function ($setting) {
return $setting["type"] == "background";
})) ? 3 : 0;
$count += count(array_filter($this->settings, function ($setting) {
return $setting["type"] == "color3";
})) ? 2 : 0;
return "<tr><th rowspan=\"{$count}\" scope=\"row\"><em>{$this->idx}</em>{$this->title}<input type=\"text\" name=\"cs_name[{$this->idx}]\" value=\"{$this->cs_name}\" readonly size=\"15\" /></th>";
}
public function getCurrentCount()
{
$count = 0;
foreach ($this->settings as $setting) {
switch ($setting["type"]) {
case "image":
case "text":
case "editor":
case "desc":
break;
case "color":
case "border":
$count += 2;
break;
case "border2":
case "color3":
$count += 3;
break;
default:
$count++;
break;
}
}
return $count;
}
public function addDescription($text, $default)
{
$this->settings[] = [
"type" => "desc",
"html" => "<td colspan=\"2\" style=\"color: #C66; font-size: 13px; background: #fff0f0\">{$text}</td></tr>"
];
}
public function addTextSetting($desc, $default, $placeholder)
{
if ($this->is_value_added)
return;
$this->settings[] = [
"type" => "text",
"html" => "<td class=\"bo-right\">{$desc}</td><td><div class=\"setter\"><input type=\"text\" name=\"cs_value[{$this->idx}]\" value=\"{$this->cs_value}\" size=\"100\" placeholder=\"{$placeholder}\" /></div></td></tr>"
];
$this->is_value_added = true;
}
public function addTextareaSetting($desc, $default, $placeholder)
{
if ($this->is_value_added)
return;
$this->settings[] = [
"type" => "text",
"html" => "<td class=\"bo-right\">{$desc}</td><td><div class=\"setter\"><textarea name=\"cs_value[{$this->idx}]\" placeholder=\"{$placeholder}\">{$this->cs_value}</textarea></div></td></tr>"
];
$this->is_value_added = true;
}
public function addEditorSetting($desc, $default, $js)
{
if ($this->is_value_added)
return;
$this->settings[] = [
"type" => "editor",
"html" => "<td class=\"bo-right\">{$desc}</td><td><div class=\"setter\">" . $this->editor_html($this->cs_name, "cs_value[{$this->idx}]", get_text($this->cs_value, 0)) . "</div></td></tr>"
];
$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)
return;
$image_set = $this->cs_value != "" ? "<img src=\"{$this->cs_value}\" class=\"prev_thumb\">" : "{$desc} 이미지 미등록";
$this->settings[] = [
"type" => "image",
"html" => "<td rowspan=\"2\" class=\"bo-right\">{$image_set}</td><td><div class=\"setter\">직접등록<input type=\"file\" name=\"cs_value_file[{$this->idx}]\" value=\"\" size=\"50\"></div></td><tr><td><div class=\"setter\">외부경로<input type=\"text\" name=\"cs_value[{$this->idx}]\" value=\"{$this->cs_value}\" size=\"50\"/></div></td></tr>"
];
$this->is_value_added = true;
}
public function addBackgroundSetting($desc, $default)
{
if ($this->is_value_added)
return;
$idx = $this->getCurrentCount();
if ($idx == 0) {
$imgval = $this->cs_value;
$img = $this->cs_value ? "<img src=\"{$imgval}\" class=\"prev_thumb\"/>" : "이미지 미등록";
$color1 = $this->cs_etc_1;
$repeat = $this->cs_etc_2;
$align = $this->cs_etc_3;
$size = $this->cs_etc_4;
$position = $this->cs_etc_5 == "fixed" ? " selected" : "";
$repeats = ["", "", ""];
$aligns = ["", "", "", "", "", "", "", ""];
$sizes = ["", "", ""];
switch ($repeat) {
case "no-repeat":
$repeats[0] = " selected";
break;
case "repeat-x":
$repeats[1] = " selected";
break;
case "repeat-y":
$repeats[2] = " selected";
break;
}
switch ($align) {
case "left center":
$aligns[0] = " selected";
break;
case "left bottom":
$aligns[1] = " selected";
break;
case "center top":
$aligns[2] = " selected";
break;
case "center center":
$aligns[3] = " selected";
break;
case "center bottom":
$aligns[4] = " selected";
break;
case "right top":
$aligns[5] = " selected";
break;
case "right center":
$aligns[6] = " selected";
break;
case "right bottom":
$aligns[7] = " selected";
break;
}
switch ($size) {
case "contain":
$sizes[0] = " selected";
break;
case "cover":
$sizes[0] = " selected";
break;
case "100% 100%":
$sizes[0] = " selected";
break;
}
$this->settings[] = [
"type" => "background",
"html" => "
<td rowspan=\"4\" class=\"bo-right bo-left txt-center\">
{$img}
</td>
<td>
<div class=\"setter\">직접등록<input type=\"file\" name=\"cs_value_file[{$this->idx}]\" value=\"\" size=\"50\"></div>
</td></tr><tr>
<td>
<div class=\"setter\">외부경로<input type=\"text\" name=\"cs_value[{$this->idx}]\" value=\"{$imgval}\" size=\"50\"/></div>
</td></tr><tr>
<td>
<div class=\"setter\">색상<input type=\"text\" name=\"cs_etc_1[{$this->idx}]\" value=\"{$color1}\" class=\"neo_color\" size=\"30\" maxlength=\"255\" placeholder=\"#색상코드\" /></div>
</td></tr><tr>
<td>
<div class=\"setter\">배경반복
<select name=\"cs_etc_2[{$this->idx}]\">
<option value=\"\">반복</option>
<option value=\"no-repeat\"{$repeats[0]}>반복없음</option>
<option value=\"repeat-x\"{$repeats[1]}>가로반복</option>
<option value=\"repeat-y\"{$repeats[2]}>세로반복</option>
</select>
배경위치
<select name=\"cs_etc_3[{$this->idx}]\">
<option value=\"\">왼쪽 상단</option>
<option value=\"left center\"{$aligns[0]}>왼쪽 중단</option>
<option value=\"left bottom\"{$aligns[1]}>왼쪽 하단</option>
<option value=\"center top\"{$aligns[2]}>중간 상단</option>
<option value=\"center center\"{$aligns[3]}>중간 중단</option>
<option value=\"center bottom\"{$aligns[4]}>중간 하단</option>
<option value=\"right top\"{$aligns[5]}>오른쪽 상단</option>
<option value=\"right center\"{$aligns[6]}>오른쪽 중단</option>
<option value=\"right bottom\"{$aligns[7]}>오른쪽 하단</option>
</select>
</div>
<br />
<div class=\"setter\">
배경크기
<select name=\"cs_etc_4[{$this->idx}]\">
<option value=\"\">원본크기</option>
<option value=\"contain\"{$sizes[0]}>맞춤</option>
<option value=\"cover\"{$sizes[1]}>꽉참</option>
<option value=\"100% 100%\"{$sizes[2]}>늘이기</option>
</select>
고정
<select name=\"cs_etc_5[{$this->idx}]\">
<option value=\"\">스크롤</option>
<option value=\"fixed\"{$position}>고정</option>
</select>
</div>
</td>"
];
}
}
public function addFontSetting($desc, $default, $placeholder = "")
{
$idx = $this->getCurrentCount() + 1;
if ($idx <= self::$etc_max) {
$key1 = "cs_etc_{$idx}";
$val = $this->$key1 ? $this->$key1 : (isset($default) ? $default : "");
$this->settings[] = [
"type" => "font",
"html" => "<td class=\"bo-right\">{$desc}</td><td><div class=\"setter\"><input type=\"text\" name=\"cs_etc_{$idx}[{$this->idx}]\" value=\"{$val}\" size=\"100\" placeholder=\"{$placeholder}\" /></div></td></tr>"
];
}
}
public function addFontSizeSetting($desc, $default)
{
$idx = $this->getCurrentCount() + 1;
if ($idx <= self::$etc_max) {
$key1 = "cs_etc_{$idx}";
$val = $this->$key1 ? $this->$key1 : (isset($default) ? $default : 16);
$this->settings[] = [
"type" => "font",
"html" => "<td class=\"bo-right\">{$desc}</td><td><div class=\"setter\"><input type=\"number\" name=\"cs_etc_{$idx}[{$this->idx}]\" value=\"{$val}\" style=\"width: 60px\" min=\"9\" max=\"72\" /></div></td></tr>"
];
}
}
public function addNumberSetting($desc, $default)
{
$idx = $this->getCurrentCount() + 1;
if ($idx <= self::$etc_max) {
$key1 = "cs_etc_{$idx}";
$val = $this->$key1 ? $this->$key1 : (isset($default) ? $default : 0);
$this->settings[] = [
"type" => "number",
"html" => "<td class=\"bo-right\">{$desc}</td><td><div class=\"setter\"><input type=\"number\" name=\"cs_etc_{$idx}[{$this->idx}]\" value=\"{$val}\" style=\"width: 60px\" min=\"-5000\" max=\"5000\" /></div></td></tr>"
];
}
}
public function addRectSetting($desc, $default)
{
$idx = $this->getCurrentCount() + 1;
if ($idx <= self::$etc_max) {
$key1 = "cs_etc_{$idx}";
$values = explode("||", $this->$key1);
if (empty($default)) {
$default = [0, 0, 0, 0];
}
if (count($values) < 6) {
$values = array_merge([""], $default, [""]);
}
foreach ($values as &$val) {
$val = intval($val);
}
$this->settings[] = [
"type" => "rect",
"html" => "<td class=\"bo-right\">{$desc}</td>
<td>
<div class=\"setter\">
<div class=\"css-setting-multi\"><span class=\"css-left-desc\">X</span><input type=\"number\" id=\"cs_etc_{$idx}_1_{$this->cs_name}\" min=\"-9999\" max=\"9999\" size=\"20\" name=\"cs_etc_{$idx}[{$this->idx}][]\" value=\"{$values[1]}\"/>px</div>
<div class=\"css-setting-multi\"><span class=\"css-left-desc\">Y</span><input type=\"number\" id=\"cs_etc_{$idx}_1_{$this->cs_name}\" min=\"-9999\" max=\"9999\" size=\"20\" name=\"cs_etc_{$idx}[{$this->idx}][]\" value=\"{$values[2]}\"/>px</div>
<div class=\"css-setting-multi\"><span class=\"css-left-desc\">너비</span><input type=\"number\" id=\"cs_etc_{$idx}_1_{$this->cs_name}\" min=\"-9999\" max=\"9999\" size=\"20\" name=\"cs_etc_{$idx}[{$this->idx}][]\" value=\"{$values[3]}\"/>px</div>
<div class=\"css-setting-multi\"><span class=\"css-left-desc\">높이</span><input type=\"number\" id=\"cs_etc_{$idx}_1_{$this->cs_name}\" min=\"-9999\" max=\"9999\" size=\"20\" name=\"cs_etc_{$idx}[{$this->idx}][]\" value=\"{$values[4]}\"/>px</div>
</div>
</td>
</tr>"
];
}
// error
}
public function addRadiusSetting($desc, $default)
{
$idx = $this->getCurrentCount() + 1;
if ($idx <= self::$etc_max) {
$key1 = "cs_etc_{$idx}";
$values = explode("||", $this->$key1);
if (empty($default)) {
$default = [0, 0, 0, 0];
}
if (count($values) < 6) {
$values = array_merge([""], $default, [""]);
}
foreach ($values as &$val) {
$val = intval($val);
}
$this->settings[] = [
"type" => "radius",
"html" => "<td class=\"bo-right\">{$desc}</td>
<td>
<div class=\"setter\">
<div class=\"css-setting-multi\"><div class=\"css-setting-radius\" style=\"border-radius: 8px 0 0 0;\"></div><input type=\"number\" id=\"cs_etc_{$idx}_1_{$this->cs_name}\" min=\"-9999\" max=\"9999\" size=\"20\" name=\"cs_etc_{$idx}[{$this->idx}][]\" value=\"{$values[1]}\"/>px</div>
<div class=\"css-setting-multi\"><div class=\"css-setting-radius\" style=\"border-radius: 0 8px 0 0;\"></div><input type=\"number\" id=\"cs_etc_{$idx}_1_{$this->cs_name}\" min=\"-9999\" max=\"9999\" size=\"20\" name=\"cs_etc_{$idx}[{$this->idx}][]\" value=\"{$values[2]}\"/>px</div>
<div class=\"css-setting-multi\"><div class=\"css-setting-radius\" style=\"border-radius: 0 0 8px 0;\"></div><input type=\"number\" id=\"cs_etc_{$idx}_1_{$this->cs_name}\" min=\"-9999\" max=\"9999\" size=\"20\" name=\"cs_etc_{$idx}[{$this->idx}][]\" value=\"{$values[3]}\"/>px</div>
<div class=\"css-setting-multi\"><div class=\"css-setting-radius\" style=\"border-radius: 0 0 0 8px;\"></div><input type=\"number\" id=\"cs_etc_{$idx}_1_{$this->cs_name}\" min=\"-9999\" max=\"9999\" size=\"20\" name=\"cs_etc_{$idx}[{$this->idx}][]\" value=\"{$values[4]}\"/>px</div>
</div>
</td>
</tr>"
];
}
// error
}
public function addMarginSetting($desc, $default)
{
$idx = $this->getCurrentCount() + 1;
if ($idx <= self::$etc_max) {
$key1 = "cs_etc_{$idx}";
$values = explode("||", $this->$key1);
if (empty($default)) {
$default = [0, 0, 0, 0];
}
if (count($values) < 6) {
$values = array_merge([""], $default, [""]);
}
foreach ($values as &$val) {
$val = intval($val);
}
$this->settings[] = [
"type" => "margin",
"html" => "<td class=\"bo-right\">{$desc}</td>
<td>
<div class=\"setter\">
<div class=\"css-setting-multi\">상<input type=\"number\" id=\"cs_etc_{$idx}_1_{$this->cs_name}\" min=\"-9999\" max=\"9999\" size=\"20\" name=\"cs_etc_{$idx}[{$this->idx}][]\" value=\"{$values[1]}\"/>px</div>
<div class=\"css-setting-multi\">하<input type=\"number\" id=\"cs_etc_{$idx}_1_{$this->cs_name}\" min=\"-9999\" max=\"9999\" size=\"20\" name=\"cs_etc_{$idx}[{$this->idx}][]\" value=\"{$values[2]}\"/>px</div>
<div class=\"css-setting-multi\">좌<input type=\"number\" id=\"cs_etc_{$idx}_1_{$this->cs_name}\" min=\"-9999\" max=\"9999\" size=\"20\" name=\"cs_etc_{$idx}[{$this->idx}][]\" value=\"{$values[3]}\"/>px</div>
<div class=\"css-setting-multi\">우<input type=\"number\" id=\"cs_etc_{$idx}_1_{$this->cs_name}\" min=\"-9999\" max=\"9999\" size=\"20\" name=\"cs_etc_{$idx}[{$this->idx}][]\" value=\"{$values[4]}\"/>px</div>
</div>
</td>
</tr>"
];
}
// error
}
public function addColorSetting($desc, $default)
{
$idx = $this->getCurrentCount() + 1;
if ($idx <= self::$etc_max - 1) {
$idx2 = $idx + 1;
$key1 = "cs_etc_{$idx}";
$key2 = "cs_etc_{$idx2}";
if (empty($default)) {
if ($this->$key1 === "")
$this->$key1 = "#000000";
if ($this->$key2 === "")
$this->$key2 = "0";
}
$this->settings[] = [
"type" => "color",
"html" => "<td class=\"bo-right\">{$desc}</td><td><div class=\"setter\">색상<input type=\"text\" name=\"cs_etc_{$idx}[{$this->idx}]\" value=\"{$this->$key1}\" class=\"colorpicker\" size=\"30\" maxlength=\"255\" placeholder=\"#색상코드\" />투명도<input type=\"number\" name=\"cs_etc_{$idx2}[{$this->idx}]\" value=\"{$this->$key2}\" placeholder=\"0\" title=\"투명도\" style=\"width:45px;\"/>%</div></td></tr>"
];
}
// error
}
public function addColor2Setting($desc, $default)
{
$idx = $this->getCurrentCount() + 1;
if ($idx <= self::$etc_max) {
$key1 = "cs_etc_{$idx}";
if (empty($default)) {
if ($this->$key1 === "")
$this->$key1 = "#000000FF";
} else {
if ($this->$key1 === "")
$this->$key1 = $default[0];
}
$this->settings[] = [
"type" => "color2",
"html" => "<td class=\"bo-right\">{$desc}</td><td><div class=\"setter\">색상<input type=\"text\" name=\"cs_etc_{$idx}[{$this->idx}]\" value=\"{$this->$key1}\" class=\"neo_color\" size=\"30\" maxlength=\"255\" placeholder=\"#색상코드\" /></div></td></tr>"
];
}
// error
}
public function addBorderSetting($desc, $default)
{
$idx = $this->getCurrentCount() + 1;
$options = [
" " => "사용 안 함",
"dotted" => "점선",
"dashed" => "대시",
"solid" => "직선",
"double" => "이중선",
"groove" => "내부 경사",
"ridge" => "외부 경사",
"inset" => "내부",
"outset" => "외부"
];
if ($idx <= self::$etc_max - 2) {
$idx2 = $idx + 1;
$key1 = "cs_etc_{$idx}";
$key2 = "cs_etc_{$idx2}";
if (is_array($default) && isset($default[0]) && isset($default[1])) {
if (empty($this->$key1))
$this->$key1 = array_key_exists($default[0], $options) ? $default[0] : "";
if (empty($this->$key2) && $this->$key2 !== 0)
$this->$key2 = intval($default[1]);
}
$options_html = "";
foreach ($options as $key => $val) {
$k = trim($key);
$s = $this->$key1 == $k ? " selected" : "";
$options_html .= "<option value=\"{$k}\"{$s}>{$val}</option>";
}
$this->settings[] = [
"type" => "border",
"html" => "<td class=\"bo-right\">{$desc}</td><td><div class=\"setter\"><select name=\"cs_etc_{$idx}[{$this->idx}]\">{$options_html}</select>두께<input type=\"number\" name=\"cs_etc_{$idx2}[{$this->idx}]\" value=\"{$this->$key2}\" placeholder=\"0\" title=\"두께\" style=\"width:45px;\"/></div></td></tr>"
];
}
}
public function addBorder2Setting($desc, $default)
{
$idx = $this->getCurrentCount() + 1;
$options = [
" " => "사용 안 함",
"dotted" => "점선",
"dashed" => "대시",
"solid" => "직선",
"double" => "이중선",
"groove" => "내부 경사",
"ridge" => "외부 경사",
"inset" => "내부",
"outset" => "외부"
];
if ($idx <= self::$etc_max - 3) {
$idx2 = $idx + 1;
$idx3 = $idx + 2;
$key1 = "cs_etc_{$idx}";
$key2 = "cs_etc_{$idx2}";
$key3 = "cs_etc_{$idx3}";
if (is_array($default) && isset($default[0]) && isset($default[1])) {
if (empty($this->$key1))
$this->$key1 = array_key_exists($default[0], $options) ? $default[0] : "";
if (empty($this->$key2) && $this->$key2 !== 0)
$this->$key2 = intval($default[1]);
}
if (empty($this->$key3) && $this->$key3 !== 0) {
if ($this->$key3 === "" || !isset($this->$key3))
$this->$key3 = intval($default[2]);
}
$values = explode("||", $this->$key3);
$options_html = "";
foreach ($options as $key => $val) {
$k = trim($key);
$s = $this->$key1 == $k ? " selected" : "";
$options_html .= "<option value=\"{$k}\"{$s}>{$val}</option>";
}
$checked_top = in_array("top", $values) ? " checked" : "";
$checked_bottom = in_array("bottom", $values) ? " checked" : "";
$checked_left = in_array("left", $values) ? " checked" : "";
$checked_right = in_array("right", $values) ? " checked" : "";
$this->settings[] = [
"type" => "border",
"html" => "<td class=\"bo-right\">{$desc}</td>
<td>
<div class=\"setter\">
<select name=\"cs_etc_{$idx}[{$this->idx}]\">{$options_html}</select>
두께<input type=\"number\" name=\"cs_etc_{$idx2}[{$this->idx}]\" value=\"{$this->$key2}\" placeholder=\"0\" title=\"두께\" style=\"width:45px;\"/>
</div>
<div class=\"setter\" style=\"margin-top: 8px\">
상<input type=\"checkbox\" name=\"cs_etc_{$idx3}[{$this->idx}][]\" id=\"cs_etc_{$idx3}_1_{$this->cs_name}\" style=\"max-width: 24px\" value=\"top\" {$checked_top}/>
하<input type=\"checkbox\" name=\"cs_etc_{$idx3}[{$this->idx}][]\" id=\"cs_etc_{$idx3}_2_{$this->cs_name}\" style=\"max-width: 24px\" value=\"bottom\" {$checked_bottom}/>
좌<input type=\"checkbox\" name=\"cs_etc_{$idx3}[{$this->idx}][]\" id=\"cs_etc_{$idx3}_3_{$this->cs_name}\" style=\"max-width: 24px\" value=\"left\" {$checked_left}/>
우<input type=\"checkbox\" name=\"cs_etc_{$idx3}[{$this->idx}][]\" id=\"cs_etc_{$idx3}_4_{$this->cs_name}\" style=\"max-width: 24px\" value=\"right\" {$checked_right}/>
</div>
</td>
</tr>"
];
}
}
public function addBackForeLine($desc, $default)
{
$idx = $this->getCurrentCount() + 1;
if ($idx <= self::$etc_max - 3) {
$key1 = "cs_etc_{$idx}";
$idx2 = $idx + 1;
$key2 = "cs_etc_{$idx2}";
$idx3 = $idx + 2;
$key3 = "cs_etc_{$idx3}";
if (is_array($default)) {
$cnt = count($default);
switch($cnt) {
case 3:
{
$this->$key3 = $default[2];
}
case 2:
{
$this->$key2 = $default[1];
}
case 1:
{
$this->$key1 = $default[0];
}
}
}
$this->settings[] = [
"type" => "color3",
"html" => "<td class=\"bo-right\">배경</td><td><div class=\"setter\">색상 <input type=\"text\" name=\"cs_etc_{$idx}[{$this->idx}]\" value=\"{$this->$key1}\" class=\"neo_color\" size=\"30\" maxlength=\"255\" placeholder=\"#색상코드\" /></div></td></tr>" .
"<tr><td class=\"bo-right\">폰트</td><td><div class=\"setter\">색상 <input type=\"text\" name=\"cs_etc_{$idx2}[{$this->idx}]\" value=\"{$this->$key2}\" class=\"neo_color\" size=\"30\" maxlength=\"255\" placeholder=\"#색상코드\" /></div></td></tr>" .
"<tr><td class=\"bo-right\">라인</td><td><div class=\"setter\">색상 <input type=\"text\" name=\"cs_etc_{$idx3}[{$this->idx}]\" value=\"{$this->$key3}\" class=\"neo_color\" size=\"20\" maxlength=\"255\" placeholder=\"#색상코드\" /></div></td></tr>"
];
}
}
public function addSelectSetting($desc, $default, $values)
{
$idx = $this->getCurrentCount() + 1;
if ($idx <= self::$etc_max - 1) {
$key1 = "cs_etc_{$idx}";
$options_html = "";
foreach ($values as $key => $val) {
$k = trim($key);
$s = $this->$key1 == $k ? " selected" : "";
$options_html .= "<option value=\"{$k}\"{$s}>{$val}</option>";
}
$this->settings[] = [
"type" => "select",
"html" => "<td class=\"bo-right\">{$desc}</td><td><div class=\"setter\"><select name=\"cs_etc_{$idx}[{$this->idx}]\">{$options_html}</select></div></td></tr>"
];
}
}
public function getExplodeValue($idx)
{
$key = "cs_etc_{$idx}";
return explode("||", $this->$key);
}
public function getSettingHtml()
{
$html = "";
foreach ($this->settings as $val) {
if ($html == "") {
$html .= $this->addHeader();
} else {
$html .= "<tr>";
}
$html .= $val['html'];
}
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, ''), ['&nbsp;','<p>&nbsp;</p>','<p><br></p>','<div><br></div>','<p></p>','<br>','']) != -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, '<a><strong><b>')) {
$content = nl2br($content);
}
}
$editor_url = G5_EDITOR_URL . '/' . $config['cf_editor'];
$html = "";
$html .= "<span class=\"sound_only\">웹에디터 시작</span>";
if ($is_dhtml_editor && $js) {
$html .= "\n<script src=\"{$editor_url}/js/service/HuskyEZCreator.js\"></script>";
$html .= "\n<script> var g5_editor_url = '" . $editor_url . "', oEditors = [], ed_nonce = '" . ft_nonce_create('smarteditor') . "', editorAdditionalFontList = [";
if (!self::$fonts) {
$sql = "SELECT * FROM {$g5['font_table']} ORDER BY font_name ASC";
$result = sql_query($sql);
$addFontList = [];
while ($row = sql_fetch_array($result)) {
$font_name = addslashes($row['font_name']);
$font_family = addslashes($row['font_family']);
$addFontList[] = "['{$font_family}', '{$font_name}']";
}
if (count($addFontList) > 0) {
self::$fonts = implode(",", $addFontList);
}
}
$html .= self::$fonts;
$html .= "];</script>";
$html .= "\n<script src=\"{$editor_url}/config.js\"></script>";
$js = false;
}
$smarteditor_class = $is_dhtml_editor ? "smarteditor2" : "";
$html .= "\n<textarea id=\"{$id}\" name=\"{$key}\" class=\"{$smarteditor_class}\" maxlength=\"{$maxlength}\" style=\"width:100%;height:300px\">{$content}</textarea>";
$html .= "\n<span class=\"sound_only\">웹 에디터 끝</span>";
return $html;
}
}