-
Notifications
You must be signed in to change notification settings - Fork 0
/
opensug_setting.php
176 lines (167 loc) · 9.95 KB
/
opensug_setting.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
<?php
! defined("EMLOG_ROOT") && exit("access deined!");
function openSug_option($cfg = "", $var = "", $str = ""){
$sel = $cfg == $var ? "selected=\"selected\" " : "";
return "<option {$sel}value=\"{$var}\">{$str}</option>";
}
function plugin_setting_view(){
$config = array();
$db = Storage::getInstance("openSug");
if( strtolower( $_SERVER["REQUEST_METHOD"] ) === "post"){
if(!preg_match("/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/", $_POST["bgcolor"])) $_POST["bgcolor"] = "";
if(!preg_match("/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/", $_POST["bgcolorHI"])) $_POST["bgcolorHI"] = "";
if(!preg_match("/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/", $_POST["borderColor"])) $_POST["borderColor"] = "";
if(!preg_match("/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/", $_POST["fontColor"])) $_POST["fontColor"] = "";
if(!preg_match("/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/", $_POST["fontColorHI"])) $_POST["fontColorHI"] = "";
if(!preg_match("/^(?:-?\d+)?$/", $_POST["XOffset"])) $_POST["XOffset"] = "";
if(!preg_match("/^(?:-?\d+)?$/", $_POST["YOffset"])) $_POST["YOffset"] = "";
if(!preg_match("/^\d+$/", $_POST["fontColorHI"])) $_POST["width"] = "";
if(!preg_match("/^(\d+(px|em))( (\d+(px|em))){0,3}$/", $_POST["padding"])) $_POST["padding"] = "";
if(!preg_match("/^(\d+(px|em))( (\d+(px|em))){0,3}$/", $_POST["radius"])) $_POST["radius"] = "";
if(!preg_match("/(px|em)$/", $_POST["fontSize"])) $_POST["fontSize"] .= "px";
if(!preg_match("/\b(\d+(?:px|em)(?:\s+\d+(?:px|em)){0,3})\b/", $_POST["fontSize"])) $_POST["fontSize"] = "14px";
$_POST["sugSubmit"] = $_POST["sugSubmit"] == "0" ? "0" : "1";
$db->setValue( "config", array(
"ipt" => $_POST["iptid"], // 输入框绑定ID
"bgcolor" => $_POST["bgcolor"], // 背景颜色
"bgcolorHI" => $_POST["bgcolorHI"], // 背景高亮颜色
"borderColor" => $_POST["borderColor"], // 边框颜色
"fontColor" => $_POST["fontColor"], // 字体颜色
"fontColorHI" => $_POST["fontColorHI"], // 字体高亮颜色
"fontFamily" => $_POST["fontFamily"], // 字体
"fontSize" => $_POST["fontSize"], // 字体大小
"padding" => $_POST["padding"], // 内边框
"radius" => $_POST["radius"], // 圆角
"shadow" => $_POST["shadow"], // 阴影
"source" => $_POST["source"], // 结果源
"sugSubmit" => $_POST["sugSubmit"], // 默认动作
"width" => $_POST["width"], // 宽度
"XOffset" => $_POST["XOffset"], // X偏移量
"YOffset" => $_POST["YOffset"], // Y偏移量
), "array" );
}
$sources = array(
"baidu" => "百度",
"google" => "谷歌",
"haoso" => "好搜",
"kugou" => "酷狗",
"yahoo" => "雅虎",
"yandex" => "Yandex",
"youku" => "优酷视频",
"taobao" => "淘宝",
"attayo" => "Attayo",
"mgtv" => "芒果视频",
"sm" => "神马搜索",
"weibo" => "微博",
"rambler" => "Rambler",
"soft" => "软件",
"naver" => "Naver",
"car" => "新浪汽车",
"car2" => "网易汽车",
"qunar" => "去哪儿",
"lagou" => "拉钩网"
);
$config = $db->getValue( "config" );
$config["fontSize"] = preg_replace("/[^\d]+/", "", $config["fontSize"] );
?>
<style type="text/css">
table{font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Helvetica Neue",Arial,"Noto Sans",sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol","Noto Color Emoji";}
input,
select{padding:.3em;outline:none;width:150px;}
.item{text-align:right;width:15%;padding-right:.3rem;}
.warning {margin:0px;}
.tips{color:#cccccc;padding:.3rem;}
.tips:hover{color:#000000}
td.item{padding:.5em 1em;width:10%;text-align:right;vertical-align:middle;user-select:none;}
</style>
<div class="d-sm-flex align-items-center justify-content-between mb-4">
<h1 class="h3 mb-0 text-gray-800">openSug.js - 为访问者提供搜索建议,方便用户搜索。</h1>
</div>
<div class="card shadow mb-4 mt-2">
<div class="card-body">
<form method="post">
<div class="form-group">
<div id="tip">
请根据您的主题模板实际输入框填写此处的ID,如您需要帮助请添加社群获取支援! <a target="_blank" href="//qm.qq.com/cgi-bin/qm/qr?k=tWNFxRGRyYkvfgVhUAMQSf-Pkqly4SU_&jump_from=webapi&authKey=VNsawBRaz2HqY8rpDrpDAt4vFX/yWz4NOktEXOdNVP5O85KHOSg2cEqKWAPQFAhl"><img border="0" src="//pub.idqqimg.com/wpa/images/group.png" alt="openSug.js" title="openSug.js"></a>
</div>
<div style="margin:0!important;padding:0 3px 0 10px!important;line-height:18px;list-style:decimal-leading-zero;border-left:3px solid #6ce26c;color:#5c5c5c;background-color:#f8f8f8;"><<span style="color:#c18401">input</span> <span style="color:#c18401">type</span>=<span style="color:#50a14f">"text"</span> name=<span style="color:#50a14f">"kw"</span> id=<span style="color:#50a14f">"输入框ID"</span> ...</div>
<hr>
<div>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td class="item" style="color:#f00"><label for="iptid">(*) 输入框ID</label></td>
<td><input autocomplete="off" x-webkit-speech="false" spellcheck="false" type="text" name="iptid" id="iptid" value="<?php echo $config["ipt"];?>" required="required" autofocus="autofocus" placeholder="iptID" /></td>
</tr>
<tr>
<td class="item"><label for="XOffset">XOffset</label></td>
<td><input autocomplete="off" x-webkit-speech="false" spellcheck="false" type="number" name="XOffset" id="XOffset" value="<?php echo $config["XOffset"];?>" placeholder="-1" /></td>
</tr>
<tr>
<td class="item"><label for="YOffset">YOffset</label></td>
<td><input autocomplete="off" x-webkit-speech="false" spellcheck="false" type="number" name="YOffset" id="YOffset" value="<?php echo $config["YOffset"];?>" placeholder="-3" /></td>
</tr>
<tr>
<td class="item"><label for="bgcolor">背景颜色</label></td>
<td><input autocomplete="off" x-webkit-speech="false" spellcheck="false" type="color" name="bgcolor" id="bgcolor" value="<?php echo $config["bgcolor"];?>" placeholder="#ffffff" /></td>
</tr>
<tr>
<td class="item"><label for="bgcolorHI">背景高亮颜色</label></td>
<td><input autocomplete="off" x-webkit-speech="false" spellcheck="false" type="color" name="bgcolorHI" id="bgcolorHI" value="<?php echo $config["bgcolorHI"];?>" placeholder="#11a7db" /></td>
</tr>
<tr>
<td class="item"><label for="borderColor">边框颜色</label></td>
<td><input autocomplete="off" x-webkit-speech="false" spellcheck="false" type="color" name="borderColor" id="borderColor" value="<?php echo $config["borderColor"];?>" placeholder="#d4ac20" /></td>
</tr>
<tr>
<td class="item"><label for="fontColor">字体颜色</label></td>
<td><input autocomplete="off" x-webkit-speech="false" spellcheck="false" type="color" name="fontColor" id="fontColor" value="<?php echo $config["fontColor"];?>" placeholder="#6b00c2" /></td>
</tr>
<tr>
<td class="item"><label for="fontColorHI">字体高亮颜色</label></td>
<td><input autocomplete="off" x-webkit-speech="false" spellcheck="false" type="color" name="fontColorHI" id="fontColorHI" value="<?php echo $config["fontColorHI"];?>" placeholder="#f14f4f" /></td>
</tr>
<tr>
<td class="item"><label for="fontFamily">字体</label></td>
<td><input autocomplete="off" x-webkit-speech="false" spellcheck="false" type="text" name="fontFamily" id="fontFamily" value="<?php echo $config["fontFamily"];?>" placeholder="Geneva" /></td>
</tr>
<tr>
<td class="item"><label for="fontSize">字体大小</label></td>
<td><input autocomplete="off" x-webkit-speech="false" spellcheck="false" type="number" name="fontSize" id="fontSize" value="<?php echo $config["fontSize"];?>" placeholder="14" /></td>
</tr>
<tr>
<td class="item"><label for="padding">内填充</label></td>
<td><input autocomplete="off" x-webkit-speech="false" spellcheck="false" type="text" name="padding" id="padding" value="<?php echo $config["padding"];?>" placeholder="1px 1px 1px 1px" /></td>
</tr>
<tr>
<td class="item"><label for="radius">边框圆角</label></td>
<td><input autocomplete="off" x-webkit-speech="false" spellcheck="false" type="text" name="radius" id="radius" value="<?php echo $config["radius"];?>" placeholder="1px 1px 1px 1px" /></td>
</tr>
<tr>
<td class="item"><label for="shadow">边框阴影</label></td>
<td><input autocomplete="off" x-webkit-speech="false" spellcheck="false" type="text" name="shadow" id="shadow" value="<?php echo $config["shadow"];?>" placeholder="0 16px 10px #00000080" /></td>
</tr>
<tr>
<td class="item"><label for="width">宽度</label></td>
<td><input autocomplete="off" x-webkit-speech="false" spellcheck="false" type="number" name="width" id="width" value="<?php echo $config["width"];?>" placeholder="推荐留空" /></td>
</tr>
<tr>
<td class="item"><label for="sugSubmit">选中默认动作</label></td>
<td><select id="sugSubmit" name="sugSubmit"><option value="1"<?php if( $config["sugSubmit"] != "0") echo " selected=\"selected\""; ?>>自动提交</option><option value="0"<?php if( $config["sugSubmit"] == "0") echo " selected=\"selected\""; ?>>手动提交</option></select></td>
</tr>
<tr>
<td class="item"><label for="source">结果源</label></td>
<td><select id="source" name="source"><?php foreach($sources as $k => $v) echo openSug_option($config["source"], $k, $v);?></select></td>
</tr>
<tr>
<td></td>
<td><input type="submit" class="btn btn-success btn-sm" value="保存" /></td>
</tr>
</tbody>
</table>
</div>
</div>
</form>
</div>
</div>
<?php } ?>