Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
opensug authored Aug 28, 2023
0 parents commit c1080a4
Show file tree
Hide file tree
Showing 4 changed files with 248 additions and 0 deletions.
6 changes: 6 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php
defined( "EMLOG_ROOT" ) || (
header( "HTTP/1.1 404 Not Found" ) &
header( "Status: 404 Not Found" ) &
exit
);
30 changes: 30 additions & 0 deletions opensug.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
/*
Plugin Name: 搜索下拉提示框
Version: 1.0.0
Plugin URL:https://wordpress.org/plugins/opensug/
Description: 为来访者提供搜索建议,使用户的搜索方便快捷。
Author: openSug
Author URL: https://www.opensug.eu.org/
*/
! defined("EMLOG_ROOT") && exit("access deined!");

// 前端脚本
addAction("index_footer", function(){
$config = array();
$db = Storage::getInstance("openSug");
$config = $db->getValue( "config" );

if( ! isset( $config["ipt"] ) || strlen($config["ipt"]) == 0) return false;

if( $config["width"] < 1 ) $config["width"] = "";

$config["sugSubmit"] = $config["sugSubmit"] == "0" ? "false" : "true";

echo "\r\n<script type=\"text/javascript\" src=\"https://opensug.github.io/js/opensug.js\"></script>\r\n<script type=\"text/javascript\">\"use strict\";(function(){\r\n var ipt = document[\"getElementById\"](\"{$config["ipt"]}\");\r\n if( ipt != null && (\r\n (ipt[\"getAttribute\"](\"type\") || \"\")[\"toLocaleLowerCase\"]() === \"search\" || \r\n (ipt[\"getAttribute\"](\"type\") || \"\")[\"toLocaleLowerCase\"]() === \"text\") && \r\n \"function\" === typeof( window[\"openSug\"] )\r\n ) window[\"openSug\"]( \"{$config["ipt"]}\", {\r\n // 提示框的背景色。\r\n bgcolor : \"{$config["bgcolor"]}\",\r\n\r\n // 提示框的高亮背景色。\r\n bgcolorHI : \"{$config["bgcolorHI"]}\",\r\n\r\n // 提示框的边框颜色。\r\n borderColor : \"{$config["borderColor"]}\",\r\n\r\n // 提示框中文本的颜色。\r\n fontColor : \"{$config["fontColor"]}\",\r\n\r\n // 高亮显示提示框中的文本颜色。\r\n fontColorHI : \"{$config["fontColorHI"]}\",\r\n\r\n // 提示框中文本的字体。\r\n fontFamily : \"{$config["fontFamily"]}\",\r\n\r\n // 提示框中的文本字体大小。\r\n fontSize : \"{$config["fontSize"]}\",\r\n\r\n // 提示框的内边距。\r\n padding : \"{$config["padding"]}\",\r\n\r\n // 边界的圆角半径。\r\n radius : \"{$config["radius"]}\",\r\n\r\n // 边框的阴影效果。\r\n shadow : \"{$config["shadow"]}\",\r\n\r\n // 搜索提示框的数据源。\r\n source : \"{$config["source"]}\",\r\n\r\n // 选择提示时是否自动提交表单。\r\n sugSubmit : {$config["sugSubmit"]},\r\n\r\n // 提示框的宽度。\r\n // 建议的空值。\r\n width : \"{$config["width"]}\",\r\n\r\n // 提示框相对于输入框的横向偏移。\r\n // 负值向右移动。\r\n XOffset : \"{$config["XOffset"]}\",\r\n\r\n // 提示框相对于输入框的纵向偏移。\r\n // 负值向下偏移。\r\n YOffset : \"{$config["YOffset"]}\"\r\n\r\n }, function(callback){\r\n /* ... */\r\n });\r\n}(this));</script>\r\n";
});

// 后台调试链接
addAction("adm_menu_ext", function (){
echo "<a id=\"openSug\" class=\"collapse-item\" href=\"plugin.php?plugin=opensug\">openSug</a>";
});
36 changes: 36 additions & 0 deletions opensug_callback.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php
! defined("EMLOG_ROOT") && exit("access deined!" );

// 插件初始化配置
function callback_init() {
$db = Storage::getInstance("openSug" ); // 插件初始化实例
$db->setValue( "config", array(
"ipt" => "", // 输入框绑定ID
"bgcolor" => "#ffffff", // 背景颜色
"bgcolorHI" => "#313131", // 背景高亮颜色
"borderColor" => "#ced4da", // 边框颜色
"fontColor" => "#313131", // 字体颜色
"fontColorHI" => "#ffffff", // 字体高亮颜色
"fontFamily" => "Montserrat,sans-serif", // 字体
"fontSize" => "14", // 字体大小
"padding" => "4px 8px", // 内边框
"radius" => "4px", // 圆角
"shadow" => "0 16px 10px #00000080", // 阴影
"source" => "", // 结果源
"sugSubmit" => "1", // 默认动作
"width" => "", // 宽度
"XOffset" => "", // X偏移量
"YOffset" => "-3", // Y偏移量
), "array" );
}

// 插件删除时清理数据
function callback_rm() {
$db = Storage::getInstance("openSug"); //使用插件的英文名称初始化一个存储实例
$ak = $db->deleteAllName("YES"); //删除此插件创建的所有数据, 请传入大写的"YES"来确认删除 ,一般用于插件删除回调函数。
}

// 插件更新时数据库
function callback_up() {

}
176 changes: 176 additions & 0 deletions opensug_setting.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,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,如您需要帮助请添加社群获取支援!&nbsp;<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;">&lt;<span style="color:#c18401">input</span>&nbsp;<span style="color:#c18401">type</span>=<span style="color:#50a14f">&quot;text&quot;</span>&nbsp;name=<span style="color:#50a14f">&quot;kw&quot;</span>&nbsp;id=<span style="color:#50a14f">&quot;输入框ID&quot;</span>&nbsp;...</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 } ?>

0 comments on commit c1080a4

Please sign in to comment.