mirror of
https://github.com/yunluo/gdk.git
synced 2024-06-15 20:15:12 +02:00
全部代码格式化
This commit is contained in:
parent
72f39b63f3
commit
5c6428e0a8
|
@ -1,13 +1,15 @@
|
|||
<?php
|
||||
|
||||
if (!defined('ABSPATH')) {exit;}
|
||||
if (!defined('ABSPATH')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
function gdk_admin_enqueue_script($hook_suffix)
|
||||
{
|
||||
if ($hook_suffix == 'post.php' || $hook_suffix == 'post-new.php') {
|
||||
wp_register_script('paste-upload-image', GDK_BASE_URL . 'assets/js/paste-upload-image.js', array('jquery'), GDK_PLUGIN_VER, true);
|
||||
if ('post.php' == $hook_suffix || 'post-new.php' == $hook_suffix) {
|
||||
wp_register_script('paste-upload-image', GDK_BASE_URL.'assets/js/paste-upload-image.js', ['jquery'], GDK_PLUGIN_VER, true);
|
||||
wp_enqueue_script('paste-upload-image');
|
||||
wp_localize_script('paste-upload-image', 'pui_vars', array('pui_nonce' => wp_create_nonce('pui-nonce')));
|
||||
wp_localize_script('paste-upload-image', 'pui_vars', ['pui_nonce' => wp_create_nonce('pui-nonce')]);
|
||||
}
|
||||
}
|
||||
add_action('admin_enqueue_scripts', 'gdk_admin_enqueue_script');
|
||||
|
@ -15,33 +17,33 @@ add_action('admin_enqueue_scripts', 'gdk_admin_enqueue_script');
|
|||
function gdk_enqueue_script_frontend()
|
||||
{
|
||||
if (!is_admin()) {
|
||||
wp_enqueue_style( 'uikit', 'https://cdn.jsdelivr.net/npm/uikit@3.7.4/dist/css/uikit.min.css', false, GDK_PLUGIN_VER, 'all' );
|
||||
wp_enqueue_style('uikit', 'https://cdn.jsdelivr.net/npm/uikit@3.7.4/dist/css/uikit.min.css', false, GDK_PLUGIN_VER, 'all');
|
||||
|
||||
wp_enqueue_style('gdk', GDK_BASE_URL . 'assets/css/gdk.css', false, GDK_PLUGIN_VER, 'all');
|
||||
wp_enqueue_style('gdk', GDK_BASE_URL.'assets/css/gdk.css', false, GDK_PLUGIN_VER, 'all');
|
||||
|
||||
wp_deregister_script('jquery');
|
||||
wp_enqueue_script('jquery', 'https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.min.js', false, GDK_PLUGIN_VER, true); //加载自定义jQuery2.0.3
|
||||
// Comment Reply
|
||||
if (is_singular() && comments_open() && get_option('thread_comments')) {
|
||||
wp_enqueue_script('comment-reply');
|
||||
}
|
||||
// Comment Reply
|
||||
if (is_singular() && comments_open() && get_option('thread_comments')) {
|
||||
wp_enqueue_script('comment-reply');
|
||||
}
|
||||
|
||||
wp_enqueue_script('libs', GDK_BASE_URL . 'assets/js/libs.min.js', ['jquery'], GDK_PLUGIN_VER, true);
|
||||
wp_enqueue_script('libs', GDK_BASE_URL.'assets/js/libs.min.js', ['jquery'], GDK_PLUGIN_VER, true);
|
||||
wp_enqueue_script('uikit', 'https://cdn.jsdelivr.net/npm/uikit@3.7.4/dist/js/uikit.min.js', [], GDK_PLUGIN_VER, true);
|
||||
wp_enqueue_script('uikit-icon', 'https://cdn.jsdelivr.net/npm/uikit@3.7.4/dist/js/uikit-icons.min.js', [], GDK_PLUGIN_VER, true);
|
||||
wp_enqueue_script('gdk', GDK_BASE_URL . 'assets/js/gdk.js', ['jquery'], GDK_PLUGIN_VER, true);
|
||||
wp_enqueue_script('gdk', GDK_BASE_URL.'assets/js/gdk.js', ['jquery'], GDK_PLUGIN_VER, true);
|
||||
wp_localize_script('gdk', 'gdk', [
|
||||
'ajaxurl' => admin_url('admin-ajax.php'),
|
||||
'pass_nonce' => wp_create_nonce('pass_nonce'),
|
||||
'pay_points' => wp_create_nonce('pay_points'),
|
||||
'check_pay_points' => wp_create_nonce('check_pay_points'),
|
||||
'check_pay_view' => wp_create_nonce('check_pay_view'),
|
||||
'check_code' => wp_create_nonce('check_code'),
|
||||
'ajaxurl' => admin_url('admin-ajax.php'),
|
||||
'pass_nonce' => wp_create_nonce('pass_nonce'),
|
||||
'pay_points' => wp_create_nonce('pay_points'),
|
||||
'check_pay_points' => wp_create_nonce('check_pay_points'),
|
||||
'check_pay_view' => wp_create_nonce('check_pay_view'),
|
||||
'check_code' => wp_create_nonce('check_code'),
|
||||
'gdk_weauth_qr_gen' => wp_create_nonce('gdk_weauth_qr_gen'),
|
||||
'gdk_weauth_check' => wp_create_nonce('gdk_weauth_check'),
|
||||
'gdk_payjs_alipay' => gdk_option('gdk_payjs_alipay'),
|
||||
'user_id' => get_current_user_id(),
|
||||
'msg_nonce' => wp_create_nonce('msg_nonce'),
|
||||
'gdk_weauth_check' => wp_create_nonce('gdk_weauth_check'),
|
||||
'gdk_payjs_alipay' => gdk_option('gdk_payjs_alipay'),
|
||||
'user_id' => get_current_user_id(),
|
||||
'msg_nonce' => wp_create_nonce('msg_nonce'),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
@ -51,63 +53,115 @@ add_action('wp_enqueue_scripts', 'gdk_enqueue_script_frontend');
|
|||
function gdk_admin_script()
|
||||
{
|
||||
?>
|
||||
<script>
|
||||
jQuery(function($) {
|
||||
/* bengin */
|
||||
if ($("#wp-content-editor-tools").length > 0) {
|
||||
/***文章编辑器 */
|
||||
QTags.addButton('h2', 'H2标题', '<h2>', '</h2>');
|
||||
QTags.addButton('ipre', '代码高亮', '<pre class="prettyprint linenums" >\n\n</pre>', "");
|
||||
$("#content").pasteUploadImage(ajaxurl); //ajax img upload
|
||||
$(".insert-shortcodes").click(function() { //shortcode botton
|
||||
if ($(".shortcodes-wrap").hasClass("is-active")) {
|
||||
$(".shortcodes-wrap").removeClass("is-active")
|
||||
} else {
|
||||
$(".shortcodes-wrap").addClass("is-active")
|
||||
<script>
|
||||
jQuery(function($) {
|
||||
/* bengin */
|
||||
if ($("#wp-content-editor-tools").length > 0) {
|
||||
/***文章编辑器 */
|
||||
QTags.addButton('h2', 'H2标题', '<h2>', '</h2>');
|
||||
QTags.addButton('ipre', '代码高亮', '<pre class="prettyprint linenums" >\n\n</pre>', "");
|
||||
$("#content").pasteUploadImage(ajaxurl); //ajax img upload
|
||||
$(".insert-shortcodes").click(function() { //shortcode botton
|
||||
if ($(".shortcodes-wrap").hasClass("is-active")) {
|
||||
$(".shortcodes-wrap").removeClass("is-active")
|
||||
} else {
|
||||
$(".shortcodes-wrap").addClass("is-active")
|
||||
}
|
||||
});
|
||||
$(".add-shortcode").click(function() {
|
||||
send_to_editor($(this).data("shortcodes"));
|
||||
$(".shortcodes-wrap").removeClass("is-active");
|
||||
return false
|
||||
});
|
||||
}
|
||||
});
|
||||
$(".add-shortcode").click(function() {
|
||||
send_to_editor( $(this).data("shortcodes") );
|
||||
$(".shortcodes-wrap").removeClass("is-active");
|
||||
return false
|
||||
});
|
||||
}
|
||||
|
||||
if ($("#replysubmit").length > 0) {
|
||||
/**评论框 */
|
||||
$("textarea").keypress(function(e) {
|
||||
if (e.ctrlKey && e.which == 13 || e.which == 10) {
|
||||
$("#replybtn").click();
|
||||
if ($("#replysubmit").length > 0) {
|
||||
/**评论框 */
|
||||
$("textarea").keypress(function(e) {
|
||||
if (e.ctrlKey && e.which == 13 || e.which == 10) {
|
||||
$("#replybtn").click();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**end**/
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**end**/
|
||||
|
||||
});
|
||||
</script>
|
||||
<?php
|
||||
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
add_action('admin_footer', 'gdk_admin_script');
|
||||
|
||||
function gdk_admin_style()
|
||||
{
|
||||
?><style>
|
||||
body{font-family:"Microsoft YaHei"}
|
||||
.shortcodes-icon {display:inline-block;width:20px;height:20px;line-height:1;vertical-align:middle;margin:0 2px}
|
||||
.insert-shortcodes {position: relative; color: #3b88c3; border-color: #3b88c3;}
|
||||
.shortcodes-wrap {background:#fff;border:1px solid #ccc;box-shadow:2px 2px 3px rgba(0,0,0,0.24);padding:10px;position:absolute;top:54px;width:500px;display:none}
|
||||
.is-active.shortcodes-wrap {display:block}
|
||||
#wp-content-media-buttons > div> a:nth-child(20){background:#f6003c;border-color:#f6003c;color:#fff}
|
||||
.wp-block {max-width:45pc}
|
||||
.wp-block[data-align=wide] {max-width:810pt}
|
||||
.wp-block[data-align=full] {max-width:none}
|
||||
#activity-widget #the-comment-list .avatar{width:50px}
|
||||
.form-field-download_name,.form-field-download_size{width:45%;float:left}
|
||||
.form-field-download_link{clear:both}
|
||||
</style>
|
||||
<?php
|
||||
body {
|
||||
font-family: "Microsoft YaHei"
|
||||
}
|
||||
|
||||
.shortcodes-icon {
|
||||
display: inline-block;
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
line-height: 1;
|
||||
vertical-align: middle;
|
||||
margin: 0 2px
|
||||
}
|
||||
|
||||
.insert-shortcodes {
|
||||
position: relative;
|
||||
color: #3b88c3;
|
||||
border-color: #3b88c3;
|
||||
}
|
||||
|
||||
.shortcodes-wrap {
|
||||
background: #fff;
|
||||
border: 1px solid #ccc;
|
||||
box-shadow: 2px 2px 3px rgba(0, 0, 0, 0.24);
|
||||
padding: 10px;
|
||||
position: absolute;
|
||||
top: 54px;
|
||||
width: 500px;
|
||||
display: none
|
||||
}
|
||||
|
||||
.is-active.shortcodes-wrap {
|
||||
display: block
|
||||
}
|
||||
|
||||
#wp-content-media-buttons>div>a:nth-child(20) {
|
||||
background: #f6003c;
|
||||
border-color: #f6003c;
|
||||
color: #fff
|
||||
}
|
||||
|
||||
.wp-block {
|
||||
max-width: 45pc
|
||||
}
|
||||
|
||||
.wp-block[data-align=wide] {
|
||||
max-width: 810pt
|
||||
}
|
||||
|
||||
.wp-block[data-align=full] {
|
||||
max-width: none
|
||||
}
|
||||
|
||||
#activity-widget #the-comment-list .avatar {
|
||||
width: 50px
|
||||
}
|
||||
|
||||
.form-field-download_name,
|
||||
.form-field-download_size {
|
||||
width: 45%;
|
||||
float: left
|
||||
}
|
||||
|
||||
.form-field-download_link {
|
||||
clear: both
|
||||
}
|
||||
</style>
|
||||
<?php
|
||||
}
|
||||
add_action('admin_head', 'gdk_admin_style');
|
|
@ -11,45 +11,51 @@ class GDK_Payjs
|
|||
|
||||
public function __construct($config = null)
|
||||
{
|
||||
if (!$config) exit('config needed');
|
||||
if (!$config) {
|
||||
exit('config needed');
|
||||
}
|
||||
|
||||
$this->mchid = $config['mchid'];
|
||||
$this->key = $config['key'];
|
||||
$api_url = $config['api_url'] ?? 'https://payjs.cn/api/';
|
||||
|
||||
$this->api_url_native = $api_url . 'native';
|
||||
$this->api_url_cashier = $api_url . 'cashier';
|
||||
$this->api_url_mweb = $api_url . 'mweb';
|
||||
$this->api_url_close = $api_url . 'close';
|
||||
$this->api_url_check = $api_url . 'check';
|
||||
$this->key = $config['key'];
|
||||
$api_url = $config['api_url'] ?? 'https://payjs.cn/api/';
|
||||
$this->api_url_native = $api_url.'native';
|
||||
$this->api_url_cashier = $api_url.'cashier';
|
||||
$this->api_url_mweb = $api_url.'mweb';
|
||||
$this->api_url_close = $api_url.'close';
|
||||
$this->api_url_check = $api_url.'check';
|
||||
}
|
||||
|
||||
// 扫码支付
|
||||
public function native(array $data)
|
||||
{
|
||||
$this->url = $this->api_url_native;
|
||||
|
||||
return $this->post($data);
|
||||
}
|
||||
|
||||
// MWEB(H5) 支付
|
||||
public function mweb(array $data)
|
||||
{
|
||||
$this->url = $this->api_url_mweb;
|
||||
|
||||
return $this->post($data);
|
||||
}
|
||||
|
||||
// 收银台模式
|
||||
public function cashier(array $data)
|
||||
{
|
||||
$this->url = $this->api_url_cashier;
|
||||
$data = $this->sign($data);
|
||||
$url = $this->url . '?' . http_build_query($data);
|
||||
return $url;
|
||||
$data = $this->sign($data);
|
||||
|
||||
return $this->url.'?'.http_build_query($data);
|
||||
}
|
||||
|
||||
// 检查订单
|
||||
public function check($payjs_order_id)
|
||||
{
|
||||
$this->url = $this->api_url_check;
|
||||
$data = ['payjs_order_id' => $payjs_order_id];
|
||||
$data = ['payjs_order_id' => $payjs_order_id];
|
||||
|
||||
return $this->post($data);
|
||||
}
|
||||
|
||||
|
@ -57,11 +63,11 @@ class GDK_Payjs
|
|||
public function notify()
|
||||
{
|
||||
$data = $_POST;
|
||||
if ($this->checkSign($data) === true) {
|
||||
if (true === $this->checkSign($data)) {
|
||||
return $data;
|
||||
} else {
|
||||
exit("验签失败");
|
||||
}
|
||||
|
||||
exit('验签失败');
|
||||
}
|
||||
|
||||
// 数据签名
|
||||
|
@ -70,7 +76,8 @@ class GDK_Payjs
|
|||
$data['mchid'] = $this->mchid;
|
||||
array_filter($data);
|
||||
ksort($data);
|
||||
$data['sign'] = strtoupper(md5(urldecode(http_build_query($data) . '&key=' . $this->key)));
|
||||
$data['sign'] = strtoupper(md5(urldecode(http_build_query($data).'&key='.$this->key)));
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
@ -81,15 +88,17 @@ class GDK_Payjs
|
|||
unset($data['sign']);
|
||||
array_filter($data);
|
||||
ksort($data);
|
||||
$sign = strtoupper(md5(urldecode(http_build_query($data) . '&key=' . $this->key)));
|
||||
$sign = strtoupper(md5(urldecode(http_build_query($data).'&key='.$this->key)));
|
||||
|
||||
return $in_sign == $sign ? true : false;
|
||||
}
|
||||
|
||||
// 数据发送
|
||||
public function post($data) {
|
||||
$data = $this->sign($data);
|
||||
public function post($data)
|
||||
{
|
||||
$data = $this->sign($data);
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS );
|
||||
curl_setopt($ch, CURLOPT_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS);
|
||||
curl_setopt($ch, CURLOPT_URL, $this->url);
|
||||
curl_setopt($ch, CURLOPT_USERAGENT, 'HTTP CLIENT');
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
|
@ -99,7 +108,7 @@ class GDK_Payjs
|
|||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
|
||||
$rst = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
|
||||
return json_decode($rst, true);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -7,57 +7,59 @@
|
|||
* Author : Syamil MJ
|
||||
* Author URI : http://aquagraphite.com
|
||||
* License : WTFPL - http://sam.zoy.org/wtfpl/
|
||||
* Documentation : https://github.com/sy4mil/Aqua-Resizer/
|
||||
* Documentation : https://github.com/sy4mil/Aqua-Resizer/.
|
||||
*
|
||||
* @param string $url - (required) must be uploaded using wp media uploader
|
||||
* @param int $width - (required)
|
||||
* @param int $height - (optional)
|
||||
* @param bool $crop - (optional) default to soft crop
|
||||
* @param bool $single - (optional) returns an array if false
|
||||
* @param bool $upscale - (optional) resizes smaller images
|
||||
*
|
||||
* @param string $url - (required) must be uploaded using wp media uploader
|
||||
* @param int $width - (required)
|
||||
* @param int $height - (optional)
|
||||
* @param bool $crop - (optional) default to soft crop
|
||||
* @param bool $single - (optional) returns an array if false
|
||||
* @param bool $upscale - (optional) resizes smaller images
|
||||
* @uses wp_upload_dir()
|
||||
* @uses image_resize_dimensions()
|
||||
* @uses wp_get_image_editor()
|
||||
*
|
||||
* @return str|array
|
||||
* @return array|string
|
||||
*/
|
||||
|
||||
if (!class_exists('Aq_Resize')) {
|
||||
class Aq_Exception extends Exception
|
||||
{}
|
||||
{
|
||||
}
|
||||
|
||||
class Aq_Resize
|
||||
{
|
||||
/**
|
||||
* The singleton instance
|
||||
*/
|
||||
private static $__instance = null;
|
||||
|
||||
/**
|
||||
* Should an Aq_Exception be thrown on error?
|
||||
* If false (default), then the error will just be logged.
|
||||
*/
|
||||
public $throwOnError = false;
|
||||
/**
|
||||
* The singleton instance.
|
||||
*/
|
||||
private static $__instance;
|
||||
|
||||
/**
|
||||
* No initialization allowed
|
||||
* No initialization allowed.
|
||||
*/
|
||||
private function __construct()
|
||||
{}
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* No cloning allowed
|
||||
* No cloning allowed.
|
||||
*/
|
||||
private function __clone()
|
||||
{}
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* For your custom default usage you may want to initialize an Aq_Resize object by yourself and then have own defaults
|
||||
* For your custom default usage you may want to initialize an Aq_Resize object by yourself and then have own defaults.
|
||||
*/
|
||||
public static function getInstance()
|
||||
{
|
||||
if (self::$instance == null) {
|
||||
self::$instance = new self;
|
||||
if (null == self::$instance) {
|
||||
self::$instance = new self();
|
||||
}
|
||||
|
||||
return self::$instance;
|
||||
|
@ -65,6 +67,13 @@ if (!class_exists('Aq_Resize')) {
|
|||
|
||||
/**
|
||||
* Run, forest.
|
||||
*
|
||||
* @param mixed $url
|
||||
* @param null|mixed $width
|
||||
* @param null|mixed $height
|
||||
* @param null|mixed $crop
|
||||
* @param mixed $single
|
||||
* @param mixed $upscale
|
||||
*/
|
||||
public function process($url, $width = null, $height = null, $crop = null, $single = true, $upscale = false)
|
||||
{
|
||||
|
@ -80,17 +89,17 @@ if (!class_exists('Aq_Resize')) {
|
|||
|
||||
// Caipt'n, ready to hook.
|
||||
if (true === $upscale) {
|
||||
add_filter('image_resize_dimensions', array($this, 'aq_upscale'), 10, 6);
|
||||
add_filter('image_resize_dimensions', [$this, 'aq_upscale'], 10, 6);
|
||||
}
|
||||
|
||||
// Define upload path & dir.
|
||||
$upload_info = wp_upload_dir();
|
||||
$upload_dir = $upload_info['basedir'];
|
||||
$upload_url = $upload_info['baseurl'];
|
||||
$upload_dir = $upload_info['basedir'];
|
||||
$upload_url = $upload_info['baseurl'];
|
||||
|
||||
$http_prefix = "http://";
|
||||
$https_prefix = "https://";
|
||||
$relative_prefix = "//"; // The protocol-relative URL
|
||||
$http_prefix = 'http://';
|
||||
$https_prefix = 'https://';
|
||||
$relative_prefix = '//'; // The protocol-relative URL
|
||||
|
||||
/* if the $url scheme differs from $upload_url scheme, make them match
|
||||
if the schemes differe, images don't show up. */
|
||||
|
@ -99,42 +108,42 @@ if (!class_exists('Aq_Resize')) {
|
|||
} elseif (!strncmp($url, $http_prefix, strlen($http_prefix))) { //if url begins with http:// make $upload_url begin with http:// as well
|
||||
$upload_url = str_replace($https_prefix, $http_prefix, $upload_url);
|
||||
} elseif (!strncmp($url, $relative_prefix, strlen($relative_prefix))) { //if url begins with // make $upload_url begin with // as well
|
||||
$upload_url = str_replace(array(0 => "$http_prefix", 1 => "$https_prefix"), $relative_prefix, $upload_url);
|
||||
$upload_url = str_replace([0 => "{$http_prefix}", 1 => "{$https_prefix}"], $relative_prefix, $upload_url);
|
||||
}
|
||||
|
||||
// Check if $img_url is local.
|
||||
if (false === strpos($url, $upload_url)) {
|
||||
throw new Aq_Exception('图片必须是本地图片: ' . $url);
|
||||
throw new Aq_Exception('图片必须是本地图片: '.$url);
|
||||
}
|
||||
|
||||
// Define path of image.
|
||||
$rel_path = str_replace($upload_url, '', $url);
|
||||
$img_path = $upload_dir . $rel_path;
|
||||
$img_path = $upload_dir.$rel_path;
|
||||
|
||||
// Check if img path exists, and is an image indeed.
|
||||
if (!file_exists($img_path) or !getimagesize($img_path)) {
|
||||
throw new Aq_Exception('图片不存在或者不是一个图片文件: ' . $img_path);
|
||||
throw new Aq_Exception('图片不存在或者不是一个图片文件: '.$img_path);
|
||||
}
|
||||
|
||||
// Get image info.
|
||||
$info = pathinfo($img_path);
|
||||
$ext = $info['extension'];
|
||||
$info = pathinfo($img_path);
|
||||
$ext = $info['extension'];
|
||||
list($orig_w, $orig_h) = getimagesize($img_path);
|
||||
|
||||
// Get image size after cropping.
|
||||
$dims = image_resize_dimensions($orig_w, $orig_h, $width, $height, $crop);
|
||||
$dims = image_resize_dimensions($orig_w, $orig_h, $width, $height, $crop);
|
||||
$dst_w = $dims[4];
|
||||
$dst_h = $dims[5];
|
||||
|
||||
// Return the original image only if it exactly fits the needed measures.
|
||||
if (!$dims || (((null === $height && $orig_w == $width) xor (null === $width && $orig_h == $height)) xor ($height == $orig_h && $width == $orig_w))) {
|
||||
$img_url = $url;
|
||||
$dst_w = $orig_w;
|
||||
$dst_h = $orig_h;
|
||||
$dst_w = $orig_w;
|
||||
$dst_h = $orig_h;
|
||||
} else {
|
||||
// Use this to check if cropped image already exists, so we can return that instead.
|
||||
$suffix = "{$dst_w}x{$dst_h}";
|
||||
$dst_rel_path = str_replace('.' . $ext, '', $rel_path);
|
||||
$suffix = "{$dst_w}x{$dst_h}";
|
||||
$dst_rel_path = str_replace('.'.$ext, '', $rel_path);
|
||||
$destfilename = "{$upload_dir}{$dst_rel_path}-{$suffix}.{$ext}";
|
||||
|
||||
if (!$dims || (true == $crop && false == $upscale && ($dst_w < $width || $dst_h < $height))) {
|
||||
|
@ -142,34 +151,32 @@ if (!class_exists('Aq_Resize')) {
|
|||
throw new Aq_Exception('Unable to resize image because image_resize_dimensions() failed');
|
||||
}
|
||||
// Else check if cache exists.
|
||||
elseif (file_exists($destfilename) && getimagesize($destfilename)) {
|
||||
if (file_exists($destfilename) && getimagesize($destfilename)) {
|
||||
$img_url = "{$upload_url}{$dst_rel_path}-{$suffix}.{$ext}";
|
||||
}
|
||||
// Else, we resize the image and return the new resized image url.
|
||||
else {
|
||||
|
||||
$editor = wp_get_image_editor($img_path);
|
||||
|
||||
if (is_wp_error($editor) || is_wp_error($editor->resize($width, $height, $crop))) {
|
||||
throw new Aq_Exception('Unable to get WP_Image_Editor: ' .
|
||||
$editor->get_error_message() . ' (is GD or ImageMagick installed?)');
|
||||
throw new Aq_Exception('Unable to get WP_Image_Editor: '.
|
||||
$editor->get_error_message().' (is GD or ImageMagick installed?)');
|
||||
}
|
||||
|
||||
$resized_file = $editor->save();
|
||||
|
||||
if (!is_wp_error($resized_file)) {
|
||||
$resized_rel_path = str_replace($upload_dir, '', $resized_file['path']);
|
||||
$img_url = $upload_url . $resized_rel_path;
|
||||
$img_url = $upload_url.$resized_rel_path;
|
||||
} else {
|
||||
throw new Aq_Exception('Unable to save resized image file: ' . $editor->get_error_message());
|
||||
throw new Aq_Exception('Unable to save resized image file: '.$editor->get_error_message());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// Okay, leave the ship.
|
||||
if (true === $upscale) {
|
||||
remove_filter('image_resize_dimensions', array($this, 'aq_upscale'));
|
||||
remove_filter('image_resize_dimensions', [$this, 'aq_upscale']);
|
||||
}
|
||||
|
||||
// Return the output.
|
||||
|
@ -178,29 +185,35 @@ if (!class_exists('Aq_Resize')) {
|
|||
$image = $img_url;
|
||||
} else {
|
||||
// array return.
|
||||
$image = array(
|
||||
$image = [
|
||||
0 => $img_url,
|
||||
1 => $dst_w,
|
||||
2 => $dst_h,
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
return $image;
|
||||
} catch (Aq_Exception $ex) {
|
||||
error_log('Aq_Resize.process() error: ' . $ex->getMessage());
|
||||
error_log('Aq_Resize.process() error: '.$ex->getMessage());
|
||||
|
||||
if ($this->throwOnError) {
|
||||
// Bubble up exception.
|
||||
throw $ex;
|
||||
} else {
|
||||
// Return false, so that this patch is backwards-compatible.
|
||||
return false;
|
||||
}
|
||||
// Return false, so that this patch is backwards-compatible.
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback to overwrite WP computing of thumbnail measures
|
||||
* Callback to overwrite WP computing of thumbnail measures.
|
||||
*
|
||||
* @param mixed $default
|
||||
* @param mixed $orig_w
|
||||
* @param mixed $orig_h
|
||||
* @param mixed $dest_w
|
||||
* @param mixed $dest_h
|
||||
* @param mixed $crop
|
||||
*/
|
||||
public function aq_upscale($default, $orig_w, $orig_h, $dest_w, $dest_h, $crop)
|
||||
{
|
||||
|
@ -211,8 +224,8 @@ if (!class_exists('Aq_Resize')) {
|
|||
|
||||
// Here is the point we allow to use larger image size than the original one.
|
||||
$aspect_ratio = $orig_w / $orig_h;
|
||||
$new_w = $dest_w;
|
||||
$new_h = $dest_h;
|
||||
$new_w = $dest_w;
|
||||
$new_h = $dest_h;
|
||||
|
||||
if (!$new_w) {
|
||||
$new_w = intval($new_h * $aspect_ratio);
|
||||
|
@ -230,27 +243,34 @@ if (!class_exists('Aq_Resize')) {
|
|||
$s_x = floor(($orig_w - $crop_w) / 2);
|
||||
$s_y = floor(($orig_h - $crop_h) / 2);
|
||||
|
||||
return array(0, 0, (int)$s_x, (int)$s_y, (int)$new_w, (int)$new_h, (int)$crop_w, (int)$crop_h);
|
||||
return [0, 0, (int) $s_x, (int) $s_y, (int) $new_w, (int) $new_h, (int) $crop_w, (int) $crop_h];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('aq_resize')) {
|
||||
|
||||
/**
|
||||
* This is just a tiny wrapper function for the class above so that there is no
|
||||
* need to change any code in your own WP themes. Usage is still the same :)
|
||||
* need to change any code in your own WP themes. Usage is still the same :).
|
||||
*
|
||||
* @param mixed $url
|
||||
* @param null|mixed $width
|
||||
* @param null|mixed $height
|
||||
* @param null|mixed $crop
|
||||
* @param mixed $single
|
||||
* @param mixed $upscale
|
||||
*/
|
||||
function aq_resize($url, $width = null, $height = null, $crop = null, $single = true, $upscale = false)
|
||||
{
|
||||
/* WPML Fix */
|
||||
// WPML Fix
|
||||
if (defined('ICL_SITEPRESS_VERSION')) {
|
||||
global $sitepress;
|
||||
$url = $sitepress->convert_url($url, $sitepress->get_default_language());
|
||||
}
|
||||
/* WPML Fix */
|
||||
// WPML Fix
|
||||
|
||||
$aq_resize = Aq_Resize::getInstance();
|
||||
|
||||
return $aq_resize->process($url, $width, $height, $crop, $single, $upscale);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,11 +3,13 @@
|
|||
include 'local_avatars.php'; //本地头像
|
||||
|
||||
include 'updates.php'; //在线更新
|
||||
include( 'widget_cache.php' );//小工具缓存
|
||||
|
||||
include 'widget_cache.php'; //小工具缓存
|
||||
|
||||
include 'Payjs.php'; //支付功能
|
||||
|
||||
include 'points/points.php'; //积分功能
|
||||
|
||||
include 'aq_resizer.php'; //缩略图功能
|
||||
include 'wechat.php'; //微信功能
|
||||
|
||||
include 'wechat.php'; //微信功能
|
||||
|
|
|
@ -4,70 +4,76 @@
|
|||
class gdk_local_avatars
|
||||
{
|
||||
private $__user_id_being_edited;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
add_action('admin_init', array(
|
||||
add_action('admin_init', [
|
||||
$this,
|
||||
'admin_init',
|
||||
));
|
||||
add_action('show_user_profile', array(
|
||||
]);
|
||||
add_action('show_user_profile', [
|
||||
$this,
|
||||
'edit_user_profile',
|
||||
));
|
||||
add_action('edit_user_profile', array(
|
||||
]);
|
||||
add_action('edit_user_profile', [
|
||||
$this,
|
||||
'edit_user_profile',
|
||||
));
|
||||
add_action('personal_options_update', array(
|
||||
]);
|
||||
add_action('personal_options_update', [
|
||||
$this,
|
||||
'edit_user_profile_update',
|
||||
));
|
||||
add_action('edit_user_profile_update', array(
|
||||
]);
|
||||
add_action('edit_user_profile_update', [
|
||||
$this,
|
||||
'edit_user_profile_update',
|
||||
));
|
||||
add_filter('get_avatar', array(
|
||||
]);
|
||||
add_filter('get_avatar', [
|
||||
$this,
|
||||
'get_avatar',
|
||||
), 10, 5);
|
||||
add_filter('avatar_defaults', array(
|
||||
], 10, 5);
|
||||
add_filter('avatar_defaults', [
|
||||
$this,
|
||||
'avatar_defaults',
|
||||
));
|
||||
]);
|
||||
}
|
||||
|
||||
public function admin_init()
|
||||
{
|
||||
register_setting('discussion', 'gdk_local_avatars_caps', array(
|
||||
register_setting('discussion', 'gdk_local_avatars_caps', [
|
||||
$this,
|
||||
'sanitize_options',
|
||||
));
|
||||
add_settings_field('basic-user-avatars-caps', '本地上传头像权限管理', array(
|
||||
]);
|
||||
add_settings_field('basic-user-avatars-caps', '本地上传头像权限管理', [
|
||||
$this,
|
||||
'avatar_settings_field',
|
||||
), 'discussion', 'avatars');
|
||||
], 'discussion', 'avatars');
|
||||
}
|
||||
|
||||
public function avatar_settings_field($args)
|
||||
{
|
||||
$options = get_option('gdk_local_avatars_caps');
|
||||
?>
|
||||
<label for="gdk_local_avatars_caps">
|
||||
<input type="checkbox" name="gdk_local_avatars_caps" id="gdk_local_avatars_caps" value="1" <?php
|
||||
checked($options['gdk_local_avatars_caps'], 1); ?>/>仅具有头像上传权限的用户具有设置本地头像权限(作者及更高等级角色)</label>
|
||||
<?php
|
||||
}
|
||||
$options = get_option('gdk_local_avatars_caps'); ?>
|
||||
<label for="gdk_local_avatars_caps">
|
||||
<input type="checkbox" name="gdk_local_avatars_caps" id="gdk_local_avatars_caps" value="1" <?php
|
||||
checked($options['gdk_local_avatars_caps'], 1); ?>/>仅具有头像上传权限的用户具有设置本地头像权限(作者及更高等级角色)
|
||||
</label>
|
||||
<?php
|
||||
}
|
||||
|
||||
public function sanitize_options($input)
|
||||
{
|
||||
$new_input['gdk_local_avatars_caps'] = empty($input['gdk_local_avatars_caps']) ? 0 : 1;
|
||||
|
||||
return $new_input;
|
||||
}
|
||||
|
||||
public function get_avatar($avatar, $id_or_email, $size = 96, $default, $alt)
|
||||
{
|
||||
if (is_numeric($id_or_email)) {
|
||||
$user_id = (int)$id_or_email;
|
||||
$user_id = (int) $id_or_email;
|
||||
} elseif (is_string($id_or_email) && ($user = get_user_by('email', $id_or_email))) {
|
||||
$user_id = $user->ID;
|
||||
} elseif (is_object($id_or_email) && !empty($id_or_email->user_id)) {
|
||||
$user_id = (int)$id_or_email->user_id;
|
||||
$user_id = (int) $id_or_email->user_id;
|
||||
}
|
||||
|
||||
if (empty($user_id)) {
|
||||
|
@ -79,41 +85,43 @@ checked($options['gdk_local_avatars_caps'], 1); ?>/>仅具有头像上传权限
|
|||
return $avatar;
|
||||
}
|
||||
|
||||
$size = (int)$size;
|
||||
$size = (int) $size;
|
||||
if (empty($alt)) {
|
||||
$alt = get_the_author_meta('display_name', $user_id);
|
||||
}
|
||||
|
||||
if (empty($local_avatars[$size])) {
|
||||
$upload_path = wp_upload_dir();
|
||||
$upload_path = wp_upload_dir();
|
||||
$avatar_full_path = str_replace($upload_path['baseurl'], $upload_path['basedir'], $local_avatars['full']);
|
||||
$image = wp_get_image_editor($avatar_full_path);
|
||||
$image = wp_get_image_editor($avatar_full_path);
|
||||
if (!is_wp_error($image)) {
|
||||
$image->resize($size, $size, true);
|
||||
$image_sized = $image->save();
|
||||
}
|
||||
$local_avatars[$size] = is_wp_error($image_sized) ? $local_avatars[$size] = $local_avatars['full'] : str_replace($upload_path['basedir'], $upload_path['baseurl'], $image_sized['path']);
|
||||
update_user_meta($user_id, 'simple_local_avatar', $local_avatars);
|
||||
} elseif (substr($local_avatars[$size], 0, 4) != 'http') {
|
||||
} elseif ('http' != substr($local_avatars[$size], 0, 4)) {
|
||||
$local_avatars[$size] = home_url($local_avatars[$size]);
|
||||
}
|
||||
$author_class = is_author($user_id) ? ' current-author' : '';
|
||||
$avatar = "<img alt='" . esc_attr($alt) . "' src='" . $local_avatars[$size] . "' class='avatar avatar-{$size}{$author_class} photo' height='{$size}' width='{$size}' />";
|
||||
$avatar = "<img alt='".esc_attr($alt)."' src='".$local_avatars[$size]."' class='avatar avatar-{$size}{$author_class} photo' height='{$size}' width='{$size}' />";
|
||||
|
||||
return apply_filters('simple_local_avatar', $avatar);
|
||||
}
|
||||
|
||||
public function edit_user_profile($profileuser)
|
||||
{
|
||||
?>
|
||||
<h3>头像</h3>
|
||||
<table class="form-table">
|
||||
<tr>
|
||||
<th><label for="basic-user-avatar">上传头像</label></th>
|
||||
<td style="width: 50px;" valign="top">
|
||||
<?php
|
||||
<h3>头像</h3>
|
||||
<table class="form-table">
|
||||
<tr>
|
||||
<th><label for="basic-user-avatar">上传头像</label></th>
|
||||
<td style="width: 50px;" valign="top">
|
||||
<?php
|
||||
echo get_avatar($profileuser->ID); ?>
|
||||
</td>
|
||||
<td>
|
||||
<?php
|
||||
</td>
|
||||
<td>
|
||||
<?php
|
||||
$options = get_option('gdk_local_avatars_caps');
|
||||
if (empty($options['gdk_local_avatars_caps']) || current_user_can('upload_files')) {
|
||||
// Nonce security ftw
|
||||
|
@ -131,14 +139,18 @@ $options = get_option('gdk_local_avatars_caps');
|
|||
} else {
|
||||
echo '<span class="description">你没有头像上传权限,如需要修改本地头像,请联系站点管理员</span>';
|
||||
}
|
||||
}
|
||||
?>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<script type="text/javascript">var form = document.getElementById('your-profile');form.encoding = 'multipart/form-data';form.setAttribute('enctype', 'multipart/form-data');</script>
|
||||
<?php
|
||||
}
|
||||
} ?>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<script type="text/javascript">
|
||||
var form = document.getElementById('your-profile');
|
||||
form.encoding = 'multipart/form-data';
|
||||
form.setAttribute('enctype', 'multipart/form-data');
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
|
||||
public function edit_user_profile_update($user_id)
|
||||
{
|
||||
if (!isset($_POST['_simple_local_avatar_nonce']) || !wp_verify_nonce($_POST['_simple_local_avatar_nonce'], 'simple_local_avatar_nonce')) {
|
||||
|
@ -146,13 +158,13 @@ $options = get_option('gdk_local_avatars_caps');
|
|||
}
|
||||
|
||||
if (!empty($_FILES['basic-user-avatar']['name'])) {
|
||||
$mimes = array(
|
||||
$mimes = [
|
||||
'jpg|jpeg|jpe' => 'image/jpeg',
|
||||
'gif' => 'image/gif',
|
||||
'png' => 'image/png',
|
||||
);
|
||||
'gif' => 'image/gif',
|
||||
'png' => 'image/png',
|
||||
];
|
||||
if (!function_exists('wp_handle_upload')) {
|
||||
require_once ABSPATH . 'wp-admin/includes/file.php';
|
||||
require_once ABSPATH.'wp-admin/includes/file.php';
|
||||
}
|
||||
|
||||
$this->avatar_delete($user_id);
|
||||
|
@ -161,29 +173,32 @@ $options = get_option('gdk_local_avatars_caps');
|
|||
}
|
||||
|
||||
$this->user_id_being_edited = $user_id;
|
||||
$avatar = wp_handle_upload($_FILES['basic-user-avatar'], array(
|
||||
'mimes' => $mimes,
|
||||
'test_form' => false,
|
||||
'unique_filename_callback' => array(
|
||||
$avatar = wp_handle_upload($_FILES['basic-user-avatar'], [
|
||||
'mimes' => $mimes,
|
||||
'test_form' => false,
|
||||
'unique_filename_callback' => [
|
||||
$this,
|
||||
'unique_filename_callback',
|
||||
),
|
||||
));
|
||||
update_user_meta($user_id, 'simple_local_avatar', array(
|
||||
],
|
||||
]);
|
||||
update_user_meta($user_id, 'simple_local_avatar', [
|
||||
'full' => $avatar['url'],
|
||||
));
|
||||
]);
|
||||
} elseif (!empty($_POST['basic-user-avatar-erase'])) {
|
||||
$this->avatar_delete($user_id);
|
||||
}
|
||||
}
|
||||
|
||||
public function avatar_defaults($avatar_defaults)
|
||||
{
|
||||
remove_action('get_avatar', array(
|
||||
remove_action('get_avatar', [
|
||||
$this,
|
||||
'get_avatar',
|
||||
));
|
||||
]);
|
||||
|
||||
return $avatar_defaults;
|
||||
}
|
||||
|
||||
public function avatar_delete($user_id)
|
||||
{
|
||||
$old_avatars = get_user_meta($user_id, 'simple_local_avatar', true);
|
||||
|
@ -191,21 +206,23 @@ $options = get_option('gdk_local_avatars_caps');
|
|||
if (is_array($old_avatars)) {
|
||||
foreach ($old_avatars as $old_avatar) {
|
||||
$old_avatar_path = str_replace($upload_path['baseurl'], $upload_path['basedir'], $old_avatar);
|
||||
@unlink($old_avatar_path);
|
||||
unlink($old_avatar_path);
|
||||
}
|
||||
}
|
||||
delete_user_meta($user_id, 'simple_local_avatar');
|
||||
}
|
||||
|
||||
public function unique_filename_callback($dir, $name, $ext)
|
||||
{
|
||||
$user = get_user_by('id', (int)$this->user_id_being_edited);
|
||||
$name = $base_name = sanitize_file_name($user->ID . '_avatar');
|
||||
$user = get_user_by('id', (int) $this->user_id_being_edited);
|
||||
$name = $base_name = sanitize_file_name($user->ID.'_avatar');
|
||||
$number = 1;
|
||||
while (file_exists($dir . "/$name$ext")) {
|
||||
$name = $base_name . '_' . $number;
|
||||
$number++;
|
||||
while (file_exists($dir."/{$name}{$ext}")) {
|
||||
$name = $base_name.'_'.$number;
|
||||
++$number;
|
||||
}
|
||||
return $name . $ext;
|
||||
|
||||
return $name.$ext;
|
||||
}
|
||||
}
|
||||
$gdk_local_avatars = new gdk_local_avatars;
|
||||
$gdk_local_avatars = new gdk_local_avatars();
|
||||
|
|
|
@ -1,35 +1,33 @@
|
|||
<?php
|
||||
/**
|
||||
* GDK_Points Table class
|
||||
* GDK_Points Table class.
|
||||
*/
|
||||
|
||||
// WP_List_Table is not loaded automatically so we need to load it in our application
|
||||
if (!class_exists('WP_List_Table')) {
|
||||
require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
|
||||
require_once ABSPATH.'wp-admin/includes/class-wp-list-table.php';
|
||||
}
|
||||
|
||||
class GDK_Points_List_Table extends WP_List_Table
|
||||
{
|
||||
/**
|
||||
* Prepare the items for the table to process
|
||||
*
|
||||
* @return Void
|
||||
* Prepare the items for the table to process.
|
||||
*/
|
||||
public function prepare_items()
|
||||
{
|
||||
$columns = $this->get_columns();
|
||||
$columns = $this->get_columns();
|
||||
$sortable = $this->get_sortable_columns();
|
||||
$data = GDK_Points::get_points(null, null, null, ARRAY_A);
|
||||
usort( $data, array(
|
||||
$data = GDK_Points::get_points(null, null, null, ARRAY_A);
|
||||
usort($data, [
|
||||
&$this,
|
||||
'sort_data'
|
||||
) );
|
||||
$perPage = 30; //每页30个数据
|
||||
'sort_data',
|
||||
]);
|
||||
$perPage = 30; //每页30个数据
|
||||
$currentPage = $this->get_pagenum();
|
||||
$totalItems = count($data);
|
||||
$totalItems = count($data);
|
||||
$this->set_pagination_args([
|
||||
'total_items' => $totalItems,
|
||||
'per_page' => $perPage,
|
||||
'per_page' => $perPage,
|
||||
]);
|
||||
|
||||
$data = array_slice($data, (($currentPage - 1) * $perPage), $perPage);
|
||||
|
@ -43,42 +41,40 @@ class GDK_Points_List_Table extends WP_List_Table
|
|||
|
||||
/**
|
||||
* Override the parent columns method.
|
||||
* Defines the columns to use in your listing table
|
||||
* Defines the columns to use in your listing table.
|
||||
*
|
||||
* @return Array
|
||||
* @return array
|
||||
*/
|
||||
public function get_columns()
|
||||
{
|
||||
$columns = [
|
||||
'point_id' => 'ID',
|
||||
'user_id' => '用户ID',
|
||||
'points' => '金币',
|
||||
return [
|
||||
'point_id' => 'ID',
|
||||
'user_id' => '用户ID',
|
||||
'points' => '金币',
|
||||
'description' => '描述',
|
||||
'datetime' => '日期&时间',
|
||||
'status' => '状态',
|
||||
'actions' => '操作',
|
||||
'datetime' => '日期&时间',
|
||||
'status' => '状态',
|
||||
'actions' => '操作',
|
||||
];
|
||||
|
||||
return $columns;
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the sortable columns
|
||||
* Define the sortable columns.
|
||||
*
|
||||
* @return Array
|
||||
* @return array
|
||||
*/
|
||||
public function get_sortable_columns()
|
||||
{
|
||||
return [
|
||||
'point_id' => [
|
||||
'point_id' => [
|
||||
'point_id',
|
||||
false,
|
||||
],
|
||||
'user_id' => [
|
||||
'user_id' => [
|
||||
'user_id',
|
||||
false,
|
||||
],
|
||||
'points' => [
|
||||
'points' => [
|
||||
'points',
|
||||
false,
|
||||
],
|
||||
|
@ -86,28 +82,26 @@ class GDK_Points_List_Table extends WP_List_Table
|
|||
'description',
|
||||
false,
|
||||
],
|
||||
'datetime' => [
|
||||
'datetime' => [
|
||||
'datetime',
|
||||
false,
|
||||
],
|
||||
'status' => [
|
||||
'status' => [
|
||||
'status',
|
||||
false,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Define what data to show on each column of the table
|
||||
* Define what data to show on each column of the table.
|
||||
*
|
||||
* @param Array $item
|
||||
* Data
|
||||
* @param String $column_name
|
||||
* - Current column name
|
||||
* @param array $item
|
||||
* Data
|
||||
* @param string $column_name
|
||||
* - Current column name
|
||||
*
|
||||
* @return Mixed
|
||||
* @return mixed
|
||||
*/
|
||||
public function column_default($item, $column_name)
|
||||
{
|
||||
|
@ -119,33 +113,42 @@ class GDK_Points_List_Table extends WP_List_Table
|
|||
case 'datetime':
|
||||
case 'status':
|
||||
return $item[$column_name];
|
||||
|
||||
break;
|
||||
|
||||
case 'actions':
|
||||
$actions = [
|
||||
'edit' => sprintf('<a href="?page=%s&action=%s&point_id=%s">编辑</a>', $_REQUEST['page'], 'edit', $item['point_id']),
|
||||
'edit' => sprintf('<a href="?page=%s&action=%s&point_id=%s">编辑</a>', $_REQUEST['page'], 'edit', $item['point_id']),
|
||||
'delete' => sprintf('<a href="?page=%s&action=%s&point_id=%s">删除</a>', $_REQUEST['page'], 'delete', $item['point_id']),
|
||||
];
|
||||
|
||||
//Return the title contents
|
||||
return sprintf('%1$s%2$s', $item[$column_name] ?? "",
|
||||
return sprintf(
|
||||
'%1$s%2$s',
|
||||
$item[$column_name] ?? '',
|
||||
$this->row_actions($actions, true)
|
||||
);
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
return print_r($item, true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows you to sort the data by the variables set in the $_GET
|
||||
* Allows you to sort the data by the variables set in the $_GET.
|
||||
*
|
||||
* @return Mixed
|
||||
* @param mixed $a
|
||||
* @param mixed $b
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
private function sort_data($a, $b)
|
||||
{
|
||||
// Set defaults
|
||||
$orderby = 'point_id';
|
||||
$order = 'desc';//desc asc
|
||||
$order = 'desc'; //desc asc
|
||||
|
||||
// If orderby is set, use this as the sort column
|
||||
if (!empty($_GET['orderby'])) {
|
||||
|
@ -159,7 +162,7 @@ class GDK_Points_List_Table extends WP_List_Table
|
|||
|
||||
$result = strnatcmp($a[$orderby], $b[$orderby]);
|
||||
|
||||
if ($order === 'asc') {
|
||||
if ('asc' === $order) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
@ -168,11 +171,10 @@ class GDK_Points_List_Table extends WP_List_Table
|
|||
}
|
||||
|
||||
/**
|
||||
* GDK_Points Admin class
|
||||
* GDK_Points Admin class.
|
||||
*/
|
||||
class GDK_Points_Admin
|
||||
{
|
||||
|
||||
public static function init()
|
||||
{
|
||||
add_action('admin_notices', [__CLASS__, 'admin_notices']);
|
||||
|
@ -198,47 +200,47 @@ class GDK_Points_Admin
|
|||
|
||||
public static function points_menu()
|
||||
{
|
||||
$alert = "";
|
||||
$alert = '';
|
||||
if (isset($_POST['psearch'])) {
|
||||
$sdata = trim($_POST['psearch']);
|
||||
if (preg_match('/E20/', $sdata) ) {
|
||||
if (preg_match('/E20/', $sdata)) {
|
||||
//order id
|
||||
global $wpdb;
|
||||
$point_id = $wpdb->get_row("SELECT point_id FROM " . GDK_Points_Database::points_get_table("users") . " WHERE description = '{$sdata}'", ARRAY_A)['point_id'];
|
||||
$points = GDK_Points::get_point($point_id);
|
||||
}elseif (preg_match('/(D|d)/', $sdata)){// description
|
||||
$data = substr($sdata,1);
|
||||
global $wpdb;
|
||||
$points = $wpdb->get_results("SELECT * FROM " . GDK_Points_Database::points_get_table("users") . " WHERE description = '{$data}'");
|
||||
//var_dump($points);
|
||||
$k[] = '<div style="margin-bottom:10px;">文章ID:' . $data . ' || 文章名为:' . get_post($data)->post_title . '</div><hr />';
|
||||
} elseif (filter_var($sdata, FILTER_VALIDATE_EMAIL)) {
|
||||
$point_id = $wpdb->get_row('SELECT point_id FROM '.GDK_Points_Database::points_get_table('users')." WHERE description = '{$sdata}'", ARRAY_A)['point_id'];
|
||||
$points = GDK_Points::get_point($point_id);
|
||||
} elseif (preg_match('/(D|d)/', $sdata)) {// description
|
||||
$data = substr($sdata, 1);
|
||||
global $wpdb;
|
||||
$points = $wpdb->get_results('SELECT * FROM '.GDK_Points_Database::points_get_table('users')." WHERE description = '{$data}'");
|
||||
//var_dump($points);
|
||||
$k[] = '<div style="margin-bottom:10px;">文章ID:'.$data.' || 文章名为:'.get_post($data)->post_title.'</div><hr />';
|
||||
} elseif (filter_var($sdata, FILTER_VALIDATE_EMAIL)) {
|
||||
//email
|
||||
$user = get_user_by('email', $sdata);
|
||||
$user = get_user_by('email', $sdata);
|
||||
$points = GDK_Points::get_points_by_user($user->ID);
|
||||
$k[] = '<div style="margin-bottom:10px;">用户ID:' . $user->ID . ' || 总金币为:' . GDK_Points::get_user_total_points($user->ID) . '</div>';
|
||||
$k[] = '<div style="margin-bottom:10px;">用户ID:'.$user->ID.' || 总金币为:'.GDK_Points::get_user_total_points($user->ID).'</div>';
|
||||
} else {
|
||||
//userid
|
||||
$points = GDK_Points::get_points_by_user($sdata);
|
||||
$k[] = '<div style="margin-bottom:10px;">用户ID:' . $sdata . ' || 总金币为:' . GDK_Points::get_user_total_points($sdata) . '</div>';
|
||||
$k[] = '<div style="margin-bottom:10px;">用户ID:'.$sdata.' || 总金币为:'.GDK_Points::get_user_total_points($sdata).'</div>';
|
||||
}
|
||||
if (is_array($points)) {
|
||||
foreach ($points as $point) {
|
||||
$userid = $point->user_id;
|
||||
$user_name = get_user_by('id', $userid)->display_name;
|
||||
$k[] = '<div style="margin-bottom:5px;">用户ID:' . $userid . ' || 金币:' . $point->points . ' || 描述:' . $point->description . ' || 日期:' . $point->datetime . ' || 用户名:' . $user_name . '</div>';
|
||||
$userid = $point->user_id;
|
||||
$user_name = get_user_by('id', $userid)->display_name;
|
||||
$k[] = '<div style="margin-bottom:5px;">用户ID:'.$userid.' || 金币:'.$point->points.' || 描述:'.$point->description.' || 日期:'.$point->datetime.' || 用户名:'.$user_name.'</div>';
|
||||
}
|
||||
} else {
|
||||
$k[] = '<div style="margin-bottom:5px;">用户ID:' . $point->user_id . ' 金币:' . $points->points . ' 描述:' . $points->description . ' 日期:' . $points->datetime . '</div>';
|
||||
$k[] = '<div style="margin-bottom:5px;">用户ID:'.$point->user_id.' 金币:'.$points->points.' 描述:'.$points->description.' 日期:'.$points->datetime.'</div>';
|
||||
}
|
||||
$alert = implode(" ", $k);
|
||||
$alert = implode(' ', $k);
|
||||
}
|
||||
|
||||
if (isset($_POST['save']) && isset($_POST['action'])) {
|
||||
if ($_POST['action'] == "edit") {
|
||||
if (isset($_POST['save'], $_POST['action'])) {
|
||||
if ('edit' == $_POST['action']) {
|
||||
$point_id = isset($_POST['point_id']) ? intval($_POST['point_id']) : null;
|
||||
$points = GDK_Points::get_point($point_id);
|
||||
$data = array();
|
||||
$points = GDK_Points::get_point($point_id);
|
||||
$data = [];
|
||||
if (isset($_POST['user_mail'])) {
|
||||
$data['user_mail'] = $_POST['user_mail'];
|
||||
}
|
||||
|
@ -265,83 +267,87 @@ class GDK_Points_Admin
|
|||
// 增加金币
|
||||
if (isset($_POST['user_mail'])) { //如果输入邮箱的话
|
||||
$usermail = $data['user_mail'];
|
||||
$user = get_user_by('email', $usermail);
|
||||
$userid = $user->ID;
|
||||
$user = get_user_by('email', $usermail);
|
||||
$userid = $user->ID;
|
||||
$username = $user->display_name;
|
||||
}
|
||||
if (isset($_POST['user_id'])) {
|
||||
//如果输入用户ID的话
|
||||
$user = get_user_by('id', $data['user_id']);
|
||||
$user = get_user_by('id', $data['user_id']);
|
||||
$usermail = $user->user_email;
|
||||
$userid = $data['user_id'];
|
||||
$userid = $data['user_id'];
|
||||
$username = $user->display_name;
|
||||
}
|
||||
GDK_Points::set_points($_POST['points'], $userid, $data);
|
||||
$mail_title = $username . '您好,金币增加通知';
|
||||
$mail_title = $username.'您好,金币增加通知';
|
||||
$mail_cotent = '<p>您的金币金额被管理员调整,请查收!</p>
|
||||
<ul>
|
||||
<li>用户名:' . $username . '</li>
|
||||
<li>增加金币:' . $_POST['points'] . '</li>
|
||||
<li>金币总额:' . GDK_Points::get_user_total_points($userid, 'accepted') . '</li>
|
||||
<li>用户名:'.$username.'</li>
|
||||
<li>增加金币:'.$_POST['points'].'</li>
|
||||
<li>金币总额:'.GDK_Points::get_user_total_points($userid, 'accepted').'</li>
|
||||
</ul>
|
||||
<p>如果您的金币金额有异常,请您在第一时间和我们取得联系哦,联系邮箱:' . get_bloginfo('admin_email') . '</p>';
|
||||
$message = mail_temp($mail_title, $mail_cotent, home_url(), get_bloginfo('name'));
|
||||
<p>如果您的金币金额有异常,请您在第一时间和我们取得联系哦,联系邮箱:'.get_bloginfo('admin_email').'</p>';
|
||||
$message = gdk_mail_temp($mail_title, $mail_cotent, home_url(), get_bloginfo('name'));
|
||||
$headers = "Content-Type:text/html;charset=UTF-8\n";
|
||||
wp_mail($usermail, 'Hi,' . $username . ',金币账户金额变动通知!', $message, $headers);
|
||||
wp_mail($usermail, 'Hi,'.$username.',金币账户金额变动通知!', $message, $headers);
|
||||
}
|
||||
}
|
||||
$alert = "金币已更新";
|
||||
$alert = '金币已更新';
|
||||
}
|
||||
if (isset($_GET["action"])) {
|
||||
$action = $_GET["action"];
|
||||
if ($action !== null) {
|
||||
if (isset($_GET['action'])) {
|
||||
$action = $_GET['action'];
|
||||
if (null !== $action) {
|
||||
switch ($action) {
|
||||
case 'edit':
|
||||
if (isset($_GET['point_id']) && ($_GET['point_id'] !== null)) {
|
||||
if (isset($_GET['point_id']) && (null !== $_GET['point_id'])) {
|
||||
return self::points_admin_points_edit(intval($_GET['point_id']));
|
||||
} else {
|
||||
return self::points_admin_points_edit();
|
||||
}
|
||||
|
||||
return self::points_admin_points_edit();
|
||||
|
||||
break;
|
||||
|
||||
case 'delete':
|
||||
if ($_GET['point_id'] !== null) {
|
||||
if (null !== $_GET['point_id']) {
|
||||
if (current_user_can('administrator')) {
|
||||
GDK_Points::remove_points($_GET['point_id']);
|
||||
global $wpdb;
|
||||
$wcu_sql = "DELETE FROM " . GDK_Points_Database::points_get_table("users") . " WHERE status = 'removed'";
|
||||
$wcu_sql = 'DELETE FROM '.GDK_Points_Database::points_get_table('users')." WHERE status = 'removed'";
|
||||
$wpdb->query($wcu_sql);
|
||||
$alert = "金币已删除";
|
||||
$alert = '金币已删除';
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($alert != "") {
|
||||
echo '<div style="background-color: #ffffe0;border: 1px solid #993;padding: 1em;margin-right: 1em;">' . $alert . '</div>';
|
||||
if ('' != $alert) {
|
||||
echo '<div style="background-color: #ffffe0;border: 1px solid #993;padding: 1em;margin-right: 1em;">'.$alert.'</div>';
|
||||
}
|
||||
|
||||
$current_url = (is_ssl() ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
|
||||
$cancel_url = remove_query_arg('point_id', remove_query_arg('action', $current_url));
|
||||
$current_url = remove_query_arg('point_id', $current_url);
|
||||
$current_url = remove_query_arg('action', $current_url);
|
||||
$current_url = (is_ssl() ? 'https://' : 'http://').$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
|
||||
$cancel_url = remove_query_arg('point_id', remove_query_arg('action', $current_url));
|
||||
$current_url = remove_query_arg('point_id', $current_url);
|
||||
$current_url = remove_query_arg('action', $current_url);
|
||||
$exampleListTable = new GDK_Points_List_Table();
|
||||
$exampleListTable->prepare_items();
|
||||
?>
|
||||
<div class="wrap">
|
||||
<h2>金币管理</h2>
|
||||
<span class="manage add">
|
||||
<a class="add button" href="<?php echo esc_url(add_query_arg('action', 'edit', $current_url)); ?>" title="点击手动添加金币">添加金币</a>
|
||||
</span>
|
||||
<form method="POST" style="float:right;">
|
||||
<input size="40" placeholder="搜索用户ID/用户邮箱/订单号/D文章ID" type="search" name="psearch" value="" />
|
||||
</form>
|
||||
<?php echo '<style type="text/css">tbody#the-list tr:hover{background:rgba(132,219,162,.61)}</style>';
|
||||
$exampleListTable->prepare_items(); ?>
|
||||
<div class="wrap">
|
||||
<h2>金币管理</h2>
|
||||
<span class="manage add">
|
||||
<a class="add button"
|
||||
href="<?php echo esc_url(add_query_arg('action', 'edit', $current_url)); ?>"
|
||||
title="点击手动添加金币">添加金币</a>
|
||||
</span>
|
||||
<form method="POST" style="float:right;">
|
||||
<input size="40" placeholder="搜索用户ID/用户邮箱/订单号/D文章ID" type="search" name="psearch" value="" />
|
||||
</form>
|
||||
<?php echo '<style type="text/css">tbody#the-list tr:hover{background:rgba(132,219,162,.61)}</style>';
|
||||
$exampleListTable->display(); ?>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
public static function points_admin_points_edit($point_id = null)
|
||||
{
|
||||
|
@ -352,29 +358,29 @@ class GDK_Points_Admin
|
|||
wp_die('Access denied.');
|
||||
}
|
||||
|
||||
$current_url = (is_ssl() ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
|
||||
$cancel_url = remove_query_arg('point_id', remove_query_arg('action', $current_url));
|
||||
$current_url = (is_ssl() ? 'https://' : 'http://').$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
|
||||
$cancel_url = remove_query_arg('point_id', remove_query_arg('action', $current_url));
|
||||
$current_url = remove_query_arg('point_id', $current_url);
|
||||
$current_url = remove_query_arg('action', $current_url);
|
||||
|
||||
$saved = false; // temporal
|
||||
|
||||
if ($point_id !== null) {
|
||||
if (null !== $point_id) {
|
||||
$points = GDK_Points::get_point($point_id);
|
||||
|
||||
if ($points !== null) {
|
||||
$user_id = $points->user_id;
|
||||
$num_points = $points->points;
|
||||
if (null !== $points) {
|
||||
$user_id = $points->user_id;
|
||||
$num_points = $points->points;
|
||||
$description = $points->description;
|
||||
$datetime = $points->datetime;
|
||||
$status = $points->status;
|
||||
$datetime = $points->datetime;
|
||||
$status = $points->status;
|
||||
}
|
||||
} else {
|
||||
$user_id = "";
|
||||
$num_points = 0;
|
||||
$description = "ADD";
|
||||
$datetime = "";
|
||||
$status = 'accepted';
|
||||
$user_id = '';
|
||||
$num_points = 0;
|
||||
$description = 'ADD';
|
||||
$datetime = '';
|
||||
$status = 'accepted';
|
||||
}
|
||||
|
||||
if (empty($point_id)) {
|
||||
|
@ -382,7 +388,7 @@ class GDK_Points_Admin
|
|||
} else {
|
||||
$pointsclass = 'editpoint';
|
||||
}
|
||||
$output .= '<div class="points ' . $pointsclass . '">';
|
||||
$output .= '<div class="points '.$pointsclass.'">';
|
||||
$output .= '<h2>';
|
||||
if (empty($point_id)) {
|
||||
$output .= '新金币';
|
||||
|
@ -390,7 +396,7 @@ class GDK_Points_Admin
|
|||
$output .= '编辑金币';
|
||||
}
|
||||
$output .= '</h2>';
|
||||
$output .= '<form id="points" action="' . $current_url . '" method="post">';
|
||||
$output .= '<form id="points" action="'.$current_url.'" method="post">';
|
||||
$output .= '<div>';
|
||||
|
||||
if ($point_id) {
|
||||
|
@ -441,11 +447,11 @@ class GDK_Points_Admin
|
|||
$output .= sprintf('<input type="text" name="points" value="%s" />', esc_attr($num_points));
|
||||
$output .= '</label>';
|
||||
$output .= '</p>';
|
||||
$status_descriptions = array(
|
||||
$status_descriptions = [
|
||||
'accepted' => '正常',
|
||||
'pending' => '待审',
|
||||
'pending' => '待审',
|
||||
'rejected' => '驳回',
|
||||
);
|
||||
];
|
||||
$output .= '<p>';
|
||||
$output .= '<label>';
|
||||
$output .= '<span class="title">状态</span>';
|
||||
|
@ -453,7 +459,7 @@ class GDK_Points_Admin
|
|||
$output .= '<select name="status">';
|
||||
foreach ($status_descriptions as $key => $label) {
|
||||
$selected = $key == $status ? ' selected="selected" ' : '';
|
||||
$output .= '<option ' . $selected . ' value="' . esc_attr($key) . '">' . $label . '</option>';
|
||||
$output .= '<option '.$selected.' value="'.esc_attr($key).'">'.$label.'</option>';
|
||||
}
|
||||
$output .= '</select>';
|
||||
$output .= '</label>';
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* class-points-shortcodes.php
|
||||
* class-points-shortcodes.php.
|
||||
*/
|
||||
class GDK_Points_Shortcodes
|
||||
{
|
||||
|
@ -13,20 +13,20 @@ class GDK_Points_Shortcodes
|
|||
add_shortcode('points_user_points', [__CLASS__, 'points_user_points']);
|
||||
add_shortcode('pay', [__CLASS__, 'pay']);
|
||||
add_shortcode('points_user_points_details', [__CLASS__, 'points_user_points_details']);
|
||||
|
||||
}
|
||||
|
||||
public static function points_users_list($atts, $content = null)
|
||||
{
|
||||
$options = shortcode_atts(
|
||||
[
|
||||
'limit' => 10,
|
||||
'limit' => 10,
|
||||
'order_by' => 'points',
|
||||
'order' => 'DESC',
|
||||
'order' => 'DESC',
|
||||
],
|
||||
$atts
|
||||
);
|
||||
extract($options);
|
||||
$output = "";
|
||||
$output = '';
|
||||
$pointsusers = GDK_Points::get_users();
|
||||
if (sizeof($pointsusers) > 0) {
|
||||
foreach ($pointsusers as $pointsuser) {
|
||||
|
@ -36,42 +36,46 @@ class GDK_Points_Shortcodes
|
|||
$output .= get_user_meta($pointsuser, 'nickname', true);
|
||||
$output .= ':</span>';
|
||||
$output .= '<span class="points-user-points">';
|
||||
$output .= " " . $total . " 金币";
|
||||
$output .= ' '.$total.' 金币';
|
||||
$output .= '</span>';
|
||||
$output .= '</div>';
|
||||
}
|
||||
} else {
|
||||
$output .= '<p>No users</p>';
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
public static function points_user_points($atts, $content = null)
|
||||
{
|
||||
$output = "";
|
||||
$options = shortcode_atts(['id' => ""],
|
||||
$output = '';
|
||||
$options = shortcode_atts(
|
||||
['id' => ''],
|
||||
$atts
|
||||
);
|
||||
extract($options);
|
||||
if ($id == "") {
|
||||
if ('' == $id) {
|
||||
$id = get_current_user_id();
|
||||
}
|
||||
if ($id !== 0) {
|
||||
if (0 !== $id) {
|
||||
$points = GDK_Points::get_user_total_points($id, 'accepted');
|
||||
$output .= $points;
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/*付费可见短代码开始*/
|
||||
// 付费可见短代码开始
|
||||
|
||||
public static function pay($atts, $content = null)
|
||||
{
|
||||
$content = do_shortcode($content);
|
||||
$content = do_shortcode($content);
|
||||
global $wpdb;
|
||||
$user_id = get_current_user_id();
|
||||
$pid = get_the_ID();
|
||||
$result = $wpdb->get_row("SELECT description FROM " . GDK_Points_Database::points_get_table("users") . " WHERE user_id=" . $user_id . " AND description=" . $pid . " AND status='accepted' LIMIT 0, 3;", ARRAY_A)['description']; //验证是否支付
|
||||
extract(shortcode_atts(['point' => "10"], $atts));
|
||||
$pid = get_the_ID();
|
||||
$result = $wpdb->get_row('SELECT description FROM '.GDK_Points_Database::points_get_table('users').' WHERE user_id='.$user_id.' AND description='.$pid." AND status='accepted' LIMIT 0, 3;", ARRAY_A)['description']; //验证是否支付
|
||||
extract(shortcode_atts(['point' => '10'], $atts));
|
||||
$notice = '';
|
||||
add_post_meta($pid, '_point_content', $content, true) or update_post_meta($pid, '_point_content', $content); //没有新建,有就更新
|
||||
if (is_user_logged_in()) {
|
||||
|
@ -82,45 +86,50 @@ class GDK_Points_Shortcodes
|
|||
} else {
|
||||
if (GDK_Points::get_user_total_points($user_id, 'accepted') < $point) {
|
||||
$notice .= '<fieldset id="hide_notice" class="fieldset ta-center"><legend class="legend ta-left">付费内容</legend>';
|
||||
$notice .= '<p>当前隐藏内容需要支付</p><span class="cm-coin">' . $point . '金币</span>';
|
||||
$notice .= '<p>您当前拥有<span class="red">' . GDK_Points::get_user_total_points($user_id, 'accepted') . '</span>金币,金币不足,请充值</p>';
|
||||
$notice .= '<p>当前隐藏内容需要支付</p><span class="cm-coin">'.$point.'金币</span>';
|
||||
$notice .= '<p>您当前拥有<span class="red">'.GDK_Points::get_user_total_points($user_id, 'accepted').'</span>金币,金币不足,请充值</p>';
|
||||
$notice .= buy_points();
|
||||
$notice .= '</fieldset>';
|
||||
} else {
|
||||
$notice .= '<fieldset id="hide_notice" class="fieldset ta-center"><legend class="legend ta-left">付费内容</legend>';
|
||||
$notice .= '<p>当前隐藏内容需要支付</p><span class="cm-coin">' . $point . '金币</span>';
|
||||
$notice .= '<p>您当前拥有<span class="red">' . GDK_Points::get_user_total_points($user_id, 'accepted') . '</span>金币</p>';
|
||||
$notice .= '<p><button class="cm-btn primary" id="pay_points" data-point="' . $point . '" data-userid="' . $user_id . '" data-action="gdk_pay_buy" data-id="' . $pid . '">点击购买</button></p>';
|
||||
$notice .= '<p>当前隐藏内容需要支付</p><span class="cm-coin">'.$point.'金币</span>';
|
||||
$notice .= '<p>您当前拥有<span class="red">'.GDK_Points::get_user_total_points($user_id, 'accepted').'</span>金币</p>';
|
||||
$notice .= '<p><button class="cm-btn primary" id="pay_points" data-point="'.$point.'" data-userid="'.$user_id.'" data-action="gdk_pay_buy" data-id="'.$pid.'">点击购买</button></p>';
|
||||
$notice .= '</fieldset>';
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$notice .= '<fieldset id="hide_notice" class="fieldset ta-center"><legend class="legend ta-left">付费内容</legend>';
|
||||
$notice .= '<p>当前隐藏内容需要支付</p><span class="cm-coin">' . $point . '金币</span>';
|
||||
$notice .= '<p>当前隐藏内容需要支付</p><span class="cm-coin">'.$point.'金币</span>';
|
||||
$notice .= '<p>您当前尚未登陆,请登陆后查看</p>';
|
||||
$notice .= weixin_login_btn();
|
||||
$notice .= '</fieldset>';
|
||||
}
|
||||
|
||||
return $notice;
|
||||
}
|
||||
/*付费可见短代码结束*/
|
||||
|
||||
// 付费可见短代码结束
|
||||
/**
|
||||
* Shortcode. 显示用户的金币细节
|
||||
*
|
||||
* @param mixed $atts
|
||||
* @param null|mixed $content
|
||||
*/
|
||||
public static function points_user_points_details($atts, $content = null)
|
||||
{
|
||||
$options = shortcode_atts(
|
||||
[
|
||||
'user_id' => '',
|
||||
'order_by' => 'point_id',
|
||||
'order' => 'DESC',
|
||||
'user_id' => '',
|
||||
'order_by' => 'point_id',
|
||||
'order' => 'DESC',
|
||||
'description' => true,
|
||||
],
|
||||
$atts
|
||||
);
|
||||
extract($options);
|
||||
date_default_timezone_set('Asia/Shanghai');
|
||||
if (is_string($description) && (($description == '0') || (strtolower($description) == 'false'))) {
|
||||
if (is_string($description) && (('0' == $description) || ('false' == strtolower($description)))) {
|
||||
$description = false;
|
||||
}
|
||||
|
||||
|
@ -131,29 +140,33 @@ class GDK_Points_Shortcodes
|
|||
global $wp_query;
|
||||
$curauth = $wp_query->get_queried_object();
|
||||
$user_id = $curauth->ID;
|
||||
$points = GDK_Points::get_points_by_user($user_id);
|
||||
$output = '<table class="points_user_points_table">' .
|
||||
'<tr>' .
|
||||
'<th>日期时间' .
|
||||
'<th>金币</th>' .
|
||||
'<th>类别</th>' .
|
||||
'<th>状态</th>' .
|
||||
$desc_th .
|
||||
$points = GDK_Points::get_points_by_user($user_id);
|
||||
$output = '<table class="points_user_points_table">'.
|
||||
'<tr>'.
|
||||
'<th>日期时间'.
|
||||
'<th>金币</th>'.
|
||||
'<th>类别</th>'.
|
||||
'<th>状态</th>'.
|
||||
$desc_th.
|
||||
'</tr>';
|
||||
if ($user_id !== 0) {
|
||||
if (0 !== $user_id) {
|
||||
if (sizeof($points) > 0) {
|
||||
foreach ($points as $point) {
|
||||
$desc_td = '';
|
||||
if ($description) {
|
||||
$desc_td = '<td>' . $point->description . '</td>';
|
||||
$desc_td = '<td>'.$point->description.'</td>';
|
||||
}
|
||||
if ($point->points > 0) {$leibie = '充值';} elseif ($point->points < 0) {$leibie = '消费';}
|
||||
$output .= '<tr>' .
|
||||
'<td>' . $point->datetime . '</td>' .
|
||||
'<td>' . $point->points . '</td>' .
|
||||
'<td>' . $leibie . '</td>' .
|
||||
'<td>' . $point->status . '</td>' .
|
||||
$desc_td .
|
||||
if ($point->points > 0) {
|
||||
$leibie = '充值';
|
||||
} elseif ($point->points < 0) {
|
||||
$leibie = '消费';
|
||||
}
|
||||
$output .= '<tr>'.
|
||||
'<td>'.$point->datetime.'</td>'.
|
||||
'<td>'.$point->points.'</td>'.
|
||||
'<td>'.$leibie.'</td>'.
|
||||
'<td>'.$point->status.'</td>'.
|
||||
$desc_td.
|
||||
'</tr>';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,48 +1,51 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* GDK_Points_Database class
|
||||
* GDK_Points_Database class.
|
||||
*/
|
||||
class GDK_Points_Database
|
||||
{
|
||||
public static $prefix = "points_";
|
||||
public static $prefix = 'points_';
|
||||
|
||||
public static function points_get_table($table)
|
||||
{
|
||||
global $wpdb;
|
||||
$result = "";
|
||||
$result = '';
|
||||
|
||||
switch ($table) {
|
||||
case "users":
|
||||
$result = $wpdb->prefix . self::$prefix . "users";
|
||||
case 'users':
|
||||
$result = $wpdb->prefix.self::$prefix.'users';
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* GDK_Points class
|
||||
* GDK_Points class.
|
||||
*/
|
||||
class GDK_Points
|
||||
{
|
||||
|
||||
public static function get_points_by_user($user_id, $limit = null, $order_by = null, $order = null, $output = OBJECT, $offset = 0)
|
||||
{
|
||||
global $wpdb;
|
||||
|
||||
$limit_str = '';
|
||||
if (isset($limit) && ($limit !== null)) {
|
||||
$limit_str = ' LIMIT ' . $offset . ' ,' . $limit;
|
||||
if (isset($limit) && (null !== $limit)) {
|
||||
$limit_str = ' LIMIT '.$offset.' ,'.$limit;
|
||||
}
|
||||
$order_by_str = "";
|
||||
if (isset($order_by) && ($order_by !== null)) {
|
||||
$order_by_str = " ORDER BY " . $order_by;
|
||||
$order_by_str = '';
|
||||
if (isset($order_by) && (null !== $order_by)) {
|
||||
$order_by_str = ' ORDER BY '.$order_by;
|
||||
}
|
||||
$order_str = "";
|
||||
if (isset($order) && ($order !== null)) {
|
||||
$order_str = " " . $order;
|
||||
$order_str = '';
|
||||
if (isset($order) && (null !== $order)) {
|
||||
$order_str = ' '.$order;
|
||||
}
|
||||
|
||||
$result = $wpdb->get_results('SELECT * FROM ' . GDK_Points_Database::points_get_table('users') . " WHERE user_id = '$user_id'" . $order_by_str . $order_str . $limit_str, $output);
|
||||
$result = $wpdb->get_results('SELECT * FROM '.GDK_Points_Database::points_get_table('users')." WHERE user_id = '{$user_id}'".$order_by_str.$order_str.$limit_str, $output);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
@ -54,14 +57,15 @@ class GDK_Points
|
|||
$result = 0;
|
||||
|
||||
$where_status = '';
|
||||
if ($status !== null) {
|
||||
$where_status = " AND status = '" . $status . "'";
|
||||
if (null !== $status) {
|
||||
$where_status = " AND status = '".$status."'";
|
||||
}
|
||||
$points = $wpdb->get_row("SELECT SUM(points) as total FROM " . GDK_Points_Database::points_get_table("users") . " WHERE user_id = '$user_id' " . $where_status);
|
||||
$points = $wpdb->get_row('SELECT SUM(points) as total FROM '.GDK_Points_Database::points_get_table('users')." WHERE user_id = '{$user_id}' ".$where_status);
|
||||
|
||||
if ($points && ($points->total !== null)) {
|
||||
if ($points && (null !== $points->total)) {
|
||||
$result = $points->total;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
@ -70,41 +74,44 @@ class GDK_Points
|
|||
global $wpdb;
|
||||
|
||||
$where_status = '';
|
||||
if ($status !== null) {
|
||||
$where_status = " WHERE status = '" . $status . "'";
|
||||
if (null !== $status) {
|
||||
$where_status = " WHERE status = '".$status."'";
|
||||
}
|
||||
$points = $wpdb->get_results("SELECT SUM(points) as total, user_id FROM " . GDK_Points_Database::points_get_table("users") . $where_status . " GROUP BY user_id");
|
||||
$points = $wpdb->get_results('SELECT SUM(points) as total, user_id FROM '.GDK_Points_Database::points_get_table('users').$where_status.' GROUP BY user_id');
|
||||
|
||||
return $points;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get users id who have some points
|
||||
* @param $user_id
|
||||
* Get users id who have some points.
|
||||
*
|
||||
* @param $user_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function get_users()
|
||||
{
|
||||
global $wpdb;
|
||||
|
||||
$users_id = $wpdb->get_results("SELECT user_id FROM " . GDK_Points_Database::points_get_table("users") . " GROUP BY user_id");
|
||||
$users_id = $wpdb->get_results('SELECT user_id FROM '.GDK_Points_Database::points_get_table('users').' GROUP BY user_id');
|
||||
|
||||
$result = array();
|
||||
$result = [];
|
||||
if (sizeof($users_id) > 0) {
|
||||
foreach ($users_id as $user_id) {
|
||||
$result[] = $user_id->user_id;
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function set_points($points, $user_id, $info = array())
|
||||
public static function set_points($points, $user_id, $info = [])
|
||||
{
|
||||
global $wpdb;
|
||||
|
||||
$values = array('points' => $points);
|
||||
$values = ['points' => $points];
|
||||
|
||||
if (isset($info['datetime']) && ($info['datetime'] !== "")) {
|
||||
if (isset($info['datetime']) && ('' !== $info['datetime'])) {
|
||||
$values['datetime'] = $info['datetime'];
|
||||
} else {
|
||||
$values['datetime'] = date('Y-m-d H:i:s', time());
|
||||
|
@ -129,16 +136,19 @@ class GDK_Points
|
|||
}
|
||||
$values['user_id'] = $user_id;
|
||||
|
||||
$rows_affected = $wpdb->insert(GDK_Points_Database::points_get_table("users"), $values);
|
||||
$rows_affected = $wpdb->insert(GDK_Points_Database::points_get_table('users'), $values);
|
||||
|
||||
return $rows_affected;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a points list.
|
||||
* @param int $limit
|
||||
*
|
||||
* @param int $limit
|
||||
* @param string $order_by
|
||||
* @param string $order
|
||||
* @param mixed $output
|
||||
*
|
||||
* @return Ambigous <mixed, NULL, multitype:, multitype:multitype: , multitype:Ambigous <multitype:, NULL> >
|
||||
*/
|
||||
public static function get_points($limit = null, $order_by = null, $order = null, $output = OBJECT)
|
||||
|
@ -147,20 +157,20 @@ class GDK_Points
|
|||
|
||||
$where_str = " WHERE status != 'removed'";
|
||||
|
||||
$limit_str = "";
|
||||
if (isset($limit) && ($limit !== null)) {
|
||||
$limit_str = " LIMIT 0 ," . $limit;
|
||||
$limit_str = '';
|
||||
if (isset($limit) && (null !== $limit)) {
|
||||
$limit_str = ' LIMIT 0 ,'.$limit;
|
||||
}
|
||||
$order_by_str = "";
|
||||
if (isset($order_by) && ($order_by !== null)) {
|
||||
$order_by_str = " ORDER BY " . $order_by;
|
||||
$order_by_str = '';
|
||||
if (isset($order_by) && (null !== $order_by)) {
|
||||
$order_by_str = ' ORDER BY '.$order_by;
|
||||
}
|
||||
$order_str = "";
|
||||
if (isset($order) && ($order !== null)) {
|
||||
$order_str = " " . $order;
|
||||
$order_str = '';
|
||||
if (isset($order) && (null !== $order)) {
|
||||
$order_str = ' '.$order;
|
||||
}
|
||||
|
||||
$result = $wpdb->get_results("SELECT * FROM " . GDK_Points_Database::points_get_table("users") . $where_str . $order_by_str . $order_str . $limit_str, $output);
|
||||
$result = $wpdb->get_results('SELECT * FROM '.GDK_Points_Database::points_get_table('users').$where_str.$order_by_str.$order_str.$limit_str, $output);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
@ -171,10 +181,9 @@ class GDK_Points
|
|||
|
||||
$result = null;
|
||||
|
||||
if (isset($point_id) && ($point_id !== null)) {
|
||||
|
||||
$points_id_str = " WHERE point_id = " . (int)$point_id;
|
||||
$result = $wpdb->get_row("SELECT * FROM " . GDK_Points_Database::points_get_table("users") . $points_id_str);
|
||||
if (isset($point_id) && (null !== $point_id)) {
|
||||
$points_id_str = ' WHERE point_id = '.(int) $point_id;
|
||||
$result = $wpdb->get_row('SELECT * FROM '.GDK_Points_Database::points_get_table('users').$points_id_str);
|
||||
}
|
||||
|
||||
return $result;
|
||||
|
@ -184,22 +193,23 @@ class GDK_Points
|
|||
{
|
||||
global $wpdb;
|
||||
|
||||
$values = array();
|
||||
$values = [];
|
||||
$values['status'] = 'removed';
|
||||
|
||||
$rows_affected = $wpdb->update(GDK_Points_Database::points_get_table("users"), $values, array('point_id' => $point_id));
|
||||
$rows_affected = $wpdb->update(GDK_Points_Database::points_get_table('users'), $values, ['point_id' => $point_id]);
|
||||
|
||||
if (!$rows_affected) {
|
||||
$rows_affected = null;
|
||||
}
|
||||
|
||||
return $rows_affected;
|
||||
}
|
||||
|
||||
public static function update_points($point_id, $info = array())
|
||||
public static function update_points($point_id, $info = [])
|
||||
{
|
||||
global $wpdb;
|
||||
|
||||
$values = array();
|
||||
$values = [];
|
||||
|
||||
if (isset($info['user_id'])) {
|
||||
$values['user_id'] = $info['user_id'];
|
||||
|
@ -229,11 +239,12 @@ class GDK_Points
|
|||
$values['ipv6'] = $info['ipv6'];
|
||||
}
|
||||
|
||||
$rows_affected = $wpdb->update(GDK_Points_Database::points_get_table("users"), $values, array('point_id' => $point_id));
|
||||
$rows_affected = $wpdb->update(GDK_Points_Database::points_get_table('users'), $values, ['point_id' => $point_id]);
|
||||
|
||||
if (!$rows_affected) { // insert
|
||||
$rows_affected = null;
|
||||
}
|
||||
|
||||
return $rows_affected;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,12 +1,15 @@
|
|||
<?php
|
||||
|
||||
include 'class-points.php';
|
||||
|
||||
include 'class-points-admin.php';
|
||||
|
||||
include 'class-points-shortcodes.php';
|
||||
|
||||
class GDK_Points_Class
|
||||
{
|
||||
private static $__notices = [];
|
||||
|
||||
public static function init()
|
||||
{
|
||||
add_action('init', [__CLASS__, 'wp_init']);
|
||||
|
@ -20,7 +23,6 @@ class GDK_Points_Class
|
|||
|
||||
/**
|
||||
* activation work.
|
||||
*
|
||||
*/
|
||||
public static function activate()
|
||||
{
|
||||
|
@ -28,16 +30,16 @@ class GDK_Points_Class
|
|||
|
||||
$charset_collate = '';
|
||||
if (!empty($wpdb->charset)) {
|
||||
$charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
|
||||
$charset_collate = "DEFAULT CHARACTER SET {$wpdb->charset}";
|
||||
}
|
||||
if (!empty($wpdb->collate)) {
|
||||
$charset_collate .= " COLLATE $wpdb->collate";
|
||||
$charset_collate .= " COLLATE {$wpdb->collate}";
|
||||
}
|
||||
|
||||
// create tables
|
||||
$points_users_table = GDK_Points_Database::points_get_table("users");
|
||||
if ($wpdb->get_var("SHOW TABLES LIKE '$points_users_table'") != $points_users_table) {
|
||||
$queries[] = "CREATE TABLE $points_users_table (
|
||||
$points_users_table = GDK_Points_Database::points_get_table('users');
|
||||
if ($wpdb->get_var("SHOW TABLES LIKE '{$points_users_table}'") != $points_users_table) {
|
||||
$queries[] = "CREATE TABLE {$points_users_table} (
|
||||
point_id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
user_id BIGINT(20) UNSIGNED NOT NULL,
|
||||
points BIGINT(20) DEFAULT 0,
|
||||
|
@ -50,10 +52,10 @@ class GDK_Points_Class
|
|||
status varchar(10) NOT NULL DEFAULT 'accepted',
|
||||
type varchar(32) NULL,
|
||||
PRIMARY KEY (point_id)
|
||||
) $charset_collate;";
|
||||
) {$charset_collate};";
|
||||
}
|
||||
if (!empty($queries)) {
|
||||
require_once ABSPATH . 'wp-admin/includes/upgrade.php';
|
||||
require_once ABSPATH.'wp-admin/includes/upgrade.php';
|
||||
dbDelta($queries);
|
||||
}
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
/**
|
||||
* Theme Update Checker Library 1.2
|
||||
* http://w-shadow.com/
|
||||
* http://w-shadow.com/.
|
||||
*/
|
||||
/*
|
||||
json数据格式:
|
||||
|
@ -12,52 +12,50 @@ json数据格式:
|
|||
}
|
||||
*/
|
||||
|
||||
if (!class_exists('ThemeUpdateChecker')):
|
||||
|
||||
if (!class_exists('ThemeUpdateChecker')) {
|
||||
class ThemeUpdateChecker
|
||||
{
|
||||
public $theme = ''; //待检查更新的主题名
|
||||
public $metadataUrl = ''; //元数据文件的路径
|
||||
{
|
||||
public $theme = ''; //待检查更新的主题名
|
||||
public $metadataUrl = ''; //元数据文件的路径
|
||||
public $enableAutomaticChecking = true; //是否启用自动更新
|
||||
protected $_optionName = ''; //更新信息的参数信息
|
||||
protected $_automaticCheckDone = false;
|
||||
protected $_optionName = ''; //更新信息的参数信息
|
||||
protected $_automaticCheckDone = false;
|
||||
protected static $_filterPrefix = 'tuc_request_update_';
|
||||
|
||||
public function __construct($theme, $metadataUrl, $enableAutomaticChecking = true)
|
||||
{
|
||||
$this->metadataUrl = $metadataUrl;
|
||||
{
|
||||
$this->metadataUrl = $metadataUrl;
|
||||
$this->enableAutomaticChecking = $enableAutomaticChecking;
|
||||
$this->theme = $theme;
|
||||
$this->optionName = 'external_theme_updates-' . $this->theme;
|
||||
$this->theme = $theme;
|
||||
$this->optionName = 'external_theme_updates-'.$this->theme;
|
||||
$this->installHooks();
|
||||
}
|
||||
|
||||
public function installHooks()
|
||||
{
|
||||
|
||||
{
|
||||
if ($this->enableAutomaticChecking) {
|
||||
add_filter('pre_set_site_transient_update_themes', array($this, 'onTransientUpdate'));
|
||||
add_filter('pre_set_site_transient_update_themes', [$this, 'onTransientUpdate']);
|
||||
}
|
||||
|
||||
//Insert our update info into the update list maintained by WP.
|
||||
add_filter('site_transient_update_themes', array($this, 'injectUpdate'));
|
||||
add_filter('site_transient_update_themes', [$this, 'injectUpdate']);
|
||||
|
||||
//Delete our update info when WP deletes its own.
|
||||
//This usually happens when a theme is installed, removed or upgraded.
|
||||
add_action('delete_site_transient_update_themes', array($this, 'deleteStoredData'));
|
||||
add_action('delete_site_transient_update_themes', [$this, 'deleteStoredData']);
|
||||
}
|
||||
|
||||
public function requestUpdate($queryArgs = array())
|
||||
{
|
||||
public function requestUpdate($queryArgs = [])
|
||||
{
|
||||
//Query args to append to the URL. Themes can add their own by using a filter callback (see addQueryArgFilter()).
|
||||
$queryArgs['installed_version'] = $this->getInstalledVersion();
|
||||
$queryArgs = apply_filters(self::$filterPrefix . 'query_args-' . $this->theme, $queryArgs);
|
||||
$queryArgs = apply_filters(self::$filterPrefix.'query_args-'.$this->theme, $queryArgs);
|
||||
|
||||
//Various options for the wp_remote_get() call. Themes can filter these, too.
|
||||
$options = array(
|
||||
$options = [
|
||||
'timeout' => 20, //seconds
|
||||
);
|
||||
$options = apply_filters(self::$filterPrefix . 'options-' . $this->theme, $options);
|
||||
];
|
||||
$options = apply_filters(self::$filterPrefix.'options-'.$this->theme, $options);
|
||||
|
||||
$url = $this->metadataUrl;
|
||||
if (!empty($queryArgs)) {
|
||||
|
@ -69,24 +67,24 @@ if (!class_exists('ThemeUpdateChecker')):
|
|||
|
||||
//Try to parse the response
|
||||
$themeUpdate = null;
|
||||
$code = wp_remote_retrieve_response_code($result);
|
||||
$body = wp_remote_retrieve_body($result);
|
||||
if (($code == 200) && !empty($body)) {
|
||||
$code = wp_remote_retrieve_response_code($result);
|
||||
$body = wp_remote_retrieve_body($result);
|
||||
if ((200 == $code) && !empty($body)) {
|
||||
$themeUpdate = ThemeUpdate::fromJson($body);
|
||||
//The update should be newer than the currently installed version.
|
||||
if (($themeUpdate != null) && version_compare($themeUpdate->version, $this->getInstalledVersion(), '<=')) {
|
||||
if ((null != $themeUpdate) && version_compare($themeUpdate->version, $this->getInstalledVersion(), '<=')) {
|
||||
$themeUpdate = null;
|
||||
}
|
||||
}
|
||||
|
||||
$themeUpdate = apply_filters(self::$filterPrefix . 'result-' . $this->theme, $themeUpdate, $result);
|
||||
return $themeUpdate;
|
||||
return apply_filters(self::$filterPrefix.'result-'.$this->theme, $themeUpdate, $result);
|
||||
}
|
||||
|
||||
public function getInstalledVersion()
|
||||
{
|
||||
{
|
||||
if (function_exists('wp_get_theme')) {
|
||||
$theme = wp_get_theme($this->theme);
|
||||
|
||||
return $theme->get('Version');
|
||||
}
|
||||
|
||||
|
@ -95,20 +93,21 @@ if (!class_exists('ThemeUpdateChecker')):
|
|||
return $theme['Version'];
|
||||
}
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
public function checkForUpdates()
|
||||
{
|
||||
{
|
||||
$state = get_option($this->optionName);
|
||||
if (empty($state)) {
|
||||
$state = new StdClass;
|
||||
$state->lastCheck = 0;
|
||||
$state = new StdClass();
|
||||
$state->lastCheck = 0;
|
||||
$state->checkedVersion = '';
|
||||
$state->update = null;
|
||||
$state->update = null;
|
||||
}
|
||||
|
||||
$state->lastCheck = time();
|
||||
$state->lastCheck = time();
|
||||
$state->checkedVersion = $this->getInstalledVersion();
|
||||
update_option($this->optionName, $state); //Save before checking in case something goes wrong
|
||||
|
||||
|
@ -117,16 +116,17 @@ if (!class_exists('ThemeUpdateChecker')):
|
|||
}
|
||||
|
||||
public function onTransientUpdate($value)
|
||||
{
|
||||
{
|
||||
if (!$this->automaticCheckDone) {
|
||||
$this->checkForUpdates();
|
||||
$this->automaticCheckDone = true;
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
public function injectUpdate($updates)
|
||||
{
|
||||
{
|
||||
$state = get_option($this->optionName);
|
||||
|
||||
//Is there an update to insert?
|
||||
|
@ -138,38 +138,36 @@ if (!class_exists('ThemeUpdateChecker')):
|
|||
}
|
||||
|
||||
public function deleteStoredData()
|
||||
{
|
||||
{
|
||||
delete_option($this->optionName);
|
||||
}
|
||||
|
||||
public function addQueryArgFilter($callback)
|
||||
{
|
||||
add_filter(self::$filterPrefix . 'query_args-' . $this->theme, $callback);
|
||||
{
|
||||
add_filter(self::$filterPrefix.'query_args-'.$this->theme, $callback);
|
||||
}
|
||||
|
||||
public function addHttpRequestArgFilter($callback)
|
||||
{
|
||||
add_filter(self::$filterPrefix . 'options-' . $this->theme, $callback);
|
||||
{
|
||||
add_filter(self::$filterPrefix.'options-'.$this->theme, $callback);
|
||||
}
|
||||
|
||||
public function addResultFilter($callback)
|
||||
{
|
||||
add_filter(self::$filterPrefix . 'result-' . $this->theme, $callback, 10, 2);
|
||||
{
|
||||
add_filter(self::$filterPrefix.'result-'.$this->theme, $callback, 10, 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
endif;
|
||||
|
||||
if (!class_exists('ThemeUpdate')):
|
||||
|
||||
if (!class_exists('ThemeUpdate')) {
|
||||
class ThemeUpdate
|
||||
{
|
||||
{
|
||||
public $version; //Version number.
|
||||
public $details_url; //The URL where the user can learn more about this version.
|
||||
public $download_url; //The download URL for this version of the theme. Optional.
|
||||
|
||||
public static function fromJson($json)
|
||||
{
|
||||
{
|
||||
$apiResponse = json_decode($json);
|
||||
if (empty($apiResponse) || !is_object($apiResponse)) {
|
||||
return null;
|
||||
|
@ -183,18 +181,18 @@ if (!class_exists('ThemeUpdate')):
|
|||
|
||||
$update = new self();
|
||||
foreach (get_object_vars($apiResponse) as $key => $value) {
|
||||
$update->$key = $value;
|
||||
$update->{$key} = $value;
|
||||
}
|
||||
|
||||
return $update;
|
||||
}
|
||||
|
||||
public function toWpFormat()
|
||||
{
|
||||
$update = array(
|
||||
{
|
||||
$update = [
|
||||
'new_version' => $this->version,
|
||||
'url' => $this->details_url,
|
||||
);
|
||||
'url' => $this->details_url,
|
||||
];
|
||||
|
||||
if (!empty($this->download_url)) {
|
||||
$update['package'] = $this->download_url;
|
||||
|
@ -203,5 +201,4 @@ if (!class_exists('ThemeUpdate')):
|
|||
return $update;
|
||||
}
|
||||
}
|
||||
|
||||
endif;
|
||||
}
|
||||
|
|
|
@ -1,47 +1,41 @@
|
|||
<?php
|
||||
|
||||
//error_reporting(0);
|
||||
|
||||
class Wechat_Captcha
|
||||
{
|
||||
public function __construct($wx_token, $wx_captcha)
|
||||
{
|
||||
$this->token = $wx_token;
|
||||
$this->token = $wx_token;
|
||||
$this->captcha = $wx_captcha;
|
||||
}
|
||||
|
||||
private function __checkSignature()
|
||||
{
|
||||
$signature = $_GET["signature"];
|
||||
$timestamp = $_GET["timestamp"];
|
||||
$nonce = $_GET["nonce"];
|
||||
$token = $this->token;
|
||||
$tmpArr = array($token, $timestamp, $nonce);
|
||||
$signature = $_GET['signature'];
|
||||
$timestamp = $_GET['timestamp'];
|
||||
$nonce = $_GET['nonce'];
|
||||
$token = $this->token;
|
||||
$tmpArr = [$token, $timestamp, $nonce];
|
||||
sort($tmpArr, SORT_STRING);
|
||||
$tmpStr = implode($tmpArr);
|
||||
$tmpStr = sha1($tmpStr);
|
||||
|
||||
return $tmpStr == $signature ? true : false;
|
||||
}
|
||||
protected function _valid()
|
||||
{
|
||||
$echoStr = $_GET["echostr"];
|
||||
//valid signature , option
|
||||
if ($this->checkSignature()) {
|
||||
echo $echoStr;
|
||||
exit;
|
||||
} else {
|
||||
echo 'error signature';
|
||||
}
|
||||
}
|
||||
|
||||
public function responseMsg()
|
||||
{
|
||||
//如果是验证请求,则执行签名验证并退出
|
||||
if (!empty($_GET["echostr"])) {
|
||||
if (!empty($_GET['echostr'])) {
|
||||
$this->valid();
|
||||
//验证签名是否有效
|
||||
return;
|
||||
//返回退出
|
||||
}
|
||||
if ($_SERVER['REQUEST_METHOD'] != 'POST') {
|
||||
if ('POST' != $_SERVER['REQUEST_METHOD']) {
|
||||
echo '';
|
||||
|
||||
return;
|
||||
}
|
||||
//如果不是验证请求,则
|
||||
|
@ -50,45 +44,61 @@ class Wechat_Captcha
|
|||
$postData = file_get_contents('php://input');
|
||||
if (empty($postData)) {
|
||||
echo '';
|
||||
|
||||
return;
|
||||
}
|
||||
//如果没有POST数据,则退出
|
||||
if (!empty($postData)) {
|
||||
//解析POST数据(XML格式)
|
||||
$object = simplexml_load_string($postData, 'SimpleXMLElement', LIBXML_NOCDATA);
|
||||
$messgeType = trim($object->MsgType); //取得消息类型
|
||||
$object = simplexml_load_string($postData, 'SimpleXMLElement', LIBXML_NOCDATA);
|
||||
$messgeType = trim($object->MsgType); //取得消息类型
|
||||
$this->fromUser = $object->FromUserName;
|
||||
$this->toUser = $object->ToUserName;
|
||||
$keyword = trim($object->Content);
|
||||
if ($messgeType == 'text' && $keyword == '验证码') {
|
||||
$response_content = '您的验证码为:【' . $this->captcha . '】,验证码有效期为2分钟,请抓紧使用,过期需重新申请';
|
||||
$xmlTemplate = "<xml>
|
||||
$this->toUser = $object->ToUserName;
|
||||
$keyword = trim($object->Content);
|
||||
if ('text' == $messgeType && '验证码' == $keyword) {
|
||||
$response_content = '您的验证码为:【'.$this->captcha.'】,验证码有效期为2分钟,请抓紧使用,过期需重新申请';
|
||||
$xmlTemplate = '<xml>
|
||||
<ToUserName><![CDATA[%s]]></ToUserName>
|
||||
<FromUserName><![CDATA[%s]]></FromUserName>
|
||||
<CreateTime>%s</CreateTime>
|
||||
<MsgType><![CDATA[text]]></MsgType>
|
||||
<Content><![CDATA[%s]]></Content>
|
||||
<FuncFlag>%d</FuncFlag>
|
||||
</xml>";
|
||||
</xml>';
|
||||
$xmlText = sprintf($xmlTemplate, $this->fromUser, $this->toUser, time(), $response_content, 0);
|
||||
echo $xmlText;
|
||||
}
|
||||
} else {
|
||||
echo "";
|
||||
echo '';
|
||||
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
protected function _valid()
|
||||
{
|
||||
$echoStr = $_GET['echostr'];
|
||||
//valid signature , option
|
||||
if ($this->checkSignature()) {
|
||||
echo $echoStr;
|
||||
|
||||
exit;
|
||||
}
|
||||
echo 'error signature';
|
||||
}
|
||||
}
|
||||
|
||||
function wx_process()
|
||||
{
|
||||
if (isset($_GET['signature'])) {
|
||||
global $wx_captchas;
|
||||
if (!isset($wx_captchas)) {
|
||||
$wx_token = gdk_option('gdk_wxmp_token');
|
||||
$wx_captchas = new Wechat_Captcha($wx_token, wx_captcha());
|
||||
$wx_captchas->responseMsg();
|
||||
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function wx_process() {
|
||||
if(isset($_GET["signature"])) {
|
||||
global $wx_captchas;
|
||||
if(!isset($wx_captchas)) {
|
||||
$wx_token = trim(gdk_option('gdk_wxmp_token'));
|
||||
$wx_captchas = new Wechat_Captcha($wx_token, wx_captcha());
|
||||
$wx_captchas->responseMsg();
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
add_action('parse_request', 'wx_process', 4);
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
class Auto_Widget_cache
|
||||
{
|
||||
public $cache_time = 18000;
|
||||
|
||||
/*
|
||||
MINUTE_IN_SECONDS = 60 seconds
|
||||
HOUR_IN_SECONDS = 3600 seconds
|
||||
|
@ -12,25 +13,27 @@ class Auto_Widget_cache
|
|||
*/
|
||||
public function __construct()
|
||||
{
|
||||
add_filter('widget_display_callback', array($this, '_cache_widget_output'), 10, 3);
|
||||
add_action('in_widget_form', array($this, 'in_widget_form'), 5, 3);
|
||||
add_filter('widget_update_callback', array($this, 'widget_update_callback'), 5, 3);
|
||||
add_filter('widget_display_callback', [$this, '_cache_widget_output'], 10, 3);
|
||||
add_action('in_widget_form', [$this, 'in_widget_form'], 5, 3);
|
||||
add_filter('widget_update_callback', [$this, 'widget_update_callback'], 5, 3);
|
||||
}
|
||||
|
||||
public function get_widget_key($i, $a)
|
||||
{
|
||||
return 'WC-' . md5(serialize(array($i, $a)));
|
||||
return 'WC-'.md5(serialize([$i, $a]));
|
||||
}
|
||||
|
||||
public function cache_widget_output($instance, $widget, $args)
|
||||
{
|
||||
if (false === $instance) {
|
||||
return $instance;
|
||||
}
|
||||
|
||||
if (isset($instance['wc_cache']) && $instance['wc_cache'] == true) {
|
||||
if (isset($instance['wc_cache']) && true == $instance['wc_cache']) {
|
||||
return $instance;
|
||||
}
|
||||
|
||||
$timer_start = microtime(true);
|
||||
$timer_start = microtime(true);
|
||||
$transient_name = $this->get_widget_key($instance, $args);
|
||||
if (false === ($cached_widget = get_transient($transient_name))) {
|
||||
ob_start();
|
||||
|
@ -39,32 +42,34 @@ class Auto_Widget_cache
|
|||
set_transient($transient_name, $cached_widget, $this->cache_time);
|
||||
}
|
||||
echo $cached_widget;
|
||||
echo '<!-- From widget cache in ' . number_format(microtime(true) - $timer_start, 5) . ' seconds -->';
|
||||
echo '<!-- From widget cache in '.number_format(microtime(true) - $timer_start, 5).' seconds -->';
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function in_widget_form($t, $return, $instance)
|
||||
{
|
||||
$instance = wp_parse_args((array)$instance, array('title' => '', 'text' => '', 'wc_cache' => null));
|
||||
$instance = wp_parse_args((array) $instance, ['title' => '', 'text' => '', 'wc_cache' => null]);
|
||||
if (!isset($instance['wc_cache'])) {
|
||||
$instance['wc_cache'] = null;
|
||||
}
|
||||
|
||||
?>
|
||||
<p>
|
||||
<input id="<?php
|
||||
} ?>
|
||||
<p>
|
||||
<input id="<?php
|
||||
echo $t->get_field_id('wc_cache'); ?>" name="<?php
|
||||
echo $t->get_field_name('wc_cache'); ?>" type="checkbox" <?php checked($instance['wc_cache'] ?? 0); ?> />
|
||||
<label for="<?php
|
||||
<label for="<?php
|
||||
echo $t->get_field_id('wc_cache'); ?>">禁止缓存本工具?</label>
|
||||
</p>
|
||||
<?php
|
||||
}
|
||||
</p>
|
||||
<?php
|
||||
}
|
||||
|
||||
public function widget_update_callback($instance, $new_instance, $old_instance)
|
||||
{
|
||||
$instance['wc_cache'] = isset($new_instance['wc_cache']);
|
||||
|
||||
return $instance;
|
||||
}
|
||||
}
|
||||
if( gdk_option('gdk_sidebar_cache')){
|
||||
if (gdk_option('gdk_sidebar_cache')) {
|
||||
$GLOBALS['Auto_Widget_cache'] = new Auto_Widget_cache();
|
||||
}
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
<?php
|
||||
|
||||
include 'plugin-options.php'; //安全功能
|
||||
|
||||
include 'metabox.php';
|
|
@ -1,100 +1,99 @@
|
|||
<?php
|
||||
|
||||
if (!class_exists('myCustomFields')) {
|
||||
|
||||
class myCustomFields
|
||||
{
|
||||
/**
|
||||
* @var string $prefix 自定义栏目前缀,一个完整的自定义栏目是需要前缀+name的,比如我的前缀是git_,name下面有baidu_submit,那么完整的自定义栏目就是git_baidu_submit.
|
||||
* @var string 自定义栏目前缀,一个完整的自定义栏目是需要前缀+name的,比如我的前缀是git_,name下面有baidu_submit,那么完整的自定义栏目就是git_baidu_submit
|
||||
*/
|
||||
public $prefix = 'gdk_';
|
||||
/**
|
||||
* @var array $postTypes 这是自定义面板的使用范围,这里一般就是在文章以及页面
|
||||
* @var array 这是自定义面板的使用范围,这里一般就是在文章以及页面
|
||||
*/
|
||||
public $postTypes = array("post");
|
||||
public $postTypes = ['post'];
|
||||
/**
|
||||
* @var array $customFields 开始组件自定义面板数组
|
||||
* @var array 开始组件自定义面板数组
|
||||
*/
|
||||
public $customFields = array(
|
||||
array(
|
||||
"name" => "thumb",
|
||||
"title" => "自定义缩略图",
|
||||
"description" => "这里可以输入您的自定义缩略图链接",
|
||||
"type" => "text",
|
||||
"scope" => ['post'],
|
||||
"capability" => "edit_posts",
|
||||
),
|
||||
array(
|
||||
"name" => "download_name",
|
||||
"title" => "单页下载文件名字",
|
||||
"description" => "这里可以输入您的下载文件的名字",
|
||||
"type" => "text",
|
||||
"scope" => ['post'],
|
||||
"capability" => "edit_posts",
|
||||
),
|
||||
array(
|
||||
"name" => "download_size",
|
||||
"title" => "单页下载文件大小",
|
||||
"description" => "这里可以输入您的下载文件的大小,可以加上单位,比如:233KB或者233MB",
|
||||
"type" => "text",
|
||||
"scope" => ['post'],
|
||||
"capability" => "edit_posts",
|
||||
),
|
||||
array(
|
||||
"name" => "download_link",
|
||||
"title" => "单页下载下载链接",
|
||||
"description" => "按照链接,名字,备注的格式,注意中间是用英文逗号,换行可添加多个,举个栗子:<code>https://www.baidu.com,百度官网,中国最大的搜索引擎网站</code>",
|
||||
"type" => "textarea",
|
||||
"scope" => ['post'],
|
||||
"capability" => "edit_posts",
|
||||
),
|
||||
);
|
||||
public $customFields = [
|
||||
[
|
||||
'name' => 'thumb',
|
||||
'title' => '自定义缩略图',
|
||||
'description' => '这里可以输入您的自定义缩略图链接',
|
||||
'type' => 'text',
|
||||
'scope' => ['post'],
|
||||
'capability' => 'edit_posts',
|
||||
],
|
||||
[
|
||||
'name' => 'download_name',
|
||||
'title' => '单页下载文件名字',
|
||||
'description' => '这里可以输入您的下载文件的名字',
|
||||
'type' => 'text',
|
||||
'scope' => ['post'],
|
||||
'capability' => 'edit_posts',
|
||||
],
|
||||
[
|
||||
'name' => 'download_size',
|
||||
'title' => '单页下载文件大小',
|
||||
'description' => '这里可以输入您的下载文件的大小,可以加上单位,比如:233KB或者233MB',
|
||||
'type' => 'text',
|
||||
'scope' => ['post'],
|
||||
'capability' => 'edit_posts',
|
||||
],
|
||||
[
|
||||
'name' => 'download_link',
|
||||
'title' => '单页下载下载链接',
|
||||
'description' => '按照链接,名字,备注的格式,注意中间是用英文逗号,换行可添加多个,举个栗子:<code>https://www.baidu.com,百度官网,中国最大的搜索引擎网站</code>',
|
||||
'type' => 'textarea',
|
||||
'scope' => ['post'],
|
||||
'capability' => 'edit_posts',
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
* PHP 5 Constructor
|
||||
* PHP 5 Constructor.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
add_action('admin_menu', array($this, 'createCustomFields'));
|
||||
add_action('save_post', array($this, 'saveCustomFields'), 1, 2);
|
||||
add_action('admin_menu', [$this, 'createCustomFields']);
|
||||
add_action('save_post', [$this, 'saveCustomFields'], 1, 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建一组你自己的自定义栏目
|
||||
* 创建一组你自己的自定义栏目.
|
||||
*/
|
||||
public function createCustomFields()
|
||||
{
|
||||
if (function_exists('add_meta_box')) {
|
||||
foreach ($this->postTypes as $postType) {
|
||||
add_meta_box('my-custom-fields', '文章选项', array($this, 'displayCustomFields'), $postType, 'normal', 'high');
|
||||
add_meta_box('my-custom-fields', '文章选项', [$this, 'displayCustomFields'], $postType, 'normal', 'high');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 在文章发布页显示出来面板
|
||||
*/
|
||||
public function displayCustomFields()
|
||||
{
|
||||
global $post;
|
||||
?>
|
||||
<div class="form-wrap">
|
||||
<?php wp_nonce_field('my-custom-fields', 'my-custom-fields_wpnonce', false, true);
|
||||
global $post; ?>
|
||||
<div class="form-wrap">
|
||||
<?php wp_nonce_field('my-custom-fields', 'my-custom-fields_wpnonce', false, true);
|
||||
foreach ($this->customFields as $customField) {
|
||||
// Check scope
|
||||
$scope = $customField['scope'];
|
||||
$scope = $customField['scope'];
|
||||
$output = false;
|
||||
foreach ($scope as $scopeItem) {
|
||||
switch ($scopeItem) {
|
||||
default:{
|
||||
default:
|
||||
if ($post->post_type == $scopeItem) {
|
||||
$output = true;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ($output) {
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
// 检查权限
|
||||
if (!current_user_can($customField['capability'], $post->ID)) {
|
||||
|
@ -104,57 +103,67 @@ if (!class_exists('myCustomFields')) {
|
|||
// 通过则输出
|
||||
if ($output) {
|
||||
?>
|
||||
<div class="form-field form-required form-field-<?php echo $customField['name'];?>">
|
||||
<?php switch ($customField['type']) {
|
||||
case "checkbox":{
|
||||
<div
|
||||
class="form-field form-required form-field-<?php echo $customField['name']; ?>">
|
||||
<?php switch ($customField['type']) {
|
||||
case 'checkbox':
|
||||
// Checkbox 组件
|
||||
echo '<label for="' . $this->prefix . $customField['name'] . '" style="display:inline;"><b>' . $customField['title'] . '</b></label> ';
|
||||
echo '<input type="checkbox" name="' . $this->prefix . $customField['name'] . '" id="' . $this->prefix . $customField['name'] . '" value="1"';
|
||||
if (get_post_meta($post->ID, $this->prefix . $customField['name'], true) == "1") {
|
||||
echo '<label for="'.$this->prefix.$customField['name'].'" style="display:inline;"><b>'.$customField['title'].'</b></label> ';
|
||||
echo '<input type="checkbox" name="'.$this->prefix.$customField['name'].'" id="'.$this->prefix.$customField['name'].'" value="1"';
|
||||
if ('1' == get_post_meta($post->ID, $this->prefix.$customField['name'], true)) {
|
||||
echo ' checked="checked"';
|
||||
}
|
||||
echo '" style="width: auto;" />';
|
||||
|
||||
break;
|
||||
}
|
||||
case "textarea":
|
||||
case "wysiwyg":{
|
||||
|
||||
case 'textarea':
|
||||
case 'wysiwyg':
|
||||
// Text area
|
||||
echo '<label for="' . $this->prefix . $customField['name'] . '"><b>' . $customField['title'] . '</b></label>';
|
||||
echo '<textarea name="' . $this->prefix . $customField['name'] . '" id="' . $this->prefix . $customField['name'] . '" columns="30" rows="5">' . htmlspecialchars(get_post_meta($post->ID, $this->prefix . $customField['name'], true)) . '</textarea>';
|
||||
echo '<label for="'.$this->prefix.$customField['name'].'"><b>'.$customField['title'].'</b></label>';
|
||||
echo '<textarea name="'.$this->prefix.$customField['name'].'" id="'.$this->prefix.$customField['name'].'" columns="30" rows="5">'.htmlspecialchars(get_post_meta($post->ID, $this->prefix.$customField['name'], true)).'</textarea>';
|
||||
// WYSIWYG
|
||||
if ($customField['type'] == "wysiwyg") { ?>
|
||||
<script type="text/javascript">
|
||||
jQuery( document ).ready( function() {
|
||||
jQuery( "<?php echo $this->prefix . $customField['name']; ?>" ).addClass( "mceEditor" );
|
||||
if ( typeof( tinyMCE ) == "object" && typeof( tinyMCE.execCommand ) == "function" ) {
|
||||
tinyMCE.execCommand( "mceAddControl", false, "<?php echo $this->prefix . $customField['name']; ?>" );
|
||||
}
|
||||
});
|
||||
</script>
|
||||
<?php }
|
||||
if ('wysiwyg' == $customField['type']) { ?>
|
||||
<script type="text/javascript">
|
||||
jQuery(document).ready(function() {
|
||||
jQuery(
|
||||
"<?php echo $this->prefix.$customField['name']; ?>"
|
||||
)
|
||||
.addClass("mceEditor");
|
||||
if (typeof(tinyMCE) == "object" && typeof(tinyMCE.execCommand) == "function") {
|
||||
tinyMCE.execCommand("mceAddControl", false,
|
||||
"<?php echo $this->prefix.$customField['name']; ?>"
|
||||
);
|
||||
}
|
||||
});
|
||||
</script>
|
||||
<?php }
|
||||
|
||||
break;
|
||||
}
|
||||
default:{
|
||||
|
||||
default:
|
||||
// Plain text field
|
||||
echo '<label for="' . $this->prefix . $customField['name'] . '"><b>' . $customField['title'] . '</b></label>';
|
||||
echo '<input type="text" name="' . $this->prefix . $customField['name'] . '" id="' . $this->prefix . $customField['name'] . '" value="' . htmlspecialchars(get_post_meta($post->ID, $this->prefix . $customField['name'], true)) . '" />';
|
||||
echo '<label for="'.$this->prefix.$customField['name'].'"><b>'.$customField['title'].'</b></label>';
|
||||
echo '<input type="text" name="'.$this->prefix.$customField['name'].'" id="'.$this->prefix.$customField['name'].'" value="'.htmlspecialchars(get_post_meta($post->ID, $this->prefix.$customField['name'], true)).'" />';
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
?>
|
||||
<?php if ($customField['description']) {
|
||||
echo '<p>' . $customField['description'] . '</p>';
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
} ?>
|
||||
<?php if ($customField['description']) {
|
||||
echo '<p>'.$customField['description'].'</p>';
|
||||
} ?>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
} ?>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存自定义栏目数据
|
||||
* 保存自定义栏目数据.
|
||||
*
|
||||
* @param mixed $post_id
|
||||
* @param mixed $post
|
||||
*/
|
||||
public function saveCustomFields($post_id, $post)
|
||||
{
|
||||
|
@ -172,27 +181,24 @@ if (!class_exists('myCustomFields')) {
|
|||
|
||||
foreach ($this->customFields as $customField) {
|
||||
if (current_user_can($customField['capability'], $post_id)) {
|
||||
if (isset($_POST[$this->prefix . $customField['name']]) && trim($_POST[$this->prefix . $customField['name']])) {
|
||||
$value = $_POST[$this->prefix . $customField['name']];
|
||||
if (isset($_POST[$this->prefix.$customField['name']]) && trim($_POST[$this->prefix.$customField['name']])) {
|
||||
$value = $_POST[$this->prefix.$customField['name']];
|
||||
// Auto-paragraphs for any WYSIWYG
|
||||
if ($customField['type'] == "wysiwyg") {
|
||||
if ('wysiwyg' == $customField['type']) {
|
||||
$value = wpautop($value);
|
||||
}
|
||||
|
||||
update_post_meta($post_id, $this->prefix . $customField['name'], $value);
|
||||
update_post_meta($post_id, $this->prefix.$customField['name'], $value);
|
||||
} else {
|
||||
delete_post_meta($post_id, $this->prefix . $customField['name']);
|
||||
delete_post_meta($post_id, $this->prefix.$customField['name']);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // End Class
|
||||
|
||||
} // End if class exists statement
|
||||
|
||||
// Instantiate the class
|
||||
if (class_exists('myCustomFields')) {
|
||||
$myCustomFields_var = new myCustomFields();
|
||||
}
|
||||
?>
|
|
@ -1,385 +1,384 @@
|
|||
<?php
|
||||
/**
|
||||
* 插件选项配置文件
|
||||
* 插件选项配置文件.
|
||||
*/
|
||||
|
||||
$gdk_options = [
|
||||
'优化' => [
|
||||
'优化' => [
|
||||
[
|
||||
'name' => '古腾堡编辑器',
|
||||
'desc' => '新版编辑器尚不成熟,很多主题不兼容,建议禁用',
|
||||
'id' => 'gdk_diasble_gutenberg',
|
||||
'type' => 'select',
|
||||
'name' => '古腾堡编辑器',
|
||||
'desc' => '新版编辑器尚不成熟,很多主题不兼容,建议禁用',
|
||||
'id' => 'gdk_diasble_gutenberg',
|
||||
'type' => 'select',
|
||||
'options' => [
|
||||
'0' => '启用',
|
||||
'1' => '禁用',
|
||||
],
|
||||
'std' => '1',
|
||||
'std' => '1',
|
||||
],
|
||||
[
|
||||
'name' => '新版小工具块编辑器',
|
||||
'desc' => '5.8版本小工具使用块编辑器,很多主题不兼容,建议禁用',
|
||||
'id' => 'gdk_diasble_widgets_block',
|
||||
'type' => 'select',
|
||||
'name' => '新版小工具块编辑器',
|
||||
'desc' => '5.8版本小工具使用块编辑器,很多主题不兼容,建议禁用',
|
||||
'id' => 'gdk_diasble_widgets_block',
|
||||
'type' => 'select',
|
||||
'options' => [
|
||||
'0' => '启用',
|
||||
'1' => '禁用',
|
||||
],
|
||||
'std' => '1',
|
||||
'std' => '1',
|
||||
],
|
||||
[
|
||||
'name' => '头部冗余代码',
|
||||
'desc' => '禁用<br>WordPress头部自带很多无用代码,不安全且浪费,建议禁用',
|
||||
'id' => 'gdk_diasble_head_useless',
|
||||
'type' => 'checkbox',
|
||||
'name' => '头部冗余代码',
|
||||
'desc' => '禁用<br>WordPress头部自带很多无用代码,不安全且浪费,建议禁用',
|
||||
'id' => 'gdk_diasble_head_useless',
|
||||
'type' => 'checkbox',
|
||||
],
|
||||
[
|
||||
'name' => 'Emojis表情功能',
|
||||
'desc' => '禁用<br>WordPress自带的Emojis功能会加载国外资源,那是网站速度,建议禁用',
|
||||
'id' => 'gdk_disable_emojis',
|
||||
'type' => 'checkbox',
|
||||
'name' => 'Emojis表情功能',
|
||||
'desc' => '禁用<br>WordPress自带的Emojis功能会加载国外资源,那是网站速度,建议禁用',
|
||||
'id' => 'gdk_disable_emojis',
|
||||
'type' => 'checkbox',
|
||||
],
|
||||
[
|
||||
'name' => '前台Dashicons字体资源',
|
||||
'desc' => '禁用<br>一般前台不需要加载dashicons字体,建议禁用',
|
||||
'id' => 'gdk_disable_dashicons',
|
||||
'type' => 'checkbox',
|
||||
'name' => '前台Dashicons字体资源',
|
||||
'desc' => '禁用<br>一般前台不需要加载dashicons字体,建议禁用',
|
||||
'id' => 'gdk_disable_dashicons',
|
||||
'type' => 'checkbox',
|
||||
],
|
||||
[
|
||||
'name' => '中英文自动空格',
|
||||
'desc' => '启用<br>【开启后,中文和英文之前将自动增加一个空格,比如:WordPress插件=>WordPress 插件】',
|
||||
'id' => 'gdk_auto_space',
|
||||
'id' => 'gdk_auto_space',
|
||||
'type' => 'checkbox',
|
||||
],
|
||||
[
|
||||
'name' => 'XML-RPC发布功能',
|
||||
'desc' => '禁用<br>该功能有安全风险,如果不使用WordPress的手机客户端或者第三方编辑器软件,那么建议禁用',
|
||||
'id' => 'gdk_disable_xmlrpc',
|
||||
'type' => 'checkbox',
|
||||
'name' => 'XML-RPC发布功能',
|
||||
'desc' => '禁用<br>该功能有安全风险,如果不使用WordPress的手机客户端或者第三方编辑器软件,那么建议禁用',
|
||||
'id' => 'gdk_disable_xmlrpc',
|
||||
'type' => 'checkbox',
|
||||
],
|
||||
[
|
||||
'name' => '文章版本功能',
|
||||
'desc' => '禁用<br>该功能有会造成数据库体量暴增为了你的数据库考虑,建议禁用',
|
||||
'id' => 'gdk_disable_revision',
|
||||
'type' => 'checkbox',
|
||||
'name' => '文章版本功能',
|
||||
'desc' => '禁用<br>该功能有会造成数据库体量暴增为了你的数据库考虑,建议禁用',
|
||||
'id' => 'gdk_disable_revision',
|
||||
'type' => 'checkbox',
|
||||
],
|
||||
[
|
||||
'name' => 'Pingback功能',
|
||||
'desc' => '禁用<br>该功能会增加垃圾评论的几率,建议禁用',
|
||||
'id' => 'gdk_disable_trackbacks',
|
||||
'type' => 'checkbox',
|
||||
'name' => 'Pingback功能',
|
||||
'desc' => '禁用<br>该功能会增加垃圾评论的几率,建议禁用',
|
||||
'id' => 'gdk_disable_trackbacks',
|
||||
'type' => 'checkbox',
|
||||
],
|
||||
[
|
||||
'name' => '文件上传重命名',
|
||||
'desc' => '该功能会将上传的文件图片等按照数字格式重命名,服务器文件不建议使用中文,默认开启',
|
||||
'id' => 'gdk_upload_rename',
|
||||
'type' => 'select',
|
||||
'name' => '文件上传重命名',
|
||||
'desc' => '该功能会将上传的文件图片等按照数字格式重命名,服务器文件不建议使用中文,默认开启',
|
||||
'id' => 'gdk_upload_rename',
|
||||
'type' => 'select',
|
||||
'options' => [
|
||||
'0' => '禁用',
|
||||
'1' => '开启',
|
||||
],
|
||||
'std' => '1',
|
||||
'std' => '1',
|
||||
],
|
||||
[
|
||||
'name' => 'WordPress更新',
|
||||
'desc' => '禁用<br>WordPress更新会不时发送请求数据,所以可以关闭WordPress更新,包括主题,插件和内核更新,建议禁用',
|
||||
'id' => 'gdk_diasble_wp_update',
|
||||
'type' => 'checkbox',
|
||||
'name' => 'WordPress更新',
|
||||
'desc' => '禁用<br>WordPress更新会不时发送请求数据,所以可以关闭WordPress更新,包括主题,插件和内核更新,建议禁用',
|
||||
'id' => 'gdk_diasble_wp_update',
|
||||
'type' => 'checkbox',
|
||||
],
|
||||
[
|
||||
'name' => 'WordPress更新中国加速',
|
||||
'desc' => '启用<br>该功能会帮助更顺利更新WordPress,注意:如果上面的WordPress禁用更新了,此处设置无效,由Litepress提供镜像,建议开启',
|
||||
'id' => 'gdk_porxy_update',
|
||||
'type' => 'checkbox',
|
||||
'name' => 'WordPress更新中国加速',
|
||||
'desc' => '启用<br>该功能会帮助更顺利更新WordPress,注意:如果上面的WordPress禁用更新了,此处设置无效,由Litepress提供镜像,建议开启',
|
||||
'id' => 'gdk_porxy_update',
|
||||
'type' => 'checkbox',
|
||||
],
|
||||
[
|
||||
'name' => '头像加速功能',
|
||||
'desc' => '该功能会增加头像加载速度,有随机头像,V2EX头像镜像和七牛头像镜像,默认选择随机头像,本地头像和微信头像不受影响',
|
||||
'id' => 'gdk_switch_get_avatar',
|
||||
'type' => 'select',
|
||||
'name' => '头像加速功能',
|
||||
'desc' => '该功能会增加头像加载速度,有随机头像,V2EX头像镜像和七牛头像镜像,默认选择随机头像,本地头像和微信头像不受影响',
|
||||
'id' => 'gdk_switch_get_avatar',
|
||||
'type' => 'select',
|
||||
'options' => [
|
||||
'1' => '随机头像',
|
||||
'2' => 'V2EX头像镜像',
|
||||
'3' => '七牛头像镜像',
|
||||
'4' => 'Cravatar',
|
||||
],
|
||||
'std' => '1',
|
||||
'std' => '1',
|
||||
],
|
||||
],
|
||||
'SEO' => [
|
||||
[
|
||||
'name' => '网站关键字', //选项显示的文字,选填
|
||||
'desc' => '各关键字间用半角逗号', '分割,数量在6个以内最佳。', //选项显示的一段描述文字,选填
|
||||
'id' => 'gdk_keywords', //选项的id,必须是唯一,后面根据这个获取值,必填
|
||||
'type' => 'text', //种类,这个是普通的文字输入,必填
|
||||
'std' => '', //选项的默认值,选填
|
||||
'desc' => '各关键字间用半角逗号', '分割,数量在6个以内最佳。', //选项显示的一段描述文字,选填
|
||||
'id' => 'gdk_keywords', //选项的id,必须是唯一,后面根据这个获取值,必填
|
||||
'type' => 'text', //种类,这个是普通的文字输入,必填
|
||||
'std' => '', //选项的默认值,选填
|
||||
],
|
||||
[
|
||||
'name' => '网站描述',
|
||||
'desc' => '用简洁的文字描述本站点,字数建议在120个字以内。',
|
||||
'id' => 'gdk_description',
|
||||
'id' => 'gdk_description',
|
||||
'type' => 'text',
|
||||
],
|
||||
[
|
||||
'name' => 'title分隔符',
|
||||
'desc' => '显示在浏览器标题栏的一个用来分隔网站名字的',
|
||||
'id' => 'gdk_delimiter',
|
||||
'id' => 'gdk_delimiter',
|
||||
'type' => 'text',
|
||||
'std' => '|',
|
||||
'std' => '|',
|
||||
],
|
||||
[
|
||||
'name' => '自动添加nofollow',
|
||||
'desc' => '该功能会给外链自动添加nofollow,推荐开启',
|
||||
'id' => 'gdk_nofollow',
|
||||
'type' => 'checkbox',
|
||||
'name' => '自动添加nofollow',
|
||||
'desc' => '该功能会给外链自动添加nofollow,推荐开启',
|
||||
'id' => 'gdk_nofollow',
|
||||
'type' => 'checkbox',
|
||||
],
|
||||
[
|
||||
'name' => '分类去Category优化',
|
||||
'desc' => '该功能会给外链自动添加nofollow,默认开启',
|
||||
'id' => 'gdk_no_category',
|
||||
'id' => 'gdk_no_category',
|
||||
'type' => 'checkbox',
|
||||
],
|
||||
[
|
||||
'name' => '文章自动内链',
|
||||
'desc' => '启用<br>该功能会将文章中与标签匹配的文字自动添加标签链接,如果是纯文字的内容建议打开,注意该功能和一些短代码等功能有冲突',
|
||||
'id' => 'gdk_tag_link',
|
||||
'type' => 'checkbox',
|
||||
'name' => '文章自动内链',
|
||||
'desc' => '启用<br>该功能会将文章中与标签匹配的文字自动添加标签链接,如果是纯文字的内容建议打开,注意该功能和一些短代码等功能有冲突',
|
||||
'id' => 'gdk_tag_link',
|
||||
'type' => 'checkbox',
|
||||
],
|
||||
[
|
||||
'name' => '关键词链接次数',
|
||||
'desc' => '文章中最多链接的次数,默认是5',
|
||||
'id' => 'gdk_tag_num',
|
||||
'id' => 'gdk_tag_num',
|
||||
'type' => 'number',
|
||||
'std' => 5,
|
||||
'std' => 5,
|
||||
],
|
||||
[
|
||||
'name' => 'Robots.txt 优化',
|
||||
'desc' => '启用<br>该功能会自动生成一个虚拟Robots.txt文件,和真实文件效果一样的,默认开启',
|
||||
'id' => 'gdk_robots',
|
||||
'type' => 'checkbox',
|
||||
'name' => 'Robots.txt 优化',
|
||||
'desc' => '启用<br>该功能会自动生成一个虚拟Robots.txt文件,和真实文件效果一样的,默认开启',
|
||||
'id' => 'gdk_robots',
|
||||
'type' => 'checkbox',
|
||||
],
|
||||
[
|
||||
'name' => '禁止蜘蛛爬取作者页面',
|
||||
'desc' => '启用<br>该功能会屏蔽蜘蛛访问作者页面,如果是单作者网站没必要展示作者页,根据自己网站实际情况选择是否开启,建议启用',
|
||||
'id' => 'gdk_no_author_page',
|
||||
'type' => 'checkbox',
|
||||
'name' => '禁止蜘蛛爬取作者页面',
|
||||
'desc' => '启用<br>该功能会屏蔽蜘蛛访问作者页面,如果是单作者网站没必要展示作者页,根据自己网站实际情况选择是否开启,建议启用',
|
||||
'id' => 'gdk_no_author_page',
|
||||
'type' => 'checkbox',
|
||||
],
|
||||
[
|
||||
'name' => '网站地图 sitemap',
|
||||
'desc' => '启用<br>该功能会自动生成网站地图[xml版和html版],链接:域名/sitemap.xml,域名/sitemap.html,开启后建议更新固定链接一次,建议启用开启',
|
||||
'id' => 'gdk_sitemap_xml',
|
||||
'type' => 'checkbox',
|
||||
'name' => '网站地图 sitemap',
|
||||
'desc' => '启用<br>该功能会自动生成网站地图[xml版和html版],链接:域名/sitemap.xml,域名/sitemap.html,开启后建议更新固定链接一次,建议启用开启',
|
||||
'id' => 'gdk_sitemap_xml',
|
||||
'type' => 'checkbox',
|
||||
],
|
||||
[
|
||||
'name' => '文章图片自动添加alt以及title',
|
||||
'desc' => '该功能会自动给文章中图片添加alt和title,并且是按照文章标题进行命名,默认开启',
|
||||
'id' => 'gdk_seo_img',
|
||||
'type' => 'checkbox',
|
||||
'name' => '文章图片自动添加alt以及title',
|
||||
'desc' => '该功能会自动给文章中图片添加alt和title,并且是按照文章标题进行命名,默认开启',
|
||||
'id' => 'gdk_seo_img',
|
||||
'type' => 'checkbox',
|
||||
],
|
||||
[
|
||||
'name' => '外链GO跳转',
|
||||
'desc' => '启用<br>启用后,文章外链会转化为/go?url=的类型',
|
||||
'id' => 'gdk_link_go',
|
||||
'id' => 'gdk_link_go',
|
||||
'type' => 'checkbox',
|
||||
],
|
||||
[
|
||||
'name' => '百度自动&主动推送',
|
||||
'desc' => '启用<br>启用后可以采用自动推送和主动推送给百度',
|
||||
'id' => 'gdk_baidu_push',
|
||||
'type' => 'checkbox',
|
||||
'name' => '百度自动&主动推送',
|
||||
'desc' => '启用<br>启用后可以采用自动推送和主动推送给百度',
|
||||
'id' => 'gdk_baidu_push',
|
||||
'type' => 'checkbox',
|
||||
],
|
||||
[
|
||||
'name' => '主动推送接口token',
|
||||
'desc' => '在百度站长平台获取主动推送token,比如:http://data.zz.baidu.com/urls?site=xxoo&token=<span class="key_word">一组字符</span>, 需要填写的是红色部分,<a class="key_word" rel="nofollow" href="http://zhanzhang.baidu.com/linksubmit/index" target="_blank">主动推送接口地址</a>',
|
||||
'id' => 'gdk_baidu_token',
|
||||
'id' => 'gdk_baidu_token',
|
||||
'type' => 'text',
|
||||
],
|
||||
],
|
||||
'安全' => [
|
||||
'安全' => [
|
||||
[
|
||||
'name' => '屏蔽各种不正常的请求',
|
||||
'desc' => '该功能会将各种不正常的请求比如破解,注入类的屏蔽掉,默认开启',
|
||||
'id' => 'gdk_block_requst',
|
||||
'type' => 'select',
|
||||
'name' => '屏蔽各种不正常的请求',
|
||||
'desc' => '该功能会将各种不正常的请求比如破解,注入类的屏蔽掉,默认开启',
|
||||
'id' => 'gdk_block_requst',
|
||||
'type' => 'select',
|
||||
'options' => [
|
||||
'0' => '禁用',
|
||||
'1' => '启用',
|
||||
],
|
||||
'std' => '1',
|
||||
'std' => '1',
|
||||
],
|
||||
[
|
||||
'name' => '网站维护模式',
|
||||
'desc' => '启用<br>启用后,未登录用户将看到一个简陋的维护页面',
|
||||
'id' => 'gdk_maintenance_mode',
|
||||
'id' => 'gdk_maintenance_mode',
|
||||
'type' => 'checkbox',
|
||||
],
|
||||
[
|
||||
'name' => '禁用REST API功能',
|
||||
'desc' => '禁用<br>启用后,REST API功能将关闭,如果没不使用该功能的话,建议关闭',
|
||||
'id' => 'gdk_disable_restapi',
|
||||
'id' => 'gdk_disable_restapi',
|
||||
'type' => 'checkbox',
|
||||
],
|
||||
[
|
||||
'name' => '保护用户暴露用户名',
|
||||
'desc' => '开启<br>启用后,将隐藏掉用户的登录名,起到保护作用',
|
||||
'id' => 'gdk_hide_user_name',
|
||||
'id' => 'gdk_hide_user_name',
|
||||
'type' => 'checkbox',
|
||||
],
|
||||
[
|
||||
'title' => '登陆安全防御',
|
||||
'type' => 'title',
|
||||
'type' => 'title',
|
||||
],
|
||||
[
|
||||
'name' => '登陆安全保护',
|
||||
'desc' => '该功能会将连续多次登陆错误的用户暂时锁定,待解锁后方可重新登陆,默认开启',
|
||||
'id' => 'gdk_lock_login',
|
||||
'type' => 'select',
|
||||
'name' => '登陆安全保护',
|
||||
'desc' => '该功能会将连续多次登陆错误的用户暂时锁定,待解锁后方可重新登陆,默认开启',
|
||||
'id' => 'gdk_lock_login',
|
||||
'type' => 'select',
|
||||
'options' => [
|
||||
'1' => '启用',
|
||||
'0' => '禁用',
|
||||
],
|
||||
'std' => '1',
|
||||
'std' => '1',
|
||||
],
|
||||
[
|
||||
'name' => '登录失败最大次数',
|
||||
'desc' => '默认:5',
|
||||
'id' => 'gdk_failed_login_limit',
|
||||
'id' => 'gdk_failed_login_limit',
|
||||
'type' => 'number',
|
||||
'std' => 5,
|
||||
'std' => 5,
|
||||
],
|
||||
[
|
||||
'name' => '登录失败锁定时间',
|
||||
'desc' => '单位秒,默认:60',
|
||||
'id' => 'gdk_lockout_duration',
|
||||
'id' => 'gdk_lockout_duration',
|
||||
'type' => 'number',
|
||||
'std' => 60,
|
||||
'std' => 60,
|
||||
],
|
||||
[
|
||||
'name' => '登录失败邮件通知',
|
||||
'desc' => '启用<br>开启后,将所有登陆失败信息发邮件通知管理员,预计会收到很多邮件,不建议启用',
|
||||
'id' => 'gdk_login_email',
|
||||
'id' => 'gdk_login_email',
|
||||
'type' => 'checkbox',
|
||||
],
|
||||
[
|
||||
'name' => '登陆数学验证',
|
||||
'desc' => '启用<br>开启后,将会登陆页面增加数学验证码',
|
||||
'id' => 'gdk_login_verify',
|
||||
'id' => 'gdk_login_verify',
|
||||
'type' => 'checkbox',
|
||||
],
|
||||
[
|
||||
'title' => '垃圾评论屏蔽',
|
||||
'type' => 'title',
|
||||
'type' => 'title',
|
||||
],
|
||||
[
|
||||
'name' => '垃圾评论拦截',
|
||||
'desc' => '该功能会默认屏蔽垃圾评论,支持纯外语拦截,日语拦截[外贸站慎用],关键词黑名单拦截,请务必选择对应主题的评论方式,关键词黑名单如图设置<a class="key_word" target="_blank" href="https://ae03.alicdn.com/kf/U146356e193b14a6da3f7cbb9cf507ea3D.png">点击查看如图设置</a>',
|
||||
'id' => 'gdk_fuck_spam',
|
||||
'type' => 'select',
|
||||
'name' => '垃圾评论拦截',
|
||||
'desc' => '该功能会默认屏蔽垃圾评论,支持纯外语拦截,日语拦截[外贸站慎用],关键词黑名单拦截,请务必选择对应主题的评论方式,关键词黑名单如图设置<a class="key_word" target="_blank" href="https://ae03.alicdn.com/kf/U146356e193b14a6da3f7cbb9cf507ea3D.png">点击查看如图设置</a>',
|
||||
'id' => 'gdk_fuck_spam',
|
||||
'type' => 'select',
|
||||
'options' => [
|
||||
'0' => '禁用',
|
||||
'1' => '启用(推荐)',
|
||||
],
|
||||
'std' => '1',
|
||||
'std' => '1',
|
||||
],
|
||||
],
|
||||
'高级' => [
|
||||
'高级' => [
|
||||
[
|
||||
'name' => '图片懒加载',
|
||||
'desc' => '启用<br>该功能会降低因为图片而导致的打开速度慢问题,建议开启',
|
||||
'id' => 'gdk_lazyload',
|
||||
'type' => 'checkbox',
|
||||
'name' => '图片懒加载',
|
||||
'desc' => '启用<br>该功能会降低因为图片而导致的打开速度慢问题,建议开启',
|
||||
'id' => 'gdk_lazyload',
|
||||
'type' => 'checkbox',
|
||||
],
|
||||
[
|
||||
'name' => 'HTML代码压缩',
|
||||
'desc' => '启用<br>开启后,将压缩网页HTML代码,提高网页加载速度',
|
||||
'id' => 'gdk_compress',
|
||||
'id' => 'gdk_compress',
|
||||
'type' => 'checkbox',
|
||||
],
|
||||
[
|
||||
'name' => '侧边栏缓存',
|
||||
'desc' => '启用<br>开启后,将会自动缓存小工具,如果想禁止缓存某个小工具,可以去小工具页面排除',
|
||||
'id' => 'gdk_sidebar_cache',
|
||||
'id' => 'gdk_sidebar_cache',
|
||||
'type' => 'checkbox',
|
||||
],
|
||||
[
|
||||
'name' => '链接新窗口打开',
|
||||
'desc' => '启用<br>启用后,所有文章链接将在新标签页打开',
|
||||
'id' => 'gdk_target_blank',
|
||||
'id' => 'gdk_target_blank',
|
||||
'type' => 'checkbox',
|
||||
],
|
||||
[
|
||||
'title' => '统一支付设置',
|
||||
'type' => 'title',
|
||||
'type' => 'title',
|
||||
],
|
||||
[
|
||||
'name' => '网站Psyjs支付功能',
|
||||
'desc' => '启用<br>网站支付功能需要HTTPS支持,需要开通Payjs使用,<a class="key_word" href="https://payjs.cn/ref/ZVEMKD" target="_blank" >点击注册Payjs</a>',
|
||||
'id' => 'gdk_payjs',
|
||||
'type' => 'checkbox',
|
||||
'name' => '网站Psyjs支付功能',
|
||||
'desc' => '启用<br>网站支付功能需要HTTPS支持,需要开通Payjs使用,<a class="key_word" href="https://payjs.cn/ref/ZVEMKD" target="_blank" >点击注册Payjs</a>',
|
||||
'id' => 'gdk_payjs',
|
||||
'type' => 'checkbox',
|
||||
],
|
||||
[
|
||||
'name' => '支付宝支付通道',
|
||||
'desc' => '启用<br>开启后,将增加支付宝支付方式,支付宝通道需要到payjs申请开通,如果开通的话,建议使用支付宝,因为费率便宜',
|
||||
'id' => 'gdk_payjs_alipay',
|
||||
'id' => 'gdk_payjs_alipay',
|
||||
'type' => 'checkbox',
|
||||
],
|
||||
[
|
||||
'name' => '金币和RMB兑换关系',
|
||||
'desc' => '请输入兑换关系,默认1RMB=10金币,请慎重选择,一旦设置好后面不能修改的,本选项仅对会员金币支付生效,游客免登陆支持不受影响',
|
||||
'id' => 'gdk_rate',
|
||||
'id' => 'gdk_rate',
|
||||
'type' => 'number',
|
||||
'std' => 10,
|
||||
'std' => 10,
|
||||
],
|
||||
[
|
||||
'name' => 'PayJs商户号',
|
||||
'desc' => '',
|
||||
'id' => 'gdk_payjs_id',
|
||||
'id' => 'gdk_payjs_id',
|
||||
'type' => 'text',
|
||||
'std' => 2333333333,
|
||||
'std' => 2333333333,
|
||||
],
|
||||
[
|
||||
'name' => 'PayJs密钥',
|
||||
'desc' => '',
|
||||
'id' => 'gdk_payjs_key',
|
||||
'id' => 'gdk_payjs_key',
|
||||
'type' => 'text',
|
||||
'std' => 444444444,
|
||||
'std' => 444444444,
|
||||
],
|
||||
[
|
||||
'title' => 'CDN镜像加速',
|
||||
'type' => 'title',
|
||||
'type' => 'title',
|
||||
],
|
||||
[
|
||||
'name' => 'CDN镜像加速',
|
||||
'desc' => '开启<br>本功能可以将本站静态资源同步到远程CDN服务器,减轻本站的流量压力,提高网站整体速度,国内主流CDN服务商[七牛,又拍,阿里OSS,腾讯COS,华为BOS等等]均支持,默认关闭,配置好服务器端后开启',
|
||||
'id' => 'gdk_cdn',
|
||||
'type' => 'checkbox',
|
||||
'name' => 'CDN镜像加速',
|
||||
'desc' => '开启<br>本功能可以将本站静态资源同步到远程CDN服务器,减轻本站的流量压力,提高网站整体速度,国内主流CDN服务商[七牛,又拍,阿里OSS,腾讯COS,华为BOS等等]均支持,默认关闭,配置好服务器端后开启',
|
||||
'id' => 'gdk_cdn',
|
||||
'type' => 'checkbox',
|
||||
],
|
||||
[
|
||||
'name' => 'CDN域名',
|
||||
'desc' => '输入您的CDN域名,一般需要到VDN后台获取,必须带 <span class="key_word">http(s):// ,且结尾不能带/ </span>',
|
||||
'id' => 'gdk_cdn_host',
|
||||
'id' => 'gdk_cdn_host',
|
||||
'type' => 'text',
|
||||
'std' => '',
|
||||
'std' => '',
|
||||
],
|
||||
[
|
||||
'name' => 'CDN镜像文件格式',
|
||||
'desc' => '在输入框内添加准备镜像的文件格式,比如png|jpg|jpeg|gif|ico(使用|分隔)',
|
||||
'id' => 'gdk_cdn_ext',
|
||||
'id' => 'gdk_cdn_ext',
|
||||
'type' => 'text',
|
||||
'std' => 'png|jpg|jpeg|gif|ico|html|7z|zip|rar|pdf|ppt|wmv|mp4|avi|mp3|txt',
|
||||
'std' => 'png|jpg|jpeg|gif|ico|html|7z|zip|rar|pdf|ppt|wmv|mp4|avi|mp3|txt',
|
||||
],
|
||||
[
|
||||
'name' => 'CDN镜像目录',
|
||||
'desc' => '在输入框内添加准备镜像的文件夹,默认为wp-content|wp-includes(使用|分隔)',
|
||||
'id' => 'gdk_cdn_dir',
|
||||
'id' => 'gdk_cdn_dir',
|
||||
'type' => 'text',
|
||||
'std' => 'wp-content|wp-includes',
|
||||
'std' => 'wp-content|wp-includes',
|
||||
],
|
||||
[
|
||||
'name' => '静态CDN服务商',
|
||||
'desc' => '选择使用国内CDN服务商,此项主要影响CDN缩略图,请选择对应服务商',
|
||||
'id' => 'gdk_cdn_serves',
|
||||
'type' => 'select',
|
||||
'name' => '静态CDN服务商',
|
||||
'desc' => '选择使用国内CDN服务商,此项主要影响CDN缩略图,请选择对应服务商',
|
||||
'id' => 'gdk_cdn_serves',
|
||||
'type' => 'select',
|
||||
'options' => [
|
||||
'1' => '七牛云',
|
||||
'2' => '又拍云',
|
||||
|
@ -388,219 +387,219 @@ $gdk_options = [
|
|||
'5' => '华为云OBS',
|
||||
'6' => '百度云BOS',
|
||||
],
|
||||
'std' => '4',
|
||||
'std' => '4',
|
||||
],
|
||||
[
|
||||
'name' => 'CDN水印',
|
||||
'desc' => '启用<br>启用后,请在七牛,又拍,OSS等CDN中设置自定义样式,名字为:<span class="key_word">water.jpg</span>,分隔符为<span class="key_word">!</span>',
|
||||
'id' => 'gdk_cdn_water',
|
||||
'id' => 'gdk_cdn_water',
|
||||
'type' => 'checkbox',
|
||||
],
|
||||
[
|
||||
'title' => '微信登录设置',
|
||||
'type' => 'title',
|
||||
'type' => 'title',
|
||||
],
|
||||
[
|
||||
'name' => '是否启用微信扫码登录',
|
||||
'desc' => '启用<br>开启后,可以使用微信扫码,另外需要HTTPS',
|
||||
'id' => 'gdk_weauth_oauth',
|
||||
'id' => 'gdk_weauth_oauth',
|
||||
'type' => 'checkbox',
|
||||
],
|
||||
[
|
||||
'name' => '强制微信登录',
|
||||
'desc' => '启用<br>开启后,将禁用WordPress自带的登录,所有登录地址都跳转到微信的登录,如需临时使用自带登录,可以使用这个链接:你的域名/wp-login.php?loggedout=true',
|
||||
'id' => 'gdk_weauth_force',
|
||||
'id' => 'gdk_weauth_force',
|
||||
'type' => 'checkbox',
|
||||
],
|
||||
[
|
||||
'title' => '微信推送设置',
|
||||
'type' => 'title',
|
||||
'type' => 'title',
|
||||
],
|
||||
[
|
||||
'name' => '评论微信推送提醒',
|
||||
'desc' => '启用<br>开启后,如果网站有新的评论,可以给管理员的微信推送提醒',
|
||||
'id' => 'gdk_workpush',
|
||||
'id' => 'gdk_workpush',
|
||||
'type' => 'checkbox',
|
||||
],
|
||||
[
|
||||
'name' => '企业微信推送应用ID',
|
||||
'desc' => '请输入您的企业微信推送应用ID',
|
||||
'id' => 'gdk_workpush_id',
|
||||
'id' => 'gdk_workpush_id',
|
||||
'type' => 'text',
|
||||
],
|
||||
[
|
||||
'name' => '企业微信推送应用Secret',
|
||||
'desc' => '请输入您的企业微信推送应用Secret',
|
||||
'id' => 'gdk_workpush_secret',
|
||||
'id' => 'gdk_workpush_secret',
|
||||
'type' => 'text',
|
||||
],
|
||||
[
|
||||
'name' => '企业微信企业ID',
|
||||
'desc' => '请输入您的企业微信ID',
|
||||
'id' => 'gdk_work_id',
|
||||
'id' => 'gdk_work_id',
|
||||
'type' => 'text',
|
||||
],
|
||||
[
|
||||
'title' => '微信群发设置',
|
||||
'type' => 'title',
|
||||
'type' => 'title',
|
||||
],
|
||||
[
|
||||
'name' => '微信wxPushet应用Token',
|
||||
'desc' => '请输入Wxpuers应用Token,从wxpusher后台获取',
|
||||
'id' => 'gdk_wxpusher_key',
|
||||
'id' => 'gdk_wxpusher_key',
|
||||
'type' => 'text',
|
||||
],
|
||||
[
|
||||
'name' => '微信Wxpusher主题ID',
|
||||
'desc' => '请输入您的Wxpusher主题ID,可以从后台获取',
|
||||
'id' => 'gdk_wxpusher_id',
|
||||
'id' => 'gdk_wxpusher_id',
|
||||
'type' => 'text',
|
||||
],
|
||||
[
|
||||
'title' => '微信公众号设置',
|
||||
'type' => 'title',
|
||||
'type' => 'title',
|
||||
],
|
||||
[
|
||||
'name' => '微信公众号TOKEN',
|
||||
'desc' => '请输入您的微信公众号TOKEN,微信公众号后台获取',
|
||||
'id' => 'gdk_wxmp_token',
|
||||
'id' => 'gdk_wxmp_token',
|
||||
'type' => 'text',
|
||||
],
|
||||
[
|
||||
'name' => '微信公众号二维码',
|
||||
'desc' => '请输入您的微信订阅号/公众号二维码图片链接',
|
||||
'id' => 'gdk_mp_qr',
|
||||
'id' => 'gdk_mp_qr',
|
||||
'type' => 'text',
|
||||
'std' => '',
|
||||
'std' => '',
|
||||
],
|
||||
[
|
||||
'title' => 'HTML5 桌面推送',
|
||||
'type' => 'title',
|
||||
'type' => 'title',
|
||||
],
|
||||
[
|
||||
'name' => 'HTML5 桌面推送',
|
||||
'desc' => '启用<br>该功能开启后会在浏览器右下角进行信息推送',
|
||||
'id' => 'gdk_h5notice',
|
||||
'type' => 'checkbox',
|
||||
'name' => 'HTML5 桌面推送',
|
||||
'desc' => '启用<br>该功能开启后会在浏览器右下角进行信息推送',
|
||||
'id' => 'gdk_h5notice',
|
||||
'type' => 'checkbox',
|
||||
],
|
||||
[
|
||||
'name' => 'HTML5推送标题【必选】',
|
||||
'desc' => '显示在弹窗顶部',
|
||||
'id' => 'gdk_notification_title',
|
||||
'id' => 'gdk_notification_title',
|
||||
'type' => 'text',
|
||||
'std' => 'Hi,你好',
|
||||
'std' => 'Hi,你好',
|
||||
],
|
||||
[
|
||||
'name' => 'HTML5推送间隔【必选】',
|
||||
'desc' => '输入数字,当自动关闭或者用户关闭之后多久再次弹窗,默认10天',
|
||||
'id' => 'gdk_notification_days',
|
||||
'id' => 'gdk_notification_days',
|
||||
'type' => 'number',
|
||||
'std' => 10,
|
||||
'std' => 10,
|
||||
],
|
||||
[
|
||||
'name' => 'HTML5推送COOKIE【必选】',
|
||||
'desc' => '修改COOKIE值可以强制向访客推送新的信息,无视时间间隔,不能使用中文,默认233',
|
||||
'id' => 'gdk_notification_cookie',
|
||||
'id' => 'gdk_notification_cookie',
|
||||
'type' => 'text',
|
||||
'std' => '233',
|
||||
'std' => '233',
|
||||
],
|
||||
[
|
||||
'name' => 'HTML5推送图片【必选】',
|
||||
'desc' => '填写一个正方形的图片,显示在推送信息左侧,默认为默认头像',
|
||||
'id' => 'gdk_notification_icon',
|
||||
'id' => 'gdk_notification_icon',
|
||||
'type' => 'text',
|
||||
'std' => '',
|
||||
'std' => '',
|
||||
],
|
||||
[
|
||||
'name' => 'HTML5推送链接【可选】',
|
||||
'desc' => '当用户点击弹窗的时候说点击的链接,默认为极客公园',
|
||||
'id' => 'gdk_notification_link',
|
||||
'id' => 'gdk_notification_link',
|
||||
'type' => 'text',
|
||||
'std' => 'https://gitcafe.net',
|
||||
'std' => 'https://gitcafe.net',
|
||||
],
|
||||
[
|
||||
'name' => 'HTML5推送内容',
|
||||
'desc' => '在这里输入推送主体内容,字数合适就行,不能太多【必选】',
|
||||
'id' => 'gdk_notification_body',
|
||||
'id' => 'gdk_notification_body',
|
||||
'type' => 'textarea',
|
||||
'std' => '极客公园,一个分享有趣的安卓APP和实用的WordPress技术以及Windows使用技巧的网站',
|
||||
'std' => '极客公园,一个分享有趣的安卓APP和实用的WordPress技术以及Windows使用技巧的网站',
|
||||
],
|
||||
[
|
||||
'title' => 'SMTP邮箱设置',
|
||||
'type' => 'title',
|
||||
'type' => 'title',
|
||||
],
|
||||
[
|
||||
'name' => 'SMTP邮箱发送',
|
||||
'desc' => '启用<br>该功能利用第三方SMTP邮箱服务发送邮件,比如评论邮件,需要配置好再开启',
|
||||
'id' => 'gdk_smtp',
|
||||
'type' => 'checkbox',
|
||||
'name' => 'SMTP邮箱发送',
|
||||
'desc' => '启用<br>该功能利用第三方SMTP邮箱服务发送邮件,比如评论邮件,需要配置好再开启',
|
||||
'id' => 'gdk_smtp',
|
||||
'type' => 'checkbox',
|
||||
],
|
||||
[
|
||||
'name' => '发件人昵称',
|
||||
'desc' => '请输入您的网站名称,比如:云落',
|
||||
'id' => 'gdk_smtp_username',
|
||||
'id' => 'gdk_smtp_username',
|
||||
'type' => 'text',
|
||||
],
|
||||
[
|
||||
'name' => 'SMTP服务器地址',
|
||||
'desc' => '请输入您的邮箱的SMTP服务器,<a class="key_word" target="_blank" href="https://blog.csdn.net/whyhonest/article/details/7289420">点击查看常用SMTP地址</a>',
|
||||
'id' => 'gdk_smtp_host',
|
||||
'id' => 'gdk_smtp_host',
|
||||
'type' => 'text',
|
||||
'std' => 'smtp.qq.com',
|
||||
'std' => 'smtp.qq.com',
|
||||
],
|
||||
[
|
||||
'name' => 'SMTP服务器端口',
|
||||
'desc' => '请输入您的smtp端口,一般QQ邮箱推荐使用465端口',
|
||||
'id' => 'gdk_smtp_port',
|
||||
'id' => 'gdk_smtp_port',
|
||||
'type' => 'number',
|
||||
'std' => 465,
|
||||
'std' => 465,
|
||||
],
|
||||
[
|
||||
'name' => '邮箱账号',
|
||||
'desc' => '请输入您的邮箱地址,比如云落的sp91@qq.com',
|
||||
'id' => 'gdk_smtp_mail',
|
||||
'id' => 'gdk_smtp_mail',
|
||||
'type' => 'text',
|
||||
],
|
||||
[
|
||||
'name' => '邮箱密码',
|
||||
'desc' => '请输入您的邮箱授权码,<span class="key_word">注意不同邮箱服务器的密码不一样,有的是密码,有的比如QQ邮箱就是授权码</span>',
|
||||
'id' => 'gdk_smtp_password',
|
||||
'id' => 'gdk_smtp_password',
|
||||
'type' => 'password',
|
||||
],
|
||||
[
|
||||
'title' => '自定义代码',
|
||||
'type' => 'title',
|
||||
'type' => 'title',
|
||||
],
|
||||
[
|
||||
'name' => '网站头部自定义代码',
|
||||
'desc' => '代码将插入到head区域',
|
||||
'id' => 'gdk_custom_head_code',
|
||||
'id' => 'gdk_custom_head_code',
|
||||
'type' => 'textarea',
|
||||
],
|
||||
[
|
||||
'name' => '网站底部自定义代码',
|
||||
'desc' => '代码将插入到foot区域',
|
||||
'id' => 'gdk_custom_foot_code',
|
||||
'id' => 'gdk_custom_foot_code',
|
||||
'type' => 'textarea',
|
||||
],
|
||||
[
|
||||
'name' => '文章顶部自定义内容',
|
||||
'desc' => '在文章顶部插入一个内容',
|
||||
'id' => 'gdk_artical_top',
|
||||
'id' => 'gdk_artical_top',
|
||||
'type' => 'textarea',
|
||||
],
|
||||
[
|
||||
'name' => '文章底部自定义内容',
|
||||
'desc' => '在文章底部插入一个内容',
|
||||
'id' => 'gdk_artical_bottom',
|
||||
'id' => 'gdk_artical_bottom',
|
||||
'type' => 'textarea',
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
//载入主题配置,默认路径在主题根目录options.php
|
||||
if (file_exists(get_template_directory() . '/options.php')) {
|
||||
include get_template_directory() . '/options.php';
|
||||
if (file_exists(get_template_directory().'/options.php')) {
|
||||
include get_template_directory().'/options.php';
|
||||
}
|
||||
|
||||
if (!empty($gdk_theme_options)) {
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
<?php
|
||||
/**
|
||||
* Git 插件后台选项
|
||||
* Git 插件后台选项.
|
||||
*/
|
||||
|
||||
if (!defined('WPINC')) {
|
||||
die;
|
||||
exit;
|
||||
}
|
||||
|
||||
$gdk_default = [];
|
||||
$gdk_options = [];
|
||||
$gdk_options = [];
|
||||
|
||||
include 'options-config.php';
|
||||
$gdk_config = get_option('gdk_options_setup');
|
||||
|
||||
|
@ -17,9 +17,9 @@ function gdk_update_options()
|
|||
global $gdk_default, $gdk_options, $gdk_config;
|
||||
foreach ($gdk_options as $panel) {
|
||||
foreach ($panel as $option) {
|
||||
$id = $option['id'] ?? '';
|
||||
$id = $option['id'] ?? '';
|
||||
$type = $option['type'] ?? '';
|
||||
$std = $option['std'] ?? '';
|
||||
$std = $option['std'] ?? '';
|
||||
if (!$id) {
|
||||
continue;
|
||||
}
|
||||
|
@ -30,7 +30,6 @@ function gdk_update_options()
|
|||
}
|
||||
|
||||
$gdk_config[$id] = $std;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -40,399 +39,469 @@ gdk_update_options();
|
|||
function gdk_option($id, $Default = false)
|
||||
{
|
||||
global $gdk_default, $gdk_config;
|
||||
return stripslashes($Default ? $gdk_default[$id] : $gdk_config[$id]);
|
||||
|
||||
return stripslashes(trim($Default ? $gdk_default[$id] : $gdk_config[$id]));
|
||||
}
|
||||
|
||||
//设置页面模板
|
||||
function gdk_options_page()
|
||||
{
|
||||
global $gdk_options;
|
||||
?>
|
||||
global $gdk_options; ?>
|
||||
|
||||
<div class="wrap">
|
||||
<h2>GDK选项 <input type="button" class="add-new-h2 get_new_version" value="检测更新"><input type="button" style="display:none;" class="add-new-h2 install_new_version" value="安装更新"></h2>
|
||||
<hr/>
|
||||
<?php
|
||||
<h2>GDK选项 <input type="button" class="add-new-h2 get_new_version" value="检测更新"><input type="button"
|
||||
style="display:none;" class="add-new-h2 install_new_version" value="安装更新"></h2>
|
||||
<hr />
|
||||
<?php
|
||||
if (isset($_GET['update'])) {
|
||||
echo '<div class="updated"><p><strong>设置已保存。</strong></p></div>';
|
||||
}
|
||||
|
||||
if (isset($_GET['reset'])) {
|
||||
echo '<div class="updated"><p><strong>设置已重置。</strong></p></div>';
|
||||
}
|
||||
|
||||
?>
|
||||
} ?>
|
||||
|
||||
<div class="wp-filter">
|
||||
<ul class="filter-links">
|
||||
<?php
|
||||
<?php
|
||||
$activePanelIdx = $_GET['panel'] ?? 0;
|
||||
foreach (array_keys($gdk_options) as $i => $name) {
|
||||
echo '<li><a href="#panel_' . $i . '" data-panel="' . $i . '" ' . ($i == $activePanelIdx ? 'class="current"' : '') . '>' . $name . '</a></li>';
|
||||
}
|
||||
?>
|
||||
echo '<li><a href="#panel_'.$i.'" data-panel="'.$i.'" '.($i == $activePanelIdx ? 'class="current"' : '').'>'.$name.'</a></li>';
|
||||
} ?>
|
||||
<li><a href="#panel_about" data-panel="about" class="about">关于</a></li>
|
||||
</ul>
|
||||
<div class="search-form"><label class="screen-reader-text" for="wp-filter-search-input">筛选插件选项…</label><input placeholder="筛选插件选项…" type="search" id="wp-filter-search-input" class="wp-filter-search"></div>
|
||||
</div>
|
||||
<div class="search-form"><label class="screen-reader-text" for="wp-filter-search-input">筛选插件选项…</label><input
|
||||
placeholder="筛选插件选项…" type="search" id="wp-filter-search-input" class="wp-filter-search"></div>
|
||||
</div>
|
||||
|
||||
<form method="post">
|
||||
<?php
|
||||
<form method="post">
|
||||
<?php
|
||||
$index = 0;
|
||||
foreach ($gdk_options as $panel) {
|
||||
echo '<div class="panel gdk_option" id="panel_' . $index . '" ' . ($index == $activePanelIdx ? ' style="display:block"' : '') . '><table class="form-table">';
|
||||
echo '<div class="panel gdk_option" id="panel_'.$index.'" '.($index == $activePanelIdx ? ' style="display:block"' : '').'><table class="form-table">';
|
||||
foreach ($panel as $option) {
|
||||
$type = $option['type'];
|
||||
if ($type == 'title') {
|
||||
if ('title' == $type) {
|
||||
?>
|
||||
<tr class="title">
|
||||
<th colspan="2">
|
||||
<h3><?php echo $option['title']; ?></h3>
|
||||
<?php if (isset($option['desc'])) {
|
||||
echo '<p>' . $option['desc'] . '</p>';
|
||||
}
|
||||
?>
|
||||
</th>
|
||||
</tr>
|
||||
<?php
|
||||
<tr class="title">
|
||||
<th colspan="2">
|
||||
<h3><?php echo $option['title']; ?>
|
||||
</h3>
|
||||
<?php if (isset($option['desc'])) {
|
||||
echo '<p>'.$option['desc'].'</p>';
|
||||
} ?>
|
||||
</th>
|
||||
</tr>
|
||||
<?php
|
||||
continue;
|
||||
}
|
||||
$id = $option['id'];
|
||||
?>
|
||||
<tr id="row-<?php echo $id; ?>">
|
||||
<th><label for="<?php echo $id; ?>"><?php echo $option['name']; ?></label></th>
|
||||
<td>
|
||||
<?php
|
||||
$id = $option['id']; ?>
|
||||
<tr id="row-<?php echo $id; ?>">
|
||||
<th><label for="<?php echo $id; ?>"><?php echo $option['name']; ?></label>
|
||||
</th>
|
||||
<td>
|
||||
<?php
|
||||
switch ($type) {
|
||||
case 'text':
|
||||
?>
|
||||
<label>
|
||||
<input name="<?php echo $id; ?>" class="regular-text" id="<?php echo $id; ?>" type="text" value="<?php echo esc_attr(gdk_option($id)) ?>" />
|
||||
</label>
|
||||
<p class="description"><?php echo $option['desc']; ?></p>
|
||||
<?php
|
||||
<label>
|
||||
<input name="<?php echo $id; ?>"
|
||||
class="regular-text" id="<?php echo $id; ?>"
|
||||
type="text"
|
||||
value="<?php echo esc_attr(gdk_option($id)); ?>" />
|
||||
</label>
|
||||
<p class="description"><?php echo $option['desc']; ?>
|
||||
</p>
|
||||
<?php
|
||||
break;
|
||||
|
||||
case 'number':
|
||||
?>
|
||||
<label>
|
||||
<input name="<?php echo $id; ?>" class="small-text" id="<?php echo $id; ?>" type="number" value="<?php echo esc_attr(gdk_option($id)) ?>" />
|
||||
<span class="description"><?php echo $option['desc']; ?></span>
|
||||
</label>
|
||||
<?php
|
||||
<label>
|
||||
<input name="<?php echo $id; ?>"
|
||||
class="small-text" id="<?php echo $id; ?>"
|
||||
type="number"
|
||||
value="<?php echo esc_attr(gdk_option($id)); ?>" />
|
||||
<span class="description"><?php echo $option['desc']; ?></span>
|
||||
</label>
|
||||
<?php
|
||||
break;
|
||||
|
||||
case 'textarea':
|
||||
?>
|
||||
<p><label for="<?php echo $id; ?>"><?php echo $option['desc']; ?></label></p>
|
||||
<p><textarea name="<?php echo $id; ?>" id="<?php echo $id; ?>" rows="10" cols="50" class="large-text code"><?php echo esc_textarea(gdk_option($id)) ?></textarea></p>
|
||||
<?php
|
||||
<p><label for="<?php echo $id; ?>"><?php echo $option['desc']; ?></label>
|
||||
</p>
|
||||
<p><textarea name="<?php echo $id; ?>"
|
||||
id="<?php echo $id; ?>" rows="10" cols="50"
|
||||
class="large-text code"><?php echo esc_textarea(gdk_option($id)); ?></textarea>
|
||||
</p>
|
||||
<?php
|
||||
break;
|
||||
|
||||
case 'select':
|
||||
?>
|
||||
<label for="<?php echo $id; ?>"></label>
|
||||
<label>
|
||||
<select name="<?php echo $id; ?>" id="<?php echo $id; ?>">
|
||||
<?php foreach ($option['options'] as $val => $name) : ?>
|
||||
<option value="<?php echo $val; ?>" <?php selected(gdk_option($id), $val);
|
||||
<label for="<?php echo $id; ?>"></label>
|
||||
<label>
|
||||
<select name="<?php echo $id; ?>"
|
||||
id="<?php echo $id; ?>">
|
||||
<?php foreach ($option['options'] as $val => $name) { ?>
|
||||
<option value="<?php echo $val; ?>" <?php selected(gdk_option($id), $val);
|
||||
?>>
|
||||
<?php echo $name;
|
||||
<?php echo $name;
|
||||
?>
|
||||
</option>
|
||||
<?php endforeach;
|
||||
</option>
|
||||
<?php }
|
||||
?>
|
||||
</select>
|
||||
</label>
|
||||
<p class="description"><?php echo $option['desc'];
|
||||
?></p>
|
||||
<?php
|
||||
</select>
|
||||
</label>
|
||||
<p class="description"><?php echo $option['desc'];
|
||||
?>
|
||||
</p>
|
||||
<?php
|
||||
break;
|
||||
|
||||
case 'radio':
|
||||
?>
|
||||
<fieldset>
|
||||
<?php foreach ($option['options'] as $val => $name): ?>
|
||||
<label>
|
||||
<input type="radio" name="<?php echo $id; ?>" id="<?php echo $id . '_' . $val; ?>" value="<?php echo $val; ?>" <?php checked(gdk_option($id), $val); ?>>
|
||||
<?php echo $name; ?>
|
||||
</label>
|
||||
<?php endforeach; ?>
|
||||
</fieldset>
|
||||
<p class="description"><?php echo $option['desc']; ?></p>
|
||||
<?php
|
||||
<fieldset>
|
||||
<?php foreach ($option['options'] as $val => $name) { ?>
|
||||
<label>
|
||||
<input type="radio" name="<?php echo $id; ?>"
|
||||
id="<?php echo $id.'_'.$val; ?>"
|
||||
value="<?php echo $val; ?>" <?php checked(gdk_option($id), $val); ?>>
|
||||
<?php echo $name; ?>
|
||||
</label>
|
||||
<?php } ?>
|
||||
</fieldset>
|
||||
<p class="description"><?php echo $option['desc']; ?>
|
||||
</p>
|
||||
<?php
|
||||
break;
|
||||
|
||||
case 'checkbox':
|
||||
?>
|
||||
<label>
|
||||
<input type='checkbox' name="<?php echo $id; ?>" id="<?php echo $id; ?>" value="1" <?php echo checked(gdk_option($id)); ?> />
|
||||
<span><?php echo $option['desc']; ?></span>
|
||||
</label>
|
||||
<?php
|
||||
<label>
|
||||
<input type='checkbox' name="<?php echo $id; ?>"
|
||||
id="<?php echo $id; ?>" value="1" <?php echo checked(gdk_option($id)); ?> />
|
||||
<span><?php echo $option['desc']; ?></span>
|
||||
</label>
|
||||
<?php
|
||||
break;
|
||||
|
||||
case 'checkboxs':
|
||||
?>
|
||||
<fieldset>
|
||||
<?php $checkboxValues = gdk_option($id);
|
||||
if (!is_array($checkboxValues)) $checkboxValues = [];
|
||||
<fieldset>
|
||||
<?php $checkboxValues = gdk_option($id);
|
||||
if (!is_array($checkboxValues)) {
|
||||
$checkboxValues = [];
|
||||
}
|
||||
|
||||
foreach ($option['options'] as $id => $name): ?>
|
||||
<label>
|
||||
<input type="checkbox" name="<?php echo $id; ?>[]" id="<?php echo $id; ?>[]" value="<?php echo $id; ?>" <?php checked(array_key_exists($id, $checkboxValues), 1); ?>>
|
||||
<?php echo $name; ?>
|
||||
</label>
|
||||
<?php endforeach; ?>
|
||||
</fieldset>
|
||||
<p class="description"><?php echo $option['desc']; ?></p>
|
||||
<?php
|
||||
foreach ($option['options'] as $id => $name) { ?>
|
||||
<label>
|
||||
<input type="checkbox"
|
||||
name="<?php echo $id; ?>[]"
|
||||
id="<?php echo $id; ?>[]"
|
||||
value="<?php echo $id; ?>" <?php checked(array_key_exists($id, $checkboxValues), 1); ?>>
|
||||
<?php echo $name; ?>
|
||||
</label>
|
||||
<?php } ?>
|
||||
</fieldset>
|
||||
<p class="description"><?php echo $option['desc']; ?>
|
||||
</p>
|
||||
<?php
|
||||
break;
|
||||
|
||||
default:
|
||||
?>
|
||||
<label>
|
||||
<input name="<?php echo $id; ?>" class="regular-text" id="<?php echo $id; ?>" type="<?php echo $type; ?>" value="<?php echo esc_attr(gdk_option($id)) ?>" />
|
||||
</label>
|
||||
<p class="description"><?php echo $option['desc']; ?></p>
|
||||
<?php
|
||||
<label>
|
||||
<input name="<?php echo $id; ?>"
|
||||
class="regular-text" id="<?php echo $id; ?>"
|
||||
type="<?php echo $type; ?>"
|
||||
value="<?php echo esc_attr(gdk_option($id)); ?>" />
|
||||
</label>
|
||||
<p class="description"><?php echo $option['desc']; ?>
|
||||
</p>
|
||||
<?php
|
||||
break;
|
||||
}
|
||||
echo '</td></tr>';
|
||||
}
|
||||
echo '</table></div>';
|
||||
$index++;
|
||||
}
|
||||
?>
|
||||
<div class="panel" id="panel_about">
|
||||
<table class="form-table">
|
||||
<tr>
|
||||
<th><h4>联系方式</h4></th>
|
||||
<td>
|
||||
<ul>
|
||||
<li>QQ:865113728(推荐)</li>
|
||||
<li>邮箱:<a href="mailto:sp91@qq.com">sp91@qq.com</a></li>
|
||||
<li><p style="font-size:14px;color:#72777c">* 和主题无关的问题恕不回复</p></li>
|
||||
</ul>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><h4>意见反馈</h4></th>
|
||||
<td>
|
||||
<input type="button" class="add-new-h2 feedback-btn" value="意见反馈">
|
||||
</td></tr>
|
||||
++$index;
|
||||
} ?>
|
||||
<div class="panel" id="panel_about">
|
||||
<table class="form-table">
|
||||
<tr>
|
||||
<th>
|
||||
<h4>联系方式</h4>
|
||||
</th>
|
||||
<td>
|
||||
<ul>
|
||||
<li>QQ:865113728(推荐)</li>
|
||||
<li>邮箱:<a href="mailto:sp91@qq.com">sp91@qq.com</a></li>
|
||||
<li>
|
||||
<p style="font-size:14px;color:#72777c">* 和主题无关的问题恕不回复</p>
|
||||
</li>
|
||||
</ul>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>
|
||||
<h4>意见反馈</h4>
|
||||
</th>
|
||||
<td>
|
||||
<input type="button" class="add-new-h2 feedback-btn" value="意见反馈">
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
</table>
|
||||
</div>
|
||||
<hr />
|
||||
<p class="submit" style="display:inline;float:left;margin-right:50px;">
|
||||
<input name="submit" type="submit" class="button button-primary" value="保存更改"/>
|
||||
<input type="hidden" name="action" value="update" />
|
||||
<input type="hidden" name="panel" value="<?php echo $activePanelIdx; ?>" id="active_panel_name" />
|
||||
</p>
|
||||
</form>
|
||||
</table>
|
||||
</div>
|
||||
<hr />
|
||||
<p class="submit" style="display:inline;float:left;margin-right:50px;">
|
||||
<input name="submit" type="submit" class="button button-primary" value="保存更改" />
|
||||
<input type="hidden" name="action" value="update" />
|
||||
<input type="hidden" name="panel"
|
||||
value="<?php echo $activePanelIdx; ?>"
|
||||
id="active_panel_name" />
|
||||
</p>
|
||||
</form>
|
||||
|
||||
<form method="post" style="display:inline;float:left;margin-right:50px;">
|
||||
<p class="submit">
|
||||
<input name="reset" type="submit" class="button button-secondary" value="重置选项" onclick="return confirm('你确定要重置选项吗?');"/>
|
||||
<input type="hidden" name="action" value="reset" />
|
||||
</p>
|
||||
</form>
|
||||
<form style="display:inline;float:left;margin-right:50px;">
|
||||
<p class="submit">
|
||||
<input type="button" class="button button-secondary mail_test" value="SMTP测试" onclick="return confirm('点击后点击后,网站会向指定邮箱发送测试邮件,如果发送有响应则证明邮箱成功,如果没有任何响应说明邮箱配置失败!');"/>
|
||||
</p>
|
||||
</form>
|
||||
<form method="post" style="display:inline;float:left;margin-right:50px;">
|
||||
<p class="submit">
|
||||
<input name="reset" type="submit" class="button button-secondary" value="重置选项"
|
||||
onclick="return confirm('你确定要重置选项吗?');" />
|
||||
<input type="hidden" name="action" value="reset" />
|
||||
</p>
|
||||
</form>
|
||||
<form style="display:inline;float:left;margin-right:50px;">
|
||||
<p class="submit">
|
||||
<input type="button" class="button button-secondary mail_test" value="SMTP测试"
|
||||
onclick="return confirm('点击后点击后,网站会向指定邮箱发送测试邮件,如果发送有响应则证明邮箱成功,如果没有任何响应说明邮箱配置失败!');" />
|
||||
</p>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<!-- 静态资源css&js -->
|
||||
<style>
|
||||
.panel {
|
||||
display: none;
|
||||
margin: 0 20px;
|
||||
}
|
||||
.panel h3 {
|
||||
margin: 0;
|
||||
border-bottom: 1px solid #d2d3e0;
|
||||
padding-bottom: 5px;
|
||||
}
|
||||
.key_word{
|
||||
color:#f70044;
|
||||
font-weight:bold;
|
||||
text-decoration:none;
|
||||
margin: 10px;
|
||||
}
|
||||
.panel th {
|
||||
font-weight: normal;
|
||||
}
|
||||
.panel {
|
||||
display: none;
|
||||
margin: 0 20px;
|
||||
}
|
||||
|
||||
.wp-filter {
|
||||
padding: 0 20px;
|
||||
margin-bottom: 0;
|
||||
font-size: 15px;
|
||||
}
|
||||
.panel h3 {
|
||||
margin: 0;
|
||||
border-bottom: 1px solid #d2d3e0;
|
||||
padding-bottom: 5px;
|
||||
}
|
||||
|
||||
.filter-links .current,.filter-links.current:focus {
|
||||
color:#6b48ff!important;
|
||||
border-bottom: 4px solid #6b48ff;
|
||||
}
|
||||
.key_word {
|
||||
color: #f70044;
|
||||
font-weight: bold;
|
||||
text-decoration: none;
|
||||
margin: 10px;
|
||||
}
|
||||
|
||||
.filter-links li>a:hover{color:#666}
|
||||
.filter-links a:focus{color:#6b48ff;box-shadow:none}
|
||||
.panel th {
|
||||
font-weight: normal;
|
||||
}
|
||||
|
||||
.gdk_option input[type=checkbox]:checked::before,.gdk_option input[type=radio]:checked::before {
|
||||
background-color: #6b48ff;
|
||||
}
|
||||
.gdk_option input[type=checkbox],.gdk_option input[type=select] {
|
||||
margin:4px;
|
||||
}
|
||||
.gdk_option input[type=radio]:focus, .gdk_option input[type=checkbox]:focus{
|
||||
box-shadow: 0 0 0 1px #6b48ff;
|
||||
}
|
||||
.wp-filter {
|
||||
padding: 0 20px;
|
||||
margin-bottom: 0;
|
||||
font-size: 15px;
|
||||
}
|
||||
|
||||
.wp-filter .drawer-toggle:before {
|
||||
content: "\f463";
|
||||
color: #fff!important;
|
||||
background: #e14d43;
|
||||
border-radius: 50%;
|
||||
box-shadow: inset 0 0 0 2px #e14d43, 0 0 0 2px #e14d43;
|
||||
}
|
||||
.install_new_version,
|
||||
.wrap.searching .nav-tab-wrapper a,
|
||||
.wrap.searching .panel tr,
|
||||
body.show-filters .wrap form {
|
||||
display: none
|
||||
}
|
||||
.filter-links .current,
|
||||
.filter-links.current:focus {
|
||||
color: #6b48ff !important;
|
||||
border-bottom: 4px solid #6b48ff;
|
||||
}
|
||||
|
||||
.wrap.searching .panel {
|
||||
display: block!important;
|
||||
}
|
||||
.filter-links li>a:hover {
|
||||
color: #666
|
||||
}
|
||||
|
||||
.filter-drawer {
|
||||
padding-top: 0;
|
||||
padding-bottom: 0;
|
||||
}
|
||||
.filter-drawer ul {
|
||||
list-style: disc inside;
|
||||
}
|
||||
.get_update_res,.get_new_version{
|
||||
margin-left: 20px;
|
||||
padding: 5px;
|
||||
font-size: medium;
|
||||
}
|
||||
.g-load{
|
||||
background: url(images/spinner.gif) no-repeat;
|
||||
background-size: 20px 20px;
|
||||
display: inline-block;
|
||||
vertical-align: middle;
|
||||
opacity: .7;
|
||||
filter: alpha(opacity=70);
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
margin: 4px 10px 0;
|
||||
}
|
||||
.filter-links a:focus {
|
||||
color: #6b48ff;
|
||||
box-shadow: none
|
||||
}
|
||||
|
||||
.gdk_option input[type=checkbox]:checked::before,.gdk_option input[type=radio]:checked::before {
|
||||
background-color: #6b48ff;
|
||||
}
|
||||
|
||||
.gdk_option input[type=checkbox],
|
||||
.gdk_option input[type=select] {
|
||||
margin: 4px;
|
||||
}
|
||||
|
||||
.gdk_option input[type=radio]:focus,
|
||||
.gdk_option input[type=checkbox]:focus {
|
||||
box-shadow: 0 0 0 1px #6b48ff;
|
||||
}
|
||||
|
||||
.wp-filter .drawer-toggle:before {
|
||||
content: "\f463";
|
||||
color: #fff !important;
|
||||
background: #e14d43;
|
||||
border-radius: 50%;
|
||||
box-shadow: inset 0 0 0 2px #e14d43, 0 0 0 2px #e14d43;
|
||||
}
|
||||
|
||||
.install_new_version,
|
||||
.wrap.searching .nav-tab-wrapper a,
|
||||
.wrap.searching .panel tr,
|
||||
body.show-filters .wrap form {
|
||||
display: none
|
||||
}
|
||||
|
||||
.wrap.searching .panel {
|
||||
display: block !important;
|
||||
}
|
||||
|
||||
.filter-drawer {
|
||||
padding-top: 0;
|
||||
padding-bottom: 0;
|
||||
}
|
||||
|
||||
.filter-drawer ul {
|
||||
list-style: disc inside;
|
||||
}
|
||||
|
||||
.get_update_res,
|
||||
.get_new_version {
|
||||
margin-left: 20px;
|
||||
padding: 5px;
|
||||
font-size: medium;
|
||||
}
|
||||
|
||||
.g-load {
|
||||
background: url(images/spinner.gif) no-repeat;
|
||||
background-size: 20px 20px;
|
||||
display: inline-block;
|
||||
vertical-align: middle;
|
||||
opacity: .7;
|
||||
filter: alpha(opacity=70);
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
margin: 4px 10px 0;
|
||||
}
|
||||
</style>
|
||||
<style id="theme-options-filter"></style>
|
||||
<script>
|
||||
/* global wp */
|
||||
jQuery(function ($) {
|
||||
var $body = $("body");
|
||||
var $themeOptionsFilter = $("#theme-options-filter");
|
||||
var $wpFilterSearchInput = $("#wp-filter-search-input");
|
||||
/* global wp */
|
||||
jQuery(function($) {
|
||||
var $body = $("body");
|
||||
var $themeOptionsFilter = $("#theme-options-filter");
|
||||
var $wpFilterSearchInput = $("#wp-filter-search-input");
|
||||
|
||||
$(".filter-links a").click(function () {
|
||||
$(this).addClass("current").parent().siblings().children(".current").removeClass("current");
|
||||
$(".panel").hide();
|
||||
$($(this).attr("href")).show();
|
||||
$("#active_panel_name").val($(this).data("panel"));
|
||||
$body.removeClass("show-filters");
|
||||
return false;
|
||||
});
|
||||
|
||||
if ($wpFilterSearchInput.is(":visible")) {
|
||||
var wrap = $(".wrap");
|
||||
|
||||
$(".panel tr").each(function () {
|
||||
$(this).attr("data-searchtext", $(this).text().replace(/\r|\n|px/g, '').replace(/ +/g, ' ').replace(/^\s+|\s+$/g, '').toLowerCase());
|
||||
$(".filter-links a").click(function() {
|
||||
$(this).addClass("current").parent().siblings().children(".current").removeClass("current");
|
||||
$(".panel").hide();
|
||||
$($(this).attr("href")).show();
|
||||
$("#active_panel_name").val($(this).data("panel"));
|
||||
$body.removeClass("show-filters");
|
||||
return false;
|
||||
});
|
||||
|
||||
$wpFilterSearchInput.on("input", function () {
|
||||
var text = $(this).val().trim().toLowerCase();
|
||||
if (text) {
|
||||
wrap.addClass("searching");
|
||||
$themeOptionsFilter.text(".wrap.searching .panel tr[data-searchtext*='" + text + "']{display:block}");
|
||||
} else {
|
||||
wrap.removeClass("searching");
|
||||
$themeOptionsFilter.text("");
|
||||
}
|
||||
});
|
||||
}
|
||||
if ($wpFilterSearchInput.is(":visible")) {
|
||||
var wrap = $(".wrap");
|
||||
|
||||
$(".wrap form").submit(function(){
|
||||
$(".submit .button").prop("disabled", true);
|
||||
$(this).find(".submit .button").val("正在提交…");
|
||||
});
|
||||
$(".panel tr").each(function() {
|
||||
$(this).attr("data-searchtext", $(this).text().replace(/\r|\n|px/g, '').replace(/ +/g, ' ')
|
||||
.replace(/^\s+|\s+$/g, '').toLowerCase());
|
||||
});
|
||||
|
||||
$(".mail_test").click(function () {
|
||||
var ajax_data = { action: 'gdk_test_email' };
|
||||
$.post(ajaxurl, ajax_data,
|
||||
function(a) {
|
||||
a = $.trim(a);
|
||||
if (a == '200') {
|
||||
alert("测试成功,您的SMTP邮箱邮件发送已成功,Enjoy it");
|
||||
}else{
|
||||
alert("测试失败,您的SMTP邮箱邮件响应失败,请重试");
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$(".get_new_version").click(function () {
|
||||
$(".get_new_version").after("<span class='g-load'></span>");
|
||||
var ajax_data = { action: 'get_new_version' };
|
||||
$.get(ajaxurl, ajax_data,
|
||||
function(a) {
|
||||
a = $.trim(a);
|
||||
$(".g-load").hide();
|
||||
if (a !== '400') {
|
||||
if ($(".get_update_res").length > 0) return;
|
||||
$(".get_new_version").after(a);
|
||||
if ($(".has_new_version").length > 0) {
|
||||
$(".install_new_version").show();
|
||||
$wpFilterSearchInput.on("input", function() {
|
||||
var text = $(this).val().trim().toLowerCase();
|
||||
if (text) {
|
||||
wrap.addClass("searching");
|
||||
$themeOptionsFilter.text(".wrap.searching .panel tr[data-searchtext*='" + text +
|
||||
"']{display:block}");
|
||||
} else {
|
||||
wrap.removeClass("searching");
|
||||
$themeOptionsFilter.text("");
|
||||
}
|
||||
}else{
|
||||
$(".get_new_version").after("检测失败,网络错误");
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
$(".wrap form").submit(function() {
|
||||
$(".submit .button").prop("disabled", true);
|
||||
$(this).find(".submit .button").val("正在提交…");
|
||||
});
|
||||
|
||||
$(".mail_test").click(function() {
|
||||
var ajax_data = {
|
||||
action: 'gdk_test_email'
|
||||
};
|
||||
$.post(ajaxurl, ajax_data,
|
||||
function(a) {
|
||||
a = $.trim(a);
|
||||
if (a == '200') {
|
||||
alert("测试成功,您的SMTP邮箱邮件发送已成功,Enjoy it");
|
||||
} else {
|
||||
alert("测试失败,您的SMTP邮箱邮件响应失败,请重试");
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$(".get_new_version").click(function() {
|
||||
$(".get_new_version").after("<span class='g-load'></span>");
|
||||
var ajax_data = {
|
||||
action: 'get_new_version'
|
||||
};
|
||||
$.get(ajaxurl, ajax_data,
|
||||
function(a) {
|
||||
a = $.trim(a);
|
||||
$(".g-load").hide();
|
||||
if (a !== '400') {
|
||||
if ($(".get_update_res").length > 0) return;
|
||||
$(".get_new_version").after(a);
|
||||
if ($(".has_new_version").length > 0) {
|
||||
$(".install_new_version").show();
|
||||
}
|
||||
} else {
|
||||
$(".get_new_version").after("检测失败,网络错误");
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$(".install_new_version").click(function() {
|
||||
$(".install_new_version").after("<span class='g-load'></span>");
|
||||
var ajax_data = {
|
||||
action: 'install_new_version'
|
||||
};
|
||||
$.get(ajaxurl, ajax_data,
|
||||
function() {
|
||||
$(".g-load").hide();
|
||||
//window.location.reload();
|
||||
});
|
||||
});
|
||||
|
||||
$(".feedback-btn").click(function() {
|
||||
$(".feedback-btn").after("<span class='g-load'></span>");
|
||||
$("<link>").attr({
|
||||
rel: "stylesheet",
|
||||
type: "text/css",
|
||||
href: "https://cdn.bootcss.com/fancybox/3.0.39/jquery.fancybox.min.css"
|
||||
}).appendTo("head");
|
||||
|
||||
$.getScript("https://cdn.bootcss.com/fancybox/3.0.39/jquery.fancybox.min.js",
|
||||
function() {
|
||||
$(".g-load").hide();
|
||||
$.fancybox.open({
|
||||
src: 'https://support.qq.com/products/51158/',
|
||||
type: 'iframe',
|
||||
opts: {
|
||||
afterShow: function(instance, current) {
|
||||
console.info('done!');
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
$(".install_new_version").click(function () {
|
||||
$(".install_new_version").after("<span class='g-load'></span>");
|
||||
var ajax_data = { action: 'install_new_version' };
|
||||
$.get(ajaxurl, ajax_data,
|
||||
function() {
|
||||
$(".g-load").hide();
|
||||
//window.location.reload();
|
||||
});
|
||||
});
|
||||
|
||||
$(".feedback-btn").click(function() {
|
||||
$(".feedback-btn").after("<span class='g-load'></span>");
|
||||
$("<link>").attr({
|
||||
rel: "stylesheet",
|
||||
type: "text/css",
|
||||
href: "https://cdn.bootcss.com/fancybox/3.0.39/jquery.fancybox.min.css"
|
||||
}).appendTo("head");
|
||||
|
||||
$.getScript("https://cdn.bootcss.com/fancybox/3.0.39/jquery.fancybox.min.js",
|
||||
function() {
|
||||
$(".g-load").hide();
|
||||
$.fancybox.open({
|
||||
src: 'https://support.qq.com/products/51158/',
|
||||
type: 'iframe',
|
||||
opts: {
|
||||
afterShow: function(instance, current) {
|
||||
console.info('done!');
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
|
@ -440,21 +509,26 @@ $(".feedback-btn").click(function() {
|
|||
function gdk_add_options_page()
|
||||
{
|
||||
global $gdk_options;
|
||||
if (isset($_POST['action']) && isset($_GET['page']) && $_GET['page'] == 'gdk-options') {
|
||||
if (isset($_POST['action'], $_GET['page']) && 'gdk-options' == $_GET['page']) {
|
||||
$action = $_POST['action'];
|
||||
|
||||
switch ($action) {
|
||||
case 'update':
|
||||
$_POST['uid'] = uniqid();
|
||||
update_option('gdk_options_setup', $_POST);
|
||||
gdk_update_options();
|
||||
header('Location: admin.php?page=gdk-options&update=true&panel=' . $_POST['panel']);
|
||||
header('Location: admin.php?page=gdk-options&update=true&panel='.$_POST['panel']);
|
||||
|
||||
break;
|
||||
|
||||
case 'reset':
|
||||
delete_option('gdk_options_setup');
|
||||
gdk_update_options();
|
||||
header('Location: admin.php?page=gdk-options&reset=true&panel=' . $_POST['panel']);
|
||||
header('Location: admin.php?page=gdk-options&reset=true&panel='.$_POST['panel']);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
exit;
|
||||
}
|
||||
add_menu_page('GDK选项', 'GDK选项', 'manage_options', 'gdk-options', 'gdk_options_page', 'dashicons-buddicons-replies');
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
<?php
|
||||
/*
|
||||
*Ajax操作文件
|
||||
*/
|
||||
|
||||
// Ajax操作文件
|
||||
|
||||
/**
|
||||
* 200 ok
|
||||
* 400 fail
|
||||
* 400 fail.
|
||||
*/
|
||||
|
||||
//后台邮箱检测
|
||||
|
@ -14,9 +13,9 @@ function gdk_test_email()
|
|||
$is_error = !wp_mail('donotreply@mywpku.com', '测试发信', 'WP 积木测试发信');
|
||||
if ($is_error) {
|
||||
exit('500');
|
||||
} else {
|
||||
exit('200');
|
||||
}
|
||||
|
||||
exit('200');
|
||||
}
|
||||
add_action('wp_ajax_nopriv_gdk_test_email', 'gdk_test_email');
|
||||
add_action('wp_ajax_gdk_test_email', 'gdk_test_email');
|
||||
|
@ -30,13 +29,13 @@ function gdk_ajax_get_update()
|
|||
exit('400');
|
||||
}
|
||||
$plugin_info = json_decode($response['body'], true);
|
||||
$version = $plugin_info['version'];
|
||||
$version = $plugin_info['version'];
|
||||
|
||||
if (version_compare($version, GDK_PLUGIN_VER, '>')) {
|
||||
exit('<span class="get_update_res has_new_version">插件有更新,已安装版本:<span class="key_word">' . GDK_PLUGIN_VER . '</span> 新版本:<span class="key_word">' . $version . '</span> <a class="feedback add-new-h2" href="' . $plugin_info['details_url'] . '" target="_blank">查看更新内容</a></span>');
|
||||
} else {
|
||||
exit('<span class="get_update_res no_new_version">你的插件目前已经是最新版了!</span>');
|
||||
exit('<span class="get_update_res has_new_version">插件有更新,已安装版本:<span class="key_word">'.GDK_PLUGIN_VER.'</span> 新版本:<span class="key_word">'.$version.'</span> <a class="feedback add-new-h2" href="'.$plugin_info['details_url'].'" target="_blank">查看更新内容</a></span>');
|
||||
}
|
||||
|
||||
exit('<span class="get_update_res no_new_version">你的插件目前已经是最新版了!</span>');
|
||||
}
|
||||
add_action('wp_ajax_nopriv_get_new_version', 'gdk_ajax_get_update');
|
||||
add_action('wp_ajax_get_new_version', 'gdk_ajax_get_update');
|
||||
|
@ -45,9 +44,9 @@ add_action('wp_ajax_get_new_version', 'gdk_ajax_get_update');
|
|||
function gdk_ajax_install_update()
|
||||
{
|
||||
$url = 'http://dl.gitcafe.net/gdk.zip';
|
||||
unzip_url($url, GDK_ROOT_PATH);
|
||||
exit(1);
|
||||
gdk_unzip_url($url, GDK_ROOT_PATH);
|
||||
|
||||
exit(1);
|
||||
}
|
||||
add_action('wp_ajax_nopriv_install_new_version', 'gdk_ajax_install_update');
|
||||
add_action('wp_ajax_install_new_version', 'gdk_ajax_install_update');
|
||||
|
@ -61,29 +60,29 @@ function gdk_pasteup_imag()
|
|||
|
||||
if ($_FILES) {
|
||||
global $post;
|
||||
$post_ID = $post->ID;
|
||||
$post_ID = $post->ID;
|
||||
$wp_upload_dir = wp_upload_dir();
|
||||
$file = $_FILES['imageFile'];
|
||||
$result = array('success' => false, 'message' => 'Null');
|
||||
if (array_key_exists($file['type'], array('image/gif', 'image/jpeg', 'image/pjpeg', 'image/png'))) {
|
||||
$file = $_FILES['imageFile'];
|
||||
$result = ['success' => false, 'message' => 'Null'];
|
||||
if (array_key_exists($file['type'], ['image/gif', 'image/jpeg', 'image/pjpeg', 'image/png'])) {
|
||||
if ($file['error'] > 0) {
|
||||
$result['message'] = 'error';
|
||||
} else {
|
||||
$file_name = md5_file($file['tmp_name']) . str_replace('image/', '.', $file['type']); //img name
|
||||
$file_url = $wp_upload_dir['url'] . '/' . $file_name;
|
||||
$file_path = $wp_upload_dir['path'] . '/' . $file_name;
|
||||
$file_name = md5_file($file['tmp_name']).strtr($file['type'], ['image/' => '.']); //img name
|
||||
$file_url = $wp_upload_dir['url'].'/'.$file_name;
|
||||
$file_path = $wp_upload_dir['path'].'/'.$file_name;
|
||||
if (!file_exists($file_path)) {
|
||||
move_uploaded_file($file['tmp_name'], $file_path);
|
||||
$attachment = [
|
||||
'guid' => $wp_upload_dir['url'] . '/' . basename($file_path),
|
||||
'guid' => $wp_upload_dir['url'].'/'.basename($file_path),
|
||||
'post_mime_type' => $file['type'],
|
||||
'post_title' => $file_name,
|
||||
'post_content' => '',
|
||||
'post_status' => 'inherit',
|
||||
'post_title' => $file_name,
|
||||
'post_content' => '',
|
||||
'post_status' => 'inherit',
|
||||
];
|
||||
$attach_id = wp_insert_attachment($attachment, $file_name, $post_ID);
|
||||
//这是wp内置的上传附件的函数
|
||||
require_once ABSPATH . 'wp-admin/includes/image.php';
|
||||
require_once ABSPATH.'wp-admin/includes/image.php';
|
||||
$attach_data = wp_generate_attachment_metadata($attach_id, $file_path);
|
||||
wp_update_attachment_metadata($attach_id, $attach_data);
|
||||
}
|
||||
|
@ -93,7 +92,8 @@ function gdk_pasteup_imag()
|
|||
} else {
|
||||
$result['message'] = '400';
|
||||
}
|
||||
echo (json_encode($result));
|
||||
echo json_encode($result);
|
||||
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
@ -107,9 +107,9 @@ function gdk_pass_view()
|
|||
exit('400');
|
||||
}
|
||||
|
||||
$action = $_POST['action'];
|
||||
$post_id = $_POST['id'];
|
||||
$pass = $_POST['pass'];
|
||||
$action = esc_attr($_POST['action']);
|
||||
$post_id = esc_attr($_POST['id']);
|
||||
$pass = esc_attr($_POST['pass']);
|
||||
$wxcaptcha = wx_captcha();
|
||||
if (!isset($action) || !isset($post_id) || !isset($pass)) {
|
||||
exit('400');
|
||||
|
@ -117,9 +117,8 @@ function gdk_pass_view()
|
|||
|
||||
if ($pass == $wxcaptcha) {
|
||||
$pass_content = get_post_meta($post_id, '_pass_content')[0];
|
||||
|
||||
exit($pass_content);
|
||||
} else {
|
||||
exit('400');
|
||||
}
|
||||
}
|
||||
add_action('wp_ajax_nopriv_gdk_pass_view', 'gdk_pass_view');
|
||||
|
@ -130,7 +129,7 @@ add_action('wp_ajax_gdk_pass_view', 'gdk_pass_view');
|
|||
//在线积分充值开始
|
||||
function pay_points()
|
||||
{
|
||||
if (!isset($_POST['action']) || $_POST['action'] !== 'pay_points') {
|
||||
if (!isset($_POST['action']) || 'pay_points' !== $_POST['action']) {
|
||||
exit('400');
|
||||
}
|
||||
|
||||
|
@ -154,12 +153,12 @@ function check_pay_points()
|
|||
if (!isset($_POST['id']) || !isset($_POST['orderid'])) {
|
||||
exit('400');
|
||||
} //无脑输出400错误
|
||||
if ($_POST['action'] == 'check_pay_points') {
|
||||
if (gdk_check($_POST['orderid'], $_POST['id'])) {
|
||||
if ('check_pay_points' == $_POST['action']) {
|
||||
if (gdk_order_check($_POST['orderid'], $_POST['id'])) {
|
||||
exit('200');
|
||||
} else {
|
||||
exit('400');
|
||||
}
|
||||
|
||||
exit('400');
|
||||
}
|
||||
}
|
||||
add_action('wp_ajax_check_pay_points', 'check_pay_points');
|
||||
|
@ -170,16 +169,16 @@ add_action('wp_ajax_nopriv_check_pay_points', 'check_pay_points');
|
|||
//游客付费可见开始
|
||||
function pay_view()
|
||||
{
|
||||
if (!isset($_POST['action']) || $_POST['action'] !== 'pay_view') {
|
||||
if (!isset($_POST['action']) || 'pay_view' !== $_POST['action']) {
|
||||
exit('400');
|
||||
}
|
||||
|
||||
if (!isset($_POST['money']) || !isset($_POST['way'])) {
|
||||
exit('400');
|
||||
}
|
||||
//无脑输出400错误
|
||||
//无脑输出400错误
|
||||
if (isset($_POST['id'])) {
|
||||
payjs_action('付费查看:' . get_the_title($_POST['id']), 'PP' . $_POST['id'], $_POST['money']); //标题,文章id
|
||||
payjs_action('付费查看:'.get_the_title($_POST['id']), 'PP'.$_POST['id'], $_POST['money']); //标题,文章id
|
||||
}
|
||||
}
|
||||
add_action('wp_ajax_pay_view', 'pay_view');
|
||||
|
@ -188,23 +187,23 @@ add_action('wp_ajax_nopriv_pay_view', 'pay_view');
|
|||
//添加提取码
|
||||
function add_code()
|
||||
{
|
||||
$id = $_POST['id'];
|
||||
$id = $_POST['id'];
|
||||
$code = $_POST['code'];
|
||||
if (empty($id) || empty($code)) {
|
||||
exit('400');
|
||||
}
|
||||
|
||||
if ($_POST['action'] == 'add_code') {
|
||||
$code = trim($code); //清理一下
|
||||
if ('add_code' == $_POST['action']) {
|
||||
$code = trim($code); //清理一下
|
||||
$pay_log = get_post_meta($id, 'pay_log', true); //获取旧的购买记录数据
|
||||
add_post_meta($id, 'pay_log', $code, true) or update_post_meta($id, 'pay_log', $pay_log . ',' . $code); //没有新建,有就更新
|
||||
add_post_meta($id, 'pay_log', $code, true) or update_post_meta($id, 'pay_log', $pay_log.','.$code); //没有新建,有就更新
|
||||
$pay_log = get_post_meta($id, 'pay_log', true); //获取新的购买记录数据
|
||||
$pay_arr = explode(",", $pay_log);
|
||||
$pay_arr = explode(',', $pay_log);
|
||||
if (array_key_exists($code, $pay_arr)) {
|
||||
exit('200'); //OK
|
||||
} else {
|
||||
exit('400'); //NO
|
||||
}
|
||||
|
||||
exit('400'); //NO
|
||||
}
|
||||
}
|
||||
add_action('wp_ajax_add_code', 'add_code');
|
||||
|
@ -214,9 +213,9 @@ add_action('wp_ajax_nopriv_add_code', 'add_code');
|
|||
function check_code()
|
||||
{
|
||||
$check_code_nonce = $_POST['check_code'];
|
||||
$code = $_POST['code'];
|
||||
$action = $_POST['action'];
|
||||
$id = $_POST['id'];
|
||||
$code = $_POST['code'];
|
||||
$action = $_POST['action'];
|
||||
$id = $_POST['id'];
|
||||
if (!isset($check_code_nonce) || !wp_verify_nonce($check_code_nonce, 'check_code')) {
|
||||
exit('400');
|
||||
}
|
||||
|
@ -224,15 +223,15 @@ function check_code()
|
|||
if (empty($code) || !isset($action) || !isset($id)) {
|
||||
exit('400');
|
||||
} //无脑输出400错误
|
||||
if ($action == 'check_code') {
|
||||
$code = trim($code); //清理一下
|
||||
if ('check_code' == $action) {
|
||||
$code = trim($code); //清理一下
|
||||
$pay_log = get_post_meta($id, 'pay_log', true); //购买记录数据
|
||||
$pay_arr = explode(",", $pay_log);
|
||||
$pay_arr = explode(',', $pay_log);
|
||||
if (array_key_exists($code, $pay_arr)) {
|
||||
exit('200');
|
||||
} else {
|
||||
exit('400');
|
||||
}
|
||||
|
||||
exit('400');
|
||||
}
|
||||
}
|
||||
add_action('wp_ajax_check_code', 'check_code');
|
||||
|
@ -241,11 +240,12 @@ add_action('wp_ajax_nopriv_check_code', 'check_code');
|
|||
//获取加密内容
|
||||
function get_content()
|
||||
{
|
||||
if (!isset($_POST['action']) || $_POST['action'] !== 'get_content') {
|
||||
if (!isset($_POST['action']) || 'get_content' !== $_POST['action']) {
|
||||
exit('400');
|
||||
} //无脑输出400错误
|
||||
if (isset($_POST['id'])) {
|
||||
$pay_content = get_post_meta($_POST['id'], '_pay_content', true);
|
||||
|
||||
exit($pay_content);
|
||||
}
|
||||
}
|
||||
|
@ -262,30 +262,31 @@ function check_pay_view()
|
|||
if (!isset($_POST['id']) || !isset($_POST['orderid'])) {
|
||||
exit('400');
|
||||
} //无脑输出400错误
|
||||
if ($_POST['action'] == 'check_pay_view') {
|
||||
$sid = get_transient('PP' . $_POST['id']);
|
||||
if ('check_pay_view' == $_POST['action']) {
|
||||
$sid = get_transient('PP'.$_POST['id']);
|
||||
if (in_string($sid, 'E20') && $_POST['orderid'] == $sid) {
|
||||
exit('200'); //OK
|
||||
} else {
|
||||
exit('400'); //no
|
||||
}
|
||||
|
||||
exit('400'); //no
|
||||
}
|
||||
}
|
||||
add_action('wp_ajax_check_pay_view', 'check_pay_view');
|
||||
add_action('wp_ajax_nopriv_check_pay_view', 'check_pay_view');
|
||||
|
||||
/**END */
|
||||
// END
|
||||
|
||||
//开始微信登陆
|
||||
//ajax生成登录二维码
|
||||
function gdk_weauth_qr_gen()
|
||||
{
|
||||
if (isset($_POST['action']) && $_POST['action'] == 'gdk_weauth_qr_gen') {
|
||||
if (isset($_POST['action']) && 'gdk_weauth_qr_gen' == $_POST['action']) {
|
||||
$rest = implode('|', gdk_weauth_qr());
|
||||
|
||||
exit($rest);
|
||||
} else {
|
||||
exit('400');
|
||||
}
|
||||
|
||||
exit('400');
|
||||
}
|
||||
add_action('wp_ajax_gdk_weauth_qr_gen', 'gdk_weauth_qr_gen');
|
||||
add_action('wp_ajax_nopriv_gdk_weauth_qr_gen', 'gdk_weauth_qr_gen');
|
||||
|
@ -297,12 +298,12 @@ function gdk_weauth_check()
|
|||
exit('400');
|
||||
}
|
||||
|
||||
if (!in_string($_POST['key'], '@') || $_POST['action'] !== 'gdk_weauth_check') {
|
||||
if (!in_string($_POST['key'], '@') || 'gdk_weauth_check' !== $_POST['action']) {
|
||||
exit('400');
|
||||
}
|
||||
|
||||
$sk = substr(trim($_POST['key']), -12); //sk
|
||||
$user_info = get_transient($sk . '-info'); //user_info
|
||||
$sk = substr(trim($_POST['key']), -12); //sk
|
||||
$user_info = get_transient($sk.'-info'); //user_info
|
||||
if (!empty($user_info)) {
|
||||
exit($user_info); //user_info
|
||||
}
|
||||
|
@ -313,21 +314,22 @@ add_action('wp_ajax_nopriv_gdk_weauth_check', 'gdk_weauth_check');
|
|||
//开始自动登陆
|
||||
function gdk_auto_login()
|
||||
{
|
||||
if (!isset($_POST['data']) || $_POST['action'] !== 'gdk_auto_login') {
|
||||
if (!isset($_POST['data']) || 'gdk_auto_login' !== $_POST['action']) {
|
||||
exit('400');
|
||||
}
|
||||
|
||||
$mail = $_POST['email'] ?? '';
|
||||
$mail = $_POST['email'] ?? '';
|
||||
$userdata = gdk_str2arr($_POST['data'], '|');
|
||||
$user_id = create_user_id($userdata);
|
||||
$user_id = create_user_id($userdata);
|
||||
if (is_numeric($user_id) && $user_id) {
|
||||
$user = get_user_by('id', $user_id);
|
||||
wp_set_current_user($user_id, $user->user_login);
|
||||
wp_set_auth_cookie($user_id, true);
|
||||
do_action('wp_login', $user->user_login);
|
||||
if ($mail && !empty($mail) && is_email($mail)) {
|
||||
wp_update_user(array('ID' => $user_id, 'user_email' => $mail)); //绑定邮箱
|
||||
wp_update_user(['ID' => $user_id, 'user_email' => $mail]); //绑定邮箱
|
||||
}
|
||||
|
||||
exit('200');
|
||||
}
|
||||
}
|
||||
|
@ -338,7 +340,7 @@ add_action('wp_ajax_nopriv_gdk_auto_login', 'gdk_auto_login');
|
|||
function gdk_bind_email_check()
|
||||
{
|
||||
$mail = isset($_POST['email']) ? $_POST['email'] : false;
|
||||
if ($mail && $_POST['action'] == 'bind_email_check') {
|
||||
if ($mail && 'bind_email_check' == $_POST['action']) {
|
||||
$user_id = email_exists($email);
|
||||
if ($user_id) {
|
||||
exit('200');
|
||||
|
@ -351,21 +353,22 @@ add_action('wp_ajax_nopriv_bind_email_check', 'gdk_bind_email_check');
|
|||
//积分支付
|
||||
function point_buy()
|
||||
{
|
||||
if (isset($_POST['point']) && isset($_POST['userid']) && isset($_POST['id']) && $_POST['action'] == 'gdk_pay_buy') {
|
||||
if (isset($_POST['point'], $_POST['userid'], $_POST['id']) && 'gdk_pay_buy' == $_POST['action']) {
|
||||
$all = GDK_Points::get_user_total_points($_POST['userid'], 'accepted');
|
||||
if( $all < $_POST['point']){
|
||||
if ($all < $_POST['point']) {
|
||||
exit;
|
||||
}else{
|
||||
GDK_Points::set_points(-$_POST['point'],
|
||||
}
|
||||
GDK_Points::set_points(
|
||||
-$_POST['point'],
|
||||
$_POST['userid'],
|
||||
array(
|
||||
[
|
||||
'description' => $_POST['id'],
|
||||
'status' => 'accepted',
|
||||
)
|
||||
'status' => 'accepted',
|
||||
]
|
||||
); //扣除金币
|
||||
$pay_content = get_post_meta($_POST['id'], '_point_content', true);
|
||||
|
||||
exit($pay_content);
|
||||
}
|
||||
}
|
||||
}
|
||||
add_action('wp_ajax_gdk_pay_buy', 'point_buy');
|
||||
|
@ -374,29 +377,28 @@ add_action('wp_ajax_nopriv_gdk_pay_buy', 'point_buy');
|
|||
//ajax 表单
|
||||
function msg_form()
|
||||
{
|
||||
if (empty($_POST['mail']) || empty($_POST['msg_content']) || $_POST['action'] !== 'msg_submit' || !wp_verify_nonce($_POST['msg_nonce'], 'msg_nonce')) {
|
||||
if (empty($_POST['mail']) || empty($_POST['msg_content']) || 'msg_submit' !== $_POST['action'] || !wp_verify_nonce($_POST['msg_nonce'], 'msg_nonce')) {
|
||||
exit('400');
|
||||
}
|
||||
if (!is_email($_POST['mail'])) {
|
||||
exit('403');
|
||||
}
|
||||
|
||||
|
||||
$msg = array(
|
||||
'post_title' => '【来自' . $_POST['mail'] . '留言】',
|
||||
'post_author' => 1,
|
||||
$msg = [
|
||||
'post_title' => '【来自'.$_POST['mail'].'留言】',
|
||||
'post_author' => 1,
|
||||
'post_content' => $_POST['msg_content'].'
|
||||
|
||||
回复邮件:' . $_POST['mail'],
|
||||
);
|
||||
回复邮件:'.$_POST['mail'],
|
||||
];
|
||||
|
||||
wp_mail(get_bloginfo('admin_email'), $msg['post_title'], $msg['post_content']);
|
||||
wp_mail(get_bloginfo('admin_email'), $msg['post_title'], $msg['post_content']);
|
||||
|
||||
if ('1' !== $_POST['only_mail']) {
|
||||
wp_insert_post($msg);
|
||||
}
|
||||
|
||||
if($_POST['only_mail'] !== '1'){
|
||||
wp_insert_post($msg);
|
||||
}
|
||||
exit('200');
|
||||
|
||||
}
|
||||
add_action('wp_ajax_msg_submit', 'msg_form');
|
||||
add_action('wp_ajax_nopriv_msg_submit', 'msg_form');
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,5 +1,8 @@
|
|||
<?php
|
||||
if (!defined('ABSPATH')) {exit;}
|
||||
|
||||
if (!defined('ABSPATH')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
if (gdk_option('gdk_cdn')) {
|
||||
add_action('wp_loaded', 'gdk_cdn_start');
|
||||
|
@ -19,23 +22,25 @@ if (gdk_option('gdk_cdn_water')) {
|
|||
//CDN水印
|
||||
|
||||
//文章首尾添加自定义内容
|
||||
function gdk_add_content($content) {
|
||||
if(is_single()) {
|
||||
$before = gdk_option('gdk_artical_top');
|
||||
$after = gdk_option('gdk_artical_bottom');
|
||||
if(!empty($before) && !empty($after)) {
|
||||
return $before . '<br>' . $content . '<br>' . $after;
|
||||
}elseif(!empty($before)) {
|
||||
return $before . '<br>' . $content;
|
||||
}elseif(!empty($after)) {
|
||||
return $content . '<br>' . $after;
|
||||
}else{
|
||||
return $content;
|
||||
}
|
||||
function gdk_add_content($content)
|
||||
{
|
||||
if (is_single()) {
|
||||
$before = gdk_option('gdk_artical_top');
|
||||
$after = gdk_option('gdk_artical_bottom');
|
||||
if (!empty($before) && !empty($after)) {
|
||||
return $before.'<br>'.$content.'<br>'.$after;
|
||||
}
|
||||
if (!empty($before)) {
|
||||
return $before.'<br>'.$content;
|
||||
}
|
||||
if (!empty($after)) {
|
||||
return $content.'<br>'.$after;
|
||||
}
|
||||
|
||||
}else{
|
||||
return $content;
|
||||
}
|
||||
return $content;
|
||||
}
|
||||
|
||||
return $content;
|
||||
}
|
||||
add_filter('the_content', 'gdk_add_content');
|
||||
|
||||
|
@ -44,18 +49,19 @@ function get_weauth_oauth()
|
|||
{
|
||||
if (in_string($_SERVER['REQUEST_URI'], 'weauth')) {
|
||||
$weauth_user = isset($_GET['user']) ? sanitize_text_field($_GET['user']) : false; //weauth发来用户信息
|
||||
$weauth_sk = isset($_GET['sk']) ? sanitize_text_field($_GET['sk']) : false; //weauth返回的12位sk信息
|
||||
$weauth_res = get_transient($weauth_sk . '-OK');
|
||||
if (empty($weauth_res) && $weauth_res !== 1) {
|
||||
$weauth_sk = isset($_GET['sk']) ? sanitize_text_field($_GET['sk']) : false; //weauth返回的12位sk信息
|
||||
$weauth_res = get_transient($weauth_sk.'-OK');
|
||||
if (empty($weauth_res) && 1 !== $weauth_res) {
|
||||
return;
|
||||
}
|
||||
|
||||
$weauth_user = stripslashes($weauth_user);
|
||||
$weauth_user = json_decode($weauth_user, true);
|
||||
$weauth_user = stripslashes($weauth_user);
|
||||
$weauth_user = json_decode($weauth_user, true);
|
||||
$oauth_result = implode('|', $weauth_user);
|
||||
set_transient($weauth_sk . '-info', $oauth_result, 60); //1分钟缓存
|
||||
set_transient($weauth_sk.'-info', $oauth_result, 60); //1分钟缓存
|
||||
header('goauth: ok');
|
||||
echo 'success'; //给对方服务器打个招呼
|
||||
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
@ -66,11 +72,11 @@ function gdk_wx_avatar($avatar, $id_or_email, $size, $default, $alt)
|
|||
{
|
||||
$user = false;
|
||||
if (is_numeric($id_or_email)) {
|
||||
$id = (int)$id_or_email;
|
||||
$id = (int) $id_or_email;
|
||||
$user = get_user_by('id', $id);
|
||||
} elseif (is_object($id_or_email)) {
|
||||
if (!empty($id_or_email->user_id)) {
|
||||
$id = (int)$id_or_email->user_id;
|
||||
$id = (int) $id_or_email->user_id;
|
||||
$user = get_user_by('id', $id);
|
||||
}
|
||||
} else {
|
||||
|
@ -82,6 +88,7 @@ function gdk_wx_avatar($avatar, $id_or_email, $size, $default, $alt)
|
|||
$avatar = "<img alt='{$alt}' src='{$avatar}' class='avatar avatar-{$size} photo' height='{$size}' width='{$size}' />";
|
||||
}
|
||||
}
|
||||
|
||||
return $avatar;
|
||||
}
|
||||
add_filter('get_avatar', 'gdk_wx_avatar', 19, 5);
|
||||
|
@ -91,18 +98,25 @@ function gdk_switch_get_avatar($avatar)
|
|||
{
|
||||
switch (gdk_option('gdk_switch_get_avatar')) {
|
||||
case 1:
|
||||
$rand_avatar = 'https://cdn.jsdelivr.net/gh/yunluo/GitCafeApi/avatar/' . mt_rand(1, 1999) . '.jpg';
|
||||
$avatar = "<img src=\"$rand_avatar\" class='avatar rand_avatar photo' />";
|
||||
$rand_avatar = 'https://cdn.jsdelivr.net/gh/yunluo/GitCafeApi/avatar/'.mt_rand(1, 1999).'.jpg';
|
||||
$avatar = "<img src=\"{$rand_avatar}\" class='avatar rand_avatar photo' />";
|
||||
|
||||
break;
|
||||
|
||||
case 2:
|
||||
$avatar = preg_replace("/http[s]{0,1}:\/\/(secure|www|\d).gravatar.com\/avatar\//", "//cdn.v2ex.com/gravatar/", $avatar);
|
||||
$avatar = preg_replace('/http[s]{0,1}:\\/\\/(secure|www|\\d).gravatar.com\\/avatar\\//', '//cdn.v2ex.com/gravatar/', $avatar);
|
||||
|
||||
break;
|
||||
|
||||
case 3:
|
||||
$avatar = preg_replace("/http[s]{0,1}:\/\/(secure|www|\d).gravatar.com\/avatar\//", "//dn-qiniu-avatar.qbox.me/avatar/", $avatar);
|
||||
$avatar = preg_replace('/http[s]{0,1}:\\/\\/(secure|www|\\d).gravatar.com\\/avatar\\//', '//dn-qiniu-avatar.qbox.me/avatar/', $avatar);
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
$avatar = preg_replace("/http[s]{0,1}:\/\/(secure|www|\d).gravatar.com\/avatar\//", "//cravatar.cn/avatar/", $avatar);
|
||||
$avatar = preg_replace('/http[s]{0,1}:\\/\\/(secure|www|\\d).gravatar.com\\/avatar\\//', '//cravatar.cn/avatar/', $avatar);
|
||||
}
|
||||
|
||||
return $avatar;
|
||||
}
|
||||
add_filter('get_avatar', 'gdk_switch_get_avatar');
|
||||
|
@ -111,12 +125,13 @@ add_filter('get_avatar', 'gdk_switch_get_avatar');
|
|||
if (gdk_option('gdk_lazyload')) {
|
||||
function gdk_lazyload($content)
|
||||
{
|
||||
if (get_post_type() != 'post') {
|
||||
return $content;
|
||||
}
|
||||
if ('post' != get_post_type()) {
|
||||
return $content;
|
||||
}
|
||||
if (!is_feed() || !is_robots()) {
|
||||
$content = preg_replace('/<img(.+)src=[\'"]([^\'"]+)[\'"](.*)>/i', "<img\$1data-original=\"\$2\" \$3>\n<noscript>\$0</noscript>", $content);
|
||||
}
|
||||
|
||||
return $content;
|
||||
}
|
||||
add_filter('the_content', 'gdk_lazyload');
|
||||
|
@ -125,11 +140,11 @@ if (gdk_option('gdk_lazyload')) {
|
|||
//强制兼容<pre>,和下面转义代码搭配使用
|
||||
function gdk_prettify_replace($text)
|
||||
{
|
||||
$replace = array(
|
||||
$replace = [
|
||||
'<pre>' => '<pre class="prettyprint linenums">',
|
||||
);
|
||||
$text = str_replace(array_keys($replace), $replace, $text);
|
||||
return $text;
|
||||
];
|
||||
|
||||
return strtr($text, $replace);
|
||||
}
|
||||
add_filter('content_save_pre', 'gdk_prettify_replace');
|
||||
add_filter('the_content', 'gdk_prettify_replace');
|
||||
|
@ -138,15 +153,17 @@ add_filter('the_content', 'gdk_prettify_replace');
|
|||
function gdk_esc_html($content)
|
||||
{
|
||||
$regex = '/(<pre\s+[^>]*?class\s*?=\s*?[",\'].*?prettyprint.*?[",\'].*?>)(.*?)(<\/pre>)/sim';
|
||||
|
||||
return preg_replace_callback($regex, 'gdk_esc_callback', $content);
|
||||
}
|
||||
function gdk_esc_callback($matches)
|
||||
{
|
||||
$tag_open = $matches[1];
|
||||
$content = $matches[2];
|
||||
$tag_open = $matches[1];
|
||||
$content = $matches[2];
|
||||
$tag_close = $matches[3];
|
||||
$content = esc_html($content);
|
||||
return $tag_open . $content . $tag_close;
|
||||
$content = esc_html($content);
|
||||
|
||||
return $tag_open.$content.$tag_close;
|
||||
}
|
||||
add_filter('the_content', 'gdk_esc_html', 2);
|
||||
add_filter('comment_text', 'gdk_esc_html', 2);
|
||||
|
@ -155,10 +172,10 @@ add_filter('comment_text', 'gdk_esc_html', 2);
|
|||
if (gdk_option('gdk_lazyload')) {
|
||||
function gdk_fancybox($content)
|
||||
{
|
||||
$pattern = "/<a(.*?)href=('|\")([^>]*).(bmp|gif|jpeg|jpg|png|swf)('|\")(.*?)>(.*?)<\\/a>/i";
|
||||
$pattern = "/<a(.*?)href=('|\")([^>]*).(bmp|gif|jpeg|jpg|png|swf)('|\")(.*?)>(.*?)<\\/a>/i";
|
||||
$replacement = '<a$1href=$2$3.$4$5 data-fancybox="gallery" rel="box" class="fancybox"$6>$7</a>';
|
||||
$content = preg_replace($pattern, $replacement, $content);
|
||||
return $content;
|
||||
|
||||
return preg_replace($pattern, $replacement, $content);
|
||||
}
|
||||
add_filter('the_content', 'gdk_fancybox');
|
||||
}
|
||||
|
@ -170,23 +187,24 @@ function gdk_link_go($content)
|
|||
if ($matches) {
|
||||
foreach ($matches[2] as $val) {
|
||||
if (in_string($val, '://') && !in_string($val, home_url()) && !preg_match('/\.(jpg|jepg|png|ico|bmp|gif|zip|rar|tiff)/i', $val) && !preg_match('/(ed2k|thunder|Flashget|flashget|qqdl):\/\//i', $val)) {
|
||||
$content = str_replace("href=\"$val\"", "href=\"" . home_url() . "?go=$val\" ", $content);
|
||||
$content = str_replace("href=\"{$val}\"", 'href="'.home_url()."?go={$val}\" ", $content);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
//邮箱SMTP设置
|
||||
function gdk_smtp($phpmailer)
|
||||
{
|
||||
$phpmailer->FromName = gdk_option('gdk_smtp_username'); //昵称
|
||||
$phpmailer->Host = gdk_option('gdk_smtp_host'); //服务器地址
|
||||
$phpmailer->Port = gdk_option('gdk_smtp_port'); //端口
|
||||
$phpmailer->Username = gdk_option('gdk_smtp_mail'); //邮箱地址
|
||||
$phpmailer->Password = gdk_option('gdk_smtp_password'); //密码
|
||||
$phpmailer->From = gdk_option('gdk_smtp_mail'); //邮箱地址
|
||||
$phpmailer->SMTPAuth = true;
|
||||
$phpmailer->FromName = gdk_option('gdk_smtp_username'); //昵称
|
||||
$phpmailer->Host = gdk_option('gdk_smtp_host'); //服务器地址
|
||||
$phpmailer->Port = gdk_option('gdk_smtp_port'); //端口
|
||||
$phpmailer->Username = gdk_option('gdk_smtp_mail'); //邮箱地址
|
||||
$phpmailer->Password = gdk_option('gdk_smtp_password'); //密码
|
||||
$phpmailer->From = gdk_option('gdk_smtp_mail'); //邮箱地址
|
||||
$phpmailer->SMTPAuth = true;
|
||||
$phpmailer->SMTPSecure = 'ssl';
|
||||
$phpmailer->IsSMTP();
|
||||
}
|
||||
|
@ -199,28 +217,30 @@ function gdk_cdn_start()
|
|||
function gdk_cdn_replace($html)
|
||||
{
|
||||
$local_host = home_url(); //博客域名
|
||||
$cdn_host = gdk_option('gdk_cdn_host'); //cdn域名
|
||||
$cdn_exts = gdk_option('gdk_cdn_ext'); //扩展名(使用|分隔)
|
||||
$cdn_dirs = gdk_option('gdk_cdn_dir'); //目录(使用|分隔)
|
||||
$cdn_dirs = str_replace('-', '\-', $cdn_dirs);
|
||||
if ($cdn_dirs) {
|
||||
$regex = '/' . str_replace('/', '\/', $local_host) . '\/((' . $cdn_dirs . ')\/[^\s\?\\\'\"\;\>\<]{1,}.(' . $cdn_exts . '))([\"\\\'\s\?]{1})/';
|
||||
$html = preg_replace($regex, $cdn_host . '/$1$4', $html);
|
||||
$cdn_host = gdk_option('gdk_cdn_host'); //cdn域名
|
||||
$cdn_exts = gdk_option('gdk_cdn_ext'); //扩展名(使用|分隔)
|
||||
$cdn_dirs = gdk_option('gdk_cdn_dir'); //目录(使用|分隔)
|
||||
$cdn_dirs = str_replace('-', '\-', $cdn_dirs);
|
||||
if (isset( $cdn_dirs)) {
|
||||
$regex = '/'.str_replace('/', '\/', $local_host).'\/(('.$cdn_dirs.')\/[^\s\?\\\'\"\;\>\<]{1,}.('.$cdn_exts.'))([\"\\\'\s\?]{1})/';
|
||||
$html = preg_replace($regex, $cdn_host.'/$1$4', $html);
|
||||
} else {
|
||||
$regex = '/' . str_replace('/', '\/', $local_host) . '\/([^\s\?\\\'\"\;\>\<]{1,}.(' . $cdn_exts . '))([\"\\\'\s\?]{1})/';
|
||||
$html = preg_replace($regex, $cdn_host . '/$1$3', $html);
|
||||
$regex = '/'.str_replace('/', '\/', $local_host).'\/([^\s\?\\\'\"\;\>\<]{1,}.('.$cdn_exts.'))([\"\\\'\s\?]{1})/';
|
||||
$html = preg_replace($regex, $cdn_host.'/$1$3', $html);
|
||||
}
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
//CDN水印
|
||||
function gdk_cdn_water($content)
|
||||
{
|
||||
if (get_post_type() == 'post') {
|
||||
$pattern = "/<img(.*?)src=('|\")(.*?).(bmp|gif|jpeg|jpg|png)('|\")(.*?)>/i";
|
||||
if ('post' == get_post_type()) {
|
||||
$pattern = "/<img(.*?)src=('|\")(.*?).(bmp|gif|jpeg|jpg|png)('|\")(.*?)>/i";
|
||||
$replacement = '<img$1src=$2$3.$4!water.jpg$5$6>';
|
||||
$content = preg_replace($pattern, $replacement, $content);
|
||||
$content = preg_replace($pattern, $replacement, $content);
|
||||
}
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
|
@ -230,48 +250,50 @@ if (gdk_option('gdk_compress')) {
|
|||
{
|
||||
function gdk_compress_html_callback($buffer)
|
||||
{
|
||||
if (substr(ltrim($buffer), 0, 5) == '<?xml') {
|
||||
if ('<?xml' == substr(ltrim($buffer), 0, 5)) {
|
||||
return $buffer;
|
||||
}
|
||||
|
||||
$initial = strlen($buffer);
|
||||
$buffer = explode("<!--wp-compress-html-->", $buffer);
|
||||
$count = count($buffer);
|
||||
$i = '';
|
||||
for ($i = 0; $i <= $count; $i++) {
|
||||
$buffer = explode('<!--wp-compress-html-->', $buffer);
|
||||
$count = count($buffer);
|
||||
$i = '';
|
||||
for ($i = 0; $i <= $count; ++$i) {
|
||||
if (stristr($buffer[$i], '<!--wp-compress-html no compression-->')) {
|
||||
$buffer[$i] = str_replace("<!--wp-compress-html no compression-->", " ", $buffer[$i]);
|
||||
$buffer[$i] = str_replace('<!--wp-compress-html no compression-->', ' ', $buffer[$i]);
|
||||
} else {
|
||||
$buffer[$i] = str_replace("\t", " ", $buffer[$i]);
|
||||
$buffer[$i] = str_replace("\t", ' ', $buffer[$i]);
|
||||
$buffer[$i] = str_replace("\n\n", "\n", $buffer[$i]);
|
||||
$buffer[$i] = str_replace("\n", "", $buffer[$i]);
|
||||
$buffer[$i] = str_replace("\r", "", $buffer[$i]);
|
||||
$buffer[$i] = str_replace("\n", '', $buffer[$i]);
|
||||
$buffer[$i] = str_replace("\r", '', $buffer[$i]);
|
||||
while (stristr($buffer[$i], ' ')) {
|
||||
$buffer[$i] = str_replace(" ", " ", $buffer[$i]);
|
||||
$buffer[$i] = str_replace(' ', ' ', $buffer[$i]);
|
||||
}
|
||||
}
|
||||
$buffer_out .= $buffer[$i];
|
||||
}
|
||||
$final = strlen($buffer_out);
|
||||
if ($initial !== 0) {
|
||||
if (0 !== $initial) {
|
||||
$savings = ($initial - $final) / $initial * 100;
|
||||
} else {
|
||||
$savings = 0;
|
||||
}
|
||||
$savings = round($savings, 2);
|
||||
$buffer_out .= "\n<!--压缩前的大小: {$initial} bytes; 压缩后的大小: {$final} bytes; 节约:{$savings}% -->";
|
||||
|
||||
return $buffer_out;
|
||||
}
|
||||
ob_start("gdk_compress_html_callback");
|
||||
ob_start('gdk_compress_html_callback');
|
||||
}
|
||||
add_action('get_header', 'gdk_compress_html');
|
||||
|
||||
function gdk_unCompress($content)
|
||||
{
|
||||
if (preg_match_all('/(crayon-|<?xml|script|textarea|<\\/pre>)/i', $content, $matches)) {
|
||||
$content = '<!--wp-compress-html--><!--wp-compress-html no compression-->' . $content;
|
||||
$content = '<!--wp-compress-html--><!--wp-compress-html no compression-->'.$content;
|
||||
$content .= '<!--wp-compress-html no compression--><!--wp-compress-html-->';
|
||||
}
|
||||
|
||||
return $content;
|
||||
}
|
||||
add_filter('the_content', 'gdk_unCompress');
|
||||
|
@ -282,17 +304,18 @@ function gdk_search_by_title($search, $wp_query)
|
|||
{
|
||||
if (!empty($search) && !empty($wp_query->query_vars['search_terms'])) {
|
||||
global $wpdb;
|
||||
$q = $wp_query->query_vars;
|
||||
$n = !empty($q['exact']) ? '' : '%';
|
||||
$search = array();
|
||||
foreach ((array)$q['search_terms'] as $term) {
|
||||
$search[] = $wpdb->prepare("{$wpdb->posts}.post_title LIKE %s", $n . $wpdb->esc_like($term) . $n);
|
||||
$q = $wp_query->query_vars;
|
||||
$n = !empty($q['exact']) ? '' : '%';
|
||||
$search = [];
|
||||
foreach ((array) $q['search_terms'] as $term) {
|
||||
$search[] = $wpdb->prepare("{$wpdb->posts}.post_title LIKE %s", $n.$wpdb->esc_like($term).$n);
|
||||
}
|
||||
if (!is_user_logged_in()) {
|
||||
$search[] = "{$wpdb->posts}.post_password = ''";
|
||||
}
|
||||
$search = ' AND ' . implode(' AND ', $search);
|
||||
$search = ' AND '.implode(' AND ', $search);
|
||||
}
|
||||
|
||||
return $search;
|
||||
}
|
||||
add_filter('posts_search', 'gdk_search_by_title', 10, 2);
|
||||
|
@ -308,6 +331,7 @@ function gdk_comment_author($query_vars)
|
|||
unset($query_vars['author_name']);
|
||||
}
|
||||
}
|
||||
|
||||
return $query_vars;
|
||||
}
|
||||
add_filter('request', 'gdk_comment_author');
|
||||
|
@ -315,34 +339,34 @@ add_filter('request', 'gdk_comment_author');
|
|||
function gdk_comment_author_link($link, $author_id, $author_nicename)
|
||||
{
|
||||
$my_name = get_user_meta($author_id, 'first_name', true);
|
||||
if ($my_name) {
|
||||
$link = str_replace($author_nicename, $my_name, $link);
|
||||
if (isset($my_name)) {
|
||||
$link = strtr($link, [$author_nicename => $my_name]);
|
||||
}
|
||||
|
||||
return $link;
|
||||
}
|
||||
add_filter('author_link', 'gdk_comment_author_link', 10, 3);
|
||||
|
||||
function weauth_page_activate()
|
||||
function gdk_weauth_page_activate()
|
||||
{
|
||||
$awesome_page_id = get_option('weixin_page_id');
|
||||
if (!$awesome_page_id) {
|
||||
$post = array(
|
||||
'post_title' => '微信登录', //这里是自动生成页面的页面标题
|
||||
'post_content' => '[gdk_login_btn]', //这里是页面的内容
|
||||
'post_status' => 'publish',
|
||||
'post_type' => 'page',
|
||||
'post_name' => 'weixin',
|
||||
);
|
||||
$post = [
|
||||
'post_title' => '微信登录', //这里是自动生成页面的页面标题
|
||||
'post_content' => '[gdk_login_btn]', //这里是页面的内容
|
||||
'post_status' => 'publish',
|
||||
'post_type' => 'page',
|
||||
'post_name' => 'weixin',
|
||||
];
|
||||
$postID = wp_insert_post($post);
|
||||
update_post_meta($postID, '_wp_page_template', ''); //这里是生成页面的模板类型
|
||||
update_option('weixin_page_id', $postID);
|
||||
}
|
||||
|
||||
}
|
||||
add_action('admin_init', 'weauth_page_activate');
|
||||
add_action('admin_init', 'gdk_weauth_page_activate');
|
||||
|
||||
//强制微信登录
|
||||
function force_weauth_login_url($login_url, $redirect, $force_reauth)
|
||||
function gdk_force_weauth_login_url($login_url, $redirect, $force_reauth)
|
||||
{
|
||||
$login_url = get_permalink(get_option('weixin_page_id'));
|
||||
if (!empty($redirect)) {
|
||||
|
@ -351,45 +375,43 @@ function force_weauth_login_url($login_url, $redirect, $force_reauth)
|
|||
if ($force_reauth) {
|
||||
$login_url = add_query_arg('reauth', '1', $login_url);
|
||||
}
|
||||
|
||||
return $login_url;
|
||||
}
|
||||
|
||||
function change_my_register_url($url)
|
||||
function gdk_change_register_url($url)
|
||||
{
|
||||
if (is_admin()) {
|
||||
return $url;
|
||||
}
|
||||
|
||||
return wp_login_url();
|
||||
}
|
||||
|
||||
if (gdk_option('gdk_weauth_oauth') && gdk_option('gdk_weauth_force')) {
|
||||
add_filter('login_url', 'force_weauth_login_url', 10, 3);
|
||||
add_filter('register_url', 'change_my_register_url');
|
||||
add_filter('login_url', 'gdk_force_weauth_login_url', 10, 3);
|
||||
add_filter('register_url', 'gdk_change_register_url');
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 清除文章相关的缓存
|
||||
* 清除文章相关的缓存.
|
||||
*/
|
||||
function gdk_clear_post_cache()
|
||||
{
|
||||
delete_transient('gdk-sitemap');
|
||||
delete_transient('gdk-sitemap-html');
|
||||
}
|
||||
add_action('save_post', 'gdk_clear_post_cache' );
|
||||
add_action('deleted_post', 'gdk_clear_post_cache' );
|
||||
add_action('save_post', 'gdk_clear_post_cache');
|
||||
add_action('deleted_post', 'gdk_clear_post_cache');
|
||||
add_action('publish_post', 'gdk_clear_post_cache');
|
||||
add_action('publish_page', 'gdk_clear_post_cache');
|
||||
add_action('save_post', 'gdk_clear_post_cache');
|
||||
|
||||
/**
|
||||
* 清除链接缓存
|
||||
* 清除链接缓存.
|
||||
*/
|
||||
function gdk_clear_link_cache()
|
||||
{
|
||||
delete_transient('gdk-daohang-html');
|
||||
}
|
||||
add_action('edit_link', 'gdk_clear_link_cache' );
|
||||
add_action('add_link', 'gdk_clear_link_cache' );
|
||||
add_action('set_object_terms', 'gdk_clear_link_cache');
|
||||
add_action('edit_link', 'gdk_clear_link_cache');
|
||||
add_action('add_link', 'gdk_clear_link_cache');
|
||||
|
|
|
@ -1,68 +1,44 @@
|
|||
<?php
|
||||
|
||||
//SMTP邮箱设置
|
||||
/*
|
||||
if (gdk_option('gdk_mailsmtp_b')) {
|
||||
function googlo_mail_smtp($phpmailer) {
|
||||
$phpmailer->From = gdk_option('gdk_maildizhi_b'); //发件人地址
|
||||
$phpmailer->FromName = gdk_option('gdk_mailnichen_b'); //发件人昵称
|
||||
$phpmailer->Host = gdk_option('gdk_mailsmtp_b'); //SMTP服务器地址
|
||||
$phpmailer->Port = gdk_option('gdk_mailport_b'); //SMTP邮件发送端口
|
||||
if (gdk_option('gdk_smtpssl_b')) {
|
||||
$phpmailer->SMTPSecure = 'ssl';
|
||||
} else {
|
||||
$phpmailer->SMTPSecure = '';
|
||||
} //SMTP加密方式(SSL/TLS)没有为空即可
|
||||
$phpmailer->Username = gdk_option('gdk_mailuser_b'); //邮箱帐号
|
||||
$phpmailer->Password = gdk_option('gdk_mailpass_b'); //邮箱密码
|
||||
$phpmailer->IsSMTP();
|
||||
$phpmailer->SMTPAuth = true; //启用SMTPAuth服务
|
||||
|
||||
}
|
||||
add_action('phpmailer_init', 'googlo_mail_smtp');
|
||||
}
|
||||
*/
|
||||
//修改默认发信地址
|
||||
function deel_res_from_email($email)
|
||||
function gdk_from_email($email)
|
||||
{
|
||||
$wp_from_email = get_option('admin_email');
|
||||
return $wp_from_email;
|
||||
return get_option('admin_email');
|
||||
}
|
||||
function deel_res_from_name($email)
|
||||
function gdk_from_name($email)
|
||||
{
|
||||
$wp_from_name = get_option('blogname');
|
||||
return $wp_from_name;
|
||||
return get_option('blogname');
|
||||
}
|
||||
add_filter('wp_mail_from', 'deel_res_from_email');
|
||||
add_filter('wp_mail_from_name', 'deel_res_from_name');
|
||||
add_filter('wp_mail_from', 'gdk_from_email');
|
||||
add_filter('wp_mail_from_name', 'gdk_from_name');
|
||||
|
||||
//评论回应邮件通知
|
||||
function comment_mail_notify($comment_id)
|
||||
{
|
||||
$admin_notify = '0'; // admin 要不要收回复通知 ( '1'=要 ; '0'=不要 )
|
||||
$admin_email = get_bloginfo('admin_email'); // $admin_email 可改为你指定的 e-mail.
|
||||
$comment = get_comment($comment_id);
|
||||
$admin_notify = '0'; // admin 要不要收回复通知 ( '1'=要 ; '0'=不要 )
|
||||
$admin_email = get_bloginfo('admin_email'); // $admin_email 可改为你指定的 e-mail.
|
||||
$comment = get_comment($comment_id);
|
||||
$comment_author_email = trim($comment->comment_author_email);
|
||||
$parent_id = $comment->comment_parent ? $comment->comment_parent : '';
|
||||
$blogname = get_option("blogname");
|
||||
$parent_id = $comment->comment_parent ? $comment->comment_parent : '';
|
||||
$blogname = get_option('blogname');
|
||||
global $wpdb;
|
||||
if ($wpdb->query("Describe {$wpdb->comments} comment_mail_notify") == '') {
|
||||
if ('' == $wpdb->query("Describe {$wpdb->comments} comment_mail_notify")) {
|
||||
$wpdb->query("ALTER TABLE {$wpdb->comments} ADD COLUMN comment_mail_notify TINYINT NOT NULL DEFAULT 0;");
|
||||
}
|
||||
|
||||
if (($comment_author_email != $admin_email && isset($_POST['comment_mail_notify'])) || ($comment_author_email == $admin_email && $admin_notify == '1')) {
|
||||
$wpdb->query("UPDATE {$wpdb->comments} SET comment_mail_notify='1' WHERE comment_ID='$comment_id'");
|
||||
if (($comment_author_email != $admin_email && isset($_POST['comment_mail_notify'])) || ($comment_author_email == $admin_email && '1' == $admin_notify)) {
|
||||
$wpdb->query("UPDATE {$wpdb->comments} SET comment_mail_notify='1' WHERE comment_ID='{$comment_id}'");
|
||||
}
|
||||
|
||||
$notify = $parent_id ? get_comment($parent_id)->comment_mail_notify : '0';
|
||||
$notify = $parent_id ? get_comment($parent_id)->comment_mail_notify : '0';
|
||||
$spam_confirmed = $comment->comment_approved;
|
||||
if ($parent_id != '' && $spam_confirmed != 'spam' && $notify == '1') {
|
||||
$wp_email = 'no-reply@' . preg_replace('#^www\.#', '', strtolower($_SERVER['SERVER_NAME'])); // e-mail 发出点, no-reply 可改为可用的 e-mail.
|
||||
$to = trim(get_comment($parent_id)->comment_author_email);
|
||||
$subject = 'Hi,您在 [' . get_option("blogname") . '] 的留言有人回复啦!';
|
||||
$message = '<div style="color:#555;font:12px/1.5 微软雅黑,Tahoma,Helvetica,Arial,sans-serif;width:650px;margin:50px auto;border-top: none;box-shadow:0 0px 3px #aaaaaa;" ><table border="0" cellspacing="0" cellpadding="0"><tbody><tr valign="top" height="2"><td valign="top"><div style="background-color:white;border-top:2px solid #12ADDB;line-padding:0 15px 12px;width:650px;color:#555555;font-family:微软雅黑, Arial;;font-size:12px;"><h2 style="border-bottom:1px solid #DDD;font-size:14px;font-weight:normal;padding:8px 0 10px 8px;"><span style="color: #12ADDB;font-weight: bold;">> </span>您在 <a style="text-decoration:none; color:#58B5F5;font-weight:600;" target="_blank" href="' . home_url() . '">' . $blogname . '</a> 网站上的留言有回复啦!</h2><div style="padding:0 12px 0 12px;margin-top:18px"><p>您好, ' . trim(get_comment($parent_id)->comment_author) . '! 您发表在文章 <a style="text-decoration:none;" target="_blank" href="' . get_the_permalink($comment->comment_post_ID) . '">《' . get_the_title($comment->comment_post_ID) . '》</a> 的评论:</p><p style="background-color: #EEE;border: 1px solid #DDD;padding: 20px;margin: 15px 0;">' . nl2br(strip_tags(get_comment($parent_id)->comment_content)) . '</p><p>' . trim($comment->comment_author) . ' 给您的回复如下:</p><p style="background-color: #EEE;border: 1px solid #DDD;padding: 20px;margin: 15px 0;">' . nl2br(strip_tags($comment->comment_content)) . '</p><p>您可以点击 <a style="text-decoration:none; color:#5692BC" target="_blank" href="' . htmlspecialchars(get_comment_link($parent_id)) . '">这里查看回复的完整內容</a>,也欢迎再次光临 <a style="text-decoration:none; color:#5692BC" target="_blank" href="' . home_url() . '">' . $blogname . '</a>。祝您天天开心,欢迎下次访问 <a style="text-decoration:none; color:#5692BC" target="_blank" href="' . home_url() . '">' . $blogname . '</a>!谢谢。</p><p style="float:right;">(此邮件由系统自动发出, 请勿回复)</p></div></div></td></tr></tbody></table><div style="color:#fff;background-color: #12ADDB;text-align : center;height:35px;padding-top:15px">Copyright © 2013-2018 ' . $blogname . '</div></div>';
|
||||
$from = "From: \"" . get_option('blogname') . "\" <$wp_email>";
|
||||
$headers = "$from\nContent-Type: text/html; charset=" . get_option('blog_charset') . "\n";
|
||||
if ('' != $parent_id && 'spam' != $spam_confirmed && '1' == $notify) {
|
||||
$wp_email = 'no-reply@'.preg_replace('#^www\.#', '', strtolower($_SERVER['SERVER_NAME'])); // e-mail 发出点, no-reply 可改为可用的 e-mail.
|
||||
$to = trim(get_comment($parent_id)->comment_author_email);
|
||||
$subject = 'Hi,您在 ['.get_option('blogname').'] 的留言有人回复啦!';
|
||||
$message = '<div style="color:#555;font:12px/1.5 微软雅黑,Tahoma,Helvetica,Arial,sans-serif;width:650px;margin:50px auto;border-top: none;box-shadow:0 0px 3px #aaaaaa;" ><table border="0" cellspacing="0" cellpadding="0"><tbody><tr valign="top" height="2"><td valign="top"><div style="background-color:white;border-top:2px solid #12ADDB;line-padding:0 15px 12px;width:650px;color:#555555;font-family:微软雅黑, Arial;;font-size:12px;"><h2 style="border-bottom:1px solid #DDD;font-size:14px;font-weight:normal;padding:8px 0 10px 8px;"><span style="color: #12ADDB;font-weight: bold;">> </span>您在 <a style="text-decoration:none; color:#58B5F5;font-weight:600;" target="_blank" href="'.home_url().'">'.$blogname.'</a> 网站上的留言有回复啦!</h2><div style="padding:0 12px 0 12px;margin-top:18px"><p>您好, '.trim(get_comment($parent_id)->comment_author).'! 您发表在文章 <a style="text-decoration:none;" target="_blank" href="'.get_the_permalink($comment->comment_post_ID).'">《'.get_the_title($comment->comment_post_ID).'》</a> 的评论:</p><p style="background-color: #EEE;border: 1px solid #DDD;padding: 20px;margin: 15px 0;">'.nl2br(strip_tags(get_comment($parent_id)->comment_content)).'</p><p>'.trim($comment->comment_author).' 给您的回复如下:</p><p style="background-color: #EEE;border: 1px solid #DDD;padding: 20px;margin: 15px 0;">'.nl2br(strip_tags($comment->comment_content)).'</p><p>您可以点击 <a style="text-decoration:none; color:#5692BC" target="_blank" href="'.htmlspecialchars(get_comment_link($parent_id)).'">这里查看回复的完整內容</a>,也欢迎再次光临 <a style="text-decoration:none; color:#5692BC" target="_blank" href="'.home_url().'">'.$blogname.'</a>。祝您天天开心,欢迎下次访问 <a style="text-decoration:none; color:#5692BC" target="_blank" href="'.home_url().'">'.$blogname.'</a>!谢谢。</p><p style="float:right;">(此邮件由系统自动发出, 请勿回复)</p></div></div></td></tr></tbody></table><div style="color:#fff;background-color: #12ADDB;text-align : center;height:35px;padding-top:15px">Copyright © 2013-2018 '.$blogname.'</div></div>';
|
||||
$from = 'From: "'.get_option('blogname')."\" <{$wp_email}>";
|
||||
$headers = "{$from}\nContent-Type: text/html; charset=".get_option('blog_charset')."\n";
|
||||
wp_mail($to, $subject, $message, $headers);
|
||||
}
|
||||
}
|
||||
|
@ -72,7 +48,8 @@ add_action('comment_post', 'comment_mail_notify');
|
|||
function gdk_notify_postauthor($notify_message, $comment_ID)
|
||||
{
|
||||
$notify = $notify_message;
|
||||
$notify .= '快速回复此评论: ' . admin_url("edit-comments.php") . '#comment-' . $comment_ID;
|
||||
$notify .= '快速回复此评论: '.admin_url('edit-comments.php').'#comment-'.$comment_ID;
|
||||
|
||||
return $notify;
|
||||
}
|
||||
add_filter('comment_notification_text', 'gdk_notify_postauthor', 10, 2);
|
||||
|
@ -81,12 +58,12 @@ add_filter('comment_notification_text', 'gdk_notify_postauthor', 10, 2);
|
|||
|
||||
function gdk_register_mail($user_id)
|
||||
{
|
||||
$user = get_user_by('id', $user_id);
|
||||
$user = get_user_by('id', $user_id);
|
||||
$user_pass = $_POST['password'];
|
||||
$blogname = get_option('blogname');
|
||||
$message = '<div class="emailcontent" style="width:100%;max-width:720px;text-align:left;margin:0 auto;padding-top:80px;padding-bottom:20px"><div class="emailtitle"><h1 style="color:#fff;background:#51a0e3;line-height:70px;font-size:24px;font-weight:400;padding-left:40px;margin:0">注册成功通知</h1><div class="emailtext" style="background:#fff;padding:20px 32px 20px"><div style="padding:0;font-weight:700;color:#6e6e6e;font-size:16px">尊敬的' . $user->user_login . ',您好!</div><p style="color:#6e6e6e;font-size:13px;line-height:24px">欢迎您注册[' . $blogname . '],下面是您的账号信息,请妥善保管!</p><table cellpadding="0" cellspacing="0" border="0" style="width:100%;border-top:1px solid #eee;border-left:1px solid #eee;color:#6e6e6e;font-size:16px;font-weight:normal"><thead><tr><th colspan="2" style="padding:10px 0;border-right:1px solid #eee;border-bottom:1px solid #eee;text-align:center;background:#f8f8f8">您的详细注册信息</th></tr></thead><tbody><tr><td style="padding:10px 0;border-right:1px solid #eee;border-bottom:1px solid #eee;text-align:center;width:100px">登录邮箱</td><td style="padding:10px 20px 10px 30px;border-right:1px solid #eee;border-bottom:1px solid #eee;line-height:30px">' . $user->user_email . '</td></tr><tr><td style="padding:10px 0;border-right:1px solid #eee;border-bottom:1px solid #eee;text-align:center">登录密码</td><td style="padding:10px 20px 10px 30px;border-right:1px solid #eee;border-bottom:1px solid #eee;line-height:30px">' . $user_pass . '</td></tr></tbody></table><p style="color:#6e6e6e;font-size:13px;line-height:24px">如果您的账号有异常,请您在第一时间和我们取得联系哦,联系邮箱:' . get_bloginfo('admin_email') . '</p></div><div class="emailad" style="margin-top:4px"><a href="' . home_url() . '"><img src="http://reg.163.com/images/secmail/adv.png" alt="" style="margin:auto;width:100%;max-width:700px;height:auto"></a></div></div></div>';
|
||||
$headers = "Content-Type:text/html;charset=UTF-8\n";
|
||||
wp_mail($user->user_email, '[' . $blogname . ']欢迎注册' . $blogname, $message, $headers);
|
||||
$blogname = get_option('blogname');
|
||||
$message = '<div class="emailcontent" style="width:100%;max-width:720px;text-align:left;margin:0 auto;padding-top:80px;padding-bottom:20px"><div class="emailtitle"><h1 style="color:#fff;background:#51a0e3;line-height:70px;font-size:24px;font-weight:400;padding-left:40px;margin:0">注册成功通知</h1><div class="emailtext" style="background:#fff;padding:20px 32px 20px"><div style="padding:0;font-weight:700;color:#6e6e6e;font-size:16px">尊敬的'.$user->user_login.',您好!</div><p style="color:#6e6e6e;font-size:13px;line-height:24px">欢迎您注册['.$blogname.'],下面是您的账号信息,请妥善保管!</p><table cellpadding="0" cellspacing="0" border="0" style="width:100%;border-top:1px solid #eee;border-left:1px solid #eee;color:#6e6e6e;font-size:16px;font-weight:normal"><thead><tr><th colspan="2" style="padding:10px 0;border-right:1px solid #eee;border-bottom:1px solid #eee;text-align:center;background:#f8f8f8">您的详细注册信息</th></tr></thead><tbody><tr><td style="padding:10px 0;border-right:1px solid #eee;border-bottom:1px solid #eee;text-align:center;width:100px">登录邮箱</td><td style="padding:10px 20px 10px 30px;border-right:1px solid #eee;border-bottom:1px solid #eee;line-height:30px">'.$user->user_email.'</td></tr><tr><td style="padding:10px 0;border-right:1px solid #eee;border-bottom:1px solid #eee;text-align:center">登录密码</td><td style="padding:10px 20px 10px 30px;border-right:1px solid #eee;border-bottom:1px solid #eee;line-height:30px">'.$user_pass.'</td></tr></tbody></table><p style="color:#6e6e6e;font-size:13px;line-height:24px">如果您的账号有异常,请您在第一时间和我们取得联系哦,联系邮箱:'.get_bloginfo('admin_email').'</p></div><div class="emailad" style="margin-top:4px"><a href="'.home_url().'"><img src="http://reg.163.com/images/secmail/adv.png" alt="" style="margin:auto;width:100%;max-width:700px;height:auto"></a></div></div></div>';
|
||||
$headers = "Content-Type:text/html;charset=UTF-8\n";
|
||||
wp_mail($user->user_email, '['.$blogname.']欢迎注册'.$blogname, $message, $headers);
|
||||
}
|
||||
add_action('user_register', 'gdk_register_mail');
|
||||
|
||||
|
@ -96,12 +73,12 @@ function gdk_login_failed_notify()
|
|||
{
|
||||
date_default_timezone_set('PRC');
|
||||
$admin_email = get_bloginfo('admin_email');
|
||||
$to = $admin_email;
|
||||
$subject = '您的网站登录错误警告';
|
||||
$message = '<p>您好!您的网站(' . get_option("blogname") . ')有登录错误!</p>' . '<p>请确定是您自己的登录失误,以防别人攻击!登录信息如下:</p>' . '<p>登录名:' . $_POST['log'] . '</p>' . '<p>登录密码:' . $_POST['pwd'] . '</p>' . '<p>登录时间:' . date("Y-m-d H:i:s") . '</p>' . '<p>登录IP:' . $_SERVER['REMOTE_ADDR'] . '</p>' . '<p style="float:right">————本邮件由系统发送,无需回复</p>';
|
||||
$wp_email = 'no-reply@' . preg_replace('#^www\.#', '', strtolower($_SERVER['SERVER_NAME']));
|
||||
$from = "From: \"" . get_option('blogname') . "\" <$wp_email>";
|
||||
$headers = "$from\nContent-Type: text/html; charset=" . get_option('blog_charset') . "\n";
|
||||
$to = $admin_email;
|
||||
$subject = '您的网站登录错误警告';
|
||||
$message = '<p>您好!您的网站('.get_option('blogname').')有登录错误!</p>'.'<p>请确定是您自己的登录失误,以防别人攻击!登录信息如下:</p>'.'<p>登录名:'.$_POST['log'].'</p>'.'<p>登录密码:'.$_POST['pwd'].'</p>'.'<p>登录时间:'.date('Y-m-d H:i:s').'</p>'.'<p>登录IP:'.$_SERVER['REMOTE_ADDR'].'</p>'.'<p style="float:right">————本邮件由系统发送,无需回复</p>';
|
||||
$wp_email = 'no-reply@'.preg_replace('#^www\.#', '', strtolower($_SERVER['SERVER_NAME']));
|
||||
$from = 'From: "'.get_option('blogname')."\" <{$wp_email}>";
|
||||
$headers = "{$from}\nContent-Type: text/html; charset=".get_option('blog_charset')."\n";
|
||||
wp_mail($to, $subject, $message, $headers);
|
||||
}
|
||||
add_action('wp_login_failed', 'gdk_login_failed_notify');
|
||||
|
|
|
@ -1,16 +1,25 @@
|
|||
<?php
|
||||
|
||||
include 'rewrite.php'; //路由重写
|
||||
|
||||
include 'Common.php'; //通用代码
|
||||
|
||||
include 'Ajax.php'; //Ajax服务
|
||||
|
||||
include 'optimization.php'; //优化措施
|
||||
|
||||
include 'advanced.php'; //高级功能
|
||||
|
||||
include 'security.php'; //安全功能
|
||||
|
||||
include 'shortcode.php'; //短代码
|
||||
|
||||
include 'seo.php'; //seo功能
|
||||
|
||||
include 'user.php'; //用户功能
|
||||
|
||||
include GDK_ROOT_PATH . 'public/download.php'; //单页下载
|
||||
include GDK_ROOT_PATH . 'public/go.php'; //跳转中间页
|
||||
include GDK_ROOT_PATH . 'public/daohang.php'; //导航页面
|
||||
include GDK_ROOT_PATH.'public/download.php'; //单页下载
|
||||
|
||||
include GDK_ROOT_PATH.'public/go.php'; //跳转中间页
|
||||
|
||||
include GDK_ROOT_PATH.'public/daohang.php'; //导航页面
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
function gdk_feed_disabled()
|
||||
{
|
||||
wp_die('Feed已经关闭, 请访问网站<a href="' . get_bloginfo('url') . '">首页</a>!');
|
||||
wp_die('Feed已经关闭, 请访问网站<a href="'.get_bloginfo('url').'">首页</a>!');
|
||||
}
|
||||
|
||||
add_action('do_feed', 'gdk_feed_disabled', 1);
|
||||
|
@ -28,13 +28,12 @@ function gdk_disable_srcset_img()
|
|||
}
|
||||
add_filter('max_srcset_image_width', 'gdk_disable_srcset_img');
|
||||
|
||||
add_filter( 'big_image_size_threshold', '__return_false' );
|
||||
add_filter('big_image_size_threshold', '__return_false');
|
||||
|
||||
//移除默认的图片宽度以及高度
|
||||
function gdk_remove_img_width($html)
|
||||
{
|
||||
$html = preg_replace('/(width|height)=\"\d*\"\s/', "", $html);
|
||||
return $html;
|
||||
return preg_replace('/(width|height)=\"\d*\"\s/', '', $html);
|
||||
}
|
||||
add_filter('post_thumbnail_html', 'gdk_remove_img_width', 10);
|
||||
add_filter('image_send_to_editor', 'gdk_remove_img_width', 10);
|
||||
|
@ -60,11 +59,12 @@ function gdk_disable_attachment_pages()
|
|||
if (is_attachment()) {
|
||||
if (!empty($post->post_parent)) {
|
||||
wp_redirect(get_permalink($post->post_parent), 301);
|
||||
exit;
|
||||
} else {
|
||||
wp_redirect(home_url());
|
||||
|
||||
exit;
|
||||
}
|
||||
wp_redirect(home_url());
|
||||
|
||||
exit;
|
||||
}
|
||||
}
|
||||
add_action('template_redirect', 'gdk_disable_attachment_pages', 1);
|
||||
|
@ -95,8 +95,8 @@ if (gdk_option('gdk_auto_space')) {
|
|||
function gdk_auto_space($data)
|
||||
{
|
||||
$data = preg_replace('/([\\x{4e00}-\\x{9fa5}]+)([A-Za-z0-9_]+)/u', '${1} ${2}', $data);
|
||||
$data = preg_replace('/([A-Za-z0-9_]+)([\\x{4e00}-\\x{9fa5}]+)/u', '${1} ${2}', $data);
|
||||
return $data;
|
||||
|
||||
return preg_replace('/([A-Za-z0-9_]+)([\\x{4e00}-\\x{9fa5}]+)/u', '${1} ${2}', $data);
|
||||
}
|
||||
add_filter('the_content', 'gdk_auto_space');
|
||||
}
|
||||
|
@ -116,11 +116,11 @@ function gdk_after_init_theme()
|
|||
update_option('thumbnail_size_h', '0'); //关闭默认缩略图
|
||||
update_option('default_ping_status', 'closed'); //关闭默认ping状态
|
||||
update_option('comment_order', 'desc'); //关闭默认评论显示顺序
|
||||
if (get_option('permalink_structure') == '' || define('GDK_HTML_LINK', true)) { //如果是默认连接格式或者主题声明 define( 'GDK_HTML_LINK', true );
|
||||
if ('' == get_option('permalink_structure') || define('GDK_HTML_LINK', true)) { //如果是默认连接格式或者主题声明 define( 'GDK_HTML_LINK', true );
|
||||
update_option('permalink_structure', '/archives/%post_id%.html'); //固定链接格式
|
||||
}
|
||||
if (gdk_option('gdk_diasble_widgets_block')){ //如果
|
||||
remove_theme_support( 'widgets-block-editor' ); //禁用新版小工具
|
||||
if (gdk_option('gdk_diasble_widgets_block')) { //如果
|
||||
remove_theme_support('widgets-block-editor'); //禁用新版小工具
|
||||
}
|
||||
update_option('posts_per_page', '30'); //每页文章数目
|
||||
}
|
||||
|
@ -129,7 +129,7 @@ add_action('after_setup_theme', 'gdk_after_init_theme');
|
|||
//新标签打开顶部网站链接
|
||||
function gdk_blank_site_bar($wp_admin_bar)
|
||||
{
|
||||
$node = $wp_admin_bar->get_node('view-site');
|
||||
$node = $wp_admin_bar->get_node('view-site');
|
||||
$node->meta['target'] = '_blank';
|
||||
$wp_admin_bar->add_node($node);
|
||||
}
|
||||
|
@ -138,7 +138,7 @@ add_action('admin_bar_menu', 'gdk_blank_site_bar', 80);
|
|||
//移除 WP_Head 无关紧要的代码
|
||||
if (gdk_option('gdk_diasble_head_useless')) {
|
||||
remove_action('wp_head', 'wp_generator'); //删除 head 中的 WP 版本号
|
||||
foreach (array('rss2_head', 'commentsrss2_head', 'rss_head', 'rdf_header', 'atom_head', 'comments_atom_head', 'opml_head', 'app_head') as $action) {
|
||||
foreach (['rss2_head', 'commentsrss2_head', 'rss_head', 'rdf_header', 'atom_head', 'comments_atom_head', 'opml_head', 'app_head'] as $action) {
|
||||
remove_action($action, 'the_generator');
|
||||
}
|
||||
|
||||
|
@ -167,8 +167,7 @@ add_action('in_admin_header', function () {
|
|||
//清理菜单类
|
||||
add_filter('nav_menu_css_class', function ($var) {
|
||||
return is_array($var) ? array_intersect($var, ['current-menu-item', 'menu-item', 'menu-item-has-children']) : '';
|
||||
}
|
||||
, 100, 1);
|
||||
}, 100, 1);
|
||||
|
||||
//移除前台加载jquery-migrate
|
||||
function gdk_disable_migrate($scripts)
|
||||
|
@ -183,12 +182,12 @@ function gdk_disable_migrate($scripts)
|
|||
add_action('wp_default_scripts', 'gdk_disable_migrate');
|
||||
|
||||
//移除 WordPress 标记
|
||||
add_filter('the_generator', function () {return '';});
|
||||
add_filter('the_generator', function () {return ''; });
|
||||
|
||||
//移除标题中的空字符
|
||||
add_filter('wp_title', function ($title) {return trim($title);});
|
||||
add_filter('wp_title', function ($title) {return trim($title); });
|
||||
|
||||
/** 开始关闭WordPress更新 **/
|
||||
// 开始关闭WordPress更新
|
||||
if (gdk_option('gdk_diasble_wp_update')) {
|
||||
add_filter('automatic_updater_disabled', '__return_true'); // 彻底关闭自动更新
|
||||
remove_action('init', 'wp_schedule_update_checks'); // 关闭更新检查定时作业
|
||||
|
@ -205,9 +204,9 @@ if (gdk_option('gdk_diasble_wp_update')) {
|
|||
remove_action('load-update.php', 'wp_update_themes');
|
||||
remove_action('load-update-core.php', 'wp_update_themes');
|
||||
remove_action('admin_init', '_maybe_update_themes');
|
||||
add_filter('pre_site_transient_update_core', function () {return null;});
|
||||
add_filter('pre_site_transient_update_plugins', function () {return null;});
|
||||
add_filter('pre_site_transient_update_themes', function () {return null;});
|
||||
add_filter('pre_site_transient_update_core', function () {return null; });
|
||||
add_filter('pre_site_transient_update_plugins', function () {return null; });
|
||||
add_filter('pre_site_transient_update_themes', function () {return null; });
|
||||
}
|
||||
|
||||
add_action('wp_before_admin_bar_render', function () {
|
||||
|
@ -244,8 +243,10 @@ function ds_disable_core_privacy_tools($caps, $cap)
|
|||
case 'erase_others_personal_data':
|
||||
case 'manage_privacy_options':
|
||||
$caps[] = 'do_not_allow';
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
return $caps;
|
||||
}
|
||||
|
||||
|
@ -255,6 +256,7 @@ function gdk_remove_dns($hints, $relation_type)
|
|||
if ('dns-prefetch' === $relation_type) {
|
||||
return array_diff(wp_dependencies_unique_hosts(), $hints);
|
||||
}
|
||||
|
||||
return $hints;
|
||||
}
|
||||
add_filter('wp_resource_hints', 'gdk_remove_dns', 10, 2);
|
||||
|
@ -277,10 +279,10 @@ if (gdk_option('gdk_disable_emojis')) {
|
|||
function gdk_disable_emojis_tinymce($plugins)
|
||||
{
|
||||
if (is_array($plugins)) {
|
||||
return array_diff($plugins, array('wpemoji'));
|
||||
return array_diff($plugins, ['wpemoji']);
|
||||
}
|
||||
|
||||
return array();
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -305,16 +307,18 @@ if (!defined('WP_POST_REVISIONS')) {
|
|||
|
||||
//前台禁用dashicon和editor
|
||||
if (gdk_option('gdk_disable_dashicons')) {
|
||||
add_action('init', function () {
|
||||
if (!is_user_logged_in()) {
|
||||
wp_deregister_style('dashicons');
|
||||
wp_register_style('dashicons', false);
|
||||
wp_enqueue_style('dashicons', '');
|
||||
wp_deregister_style('editor-buttons');
|
||||
wp_register_style('editor-buttons', false);
|
||||
wp_enqueue_style('editor-buttons', '');
|
||||
add_action(
|
||||
'init',
|
||||
function () {
|
||||
if (!is_user_logged_in()) {
|
||||
wp_deregister_style('dashicons');
|
||||
wp_register_style('dashicons', false);
|
||||
wp_enqueue_style('dashicons', '');
|
||||
wp_deregister_style('editor-buttons');
|
||||
wp_register_style('editor-buttons', false);
|
||||
wp_enqueue_style('editor-buttons', '');
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -329,15 +333,18 @@ add_action('wp_dashboard_setup', 'gdk_dweandw_remove', 20);
|
|||
|
||||
//国内更新WordPress加速
|
||||
if (gdk_option('gdk_porxy_update') && !gdk_option('gdk_diasble_wp_update')) {
|
||||
add_filter('site_transient_update_core', function ($value) {
|
||||
foreach ($value->updates as &$update) {
|
||||
if ($update->locale == 'zh_CN') {
|
||||
$update->download = 'http://cn.wp101.net/latest-zh_CN.zip';
|
||||
$update->packages->full = 'http://cn.wp101.net/latest-zh_CN.zip';
|
||||
add_filter(
|
||||
'site_transient_update_core',
|
||||
function ($value) {
|
||||
foreach ($value->updates as &$update) {
|
||||
if ('zh_CN' == $update->locale) {
|
||||
$update->download = 'http://cn.wp101.net/latest-zh_CN.zip';
|
||||
$update->packages->full = 'http://cn.wp101.net/latest-zh_CN.zip';
|
||||
}
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -345,14 +352,15 @@ if (gdk_option('gdk_porxy_update') && !gdk_option('gdk_diasble_wp_update')) {
|
|||
if (gdk_option('gdk_upload_rename')) {
|
||||
function gdk_upload_rename($file)
|
||||
{
|
||||
$info = pathinfo($file['name']);
|
||||
$ext = $info['extension'];
|
||||
$info = pathinfo($file['name']);
|
||||
$ext = $info['extension'];
|
||||
$ignore_exts = ['zip', 'rar', '7z'];
|
||||
//被忽略的文件格式
|
||||
if (!array_key_exists($ext, $ignore_exts)) {
|
||||
$filedate = date('YmdHis') . mt_rand(100, 999);
|
||||
$file['name'] = $filedate . '.' . $ext;
|
||||
$filedate = date('YmdHis').mt_rand(100, 999);
|
||||
$file['name'] = $filedate.'.'.$ext;
|
||||
}
|
||||
|
||||
return $file;
|
||||
}
|
||||
add_filter('wp_handle_upload_prefilter', 'gdk_upload_rename');
|
||||
|
@ -361,12 +369,12 @@ if (gdk_option('gdk_upload_rename')) {
|
|||
// 禁用自动生成的图片尺寸
|
||||
function gdk_disable_image_sizes($sizes)
|
||||
{
|
||||
unset($sizes['thumbnail']); // disable thumbnail size
|
||||
unset($sizes['medium']); // disable medium size
|
||||
unset($sizes['large']); // disable large size
|
||||
unset($sizes['medium_large']); // disable medium-large size
|
||||
unset($sizes['1536x1536']); // disable 2x medium-large size
|
||||
unset($sizes['2048x2048']); // disable 2x large size
|
||||
unset($sizes['thumbnail'], $sizes['medium'], $sizes['large'], $sizes['medium_large'], $sizes['1536x1536'], $sizes['2048x2048']); // disable thumbnail size
|
||||
// disable medium size
|
||||
// disable large size
|
||||
// disable medium-large size
|
||||
// disable 2x medium-large size
|
||||
// disable 2x large size
|
||||
return $sizes;
|
||||
}
|
||||
add_action('intermediate_image_sizes_advanced', 'gdk_disable_image_sizes');
|
||||
|
@ -385,8 +393,9 @@ function gdk_redirect_single_search_result()
|
|||
{
|
||||
if (is_search()) {
|
||||
global $wp_query;
|
||||
if ($wp_query->post_count == 1) {
|
||||
if (1 == $wp_query->post_count) {
|
||||
wp_redirect(get_permalink($wp_query->posts['0']->ID));
|
||||
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
@ -397,7 +406,8 @@ add_action('template_redirect', 'gdk_redirect_single_search_result');
|
|||
function gdk_redirect_search()
|
||||
{
|
||||
if (is_search() && !empty($_GET['s'])) {
|
||||
wp_redirect(home_url("/search/") . urlencode(get_query_var('s')));
|
||||
wp_redirect(home_url('/search/').urlencode(get_query_var('s')));
|
||||
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
@ -420,7 +430,7 @@ if (gdk_option('gdk_disable_restapi')) {
|
|||
status_header(405);
|
||||
wp_die('{"code":"rest_api_disabled","message":"REST API services are disabled on this site.","data":{"status":405}}');
|
||||
}
|
||||
// Remove the REST API endpoint.
|
||||
// Remove the REST API endpoint.
|
||||
remove_action('rest_api_init', 'wp_oembed_register_route');
|
||||
}
|
||||
|
||||
|
@ -449,76 +459,80 @@ function gdk_custom_footer_code()
|
|||
add_action('wp_footer', 'gdk_custom_footer_code', 400);
|
||||
|
||||
if (gdk_option('gdk_no_category')) {
|
||||
if (!function_exists('gdk_no_category_base_refresh_rules')):
|
||||
if (!function_exists('gdk_no_category_base_refresh_rules')) {
|
||||
add_action('load-themes.php', 'gdk_no_category_base_refresh_rules');
|
||||
add_action('created_category', 'gdk_no_category_base_refresh_rules');
|
||||
add_action('edited_category', 'gdk_no_category_base_refresh_rules');
|
||||
add_action('delete_category', 'gdk_no_category_base_refresh_rules');
|
||||
function gdk_no_category_base_refresh_rules()
|
||||
{
|
||||
{
|
||||
global $wp_rewrite;
|
||||
$wp_rewrite->flush_rules();
|
||||
}
|
||||
add_action('init', 'gdk_no_category_base_permastruct');
|
||||
function gdk_no_category_base_permastruct()
|
||||
{
|
||||
{
|
||||
global $wp_rewrite;
|
||||
$wp_rewrite->extra_permastructs['category']['struct'] = '%category%';
|
||||
}
|
||||
// Add our custom category rewrite rules
|
||||
add_filter('category_rewrite_rules', 'gdk_no_category_base_rewrite_rules');
|
||||
function gdk_no_category_base_rewrite_rules($category_rewrite)
|
||||
{
|
||||
{
|
||||
//var_dump($category_rewrite); // For Debugging
|
||||
$category_rewrite = array();
|
||||
$categories = get_categories(array('hide_empty' => false));
|
||||
$category_rewrite = [];
|
||||
$categories = get_categories(['hide_empty' => false]);
|
||||
foreach ($categories as $category) {
|
||||
$gdk_category = $category->slug;
|
||||
if ($category->parent == $category->cat_ID) // recursive recursion
|
||||
{
|
||||
if ($category->parent == $category->cat_ID) { // recursive recursion
|
||||
$category->parent = 0;
|
||||
} elseif ($category->parent != 0) {
|
||||
$gdk_category = get_category_parents($category->parent, false, '/', true) . $gdk_category;
|
||||
} elseif (0 != $category->parent) {
|
||||
$gdk_category = get_category_parents($category->parent, false, '/', true).$gdk_category;
|
||||
}
|
||||
|
||||
$category_rewrite['('.$gdk_category.')/(?:feed/)?(feed|rdf|rss|rss2|atom)/?$'] = 'index.php?category_name=$matches[1]&feed=$matches[2]';
|
||||
$category_rewrite['('.$gdk_category.')/page/?([0-9]{1,})/?$'] = 'index.php?category_name=$matches[1]&paged=$matches[2]';
|
||||
$category_rewrite['('.$gdk_category.')/?$'] = 'index.php?category_name=$matches[1]';
|
||||
}
|
||||
// Redirect support from Old Category Base
|
||||
global $wp_rewrite;
|
||||
$old_category_base = get_option('category_base') ? get_option('category_base') : 'category';
|
||||
$old_category_base = trim($old_category_base, '/');
|
||||
$category_rewrite[$old_category_base.'/(.*)$'] = 'index.php?category_redirect=$matches[1]';
|
||||
|
||||
return $category_rewrite;
|
||||
}
|
||||
// Add 'category_redirect' query variable
|
||||
add_filter('query_vars', 'gdk_no_category_base_query_vars');
|
||||
function gdk_no_category_base_query_vars($public_query_vars)
|
||||
{
|
||||
$public_query_vars[] = 'category_redirect';
|
||||
|
||||
return $public_query_vars;
|
||||
}
|
||||
|
||||
add_filter('request', 'gdk_no_category_base_request');
|
||||
function gdk_no_category_base_request($query_vars)
|
||||
{
|
||||
if (isset($query_vars['category_redirect'])) {
|
||||
$catlink = trailingslashit(get_option('home')).user_trailingslashit($query_vars['category_redirect'], 'category');
|
||||
status_header(301);
|
||||
header("Location: {$catlink}");
|
||||
|
||||
exit();
|
||||
}
|
||||
|
||||
$category_rewrite['(' . $gdk_category . ')/(?:feed/)?(feed|rdf|rss|rss2|atom)/?$'] = 'index.php?category_name=$matches[1]&feed=$matches[2]';
|
||||
$category_rewrite['(' . $gdk_category . ')/page/?([0-9]{1,})/?$'] = 'index.php?category_name=$matches[1]&paged=$matches[2]';
|
||||
$category_rewrite['(' . $gdk_category . ')/?$'] = 'index.php?category_name=$matches[1]';
|
||||
return $query_vars;
|
||||
}
|
||||
// Redirect support from Old Category Base
|
||||
global $wp_rewrite;
|
||||
$old_category_base = get_option('category_base') ? get_option('category_base') : 'category';
|
||||
$old_category_base = trim($old_category_base, '/');
|
||||
$category_rewrite[$old_category_base . '/(.*)$'] = 'index.php?category_redirect=$matches[1]';
|
||||
return $category_rewrite;
|
||||
}
|
||||
// Add 'category_redirect' query variable
|
||||
add_filter('query_vars', 'gdk_no_category_base_query_vars');
|
||||
function gdk_no_category_base_query_vars($public_query_vars)
|
||||
{
|
||||
$public_query_vars[] = 'category_redirect';
|
||||
return $public_query_vars;
|
||||
}
|
||||
|
||||
add_filter('request', 'gdk_no_category_base_request');
|
||||
function gdk_no_category_base_request($query_vars)
|
||||
{
|
||||
if (isset($query_vars['category_redirect'])) {
|
||||
$catlink = trailingslashit(get_option('home')) . user_trailingslashit($query_vars['category_redirect'], 'category');
|
||||
status_header(301);
|
||||
header("Location: $catlink");
|
||||
exit();
|
||||
}
|
||||
return $query_vars;
|
||||
}
|
||||
endif;
|
||||
}
|
||||
|
||||
//站长评论邮件添加评论链接
|
||||
function gdk_notify_admin($notify_message, $comment_ID)
|
||||
{
|
||||
$notify = $notify_message;
|
||||
$notify .= '快速回复此评论: ' . admin_url("edit-comments.php") . '#comment-' . $comment_ID;
|
||||
$notify .= '快速回复此评论: '.admin_url('edit-comments.php').'#comment-'.$comment_ID;
|
||||
|
||||
return $notify;
|
||||
}
|
||||
add_filter('comment_notification_text', 'gdk_notify_admin', 10, 2);
|
||||
|
@ -527,8 +541,9 @@ add_filter('comment_notification_text', 'gdk_notify_admin', 10, 2);
|
|||
function gdk_comment_add_at($comment_text, $comment = '')
|
||||
{
|
||||
if ($comment->comment_parent > 0) {
|
||||
$comment_text = '@<a href="#comment-' . $comment->comment_parent . '">' . get_comment_author($comment->comment_parent) . '</a> ' . $comment_text;
|
||||
$comment_text = '@<a href="#comment-'.$comment->comment_parent.'">'.get_comment_author($comment->comment_parent).'</a> '.$comment_text;
|
||||
}
|
||||
|
||||
return $comment_text;
|
||||
}
|
||||
add_filter('comment_text', 'gdk_comment_add_at', 20, 2);
|
||||
|
@ -539,6 +554,7 @@ function gdk_search_filter_page($query)
|
|||
if ($query->is_search && !$query->is_admin) {
|
||||
$query->set('post_type', 'post');
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
add_filter('pre_get_posts', 'gdk_search_filter_page');
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* 各页面重写规则
|
||||
* 各页面重写规则.
|
||||
*/
|
||||
|
||||
//页面伪静态规则
|
||||
|
@ -8,7 +8,7 @@ function gdk_page_permalink()
|
|||
{
|
||||
global $wp_rewrite;
|
||||
if (!strpos($wp_rewrite->get_page_permastruct(), '.html')) {
|
||||
$wp_rewrite->page_structure = $wp_rewrite->page_structure . '.html';
|
||||
$wp_rewrite->page_structure = $wp_rewrite->page_structure.'.html';
|
||||
}
|
||||
}
|
||||
add_action('init', 'gdk_page_permalink', -1);
|
||||
|
@ -42,9 +42,9 @@ function gdk_custom_cancel_redirect($redirect_url)
|
|||
$api_daohang = get_query_var('daohang');
|
||||
if (!empty($api_sitemap) || !empty($api_daohang)) {
|
||||
return false;
|
||||
} else {
|
||||
return $redirect_url;
|
||||
}
|
||||
|
||||
return $redirect_url;
|
||||
}
|
||||
add_filter('redirect_canonical', 'gdk_custom_cancel_redirect');
|
||||
|
||||
|
@ -55,6 +55,7 @@ function gdk_public_query_vars($public_query_vars)
|
|||
$public_query_vars[] = 'dl';
|
||||
$public_query_vars[] = 'sitemap';
|
||||
$public_query_vars[] = 'daohang';
|
||||
|
||||
return $public_query_vars;
|
||||
}
|
||||
add_action('query_vars', 'gdk_public_query_vars');
|
||||
|
|
|
@ -7,19 +7,19 @@ function gdk_prevent_requst()
|
|||
{
|
||||
global $user_ID;
|
||||
if (!current_user_can('level_10')) {
|
||||
if (strlen($_SERVER['REQUEST_URI']) > 255 ||
|
||||
stripos($_SERVER['REQUEST_URI'], 'eval(') ||
|
||||
stripos($_SERVER['REQUEST_URI'], 'CONCAT') ||
|
||||
stripos($_SERVER['REQUEST_URI'], 'UNION+SELECT') ||
|
||||
stripos($_SERVER['REQUEST_URI'], 'GLOBALS(') ||
|
||||
stripos($_SERVER['REQUEST_URI'], '_REQUEST') ||
|
||||
stripos($_SERVER['REQUEST_URI'], '/localhost') ||
|
||||
stripos($_SERVER['QUERY_STRING'], '127.0.0.1') ||
|
||||
stripos($_SERVER['REQUEST_URI'], '/config.') ||
|
||||
stripos($_SERVER['REQUEST_URI'], 'wp-config.') ||
|
||||
stripos($_SERVER['REQUEST_URI'], 'etc/passwd') ||
|
||||
stripos($_SERVER['REQUEST_URI'], '<') ||
|
||||
stripos($_SERVER['REQUEST_URI'], 'base64')) {
|
||||
if (strlen($_SERVER['REQUEST_URI']) > 255
|
||||
|| stripos($_SERVER['REQUEST_URI'], 'eval(')
|
||||
|| stripos($_SERVER['REQUEST_URI'], 'CONCAT')
|
||||
|| stripos($_SERVER['REQUEST_URI'], 'UNION+SELECT')
|
||||
|| stripos($_SERVER['REQUEST_URI'], 'GLOBALS(')
|
||||
|| stripos($_SERVER['REQUEST_URI'], '_REQUEST')
|
||||
|| stripos($_SERVER['REQUEST_URI'], '/localhost')
|
||||
|| stripos($_SERVER['QUERY_STRING'], '127.0.0.1')
|
||||
|| stripos($_SERVER['REQUEST_URI'], '/config.')
|
||||
|| stripos($_SERVER['REQUEST_URI'], 'wp-config.')
|
||||
|| stripos($_SERVER['REQUEST_URI'], 'etc/passwd')
|
||||
|| stripos($_SERVER['REQUEST_URI'], '<')
|
||||
|| stripos($_SERVER['REQUEST_URI'], 'base64')) {
|
||||
@header('HTTP/1.1 403 Forbidden');
|
||||
@header('Status: 403 Forbidden');
|
||||
@header('Connection: Close');
|
||||
|
@ -43,12 +43,13 @@ if (gdk_option('gdk_disable_trackbacks')) {
|
|||
function gdk_xmlrpc_methods($methods)
|
||||
{
|
||||
unset($methods['system.multicall']);
|
||||
$methods['pingback.ping'] = '__return_false';
|
||||
$methods['pingback.ping'] = '__return_false';
|
||||
$methods['pingback.extensions.getPingbacks'] = '__return_false';
|
||||
|
||||
return $methods;
|
||||
}
|
||||
|
||||
//阻止站内PingBack
|
||||
//阻止站内PingBack
|
||||
function gdk_noself_ping(&$links)
|
||||
{
|
||||
$home = home_url();
|
||||
|
@ -57,12 +58,11 @@ if (gdk_option('gdk_disable_trackbacks')) {
|
|||
unset($links[$l]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
add_action('pre_ping', 'gdk_noself_ping');
|
||||
//禁用 pingbacks, enclosures, trackbacks
|
||||
//禁用 pingbacks, enclosures, trackbacks
|
||||
remove_action('do_pings', 'do_all_pings', 10);
|
||||
//去掉 _encloseme 和 do_ping 操作。
|
||||
//去掉 _encloseme 和 do_ping 操作。
|
||||
remove_action('publish_post', '_publish_post_hook', 5);
|
||||
}
|
||||
|
||||
|
@ -73,10 +73,11 @@ if (!function_exists('security_stop_user_enumeration')) {
|
|||
{
|
||||
if (preg_match('/\?author=([0-9]*)(\/*)/i', $request)) {
|
||||
wp_redirect(get_site_url(), 301);
|
||||
die();
|
||||
} else {
|
||||
return $redirect;
|
||||
|
||||
exit();
|
||||
}
|
||||
|
||||
return $redirect;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -84,15 +85,16 @@ if (!function_exists('security_stop_user_enumeration')) {
|
|||
if (!class_exists('GDK_Limit_Login_Attempts')) {
|
||||
class GDK_Limit_Login_Attempts
|
||||
{
|
||||
public $transient_name = 'attempted_login'; //Transient used
|
||||
private $__failed_login_limit; //登录失败的次数限制
|
||||
private $__lockout_duration; //暂停登陆时间
|
||||
public $transient_name = 'attempted_login'; //Transient used
|
||||
|
||||
public function __construct($config = null)
|
||||
{
|
||||
$this->failed_login_limit = $config['failed_login_limit'];
|
||||
$this->lockout_duration = $config['lockout_duration'];
|
||||
add_filter('authenticate', array($this, 'check_attempted_login'), 30, 3);
|
||||
add_action('wp_login_failed', array($this, 'login_failed'), 10, 1);
|
||||
$this->lockout_duration = $config['lockout_duration'];
|
||||
add_filter('authenticate', [$this, 'check_attempted_login'], 30, 3);
|
||||
add_action('wp_login_failed', [$this, 'login_failed'], 10, 1);
|
||||
}
|
||||
|
||||
public function check_attempted_login($user, $username, $password)
|
||||
|
@ -100,12 +102,13 @@ if (!class_exists('GDK_Limit_Login_Attempts')) {
|
|||
if (get_transient($this->transient_name)) {
|
||||
$datas = get_transient($this->transient_name);
|
||||
if ($datas['tried'] >= $this->failed_login_limit) {
|
||||
$until = get_option('_transient_timeout_' . $this->transient_name);
|
||||
$time = $this->when($until);
|
||||
$until = get_option('_transient_timeout_'.$this->transient_name);
|
||||
$time = $this->when($until);
|
||||
//Display error message to the user when limit is reached
|
||||
return new WP_Error('too_many_tried', sprintf(esc_attr('ERROR:您已触发登陆安全保护,请在 %1$s 后再次尝试.'), $time));
|
||||
}
|
||||
}
|
||||
|
||||
return $user;
|
||||
}
|
||||
|
||||
|
@ -113,13 +116,12 @@ if (!class_exists('GDK_Limit_Login_Attempts')) {
|
|||
{
|
||||
if (get_transient($this->transient_name)) {
|
||||
$datas = get_transient($this->transient_name);
|
||||
$datas['tried']++;
|
||||
++$datas['tried'];
|
||||
if ($datas['tried'] <= $this->failed_login_limit) {
|
||||
set_transient($this->transient_name, $datas, $this->lockout_duration);
|
||||
}
|
||||
|
||||
} else {
|
||||
$datas = array('tried' => 1);
|
||||
$datas = ['tried' => 1];
|
||||
set_transient($this->transient_name, $datas, $this->lockout_duration);
|
||||
}
|
||||
}
|
||||
|
@ -131,13 +133,13 @@ if (!class_exists('GDK_Limit_Login_Attempts')) {
|
|||
}
|
||||
|
||||
$right_now = time();
|
||||
$diff = abs($right_now - $time);
|
||||
$second = 1;
|
||||
$minute = $second * 60;
|
||||
$hour = $minute * 60;
|
||||
$day = $hour * 24;
|
||||
$diff = abs($right_now - $time);
|
||||
$second = 1;
|
||||
$minute = $second * 60;
|
||||
$hour = $minute * 60;
|
||||
$day = $hour * 24;
|
||||
if ($diff < $minute) {
|
||||
return floor($diff / $second) . ' ' . esc_attr('秒');
|
||||
return floor($diff / $second).' '.esc_attr('秒');
|
||||
}
|
||||
|
||||
if ($diff < $minute * 2) {
|
||||
|
@ -145,21 +147,21 @@ if (!class_exists('GDK_Limit_Login_Attempts')) {
|
|||
}
|
||||
|
||||
if ($diff < $hour) {
|
||||
return floor($diff / $minute) . ' ' . esc_attr('分钟');
|
||||
return floor($diff / $minute).' '.esc_attr('分钟');
|
||||
}
|
||||
|
||||
if ($diff < $hour * 2) {
|
||||
return esc_attr('about 1 hour');
|
||||
}
|
||||
|
||||
return floor($diff / $hour) . ' ' . esc_attr('小时');
|
||||
return floor($diff / $hour).' '.esc_attr('小时');
|
||||
}
|
||||
}
|
||||
}
|
||||
//Enable it:
|
||||
$LLA_config = [
|
||||
'failed_login_limit' => gdk_option('gdk_failed_login_limit'), // 登录失败的次数限制
|
||||
'lockout_duration' => gdk_option('gdk_lockout_duration'), // 暂停登陆时间
|
||||
'lockout_duration' => gdk_option('gdk_lockout_duration'), // 暂停登陆时间
|
||||
];
|
||||
if (gdk_option('gdk_lock_login')) {
|
||||
new GDK_Limit_Login_Attempts($LLA_config);
|
||||
|
@ -174,6 +176,7 @@ function gdk_disable_login_errors($error)
|
|||
// For security reason
|
||||
return esc_attr('Access Denied!');
|
||||
}
|
||||
|
||||
return $error;
|
||||
}
|
||||
//add_filter('login_errors', 'gdk_disable_login_errors');
|
||||
|
@ -182,7 +185,7 @@ function gdk_disable_login_errors($error)
|
|||
function gdk_maintenance_mode()
|
||||
{
|
||||
if (!current_user_can('edit_themes') || !is_user_logged_in()) {
|
||||
wp_die('网站维护中ing, 没事儿您就别来啦……', 'Maintenance - Could you please not disturb me ', array('response' => '503'));
|
||||
wp_die('网站维护中ing, 没事儿您就别来啦……', 'Maintenance - Could you please not disturb me ', ['response' => '503']);
|
||||
}
|
||||
}
|
||||
if (gdk_option('gdk_maintenance_mode')) {
|
||||
|
@ -194,7 +197,7 @@ if (gdk_option('gdk_fuck_spam')) {
|
|||
//拦截无来路的评论
|
||||
function gdk_comment_check_referrer()
|
||||
{
|
||||
if (!isset($_SERVER['HTTP_REFERER']) || $_SERVER['HTTP_REFERER'] == '') {
|
||||
if (!isset($_SERVER['HTTP_REFERER']) || '' == $_SERVER['HTTP_REFERER']) {
|
||||
wp_die(esc_attr('Please enable referrers in your browser!'));
|
||||
}
|
||||
}
|
||||
|
@ -214,17 +217,18 @@ if (gdk_option('gdk_fuck_spam')) {
|
|||
$pattern = '/[一-龥]/u';
|
||||
// 禁止全英文评论
|
||||
if (!preg_match($pattern, $commentdata['comment_content'])) {
|
||||
gdk_die("您的评论中必须包含汉字!");
|
||||
gdk_die('您的评论中必须包含汉字!');
|
||||
}
|
||||
$pattern = '/[あ-んア-ン]/u';
|
||||
// 禁止日文评论
|
||||
if (preg_match($pattern, $commentdata['comment_content'])) {
|
||||
gdk_die("评论禁止包含日文!");
|
||||
gdk_die('评论禁止包含日文!');
|
||||
}
|
||||
//屏蔽评论里面黑名单内容
|
||||
if (wp_check_comment_disallowed_list($commentdata['comment_author'], $commentdata['comment_author_email'], $commentdata['comment_author_url'], $commentdata['comment_content'], $commentdata['comment_author_IP'], $commentdata['comment_agent'])) {
|
||||
gdk_die('不好意思,您的评论违反本站评论规则');
|
||||
}
|
||||
|
||||
return $commentdata;
|
||||
}
|
||||
add_filter('preprocess_comment', 'gdk_comment_lang');
|
||||
|
@ -232,42 +236,43 @@ if (gdk_option('gdk_fuck_spam')) {
|
|||
|
||||
//隐藏用户名字
|
||||
if (gdk_option('gdk_hide_user_name')) {
|
||||
// 文本加密
|
||||
function gdk_text_encrypt($string, $operation, $key = '')
|
||||
{
|
||||
$string = $operation == 'D' ? str_replace(array('!', '-', '_'), array('=', '+', '/'), $string) : $string;
|
||||
$key = md5($key);
|
||||
$key_length = strlen($key);
|
||||
$string = $operation == 'D' ? base64_decode($string) : substr(md5($string . $key), 0, 8) . $string;
|
||||
$string = 'D' == $operation ? str_replace(['!', '-', '_'], ['=', '+', '/'], $string) : $string;
|
||||
$key = md5($key);
|
||||
$key_length = strlen($key);
|
||||
$string = 'D' == $operation ? base64_decode($string) : substr(md5($string.$key), 0, 8).$string;
|
||||
$string_length = strlen($string);
|
||||
$rndkey = $box = array();
|
||||
$result = '';
|
||||
for ($i = 0; $i <= 255; $i++) {
|
||||
$rndkey = $box = [];
|
||||
$result = '';
|
||||
for ($i = 0; $i <= 255; ++$i) {
|
||||
$rndkey[$i] = ord($key[$i % $key_length]);
|
||||
$box[$i] = $i;
|
||||
$box[$i] = $i;
|
||||
}
|
||||
for ($j = $i = 0; $i < 256; $i++) {
|
||||
$j = ($j + $box[$i] + $rndkey[$i]) % 256;
|
||||
$tmp = $box[$i];
|
||||
for ($j = $i = 0; $i < 256; ++$i) {
|
||||
$j = ($j + $box[$i] + $rndkey[$i]) % 256;
|
||||
$tmp = $box[$i];
|
||||
$box[$i] = $box[$j];
|
||||
$box[$j] = $tmp;
|
||||
}
|
||||
for ($a = $j = $i = 0; $i < $string_length; $i++) {
|
||||
$a = ($a + 1) % 256;
|
||||
$j = ($j + $box[$a]) % 256;
|
||||
$tmp = $box[$a];
|
||||
for ($a = $j = $i = 0; $i < $string_length; ++$i) {
|
||||
$a = ($a + 1) % 256;
|
||||
$j = ($j + $box[$a]) % 256;
|
||||
$tmp = $box[$a];
|
||||
$box[$a] = $box[$j];
|
||||
$box[$j] = $tmp;
|
||||
$result .= chr(ord($string[$i]) ^ ($box[($box[$a] + $box[$j]) % 256]));
|
||||
}
|
||||
if ($operation == 'D') {
|
||||
if (substr($result, 0, 8) == substr(md5(substr($result, 8) . $key), 0, 8)) {
|
||||
if ('D' == $operation) {
|
||||
if (substr($result, 0, 8) == substr(md5(substr($result, 8).$key), 0, 8)) {
|
||||
return substr($result, 8);
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
} else {
|
||||
return str_replace(array('=', '+', '/'), array('!', '-', '_'), base64_encode($result));
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
return strtr(base64_encode($result), '=+/', '!-_');
|
||||
}
|
||||
|
||||
function gdk_custom_author_link_request($query_vars)
|
||||
|
@ -275,11 +280,12 @@ if (gdk_option('gdk_hide_user_name')) {
|
|||
if (array_key_exists('author_name', $query_vars)) {
|
||||
global $wpdb;
|
||||
$author_id = gdk_text_encrypt($query_vars['author_name'], 'D', AUTH_KEY);
|
||||
if ($author_id) {
|
||||
if (isset($author_id)) {
|
||||
$query_vars['author'] = $author_id;
|
||||
unset($query_vars['author_name']);
|
||||
}
|
||||
}
|
||||
|
||||
return $query_vars;
|
||||
}
|
||||
add_filter('request', 'gdk_custom_author_link_request');
|
||||
|
@ -287,14 +293,13 @@ if (gdk_option('gdk_hide_user_name')) {
|
|||
function gdk_custom_author_link($link, $author_id)
|
||||
{
|
||||
global $wp_rewrite;
|
||||
$author_id = (int)$author_id;
|
||||
$link = $wp_rewrite->get_author_permastruct();
|
||||
$author_id = (int) $author_id;
|
||||
$link = $wp_rewrite->get_author_permastruct();
|
||||
if (empty($link)) {
|
||||
$file = home_url('/');
|
||||
$link = $file . '?author=' . gdk_text_encrypt($author_id, 'E', AUTH_KEY);
|
||||
$link = home_url('/').'?author='.gdk_text_encrypt($author_id, 'E', AUTH_KEY);
|
||||
} else {
|
||||
$link = str_replace('%author%', gdk_text_encrypt($author_id, 'E', AUTH_KEY), $link);
|
||||
$link = home_url() . user_trailingslashit($link);
|
||||
$link = home_url().user_trailingslashit($link);
|
||||
}
|
||||
|
||||
return $link;
|
||||
|
@ -305,6 +310,7 @@ if (gdk_option('gdk_hide_user_name')) {
|
|||
function gdk_custom_rest_prepare_user($response, $user, $request)
|
||||
{
|
||||
$response->data['slug'] = gdk_text_encrypt($user->ID, 'E', AUTH_KEY);
|
||||
|
||||
return $response;
|
||||
}
|
||||
add_filter('rest_prepare_user', 'gdk_custom_rest_prepare_user', 10, 3);
|
||||
|
@ -312,20 +318,17 @@ if (gdk_option('gdk_hide_user_name')) {
|
|||
|
||||
//记录登陆失败发邮件
|
||||
if (gdk_option('gdk_login_email')) {
|
||||
add_action('wp_authenticate', 'log_login', 10, 2);
|
||||
add_action('wp_authenticate', 'gdk_log_login', 10, 2);
|
||||
}
|
||||
function log_login($username, $password)
|
||||
function gdk_log_login($username, $password)
|
||||
{
|
||||
|
||||
if (!empty($username) && !empty($password)) {
|
||||
|
||||
if (isset($username, $password)) {
|
||||
$check = wp_authenticate_username_password(null, $username, $password);
|
||||
if (is_wp_error($check)) {
|
||||
|
||||
$ua = getBrowser();
|
||||
$ua = gdk_getBrowser();
|
||||
$agent = $ua['name'];
|
||||
|
||||
$referrer = (isset($_SERVER['HTTP_REFERER'])) ? $_SERVER['HTTP_REFERER'] : $_SERVER['PHP_SELF'];
|
||||
$referrer = $_SERVER['HTTP_REFERER'] ?? $_SERVER['PHP_SELF'];
|
||||
if (strstr($referrer, 'wp-login')) {
|
||||
$ref = 'wp-login.php';
|
||||
}
|
||||
|
@ -336,40 +339,36 @@ function log_login($username, $password)
|
|||
|
||||
$contact_errors = false;
|
||||
// get the posted data
|
||||
$name = get_bloginfo('name');
|
||||
$name = get_bloginfo('name');
|
||||
$email_address = get_bloginfo('admin_email');
|
||||
|
||||
// write the email content
|
||||
$header = "MIME-Version: 1.0\n";
|
||||
$header .= "Content-Type: text/html; charset=utf-8\n";
|
||||
$header .= "From: $name <$email_address>\n";
|
||||
$header .= "From: {$name} <{$email_address}>\n";
|
||||
|
||||
$message = "<a href='" . home_url() . "' target='_blank'>" . $name . "</a> 登陆失败提醒<br>" . PHP_EOL;
|
||||
|
||||
$message .= "Browser: " . $agent . "<br>" . PHP_EOL;
|
||||
$message .= "OS: " . $ua['platform'] . "<br>" . PHP_EOL;
|
||||
$message .= 'IP: <a href="https://www.ipip.net/ip/'. gdk_get_ip() . '.html" target="_blank">'. gdk_get_ip() . '</a><br>' . PHP_EOL;
|
||||
$message .= "Date: " . date('Y-m-d H:i:s') . "<br>" . PHP_EOL;
|
||||
$message .= "Referrer: " . $referrer . "<br>" . PHP_EOL;
|
||||
$message .= "User Agent: " . $ua['userAgent'] . "<br>" . PHP_EOL;
|
||||
$message .= "Username: " . $username . "<br>" . PHP_EOL;
|
||||
$message .= "Password: " . $password . "<br>" . PHP_EOL;
|
||||
|
||||
$subject = "登陆失败提醒 - " . $name;
|
||||
$to = $email_address;
|
||||
$mail_content = mail_temp($subject, $message , home_url(), $name );
|
||||
if (!empty($to)) {
|
||||
$message = "<a href='".home_url()."' target='_blank'>".$name.'</a> 登陆失败提醒<br>'.PHP_EOL;
|
||||
$message .= 'Browser: '.$agent.'<br>'.PHP_EOL;
|
||||
$message .= 'OS: '.$ua['platform'].'<br>'.PHP_EOL;
|
||||
$message .= 'IP: <a href="https://www.ipip.net/ip/'.gdk_get_ip().'.html" target="_blank">'.gdk_get_ip().'</a><br>'.PHP_EOL;
|
||||
$message .= 'Date: '.date('Y-m-d H:i:s').'<br>'.PHP_EOL;
|
||||
$message .= 'Referrer: '.$referrer.'<br>'.PHP_EOL;
|
||||
$message .= 'User Agent: '.$ua['userAgent'].'<br>'.PHP_EOL;
|
||||
$message .= 'Username: '.$username.'<br>'.PHP_EOL;
|
||||
$message .= 'Password: '.$password.'<br>'.PHP_EOL;
|
||||
$subject = '登陆失败提醒 - '.$name;
|
||||
$mail_content = gdk_mail_temp($subject, $message, home_url(), $name);
|
||||
if (isset($email_address)) {
|
||||
// send the email using wp_mail()
|
||||
if (!wp_mail($to, $subject, $mail_content , $header)) {
|
||||
if (!wp_mail($email_address, $subject, $mail_content, $header)) {
|
||||
$contact_errors = true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//ban yonghu
|
||||
//封禁用户
|
||||
function gdk_edit_user_profile($user)
|
||||
{
|
||||
if (!current_user_can('edit_users')) {
|
||||
|
@ -378,20 +377,19 @@ function gdk_edit_user_profile($user)
|
|||
|
||||
if (get_current_user_id() == $user->ID) {
|
||||
return;
|
||||
}
|
||||
|
||||
?>
|
||||
<table class="form-table">
|
||||
<tr>
|
||||
<th scope="row">封禁用户</th>
|
||||
<td>
|
||||
<label for="gdk_ban">
|
||||
<input name="gdk_ban" type="checkbox" id="gdk_ban" <?php checked(gdk_is_user_banned($user->ID), true) ?> value="1">
|
||||
封禁此用户</label>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<?php
|
||||
} ?>
|
||||
<table class="form-table">
|
||||
<tr>
|
||||
<th scope="row">封禁用户</th>
|
||||
<td>
|
||||
<label for="gdk_ban">
|
||||
<input name="gdk_ban" type="checkbox" id="gdk_ban" <?php checked(gdk_is_user_banned($user->ID), true); ?>
|
||||
value="1">
|
||||
封禁此用户</label>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<?php
|
||||
}
|
||||
|
||||
function gdk_edit_user_profile_update($user_id)
|
||||
|
@ -438,9 +436,11 @@ function gdk_authenticate_user($user, $password)
|
|||
|
||||
if (get_user_option('gdk_banned', $user->ID, false)) {
|
||||
return new WP_Error(
|
||||
'gdk_banned', '<strong>ERROR</strong>: 此账号已被封禁.'
|
||||
'gdk_banned',
|
||||
'<strong>ERROR</strong>: 此账号已被封禁.'
|
||||
);
|
||||
}
|
||||
|
||||
return $user;
|
||||
}
|
||||
|
||||
|
|
|
@ -2,8 +2,9 @@
|
|||
|
||||
//加载网站地图xml
|
||||
if (gdk_option('gdk_sitemap_xml')) {
|
||||
include GDK_ROOT_PATH . 'public/sitemap-xml.php';
|
||||
include GDK_ROOT_PATH . 'public/sitemap.php';
|
||||
include GDK_ROOT_PATH.'public/sitemap-xml.php';
|
||||
|
||||
include GDK_ROOT_PATH.'public/sitemap.php';
|
||||
}
|
||||
|
||||
// 屏蔽蜘蛛爬取作者页面
|
||||
|
@ -23,11 +24,12 @@ if (gdk_option('gdk_robots')) {
|
|||
function gdk_robots_txt($robotext)
|
||||
{
|
||||
if (gdk_option('gdk_sitemap_xml')) {
|
||||
$sitemap = 'Sitemap: ' . home_url('/sitemap.xml');
|
||||
$sitemap = 'Sitemap: '.home_url('/sitemap.xml');
|
||||
} else {
|
||||
$sitemap = '';
|
||||
}
|
||||
$robotext = "User-agent: *
|
||||
|
||||
return "User-agent: *
|
||||
Disallow: /wp-admin/
|
||||
Disallow: /wp-content/plugins/
|
||||
Disallow: /wp-includes/
|
||||
|
@ -37,7 +39,6 @@ Disallow: /*/feed
|
|||
Disallow: /attachment/
|
||||
Disallow: /wp-content/themes/
|
||||
{$sitemap}";
|
||||
return $robotext;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -48,14 +49,15 @@ if (gdk_option('gdk_tag_link')) {
|
|||
$post_tags = get_the_tags();
|
||||
if ($post_tags) {
|
||||
foreach ($post_tags as $tag) {
|
||||
$link = get_tag_link($tag->term_id);
|
||||
$keyword = $tag->name;
|
||||
$link = get_tag_link($tag->term_id);
|
||||
$keyword = $tag->name;
|
||||
$cleankeyword = stripslashes($keyword);
|
||||
$url = '<a target="_blank" href="' . $link . '" title="' . str_replace('%s', addcslashes($cleankeyword, '$'), '查看更多关于%s的文章') . '">' . addcslashes($cleankeyword, '$') . '</a>';
|
||||
$regEx = '\'(?!((<.*?)|(<a.*?)))(' . $cleankeyword . ')(?!(([^<>]*?)>)|([^>]*?</a>))\'s';
|
||||
$content = preg_replace($regEx, $url, $content, gdk_option('gdk_tag_num') ?? 5);
|
||||
$url = '<a target="_blank" href="'.$link.'" title="'.str_replace('%s', addcslashes($cleankeyword, '$'), '查看更多关于%s的文章').'">'.addcslashes($cleankeyword, '$').'</a>';
|
||||
$regEx = '\'(?!((<.*?)|(<a.*?)))('.$cleankeyword.')(?!(([^<>]*?)>)|([^>]*?</a>))\'s';
|
||||
$content = preg_replace($regEx, $url, $content, gdk_option('gdk_tag_num') ?? 5);
|
||||
}
|
||||
}
|
||||
|
||||
return $content;
|
||||
}
|
||||
add_filter('the_content', 'gdk_tag_link', 1);
|
||||
|
@ -71,13 +73,14 @@ if (gdk_option('gdk_nofollow')) {
|
|||
}
|
||||
function gdk_nofollow_callback($matches)
|
||||
{
|
||||
$link = $matches[0];
|
||||
$link = $matches[0];
|
||||
$site_link = get_bloginfo('url');
|
||||
if (strpos($link, 'rel') === false) {
|
||||
$link = preg_replace("%(href=\S(?!$site_link))%i", 'rel="nofollow" $1', $link);
|
||||
} elseif (preg_match("%href=\S(?!$site_link)%i", $link)) {
|
||||
if (false === strpos($link, 'rel')) {
|
||||
$link = preg_replace("%(href=\\S(?!{$site_link}))%i", 'rel="nofollow" $1', $link);
|
||||
} elseif (preg_match("%href=\\S(?!{$site_link})%i", $link)) {
|
||||
$link = preg_replace('/rel=\S(?!nofollow)\S*/i', 'rel="nofollow"', $link);
|
||||
}
|
||||
|
||||
return $link;
|
||||
}
|
||||
}
|
||||
|
@ -87,35 +90,34 @@ if (gdk_option('gdk_baidu_push')) {
|
|||
function gdk_baidu_submit($post_ID)
|
||||
{
|
||||
global $post;
|
||||
$bd_submit_site = get_bloginfo('url');
|
||||
$bd_submit_site = get_bloginfo('url');
|
||||
$bd_submit_token = gdk_option('gdk_baidu_token');
|
||||
if (empty($post_ID) || empty($bd_submit_site) || empty($bd_submit_token)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (get_post_meta($post_ID, 'gdk_baidu_submit', true) == 1) {
|
||||
if (1 == get_post_meta($post_ID, 'gdk_baidu_submit', true)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$url = get_permalink($post_ID);
|
||||
$api = $api = 'http://data.zz.baidu.com/urls?site=' . $bd_submit_site . '&token=' . $bd_submit_token;
|
||||
$url = get_permalink($post_ID);
|
||||
$api = $api = 'http://data.zz.baidu.com/urls?site='.$bd_submit_site.'&token='.$bd_submit_token;
|
||||
$status = $post->post_status;
|
||||
if ($status != '' && $status != 'publish') {
|
||||
$request = new WP_Http;
|
||||
$result = $request->request($api, array(
|
||||
'method' => 'POST',
|
||||
'body' => $url,
|
||||
if ('' != $status && 'publish' != $status) {
|
||||
$request = new WP_Http();
|
||||
$result = $request->request($api, [
|
||||
'method' => 'POST',
|
||||
'body' => $url,
|
||||
'headers' => 'Content-Type: text/plain',
|
||||
));
|
||||
if (is_array($result) && !is_wp_error($result) && $result['response']['code'] == '200') {
|
||||
error_log('baidu_submit_result:' . $result['body']);
|
||||
]);
|
||||
if (is_array($result) && !is_wp_error($result) && '200' == $result['response']['code']) {
|
||||
error_log('baidu_submit_result:'.$result['body']);
|
||||
$result = json_decode($result['body'], true);
|
||||
}
|
||||
if (array_key_exists('success', $result)) {
|
||||
add_post_meta($post_ID, 'gdk_baidu_submit', 1, true);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
add_action('publish_post', 'gdk_baidu_submit', 0);
|
||||
add_action('wp_footer', 'gdk_baidu_auto_push', 500);
|
||||
|
@ -145,9 +147,10 @@ if (gdk_option('gdk_seo_img')) {
|
|||
function gdk_imagesalt($content)
|
||||
{
|
||||
global $post;
|
||||
$pattern = "/<a(.*?)href=('|\")(.*?).(bmp|gif|jpeg|jpg|png)('|\")(.*?)>/i";
|
||||
$replacement = '<a$1href=$2$3.$4$5 alt="' . strip_tags($post->post_title) . '" title="' . strip_tags($post->post_title) . '"$6>';
|
||||
$content = preg_replace($pattern, $replacement, $content);
|
||||
$pattern = "/<a(.*?)href=('|\")(.*?).(bmp|gif|jpeg|jpg|png)('|\")(.*?)>/i";
|
||||
$replacement = '<a$1href=$2$3.$4$5 alt="'.strip_tags($post->post_title).'" title="'.strip_tags($post->post_title).'"$6>';
|
||||
$content = preg_replace($pattern, $replacement, $content);
|
||||
|
||||
return $content;
|
||||
}
|
||||
add_filter('the_content', 'gdk_imagesalt');
|
||||
|
@ -157,10 +160,11 @@ if (gdk_option('gdk_seo_img')) {
|
|||
preg_match_all('/<img (.*?)\/>/', $content, $images);
|
||||
if (!is_null($images)) {
|
||||
foreach ($images[1] as $index => $value) {
|
||||
$new_img = str_replace('<img', '<img alt="' . strip_tags($post->post_title) . '-' . get_option('blogname') . '"', $images[0][$index]);
|
||||
$new_img = str_replace('<img', '<img alt="'.strip_tags($post->post_title).'-'.get_option('blogname').'"', $images[0][$index]);
|
||||
$content = str_replace($images[0][$index], $new_img, $content);
|
||||
}
|
||||
}
|
||||
|
||||
return $content;
|
||||
}
|
||||
add_filter('the_content', 'gdk_image_alt_tag', 99999);
|
||||
|
@ -174,12 +178,11 @@ function gdk_keywords()
|
|||
if (is_single()) {
|
||||
if (get_the_tags($post->ID)) {
|
||||
foreach (get_the_tags($post->ID) as $tag) {
|
||||
$keywords .= $tag->name . ', ';
|
||||
$keywords .= $tag->name.', ';
|
||||
}
|
||||
|
||||
}
|
||||
foreach (get_the_category($post->ID) as $category) {
|
||||
$keywords .= $category->cat_name . ', ';
|
||||
$keywords .= $category->cat_name.', ';
|
||||
}
|
||||
|
||||
$keywords = substr_replace($keywords, '', -2);
|
||||
|
@ -203,7 +206,7 @@ function gdk_keywords()
|
|||
$keywords = trim(wp_title('', false));
|
||||
}
|
||||
if ($keywords) {
|
||||
echo "<meta name=\"keywords\" content=\"$keywords\">\n";
|
||||
echo "<meta name=\"keywords\" content=\"{$keywords}\">\n";
|
||||
}
|
||||
}
|
||||
add_action('wp_head', 'gdk_keywords');
|
||||
|
@ -213,48 +216,47 @@ function gdk_description()
|
|||
{
|
||||
global $s, $post;
|
||||
$description = '';
|
||||
$blog_name = get_bloginfo('name');
|
||||
$excerpt = $post->post_excerpt;
|
||||
$blog_name = get_bloginfo('name');
|
||||
$excerpt = $post->post_excerpt;
|
||||
if (is_singular()) {
|
||||
if (!empty($excerpt)) {
|
||||
$text = $excerpt;
|
||||
} else {
|
||||
$text = strip_shortcodes($post->post_content);
|
||||
}
|
||||
$description = trim(str_replace(array(
|
||||
$description = trim(str_replace([
|
||||
"\r\n",
|
||||
"\r",
|
||||
"\n",
|
||||
" ",
|
||||
" ",
|
||||
), " ", str_replace("\"", "'", strip_tags($text))));
|
||||
' ',
|
||||
' ',
|
||||
], ' ', str_replace('"', "'", strip_tags($text))));
|
||||
if (!($description)) {
|
||||
$description = $blog_name . "-" . trim(wp_title('', false));
|
||||
$description = $blog_name.'-'.trim(wp_title('', false));
|
||||
}
|
||||
|
||||
} elseif (is_home() || is_front_page()) {
|
||||
$description = gdk_option('gdk_description'); // 首頁要自己加
|
||||
} elseif (is_tag()) {
|
||||
if (in_string(tag_description(), '@@')) {
|
||||
$description = $blog_name . "'" . gdk_term_meta('tag', 'des') . "'";
|
||||
$description = $blog_name."'".gdk_term_meta('tag', 'des')."'";
|
||||
} else {
|
||||
$description = $blog_name . "'" . single_tag_title('', false) . "'";
|
||||
$description = $blog_name."'".single_tag_title('', false)."'";
|
||||
}
|
||||
} elseif (is_category()) {
|
||||
if (in_string(category_description(), '@@')) {
|
||||
$description = $blog_name . "'" . trim(strip_tags(gdk_term_meta('tag', 'des')));
|
||||
$description = $blog_name."'".trim(strip_tags(gdk_term_meta('tag', 'des')));
|
||||
} else {
|
||||
$description = $blog_name . "'" . trim(strip_tags(category_description()));
|
||||
$description = $blog_name."'".trim(strip_tags(category_description()));
|
||||
}
|
||||
} elseif (is_archive()) {
|
||||
$description = $blog_name . "'" . trim(wp_title('', false)) . "'";
|
||||
$description = $blog_name."'".trim(wp_title('', false))."'";
|
||||
} elseif (is_search()) {
|
||||
$description = $blog_name . ": '" . esc_html($s, 1) . "' 的搜索結果";
|
||||
$description = $blog_name.": '".esc_html($s, 1)."' 的搜索結果";
|
||||
} else {
|
||||
$description = $blog_name . "'" . trim(wp_title('', false)) . "'";
|
||||
$description = $blog_name."'".trim(wp_title('', false))."'";
|
||||
}
|
||||
$description = mb_substr($description, 0, 220, 'utf-8');
|
||||
echo "<meta name=\"description\" content=\"$description\">\n";
|
||||
echo "<meta name=\"description\" content=\"{$description}\">\n";
|
||||
}
|
||||
add_action('wp_head', 'gdk_description');
|
||||
|
||||
|
@ -266,28 +268,28 @@ function meta_og()
|
|||
if (has_post_thumbnail($post->ID)) {
|
||||
$img_src = gdk_thumbnail_src();
|
||||
}
|
||||
$excerpt = strip_tags($post->post_content);
|
||||
$excerpt = strip_tags($post->post_content);
|
||||
$excerpt_more = '';
|
||||
if (strlen($excerpt) > 155) {
|
||||
$excerpt = substr($excerpt, 0, 155);
|
||||
$excerpt = substr($excerpt, 0, 155);
|
||||
$excerpt_more = ' ...';
|
||||
}
|
||||
$excerpt = str_replace('"', '', $excerpt);
|
||||
$excerpt = str_replace("'", '', $excerpt);
|
||||
$excerpt = str_replace('"', '', $excerpt);
|
||||
$excerpt = str_replace("'", '', $excerpt);
|
||||
$excerptwords = preg_split('/[\n\r\t ]+/', $excerpt, -1, PREG_SPLIT_NO_EMPTY);
|
||||
array_pop($excerptwords);
|
||||
$excerpt = implode(' ', $excerptwords) . $excerpt_more;
|
||||
?>
|
||||
<meta name="author" content="Your Name">
|
||||
<meta name="description" content="<?php echo $excerpt; ?>">
|
||||
<meta property="og:title" content="<?php echo the_title(); ?>">
|
||||
<meta property="og:description" content="<?php echo $excerpt; ?>">
|
||||
<meta property="og:type" content="article">
|
||||
<meta property="og:url" content="<?php echo the_permalink(); ?>">
|
||||
<meta property="og:site_name" content="<?php echo get_bloginfo('name'); ?>">
|
||||
<meta property="og:image" content="<?php $img_src; ?>">
|
||||
<?php
|
||||
} else {
|
||||
$excerpt = implode(' ', $excerptwords).$excerpt_more; ?>
|
||||
<meta name="author" content="Your Name">
|
||||
<meta name="description" content="<?php echo $excerpt; ?>">
|
||||
<meta property="og:title" content="<?php echo the_title(); ?>">
|
||||
<meta property="og:description" content="<?php echo $excerpt; ?>">
|
||||
<meta property="og:type" content="article">
|
||||
<meta property="og:url" content="<?php echo the_permalink(); ?>">
|
||||
<meta property="og:site_name"
|
||||
content="<?php echo get_bloginfo('name'); ?>">
|
||||
<meta property="og:image" content="<?php ?>">
|
||||
<?php
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -302,7 +304,7 @@ function gdk_canonical()
|
|||
echo "<link rel='canonical' href='";
|
||||
echo get_permalink($post->ID);
|
||||
echo "' />\n";
|
||||
echo "<meta name=\"robots\" content=\"noindex,follow\">";
|
||||
echo '<meta name="robots" content="noindex,follow">';
|
||||
}
|
||||
}
|
||||
add_action('wp_head', 'gdk_canonical');
|
|
@ -2,11 +2,11 @@
|
|||
|
||||
//百度收录提示
|
||||
if (gdk_option('gdk_baidurecord_b') && function_exists('curl_init')) {
|
||||
function baidu_check($url, $post_id)
|
||||
function gdk_baidu_check($url, $post_id)
|
||||
{
|
||||
$baidu_record = get_post_meta($post_id, 'baidu_record', true);
|
||||
if ($baidu_record != 1) {
|
||||
$url = 'http://www.baidu.com/s?wd=' . $url;
|
||||
if (1 != $baidu_record) {
|
||||
$url = 'http://www.baidu.com/s?wd='.$url;
|
||||
$curl = curl_init();
|
||||
curl_setopt($curl, CURLOPT_URL, $url);
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
|
||||
|
@ -14,51 +14,51 @@ if (gdk_option('gdk_baidurecord_b') && function_exists('curl_init')) {
|
|||
curl_close($curl);
|
||||
if (!strpos($rs, '没有找到该URL,您可以直接访问') && !strpos($rs, '很抱歉,没有找到与')) {
|
||||
update_post_meta($post_id, 'baidu_record', 1) || add_post_meta($post_id, 'baidu_record', 1, true);
|
||||
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
function baidu_record()
|
||||
{
|
||||
global $wpdb;
|
||||
$post_id = null === $post_id ? get_the_ID() : $post_id;
|
||||
if (baidu_check(get_permalink($post_id), $post_id) == 1) {
|
||||
echo '<a target="_blank" title="点击查看" rel="external nofollow" href="http://www.baidu.com/s?wd=' . get_the_title() . '">已收录</a>';
|
||||
$post_id = get_the_ID() ?? null;
|
||||
if (1 == gdk_baidu_check(get_permalink($post_id), $post_id)) {
|
||||
echo '<a target="_blank" title="点击查看" rel="external nofollow" href="http://www.baidu.com/s?wd='.get_the_title().'">已收录</a>';
|
||||
} else {
|
||||
echo '<a style="color:red;" rel="external nofollow" title="点击提交,谢谢您!" target="_blank" href="http://zhanzhang.baidu.com/sitesubmit/index?sitename=' . get_permalink() . '">未收录</a>';
|
||||
echo '<a style="color:red;" rel="external nofollow" title="点击提交,谢谢您!" target="_blank" href="http://zhanzhang.baidu.com/sitesubmit/index?sitename='.get_permalink().'">未收录</a>';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//百度主动推送
|
||||
if (gdk_option('gdk_sitemap_api')) {
|
||||
function Git_Baidu_Submit($post_ID)
|
||||
function gdk_Baidu_Submit($post_ID)
|
||||
{
|
||||
if (get_post_meta($post_ID, 'gdk_baidu_submit', true) == 1) {
|
||||
if (1 == get_post_meta($post_ID, 'gdk_baidu_submit', true)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$url = get_permalink($post_ID);
|
||||
$api = gdk_option('gdk_sitemap_api');
|
||||
$request = new WP_Http;
|
||||
$result = $request->request($api, array(
|
||||
'method' => 'POST',
|
||||
'body' => $url,
|
||||
$url = get_permalink($post_ID);
|
||||
$api = gdk_option('gdk_sitemap_api');
|
||||
$request = new WP_Http();
|
||||
$result = $request->request($api, [
|
||||
'method' => 'POST',
|
||||
'body' => $url,
|
||||
'headers' => 'Content-Type: text/plain',
|
||||
));
|
||||
if (is_array($result) && !is_wp_error($result) && $result['response']['code'] == '200') {
|
||||
error_log('baidu_submit_result:' . $result['body']);
|
||||
]);
|
||||
if (is_array($result) && !is_wp_error($result) && '200' == $result['response']['code']) {
|
||||
error_log('baidu_submit_result:'.$result['body']);
|
||||
$result = json_decode($result['body'], true);
|
||||
}
|
||||
if (array_key_exists('success', $result)) {
|
||||
add_post_meta($post_ID, 'gdk_baidu_submit', 1, true);
|
||||
}
|
||||
}
|
||||
add_action('publish_post', 'Git_Baidu_Submit', 0);
|
||||
add_action('publish_post', 'gdk_Baidu_Submit', 0);
|
||||
}
|
||||
|
||||
//强制微信登录
|
||||
|
@ -71,16 +71,17 @@ function force_weauth_login_url($login_url, $redirect, $force_reauth)
|
|||
if ($force_reauth) {
|
||||
$login_url = add_query_arg('reauth', '1', $login_url);
|
||||
}
|
||||
|
||||
return $login_url;
|
||||
}if (gdk_option('gdk_weauth_oauth') && gdk_option('gdk_weauth_oauth_force')) {
|
||||
} if (gdk_option('gdk_weauth_oauth') && gdk_option('gdk_weauth_oauth_force')) {
|
||||
add_filter('login_url', 'force_weauth_login_url', 10, 3);
|
||||
}
|
||||
|
||||
//在登录框添加额外的微信登录
|
||||
function weixin_login_button()
|
||||
{
|
||||
echo '<p><a class="button button-large" href="' . get_permalink(gdk_page_id('weauth')) . '">微信登录</a></p><br>';
|
||||
}if (gdk_option('gdk_weauth_oauth')) {
|
||||
echo '<p><a class="button button-large" href="'.get_permalink(gdk_page_id('weauth')).'">微信登录</a></p><br>';
|
||||
} if (gdk_option('gdk_weauth_oauth')) {
|
||||
add_action('login_form', 'weixin_login_button');
|
||||
}
|
||||
|
||||
|
@ -88,29 +89,30 @@ function weixin_login_button()
|
|||
if (gdk_option('gdk_Server') && !is_admin()) {
|
||||
function sc_send($comment_id)
|
||||
{
|
||||
$text = '网站上有新的评论,请及时查看'; //微信推送信息标题
|
||||
$text = '网站上有新的评论,请及时查看'; //微信推送信息标题
|
||||
$comment = get_comment($comment_id);
|
||||
$desp = '' . $comment->comment_content . '
|
||||
$desp = ''.$comment->comment_content.'
|
||||
***
|
||||
<br>
|
||||
* 评论人 :' . get_comment_author($comment_id) . '
|
||||
* 文章标题 :' . get_the_title() . '
|
||||
* 文章链接 :' . get_the_permalink($comment->comment_post_ID) . '
|
||||
* 评论人 :'.get_comment_author($comment_id).'
|
||||
* 文章标题 :'.get_the_title().'
|
||||
* 文章链接 :'.get_the_permalink($comment->comment_post_ID).'
|
||||
'; //微信推送内容正文
|
||||
$key = gdk_option('gdk_Server_key');
|
||||
$postdata = http_build_query(array(
|
||||
$key = gdk_option('gdk_Server_key');
|
||||
$postdata = http_build_query([
|
||||
'text' => $text,
|
||||
'desp' => $desp,
|
||||
));
|
||||
$opts = array(
|
||||
'http' => array(
|
||||
'method' => 'POST',
|
||||
'header' => 'Content-type: application/x-www-form-urlencoded',
|
||||
]);
|
||||
$opts = [
|
||||
'http' => [
|
||||
'method' => 'POST',
|
||||
'header' => 'Content-type: application/x-www-form-urlencoded',
|
||||
'content' => $postdata,
|
||||
),
|
||||
);
|
||||
$context = stream_context_create($opts);
|
||||
return $result = file_get_contents('http://sc.ftqq.com/' . $key . '.send', false, $context);
|
||||
],
|
||||
];
|
||||
$context = stream_context_create($opts);
|
||||
|
||||
return $result = file_get_contents('http://sc.ftqq.com/'.$key.'.send', false, $context);
|
||||
}
|
||||
add_action('comment_post', 'sc_send', 19, 2);
|
||||
}
|
||||
|
@ -124,30 +126,21 @@ function wp_bili($matches, $attr, $url, $rawattr)
|
|||
} else {
|
||||
$height = 480;
|
||||
}
|
||||
$iframe = '<iframe width=100% height=' . $height . 'px src="//www.bilibili.com/blackboard/player.html?aid=' . esc_attr($matches[1]) . '" scrolling="no" border="0" framespacing="0" frameborder="no"></iframe>';
|
||||
$iframe = '<iframe width=100% height='.$height.'px src="//www.bilibili.com/blackboard/player.html?aid='.esc_attr($matches[1]).'" scrolling="no" border="0" framespacing="0" frameborder="no"></iframe>';
|
||||
|
||||
return apply_filters('iframe_bili', $iframe, $matches, $attr, $url, $ramattr);
|
||||
}
|
||||
wp_embed_register_handler('bili_iframe', '#https://www.bilibili.com/video/av(.*?)/#i', 'wp_bili');
|
||||
|
||||
//bing美图自定义登录页面背景
|
||||
function custom_login_head()
|
||||
function gdk_custom_login_head()
|
||||
{
|
||||
if (gdk_option('gdk_loginbg')) {
|
||||
$imgurl = gdk_option('gdk_loginbg');
|
||||
} else {
|
||||
$imgurl = get_transient('Bing_img');
|
||||
if (false === $imgurl) {
|
||||
$arr = json_decode(curl_post('https://cn.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1')['data']);
|
||||
$imgurl = 'http://cn.bing.com' . $arr->images[0]->url;
|
||||
set_transient('Bing_img', $imgurl, 60 * 60 * 24);
|
||||
}
|
||||
$imgurl = gdk_get_bing_img();
|
||||
}
|
||||
if (defined('UM_DIR')) {
|
||||
echo '<style type="text/css">#um_captcha{width:170px!important;}</style>';
|
||||
}
|
||||
echo '<style type="text/css">#reg_passmail{display:none!important}body{background: url(' . $imgurl . ') center center no-repeat;-moz-background-size: cover;-o-background-size: cover;-webkit-background-size: cover;background-size: cover;background-attachment: fixed;}.login label,a {font-weight: bold;}.login-action-register #login{padding: 5% 0 0;}.login p {line-height: 1;}.login form {margin-top: 10px;padding: 16px 24px 16px;}h1 a { background-image:url(' . home_url() . '/favicon.ico)!important;width:32px;height:32px;-webkit-border-radius:50px;-moz-border-radius:50px;border-radius:50px;}#registerform,#loginform {background-color:rgba(251,251,251,0.3)!important;}.login label,a{color:#000!important;}form label input{margin-top:10px!important;}@media screen and (max-width:600px){.login-action-register h1 {display: none;}.login-action-register #login{top:50%!important;}}</style>';
|
||||
echo '<style type="text/css">#um_captcha{width:170px!important;}#reg_passmail{display:none!important}body{background: url('.$imgurl.') center center no-repeat;-moz-background-size: cover;-o-background-size: cover;-webkit-background-size: cover;background-size: cover;background-attachment: fixed;}.login label,a {font-weight: bold;}.login-action-register #login{padding: 5% 0 0;}.login p {line-height: 1;}.login form {margin-top: 10px;padding: 16px 24px 16px;}h1 a { background-image:url('.home_url().'/favicon.ico)!important;width:32px;height:32px;-webkit-border-radius:50px;-moz-border-radius:50px;border-radius:50px;}#registerform,#loginform {background-color:rgba(251,251,251,0.3)!important;}.login label,a{color:#000!important;}form label input{margin-top:10px!important;}@media screen and (max-width:600px){.login-action-register h1 {display: none;}.login-action-register #login{top:50%!important;}}</style>';
|
||||
}
|
||||
add_action('login_head', 'custom_login_head');
|
||||
add_action('login_head', 'gdk_custom_login_head');
|
||||
|
||||
// add youku using iframe
|
||||
function wp_iframe_handler_youku($matches, $attr, $url, $rawattr)
|
||||
|
@ -157,7 +150,8 @@ function wp_iframe_handler_youku($matches, $attr, $url, $rawattr)
|
|||
} else {
|
||||
$height = 485;
|
||||
}
|
||||
$iframe = '<iframe width=100% height=' . $height . 'px src="http://player.youku.com/embed/' . esc_attr($matches[1]) . '" frameborder=0 allowfullscreen></iframe>';
|
||||
$iframe = '<iframe width=100% height='.$height.'px src="http://player.youku.com/embed/'.esc_attr($matches[1]).'" frameborder=0 allowfullscreen></iframe>';
|
||||
|
||||
return apply_filters('iframe_youku', $iframe, $matches, $attr, $url, $ramattr);
|
||||
}
|
||||
wp_embed_register_handler('youku_iframe', '#http://v.youku.com/v_show/id_(.*?).html#i', 'wp_iframe_handler_youku');
|
||||
|
|
|
@ -13,7 +13,6 @@ function gdk_potin()
|
|||
}
|
||||
add_shortcode('gdk_potin_btn', 'gdk_potin');
|
||||
|
||||
//
|
||||
function gdk_login_fancybox()
|
||||
{
|
||||
return weixin_login_btn();
|
||||
|
@ -23,37 +22,40 @@ add_shortcode('gdk_login_btn', 'gdk_login_fancybox');
|
|||
//添加钮Download
|
||||
function gdk_DownloadUrl($atts, $content = null)
|
||||
{
|
||||
extract(shortcode_atts(array(
|
||||
extract(shortcode_atts([
|
||||
'href' => 'http://',
|
||||
), $atts));
|
||||
return '<a class="dl" href="' . $href . '" target="_blank" rel="nofollow"><i class="fa fa-cloud-download"></i>' . $content . '</a>';
|
||||
], $atts));
|
||||
|
||||
return '<a class="dl" href="'.$href.'" target="_blank" rel="nofollow"><i class="fa fa-cloud-download"></i>'.$content.'</a>';
|
||||
}
|
||||
add_shortcode('dl', 'gdk_DownloadUrl');
|
||||
//添加钮git
|
||||
function gdk_GithubUrl($atts, $content = null)
|
||||
{
|
||||
extract(shortcode_atts(array(
|
||||
extract(shortcode_atts([
|
||||
'href' => 'http://',
|
||||
), $atts));
|
||||
return '<a class="dl" href="' . $href . '" target="_blank" rel="nofollow"><i class="fa fa-github-alt"></i>' . $content . '</a>';
|
||||
], $atts));
|
||||
|
||||
return '<a class="dl" href="'.$href.'" target="_blank" rel="nofollow"><i class="fa fa-github-alt"></i>'.$content.'</a>';
|
||||
}
|
||||
add_shortcode('gt', 'gdk_GithubUrl');
|
||||
//添加钮Demo
|
||||
function gdk_DemoUrl($atts, $content = null)
|
||||
{
|
||||
extract(shortcode_atts(array(
|
||||
extract(shortcode_atts([
|
||||
'href' => 'http://',
|
||||
), $atts));
|
||||
return '<a class="dl" href="' . $href . '" target="_blank" rel="nofollow"><i class="fa fa-external-link"></i>' . $content . '</a>';
|
||||
], $atts));
|
||||
|
||||
return '<a class="dl" href="'.$href.'" target="_blank" rel="nofollow"><i class="fa fa-external-link"></i>'.$content.'</a>';
|
||||
}
|
||||
add_shortcode('dm', 'gdk_DemoUrl');
|
||||
//使用短代码添加回复后可见内容开始
|
||||
function gdk_reply_to_read($atts, $content = null)
|
||||
{
|
||||
extract(shortcode_atts(array(
|
||||
'notice' => '<div class="alert info pull-center"><p class="reply-to-read">注意:本段内容须成功“<a href="' . get_permalink() . '#respond" title="回复本文">回复本文</a>”后“<a href="javascript:window.location.reload();" title="刷新本页">刷新本页</a>”方可查看!</p></div>',
|
||||
), $atts));
|
||||
$email = null;
|
||||
extract(shortcode_atts([
|
||||
'notice' => '<div class="alert info pull-center"><p class="reply-to-read">注意:本段内容须成功“<a href="'.get_permalink().'#respond" title="回复本文">回复本文</a>”后“<a href="javascript:window.location.reload();" title="刷新本页">刷新本页</a>”方可查看!</p></div>',
|
||||
], $atts));
|
||||
$email = null;
|
||||
$user_ID = get_current_user_id();
|
||||
if ($user_ID > 0) {
|
||||
$email = get_user_by('id', $user_ID)->user_email;
|
||||
|
@ -62,8 +64,8 @@ function gdk_reply_to_read($atts, $content = null)
|
|||
if ($email == $admin_email) {
|
||||
return $content;
|
||||
}
|
||||
} elseif (isset($_COOKIE['comment_author_email_' . COOKIEHASH])) {
|
||||
$email = str_replace('%40', '@', $_COOKIE['comment_author_email_' . COOKIEHASH]);
|
||||
} elseif (isset($_COOKIE['comment_author_email_'.COOKIEHASH])) {
|
||||
$email = str_replace('%40', '@', $_COOKIE['comment_author_email_'.COOKIEHASH]);
|
||||
} else {
|
||||
return $notice;
|
||||
}
|
||||
|
@ -72,144 +74,150 @@ function gdk_reply_to_read($atts, $content = null)
|
|||
}
|
||||
global $wpdb;
|
||||
$post_id = get_the_ID();
|
||||
$query = "SELECT `comment_ID` FROM {$wpdb->comments} WHERE `comment_post_ID`={$post_id} and `comment_approved`='1' and `comment_author_email`='{$email}' LIMIT 1";
|
||||
$query = "SELECT `comment_ID` FROM {$wpdb->comments} WHERE `comment_post_ID`={$post_id} and `comment_approved`='1' and `comment_author_email`='{$email}' LIMIT 1";
|
||||
if ($wpdb->get_results($query)) {
|
||||
return do_shortcode($content);
|
||||
} else {
|
||||
return $notice;
|
||||
}
|
||||
|
||||
return $notice;
|
||||
}
|
||||
add_shortcode('reply', 'gdk_reply_to_read');
|
||||
|
||||
//绿色提醒框
|
||||
function gdk_toz($atts, $content = null)
|
||||
{
|
||||
return '<div class="alert success">' . $content . '</div>';
|
||||
return '<div class="alert success">'.$content.'</div>';
|
||||
}
|
||||
add_shortcode('v_notice', 'gdk_toz');
|
||||
//红色提醒框
|
||||
function gdk_toa($atts, $content = null)
|
||||
{
|
||||
return '<div class="alert error">' . $content . '</div>';
|
||||
return '<div class="alert error">'.$content.'</div>';
|
||||
}
|
||||
add_shortcode('v_error', 'gdk_toa');
|
||||
//黄色提醒框
|
||||
function gdk_toc($atts, $content = null)
|
||||
{
|
||||
return '<div class="alert warning">' . $content . '</div>';
|
||||
return '<div class="alert warning">'.$content.'</div>';
|
||||
}
|
||||
add_shortcode('v_warn', 'gdk_toc');
|
||||
|
||||
//蓝色提醒框
|
||||
function gdk_tod($atts, $content = null)
|
||||
{
|
||||
return '<div class="alert primary">' . $content . '</div>';
|
||||
return '<div class="alert primary">'.$content.'</div>';
|
||||
}
|
||||
add_shortcode('v_blue', 'gdk_tod');
|
||||
//蓝边文本框
|
||||
function gdk_toe($atts, $content = null)
|
||||
{
|
||||
return '<div class="alert">' . $content . '</div>';
|
||||
return '<div class="alert">'.$content.'</div>';
|
||||
}
|
||||
add_shortcode('v_tips', 'gdk_toe');
|
||||
|
||||
//灵魂按钮
|
||||
function gdk_tom($atts, $content = null)
|
||||
{
|
||||
extract(shortcode_atts(array(
|
||||
extract(shortcode_atts([
|
||||
'href' => 'http://',
|
||||
), $atts));
|
||||
return '<a class="cm-btn success" href="' . $href . '" target="_blank" rel="nofollow">' . $content . '</a>';
|
||||
], $atts));
|
||||
|
||||
return '<a class="cm-btn success" href="'.$href.'" target="_blank" rel="nofollow">'.$content.'</a>';
|
||||
}
|
||||
add_shortcode('lhb', 'gdk_tom');
|
||||
//添加视频按钮
|
||||
function gdk_too($atts, $content = null)
|
||||
{
|
||||
extract(shortcode_atts(array(
|
||||
extract(shortcode_atts([
|
||||
'play' => '0',
|
||||
), $atts));
|
||||
if ($play == 0) {
|
||||
return '<video style="width:100%;" src="' . $content . '" controls preload >您的浏览器不支持HTML5的 video 标签,无法为您播放!</video>';
|
||||
], $atts));
|
||||
if (0 == $play) {
|
||||
return '<video style="width:100%;" src="'.$content.'" controls preload >您的浏览器不支持HTML5的 video 标签,无法为您播放!</video>';
|
||||
}
|
||||
if ($play == 1) {
|
||||
return '<video style="width:100%;" src="' . $content . '" controls preload autoplay >您的浏览器不支持HTML5的 video 标签,无法为您播放!</video>';
|
||||
if (1 == $play) {
|
||||
return '<video style="width:100%;" src="'.$content.'" controls preload autoplay >您的浏览器不支持HTML5的 video 标签,无法为您播放!</video>';
|
||||
}
|
||||
}
|
||||
add_shortcode('video', 'gdk_too');
|
||||
//添加音频按钮
|
||||
function gdk_tkk($atts, $content = null)
|
||||
{
|
||||
extract(shortcode_atts(array(
|
||||
extract(shortcode_atts([
|
||||
'play' => '0',
|
||||
), $atts));
|
||||
if ($play == 0) {
|
||||
return '<audio style="width:100%;" src="' . $content . '" controls loop>您的浏览器不支持 audio 标签。</audio>';
|
||||
], $atts));
|
||||
if (0 == $play) {
|
||||
return '<audio style="width:100%;" src="'.$content.'" controls loop>您的浏览器不支持 audio 标签。</audio>';
|
||||
}
|
||||
if ($play == 1) {
|
||||
return '<audio style="width:100%;" src="' . $content . '" controls autoplay loop>您的浏览器不支持 audio 标签。</audio>';
|
||||
if (1 == $play) {
|
||||
return '<audio style="width:100%;" src="'.$content.'" controls autoplay loop>您的浏览器不支持 audio 标签。</audio>';
|
||||
}
|
||||
}
|
||||
add_shortcode('audio', 'gdk_tkk');
|
||||
//弹窗下载
|
||||
function gdk_ton($atts, $content = null)
|
||||
{
|
||||
extract(shortcode_atts(array(
|
||||
'href' => 'http://',
|
||||
extract(shortcode_atts([
|
||||
'href' => 'http://',
|
||||
'filename' => '',
|
||||
'filesize' => '',
|
||||
'filedown' => '',
|
||||
), $atts));
|
||||
return '<a class="lhb" id="showdiv" href="#fancydlbox" >文件下载</a><div id="fancydlbox" style="cursor:default;display:none;width:800px;"><div class="part" style="padding:20px 0;"><h2>下载声明:</h2> <div class="fancydlads" align="left"><p>' . gdk_option('gdk_fancydlcp') . '</p></div></div><div class="part" style="padding:20px 0;"><h2>文件信息:</h2> <div class="dlnotice" align="left"><p>文件名称:' . $filename . '<br />文件大小:' . $filesize . '<br />发布日期:' . get_the_modified_time('Y年n月j日') . '</p></div></div><div class="part" id="download_button_part"><a id="download_button" target="_blank" href="' . $href . '"><span></span>' . $filedown . '</a> </div><div class="part" style="padding:20px 0;"><div class="moredl" style="text-align:center;">[更多地址] : ' . $content . '</div></div><div class="dlfooter">' . gdk_option('gdk_fancydlad') . '</div></div>';
|
||||
], $atts));
|
||||
|
||||
return '<a class="lhb" id="showdiv" href="#fancydlbox" >文件下载</a><div id="fancydlbox" style="cursor:default;display:none;width:800px;"><div class="part" style="padding:20px 0;"><h2>下载声明:</h2> <div class="fancydlads" align="left"><p>'.gdk_option('gdk_fancydlcp').'</p></div></div><div class="part" style="padding:20px 0;"><h2>文件信息:</h2> <div class="dlnotice" align="left"><p>文件名称:'.$filename.'<br />文件大小:'.$filesize.'<br />发布日期:'.get_the_modified_time('Y年n月j日').'</p></div></div><div class="part" id="download_button_part"><a id="download_button" target="_blank" href="'.$href.'"><span></span>'.$filedown.'</a> </div><div class="part" style="padding:20px 0;"><div class="moredl" style="text-align:center;">[更多地址] : '.$content.'</div></div><div class="dlfooter">'.gdk_option('gdk_fancydlad').'</div></div>';
|
||||
}
|
||||
add_shortcode('fanctdl', 'gdk_ton');
|
||||
|
||||
|
||||
//下载单页短代码
|
||||
function gdk_download($atts, $content = null)
|
||||
{
|
||||
extract(shortcode_atts(array('title' => '点击下载',), $atts));
|
||||
return '<a class="cm-btn primary" href="' . home_url() . '?dl=' . get_the_ID() . '" target="_blank" rel="nofollow">' . $title . '</a>';
|
||||
extract(shortcode_atts(['title' => '点击下载'], $atts));
|
||||
|
||||
return '<a class="cm-btn primary" href="'.home_url().'?dl='.get_the_ID().'" target="_blank" rel="nofollow">'.$title.'</a>';
|
||||
}
|
||||
add_shortcode('pdownload', 'gdk_download');
|
||||
|
||||
//为WordPress添加展开收缩功能
|
||||
function gdk_xcollapse($atts, $content = null)
|
||||
{
|
||||
extract(shortcode_atts(array(
|
||||
extract(shortcode_atts([
|
||||
'title' => '',
|
||||
), $atts));
|
||||
return '<div style="margin: 0.5em 0;"><div class="xControl"><a href="javascript:void(0)" class="collapseButton xButton"><i class="fa fa-plus-square" ></i> ' . $title . '</a><div style="clear: both;"></div></div><div class="xContent" style="display: none;">' . $content . '</div></div>';
|
||||
], $atts));
|
||||
|
||||
return '<div style="margin: 0.5em 0;"><div class="xControl"><a href="javascript:void(0)" class="collapseButton xButton"><i class="fa fa-plus-square" ></i> '.$title.'</a><div style="clear: both;"></div></div><div class="xContent" style="display: none;">'.$content.'</div></div>';
|
||||
}
|
||||
add_shortcode('collapse', 'gdk_xcollapse');
|
||||
//简单的下载面板
|
||||
function gdk_xdltable($atts, $content = null)
|
||||
{
|
||||
extract(shortcode_atts(array(
|
||||
extract(shortcode_atts([
|
||||
'file' => '',
|
||||
'size' => '',
|
||||
), $atts));
|
||||
return '<table class="dltable"><tbody><tr><td style="background-color:#F9F9F9;" rowspan="3"><p>文件下载</p></td><td><i class="fa fa-list-alt"></i> 文件名称:' . $file . '</td><td><i class="fa fa-th-large"></i> 文件大小:' . $size . '</td></tr><tr><td colspan="2"><i class="fa fa-volume-up"></i> 下载声明:' . gdk_option('gdk_dltable_b') . '</td></tr><tr><td colspan="2"><i class="fa fa-download"></i> 下载地址:' . $content . '</td></tr></tbody></table>';
|
||||
], $atts));
|
||||
|
||||
return '<table class="dltable"><tbody><tr><td style="background-color:#F9F9F9;" rowspan="3"><p>文件下载</p></td><td><i class="fa fa-list-alt"></i> 文件名称:'.$file.'</td><td><i class="fa fa-th-large"></i> 文件大小:'.$size.'</td></tr><tr><td colspan="2"><i class="fa fa-volume-up"></i> 下载声明:'.gdk_option('gdk_dltable_b').'</td></tr><tr><td colspan="2"><i class="fa fa-download"></i> 下载地址:'.$content.'</td></tr></tbody></table>';
|
||||
}
|
||||
add_shortcode('dltable', 'gdk_xdltable');
|
||||
//网易云音乐
|
||||
function gdk_music163($atts, $content = null)
|
||||
{
|
||||
extract(shortcode_atts(array(
|
||||
extract(shortcode_atts([
|
||||
'play' => '1',
|
||||
), $atts));
|
||||
return '<iframe style="width:100%;max-height:86px;" frameborder="no" border="0" marginwidth="0" marginheight="0" src="http://music.163.com/outchain/player?type=2&id=' . $content . '&auto=' . $play . '&height=66"></iframe>';
|
||||
], $atts));
|
||||
|
||||
return '<iframe style="width:100%;max-height:86px;" frameborder="no" border="0" marginwidth="0" marginheight="0" src="http://music.163.com/outchain/player?type=2&id='.$content.'&auto='.$play.'&height=66"></iframe>';
|
||||
}
|
||||
add_shortcode('netmusic', 'gdk_music163');
|
||||
//登录可见
|
||||
function gdk_login_to_read($atts, $content = null)
|
||||
{
|
||||
$logina = '<a target="_blank" href="' . esc_url(wp_login_url(get_permalink())) . '">登录</a>';
|
||||
extract(shortcode_atts(array(
|
||||
'notice' => '<div class="alert info pull-center"><p class="reply-to-read" style="color: blue;">注意:本段内容须“' . $logina . '”后方可查看!</p></div>',
|
||||
), $atts));
|
||||
$logina = '<a target="_blank" href="'.esc_url(wp_login_url(get_permalink())).'">登录</a>';
|
||||
extract(shortcode_atts([
|
||||
'notice' => '<div class="alert info pull-center"><p class="reply-to-read" style="color: blue;">注意:本段内容须“'.$logina.'”后方可查看!</p></div>',
|
||||
], $atts));
|
||||
if (is_user_logged_in() && !is_null($content) && !is_feed()) {
|
||||
return '<fieldset class="fieldset"><legend class="legend">隐藏内容</legend><p>' . $content . '</p></fieldset>';
|
||||
return '<fieldset class="fieldset"><legend class="legend">隐藏内容</legend><p>'.$content.'</p></fieldset>';
|
||||
}
|
||||
|
||||
return $notice;
|
||||
}
|
||||
add_shortcode('vip', 'gdk_login_to_read');
|
||||
|
@ -220,8 +228,9 @@ function gdk_secret_view($atts, $content = null)
|
|||
$pid = get_the_ID();
|
||||
add_post_meta($pid, '_pass_content', $content, true) or update_post_meta($pid, '_pass_content', $content);
|
||||
if (current_user_can('administrator')) {
|
||||
return '<fieldset class="fieldset"><legend class="legend">隐藏内容</legend><p>' . $content . '</p></fieldset>';
|
||||
return '<fieldset class="fieldset"><legend class="legend">隐藏内容</legend><p>'.$content.'</p></fieldset>';
|
||||
} //admin show
|
||||
|
||||
return '<div class="cm-grid cm-card pass_viewbox">
|
||||
<div class="cm-row">
|
||||
<div class="cm-col-md-4">
|
||||
|
@ -230,23 +239,24 @@ function gdk_secret_view($atts, $content = null)
|
|||
<div class="cm-col-md-8" style="margin-top:4%;">
|
||||
<div class="hide_content_info" style="margin:10px 0">
|
||||
<div class="cm-alert primary">本段内容已被隐藏,您需要扫码关注微信公众号申请验证码查看,发送【验证码】获取验证码,验证码2分钟有效</div>
|
||||
<input type="text" id="pass_view" placeholder="输入验证码并提交" style="width:70%"> <input id="submit_pass_view" class="cm-btn success" data-action="gdk_pass_view" data-id="' . $pid . '" type="button" value="提交">
|
||||
<input type="text" id="pass_view" placeholder="输入验证码并提交" style="width:70%"> <input id="submit_pass_view" class="cm-btn success" data-action="gdk_pass_view" data-id="'.$pid.'" type="button" value="提交">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>';
|
||||
|
||||
}
|
||||
add_shortcode('wxcaptcha', 'gdk_secret_view');
|
||||
|
||||
// 支持文章和页面运行PHP代码
|
||||
function gdk_php_include($attr)
|
||||
{
|
||||
$file = $attr['file'];
|
||||
$file = $attr['file'];
|
||||
$upload_dir = wp_upload_dir();
|
||||
$folder = $upload_dir['basedir'] . '/php-content' . "/{$file}.php";
|
||||
$folder = $upload_dir['basedir'].'/php-content'."/{$file}.php";
|
||||
ob_start();
|
||||
|
||||
include $folder;
|
||||
|
||||
return ob_get_clean();
|
||||
}
|
||||
add_shortcode('phpcode', 'gdk_php_include');
|
||||
|
@ -254,26 +264,27 @@ add_shortcode('phpcode', 'gdk_php_include');
|
|||
//给文章加内链短代码
|
||||
function gdk_insert_posts($atts, $content = null)
|
||||
{
|
||||
extract(shortcode_atts(array(
|
||||
extract(shortcode_atts([
|
||||
'ids' => '',
|
||||
), $atts));
|
||||
], $atts));
|
||||
global $post;
|
||||
$content = '';
|
||||
$postids = explode(',', $ids);
|
||||
$inset_posts = get_posts(array(
|
||||
$content = '';
|
||||
$postids = explode(',', $ids);
|
||||
$inset_posts = get_posts([
|
||||
'post__in' => $postids,
|
||||
));
|
||||
]);
|
||||
foreach ($inset_posts as $key => $post) {
|
||||
setup_postdata($post);
|
||||
$content .= '<div class="neilian"><div class="fll"><a target="_blank" href="' . get_permalink() . '" class="fll linkss"><i class="fa fa-link fa-fw"></i> ';
|
||||
$content .= '<div class="neilian"><div class="fll"><a target="_blank" href="'.get_permalink().'" class="fll linkss"><i class="fa fa-link fa-fw"></i> ';
|
||||
$content .= get_the_title();
|
||||
$content .= '</a><p class="note">';
|
||||
$content .= get_the_excerpt();
|
||||
$content .= '</p></div><div class="frr"><a target="_blank" href="' . get_permalink() . '"><img src=';
|
||||
$content .= '</p></div><div class="frr"><a target="_blank" href="'.get_permalink().'"><img src=';
|
||||
$content .= gdk_thumbnail_src();
|
||||
$content .= ' class="neilian-thumb"></a></div></div>';
|
||||
}
|
||||
wp_reset_postdata();
|
||||
|
||||
return $content;
|
||||
}
|
||||
add_shortcode('neilian', 'gdk_insert_posts');
|
||||
|
@ -281,42 +292,42 @@ add_shortcode('neilian', 'gdk_insert_posts');
|
|||
//给文章加内链短代码
|
||||
function gdk_insert_temp($atts, $content = null)
|
||||
{
|
||||
extract(shortcode_atts(array('id' => ''), $atts));
|
||||
$data = get_post($id);
|
||||
$content = $data->post_content;
|
||||
return $content;
|
||||
extract(shortcode_atts(['id' => ''], $atts));
|
||||
$data = get_post($id);
|
||||
|
||||
return $data->post_content;
|
||||
}
|
||||
add_shortcode('temp', 'gdk_insert_temp');
|
||||
|
||||
//快速插入列表
|
||||
function gdk_list_shortcode_handler($atts, $content = '')
|
||||
function gdk_list_shortcode_handler($atts, $content = null)
|
||||
{
|
||||
$content = trim($content);
|
||||
$lists = explode("\n", $content);
|
||||
$output = '';
|
||||
$lists = explode("\n", $content);
|
||||
$output = '';
|
||||
foreach ($lists as $li) {
|
||||
if (trim($li) != '') {
|
||||
if ('' != trim($li)) {
|
||||
$output .= "<li>{$li}</li>";
|
||||
}
|
||||
}
|
||||
$output = "<ul>" . $output . "</ul>\n";
|
||||
return $output;
|
||||
|
||||
return '<ul>'.$output."</ul>\n";
|
||||
}
|
||||
add_shortcode('list', 'gdk_list_shortcode_handler');
|
||||
|
||||
//表格短代码
|
||||
function gdk_table_shortcode_handler($atts, $content = '')
|
||||
function gdk_table_shortcode_handler($atts, $content = null)
|
||||
{
|
||||
extract(shortcode_atts(['width' => '100%'], $atts));
|
||||
$output = '';
|
||||
$output = '';
|
||||
$content = trim($content);
|
||||
$trs = explode("\r\n", $content);
|
||||
$ths = explode(" ", $trs[0]); //表头数组
|
||||
$trs = explode("\r\n", $content);
|
||||
$ths = explode(' ', $trs[0]); //表头数组
|
||||
$output .= '<thead><tr>';
|
||||
//var_dump($ths);
|
||||
foreach ($ths as $th) {
|
||||
$th = trim($th);
|
||||
$output .= '<th>' . $th . '</th>';
|
||||
$output .= '<th>'.$th.'</th>';
|
||||
}
|
||||
$output .= '</tr></thead>';
|
||||
$output .= '<tbody>';
|
||||
|
@ -324,194 +335,204 @@ function gdk_table_shortcode_handler($atts, $content = '')
|
|||
foreach ($trs as $tr) {
|
||||
$tr = trim($tr);
|
||||
if ($tr) {
|
||||
$tds = explode(" ", $tr);
|
||||
$tds = explode(' ', $tr);
|
||||
$output .= '<tr>';
|
||||
foreach ($tds as $td) {
|
||||
$td = trim($td);
|
||||
if ($td) {
|
||||
$output .= '<td>' . $td . '</td>';
|
||||
$output .= '<td>'.$td.'</td>';
|
||||
}
|
||||
}
|
||||
$output .= '</tr>';
|
||||
}
|
||||
}
|
||||
$output .= '</tbody>';
|
||||
$width = ' width="' . $width . '"';
|
||||
$output = '<table class="gdk-table"' . $width . ' >' . $output . '</table>';
|
||||
$width = ' width="'.$width.'"';
|
||||
|
||||
return $output;
|
||||
return '<table class="gdk-table"'.$width.' >'.$output.'</table>';
|
||||
}
|
||||
add_shortcode('table', 'gdk_table_shortcode_handler');
|
||||
|
||||
add_shortcode('youku', function ($atts, $content = '') {
|
||||
extract(shortcode_atts(array(
|
||||
'width' => '510',
|
||||
add_shortcode('youku', function ($atts, $content = null) {
|
||||
extract(shortcode_atts([
|
||||
'width' => '510',
|
||||
'height' => '498',
|
||||
), $atts));
|
||||
], $atts));
|
||||
|
||||
$width = (isset($_GET['width']) && intval($_GET['width'])) ? intval($_GET['width']) : $width; // 用于 JSON 接口
|
||||
$width = (isset($_GET['width']) && intval($_GET['width'])) ? intval($_GET['width']) : $width; // 用于 JSON 接口
|
||||
$height = round($width / 4 * 3);
|
||||
|
||||
if (preg_match('#http://v.youku.com/v_show/id_(.*?).html#i', $content, $matches)) {
|
||||
return '<iframe class="wpjam_video" height=' . esc_attr($height) . ' width=' . esc_attr($width) . ' src="http://player.youku.com/embed/' . esc_attr($matches[1]) . '" frameborder=0 allowfullscreen></iframe>';
|
||||
return '<iframe class="wpjam_video" height='.esc_attr($height).' width='.esc_attr($width).' src="http://player.youku.com/embed/'.esc_attr($matches[1]).'" frameborder=0 allowfullscreen></iframe>';
|
||||
}
|
||||
});
|
||||
|
||||
add_shortcode('qqv', function ($atts, $content = '') {
|
||||
extract(shortcode_atts(array(
|
||||
'width' => '510',
|
||||
extract(shortcode_atts([
|
||||
'width' => '510',
|
||||
'height' => '498',
|
||||
), $atts));
|
||||
], $atts));
|
||||
|
||||
$width = (isset($_GET['width']) && intval($_GET['width'])) ? intval($_GET['width']) : $width; // 用于 JSON 接口
|
||||
$width = (isset($_GET['width']) && intval($_GET['width'])) ? intval($_GET['width']) : $width; // 用于 JSON 接口
|
||||
$height = round($width / 4 * 3);
|
||||
|
||||
if (preg_match('#//v.qq.com/iframe/player.html\?vid=(.+)#i', $content, $matches)) {
|
||||
//var_dump($matches);exit();
|
||||
return '<iframe class="wpjam_video" height=' . esc_attr($height) . ' width=' . esc_attr($width) . ' src="http://v.qq.com/iframe/player.html?vid=' . esc_attr($matches[1]) . '" frameborder=0 allowfullscreen></iframe>';
|
||||
} elseif (preg_match('#//v.qq.com/iframe/preview.html\?vid=(.+)#i', $content, $matches)) {
|
||||
return '<iframe class="wpjam_video" height='.esc_attr($height).' width='.esc_attr($width).' src="http://v.qq.com/iframe/player.html?vid='.esc_attr($matches[1]).'" frameborder=0 allowfullscreen></iframe>';
|
||||
}
|
||||
if (preg_match('#//v.qq.com/iframe/preview.html\?vid=(.+)#i', $content, $matches)) {
|
||||
//var_dump($matches);exit();
|
||||
return '<iframe class="wpjam_video" height=' . esc_attr($height) . ' width=' . esc_attr($width) . ' src="http://v.qq.com/iframe/player.html?vid=' . esc_attr($matches[1]) . '" frameborder=0 allowfullscreen></iframe>';
|
||||
return '<iframe class="wpjam_video" height='.esc_attr($height).' width='.esc_attr($width).' src="http://v.qq.com/iframe/player.html?vid='.esc_attr($matches[1]).'" frameborder=0 allowfullscreen></iframe>';
|
||||
}
|
||||
});
|
||||
|
||||
add_shortcode('tudou', function ($atts, $content = '') {
|
||||
extract(shortcode_atts(array(
|
||||
'width' => '480',
|
||||
extract(shortcode_atts([
|
||||
'width' => '480',
|
||||
'height' => '400',
|
||||
), $atts));
|
||||
], $atts));
|
||||
|
||||
$width = (isset($_GET['width']) && intval($_GET['width'])) ? intval($_GET['width']) : $width; // 用于 JSON 接口
|
||||
$width = (isset($_GET['width']) && intval($_GET['width'])) ? intval($_GET['width']) : $width; // 用于 JSON 接口
|
||||
$height = round($width / 4 * 3);
|
||||
|
||||
if (preg_match('#http://www.tudou.com/programs/view/(.*?)#i', $content, $matches)) {
|
||||
return '<iframe class="wpjam_video" width=' . esc_attr($width) . ' height=' . esc_attr($height) . ' src="http://www.tudou.com/programs/view/html5embed.action?code=' . esc_attr($matches[1]) . '" frameborder=0 allowfullscreen></iframe>';
|
||||
return '<iframe class="wpjam_video" width='.esc_attr($width).' height='.esc_attr($height).' src="http://www.tudou.com/programs/view/html5embed.action?code='.esc_attr($matches[1]).'" frameborder=0 allowfullscreen></iframe>';
|
||||
}
|
||||
});
|
||||
|
||||
add_shortcode('sohutv', function ($atts, $content = '') {
|
||||
extract(shortcode_atts(array(
|
||||
'width' => '510',
|
||||
extract(shortcode_atts([
|
||||
'width' => '510',
|
||||
'height' => '498',
|
||||
), $atts));
|
||||
], $atts));
|
||||
|
||||
$width = (isset($_GET['width']) && intval($_GET['width'])) ? intval($_GET['width']) : $width; // 用于 JSON 接口
|
||||
$width = (isset($_GET['width']) && intval($_GET['width'])) ? intval($_GET['width']) : $width; // 用于 JSON 接口
|
||||
$height = round($width / 4 * 3);
|
||||
|
||||
if (preg_match('#http://tv.sohu.com/upload/static/share/share_play.html\#(.+)#i', $content, $matches)) {
|
||||
//var_dump($matches);exit();
|
||||
return '<iframe class="wpjam_video" height=' . esc_attr($height) . ' width=' . esc_attr($width) . ' src="http://tv.sohu.com/upload/static/share/share_play.html#' . esc_attr($matches[1]) . '" frameborder=0 allowfullscreen></iframe>';
|
||||
return '<iframe class="wpjam_video" height='.esc_attr($height).' width='.esc_attr($width).' src="http://tv.sohu.com/upload/static/share/share_play.html#'.esc_attr($matches[1]).'" frameborder=0 allowfullscreen></iframe>';
|
||||
}
|
||||
});
|
||||
|
||||
//付费可见短代码
|
||||
function gdk_pay_nologin($atts, $content = '')
|
||||
{
|
||||
$content = do_shortcode($content);
|
||||
extract(shortcode_atts(array('money' => '1'), $atts));
|
||||
$content = do_shortcode($content);
|
||||
extract(shortcode_atts(['money' => '1'], $atts));
|
||||
$pid = get_the_ID(); //文章ID
|
||||
add_post_meta($pid, '_pay_content', $content, true) or update_post_meta($pid, '_pay_content', $content); //没有新建,有就更新
|
||||
if (current_user_can('administrator')) {
|
||||
return '<fieldset class="fieldset"><legend class="legend">隐藏内容</legend><p>' . $content . '</p></fieldset>';
|
||||
return '<fieldset class="fieldset"><legend class="legend">隐藏内容</legend><p>'.$content.'</p></fieldset>';
|
||||
} //admin show
|
||||
$pay_log = get_post_meta($pid, 'pay_log', true); //购买记录数据
|
||||
$pay_arr = explode(",", $pay_log);
|
||||
$pay_log = get_post_meta($pid, 'pay_log', true); //购买记录数据
|
||||
$pay_arr = explode(',', $pay_log);
|
||||
$pay_count = count($pay_arr); //已购买人数
|
||||
$notice = '<fieldset id="hide_notice" class="fieldset ta-center"><legend class="legend ta-left">付费内容</legend>';
|
||||
$notice .= '<p>当前隐藏内容需要支付</p><span class="cm-coin">' . $money . '元</span>';
|
||||
$notice .= '<p>已有<span class="red">' . $pay_count . '</span>人支付</p>';
|
||||
$notice .= '<p><button id="pay_view" type="button" data-action="pay_view" data-money="' . $money . '" data-id="' . $pid . '">立即查看</button></p>';
|
||||
$notice = '<fieldset id="hide_notice" class="fieldset ta-center"><legend class="legend ta-left">付费内容</legend>';
|
||||
$notice .= '<p>当前隐藏内容需要支付</p><span class="cm-coin">'.$money.'元</span>';
|
||||
$notice .= '<p>已有<span class="red">'.$pay_count.'</span>人支付</p>';
|
||||
$notice .= '<p><button id="pay_view" type="button" data-action="pay_view" data-money="'.$money.'" data-id="'.$pid.'">立即查看</button></p>';
|
||||
$notice .= '</fieldset>';
|
||||
|
||||
return $notice;
|
||||
}
|
||||
add_shortcode('pax', 'gdk_pay_nologin');
|
||||
|
||||
function box_shortcode($atts, $content = null)
|
||||
{
|
||||
extract(
|
||||
shortcode_atts([
|
||||
's' => '1',
|
||||
], $atts)
|
||||
);
|
||||
|
||||
function box_shortcode( $atts, $content = null ) {
|
||||
extract(
|
||||
shortcode_atts(array(
|
||||
's' => '1'
|
||||
), $atts));
|
||||
if ('1' == $s) {
|
||||
$box_classes = 'c1_4 aside';
|
||||
}
|
||||
if ('2' == $s) {
|
||||
$box_classes = 'c2_4 main';
|
||||
}
|
||||
if ('3' == $s) {
|
||||
$box_classes = 'c3_4';
|
||||
}
|
||||
if ('4' == $s) {
|
||||
$box_classes = 'c4_4';
|
||||
}
|
||||
|
||||
if($s == '1') { $box_classes = 'c1_4 aside'; }
|
||||
if($s == '2') { $box_classes = 'c2_4 main'; }
|
||||
if($s == '3') { $box_classes = 'c3_4'; }
|
||||
if($s == '4') { $box_classes = 'c4_4'; }
|
||||
|
||||
return '<section class="' . $box_classes . '">' . $content . '</section>';
|
||||
return '<section class="'.$box_classes.'">'.$content.'</section>';
|
||||
}
|
||||
add_shortcode( 'b', 'box_shortcode' );
|
||||
add_shortcode('b', 'box_shortcode');
|
||||
|
||||
function contentblock_shortcode( $atts, $content = null ) {
|
||||
return '<div class="inner">' . do_shortcode($content) . '</div>';
|
||||
function contentblock_shortcode($atts, $content = null)
|
||||
{
|
||||
return '<div class="inner">'.do_shortcode($content).'</div>';
|
||||
}
|
||||
add_shortcode( 'cb', 'contentblock_shortcode' );
|
||||
|
||||
add_shortcode('cb', 'contentblock_shortcode');
|
||||
|
||||
//WordPress 段代码按钮集合
|
||||
function gdk_shortcode_list()
|
||||
{
|
||||
$wpshortcodes = [
|
||||
'横线' => '<hr />',
|
||||
'H3标题' => '<h3> </h3>',
|
||||
'记号笔' => '<mark> </mark>',
|
||||
'链接按钮' => '[dm href=] [/dm]',
|
||||
'下载按钮' => '[dl href=] [/dl]',
|
||||
'透明按钮' => '[lhb href=] [/lhb]',
|
||||
'视频按钮' => '[video play=0] [/video]',
|
||||
'音频按钮' => '[audio play=0] [/audio]',
|
||||
'绿色通知' => '[v_notice]
|
||||
'横线' => '<hr />',
|
||||
'H3标题' => '<h3> </h3>',
|
||||
'记号笔' => '<mark> </mark>',
|
||||
'链接按钮' => '[dm href=] [/dm]',
|
||||
'下载按钮' => '[dl href=] [/dl]',
|
||||
'透明按钮' => '[lhb href=] [/lhb]',
|
||||
'视频按钮' => '[video play=0] [/video]',
|
||||
'音频按钮' => '[audio play=0] [/audio]',
|
||||
'绿色通知' => '[v_notice]
|
||||
|
||||
[/v_notice]',
|
||||
'红色警告' => '[v_error]
|
||||
'红色警告' => '[v_error]
|
||||
|
||||
[/v_error]',
|
||||
'黄色错误' => '[v_warn]
|
||||
'黄色错误' => '[v_warn]
|
||||
|
||||
[/v_warn]',
|
||||
'蓝色提示' => '[v_blue]
|
||||
'蓝色提示' => '[v_blue]
|
||||
|
||||
[/v_blue]',
|
||||
'默认提示' => '[v_tips]
|
||||
'默认提示' => '[v_tips]
|
||||
|
||||
[/v_tips]',
|
||||
'隐藏收缩' => '[collapse title=\'\']
|
||||
'隐藏收缩' => '[collapse title=\'\']
|
||||
|
||||
[/collapse]',
|
||||
'回复可见' => '[reply]
|
||||
'回复可见' => '[reply]
|
||||
|
||||
[/reply]',
|
||||
'登陆可见' => '[vip]
|
||||
'登陆可见' => '[vip]
|
||||
|
||||
[/vip]',
|
||||
'微信验证码可见' => '[wxcaptcha]
|
||||
|
||||
[/wxcaptcha]',
|
||||
'积分购买可见' => '[pay point=\'10\']这里是需要付费的内容[/pay]',
|
||||
'游客付费可见' => '[pax money=1]
|
||||
'积分购买可见' => '[pay point=\'10\']这里是需要付费的内容[/pay]',
|
||||
'游客付费可见' => '[pax money=1]
|
||||
|
||||
[/pax]',
|
||||
'弹窗下载' => '[fanctdl filename=\'这里填写文件名\' filepass=\'这里填写文件密码什么的\' href=\'这里填写的主下载链接\' filedown=\'这里填写的是文件的主下载名称\']这里填写的文件的辅助下载链接,可写多个,空格间隔[/fanctdl]',
|
||||
'面板下载' => '[dltable file=\'在此处写下文件名称\' pass=\'在这里写下文件密码\']这里填写的文件的辅助下载链接,可写多个,空格间隔[/dltable]',
|
||||
'单页下载' => '[pdownload title=点击下载]',
|
||||
'文章内链' => '[neilian ids=]',
|
||||
'无序列表' => '[list]
|
||||
'弹窗下载' => '[fanctdl filename=\'这里填写文件名\' filepass=\'这里填写文件密码什么的\' href=\'这里填写的主下载链接\' filedown=\'这里填写的是文件的主下载名称\']这里填写的文件的辅助下载链接,可写多个,空格间隔[/fanctdl]',
|
||||
'面板下载' => '[dltable file=\'在此处写下文件名称\' pass=\'在这里写下文件密码\']这里填写的文件的辅助下载链接,可写多个,空格间隔[/dltable]',
|
||||
'单页下载' => '[pdownload title=点击下载]',
|
||||
'文章内链' => '[neilian ids=]',
|
||||
'无序列表' => '[list]
|
||||
|
||||
[/list]',
|
||||
'表格简码' => '[table]
|
||||
'表格简码' => '[table]
|
||||
|
||||
[/table]',
|
||||
];
|
||||
$output = '';
|
||||
foreach ($wpshortcodes as $name => $alt) {
|
||||
$output .= '<a class="add-shortcode ed_button button button-small" data-shortcodes="' . $alt . '">' . $name . '</a>';
|
||||
$output .= '<a class="add-shortcode ed_button button button-small" data-shortcodes="'.$alt.'">'.$name.'</a>';
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
function gdk_shortcode_button()
|
||||
{
|
||||
$context = '<a class="button insert-shortcodes" title="添加简码" data-editor="content" href="javascript:;"><span class="dashicons dashicons-twitter shortcodes-icon"></span>短代码</a><div class="shortcodes-wrap">' . gdk_shortcode_list() . '</div>';
|
||||
echo $context;
|
||||
echo '<a class="button insert-shortcodes" title="添加简码" data-editor="content" href="javascript:;"><span class="dashicons dashicons-twitter shortcodes-icon"></span>短代码</a><div class="shortcodes-wrap">'.gdk_shortcode_list().'</div>';
|
||||
}
|
||||
add_action('media_buttons', 'gdk_shortcode_button');
|
||||
|
|
|
@ -6,59 +6,57 @@ function gdk_reset_password_message($message, $key)
|
|||
if (strpos($_POST['user_login'], '@')) {
|
||||
$user_data = get_user_by('email', trim($_POST['user_login']));
|
||||
} else {
|
||||
$login = trim($_POST['user_login']);
|
||||
$login = trim($_POST['user_login']);
|
||||
$user_data = get_user_by('login', $login);
|
||||
}
|
||||
$user_login = $user_data->user_login;
|
||||
$msg = "有人要求重设如下帐号的密码:\r\n\r\n";
|
||||
$msg .= network_site_url() . "\r\n\r\n";
|
||||
$msg .= sprintf('用户名:%s', $user_login) . "\r\n\r\n";
|
||||
$msg = "有人要求重设如下帐号的密码:\r\n\r\n";
|
||||
$msg .= network_site_url()."\r\n\r\n";
|
||||
$msg .= sprintf('用户名:%s', $user_login)."\r\n\r\n";
|
||||
$msg .= "若这不是您本人要求的,请忽略本邮件,一切如常。\r\n\r\n";
|
||||
$msg .= "要重置您的密码,请打开下面的链接:\r\n\r\n";
|
||||
$msg .= wp_login_url() . "?action=rp&key=$key&login=" . rawurlencode($user_login);
|
||||
$msg .= wp_login_url()."?action=rp&key={$key}&login=".rawurlencode($user_login);
|
||||
|
||||
return $msg;
|
||||
}
|
||||
add_filter('retrieve_password_message', 'gdk_reset_password_message', null, 2);
|
||||
|
||||
if (!defined('UM_DIR')) { /*判断是否按照UM插件*/
|
||||
if (!defined('UM_DIR')) { // 判断是否按照UM插件
|
||||
//注册表单
|
||||
function gdk_show_extra_register_fields()
|
||||
{
|
||||
?>
|
||||
<p>
|
||||
<label for="password">密码<br/>
|
||||
<input id="password" class="input" type="password" tabindex="30" size="25" value="" name="password" />
|
||||
<p>
|
||||
<label for="password">密码<br />
|
||||
<input id="password" class="input" type="password" tabindex="30" size="25" value="" name="password" />
|
||||
</label>
|
||||
</p>
|
||||
<p>
|
||||
<label for="repeat_password">确认密码<br/>
|
||||
<input id="repeat_password" class="input" type="password" tabindex="40" size="25" value="" name="repeat_password" />
|
||||
</p>
|
||||
<p>
|
||||
<label for="repeat_password">确认密码<br />
|
||||
<input id="repeat_password" class="input" type="password" tabindex="40" size="25" value=""
|
||||
name="repeat_password" />
|
||||
</label>
|
||||
</p>
|
||||
<?php
|
||||
}
|
||||
</p>
|
||||
<?php
|
||||
}
|
||||
add_action('register_form', 'gdk_show_extra_register_fields');
|
||||
/*
|
||||
* Check the form for errors
|
||||
*/
|
||||
function gdk_check_extra_register_fields($login, $email, $errors)
|
||||
// Check the form for errors
|
||||
function gdk_order_check_extra_register_fields($login, $email, $errors)
|
||||
{
|
||||
if ($_POST['password'] !== $_POST['repeat_password']) {
|
||||
$errors->add('passwords_not_matched', "<strong>错误提示</strong>: 两次填写密码不一致");
|
||||
$errors->add('passwords_not_matched', '<strong>错误提示</strong>: 两次填写密码不一致');
|
||||
}
|
||||
if (strlen($_POST['password']) < 8) {
|
||||
$errors->add('password_too_short', "<strong>错误提示</strong>: 密码必须大于8个字符");
|
||||
$errors->add('password_too_short', '<strong>错误提示</strong>: 密码必须大于8个字符');
|
||||
}
|
||||
}
|
||||
add_action('register_post', 'gdk_check_extra_register_fields', 10, 3);
|
||||
/*
|
||||
* 提交用户密码进数据库
|
||||
*/
|
||||
add_action('register_post', 'gdk_order_check_extra_register_fields', 10, 3);
|
||||
// 提交用户密码进数据库
|
||||
function gdk_register_extra_fields($user_id)
|
||||
{
|
||||
$userdata = array();
|
||||
$userdata = [];
|
||||
$userdata['ID'] = $user_id;
|
||||
if ($_POST['password'] !== '') {
|
||||
if ('' !== $_POST['password']) {
|
||||
$userdata['user_pass'] = $_POST['password'];
|
||||
}
|
||||
$pattern = '/[一-龥]/u';
|
||||
|
@ -76,7 +74,7 @@ if (gdk_option('gdk_login_verify')) {
|
|||
{
|
||||
$num1 = mt_rand(0, 20);
|
||||
$num2 = mt_rand(0, 20);
|
||||
echo "<p><label for='sum'> {$num1} + {$num2} = ?<br /><input type='text' name='sum' class='input' value='' size='25' tabindex='4'>" . "<input type='hidden' name='num1' value='{$num1}'>" . "<input type='hidden' name='num2' value='{$num2}'></label></p>";
|
||||
echo "<p><label for='sum'> {$num1} + {$num2} = ?<br /><input type='text' name='sum' class='input' value='' size='25' tabindex='4'>"."<input type='hidden' name='num1' value='{$num1}'>"."<input type='hidden' name='num2' value='{$num2}'></label></p>";
|
||||
}
|
||||
add_action('login_form', 'gdk_login_verify');
|
||||
add_action('register_form', 'gdk_login_verify');
|
||||
|
@ -84,12 +82,16 @@ if (gdk_option('gdk_login_verify')) {
|
|||
function gdk_login_verify_val()
|
||||
{
|
||||
$sum = $_POST['sum'];
|
||||
|
||||
switch ($sum) {
|
||||
case $_POST['num1'] + $_POST['num2']:
|
||||
break;
|
||||
|
||||
case null:
|
||||
wp_die('错误: 请输入验证码 <a href="javascript:;" onclick="javascript:history.back();">返回上页</a>');
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
wp_die('错误: 验证码错误,请重试 <a href="javascript:;" onclick="javascript:history.back();">返回上页</a>');
|
||||
}
|
||||
|
@ -101,7 +103,7 @@ if (gdk_option('gdk_login_verify')) {
|
|||
//仅显示作者自己的文章
|
||||
function gdk_show_mypost($wp_query)
|
||||
{
|
||||
if (strpos($_SERVER['REQUEST_URI'], '/wp-admin/edit.php') !== false) {
|
||||
if (false !== strpos($_SERVER['REQUEST_URI'], '/wp-admin/edit.php')) {
|
||||
if (!current_user_can('manage_options')) {
|
||||
$wp_query->set('author', get_current_user_id());
|
||||
}
|
||||
|
@ -117,22 +119,20 @@ function gdk_show_myupload($wp_query_obj)
|
|||
return;
|
||||
}
|
||||
|
||||
if ('admin-ajax.php' != $pagenow || $_REQUEST['action'] != 'query-attachments') {
|
||||
if ('admin-ajax.php' != $pagenow || 'query-attachments' != $_REQUEST['action']) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!current_user_can('manage_options') && !current_user_can('manage_media_library')) {
|
||||
$wp_query_obj->set('author', get_current_user_id());
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
add_action('pre_get_posts', 'gdk_show_myupload');
|
||||
|
||||
//在[媒体库]只显示用户上传的文件
|
||||
function gdk_show_myupload_library($wp_query)
|
||||
{
|
||||
if (strpos($_SERVER['REQUEST_URI'], '/wp-admin/upload.php') !== false) {
|
||||
if (false !== strpos($_SERVER['REQUEST_URI'], '/wp-admin/upload.php')) {
|
||||
if (!current_user_can('manage_options') && !current_user_can('manage_media_library')) {
|
||||
$wp_query->set('author', get_current_user_id());
|
||||
}
|
||||
|
@ -143,12 +143,11 @@ add_filter('parse_query', 'gdk_show_myupload_library');
|
|||
//添加后台个人信息
|
||||
function gdk_contact_fields($contactmethods)
|
||||
{
|
||||
$contactmethods['qq'] = 'QQ';
|
||||
$contactmethods['qq'] = 'QQ';
|
||||
$contactmethods['sina_weibo'] = '新浪微博';
|
||||
$contactmethods['weixin'] = '微信';
|
||||
unset($contactmethods['yim']);
|
||||
unset($contactmethods['aim']);
|
||||
unset($contactmethods['jabber']);
|
||||
$contactmethods['weixin'] = '微信';
|
||||
unset($contactmethods['yim'], $contactmethods['aim'], $contactmethods['jabber']);
|
||||
|
||||
return $contactmethods;
|
||||
}
|
||||
add_filter('user_contactmethods', 'gdk_contact_fields');
|
||||
|
@ -164,8 +163,8 @@ function gdk_sanitize_user($username, $raw_username, $strict)
|
|||
$username = preg_replace('|[^a-z\p{Han}0-9 _.\-@]|iu', '', $username);
|
||||
}
|
||||
$username = trim($username);
|
||||
$username = preg_replace('|\s+|', ' ', $username);
|
||||
return $username;
|
||||
|
||||
return preg_replace('|\s+|', ' ', $username);
|
||||
}
|
||||
add_filter('sanitize_user', 'gdk_sanitize_user', 10, 3);
|
||||
|
||||
|
@ -173,12 +172,13 @@ add_filter('sanitize_user', 'gdk_sanitize_user', 10, 3);
|
|||
function gdk_userid_column($cols)
|
||||
{
|
||||
$cols['ssid'] = 'ID';
|
||||
|
||||
return $cols;
|
||||
}
|
||||
add_action('manage_users_columns', 'gdk_userid_column');
|
||||
function gdk_userid_value($value, $column_name, $id)
|
||||
{
|
||||
if ($column_name == 'ssid') {
|
||||
if ('ssid' == $column_name) {
|
||||
$value = $id;
|
||||
}
|
||||
|
||||
|
@ -191,12 +191,13 @@ add_filter('manage_users_columns', 'gdk_add_user_nickname');
|
|||
function gdk_add_user_nickname($columns)
|
||||
{
|
||||
$columns['user_nickname'] = '昵称';
|
||||
|
||||
return $columns;
|
||||
}
|
||||
add_action('manage_users_custom_column', 'gdk_show_user_nickname_val', 20, 3);
|
||||
function gdk_show_user_nickname_val($value, $column_name, $user_id)
|
||||
{
|
||||
$user = get_userdata($user_id);
|
||||
$user = get_userdata($user_id);
|
||||
$user_nickname = $user->nickname;
|
||||
if ('user_nickname' == $column_name) {
|
||||
return $user_nickname;
|
||||
|
@ -209,20 +210,20 @@ add_filter('manage_users_columns', 'gdk_points_columns');
|
|||
function gdk_points_columns($columns)
|
||||
{
|
||||
$columns['points'] = '金币';
|
||||
|
||||
return $columns;
|
||||
}
|
||||
function gdk_points_value($value, $column_name, $user_id)
|
||||
{
|
||||
if ($column_name == 'points') {
|
||||
if ('points' == $column_name) {
|
||||
$jinbi = GDK_Points::get_user_total_points($user_id, 'accepted');
|
||||
if ($jinbi != "") {
|
||||
$ret = $jinbi;
|
||||
return $ret;
|
||||
} else {
|
||||
$ret = '暂无充值';
|
||||
return $ret;
|
||||
if ('' != $jinbi) {
|
||||
return $jinbi;
|
||||
}
|
||||
|
||||
return '暂无充值';
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
add_action('manage_users_custom_column', 'gdk_points_value', 10, 3);
|
||||
|
@ -231,25 +232,25 @@ add_action('manage_users_custom_column', 'gdk_points_value', 10, 3);
|
|||
function gdk_users_comments($columns)
|
||||
{
|
||||
$columns['comments'] = '评论';
|
||||
|
||||
return $columns;
|
||||
}
|
||||
add_filter('manage_users_columns', 'gdk_users_comments');
|
||||
function gdk_show_users_comments($value, $column_name, $user_id)
|
||||
{
|
||||
if ($column_name == 'comments') {
|
||||
$comments_counts = get_comments(array(
|
||||
'status' => '1',
|
||||
if ('comments' == $column_name) {
|
||||
$comments_counts = get_comments([
|
||||
'status' => '1',
|
||||
'user_id' => $user_id,
|
||||
'count' => true,
|
||||
));
|
||||
if ($comments_counts != "") {
|
||||
$ret = $comments_counts;
|
||||
return $ret;
|
||||
} else {
|
||||
$ret = '暂未评论';
|
||||
return $ret;
|
||||
'count' => true,
|
||||
]);
|
||||
if ('' != $comments_counts) {
|
||||
return $comments_counts;
|
||||
}
|
||||
|
||||
return '暂未评论';
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
add_action('manage_users_custom_column', 'gdk_show_users_comments', 10, 3);
|
||||
|
@ -264,21 +265,21 @@ add_action('user_register', 'gdk_log_ip');
|
|||
function gdk_signup_ip($column_headers)
|
||||
{
|
||||
$column_headers['signup_ip'] = 'IP地址';
|
||||
|
||||
return $column_headers;
|
||||
}
|
||||
add_filter('manage_users_columns', 'gdk_signup_ip');
|
||||
function gdk_ripms_columns($value, $column_name, $user_id)
|
||||
{
|
||||
if ($column_name == 'signup_ip') {
|
||||
if ('signup_ip' == $column_name) {
|
||||
$ip = get_user_meta($user_id, 'signup_ip', true);
|
||||
if ($ip != "") {
|
||||
$ret = $ip;
|
||||
return $ret;
|
||||
} else {
|
||||
$ret = '没有记录';
|
||||
return $ret;
|
||||
if ('' != $ip) {
|
||||
return $ip;
|
||||
}
|
||||
|
||||
return '没有记录';
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
add_action('manage_users_custom_column', 'gdk_ripms_columns', 10, 3);
|
||||
|
@ -294,22 +295,22 @@ function gdk_add_last_login_column($columns)
|
|||
{
|
||||
$columns['last_login'] = '上次登录';
|
||||
unset($columns['name']);
|
||||
|
||||
return $columns;
|
||||
}
|
||||
add_filter('manage_users_columns', 'gdk_add_last_login_column');
|
||||
// 显示登录时间到新增栏目
|
||||
function gdk_add_last_login($value, $column_name, $user_id)
|
||||
{
|
||||
if ($column_name == 'last_login') {
|
||||
if ('last_login' == $column_name) {
|
||||
$login = get_user_meta($user_id, 'last_login', true);
|
||||
if ($login != "") {
|
||||
$ret = $login;
|
||||
return $ret;
|
||||
} else {
|
||||
$ret = '暂未登录';
|
||||
return $ret;
|
||||
if ('' != $login) {
|
||||
return $login;
|
||||
}
|
||||
|
||||
return '暂未登录';
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
add_action('manage_users_custom_column', 'gdk_add_last_login', 10, 3);
|
|
@ -4,8 +4,8 @@ add_action('template_redirect', 'gdk_edl_redirect');
|
|||
|
||||
function gdk_edl_redirect()
|
||||
{
|
||||
global $wp, $wp_query;
|
||||
$b = $wp_query->query_vars['dl'] ?? '';
|
||||
global $wp_query;
|
||||
$b = $wp_query->query_vars['dl'] ?? null;
|
||||
if ($b) {
|
||||
gdk_edl();
|
||||
exit;
|
||||
|
@ -16,7 +16,7 @@ function gdk_edl_redirect()
|
|||
function gdk_edl()
|
||||
{
|
||||
header('Content-type: text/html; charset=utf-8');
|
||||
$pid = isset($_GET['dl']) ? trim(htmlspecialchars($_GET['dl'], ENT_QUOTES)) : '';
|
||||
$pid = isset($_GET['dl']) ? trim(htmlspecialchars($_GET['dl'], ENT_QUOTES)) : null;
|
||||
if (!$pid) {
|
||||
wp_die('<h1>下载页面不是直接打开的哦</h1>');
|
||||
}
|
||||
|
@ -63,7 +63,7 @@ function gdk_edl()
|
|||
</div>
|
||||
</nav>
|
||||
|
||||
<div class="page-header header-filter" filter-color="purple" style="background-image: url(<?php echo get_bing_img(); ?>); background-size: cover; background-position: top center;">
|
||||
<div class="page-header header-filter" filter-color="purple" style="background-image: url(<?php echo gdk_get_bing_img(); ?>); background-size: cover; background-position: top center;">
|
||||
<div class="container" >
|
||||
<div class="row" id="important">
|
||||
<div class="col-md-12 ml-auto mr-auto ml-up">
|
||||
|
|
|
@ -18,7 +18,7 @@ if (in_string($userid, 'PP')) { //免登陆支付,插入缓存,然后直接停
|
|||
exit;
|
||||
}
|
||||
|
||||
if (gdk_check($data['out_trade_no']) !== 0) {
|
||||
if (gdk_order_check($data['out_trade_no']) !== 0) {
|
||||
exit('Repeat push');
|
||||
}
|
||||
//在入库前,数据库不应该有同样的订单号
|
||||
|
@ -35,11 +35,11 @@ $point_number = $money * gdk_option('gdk_rate');
|
|||
$headers = "Content-Type:text/html;charset=UTF-8\n";
|
||||
$mail_title = '尊敬的' . $user->display_name . ',您好!';
|
||||
$mail_cotent = '<p>您的金币充值已成功到账,请查收!</p><p>金币充值金额为:' . $user->display_name . '</p><p>如果您的金币金额有异常,请您在第一时间和我们取得联系哦,联系邮箱:' . get_bloginfo('admin_email') . '</p>';
|
||||
$message = mail_temp($mail_title, $mail_cotent, home_url(), get_bloginfo('name'));
|
||||
$message = gdk_mail_temp($mail_title, $mail_cotent, home_url(), get_bloginfo('name'));
|
||||
GDK_Points::set_points($point_number, $userid, array('description' => $orderid, 'status' => 'accepted'));
|
||||
//增加金币金币
|
||||
wp_mail($user->user_email, 'Hi,' . $user->display_name . ',充值成功到账通知!', $message, $headers);
|
||||
$mail_admin_cotent = '<p>充值订单</p><p>用户ID:' . $userid . '</p><p>用户名:' . $user->display_name . '</p><p>金额:' . $money . '元</p>';
|
||||
$admin_notice = mail_temp('站长你好', $mail_admin_cotent, home_url(), get_bloginfo('name'));
|
||||
$admin_notice = gdk_mail_temp('站长你好', $mail_admin_cotent, home_url(), get_bloginfo('name'));
|
||||
wp_mail(get_bloginfo('admin_email'), '【收款成功】网站充值订单已完成', $admin_notice, $headers);
|
||||
//more
|
||||
|
|
Loading…
Reference in a new issue