add setting type

This commit is contained in:
Amberstone 2025-01-28 18:27:41 +09:00
parent a73228fa09
commit ec82e77e7d
Signed by: amber
GPG key ID: 094B0E55F98D8BF1

View file

@ -9,6 +9,7 @@
*/
class Setting
{
public static $etc_max = 20;
public static $fonts;
public $idx;
public $html;
@ -106,6 +107,12 @@ class Setting
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;
}
}
@ -121,7 +128,7 @@ class Setting
$set->cs_value = $row['cs_value'];
$set->cs_name = $row['cs_name'];
$set->cs_descript = $row['cs_descript'];
for ($i = 1; $i <= 20; $i++) {
for ($i = 1; $i <= self::$etc_max; $i++) {
$key = "cs_etc_{$i}";
$set->$key = $row[$key];
}
@ -143,7 +150,7 @@ class Setting
$set->cs_value = $row['cs_value'];
$set->cs_name = $row['cs_name'];
$set->cs_descript = $row['cs_descript'];
for ($i = 1; $i <= 20; $i++) {
for ($i = 1; $i <= self::$etc_max; $i++) {
$key = "cs_etc_{$i}";
$set->$key = $row[$key];
}
@ -161,14 +168,14 @@ class Setting
$this->cs_name = $data['cs_name'];
$this->cs_value = $data['cs_value'];
$this->cs_descript = $data['cs_descript'];
for ($i = 1; $i <= 20; $i++) {
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 <= 20; $i++) {
for ($i = 1; $i <= self::$etc_max; $i++) {
$key = "cs_etc_{$i}";
$this->$key = "";
}
@ -183,6 +190,9 @@ class Setting
$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;
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>";
}
@ -265,7 +275,7 @@ class Setting
public function addFontSetting($desc, $default, $placeholder = "")
{
$idx = $this->getCurrentCount() + 1;
if ($idx <= 20) {
if ($idx <= self::$etc_max) {
$key1 = "cs_etc_{$idx}";
$val = $this->$key1 ? $this->$key1 : (isset($default) ? $default : "");
@ -279,7 +289,7 @@ class Setting
public function addFontSizeSetting($desc, $default)
{
$idx = $this->getCurrentCount() + 1;
if ($idx <= 20) {
if ($idx <= self::$etc_max) {
$key1 = "cs_etc_{$idx}";
$val = $this->$key1 ? $this->$key1 : (isset($default) ? $default : 16);
@ -290,10 +300,24 @@ class Setting
}
}
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 <= 20) {
if ($idx <= self::$etc_max) {
$key1 = "cs_etc_{$idx}";
$values = explode("||", $this->$key1);
@ -329,7 +353,7 @@ class Setting
public function addRadiusSetting($desc, $default)
{
$idx = $this->getCurrentCount() + 1;
if ($idx <= 20) {
if ($idx <= self::$etc_max) {
$key1 = "cs_etc_{$idx}";
$values = explode("||", $this->$key1);
@ -365,7 +389,7 @@ class Setting
public function addMarginSetting($desc, $default)
{
$idx = $this->getCurrentCount() + 1;
if ($idx <= 20) {
if ($idx <= self::$etc_max) {
$key1 = "cs_etc_{$idx}";
$values = explode("||", $this->$key1);
@ -401,7 +425,7 @@ class Setting
public function addColorSetting($desc, $default)
{
$idx = $this->getCurrentCount() + 1;
if ($idx <= 19) {
if ($idx <= self::$etc_max - 1) {
$idx2 = $idx + 1;
$key1 = "cs_etc_{$idx}";
$key2 = "cs_etc_{$idx2}";
@ -422,7 +446,7 @@ class Setting
public function addColor2Setting($desc, $default)
{
$idx = $this->getCurrentCount() + 1;
if ($idx <= 20) {
if ($idx <= self::$etc_max) {
$key1 = "cs_etc_{$idx}";
if (empty($default)) {
if ($this->$key1 === "")
@ -454,10 +478,16 @@ class Setting
"outset" => "외부"
];
if ($idx <= 19) {
if ($idx <= self::$etc_max - 1) {
$idx2 = $idx + 1;
$key1 = "cs_etc_{$idx}";
$key2 = "cs_etc_{$idx2}";
if (is_array($default) && isset($default[0]) && isset($default[1])) {
if (!isset($this->$key1))
$this->$key1 = array_key_exists($default[0], $options) ? $default[0] : "";
if (!isset($this->$key2))
$this->$key2 = intval($default[1]);
}
$options_html = "";
foreach ($options as $key => $val) {
$k = trim($key);
@ -471,11 +501,137 @@ class Setting
}
}
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 addSelectSetting($desc, $default, $values)
{
$idx = $this->getCurrentCount() + 1;
if ($idx <= 19) {
if ($idx <= self::$etc_max - 1) {
$key1 = "cs_etc_{$idx}";
$options_html = "";
foreach ($values as $key => $val) {
@ -513,7 +669,7 @@ class Setting
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 = "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";