mirror of
https://github.com/yunluo/gdk.git
synced 2024-05-07 00:36:45 +02:00
格式化代码
This commit is contained in:
parent
e3e72cefdb
commit
e1bc9ddd61
|
@ -1,49 +1,49 @@
|
|||
<?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);
|
||||
wp_enqueue_script('paste-upload-image');
|
||||
wp_localize_script('paste-upload-image', 'pui_vars', array('pui_nonce' => wp_create_nonce('pui-nonce')));
|
||||
}
|
||||
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);
|
||||
wp_enqueue_script('paste-upload-image');
|
||||
wp_localize_script('paste-upload-image', 'pui_vars', array('pui_nonce' => wp_create_nonce('pui-nonce')));
|
||||
}
|
||||
}
|
||||
add_action('admin_enqueue_scripts', 'gdk_admin_enqueue_script');
|
||||
|
||||
|
||||
function gdk_enqueue_script_frontend() {
|
||||
function gdk_enqueue_script_frontend()
|
||||
{
|
||||
if (!is_admin()) {
|
||||
wp_enqueue_style( 'pure_css', 'https://cdn.jsdelivr.net/npm/css-mint@2.0.7/build/css-mint.min.css', false, GDK_PLUGIN_VER, 'all' );
|
||||
wp_enqueue_style( 'font-awesome', GDK_BASE_URL.'assets/css/font-awesome.min.css', false, GDK_PLUGIN_VER, 'all' );
|
||||
wp_enqueue_style('pure_css', 'https://cdn.jsdelivr.net/npm/css-mint@2.0.7/build/css-mint.min.css', false, GDK_PLUGIN_VER, 'all');
|
||||
wp_enqueue_style('font-awesome', GDK_BASE_URL . 'assets/css/font-awesome.min.css', false, GDK_PLUGIN_VER, 'all');
|
||||
//wp_enqueue_style( 'milligram_css', GDK_BASE_URL.'assets/css/milligram.min.css', false, GDK_PLUGIN_VER, 'all' );
|
||||
wp_enqueue_style( 'gdk_css', GDK_BASE_URL.'assets/css/gdk.css', false, GDK_PLUGIN_VER, 'all' );
|
||||
wp_enqueue_style('gdk_css', 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@2.1.0/dist/jquery.min.js', false, GDK_PLUGIN_VER, true);//加载自定义jQuery2.0.3
|
||||
wp_enqueue_script('code_prettify_js', GDK_BASE_URL.'assets/js/prettify.min.js', array('jquery'), GDK_PLUGIN_VER, true);
|
||||
wp_enqueue_script('fancybox_js', GDK_BASE_URL.'assets/js/fancybox.min.js', array('jquery'), GDK_PLUGIN_VER, true);
|
||||
wp_enqueue_script('lazyload_js', GDK_BASE_URL.'assets/js/lazyload.min.js', array('jquery'), GDK_PLUGIN_VER, true);
|
||||
wp_enqueue_script('sweetalert_js','https://cdn.jsdelivr.net/combine/npm/sweetalert@2.0.0,npm/qrious@4.0.2', [], GDK_PLUGIN_VER, true);
|
||||
wp_enqueue_script('gdk_js', GDK_BASE_URL.'assets/js/gdk.js', array('jquery'), GDK_PLUGIN_VER, true);
|
||||
wp_enqueue_script('jquery', 'https://cdn.jsdelivr.net/npm/jquery@2.1.0/dist/jquery.min.js', false, GDK_PLUGIN_VER, true); //加载自定义jQuery2.0.3
|
||||
wp_enqueue_script('code_prettify_js', GDK_BASE_URL . 'assets/js/prettify.min.js', array('jquery'), GDK_PLUGIN_VER, true);
|
||||
wp_enqueue_script('fancybox_js', GDK_BASE_URL . 'assets/js/fancybox.min.js', array('jquery'), GDK_PLUGIN_VER, true);
|
||||
wp_enqueue_script('lazyload_js', GDK_BASE_URL . 'assets/js/lazyload.min.js', array('jquery'), GDK_PLUGIN_VER, true);
|
||||
wp_enqueue_script('sweetalert_js', 'https://cdn.jsdelivr.net/combine/npm/sweetalert@2.0.0,npm/qrious@4.0.2', [], GDK_PLUGIN_VER, true);
|
||||
wp_enqueue_script('gdk_js', GDK_BASE_URL . 'assets/js/gdk.js', array('jquery'), GDK_PLUGIN_VER, true);
|
||||
wp_localize_script('gdk_js', 'ajax', [
|
||||
'url'=> 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'),
|
||||
'url' => 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'),
|
||||
'user_id' => get_current_user_id()
|
||||
'gdk_weauth_check' => wp_create_nonce('gdk_weauth_check'),
|
||||
'user_id' => get_current_user_id(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
add_action('wp_enqueue_scripts', 'gdk_enqueue_script_frontend');
|
||||
|
||||
|
||||
//后台脚本
|
||||
function gdk_admin_script() {
|
||||
function gdk_admin_script()
|
||||
{
|
||||
?>
|
||||
<script>
|
||||
jQuery(function($) {
|
||||
|
@ -87,10 +87,10 @@ if ($("#replysubmit").length > 0) {
|
|||
<?php
|
||||
|
||||
}
|
||||
add_action('admin_footer','gdk_admin_script');
|
||||
add_action('admin_footer', 'gdk_admin_script');
|
||||
|
||||
|
||||
function gdk_admin_style() {
|
||||
function gdk_admin_style()
|
||||
{
|
||||
?><style>body{font-family: "Microsoft YaHei";}.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}.insert-shortcodes{padding-left:35px!important}#insert-shortcode-button {background: url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA1MTIgNTEyIj4gPHBhdGggZD0iTTI5MC41OSAxOTJjLTIwLjE4IDAtMTA2LjgyIDEuOTgtMTYyLjU5IDg1Ljk1VjE5MmMwLTUyLjk0LTQzLjA2LTk2LTk2LTk2LTE3LjY3IDAtMzIgMTQuMzMtMzIgMzJzMTQuMzMgMzIgMzIgMzJjMTcuNjQgMCAzMiAxNC4zNiAzMiAzMnYyNTZjMCAzNS4zIDI4LjcgNjQgNjQgNjRoMTc2YzguODQgMCAxNi03LjE2IDE2LTE2di0xNmMwLTE3LjY3LTE0LjMzLTMyLTMyLTMyaC0zMmwxMjgtOTZ2MTQ0YzAgOC44NCA3LjE2IDE2IDE2IDE2aDMyYzguODQgMCAxNi03LjE2IDE2LTE2VjI4OS44NmMtMTAuMjkgMi42Ny0yMC44OSA0LjU0LTMyIDQuNTQtNjEuODEgMC0xMTMuNTItNDQuMDUtMTI1LjQxLTEwMi40ek00NDggOTZoLTY0bC02NC02NHYxMzQuNGMwIDUzLjAyIDQyLjk4IDk2IDk2IDk2czk2LTQyLjk4IDk2LTk2VjMybC02NCA2NHptLTcyIDgwYy04Ljg0IDAtMTYtNy4xNi0xNi0xNnM3LjE2LTE2IDE2LTE2IDE2IDcuMTYgMTYgMTYtNy4xNiAxNi0xNiAxNnptODAgMGMtOC44NCAwLTE2LTcuMTYtMTYtMTZzNy4xNi0xNiAxNi0xNiAxNiA3LjE2IDE2IDE2LTcuMTYgMTYtMTYgMTZ6Ij48L3BhdGg+IDwvc3ZnPg==) no-repeat left/30%;background-position: 10% 40%;}#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;}
|
||||
</style>
|
||||
<?php
|
||||
|
|
|
@ -86,7 +86,7 @@ jQuery(function ($) { /**声明加载jQuery */
|
|||
* 已经密码可见的自动从浏览器读取内容
|
||||
* 并显示,这里加个延时处理
|
||||
*/
|
||||
|
||||
|
||||
(function () {
|
||||
if ($("#submit_pass_view").length > 0) { /**如果网站有密码可见,就执行 */
|
||||
setTimeout(function () {
|
||||
|
@ -414,7 +414,7 @@ jQuery(function ($) { /**声明加载jQuery */
|
|||
* @param {string} a 微信账号信息字符串,格式是:风起云落|1|zh_CN||海牙|荷兰|https://wx.qlogo.cn/m***A/132|o02B***jw|oq***HPA
|
||||
* @param {string} c email
|
||||
*/
|
||||
function gdk_auto_login(a ,c) {
|
||||
function gdk_auto_login(a, c) {
|
||||
var ajax_data = {
|
||||
action: 'gdk_auto_login',
|
||||
data: a,
|
||||
|
@ -485,7 +485,7 @@ jQuery(function ($) { /**声明加载jQuery */
|
|||
if (b.length > 100) {
|
||||
swal("微信登录成功!", "跳转刷新中!", "success", {
|
||||
button: false
|
||||
});
|
||||
});
|
||||
clearTimeout(timeres);
|
||||
bind_mail(b);
|
||||
//gdk_auto_login(b);
|
||||
|
@ -541,15 +541,15 @@ jQuery(function ($) { /**声明加载jQuery */
|
|||
});
|
||||
|
||||
|
||||
/**
|
||||
* 积分可见
|
||||
*/
|
||||
/**
|
||||
* 积分可见
|
||||
*/
|
||||
$("#pay_points").click(function () {
|
||||
var ajax_data = {
|
||||
action: $("#pay_points").data("action"),
|
||||
userid : $("#pay_points").data("userid"),
|
||||
id : $("#pay_points").data("id"),
|
||||
point : $("#pay_points").data("point")
|
||||
userid: $("#pay_points").data("userid"),
|
||||
id: $("#pay_points").data("id"),
|
||||
point: $("#pay_points").data("point")
|
||||
|
||||
};
|
||||
$.post(ajax.url, ajax_data, function (b) {
|
||||
|
|
|
@ -83,6 +83,7 @@ class GDK_Payjs
|
|||
$data = $this->sign($data);
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $this->url);
|
||||
curl_setopt($ch, CURLOPT_USERAGENT, 'HTTP CLIENT');
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($ch, CURLOPT_POST, 1);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
|
||||
|
|
|
@ -2,19 +2,20 @@
|
|||
|
||||
//激活插件后,主要是创建页面
|
||||
|
||||
function weauth_plugin_activate() {
|
||||
$weixin_login_id = get_option("gdk_option['weixin_login_id']");
|
||||
if (!$weixin_login_id) {
|
||||
$post1 = array(
|
||||
'post_title' => "微信登录", //这里是自动生成页面的页面标题
|
||||
'post_content' => "[weauth]", //这里是页面的内容
|
||||
'post_status' => "publish",
|
||||
'post_type' => 'page',
|
||||
'post_name' => 'weixin-login',
|
||||
);
|
||||
$page_id = wp_insert_post($post1);
|
||||
update_post_meta($page_id, "_wp_page_template", ""); //这里是生成页面的模板类型
|
||||
update_option("gdk_option['weixin_login_id']", $page_id);
|
||||
}
|
||||
function weauth_plugin_activate()
|
||||
{
|
||||
$weixin_login_id = get_option("gdk_option['weixin_login_id']");
|
||||
if (!$weixin_login_id) {
|
||||
$post1 = array(
|
||||
'post_title' => "微信登录", //这里是自动生成页面的页面标题
|
||||
'post_content' => "[weauth]", //这里是页面的内容
|
||||
'post_status' => "publish",
|
||||
'post_type' => 'page',
|
||||
'post_name' => 'weixin-login',
|
||||
);
|
||||
$page_id = wp_insert_post($post1);
|
||||
update_post_meta($page_id, "_wp_page_template", ""); //这里是生成页面的模板类型
|
||||
update_option("gdk_option['weixin_login_id']", $page_id);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,15 +22,16 @@
|
|||
* @return str|array
|
||||
*/
|
||||
|
||||
if(!class_exists('Aq_Resize')) {
|
||||
class Aq_Exception extends Exception {}
|
||||
if (!class_exists('Aq_Resize')) {
|
||||
class Aq_Exception extends Exception
|
||||
{}
|
||||
|
||||
class Aq_Resize
|
||||
{
|
||||
/**
|
||||
* The singleton instance
|
||||
*/
|
||||
static private $instance = null;
|
||||
private static $__instance = null;
|
||||
|
||||
/**
|
||||
* Should an Aq_Exception be thrown on error?
|
||||
|
@ -41,18 +42,21 @@ if(!class_exists('Aq_Resize')) {
|
|||
/**
|
||||
* No initialization allowed
|
||||
*/
|
||||
private function __construct() {}
|
||||
private function __construct()
|
||||
{}
|
||||
|
||||
/**
|
||||
* No cloning allowed
|
||||
*/
|
||||
private function __clone() {}
|
||||
private function __clone()
|
||||
{}
|
||||
|
||||
/**
|
||||
* For your custom default usage you may want to initialize an Aq_Resize object by yourself and then have own defaults
|
||||
*/
|
||||
static public function getInstance() {
|
||||
if(self::$instance == null) {
|
||||
public static function getInstance()
|
||||
{
|
||||
if (self::$instance == null) {
|
||||
self::$instance = new self;
|
||||
}
|
||||
|
||||
|
@ -62,95 +66,100 @@ if(!class_exists('Aq_Resize')) {
|
|||
/**
|
||||
* Run, forest.
|
||||
*/
|
||||
public function process( $url, $width = null, $height = null, $crop = null, $single = true, $upscale = false ) {
|
||||
public function process($url, $width = null, $height = null, $crop = null, $single = true, $upscale = false)
|
||||
{
|
||||
try {
|
||||
// Validate inputs.
|
||||
if (!$url)
|
||||
if (!$url) {
|
||||
throw new Aq_Exception('$url parameter is required');
|
||||
if (!$width)
|
||||
}
|
||||
|
||||
if (!$width) {
|
||||
throw new Aq_Exception('$width parameter is required');
|
||||
}
|
||||
|
||||
// Caipt'n, ready to hook.
|
||||
if ( true === $upscale ) add_filter( 'image_resize_dimensions', array($this, 'aq_upscale'), 10, 6 );
|
||||
if (true === $upscale) {
|
||||
add_filter('image_resize_dimensions', array($this, 'aq_upscale'), 10, 6);
|
||||
}
|
||||
|
||||
// Define upload path & dir.
|
||||
$upload_info = wp_upload_dir();
|
||||
$upload_dir = $upload_info['basedir'];
|
||||
$upload_url = $upload_info['baseurl'];
|
||||
|
||||
$http_prefix = "http://";
|
||||
$https_prefix = "https://";
|
||||
$upload_dir = $upload_info['basedir'];
|
||||
$upload_url = $upload_info['baseurl'];
|
||||
|
||||
$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. */
|
||||
if(!strncmp($url,$https_prefix,strlen($https_prefix))){ //if url begins with https:// make $upload_url begin with https:// as well
|
||||
$upload_url = str_replace($http_prefix,$https_prefix,$upload_url);
|
||||
|
||||
/* if the $url scheme differs from $upload_url scheme, make them match
|
||||
if the schemes differe, images don't show up. */
|
||||
if (!strncmp($url, $https_prefix, strlen($https_prefix))) { //if url begins with https:// make $upload_url begin with https:// as well
|
||||
$upload_url = str_replace($http_prefix, $https_prefix, $upload_url);
|
||||
} 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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
// Check if $img_url is local.
|
||||
if ( false === strpos( $url, $upload_url ) )
|
||||
if (false === strpos($url, $upload_url)) {
|
||||
throw new Aq_Exception('图片必须是本地图片: ' . $url);
|
||||
}
|
||||
|
||||
// Define path of image.
|
||||
$rel_path = str_replace( $upload_url, '', $url );
|
||||
$rel_path = str_replace($upload_url, '', $url);
|
||||
$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 ) )
|
||||
if (!file_exists($img_path) or !getimagesize($img_path)) {
|
||||
throw new Aq_Exception('图片不存在或者不是一个图片文件: ' . $img_path);
|
||||
}
|
||||
|
||||
// Get image info.
|
||||
$info = pathinfo( $img_path );
|
||||
$ext = $info['extension'];
|
||||
list( $orig_w, $orig_h ) = getimagesize( $img_path );
|
||||
$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 ) ) ) {
|
||||
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 ) ) ) {
|
||||
if (!$dims || (true == $crop && false == $upscale && ($dst_w < $width || $dst_h < $height))) {
|
||||
// Can't resize, so return false saying that the action to do could not be processed as planned.
|
||||
throw new Aq_Exception('Unable to resize image because image_resize_dimensions() failed');
|
||||
}
|
||||
// Else check if cache exists.
|
||||
elseif ( file_exists( $destfilename ) && getimagesize( $destfilename ) ) {
|
||||
elseif (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 );
|
||||
$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?)');
|
||||
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?)');
|
||||
}
|
||||
|
||||
$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;
|
||||
if (!is_wp_error($resized_file)) {
|
||||
$resized_rel_path = str_replace($upload_dir, '', $resized_file['path']);
|
||||
$img_url = $upload_url . $resized_rel_path;
|
||||
} else {
|
||||
throw new Aq_Exception('Unable to save resized image file: ' . $editor->get_error_message());
|
||||
}
|
||||
|
@ -159,31 +168,31 @@ if(!class_exists('Aq_Resize')) {
|
|||
}
|
||||
|
||||
// Okay, leave the ship.
|
||||
if ( true === $upscale ) remove_filter( 'image_resize_dimensions', array( $this, 'aq_upscale' ) );
|
||||
if (true === $upscale) {
|
||||
remove_filter('image_resize_dimensions', array($this, 'aq_upscale'));
|
||||
}
|
||||
|
||||
// Return the output.
|
||||
if ( $single ) {
|
||||
if ($single) {
|
||||
// str return.
|
||||
$image = $img_url;
|
||||
} else {
|
||||
// array return.
|
||||
$image = array (
|
||||
$image = array(
|
||||
0 => $img_url,
|
||||
1 => $dst_w,
|
||||
2 => $dst_h
|
||||
2 => $dst_h,
|
||||
);
|
||||
}
|
||||
|
||||
return $image;
|
||||
}
|
||||
catch (Aq_Exception $ex) {
|
||||
} catch (Aq_Exception $ex) {
|
||||
error_log('Aq_Resize.process() error: ' . $ex->getMessage());
|
||||
|
||||
if ($this->throwOnError) {
|
||||
// Bubble up exception.
|
||||
throw $ex;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
// Return false, so that this patch is backwards-compatible.
|
||||
return false;
|
||||
}
|
||||
|
@ -193,56 +202,55 @@ if(!class_exists('Aq_Resize')) {
|
|||
/**
|
||||
* Callback to overwrite WP computing of thumbnail measures
|
||||
*/
|
||||
function aq_upscale( $default, $orig_w, $orig_h, $dest_w, $dest_h, $crop ) {
|
||||
if ( ! $crop ) return null; // Let the wordpress default function handle this.
|
||||
public function aq_upscale($default, $orig_w, $orig_h, $dest_w, $dest_h, $crop)
|
||||
{
|
||||
if (!$crop) {
|
||||
return null;
|
||||
}
|
||||
// Let the wordpress default function handle this.
|
||||
|
||||
// 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 );
|
||||
if (!$new_w) {
|
||||
$new_w = intval($new_h * $aspect_ratio);
|
||||
}
|
||||
|
||||
if ( ! $new_h ) {
|
||||
$new_h = intval( $new_w / $aspect_ratio );
|
||||
if (!$new_h) {
|
||||
$new_h = intval($new_w / $aspect_ratio);
|
||||
}
|
||||
|
||||
$size_ratio = max( $new_w / $orig_w, $new_h / $orig_h );
|
||||
$size_ratio = max($new_w / $orig_w, $new_h / $orig_h);
|
||||
|
||||
$crop_w = round( $new_w / $size_ratio );
|
||||
$crop_h = round( $new_h / $size_ratio );
|
||||
$crop_w = round($new_w / $size_ratio);
|
||||
$crop_h = round($new_h / $size_ratio);
|
||||
|
||||
$s_x = floor( ( $orig_w - $crop_w ) / 2 );
|
||||
$s_y = floor( ( $orig_h - $crop_h ) / 2 );
|
||||
$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 array(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')) {
|
||||
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 :)
|
||||
*/
|
||||
function aq_resize( $url, $width = null, $height = null, $crop = null, $single = true, $upscale = false ) {
|
||||
function aq_resize($url, $width = null, $height = null, $crop = null, $single = true, $upscale = false)
|
||||
{
|
||||
/* WPML Fix */
|
||||
if ( defined( 'ICL_SITEPRESS_VERSION' ) ){
|
||||
if (defined('ICL_SITEPRESS_VERSION')) {
|
||||
global $sitepress;
|
||||
$url = $sitepress->convert_url( $url, $sitepress->get_default_language() );
|
||||
$url = $sitepress->convert_url($url, $sitepress->get_default_language());
|
||||
}
|
||||
/* WPML Fix */
|
||||
|
||||
$aq_resize = Aq_Resize::getInstance();
|
||||
return $aq_resize->process( $url, $width, $height, $crop, $single, $upscale );
|
||||
return $aq_resize->process($url, $width, $height, $crop, $single, $upscale);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
<?php
|
||||
|
||||
include( 'clean-up.php' );//数据库清理
|
||||
include( 'local_avatars.php' );//本地头像
|
||||
include 'clean-up.php'; //数据库清理
|
||||
include 'local_avatars.php'; //本地头像
|
||||
|
||||
include( 'updates.php' );//在线更新
|
||||
include 'updates.php'; //在线更新
|
||||
//include( 'widget_cache.php' );//小工具缓存
|
||||
|
||||
include( 'Payjs.php' );//支付功能
|
||||
include( 'points/points.php' );//积分功能
|
||||
include 'Payjs.php'; //支付功能
|
||||
include 'points/points.php'; //积分功能
|
||||
|
||||
include( 'aq_resizer.php' );//缩略图功能
|
||||
include( 'wechat.php' );//微信功能
|
||||
include 'aq_resizer.php'; //缩略图功能
|
||||
include 'wechat.php'; //微信功能
|
||||
|
|
|
@ -1,195 +1,195 @@
|
|||
<?php
|
||||
|
||||
|
||||
|
||||
function gdk_clean_up_page(){
|
||||
?>
|
||||
function gdk_clean_up_page()
|
||||
{
|
||||
?>
|
||||
<div class="wrap">
|
||||
|
||||
<h2>WP数据库优化</h2>
|
||||
|
||||
<?php
|
||||
function wp_clean_up($type){
|
||||
global $wpdb;
|
||||
switch($type){
|
||||
case "revision":
|
||||
$wcu_sql = "DELETE FROM $wpdb->posts WHERE post_type = 'revision'";
|
||||
$wpdb->query($wcu_sql);
|
||||
break;
|
||||
case "draft":
|
||||
$wcu_sql = "DELETE FROM $wpdb->posts WHERE post_status = 'draft'";
|
||||
$wpdb->query($wcu_sql);
|
||||
break;
|
||||
case "autodraft":
|
||||
$wcu_sql = "DELETE FROM $wpdb->posts WHERE post_status = 'auto-draft'";
|
||||
$wpdb->query($wcu_sql);
|
||||
break;
|
||||
case "moderated":
|
||||
$wcu_sql = "DELETE FROM $wpdb->comments WHERE comment_approved = '0'";
|
||||
$wpdb->query($wcu_sql);
|
||||
break;
|
||||
case "spam":
|
||||
$wcu_sql = "DELETE FROM $wpdb->comments WHERE comment_approved = 'spam'";
|
||||
$wpdb->query($wcu_sql);
|
||||
break;
|
||||
case "trash":
|
||||
$wcu_sql = "DELETE FROM $wpdb->comments WHERE comment_approved = 'trash'";
|
||||
$wpdb->query($wcu_sql);
|
||||
break;
|
||||
case "postmeta":
|
||||
$wcu_sql = "DELETE pm FROM $wpdb->postmeta pm LEFT JOIN $wpdb->posts wp ON wp.ID = pm.post_id WHERE wp.ID IS NULL";
|
||||
$wpdb->query($wcu_sql);
|
||||
break;
|
||||
case "commentmeta":
|
||||
$wcu_sql = "DELETE FROM $wpdb->commentmeta WHERE comment_id NOT IN (SELECT comment_id FROM $wpdb->comments)";
|
||||
$wpdb->query($wcu_sql);
|
||||
break;
|
||||
case "relationships":
|
||||
$wcu_sql = "DELETE FROM $wpdb->term_relationships WHERE term_taxonomy_id=1 AND object_id NOT IN (SELECT id FROM $wpdb->posts)";
|
||||
$wpdb->query($wcu_sql);
|
||||
break;
|
||||
case "feed":
|
||||
$wcu_sql = "DELETE FROM $wpdb->options WHERE option_name LIKE '_site_transient_browser_%' OR option_name LIKE '_site_transient_timeout_browser_%' OR option_name LIKE '_transient_feed_%' OR option_name LIKE '_transient_timeout_feed_%'";
|
||||
$wpdb->query($wcu_sql);
|
||||
break;
|
||||
}
|
||||
}
|
||||
function wp_clean_up($type)
|
||||
{
|
||||
global $wpdb;
|
||||
switch ($type) {
|
||||
case "revision":
|
||||
$wcu_sql = "DELETE FROM $wpdb->posts WHERE post_type = 'revision'";
|
||||
$wpdb->query($wcu_sql);
|
||||
break;
|
||||
case "draft":
|
||||
$wcu_sql = "DELETE FROM $wpdb->posts WHERE post_status = 'draft'";
|
||||
$wpdb->query($wcu_sql);
|
||||
break;
|
||||
case "autodraft":
|
||||
$wcu_sql = "DELETE FROM $wpdb->posts WHERE post_status = 'auto-draft'";
|
||||
$wpdb->query($wcu_sql);
|
||||
break;
|
||||
case "moderated":
|
||||
$wcu_sql = "DELETE FROM $wpdb->comments WHERE comment_approved = '0'";
|
||||
$wpdb->query($wcu_sql);
|
||||
break;
|
||||
case "spam":
|
||||
$wcu_sql = "DELETE FROM $wpdb->comments WHERE comment_approved = 'spam'";
|
||||
$wpdb->query($wcu_sql);
|
||||
break;
|
||||
case "trash":
|
||||
$wcu_sql = "DELETE FROM $wpdb->comments WHERE comment_approved = 'trash'";
|
||||
$wpdb->query($wcu_sql);
|
||||
break;
|
||||
case "postmeta":
|
||||
$wcu_sql = "DELETE pm FROM $wpdb->postmeta pm LEFT JOIN $wpdb->posts wp ON wp.ID = pm.post_id WHERE wp.ID IS NULL";
|
||||
$wpdb->query($wcu_sql);
|
||||
break;
|
||||
case "commentmeta":
|
||||
$wcu_sql = "DELETE FROM $wpdb->commentmeta WHERE comment_id NOT IN (SELECT comment_id FROM $wpdb->comments)";
|
||||
$wpdb->query($wcu_sql);
|
||||
break;
|
||||
case "relationships":
|
||||
$wcu_sql = "DELETE FROM $wpdb->term_relationships WHERE term_taxonomy_id=1 AND object_id NOT IN (SELECT id FROM $wpdb->posts)";
|
||||
$wpdb->query($wcu_sql);
|
||||
break;
|
||||
case "feed":
|
||||
$wcu_sql = "DELETE FROM $wpdb->options WHERE option_name LIKE '_site_transient_browser_%' OR option_name LIKE '_site_transient_timeout_browser_%' OR option_name LIKE '_transient_feed_%' OR option_name LIKE '_transient_timeout_feed_%'";
|
||||
$wpdb->query($wcu_sql);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
function wp_clean_up_count($type){
|
||||
global $wpdb;
|
||||
switch($type){
|
||||
case "revision":
|
||||
$wcu_sql = "SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = 'revision'";
|
||||
$count = $wpdb->get_var($wcu_sql);
|
||||
break;
|
||||
case "draft":
|
||||
$wcu_sql = "SELECT COUNT(*) FROM $wpdb->posts WHERE post_status = 'draft'";
|
||||
$count = $wpdb->get_var($wcu_sql);
|
||||
break;
|
||||
case "autodraft":
|
||||
$wcu_sql = "SELECT COUNT(*) FROM $wpdb->posts WHERE post_status = 'auto-draft'";
|
||||
$count = $wpdb->get_var($wcu_sql);
|
||||
break;
|
||||
case "moderated":
|
||||
$wcu_sql = "SELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved = '0'";
|
||||
$count = $wpdb->get_var($wcu_sql);
|
||||
break;
|
||||
case "spam":
|
||||
$wcu_sql = "SELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved = 'spam'";
|
||||
$count = $wpdb->get_var($wcu_sql);
|
||||
break;
|
||||
case "trash":
|
||||
$wcu_sql = "SELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved = 'trash'";
|
||||
$count = $wpdb->get_var($wcu_sql);
|
||||
break;
|
||||
case "postmeta":
|
||||
$wcu_sql = "SELECT COUNT(*) FROM $wpdb->postmeta pm LEFT JOIN $wpdb->posts wp ON wp.ID = pm.post_id WHERE wp.ID IS NULL";
|
||||
//$wcu_sql = "SELECT COUNT(*) FROM $wpdb->postmeta WHERE NOT EXISTS ( SELECT * FROM $wpdb->posts WHERE $wpdb->postmeta.post_id = $wpdb->posts.ID )";
|
||||
$count = $wpdb->get_var($wcu_sql);
|
||||
break;
|
||||
case "commentmeta":
|
||||
$wcu_sql = "SELECT COUNT(*) FROM $wpdb->commentmeta WHERE comment_id NOT IN (SELECT comment_id FROM $wpdb->comments)";
|
||||
$count = $wpdb->get_var($wcu_sql);
|
||||
break;
|
||||
case "relationships":
|
||||
$wcu_sql = "SELECT COUNT(*) FROM $wpdb->term_relationships WHERE term_taxonomy_id=1 AND object_id NOT IN (SELECT id FROM $wpdb->posts)";
|
||||
$count = $wpdb->get_var($wcu_sql);
|
||||
break;
|
||||
case "feed":
|
||||
$wcu_sql = "SELECT COUNT(*) FROM $wpdb->options WHERE option_name LIKE '_site_transient_browser_%' OR option_name LIKE '_site_transient_timeout_browser_%' OR option_name LIKE '_transient_feed_%' OR option_name LIKE '_transient_timeout_feed_%'";
|
||||
$count = $wpdb->get_var($wcu_sql);
|
||||
break;
|
||||
}
|
||||
return $count;
|
||||
}
|
||||
function wp_clean_up_count($type)
|
||||
{
|
||||
global $wpdb;
|
||||
switch ($type) {
|
||||
case "revision":
|
||||
$wcu_sql = "SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = 'revision'";
|
||||
$count = $wpdb->get_var($wcu_sql);
|
||||
break;
|
||||
case "draft":
|
||||
$wcu_sql = "SELECT COUNT(*) FROM $wpdb->posts WHERE post_status = 'draft'";
|
||||
$count = $wpdb->get_var($wcu_sql);
|
||||
break;
|
||||
case "autodraft":
|
||||
$wcu_sql = "SELECT COUNT(*) FROM $wpdb->posts WHERE post_status = 'auto-draft'";
|
||||
$count = $wpdb->get_var($wcu_sql);
|
||||
break;
|
||||
case "moderated":
|
||||
$wcu_sql = "SELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved = '0'";
|
||||
$count = $wpdb->get_var($wcu_sql);
|
||||
break;
|
||||
case "spam":
|
||||
$wcu_sql = "SELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved = 'spam'";
|
||||
$count = $wpdb->get_var($wcu_sql);
|
||||
break;
|
||||
case "trash":
|
||||
$wcu_sql = "SELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved = 'trash'";
|
||||
$count = $wpdb->get_var($wcu_sql);
|
||||
break;
|
||||
case "postmeta":
|
||||
$wcu_sql = "SELECT COUNT(*) FROM $wpdb->postmeta pm LEFT JOIN $wpdb->posts wp ON wp.ID = pm.post_id WHERE wp.ID IS NULL";
|
||||
//$wcu_sql = "SELECT COUNT(*) FROM $wpdb->postmeta WHERE NOT EXISTS ( SELECT * FROM $wpdb->posts WHERE $wpdb->postmeta.post_id = $wpdb->posts.ID )";
|
||||
$count = $wpdb->get_var($wcu_sql);
|
||||
break;
|
||||
case "commentmeta":
|
||||
$wcu_sql = "SELECT COUNT(*) FROM $wpdb->commentmeta WHERE comment_id NOT IN (SELECT comment_id FROM $wpdb->comments)";
|
||||
$count = $wpdb->get_var($wcu_sql);
|
||||
break;
|
||||
case "relationships":
|
||||
$wcu_sql = "SELECT COUNT(*) FROM $wpdb->term_relationships WHERE term_taxonomy_id=1 AND object_id NOT IN (SELECT id FROM $wpdb->posts)";
|
||||
$count = $wpdb->get_var($wcu_sql);
|
||||
break;
|
||||
case "feed":
|
||||
$wcu_sql = "SELECT COUNT(*) FROM $wpdb->options WHERE option_name LIKE '_site_transient_browser_%' OR option_name LIKE '_site_transient_timeout_browser_%' OR option_name LIKE '_transient_feed_%' OR option_name LIKE '_transient_timeout_feed_%'";
|
||||
$count = $wpdb->get_var($wcu_sql);
|
||||
break;
|
||||
}
|
||||
return $count;
|
||||
}
|
||||
|
||||
function wp_clean_up_optimize(){
|
||||
global $wpdb;
|
||||
$wcu_sql = 'SHOW TABLE STATUS FROM `'.DB_NAME.'`';
|
||||
$result = $wpdb->get_results($wcu_sql);
|
||||
foreach($result as $row){
|
||||
$wcu_sql = 'OPTIMIZE TABLE '.$row->Name;
|
||||
$wpdb->query($wcu_sql);
|
||||
}
|
||||
}
|
||||
function wp_clean_up_optimize()
|
||||
{
|
||||
global $wpdb;
|
||||
$wcu_sql = 'SHOW TABLE STATUS FROM `' . DB_NAME . '`';
|
||||
$result = $wpdb->get_results($wcu_sql);
|
||||
foreach ($result as $row) {
|
||||
$wcu_sql = 'OPTIMIZE TABLE ' . $row->Name;
|
||||
$wpdb->query($wcu_sql);
|
||||
}
|
||||
}
|
||||
|
||||
$wcu_message = '';
|
||||
$wcu_message = '';
|
||||
|
||||
if(isset($_POST['wp_clean_up_revision'])){
|
||||
wp_clean_up('revision');
|
||||
$wcu_message = "所有修改版本已删除!";
|
||||
}
|
||||
if (isset($_POST['wp_clean_up_revision'])) {
|
||||
wp_clean_up('revision');
|
||||
$wcu_message = "所有修改版本已删除!";
|
||||
}
|
||||
|
||||
if(isset($_POST['wp_clean_up_draft'])){
|
||||
wp_clean_up('draft');
|
||||
$wcu_message = "所有草稿已删除!";
|
||||
}
|
||||
if (isset($_POST['wp_clean_up_draft'])) {
|
||||
wp_clean_up('draft');
|
||||
$wcu_message = "所有草稿已删除!";
|
||||
}
|
||||
|
||||
if(isset($_POST['wp_clean_up_autodraft'])){
|
||||
wp_clean_up('autodraft');
|
||||
$wcu_message = "所有自动草稿已删除!";
|
||||
}
|
||||
if (isset($_POST['wp_clean_up_autodraft'])) {
|
||||
wp_clean_up('autodraft');
|
||||
$wcu_message = "所有自动草稿已删除!";
|
||||
}
|
||||
|
||||
if(isset($_POST['wp_clean_up_moderated'])){
|
||||
wp_clean_up('moderated');
|
||||
$wcu_message = "所有待审评论已删除!";
|
||||
}
|
||||
if (isset($_POST['wp_clean_up_moderated'])) {
|
||||
wp_clean_up('moderated');
|
||||
$wcu_message = "所有待审评论已删除!";
|
||||
}
|
||||
|
||||
if(isset($_POST['wp_clean_up_spam'])){
|
||||
wp_clean_up('spam');
|
||||
$wcu_message = "所有垃圾评论已删除!";
|
||||
}
|
||||
if (isset($_POST['wp_clean_up_spam'])) {
|
||||
wp_clean_up('spam');
|
||||
$wcu_message = "所有垃圾评论已删除!";
|
||||
}
|
||||
|
||||
if(isset($_POST['wp_clean_up_trash'])){
|
||||
wp_clean_up('trash');
|
||||
$wcu_message = "所有回收站评论已删除!";
|
||||
}
|
||||
if (isset($_POST['wp_clean_up_trash'])) {
|
||||
wp_clean_up('trash');
|
||||
$wcu_message = "所有回收站评论已删除!";
|
||||
}
|
||||
|
||||
if(isset($_POST['wp_clean_up_postmeta'])){
|
||||
wp_clean_up('postmeta');
|
||||
$wcu_message = "所有孤立的文章元信息!";
|
||||
}
|
||||
if (isset($_POST['wp_clean_up_postmeta'])) {
|
||||
wp_clean_up('postmeta');
|
||||
$wcu_message = "所有孤立的文章元信息!";
|
||||
}
|
||||
|
||||
if(isset($_POST['wp_clean_up_commentmeta'])){
|
||||
wp_clean_up('commentmeta');
|
||||
$wcu_message = "所有孤立的评论元信息!";
|
||||
}
|
||||
if (isset($_POST['wp_clean_up_commentmeta'])) {
|
||||
wp_clean_up('commentmeta');
|
||||
$wcu_message = "所有孤立的评论元信息!";
|
||||
}
|
||||
|
||||
if(isset($_POST['wp_clean_up_relationships'])){
|
||||
wp_clean_up('relationships');
|
||||
$wcu_message = "所有孤立的关系信息!";
|
||||
}
|
||||
if (isset($_POST['wp_clean_up_relationships'])) {
|
||||
wp_clean_up('relationships');
|
||||
$wcu_message = "所有孤立的关系信息!";
|
||||
}
|
||||
|
||||
if(isset($_POST['wp_clean_up_feed'])){
|
||||
wp_clean_up('feed');
|
||||
$wcu_message = "所有控制板订阅缓存!";
|
||||
}
|
||||
if (isset($_POST['wp_clean_up_feed'])) {
|
||||
wp_clean_up('feed');
|
||||
$wcu_message = "所有控制板订阅缓存!";
|
||||
}
|
||||
|
||||
if (isset($_POST['wp_clean_up_all'])) {
|
||||
wp_clean_up('revision');
|
||||
wp_clean_up('draft');
|
||||
wp_clean_up('autodraft');
|
||||
wp_clean_up('moderated');
|
||||
wp_clean_up('spam');
|
||||
wp_clean_up('trash');
|
||||
wp_clean_up('postmeta');
|
||||
wp_clean_up('commentmeta');
|
||||
wp_clean_up('relationships');
|
||||
wp_clean_up('feed');
|
||||
$wcu_message = "所有冗余数据已删除!";
|
||||
}
|
||||
|
||||
if (isset($_POST['wp_clean_up_optimize'])) {
|
||||
wp_clean_up_optimize();
|
||||
$wcu_message = "数据库已优化!";
|
||||
}
|
||||
|
||||
if(isset($_POST['wp_clean_up_all'])){
|
||||
wp_clean_up('revision');
|
||||
wp_clean_up('draft');
|
||||
wp_clean_up('autodraft');
|
||||
wp_clean_up('moderated');
|
||||
wp_clean_up('spam');
|
||||
wp_clean_up('trash');
|
||||
wp_clean_up('postmeta');
|
||||
wp_clean_up('commentmeta');
|
||||
wp_clean_up('relationships');
|
||||
wp_clean_up('feed');
|
||||
$wcu_message = "所有冗余数据已删除!";
|
||||
}
|
||||
|
||||
if(isset($_POST['wp_clean_up_optimize'])){
|
||||
wp_clean_up_optimize();
|
||||
$wcu_message = "数据库已优化!";
|
||||
}
|
||||
|
||||
if($wcu_message != ''){
|
||||
echo '<div id="message" class="updated fade"><p><strong>' . $wcu_message . '</strong></p></div>';
|
||||
}
|
||||
?>
|
||||
if ($wcu_message != '') {
|
||||
echo '<div id="message" class="updated fade"><p><strong>' . $wcu_message . '</strong></p></div>';
|
||||
}
|
||||
?>
|
||||
|
||||
|
||||
<p>
|
||||
|
@ -212,7 +212,7 @@ function wp_clean_up_optimize(){
|
|||
<td class="column-name">
|
||||
<form method="post">
|
||||
<input type="hidden" name="wp_clean_up_revision" value="revision" />
|
||||
<input type="submit" class="<?php if(wp_clean_up_count('revision')>0){echo 'button-primary';}else{echo 'button';} ?>" value="删除" />
|
||||
<input type="submit" class="<?php if (wp_clean_up_count('revision') > 0) {echo 'button-primary';} else {echo 'button';} ?>" value="删除" />
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
|
@ -226,7 +226,7 @@ function wp_clean_up_optimize(){
|
|||
<td class="column-name">
|
||||
<form method="post">
|
||||
<input type="hidden" name="wp_clean_up_draft" value="draft" />
|
||||
<input type="submit" class="<?php if(wp_clean_up_count('draft')>0){echo 'button-primary';}else{echo 'button';} ?>" value="删除" />
|
||||
<input type="submit" class="<?php if (wp_clean_up_count('draft') > 0) {echo 'button-primary';} else {echo 'button';} ?>" value="删除" />
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
|
@ -240,7 +240,7 @@ function wp_clean_up_optimize(){
|
|||
<td class="column-name">
|
||||
<form method="post">
|
||||
<input type="hidden" name="wp_clean_up_autodraft" value="autodraft" />
|
||||
<input type="submit" class="<?php if(wp_clean_up_count('autodraft')>0){echo 'button-primary';}else{echo 'button';} ?>" value="删除" />
|
||||
<input type="submit" class="<?php if (wp_clean_up_count('autodraft') > 0) {echo 'button-primary';} else {echo 'button';} ?>" value="删除" />
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
|
@ -254,7 +254,7 @@ function wp_clean_up_optimize(){
|
|||
<td class="column-name">
|
||||
<form method="post">
|
||||
<input type="hidden" name="wp_clean_up_moderated" value="moderated" />
|
||||
<input type="submit" class="<?php if(wp_clean_up_count('moderated')>0){echo 'button-primary';}else{echo 'button';} ?>" value="删除" />
|
||||
<input type="submit" class="<?php if (wp_clean_up_count('moderated') > 0) {echo 'button-primary';} else {echo 'button';} ?>" value="删除" />
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
|
@ -268,7 +268,7 @@ function wp_clean_up_optimize(){
|
|||
<td class="column-name">
|
||||
<form method="post">
|
||||
<input type="hidden" name="wp_clean_up_spam" value="spam" />
|
||||
<input type="submit" class="<?php if(wp_clean_up_count('spam')>0){echo 'button-primary';}else{echo 'button';} ?>" value="删除" />
|
||||
<input type="submit" class="<?php if (wp_clean_up_count('spam') > 0) {echo 'button-primary';} else {echo 'button';} ?>" value="删除" />
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
|
@ -282,7 +282,7 @@ function wp_clean_up_optimize(){
|
|||
<td class="column-name">
|
||||
<form method="post">
|
||||
<input type="hidden" name="wp_clean_up_trash" value="trash" />
|
||||
<input type="submit" class="<?php if(wp_clean_up_count('trash')>0){echo 'button-primary';}else{echo 'button';} ?>" value="删除" />
|
||||
<input type="submit" class="<?php if (wp_clean_up_count('trash') > 0) {echo 'button-primary';} else {echo 'button';} ?>" value="删除" />
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
|
@ -296,7 +296,7 @@ function wp_clean_up_optimize(){
|
|||
<td class="column-name">
|
||||
<form method="post">
|
||||
<input type="hidden" name="wp_clean_up_postmeta" value="postmeta" />
|
||||
<input type="submit" class="<?php if(wp_clean_up_count('postmeta')>0){echo 'button-primary';}else{echo 'button';} ?>" value="删除" />
|
||||
<input type="submit" class="<?php if (wp_clean_up_count('postmeta') > 0) {echo 'button-primary';} else {echo 'button';} ?>" value="删除" />
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
|
@ -310,7 +310,7 @@ function wp_clean_up_optimize(){
|
|||
<td class="column-name">
|
||||
<form method="post">
|
||||
<input type="hidden" name="wp_clean_up_commentmeta" value="commentmeta" />
|
||||
<input type="submit" class="<?php if(wp_clean_up_count('commentmeta')>0){echo 'button-primary';}else{echo 'button';} ?>" value="删除" />
|
||||
<input type="submit" class="<?php if (wp_clean_up_count('commentmeta') > 0) {echo 'button-primary';} else {echo 'button';} ?>" value="删除" />
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
|
@ -324,7 +324,7 @@ function wp_clean_up_optimize(){
|
|||
<td class="column-name">
|
||||
<form method="post">
|
||||
<input type="hidden" name="wp_clean_up_relationships" value="relationships" />
|
||||
<input type="submit" class="<?php if(wp_clean_up_count('relationships')>0){echo 'button-primary';}else{echo 'button';} ?>" value="删除" />
|
||||
<input type="submit" class="<?php if (wp_clean_up_count('relationships') > 0) {echo 'button-primary';} else {echo 'button';} ?>" value="删除" />
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
|
@ -338,7 +338,7 @@ function wp_clean_up_optimize(){
|
|||
<td class="column-name">
|
||||
<form method="post">
|
||||
<input type="hidden" name="wp_clean_up_feed" value="feed" />
|
||||
<input type="submit" class="<?php if(wp_clean_up_count('feed')>0){echo 'button-primary';}else{echo 'button';} ?>" value="删除" />
|
||||
<input type="submit" class="<?php if (wp_clean_up_count('feed') > 0) {echo 'button-primary';} else {echo 'button';} ?>" value="删除" />
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
|
@ -362,34 +362,34 @@ function wp_clean_up_optimize(){
|
|||
</thead>
|
||||
<tbody id="the-list">
|
||||
<?php
|
||||
global $wpdb;
|
||||
$total_size = 0;
|
||||
$alternate = " class='alternate'";
|
||||
$wcu_sql = 'SHOW TABLE STATUS FROM `'.DB_NAME.'`';
|
||||
$result = $wpdb->get_results($wcu_sql);
|
||||
global $wpdb;
|
||||
$total_size = 0;
|
||||
$alternate = " class='alternate'";
|
||||
$wcu_sql = 'SHOW TABLE STATUS FROM `' . DB_NAME . '`';
|
||||
$result = $wpdb->get_results($wcu_sql);
|
||||
|
||||
foreach($result as $row){
|
||||
foreach ($result as $row) {
|
||||
|
||||
$table_size = $row->Data_length + $row->Index_length;
|
||||
$table_size = $table_size / 1024;
|
||||
$table_size = sprintf("%0.3f",$table_size);
|
||||
$table_size = $row->Data_length + $row->Index_length;
|
||||
$table_size = $table_size / 1024;
|
||||
$table_size = sprintf("%0.3f", $table_size);
|
||||
|
||||
$every_size = $row->Data_length + $row->Index_length;
|
||||
$every_size = $every_size / 1024;
|
||||
$total_size += $every_size;
|
||||
$every_size = $row->Data_length + $row->Index_length;
|
||||
$every_size = $every_size / 1024;
|
||||
$total_size += $every_size;
|
||||
|
||||
echo "<tr". $alternate .">
|
||||
<td class='column-name'>". $row->Name ."</td>
|
||||
<td class='column-name'>". $table_size ." KB"."</td>
|
||||
echo "<tr" . $alternate . ">
|
||||
<td class='column-name'>" . $row->Name . "</td>
|
||||
<td class='column-name'>" . $table_size . " KB" . "</td>
|
||||
</tr>\n";
|
||||
$alternate = (empty($alternate)) ? " class='alternate'" : "";
|
||||
}
|
||||
?>
|
||||
$alternate = (empty($alternate)) ? " class='alternate'" : "";
|
||||
}
|
||||
?>
|
||||
</tbody>
|
||||
<tfoot>
|
||||
<tr>
|
||||
<th scope="col">总共</th>
|
||||
<th scope="col" style="font-family:Tahoma;"><?php echo sprintf("%0.3f",$total_size).' KB'; ?></th>
|
||||
<th scope="col" style="font-family:Tahoma;"><?php echo sprintf("%0.3f", $total_size) . ' KB'; ?></th>
|
||||
</tr>
|
||||
</tfoot>
|
||||
</table>
|
||||
|
|
|
@ -1,73 +1,93 @@
|
|||
<?php
|
||||
|
||||
//本地头像
|
||||
class gdk_local_avatars {
|
||||
private $user_id_being_edited;
|
||||
public function __construct() {
|
||||
class gdk_local_avatars
|
||||
{
|
||||
private $__user_id_being_edited;
|
||||
public function __construct()
|
||||
{
|
||||
add_action('admin_init', array(
|
||||
$this,
|
||||
'admin_init'
|
||||
'admin_init',
|
||||
));
|
||||
add_action('show_user_profile', array(
|
||||
$this,
|
||||
'edit_user_profile'
|
||||
'edit_user_profile',
|
||||
));
|
||||
add_action('edit_user_profile', array(
|
||||
$this,
|
||||
'edit_user_profile'
|
||||
'edit_user_profile',
|
||||
));
|
||||
add_action('personal_options_update', array(
|
||||
$this,
|
||||
'edit_user_profile_update'
|
||||
'edit_user_profile_update',
|
||||
));
|
||||
add_action('edit_user_profile_update', array(
|
||||
$this,
|
||||
'edit_user_profile_update'
|
||||
'edit_user_profile_update',
|
||||
));
|
||||
add_filter('get_avatar', array(
|
||||
$this,
|
||||
'get_avatar'
|
||||
) , 10, 5);
|
||||
'get_avatar',
|
||||
), 10, 5);
|
||||
add_filter('avatar_defaults', array(
|
||||
$this,
|
||||
'avatar_defaults'
|
||||
'avatar_defaults',
|
||||
));
|
||||
}
|
||||
public function admin_init() {
|
||||
public function admin_init()
|
||||
{
|
||||
register_setting('discussion', 'gdk_local_avatars_caps', array(
|
||||
$this,
|
||||
'sanitize_options'
|
||||
'sanitize_options',
|
||||
));
|
||||
add_settings_field('basic-user-avatars-caps', '本地上传头像权限管理', array(
|
||||
$this,
|
||||
'avatar_settings_field'
|
||||
) , 'discussion', 'avatars');
|
||||
'avatar_settings_field',
|
||||
), 'discussion', 'avatars');
|
||||
}
|
||||
public function avatar_settings_field($args) {
|
||||
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>
|
||||
checked($options['gdk_local_avatars_caps'], 1); ?>/>仅具有头像上传权限的用户具有设置本地头像权限(作者及更高等级角色)</label>
|
||||
<?php
|
||||
}
|
||||
public function sanitize_options($input) {
|
||||
}
|
||||
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;
|
||||
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;
|
||||
if (empty($user_id)) return $avatar;
|
||||
public function get_avatar($avatar, $id_or_email, $size = 96, $default, $alt)
|
||||
{
|
||||
if (is_numeric($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;
|
||||
}
|
||||
|
||||
if (empty($user_id)) {
|
||||
return $avatar;
|
||||
}
|
||||
|
||||
$local_avatars = get_user_meta($user_id, 'simple_local_avatar', true);
|
||||
if (empty($local_avatars) || empty($local_avatars['full'])) return $avatar;
|
||||
if (empty($local_avatars) || empty($local_avatars['full'])) {
|
||||
return $avatar;
|
||||
}
|
||||
|
||||
$size = (int)$size;
|
||||
if (empty($alt)) $alt = get_the_author_meta('display_name', $user_id);
|
||||
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();
|
||||
|
@ -78,22 +98,23 @@ class gdk_local_avatars {
|
|||
$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) {
|
||||
?>
|
||||
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
|
||||
echo get_avatar($profileuser->ID); ?>
|
||||
echo get_avatar($profileuser->ID); ?>
|
||||
</td>
|
||||
<td>
|
||||
<?php
|
||||
$options = get_option('gdk_local_avatars_caps');
|
||||
$options = get_option('gdk_local_avatars_caps');
|
||||
if (empty($options['gdk_local_avatars_caps']) || current_user_can('upload_files')) {
|
||||
// Nonce security ftw
|
||||
wp_nonce_field('simple_local_avatar_nonce', '_simple_local_avatar_nonce', false);
|
||||
|
@ -111,48 +132,60 @@ class gdk_local_avatars {
|
|||
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
|
||||
}
|
||||
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')) return;
|
||||
}
|
||||
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')) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!empty($_FILES['basic-user-avatar']['name'])) {
|
||||
$mimes = array(
|
||||
'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';
|
||||
if (!function_exists('wp_handle_upload')) {
|
||||
require_once ABSPATH . 'wp-admin/includes/file.php';
|
||||
}
|
||||
|
||||
$this->avatar_delete($user_id);
|
||||
if (strstr($_FILES['basic-user-avatar']['name'], '.php')) wp_die('基于安全考虑 ".php" 格式文件禁止上传');
|
||||
if (strstr($_FILES['basic-user-avatar']['name'], '.php')) {
|
||||
wp_die('基于安全考虑 ".php" 格式文件禁止上传');
|
||||
}
|
||||
|
||||
$this->user_id_being_edited = $user_id;
|
||||
$avatar = wp_handle_upload($_FILES['basic-user-avatar'], array(
|
||||
'mimes' => $mimes,
|
||||
'test_form' => false,
|
||||
$avatar = wp_handle_upload($_FILES['basic-user-avatar'], array(
|
||||
'mimes' => $mimes,
|
||||
'test_form' => false,
|
||||
'unique_filename_callback' => array(
|
||||
$this,
|
||||
'unique_filename_callback'
|
||||
)
|
||||
'unique_filename_callback',
|
||||
),
|
||||
));
|
||||
update_user_meta($user_id, 'simple_local_avatar', array(
|
||||
'full' => $avatar['url']
|
||||
'full' => $avatar['url'],
|
||||
));
|
||||
} elseif (!empty($_POST['basic-user-avatar-erase'])) {
|
||||
$this->avatar_delete($user_id);
|
||||
}
|
||||
}
|
||||
public function avatar_defaults($avatar_defaults) {
|
||||
public function avatar_defaults($avatar_defaults)
|
||||
{
|
||||
remove_action('get_avatar', array(
|
||||
$this,
|
||||
'get_avatar'
|
||||
'get_avatar',
|
||||
));
|
||||
return $avatar_defaults;
|
||||
}
|
||||
public function avatar_delete($user_id) {
|
||||
public function avatar_delete($user_id)
|
||||
{
|
||||
$old_avatars = get_user_meta($user_id, 'simple_local_avatar', true);
|
||||
$upload_path = wp_upload_dir();
|
||||
if (is_array($old_avatars)) {
|
||||
|
@ -163,9 +196,10 @@ class gdk_local_avatars {
|
|||
}
|
||||
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');
|
||||
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');
|
||||
$number = 1;
|
||||
while (file_exists($dir . "/$name$ext")) {
|
||||
$name = $base_name . '_' . $number;
|
||||
|
|
|
@ -4,450 +4,464 @@
|
|||
*/
|
||||
|
||||
// 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');
|
||||
if (!class_exists('WP_List_Table')) {
|
||||
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
|
||||
*/
|
||||
public function prepare_items() {
|
||||
$columns = $this->get_columns();
|
||||
$hidden = $this->get_hidden_columns();
|
||||
$sortable = $this->get_sortable_columns();
|
||||
$data = $this->table_data();
|
||||
usort( $data, [ &$this, 'sort_data' ] );
|
||||
$perPage = 30;//每页30个数据
|
||||
$currentPage = $this->get_pagenum();
|
||||
$totalItems = count( $data );
|
||||
$this->set_pagination_args( [
|
||||
'total_items' => $totalItems,
|
||||
'per_page' => $perPage
|
||||
] );
|
||||
class GDK_Points_List_Table extends WP_List_Table
|
||||
{
|
||||
/**
|
||||
* Prepare the items for the table to process
|
||||
*
|
||||
* @return Void
|
||||
*/
|
||||
public function prepare_items()
|
||||
{
|
||||
$columns = $this->get_columns();
|
||||
$hidden = $this->get_hidden_columns();
|
||||
$sortable = $this->get_sortable_columns();
|
||||
$data = $this->table_data();
|
||||
usort($data, [ & $this, 'sort_data']);
|
||||
$perPage = 30; //每页30个数据
|
||||
$currentPage = $this->get_pagenum();
|
||||
$totalItems = count($data);
|
||||
$this->set_pagination_args([
|
||||
'total_items' => $totalItems,
|
||||
'per_page' => $perPage,
|
||||
]);
|
||||
|
||||
$data = array_slice( $data, (($currentPage - 1) * $perPage), $perPage );
|
||||
$data = array_slice($data, (($currentPage - 1) * $perPage), $perPage);
|
||||
|
||||
$this->_column_headers = [
|
||||
$columns,
|
||||
$hidden,
|
||||
$sortable
|
||||
];
|
||||
$this->items = $data;
|
||||
}
|
||||
$this->_column_headers = [
|
||||
$columns,
|
||||
$hidden,
|
||||
$sortable,
|
||||
];
|
||||
$this->items = $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Override the parent columns method.
|
||||
* Defines the columns to use in your listing table
|
||||
*
|
||||
* @return Array
|
||||
*/
|
||||
public function get_columns() {
|
||||
$columns = [
|
||||
'point_id' => 'ID',
|
||||
'user_id' => '用户ID',
|
||||
'points' => '金币',
|
||||
'description' => '描述',
|
||||
'datetime' => '日期&时间',
|
||||
'status' => '状态',
|
||||
'actions' => '操作'
|
||||
];
|
||||
/**
|
||||
* Override the parent columns method.
|
||||
* Defines the columns to use in your listing table
|
||||
*
|
||||
* @return Array
|
||||
*/
|
||||
public function get_columns()
|
||||
{
|
||||
$columns = [
|
||||
'point_id' => 'ID',
|
||||
'user_id' => '用户ID',
|
||||
'points' => '金币',
|
||||
'description' => '描述',
|
||||
'datetime' => '日期&时间',
|
||||
'status' => '状态',
|
||||
'actions' => '操作',
|
||||
];
|
||||
|
||||
return $columns;
|
||||
}
|
||||
return $columns;
|
||||
}
|
||||
|
||||
/**
|
||||
* Define which columns are hidden
|
||||
*
|
||||
* @return Array
|
||||
*/
|
||||
public function get_hidden_columns() {
|
||||
return [];
|
||||
}
|
||||
/**
|
||||
* Define which columns are hidden
|
||||
*
|
||||
* @return Array
|
||||
*/
|
||||
public function get_hidden_columns()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the sortable columns
|
||||
*
|
||||
* @return Array
|
||||
*/
|
||||
public function get_sortable_columns() {
|
||||
return [
|
||||
'point_id' => [
|
||||
'point_id',
|
||||
false
|
||||
],
|
||||
'user_id' => [
|
||||
'user_id',
|
||||
false
|
||||
],
|
||||
'points' => [
|
||||
'points',
|
||||
false
|
||||
],
|
||||
'description' => [
|
||||
'description',
|
||||
false
|
||||
],
|
||||
'datetime' => [
|
||||
'datetime',
|
||||
false
|
||||
],
|
||||
'status' => [
|
||||
'status',
|
||||
false
|
||||
]
|
||||
];
|
||||
}
|
||||
/**
|
||||
* Define the sortable columns
|
||||
*
|
||||
* @return Array
|
||||
*/
|
||||
public function get_sortable_columns()
|
||||
{
|
||||
return [
|
||||
'point_id' => [
|
||||
'point_id',
|
||||
false,
|
||||
],
|
||||
'user_id' => [
|
||||
'user_id',
|
||||
false,
|
||||
],
|
||||
'points' => [
|
||||
'points',
|
||||
false,
|
||||
],
|
||||
'description' => [
|
||||
'description',
|
||||
false,
|
||||
],
|
||||
'datetime' => [
|
||||
'datetime',
|
||||
false,
|
||||
],
|
||||
'status' => [
|
||||
'status',
|
||||
false,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the table data
|
||||
*
|
||||
* @return Array
|
||||
*/
|
||||
private function table_data() {
|
||||
$data = [];
|
||||
$data = GDK_Points::get_points( null, null, null, ARRAY_A );
|
||||
return $data;
|
||||
}
|
||||
/**
|
||||
* Get the table data
|
||||
*
|
||||
* @return Array
|
||||
*/
|
||||
private function __table_data()
|
||||
{
|
||||
$data = [];
|
||||
$data = GDK_Points::get_points(null, null, null, ARRAY_A);
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Define what data to show on each column of the table
|
||||
*
|
||||
* @param Array $item
|
||||
* Data
|
||||
* @param String $column_name
|
||||
* - Current column name
|
||||
*
|
||||
* @return Mixed
|
||||
*/
|
||||
public function column_default( $item, $column_name ) {
|
||||
switch ( $column_name ) {
|
||||
case 'point_id' :
|
||||
case 'user_id' :
|
||||
case 'description' :
|
||||
case 'points' :
|
||||
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']),
|
||||
'delete' => sprintf('<a href="?page=%s&action=%s&point_id=%s">删除</a>',$_REQUEST['page'],'delete',$item['point_id']),
|
||||
];
|
||||
/**
|
||||
* Define what data to show on each column of the table
|
||||
*
|
||||
* @param Array $item
|
||||
* Data
|
||||
* @param String $column_name
|
||||
* - Current column name
|
||||
*
|
||||
* @return Mixed
|
||||
*/
|
||||
public function column_default($item, $column_name)
|
||||
{
|
||||
switch ($column_name) {
|
||||
case 'point_id':
|
||||
case 'user_id':
|
||||
case 'description':
|
||||
case 'points':
|
||||
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']),
|
||||
'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]??"",
|
||||
$this->row_actions($actions, true)
|
||||
);
|
||||
break;
|
||||
default :
|
||||
return print_r( $item, true );
|
||||
}
|
||||
}
|
||||
//Return the title contents
|
||||
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
|
||||
*
|
||||
* @return Mixed
|
||||
*/
|
||||
private function sort_data( $a, $b ) {
|
||||
// Set defaults
|
||||
$orderby = 'point_id';
|
||||
$order = 'desc';
|
||||
/**
|
||||
* Allows you to sort the data by the variables set in the $_GET
|
||||
*
|
||||
* @return Mixed
|
||||
*/
|
||||
private function __sort_data($a, $b)
|
||||
{
|
||||
// Set defaults
|
||||
$orderby = 'point_id';
|
||||
$order = 'desc';
|
||||
|
||||
// If orderby is set, use this as the sort column
|
||||
if ( !empty( $_GET['orderby'] ) ) {
|
||||
$orderby = $_GET['orderby'];
|
||||
}
|
||||
// If orderby is set, use this as the sort column
|
||||
if (!empty($_GET['orderby'])) {
|
||||
$orderby = $_GET['orderby'];
|
||||
}
|
||||
|
||||
// If order is set use this as the order
|
||||
if ( !empty( $_GET['order'] ) ) {
|
||||
$order = $_GET['order'];
|
||||
}
|
||||
// If order is set use this as the order
|
||||
if (!empty($_GET['order'])) {
|
||||
$order = $_GET['order'];
|
||||
}
|
||||
|
||||
$result = strnatcmp( $a[$orderby], $b[$orderby] );
|
||||
$result = strnatcmp($a[$orderby], $b[$orderby]);
|
||||
|
||||
if ( $order === 'asc' ) {
|
||||
return $result;
|
||||
}
|
||||
if ($order === 'asc') {
|
||||
return $result;
|
||||
}
|
||||
|
||||
return -$result;
|
||||
}
|
||||
return -$result;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* GDK_Points Admin class
|
||||
*/
|
||||
class GDK_Points_Admin {
|
||||
class GDK_Points_Admin
|
||||
{
|
||||
|
||||
public static function init () {
|
||||
add_action( 'admin_notices', [ __CLASS__, 'admin_notices' ] );
|
||||
add_action( 'admin_menu', [ __CLASS__, 'admin_menu' ], 'manage_options' );
|
||||
}
|
||||
public static function init()
|
||||
{
|
||||
add_action('admin_notices', [__CLASS__, 'admin_notices']);
|
||||
add_action('admin_menu', [__CLASS__, 'admin_menu'], 'manage_options');
|
||||
}
|
||||
|
||||
public static function admin_notices() {
|
||||
if ( !empty( self::$notices ) ) {
|
||||
foreach ( self::$notices as $notice ) {
|
||||
echo $notice;
|
||||
}
|
||||
}
|
||||
}
|
||||
public static function admin_notices()
|
||||
{
|
||||
if (!empty(self::$notices)) {
|
||||
foreach (self::$notices as $notice) {
|
||||
echo $notice;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the admin section.
|
||||
*/
|
||||
public static function admin_menu() {
|
||||
$admin_page = add_menu_page('金币','金币','manage_options','points',[ __CLASS__, 'points_menu'],'dashicons-awards');
|
||||
}
|
||||
/**
|
||||
* Adds the admin section.
|
||||
*/
|
||||
public static function admin_menu()
|
||||
{
|
||||
$admin_page = add_menu_page('金币', '金币', 'manage_options', 'points', [__CLASS__, 'points_menu'], 'dashicons-awards');
|
||||
}
|
||||
|
||||
public static function points_menu() {
|
||||
$alert = "";
|
||||
if(isset( $_POST['psearch'] )){
|
||||
$sdata = trim($_POST['psearch']);
|
||||
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(filter_var($sdata, FILTER_VALIDATE_EMAIL)){//email
|
||||
$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>';
|
||||
}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>';
|
||||
}
|
||||
if(is_array($points)){
|
||||
foreach ( $points as $point ) {
|
||||
$k[] = '<div style="margin-bottom:5px;">金币:'.$point->points.' 描述:'.$point->description.' 日期:'.$point->datetime.'</div>';
|
||||
}
|
||||
}else{
|
||||
$k[] = '<div style="margin-bottom:5px;">金币:'.$points->points.' 描述:'.$points->description.' 日期:'.$points->datetime.'</div>';
|
||||
}
|
||||
$alert = implode(" ", $k);
|
||||
}
|
||||
public static function points_menu()
|
||||
{
|
||||
$alert = "";
|
||||
if (isset($_POST['psearch'])) {
|
||||
$sdata = trim($_POST['psearch']);
|
||||
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 (filter_var($sdata, FILTER_VALIDATE_EMAIL)) { //email
|
||||
$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>';
|
||||
} 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>';
|
||||
}
|
||||
if (is_array($points)) {
|
||||
foreach ($points as $point) {
|
||||
$k[] = '<div style="margin-bottom:5px;">金币:' . $point->points . ' 描述:' . $point->description . ' 日期:' . $point->datetime . '</div>';
|
||||
}
|
||||
} else {
|
||||
$k[] = '<div style="margin-bottom:5px;">金币:' . $points->points . ' 描述:' . $points->description . ' 日期:' . $points->datetime . '</div>';
|
||||
}
|
||||
$alert = implode(" ", $k);
|
||||
}
|
||||
|
||||
if ( isset( $_POST['save'] ) && isset( $_POST['action'] ) ) {
|
||||
if ( $_POST['action'] == "edit" ) {
|
||||
$point_id = isset($_POST['point_id'])?intval( $_POST['point_id'] ) : null;
|
||||
$points = GDK_Points::get_point( $point_id );
|
||||
$data = array();
|
||||
if ( isset( $_POST['user_mail'] ) ) {
|
||||
$data['user_mail'] = $_POST['user_mail'];
|
||||
}
|
||||
if ( isset( $_POST['user_id'] ) ) {
|
||||
$data['user_id'] = $_POST['user_id'];
|
||||
}
|
||||
if ( isset( $_POST['datetime'] ) ) {
|
||||
$data['datetime'] = $_POST['datetime'];
|
||||
}
|
||||
if ( isset( $_POST['description'] ) ) {
|
||||
$data['description'] = $_POST['description'];
|
||||
}
|
||||
if ( isset( $_POST['status'] ) ) {
|
||||
$data['status'] = $_POST['status'];
|
||||
}
|
||||
if ( isset( $_POST['points'] ) ) {
|
||||
$data['points'] = $_POST['points'];
|
||||
}
|
||||
if (isset($_POST['save']) && isset($_POST['action'])) {
|
||||
if ($_POST['action'] == "edit") {
|
||||
$point_id = isset($_POST['point_id']) ? intval($_POST['point_id']) : null;
|
||||
$points = GDK_Points::get_point($point_id);
|
||||
$data = array();
|
||||
if (isset($_POST['user_mail'])) {
|
||||
$data['user_mail'] = $_POST['user_mail'];
|
||||
}
|
||||
if (isset($_POST['user_id'])) {
|
||||
$data['user_id'] = $_POST['user_id'];
|
||||
}
|
||||
if (isset($_POST['datetime'])) {
|
||||
$data['datetime'] = $_POST['datetime'];
|
||||
}
|
||||
if (isset($_POST['description'])) {
|
||||
$data['description'] = $_POST['description'];
|
||||
}
|
||||
if (isset($_POST['status'])) {
|
||||
$data['status'] = $_POST['status'];
|
||||
}
|
||||
if (isset($_POST['points'])) {
|
||||
$data['points'] = $_POST['points'];
|
||||
}
|
||||
|
||||
if ( $points ) { // 编辑金币
|
||||
GDK_Points::update_points($point_id, $data);
|
||||
} else { // 增加金币
|
||||
if ( isset( $_POST['user_mail'] ) ) {//如果输入邮箱的话
|
||||
$usermail = $data['user_mail'];
|
||||
$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'] );
|
||||
$usermail = $user->user_email;
|
||||
$userid = $data['user_id'];
|
||||
$username = $user->display_name;
|
||||
}
|
||||
GDK_Points::set_points($_POST['points'], $userid, $data);
|
||||
$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 40px"><div style="padding:0;font-weight:700;color:#6e6e6e;font-size:16px">尊敬的'.$username.',您好!</div><p style="color:#6e6e6e;font-size:13px;line-height:24px">您的金币金额被管理员调整,请查收!</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">'.$username.'</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">'.$_POST['points'].'</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">'.GDK_Points::get_user_total_points($userid, 'accepted' ).'</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( $usermail , 'Hi,'.$username.',金币账户金额增加通知!', $message ,$headers);
|
||||
}
|
||||
}
|
||||
$alert= "金币已更新";
|
||||
}
|
||||
if ( isset( $_GET["action"] ) ) {
|
||||
$action = $_GET["action"];
|
||||
if ( $action !== null ) {
|
||||
switch ( $action ) {
|
||||
case 'edit' :
|
||||
if ( isset( $_GET['point_id'] ) && ( $_GET['point_id'] !== null ) ) {
|
||||
return self::points_admin_points_edit( intval( $_GET['point_id'] ) );
|
||||
} else {
|
||||
return self::points_admin_points_edit();
|
||||
}
|
||||
break;
|
||||
case 'delete' :
|
||||
if ( $_GET['point_id'] !== null ) {
|
||||
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'";
|
||||
$wpdb->query($wcu_sql);
|
||||
$alert= "金币已删除";
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($points) { // 编辑金币
|
||||
GDK_Points::update_points($point_id, $data);
|
||||
} else { // 增加金币
|
||||
if (isset($_POST['user_mail'])) { //如果输入邮箱的话
|
||||
$usermail = $data['user_mail'];
|
||||
$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']);
|
||||
$usermail = $user->user_email;
|
||||
$userid = $data['user_id'];
|
||||
$username = $user->display_name;
|
||||
}
|
||||
GDK_Points::set_points($_POST['points'], $userid, $data);
|
||||
$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 40px"><div style="padding:0;font-weight:700;color:#6e6e6e;font-size:16px">尊敬的' . $username . ',您好!</div><p style="color:#6e6e6e;font-size:13px;line-height:24px">您的金币金额被管理员调整,请查收!</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">' . $username . '</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">' . $_POST['points'] . '</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">' . GDK_Points::get_user_total_points($userid, 'accepted') . '</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($usermail, 'Hi,' . $username . ',金币账户金额增加通知!', $message, $headers);
|
||||
}
|
||||
}
|
||||
$alert = "金币已更新";
|
||||
}
|
||||
if (isset($_GET["action"])) {
|
||||
$action = $_GET["action"];
|
||||
if ($action !== null) {
|
||||
switch ($action) {
|
||||
case 'edit':
|
||||
if (isset($_GET['point_id']) && ($_GET['point_id'] !== null)) {
|
||||
return self::points_admin_points_edit(intval($_GET['point_id']));
|
||||
} else {
|
||||
return self::points_admin_points_edit();
|
||||
}
|
||||
break;
|
||||
case 'delete':
|
||||
if ($_GET['point_id'] !== null) {
|
||||
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'";
|
||||
$wpdb->query($wcu_sql);
|
||||
$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 );
|
||||
$exampleListTable = new GDK_Points_List_Table();
|
||||
$exampleListTable->prepare_items();
|
||||
?>
|
||||
$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>
|
||||
<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/用户邮箱/订单号" 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(); ?>
|
||||
<?php echo '<style type="text/css">tbody#the-list tr:hover{background:rgba(132,219,162,.61)}</style>';
|
||||
$exampleListTable->display(); ?>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
|
||||
public static function points_admin_points_edit( $point_id = null ) {
|
||||
global $wpdb;
|
||||
$output = '';
|
||||
public static function points_admin_points_edit($point_id = null)
|
||||
{
|
||||
global $wpdb;
|
||||
$output = '';
|
||||
|
||||
if ( !current_user_can( 'administrator' ) ) {
|
||||
wp_die( 'Access denied.' );
|
||||
}
|
||||
if (!current_user_can('administrator')) {
|
||||
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 = 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);
|
||||
|
||||
$saved = false; // temporal
|
||||
$saved = false; // temporal
|
||||
|
||||
if ( $point_id !== null ) {
|
||||
$points = GDK_Points::get_point( $point_id );
|
||||
if ($point_id !== null) {
|
||||
$points = GDK_Points::get_point($point_id);
|
||||
|
||||
if ( $points !== null ) {
|
||||
$user_id = $points->user_id;
|
||||
$num_points = $points->points;
|
||||
$description = $points->description;
|
||||
$datetime = $points->datetime;
|
||||
$status = $points->status;
|
||||
}
|
||||
} else {
|
||||
$user_id = "";
|
||||
$num_points = 0;
|
||||
$description = "ADD";
|
||||
$datetime = "";
|
||||
$status = 'accepted';
|
||||
}
|
||||
if ($points !== null) {
|
||||
$user_id = $points->user_id;
|
||||
$num_points = $points->points;
|
||||
$description = $points->description;
|
||||
$datetime = $points->datetime;
|
||||
$status = $points->status;
|
||||
}
|
||||
} else {
|
||||
$user_id = "";
|
||||
$num_points = 0;
|
||||
$description = "ADD";
|
||||
$datetime = "";
|
||||
$status = 'accepted';
|
||||
}
|
||||
|
||||
if ( empty( $point_id ) ) {
|
||||
$pointsclass = 'newpoint';
|
||||
} else {
|
||||
$pointsclass = 'editpoint';
|
||||
}
|
||||
$output .= '<div class="points '.$pointsclass.'">';
|
||||
$output .= '<h2>';
|
||||
if ( empty( $point_id ) ) {
|
||||
$output .= '新金币';
|
||||
} else {
|
||||
$output .= '编辑金币';
|
||||
}
|
||||
$output .= '</h2>';
|
||||
$output .= '<form id="points" action="' . $current_url . '" method="post">';
|
||||
$output .= '<div>';
|
||||
if (empty($point_id)) {
|
||||
$pointsclass = 'newpoint';
|
||||
} else {
|
||||
$pointsclass = 'editpoint';
|
||||
}
|
||||
$output .= '<div class="points ' . $pointsclass . '">';
|
||||
$output .= '<h2>';
|
||||
if (empty($point_id)) {
|
||||
$output .= '新金币';
|
||||
} else {
|
||||
$output .= '编辑金币';
|
||||
}
|
||||
$output .= '</h2>';
|
||||
$output .= '<form id="points" action="' . $current_url . '" method="post">';
|
||||
$output .= '<div>';
|
||||
|
||||
if ( $point_id ) {
|
||||
$output .= sprintf( '<input type="hidden" name="point_id" value="%d" />', intval( $point_id ) );
|
||||
}
|
||||
if ($point_id) {
|
||||
$output .= sprintf('<input type="hidden" name="point_id" value="%d" />', intval($point_id));
|
||||
}
|
||||
|
||||
$output .= '<input type="hidden" name="action" value="edit" />';
|
||||
$output .= '<p class="usermail">';
|
||||
$output .= '<label>';
|
||||
$output .= '<span class="title">用户邮箱</span>';
|
||||
$output .= ' ';
|
||||
$output .= sprintf( '<input type="text" name="user_mail" value="%s" />', $user_mail );
|
||||
$output .= ' ';
|
||||
$output .= '<span class="description">用户在网站的注册邮箱</span>';
|
||||
$output .= '</label>';
|
||||
$output .= '</p>';
|
||||
$output .= '<p class="userid">';
|
||||
$output .= '<label>';
|
||||
$output .= '<span class="title">用户ID</span>';
|
||||
$output .= ' ';
|
||||
$output .= sprintf( '<input type="text" name="user_id" value="%s" />', $user_id );
|
||||
$output .= ' ';
|
||||
$output .= '<span class="description">输入用户ID,与用户邮箱勿冲突</span>';
|
||||
$output .= '</label>';
|
||||
$output .= '</p>';
|
||||
$output .= '<p>';
|
||||
$output .= '<label>';
|
||||
$output .= '<span class="title">日期&时间</span>';
|
||||
$output .= ' ';
|
||||
$output .= sprintf( '<input type="text" name="datetime" value="%s" id="datetimepicker" />', esc_attr( $datetime ) );
|
||||
$output .= ' ';
|
||||
$output .= '<span class="description">格式 : YYYY-MM-DD HH:MM:SS【可忽略,自动生成】</span>';
|
||||
$output .= '</label>';
|
||||
$output .= '</p>';
|
||||
$output .= '<p>';
|
||||
$output .= '<label>';
|
||||
$output .= '<span class="title">描述</span>';
|
||||
$output .= '<br>';
|
||||
$output .= '<textarea name="description">';
|
||||
$output .= stripslashes( $description );
|
||||
$output .= '</textarea>';
|
||||
$output .= '</label>';
|
||||
$output .= '</p>';
|
||||
$output .= '<p>';
|
||||
$output .= '<label>';
|
||||
$output .= '<span class="title">金币</span>';
|
||||
$output .= ' ';
|
||||
$output .= sprintf( '<input type="text" name="points" value="%s" />', esc_attr( $num_points ) );
|
||||
$output .= '</label>';
|
||||
$output .= '</p>';
|
||||
$status_descriptions = array(
|
||||
'accepted' => '正常',
|
||||
'pending' => '待审',
|
||||
'rejected' => '驳回',
|
||||
);
|
||||
$output .= '<p>';
|
||||
$output .= '<label>';
|
||||
$output .= '<span class="title">状态</span>';
|
||||
$output .= ' ';
|
||||
$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 .= '</select>';
|
||||
$output .= '</label>';
|
||||
$output .= '</p>';
|
||||
$output .= wp_nonce_field( 'save', 'points-nonce', true, false );
|
||||
$output .= sprintf( '<input class="button" type="submit" name="save" value="%s"/>', '保存' );
|
||||
$output .= ' ';
|
||||
$output .= sprintf( '<a class="cancel" href="%s">%s</a>', $cancel_url, $saved ? '返回' : '取消' );
|
||||
$output .= '</div>';
|
||||
$output .= '</form>';
|
||||
$output .= '</div>';
|
||||
echo $output;
|
||||
}
|
||||
$output .= '<input type="hidden" name="action" value="edit" />';
|
||||
$output .= '<p class="usermail">';
|
||||
$output .= '<label>';
|
||||
$output .= '<span class="title">用户邮箱</span>';
|
||||
$output .= ' ';
|
||||
$output .= sprintf('<input type="text" name="user_mail" value="%s" />', $user_mail);
|
||||
$output .= ' ';
|
||||
$output .= '<span class="description">用户在网站的注册邮箱</span>';
|
||||
$output .= '</label>';
|
||||
$output .= '</p>';
|
||||
$output .= '<p class="userid">';
|
||||
$output .= '<label>';
|
||||
$output .= '<span class="title">用户ID</span>';
|
||||
$output .= ' ';
|
||||
$output .= sprintf('<input type="text" name="user_id" value="%s" />', $user_id);
|
||||
$output .= ' ';
|
||||
$output .= '<span class="description">输入用户ID,与用户邮箱勿冲突</span>';
|
||||
$output .= '</label>';
|
||||
$output .= '</p>';
|
||||
$output .= '<p>';
|
||||
$output .= '<label>';
|
||||
$output .= '<span class="title">日期&时间</span>';
|
||||
$output .= ' ';
|
||||
$output .= sprintf('<input type="text" name="datetime" value="%s" id="datetimepicker" />', esc_attr($datetime));
|
||||
$output .= ' ';
|
||||
$output .= '<span class="description">格式 : YYYY-MM-DD HH:MM:SS【可忽略,自动生成】</span>';
|
||||
$output .= '</label>';
|
||||
$output .= '</p>';
|
||||
$output .= '<p>';
|
||||
$output .= '<label>';
|
||||
$output .= '<span class="title">描述</span>';
|
||||
$output .= '<br>';
|
||||
$output .= '<textarea name="description">';
|
||||
$output .= stripslashes($description);
|
||||
$output .= '</textarea>';
|
||||
$output .= '</label>';
|
||||
$output .= '</p>';
|
||||
$output .= '<p>';
|
||||
$output .= '<label>';
|
||||
$output .= '<span class="title">金币</span>';
|
||||
$output .= ' ';
|
||||
$output .= sprintf('<input type="text" name="points" value="%s" />', esc_attr($num_points));
|
||||
$output .= '</label>';
|
||||
$output .= '</p>';
|
||||
$status_descriptions = array(
|
||||
'accepted' => '正常',
|
||||
'pending' => '待审',
|
||||
'rejected' => '驳回',
|
||||
);
|
||||
$output .= '<p>';
|
||||
$output .= '<label>';
|
||||
$output .= '<span class="title">状态</span>';
|
||||
$output .= ' ';
|
||||
$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 .= '</select>';
|
||||
$output .= '</label>';
|
||||
$output .= '</p>';
|
||||
$output .= wp_nonce_field('save', 'points-nonce', true, false);
|
||||
$output .= sprintf('<input class="button" type="submit" name="save" value="%s"/>', '保存');
|
||||
$output .= ' ';
|
||||
$output .= sprintf('<a class="cancel" href="%s">%s</a>', $cancel_url, $saved ? '返回' : '取消');
|
||||
$output .= '</div>';
|
||||
$output .= '</form>';
|
||||
$output .= '</div>';
|
||||
echo $output;
|
||||
}
|
||||
}
|
|
@ -1,161 +1,166 @@
|
|||
<?php
|
||||
/**
|
||||
* class-points-shortcodes.php
|
||||
*/
|
||||
class GDK_Points_Shortcodes {
|
||||
/**
|
||||
* Add shortcodes.
|
||||
*/
|
||||
public static function init() {
|
||||
add_shortcode( 'points_users_list', [ __CLASS__, 'points_users_list' ] );
|
||||
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' ] );
|
||||
* class-points-shortcodes.php
|
||||
*/
|
||||
class GDK_Points_Shortcodes
|
||||
{
|
||||
/**
|
||||
* Add shortcodes.
|
||||
*/
|
||||
public static function init()
|
||||
{
|
||||
add_shortcode('points_users_list', [__CLASS__, 'points_users_list']);
|
||||
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,
|
||||
'order_by' => 'points',
|
||||
'order' => 'DESC'
|
||||
],
|
||||
$atts
|
||||
);
|
||||
extract( $options );
|
||||
$output = "";
|
||||
$pointsusers = GDK_Points::get_users();
|
||||
if ( sizeof( $pointsusers )>0 ) {
|
||||
foreach ( $pointsusers as $pointsuser ) {
|
||||
$total = GDK_Points::get_user_total_points( $pointsuser );
|
||||
$output .='<div class="points-user">';
|
||||
$output .= '<span style="font-weight:bold;width:100%;" class="points-user-username">';
|
||||
$output .= get_user_meta ( $pointsuser, 'nickname', true );
|
||||
$output .= ':</span>';
|
||||
$output .= '<span class="points-user-points">';
|
||||
$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' => ""],
|
||||
$atts
|
||||
);
|
||||
extract( $options );
|
||||
if ( $id == "" ) {
|
||||
$id = get_current_user_id();
|
||||
}
|
||||
if ( $id !== 0 ) {
|
||||
$points = GDK_Points::get_user_total_points( $id, 'accepted' );
|
||||
$output .= $points;
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
||||
/*付费可见短代码开始*/
|
||||
|
||||
public static function pay($atts, $content = null) {
|
||||
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));
|
||||
$notice = '';
|
||||
add_post_meta($pid, '_point_content', $content, true) or update_post_meta($pid, '_point_content', $content);//没有新建,有就更新
|
||||
if (is_user_logged_in()) {
|
||||
if ($result == $pid || current_user_can('administrator')) {
|
||||
$notice.= '<div class="cm-alert success">';
|
||||
$notice.= $content;
|
||||
$notice.= '</div>';
|
||||
}
|
||||
public static function points_users_list($atts, $content = null)
|
||||
{
|
||||
$options = shortcode_atts(
|
||||
[
|
||||
'limit' => 10,
|
||||
'order_by' => 'points',
|
||||
'order' => 'DESC',
|
||||
],
|
||||
$atts
|
||||
);
|
||||
extract($options);
|
||||
$output = "";
|
||||
$pointsusers = GDK_Points::get_users();
|
||||
if (sizeof($pointsusers) > 0) {
|
||||
foreach ($pointsusers as $pointsuser) {
|
||||
$total = GDK_Points::get_user_total_points($pointsuser);
|
||||
$output .= '<div class="points-user">';
|
||||
$output .= '<span style="font-weight:bold;width:100%;" class="points-user-username">';
|
||||
$output .= get_user_meta($pointsuser, 'nickname', true);
|
||||
$output .= ':</span>';
|
||||
$output .= '<span class="points-user-points">';
|
||||
$output .= " " . $total . " 金币";
|
||||
$output .= '</span>';
|
||||
$output .= '</div>';
|
||||
}
|
||||
} else {
|
||||
if (GDK_Points::get_user_total_points($user_id, 'accepted') < $point) {
|
||||
$notice.= '<fieldset id="hide_notice" class="fieldset"><legend class="legend">付费内容</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.= buy_points();
|
||||
$notice.= '</fieldset>';
|
||||
$output .= '<p>No users</p>';
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
public static function points_user_points($atts, $content = null)
|
||||
{
|
||||
$output = "";
|
||||
$options = shortcode_atts(['id' => ""],
|
||||
$atts
|
||||
);
|
||||
extract($options);
|
||||
if ($id == "") {
|
||||
$id = get_current_user_id();
|
||||
}
|
||||
if ($id !== 0) {
|
||||
$points = GDK_Points::get_user_total_points($id, 'accepted');
|
||||
$output .= $points;
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
||||
/*付费可见短代码开始*/
|
||||
|
||||
public static function pay($atts, $content = null)
|
||||
{
|
||||
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));
|
||||
$notice = '';
|
||||
add_post_meta($pid, '_point_content', $content, true) or update_post_meta($pid, '_point_content', $content); //没有新建,有就更新
|
||||
if (is_user_logged_in()) {
|
||||
if ($result == $pid || current_user_can('administrator')) {
|
||||
$notice .= '<div class="cm-alert success">';
|
||||
$notice .= $content;
|
||||
$notice .= '</div>';
|
||||
} else {
|
||||
$notice.= '<fieldset id="hide_notice" class="fieldset"><legend class="legend">付费内容</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.= '</fieldset>';
|
||||
if (GDK_Points::get_user_total_points($user_id, 'accepted') < $point) {
|
||||
$notice .= '<fieldset id="hide_notice" class="fieldset"><legend class="legend">付费内容</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 .= buy_points();
|
||||
$notice .= '</fieldset>';
|
||||
} else {
|
||||
$notice .= '<fieldset id="hide_notice" class="fieldset"><legend class="legend">付费内容</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 .= '</fieldset>';
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$notice .= '<fieldset id="hide_notice" class="fieldset"><legend class="legend">付费内容</legend>';
|
||||
$notice .= '<p>当前隐藏内容需要支付</p><span class="cm-coin">' . $point . '金币</span>';
|
||||
$notice .= '<p>您当前尚未登陆,请登陆后查看</p>';
|
||||
$notice .= weixin_login_btn();
|
||||
$notice .= '</fieldset>';
|
||||
}
|
||||
return $notice;
|
||||
}
|
||||
/*付费可见短代码结束*/
|
||||
/**
|
||||
* Shortcode. 显示用户的金币细节
|
||||
*/
|
||||
public static function points_user_points_details($atts, $content = null)
|
||||
{
|
||||
$options = shortcode_atts(
|
||||
[
|
||||
'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'))) {
|
||||
$description = false;
|
||||
}
|
||||
|
||||
$desc_th = '';
|
||||
if ($description) {
|
||||
$desc_th = '<th>描述</th>';
|
||||
}
|
||||
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 .
|
||||
'</tr>';
|
||||
if ($user_id !== 0) {
|
||||
if (sizeof($points) > 0) {
|
||||
foreach ($points as $point) {
|
||||
$desc_td = '';
|
||||
if ($description) {
|
||||
$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 .
|
||||
'</tr>';
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$notice.= '<fieldset id="hide_notice" class="fieldset"><legend class="legend">付费内容</legend>';
|
||||
$notice.= '<p>当前隐藏内容需要支付</p><span class="cm-coin">'.$point.'金币</span>';
|
||||
$notice.= '<p>您当前尚未登陆,请登陆后查看</p>';
|
||||
$notice.= weixin_login_btn();
|
||||
$notice.= '</fieldset>';
|
||||
|
||||
$output .= '</table>';
|
||||
|
||||
return $output;
|
||||
}
|
||||
return $notice;
|
||||
}
|
||||
/*付费可见短代码结束*/
|
||||
/**
|
||||
* Shortcode. 显示用户的金币细节
|
||||
*/
|
||||
public static function points_user_points_details ( $atts, $content = null ) {
|
||||
$options = shortcode_atts(
|
||||
[
|
||||
'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' ) ) ) {
|
||||
$description = false;
|
||||
}
|
||||
|
||||
$desc_th = '';
|
||||
if ( $description ) {
|
||||
$desc_th = '<th>描述</th>';
|
||||
}
|
||||
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 .
|
||||
'</tr>';
|
||||
if ( $user_id !== 0 ) {
|
||||
if ( sizeof( $points ) > 0 ) {
|
||||
foreach ( $points as $point ) {
|
||||
$desc_td = '';
|
||||
if ( $description ) {
|
||||
$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 .
|
||||
'</tr>';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$output .= '</table>';
|
||||
|
||||
|
||||
return $output;
|
||||
}
|
||||
}
|
||||
GDK_Points_Shortcodes::init();
|
||||
GDK_Points_Shortcodes::init();
|
||||
|
|
|
@ -3,226 +3,237 @@
|
|||
/**
|
||||
* GDK_Points_Database class
|
||||
*/
|
||||
class GDK_Points_Database {
|
||||
public static $prefix = "points_";
|
||||
public static function points_get_table( $table ) {
|
||||
global $wpdb;
|
||||
$result = "";
|
||||
switch ( $table ) {
|
||||
case "users":
|
||||
$result = $wpdb->prefix . self::$prefix . "users";
|
||||
break;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
class GDK_Points_Database
|
||||
{
|
||||
public static $prefix = "points_";
|
||||
public static function points_get_table($table)
|
||||
{
|
||||
global $wpdb;
|
||||
$result = "";
|
||||
switch ($table) {
|
||||
case "users":
|
||||
$result = $wpdb->prefix . self::$prefix . "users";
|
||||
break;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* GDK_Points class
|
||||
*/
|
||||
class GDK_Points {
|
||||
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;
|
||||
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;
|
||||
}
|
||||
$order_by_str = "";
|
||||
if ( isset( $order_by ) && ( $order_by !== null ) ) {
|
||||
$order_by_str = " ORDER BY " . $order_by;
|
||||
}
|
||||
$order_str = "";
|
||||
if ( isset( $order ) && ( $order !== null ) ) {
|
||||
$order_str = " " . $order;
|
||||
}
|
||||
$limit_str = '';
|
||||
if (isset($limit) && ($limit !== null)) {
|
||||
$limit_str = ' LIMIT ' . $offset . ' ,' . $limit;
|
||||
}
|
||||
$order_by_str = "";
|
||||
if (isset($order_by) && ($order_by !== null)) {
|
||||
$order_by_str = " ORDER BY " . $order_by;
|
||||
}
|
||||
$order_str = "";
|
||||
if (isset($order) && ($order !== null)) {
|
||||
$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;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function get_user_total_points ( $user_id, $status = null ) {
|
||||
global $wpdb;
|
||||
public static function get_user_total_points($user_id, $status = null)
|
||||
{
|
||||
global $wpdb;
|
||||
|
||||
$result = 0;
|
||||
$result = 0;
|
||||
|
||||
$where_status = '';
|
||||
if ( $status !== null ) {
|
||||
$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);
|
||||
$where_status = '';
|
||||
if ($status !== null) {
|
||||
$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);
|
||||
|
||||
if ( $points && ( $points->total !== NULL ) ) {
|
||||
$result = $points->total;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
if ($points && ($points->total !== null)) {
|
||||
$result = $points->total;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function get_users_total_points ( $limit = null, $order_by = null, $order = null, $status = null ) {
|
||||
global $wpdb;
|
||||
public static function get_users_total_points($limit = null, $order_by = null, $order = null, $status = null)
|
||||
{
|
||||
global $wpdb;
|
||||
|
||||
$where_status = '';
|
||||
if ( $status !== null ) {
|
||||
$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");
|
||||
$where_status = '';
|
||||
if ($status !== null) {
|
||||
$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");
|
||||
|
||||
return $points;
|
||||
}
|
||||
return $points;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get users id who have some points
|
||||
* @param $user_id
|
||||
* @return array
|
||||
*/
|
||||
public static function get_users() {
|
||||
global $wpdb;
|
||||
/**
|
||||
* 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();
|
||||
if ( sizeof( $users_id ) > 0 ) {
|
||||
foreach ( $users_id as $user_id ) {
|
||||
$result[] = $user_id->user_id;
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
$result = array();
|
||||
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() ) {
|
||||
global $wpdb;
|
||||
public static function set_points($points, $user_id, $info = array())
|
||||
{
|
||||
global $wpdb;
|
||||
|
||||
$values = array( 'points' => $points );
|
||||
$values = array('points' => $points);
|
||||
|
||||
if ( isset( $info['datetime'] ) && ( $info['datetime'] !== "" ) ) {
|
||||
$values['datetime'] = $info['datetime'];
|
||||
} else {
|
||||
$values['datetime'] = date('Y-m-d H:i:s', time() );
|
||||
}
|
||||
if ( isset( $info['description'] ) ) {
|
||||
$values['description'] = $info['description'];
|
||||
}
|
||||
if ( isset( $info['status'] ) ) {
|
||||
$values['status'] = $info['status'];
|
||||
}
|
||||
if ( isset( $info['type'] ) ) {
|
||||
$values['type'] = $info['type'];
|
||||
}
|
||||
if ( isset( $info['data'] ) ) {
|
||||
$values['data'] = $info['data']; // yet serialized
|
||||
}
|
||||
if ( isset( $info['ip'] ) ) {
|
||||
$values['ip'] = $info['ip'];
|
||||
}
|
||||
if ( isset( $info['ipv6'] ) ) {
|
||||
$values['ipv6'] = $info['ipv6'];
|
||||
}
|
||||
$values['user_id'] = $user_id;
|
||||
if (isset($info['datetime']) && ($info['datetime'] !== "")) {
|
||||
$values['datetime'] = $info['datetime'];
|
||||
} else {
|
||||
$values['datetime'] = date('Y-m-d H:i:s', time());
|
||||
}
|
||||
if (isset($info['description'])) {
|
||||
$values['description'] = $info['description'];
|
||||
}
|
||||
if (isset($info['status'])) {
|
||||
$values['status'] = $info['status'];
|
||||
}
|
||||
if (isset($info['type'])) {
|
||||
$values['type'] = $info['type'];
|
||||
}
|
||||
if (isset($info['data'])) {
|
||||
$values['data'] = $info['data']; // yet serialized
|
||||
}
|
||||
if (isset($info['ip'])) {
|
||||
$values['ip'] = $info['ip'];
|
||||
}
|
||||
if (isset($info['ipv6'])) {
|
||||
$values['ipv6'] = $info['ipv6'];
|
||||
}
|
||||
$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;
|
||||
}
|
||||
return $rows_affected;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a points list.
|
||||
* @param int $limit
|
||||
* @param string $order_by
|
||||
* @param string $order
|
||||
* @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 ) {
|
||||
global $wpdb;
|
||||
/**
|
||||
* Get a points list.
|
||||
* @param int $limit
|
||||
* @param string $order_by
|
||||
* @param string $order
|
||||
* @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)
|
||||
{
|
||||
global $wpdb;
|
||||
|
||||
$where_str = " WHERE status != 'removed'";
|
||||
$where_str = " WHERE status != 'removed'";
|
||||
|
||||
$limit_str = "";
|
||||
if ( isset( $limit ) && ( $limit !== null ) ) {
|
||||
$limit_str = " LIMIT 0 ," . $limit;
|
||||
}
|
||||
$order_by_str = "";
|
||||
if ( isset( $order_by ) && ( $order_by !== null ) ) {
|
||||
$order_by_str = " ORDER BY " . $order_by;
|
||||
}
|
||||
$order_str = "";
|
||||
if ( isset( $order ) && ( $order !== null ) ) {
|
||||
$order_str = " " . $order;
|
||||
}
|
||||
$limit_str = "";
|
||||
if (isset($limit) && ($limit !== null)) {
|
||||
$limit_str = " LIMIT 0 ," . $limit;
|
||||
}
|
||||
$order_by_str = "";
|
||||
if (isset($order_by) && ($order_by !== null)) {
|
||||
$order_by_str = " ORDER BY " . $order_by;
|
||||
}
|
||||
$order_str = "";
|
||||
if (isset($order) && ($order !== null)) {
|
||||
$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;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function get_point ( $point_id = null ) {
|
||||
global $wpdb;
|
||||
public static function get_point($point_id = null)
|
||||
{
|
||||
global $wpdb;
|
||||
|
||||
$result = null;
|
||||
$result = null;
|
||||
|
||||
if ( isset( $point_id ) && ( $point_id !== 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 );
|
||||
}
|
||||
$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;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function remove_points( $point_id ) {
|
||||
global $wpdb;
|
||||
public static function remove_points($point_id)
|
||||
{
|
||||
global $wpdb;
|
||||
|
||||
$values = array();
|
||||
$values['status'] = 'removed';
|
||||
$values = array();
|
||||
$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, array('point_id' => $point_id));
|
||||
|
||||
if ( !$rows_affected ) {
|
||||
$rows_affected = null;
|
||||
}
|
||||
return $rows_affected;
|
||||
}
|
||||
if (!$rows_affected) {
|
||||
$rows_affected = null;
|
||||
}
|
||||
return $rows_affected;
|
||||
}
|
||||
|
||||
public static function update_points( $point_id, $info = array() ) {
|
||||
global $wpdb;
|
||||
public static function update_points($point_id, $info = array())
|
||||
{
|
||||
global $wpdb;
|
||||
|
||||
$values = array();
|
||||
$values = array();
|
||||
|
||||
if ( isset( $info['user_id'] ) ) {
|
||||
$values['user_id'] = $info['user_id'];
|
||||
}
|
||||
if ( isset( $info['datetime'] ) ) {
|
||||
$values['datetime'] = $info['datetime'];
|
||||
}
|
||||
if ( isset( $info['description'] ) ) {
|
||||
$values['description'] = $info['description'];
|
||||
}
|
||||
if ( isset( $info['status'] ) ) {
|
||||
$values['status'] = $info['status'];
|
||||
}
|
||||
if ( isset( $info['points'] ) ) {
|
||||
$values['points'] = $info['points'];
|
||||
}
|
||||
if ( isset( $info['type'] ) ) {
|
||||
$values['type'] = $info['type'];
|
||||
}
|
||||
if ( isset( $info['data'] ) ) {
|
||||
$values['data'] = $info['data']; // yet serialized
|
||||
}
|
||||
if ( isset( $info['ip'] ) ) {
|
||||
$values['ip'] = $info['ip'];
|
||||
}
|
||||
if ( isset( $info['ipv6'] ) ) {
|
||||
$values['ipv6'] = $info['ipv6'];
|
||||
}
|
||||
if (isset($info['user_id'])) {
|
||||
$values['user_id'] = $info['user_id'];
|
||||
}
|
||||
if (isset($info['datetime'])) {
|
||||
$values['datetime'] = $info['datetime'];
|
||||
}
|
||||
if (isset($info['description'])) {
|
||||
$values['description'] = $info['description'];
|
||||
}
|
||||
if (isset($info['status'])) {
|
||||
$values['status'] = $info['status'];
|
||||
}
|
||||
if (isset($info['points'])) {
|
||||
$values['points'] = $info['points'];
|
||||
}
|
||||
if (isset($info['type'])) {
|
||||
$values['type'] = $info['type'];
|
||||
}
|
||||
if (isset($info['data'])) {
|
||||
$values['data'] = $info['data']; // yet serialized
|
||||
}
|
||||
if (isset($info['ip'])) {
|
||||
$values['ip'] = $info['ip'];
|
||||
}
|
||||
if (isset($info['ipv6'])) {
|
||||
$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, array('point_id' => $point_id));
|
||||
|
||||
if ( !$rows_affected ) { // insert
|
||||
$rows_affected = null;
|
||||
}
|
||||
return $rows_affected;
|
||||
}
|
||||
if (!$rows_affected) { // insert
|
||||
$rows_affected = null;
|
||||
}
|
||||
return $rows_affected;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,41 +1,43 @@
|
|||
<?php
|
||||
|
||||
|
||||
include 'class-points.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']);
|
||||
add_action('admin_init', [__CLASS__, 'activate']);
|
||||
}
|
||||
|
||||
class GDK_Points_Class {
|
||||
private static $notices = [];
|
||||
public static function init() {
|
||||
add_action( 'init', [ __CLASS__, 'wp_init' ] );
|
||||
add_action( 'admin_init', [ __CLASS__, 'activate' ] );
|
||||
}
|
||||
public static function wp_init()
|
||||
{
|
||||
GDK_Points_Admin::init();
|
||||
}
|
||||
|
||||
public static function wp_init() {
|
||||
GDK_Points_Admin::init();
|
||||
}
|
||||
/**
|
||||
* activation work.
|
||||
*
|
||||
*/
|
||||
public static function activate()
|
||||
{
|
||||
global $wpdb;
|
||||
|
||||
/**
|
||||
* activation work.
|
||||
*
|
||||
*/
|
||||
public static function activate() {
|
||||
global $wpdb;
|
||||
$charset_collate = '';
|
||||
if (!empty($wpdb->charset)) {
|
||||
$charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
|
||||
}
|
||||
if (!empty($wpdb->collate)) {
|
||||
$charset_collate .= " COLLATE $wpdb->collate";
|
||||
}
|
||||
|
||||
$charset_collate = '';
|
||||
if ( ! empty( $wpdb->charset ) ) {
|
||||
$charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
|
||||
}
|
||||
if ( ! empty( $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 (
|
||||
// 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 (
|
||||
point_id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
user_id BIGINT(20) UNSIGNED NOT NULL,
|
||||
points BIGINT(20) DEFAULT 0,
|
||||
|
@ -49,11 +51,11 @@ class GDK_Points_Class {
|
|||
type varchar(32) NULL,
|
||||
PRIMARY KEY (point_id)
|
||||
) $charset_collate;";
|
||||
}
|
||||
if ( !empty( $queries ) ) {
|
||||
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
|
||||
dbDelta( $queries );
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!empty($queries)) {
|
||||
require_once ABSPATH . 'wp-admin/includes/upgrade.php';
|
||||
dbDelta($queries);
|
||||
}
|
||||
}
|
||||
}
|
||||
GDK_Points_Class::init();
|
||||
GDK_Points_Class::init();
|
||||
|
|
|
@ -11,181 +11,196 @@ json数据格式:
|
|||
"download_url" : "http://a.xxoo.net/Git-alpha.zip"
|
||||
}
|
||||
*/
|
||||
if ( !class_exists('ThemeUpdateChecker') ):
|
||||
if (!class_exists('ThemeUpdateChecker')):
|
||||
|
||||
class ThemeUpdateChecker {
|
||||
public $theme = ''; //待检查更新的主题名
|
||||
public $metadataUrl = ''; //元数据文件的路径
|
||||
public $enableAutomaticChecking = true; //是否启用自动更新
|
||||
protected $optionName = ''; //更新信息的参数信息
|
||||
protected $automaticCheckDone = false;
|
||||
protected static $filterPrefix = 'tuc_request_update_';
|
||||
class ThemeUpdateChecker
|
||||
{
|
||||
public $theme = ''; //待检查更新的主题名
|
||||
public $metadataUrl = ''; //元数据文件的路径
|
||||
public $enableAutomaticChecking = true; //是否启用自动更新
|
||||
protected $_optionName = ''; //更新信息的参数信息
|
||||
protected $_automaticCheckDone = false;
|
||||
protected static $_filterPrefix = 'tuc_request_update_';
|
||||
|
||||
public function __construct($theme, $metadataUrl, $enableAutomaticChecking = true){
|
||||
$this->metadataUrl = $metadataUrl;
|
||||
$this->enableAutomaticChecking = $enableAutomaticChecking;
|
||||
$this->theme = $theme;
|
||||
$this->optionName = 'external_theme_updates-'.$this->theme;
|
||||
$this->installHooks();
|
||||
}
|
||||
public function __construct($theme, $metadataUrl, $enableAutomaticChecking = true)
|
||||
{
|
||||
$this->metadataUrl = $metadataUrl;
|
||||
$this->enableAutomaticChecking = $enableAutomaticChecking;
|
||||
$this->theme = $theme;
|
||||
$this->optionName = 'external_theme_updates-' . $this->theme;
|
||||
$this->installHooks();
|
||||
}
|
||||
|
||||
public function installHooks(){
|
||||
public function installHooks()
|
||||
{
|
||||
|
||||
if ( $this->enableAutomaticChecking ){
|
||||
add_filter('pre_set_site_transient_update_themes', array($this, 'onTransientUpdate'));
|
||||
}
|
||||
if ($this->enableAutomaticChecking) {
|
||||
add_filter('pre_set_site_transient_update_themes', array($this, 'onTransientUpdate'));
|
||||
}
|
||||
|
||||
//Insert our update info into the update list maintained by WP.
|
||||
add_filter('site_transient_update_themes', array($this,'injectUpdate'));
|
||||
//Insert our update info into the update list maintained by WP.
|
||||
add_filter('site_transient_update_themes', array($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'));
|
||||
}
|
||||
//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'));
|
||||
}
|
||||
|
||||
public function requestUpdate($queryArgs = array()){
|
||||
//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);
|
||||
public function requestUpdate($queryArgs = array())
|
||||
{
|
||||
//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);
|
||||
|
||||
//Various options for the wp_remote_get() call. Themes can filter these, too.
|
||||
$options = array(
|
||||
'timeout' => 20, //seconds
|
||||
);
|
||||
$options = apply_filters(self::$filterPrefix.'options-'.$this->theme, $options);
|
||||
//Various options for the wp_remote_get() call. Themes can filter these, too.
|
||||
$options = array(
|
||||
'timeout' => 20, //seconds
|
||||
);
|
||||
$options = apply_filters(self::$filterPrefix . 'options-' . $this->theme, $options);
|
||||
|
||||
$url = $this->metadataUrl;
|
||||
if ( !empty($queryArgs) ){
|
||||
$url = add_query_arg($queryArgs, $url);
|
||||
}
|
||||
$url = $this->metadataUrl;
|
||||
if (!empty($queryArgs)) {
|
||||
$url = add_query_arg($queryArgs, $url);
|
||||
}
|
||||
|
||||
//Send the request.
|
||||
$result = wp_remote_get($url, $options);
|
||||
//Send the request.
|
||||
$result = wp_remote_get($url, $options);
|
||||
|
||||
//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) ){
|
||||
$themeUpdate = ThemeUpdate::fromJson($body);
|
||||
//The update should be newer than the currently installed version.
|
||||
if ( ($themeUpdate != null) && version_compare($themeUpdate->version, $this->getInstalledVersion(), '<=') ){
|
||||
$themeUpdate = null;
|
||||
}
|
||||
}
|
||||
//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)) {
|
||||
$themeUpdate = ThemeUpdate::fromJson($body);
|
||||
//The update should be newer than the currently installed version.
|
||||
if (($themeUpdate != null) && version_compare($themeUpdate->version, $this->getInstalledVersion(), '<=')) {
|
||||
$themeUpdate = null;
|
||||
}
|
||||
}
|
||||
|
||||
$themeUpdate = apply_filters(self::$filterPrefix.'result-'.$this->theme, $themeUpdate, $result);
|
||||
return $themeUpdate;
|
||||
}
|
||||
$themeUpdate = apply_filters(self::$filterPrefix . 'result-' . $this->theme, $themeUpdate, $result);
|
||||
return $themeUpdate;
|
||||
}
|
||||
|
||||
public function getInstalledVersion(){
|
||||
if ( function_exists('wp_get_theme') ) {
|
||||
$theme = wp_get_theme($this->theme);
|
||||
return $theme->get('Version');
|
||||
}
|
||||
public function getInstalledVersion()
|
||||
{
|
||||
if (function_exists('wp_get_theme')) {
|
||||
$theme = wp_get_theme($this->theme);
|
||||
return $theme->get('Version');
|
||||
}
|
||||
|
||||
foreach(get_themes() as $theme){
|
||||
if ( $theme['Stylesheet'] === $this->theme ){
|
||||
return $theme['Version'];
|
||||
}
|
||||
}
|
||||
return '';
|
||||
}
|
||||
foreach (get_themes() as $theme) {
|
||||
if ($theme['Stylesheet'] === $this->theme) {
|
||||
return $theme['Version'];
|
||||
}
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
public function checkForUpdates(){
|
||||
$state = get_option($this->optionName);
|
||||
if ( empty($state) ){
|
||||
$state = new StdClass;
|
||||
$state->lastCheck = 0;
|
||||
$state->checkedVersion = '';
|
||||
$state->update = null;
|
||||
}
|
||||
public function checkForUpdates()
|
||||
{
|
||||
$state = get_option($this->optionName);
|
||||
if (empty($state)) {
|
||||
$state = new StdClass;
|
||||
$state->lastCheck = 0;
|
||||
$state->checkedVersion = '';
|
||||
$state->update = null;
|
||||
}
|
||||
|
||||
$state->lastCheck = time();
|
||||
$state->checkedVersion = $this->getInstalledVersion();
|
||||
update_option($this->optionName, $state); //Save before checking in case something goes wrong
|
||||
$state->lastCheck = time();
|
||||
$state->checkedVersion = $this->getInstalledVersion();
|
||||
update_option($this->optionName, $state); //Save before checking in case something goes wrong
|
||||
|
||||
$state->update = $this->requestUpdate();
|
||||
update_option($this->optionName, $state);
|
||||
}
|
||||
$state->update = $this->requestUpdate();
|
||||
update_option($this->optionName, $state);
|
||||
}
|
||||
|
||||
public function onTransientUpdate($value){
|
||||
if ( !$this->automaticCheckDone ){
|
||||
$this->checkForUpdates();
|
||||
$this->automaticCheckDone = true;
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
public function onTransientUpdate($value)
|
||||
{
|
||||
if (!$this->automaticCheckDone) {
|
||||
$this->checkForUpdates();
|
||||
$this->automaticCheckDone = true;
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
public function injectUpdate($updates){
|
||||
$state = get_option($this->optionName);
|
||||
public function injectUpdate($updates)
|
||||
{
|
||||
$state = get_option($this->optionName);
|
||||
|
||||
//Is there an update to insert?
|
||||
if ( !empty($state) && isset($state->update) && !empty($state->update) ){
|
||||
$updates->response[$this->theme] = $state->update->toWpFormat();
|
||||
}
|
||||
//Is there an update to insert?
|
||||
if (!empty($state) && isset($state->update) && !empty($state->update)) {
|
||||
$updates->response[$this->theme] = $state->update->toWpFormat();
|
||||
}
|
||||
|
||||
return $updates;
|
||||
}
|
||||
return $updates;
|
||||
}
|
||||
|
||||
public function deleteStoredData(){
|
||||
delete_option($this->optionName);
|
||||
}
|
||||
public function deleteStoredData()
|
||||
{
|
||||
delete_option($this->optionName);
|
||||
}
|
||||
|
||||
public function addQueryArgFilter($callback){
|
||||
add_filter(self::$filterPrefix.'query_args-'.$this->theme, $callback);
|
||||
}
|
||||
public function addQueryArgFilter($callback)
|
||||
{
|
||||
add_filter(self::$filterPrefix . 'query_args-' . $this->theme, $callback);
|
||||
}
|
||||
|
||||
public function addHttpRequestArgFilter($callback){
|
||||
add_filter(self::$filterPrefix.'options-'.$this->theme, $callback);
|
||||
}
|
||||
public function addHttpRequestArgFilter($callback)
|
||||
{
|
||||
add_filter(self::$filterPrefix . 'options-' . $this->theme, $callback);
|
||||
}
|
||||
|
||||
public function addResultFilter($callback){
|
||||
add_filter(self::$filterPrefix.'result-'.$this->theme, $callback, 10, 2);
|
||||
}
|
||||
}
|
||||
public function addResultFilter($callback)
|
||||
{
|
||||
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.
|
||||
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;
|
||||
}
|
||||
public static function fromJson($json)
|
||||
{
|
||||
$apiResponse = json_decode($json);
|
||||
if (empty($apiResponse) || !is_object($apiResponse)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
//Very, very basic validation.
|
||||
$valid = isset($apiResponse->version) && !empty($apiResponse->version) && isset($apiResponse->details_url) && !empty($apiResponse->details_url);
|
||||
if ( !$valid ){
|
||||
return null;
|
||||
}
|
||||
//Very, very basic validation.
|
||||
$valid = isset($apiResponse->version) && !empty($apiResponse->version) && isset($apiResponse->details_url) && !empty($apiResponse->details_url);
|
||||
if (!$valid) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$update = new self();
|
||||
foreach(get_object_vars($apiResponse) as $key => $value){
|
||||
$update->$key = $value;
|
||||
}
|
||||
$update = new self();
|
||||
foreach (get_object_vars($apiResponse) as $key => $value) {
|
||||
$update->$key = $value;
|
||||
}
|
||||
|
||||
return $update;
|
||||
}
|
||||
return $update;
|
||||
}
|
||||
|
||||
public function toWpFormat(){
|
||||
$update = array(
|
||||
'new_version' => $this->version,
|
||||
'url' => $this->details_url,
|
||||
);
|
||||
public function toWpFormat()
|
||||
{
|
||||
$update = array(
|
||||
'new_version' => $this->version,
|
||||
'url' => $this->details_url,
|
||||
);
|
||||
|
||||
if ( !empty($this->download_url) ){
|
||||
$update['package'] = $this->download_url;
|
||||
}
|
||||
if (!empty($this->download_url)) {
|
||||
$update['package'] = $this->download_url;
|
||||
}
|
||||
|
||||
return $update;
|
||||
}
|
||||
}
|
||||
return $update;
|
||||
}
|
||||
}
|
||||
|
||||
endif;
|
||||
endif;
|
||||
|
|
112
class/wechat.php
112
class/wechat.php
|
@ -13,13 +13,13 @@ error_reporting(0);
|
|||
class WeChat
|
||||
{
|
||||
|
||||
private $token = ""; //TOKEN值
|
||||
private $callback_function = NULL; //回调函数名称
|
||||
private $articles = array(); //图文信息array
|
||||
private $__token = ""; //TOKEN值
|
||||
private $__callback_function = null; //回调函数名称
|
||||
private $__articles = array(); //图文信息array
|
||||
|
||||
public $debug = false; //是否调试状态
|
||||
public $fromUser = ""; //当前消息的发送者
|
||||
public $toUser = ""; //当前消息的接收者
|
||||
public $debug = false; //是否调试状态
|
||||
public $fromUser = ""; //当前消息的发送者
|
||||
public $toUser = ""; //当前消息的接收者
|
||||
|
||||
/**
|
||||
* 构造函数
|
||||
|
@ -27,9 +27,9 @@ class WeChat
|
|||
* @param string $token 设置在公共平台的TOKEN值
|
||||
* @param callable $callback_function_name 回调函数名称
|
||||
*/
|
||||
function __construct($token, $callback_function_name)
|
||||
public function __construct($token, $callback_function_name)
|
||||
{
|
||||
$this->token = $token;
|
||||
$this->token = $token;
|
||||
$this->callback_function = $callback_function_name;
|
||||
}
|
||||
|
||||
|
@ -38,11 +38,11 @@ class WeChat
|
|||
*
|
||||
* @return boolean 正确返回true,否则返回false
|
||||
*/
|
||||
private function checkSignature()
|
||||
private function __checkSignature()
|
||||
{
|
||||
$signature = $_GET["signature"];
|
||||
$timestamp = $_GET["timestamp"];
|
||||
$nonce = $_GET["nonce"];
|
||||
$nonce = $_GET["nonce"];
|
||||
|
||||
$token = $this->token;
|
||||
|
||||
|
@ -51,17 +51,18 @@ class WeChat
|
|||
$tmpStr = implode($tmpArr);
|
||||
$tmpStr = sha1($tmpStr);
|
||||
|
||||
|
||||
if ($tmpStr == $signature)
|
||||
if ($tmpStr == $signature) {
|
||||
return true;
|
||||
else
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证签名是否有效
|
||||
*/
|
||||
protected function valid()
|
||||
protected function _valid()
|
||||
{
|
||||
$echoStr = $_GET["echostr"];
|
||||
//valid signature , option
|
||||
|
@ -81,7 +82,7 @@ class WeChat
|
|||
//如果是验证请求,则执行签名验证并退出
|
||||
if (!empty($_GET["echostr"])) {
|
||||
$this->valid(); //验证签名是否有效
|
||||
return; //返回退出
|
||||
return; //返回退出
|
||||
}
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] != 'POST') {
|
||||
|
@ -96,14 +97,13 @@ class WeChat
|
|||
if (empty($postData)) {
|
||||
echo '';
|
||||
return;
|
||||
} //如果没有POST数据,则退出
|
||||
|
||||
} //如果没有POST数据,则退出
|
||||
|
||||
//解析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; //记录消息发送方(不是发送者的微信号,而是一个加密后的OpenID)
|
||||
$this->toUser = "" . $object->ToUserName; //记录消息接收方(就是公共平台的OpenID)
|
||||
$this->toUser = "" . $object->ToUserName; //记录消息接收方(就是公共平台的OpenID)
|
||||
|
||||
//如果回调函数没有设置,则退出
|
||||
if (!is_callable($this->callback_function)) {
|
||||
|
@ -112,16 +112,16 @@ class WeChat
|
|||
|
||||
//根据不同的消息类型,分别处理
|
||||
switch ($messgeType) {
|
||||
case "text": //文本消息
|
||||
case "text": //文本消息
|
||||
//调用回调函数
|
||||
call_user_func($this->callback_function, $this, "text", $object->Content, "", "");
|
||||
break;
|
||||
case "event": //事件
|
||||
case "event": //事件
|
||||
switch ($object->Event) {
|
||||
case "subscribe": //订阅事件
|
||||
case "subscribe": //订阅事件
|
||||
call_user_func($this->callback_function, $this, "subscribe", $object->FromUserName, "", "");
|
||||
break;
|
||||
default :
|
||||
default:
|
||||
//Unknow Event
|
||||
break;
|
||||
}
|
||||
|
@ -142,7 +142,7 @@ class WeChat
|
|||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function textResponse($toUser, $fromUser, $content, $flag = 0)
|
||||
protected function _textResponse($toUser, $fromUser, $content, $flag = 0)
|
||||
{
|
||||
$xmlTemplate = "<xml>
|
||||
<ToUserName><![CDATA[%s]]></ToUserName>
|
||||
|
@ -158,7 +158,6 @@ class WeChat
|
|||
return $xmlText;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 形成 图文消息响应值
|
||||
*
|
||||
|
@ -168,7 +167,7 @@ class WeChat
|
|||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function newsResponse($toUser, $fromUser, $articles)
|
||||
protected function _newsResponse($toUser, $fromUser, $articles)
|
||||
{
|
||||
$xmlTemplate = "<xml>
|
||||
<ToUserName><![CDATA[%s]]></ToUserName>
|
||||
|
@ -194,7 +193,6 @@ class WeChat
|
|||
return $xmlText;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 发送文本内容
|
||||
*
|
||||
|
@ -205,7 +203,6 @@ class WeChat
|
|||
echo $this->textResponse($this->fromUser, $this->toUser, $content);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 添加一条图文信息
|
||||
*
|
||||
|
@ -217,9 +214,9 @@ class WeChat
|
|||
public function addNews($title, $description, $url, $pictureUrl)
|
||||
{
|
||||
$article = array('Title' => $title,
|
||||
'Description' => $description,
|
||||
'PicUrl' => $pictureUrl,
|
||||
'Url' => $url);
|
||||
'Description' => $description,
|
||||
'PicUrl' => $pictureUrl,
|
||||
'Url' => $url);
|
||||
$this->articles[] = $article;
|
||||
}
|
||||
|
||||
|
@ -232,17 +229,11 @@ class WeChat
|
|||
echo $this->newsResponse($this->fromUser, $this->toUser, $this->articles);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
define("WX_WELCOME", '欢迎关注极客公园'); //欢迎词
|
||||
define("POSTNUM", '5'); //文章数量
|
||||
define("DEFAULT_THUMB", '');//封面
|
||||
|
||||
|
||||
define("WX_WELCOME", '欢迎关注极客公园'); //欢迎词
|
||||
define("POSTNUM", '5'); //文章数量
|
||||
define("DEFAULT_THUMB", ''); //封面
|
||||
|
||||
add_action('pre_get_posts', 'wm_preprocess', 4);
|
||||
/**
|
||||
|
@ -253,11 +244,11 @@ add_action('pre_get_posts', 'wm_preprocess', 4);
|
|||
function wm_preprocess($wp_query)
|
||||
{
|
||||
global $object;
|
||||
$wx_token = trim(gdk_option('gdk_wxmp_token'));
|
||||
$wx_token = trim(gdk_option('gdk_wxmp_token'));
|
||||
if (!isset($object)) {
|
||||
//创建一个WeChat类的实例, 回调函数名称为"onMessage",即消息处理函数
|
||||
$object = new WeChat($wx_token, "onMessage");
|
||||
$object->process(); //处理消息
|
||||
$object->process(); //处理消息
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -276,7 +267,7 @@ function onMessage(WeChat $object, $messageType, $content, $arg1, $arg2)
|
|||
|
||||
//处理subscribe消息
|
||||
switch ($messageType) {
|
||||
case "subscribe": //当用户关注
|
||||
case "subscribe": //当用户关注
|
||||
$object->addNews(WX_WELCOME, "", "", "");
|
||||
$object->sendNews();
|
||||
break;
|
||||
|
@ -284,12 +275,12 @@ function onMessage(WeChat $object, $messageType, $content, $arg1, $arg2)
|
|||
$keyword = trim($content);
|
||||
switch ($keyword) {
|
||||
case 'yzm':
|
||||
case 'Yzm':
|
||||
case 'yZm':
|
||||
case 'yzM':
|
||||
case 'YZM':
|
||||
case '验证码':
|
||||
$object->sendText('您的验证码为:【'.wx_captcha().'】,验证码有效期为2分钟,请抓紧使用,过期需重新申请');
|
||||
case 'Yzm':
|
||||
case 'yZm':
|
||||
case 'yzM':
|
||||
case 'YZM':
|
||||
case '验证码':
|
||||
$object->sendText('您的验证码为:【' . wx_captcha() . '】,验证码有效期为2分钟,请抓紧使用,过期需重新申请');
|
||||
break;
|
||||
case 'r':
|
||||
send_post($object, 'r');
|
||||
|
@ -298,7 +289,7 @@ function onMessage(WeChat $object, $messageType, $content, $arg1, $arg2)
|
|||
case "h":
|
||||
case "?":
|
||||
case "?":
|
||||
case "???":
|
||||
case "???":
|
||||
$object->sendText(WX_WELCOME);
|
||||
break;
|
||||
default:
|
||||
|
@ -311,24 +302,21 @@ function onMessage(WeChat $object, $messageType, $content, $arg1, $arg2)
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//获取博客文章
|
||||
function wm_query_posts($q, $s = "")
|
||||
{
|
||||
global $wp_query;
|
||||
$articles = [];
|
||||
$articles = [];
|
||||
$query_base = array(
|
||||
'ignore_sticky_posts' => true,
|
||||
'posts_per_page' => POSTNUM,
|
||||
'post_status' => 'publish',
|
||||
'posts_per_page' => POSTNUM,
|
||||
'post_status' => 'publish',
|
||||
);
|
||||
if (empty($s)) {
|
||||
switch ($q) {
|
||||
case "n":
|
||||
$query_more = array(
|
||||
"order" => "DESC",
|
||||
"order" => "DESC",
|
||||
"orderby" => "date",
|
||||
);
|
||||
break;
|
||||
|
@ -352,8 +340,8 @@ function wm_query_posts($q, $s = "")
|
|||
while (have_posts()) {
|
||||
the_post();
|
||||
global $post;
|
||||
$title = get_the_title();
|
||||
$excerpt = gdk_print_excerpt(120,$post,false);
|
||||
$title = get_the_title();
|
||||
$excerpt = gdk_print_excerpt(120, $post, false);
|
||||
$thumbnail_id = get_post_thumbnail_id($post->ID);
|
||||
if ($thumbnail_id) {
|
||||
$thumb = wp_get_attachment_image_src($thumbnail_id, 'full');
|
||||
|
@ -364,7 +352,7 @@ function wm_query_posts($q, $s = "")
|
|||
if (empty(DEFAULT_THUMB) && !empty(DEFAULT_THUMB)) {
|
||||
$thumb = DEFAULT_THUMB;
|
||||
}
|
||||
$link = get_permalink();
|
||||
$link = get_permalink();
|
||||
$articles[] = array($title, $excerpt, $link, $thumb);
|
||||
}
|
||||
}
|
||||
|
@ -383,4 +371,4 @@ function send_post(WeChat $object, $type = '', $value = '')
|
|||
$object->addNews($v['0'], $v['1'], $v['2'], $v['3']);
|
||||
}
|
||||
$object->sendNews();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
|
||||
<?php
|
||||
|
||||
class Auto_Widget_cache {
|
||||
class Auto_Widget_cache
|
||||
{
|
||||
public $cache_time = 18000;
|
||||
/*
|
||||
MINUTE_IN_SECONDS = 60 seconds
|
||||
|
@ -9,19 +10,28 @@ class Auto_Widget_cache {
|
|||
DAY_IN_SECONDS = 86400 seconds
|
||||
WEEK_IN_SECONDS = 604800 seconds
|
||||
YEAR_IN_SECONDS = 3153600 seconds
|
||||
*/
|
||||
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);
|
||||
*/
|
||||
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);
|
||||
}
|
||||
function get_widget_key($i, $a) {
|
||||
public function get_widget_key($i, $a)
|
||||
{
|
||||
return 'WC-' . md5(serialize(array($i, $a)));
|
||||
}
|
||||
function _cache_widget_output($instance, $widget, $args) {
|
||||
if (false === $instance) return $instance;
|
||||
if (isset($instance['wc_cache']) && $instance['wc_cache'] == true) return $instance;
|
||||
$timer_start = microtime(true);
|
||||
public function cache_widget_output($instance, $widget, $args)
|
||||
{
|
||||
if (false === $instance) {
|
||||
return $instance;
|
||||
}
|
||||
|
||||
if (isset($instance['wc_cache']) && $instance['wc_cache'] == true) {
|
||||
return $instance;
|
||||
}
|
||||
|
||||
$timer_start = microtime(true);
|
||||
$transient_name = $this->get_widget_key($instance, $args);
|
||||
if (false === ($cached_widget = get_transient($transient_name))) {
|
||||
ob_start();
|
||||
|
@ -33,23 +43,28 @@ class Auto_Widget_cache {
|
|||
echo '<!-- From widget cache in ' . number_format(microtime(true) - $timer_start, 5) . ' seconds -->';
|
||||
return false;
|
||||
}
|
||||
function in_widget_form($t, $return, $instance) {
|
||||
public function in_widget_form($t, $return, $instance)
|
||||
{
|
||||
$instance = wp_parse_args((array)$instance, array('title' => '', 'text' => '', 'wc_cache' => null));
|
||||
if (!isset($instance['wc_cache'])) $instance['wc_cache'] = null;
|
||||
?>
|
||||
if (!isset($instance['wc_cache'])) {
|
||||
$instance['wc_cache'] = null;
|
||||
}
|
||||
|
||||
?>
|
||||
<p>
|
||||
<input id="<?php
|
||||
echo $t->get_field_id('wc_cache'); ?>" name="<?php
|
||||
echo $t->get_field_name('wc_cache'); ?>" type="checkbox" <?php
|
||||
checked(isset($instance['wc_cache']) ? $instance['wc_cache'] : 0); ?> />
|
||||
echo $t->get_field_id('wc_cache'); ?>" name="<?php
|
||||
echo $t->get_field_name('wc_cache'); ?>" type="checkbox" <?php
|
||||
checked(isset($instance['wc_cache']) ? $instance['wc_cache'] : 0); ?> />
|
||||
<label for="<?php
|
||||
echo $t->get_field_id('wc_cache'); ?>">禁止缓存本工具?</label>
|
||||
echo $t->get_field_id('wc_cache'); ?>">禁止缓存本工具?</label>
|
||||
</p>
|
||||
<?php
|
||||
}
|
||||
function widget_update_callback($instance, $new_instance, $old_instance) {
|
||||
}
|
||||
public function widget_update_callback($instance, $new_instance, $old_instance)
|
||||
{
|
||||
$instance['wc_cache'] = isset($new_instance['wc_cache']);
|
||||
return $instance;
|
||||
}
|
||||
}
|
||||
}
|
||||
$GLOBALS['Auto_Widget_cache'] = new Auto_Widget_cache();
|
|
@ -1,3 +1,2 @@
|
|||
<?php
|
||||
include( 'plugin-options.php' );//安全功能
|
||||
|
||||
include 'plugin-options.php'; //安全功能
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -3,59 +3,74 @@
|
|||
* Git 插件后台选项
|
||||
*/
|
||||
|
||||
if ( ! defined( 'WPINC' ) ) {
|
||||
die;
|
||||
}
|
||||
if (!defined('WPINC')) {
|
||||
die;
|
||||
}
|
||||
|
||||
$current_theme = wp_get_theme();
|
||||
$current_theme = wp_get_theme();
|
||||
$gdk_default_options = [];
|
||||
$gdk_options = array();
|
||||
include('options-config.php');
|
||||
$gdk_options = array();
|
||||
include 'options-config.php';
|
||||
$gdk_current_options = get_option('gdk_options_setup');
|
||||
|
||||
function gdk_update_options() {
|
||||
global $gdk_default_options, $gdk_options, $gdk_current_options;
|
||||
foreach ($gdk_options as $panel) {
|
||||
foreach ($panel as $option) {
|
||||
$id = $option['id'] ?? '';
|
||||
$type = $option['type'] ?? '';
|
||||
$std = $option['std'] ?? '';
|
||||
if ( !$id ) continue;
|
||||
$gdk_default_options[$id] = $std;
|
||||
if ( isset($gdk_current_options[$id]) ) continue;
|
||||
$gdk_current_options[$id] = $std;
|
||||
}
|
||||
}
|
||||
function gdk_update_options()
|
||||
{
|
||||
global $gdk_default_options, $gdk_options, $gdk_current_options;
|
||||
foreach ($gdk_options as $panel) {
|
||||
foreach ($panel as $option) {
|
||||
$id = $option['id'] ?? '';
|
||||
$type = $option['type'] ?? '';
|
||||
$std = $option['std'] ?? '';
|
||||
if (!$id) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$gdk_default_options[$id] = $std;
|
||||
if (isset($gdk_current_options[$id])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$gdk_current_options[$id] = $std;
|
||||
}
|
||||
}
|
||||
}
|
||||
gdk_update_options();
|
||||
|
||||
//获取设置选项
|
||||
function gdk_option($id, $returnDefault = false) {
|
||||
global $gdk_default_options, $gdk_current_options;
|
||||
return stripslashes( $returnDefault ? $gdk_default_options[$id] : $gdk_current_options[$id] );
|
||||
function gdk_option($id, $returnDefault = false)
|
||||
{
|
||||
global $gdk_default_options, $gdk_current_options;
|
||||
return stripslashes($returnDefault ? $gdk_default_options[$id] : $gdk_current_options[$id]);
|
||||
}
|
||||
|
||||
//设置页面模板
|
||||
function gdk_options_page() {
|
||||
global $gdk_options;
|
||||
?>
|
||||
function gdk_options_page()
|
||||
{
|
||||
global $gdk_options;
|
||||
?>
|
||||
|
||||
<div class="wrap">
|
||||
<h2>GDK选项</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>';
|
||||
?>
|
||||
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
|
||||
$activePanelIdx = empty($_GET['panel']) ? 0 : $_GET['panel'];
|
||||
foreach ( array_keys($gdk_options) as $i => $name ) {
|
||||
echo '<li><a href="#panel_' . $i . '" data-panel="' . $i . '" ' . ( $i == $activePanelIdx ? 'class="current"' : '' ) . '>' . $name . '</a></li>';
|
||||
}
|
||||
?>
|
||||
foreach (array_keys($gdk_options) as $i => $name) {
|
||||
echo '<li><a href="#panel_' . $i . '" data-panel="' . $i . '" ' . ($i == $activePanelIdx ? 'class="current"' : '') . '>' . $name . '</a></li>';
|
||||
}
|
||||
?>
|
||||
<li><a href="#panel_data" data-panel="data">数据清理</a></li>
|
||||
<li><a href="#panel_about" data-panel="about">关于插件</a></li>
|
||||
</ul>
|
||||
|
@ -65,104 +80,110 @@ foreach ( array_keys($gdk_options) as $i => $name ) {
|
|||
<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">';
|
||||
foreach ( $panel as $option ) {
|
||||
$type = $option['type'];
|
||||
if ( $type == 'title' ) {
|
||||
?>
|
||||
foreach ($gdk_options as $panel) {
|
||||
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') {
|
||||
?>
|
||||
<tr class="title">
|
||||
<th colspan="2">
|
||||
<h3><?php echo $option['title']; ?></h3>
|
||||
<?php if ( isset( $option['desc'] ) ) echo '<p>' . $option['desc'] . '</p>'; ?>
|
||||
<?php if (isset($option['desc'])) {
|
||||
echo '<p>' . $option['desc'] . '</p>';
|
||||
}
|
||||
?>
|
||||
</th>
|
||||
</tr>
|
||||
<?php
|
||||
continue;
|
||||
}
|
||||
$id = $option['id'];
|
||||
?>
|
||||
continue;
|
||||
}
|
||||
$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':
|
||||
?>
|
||||
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 )) ?>" />
|
||||
<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':
|
||||
?>
|
||||
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 )) ?>" />
|
||||
<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':
|
||||
?>
|
||||
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>
|
||||
<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 'radio':
|
||||
?>
|
||||
break;
|
||||
case 'radio':
|
||||
?>
|
||||
<fieldset>
|
||||
<?php foreach ($option['options'] as $val => $name) : ?>
|
||||
<?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); ?>>
|
||||
<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
|
||||
break;
|
||||
case 'checkbox':
|
||||
?>
|
||||
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
|
||||
break;
|
||||
case 'checkboxs':
|
||||
?>
|
||||
break;
|
||||
case 'checkboxs':
|
||||
?>
|
||||
<fieldset>
|
||||
<?php $checkboxValues = gdk_option( $id );
|
||||
if ( !is_array($checkboxValues) ) $checkboxValues = [];
|
||||
foreach ( $option['options'] as $id => $name ) : ?>
|
||||
<?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( in_array($id, $checkboxValues), true); ?>>
|
||||
<input type="checkbox" name="<?php echo $id; ?>[]" id="<?php echo $id; ?>[]" value="<?php echo $id; ?>" <?php checked(in_array($id, $checkboxValues), true); ?>>
|
||||
<?php echo $name; ?>
|
||||
</label>
|
||||
<?php endforeach; ?>
|
||||
</fieldset>
|
||||
<p class="description"><?php echo $option['desc']; ?></p>
|
||||
<?php
|
||||
break;
|
||||
default:
|
||||
?>
|
||||
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 )) ?>" />
|
||||
<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++;
|
||||
}
|
||||
?>
|
||||
break;
|
||||
}
|
||||
echo '</td></tr>';
|
||||
}
|
||||
echo '</table></div>';
|
||||
$index++;
|
||||
}
|
||||
?>
|
||||
<div class="panel" id="panel_data">
|
||||
<table class="form-table">
|
||||
<?php echo gdk_clean_up_page();?>
|
||||
<?php echo gdk_clean_up_page(); ?>
|
||||
</table>
|
||||
</div>
|
||||
<div class="panel" id="panel_about">
|
||||
|
@ -360,27 +381,26 @@ jQuery(function ($) {
|
|||
<?php
|
||||
}
|
||||
|
||||
|
||||
|
||||
function gdk_add_options_page() {
|
||||
global $gdk_options;
|
||||
if ( isset($_POST['action']) && isset($_GET['page']) && $_GET['page'] == 'gdk-options' ) {
|
||||
$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']);
|
||||
break;
|
||||
case 'reset':
|
||||
delete_option('gdk_options_setup');
|
||||
gdk_update_options();
|
||||
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' );
|
||||
function gdk_add_options_page()
|
||||
{
|
||||
global $gdk_options;
|
||||
if (isset($_POST['action']) && isset($_GET['page']) && $_GET['page'] == 'gdk-options') {
|
||||
$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']);
|
||||
break;
|
||||
case 'reset':
|
||||
delete_option('gdk_options_setup');
|
||||
gdk_update_options();
|
||||
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');
|
||||
}
|
||||
add_action( 'admin_menu', 'gdk_add_options_page' );
|
||||
add_action('admin_menu', 'gdk_add_options_page');
|
|
@ -1,8 +1,7 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
*Ajax操作文件
|
||||
*/
|
||||
*Ajax操作文件
|
||||
*/
|
||||
|
||||
/**
|
||||
* 200 ok
|
||||
|
@ -10,268 +9,332 @@
|
|||
*/
|
||||
|
||||
//后台邮箱检测
|
||||
function gdk_test_email() {
|
||||
function gdk_test_email()
|
||||
{
|
||||
$is_error = !wp_mail('donotreply@mywpku.com', '测试发信', 'WP 积木测试发信');
|
||||
if ($is_error) {
|
||||
exit('500');
|
||||
}else{
|
||||
} else {
|
||||
exit('200');
|
||||
}
|
||||
}
|
||||
add_action('wp_ajax_nopriv_gdk_test_email', 'gdk_test_email');
|
||||
add_action('wp_ajax_gdk_test_email', 'gdk_test_email');
|
||||
|
||||
|
||||
//粘贴上传图片
|
||||
function gdk_pasteup_imag() {
|
||||
if( !isset( $_POST['pui_nonce'] ) || !wp_verify_nonce($_POST['pui_nonce'], 'pui-nonce') ) exit('400');
|
||||
if($_FILES) {
|
||||
global $post;
|
||||
$post_ID = $post->ID;
|
||||
$wp_upload_dir = wp_upload_dir();
|
||||
$file = $_FILES['imageFile'];
|
||||
$result=array ('success'=>false,'message'=>'Null');
|
||||
if (in_array($file['type'],array ('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;
|
||||
if (!file_exists($file_path)) {
|
||||
move_uploaded_file($file['tmp_name'],$file_path);
|
||||
$attachment = [
|
||||
'guid' => $wp_upload_dir['url'] . '/' . basename( $file_path ),
|
||||
'post_mime_type' => $file['type'],
|
||||
'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' );
|
||||
$attach_data = wp_generate_attachment_metadata( $attach_id, $file_path );
|
||||
wp_update_attachment_metadata( $attach_id, $attach_data );
|
||||
}
|
||||
$result['success'] = true;
|
||||
$result['message'] = $file_url;
|
||||
}
|
||||
} else {
|
||||
$result['message'] = '400';
|
||||
}
|
||||
echo(json_encode($result));
|
||||
exit();
|
||||
}
|
||||
function gdk_pasteup_imag()
|
||||
{
|
||||
if (!isset($_POST['pui_nonce']) || !wp_verify_nonce($_POST['pui_nonce'], 'pui-nonce')) {
|
||||
exit('400');
|
||||
}
|
||||
|
||||
if ($_FILES) {
|
||||
global $post;
|
||||
$post_ID = $post->ID;
|
||||
$wp_upload_dir = wp_upload_dir();
|
||||
$file = $_FILES['imageFile'];
|
||||
$result = array('success' => false, 'message' => 'Null');
|
||||
if (in_array($file['type'], array('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;
|
||||
if (!file_exists($file_path)) {
|
||||
move_uploaded_file($file['tmp_name'], $file_path);
|
||||
$attachment = [
|
||||
'guid' => $wp_upload_dir['url'] . '/' . basename($file_path),
|
||||
'post_mime_type' => $file['type'],
|
||||
'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';
|
||||
$attach_data = wp_generate_attachment_metadata($attach_id, $file_path);
|
||||
wp_update_attachment_metadata($attach_id, $attach_data);
|
||||
}
|
||||
$result['success'] = true;
|
||||
$result['message'] = $file_url;
|
||||
}
|
||||
} else {
|
||||
$result['message'] = '400';
|
||||
}
|
||||
echo (json_encode($result));
|
||||
exit();
|
||||
}
|
||||
}
|
||||
add_action('wp_ajax_nopriv_gdk_pasteup_imag', 'gdk_pasteup_imag');
|
||||
add_action('wp_ajax_gdk_pasteup_imag', 'gdk_pasteup_imag');
|
||||
|
||||
//密码可见
|
||||
function gdk_pass_view() {
|
||||
if( !isset( $_POST['pass_nonce'] ) || !wp_verify_nonce($_POST['pass_nonce'], 'pass_nonce') ) exit('400');
|
||||
$action = $_POST['action'];
|
||||
$post_id = $_POST['id'];
|
||||
$pass = $_POST['pass'];
|
||||
$wxcaptcha = wx_captcha();
|
||||
if(!isset( $action ) || !isset( $post_id ) || !isset( $pass ) ) exit('400');
|
||||
if($pass == $wxcaptcha ) {
|
||||
$pass_content = get_post_meta($post_id, '_pass_content')[0];
|
||||
exit($pass_content);
|
||||
}else{
|
||||
exit('400');
|
||||
}
|
||||
function gdk_pass_view()
|
||||
{
|
||||
if (!isset($_POST['pass_nonce']) || !wp_verify_nonce($_POST['pass_nonce'], 'pass_nonce')) {
|
||||
exit('400');
|
||||
}
|
||||
|
||||
$action = $_POST['action'];
|
||||
$post_id = $_POST['id'];
|
||||
$pass = $_POST['pass'];
|
||||
$wxcaptcha = wx_captcha();
|
||||
if (!isset($action) || !isset($post_id) || !isset($pass)) {
|
||||
exit('400');
|
||||
}
|
||||
|
||||
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');
|
||||
add_action('wp_ajax_gdk_pass_view', 'gdk_pass_view');
|
||||
|
||||
//密码可见end
|
||||
|
||||
|
||||
|
||||
//在线积分充值开始
|
||||
function pay_points() {
|
||||
if( !isset( $_POST['action'] ) || $_POST['action'] !== 'pay_points' ) exit('400');
|
||||
if (!isset($_POST['money']) || !isset($_POST['way'])) exit('400');//无脑输出400错误
|
||||
if (isset($_POST['id'])) {
|
||||
payjs_action('积分充值',$_POST['id']);
|
||||
}
|
||||
function pay_points()
|
||||
{
|
||||
if (!isset($_POST['action']) || $_POST['action'] !== 'pay_points') {
|
||||
exit('400');
|
||||
}
|
||||
|
||||
if (!isset($_POST['money']) || !isset($_POST['way'])) {
|
||||
exit('400');
|
||||
}
|
||||
//无脑输出400错误
|
||||
if (isset($_POST['id'])) {
|
||||
payjs_action('积分充值', $_POST['id']);
|
||||
}
|
||||
}
|
||||
add_action( 'wp_ajax_pay_points', 'pay_points' );
|
||||
add_action( 'wp_ajax_nopriv_pay_points', 'pay_points' );
|
||||
add_action('wp_ajax_pay_points', 'pay_points');
|
||||
add_action('wp_ajax_nopriv_pay_points', 'pay_points');
|
||||
|
||||
//检查积分充值
|
||||
function check_pay_points(){
|
||||
if( !isset( $_POST['check_pay_points'] ) || !wp_verify_nonce($_POST['check_pay_points'], 'check_pay_points') ) exit('400');
|
||||
if (!isset($_POST['id']) || !isset($_POST['orderid'])) exit('400');//无脑输出400错误
|
||||
if ( $_POST['action'] == 'check_pay_points') {
|
||||
if(gdk_check( $_POST['orderid'] , $_POST['id'])){
|
||||
function check_pay_points()
|
||||
{
|
||||
if (!isset($_POST['check_pay_points']) || !wp_verify_nonce($_POST['check_pay_points'], 'check_pay_points')) {
|
||||
exit('400');
|
||||
}
|
||||
|
||||
if (!isset($_POST['id']) || !isset($_POST['orderid'])) {
|
||||
exit('400');
|
||||
}
|
||||
//无脑输出400错误
|
||||
if ($_POST['action'] == 'check_pay_points') {
|
||||
if (gdk_check($_POST['orderid'], $_POST['id'])) {
|
||||
exit('200');
|
||||
}else{
|
||||
} else {
|
||||
exit('400');
|
||||
}
|
||||
}
|
||||
}
|
||||
add_action( 'wp_ajax_check_pay_points', 'check_pay_points' );
|
||||
add_action( 'wp_ajax_nopriv_check_pay_points', 'check_pay_points' );
|
||||
add_action('wp_ajax_check_pay_points', 'check_pay_points');
|
||||
add_action('wp_ajax_nopriv_check_pay_points', 'check_pay_points');
|
||||
|
||||
//积分充值结束
|
||||
|
||||
//游客付费可见开始
|
||||
function pay_view() {
|
||||
if( !isset( $_POST['action'] ) || $_POST['action'] !== 'pay_view' ) exit('400');
|
||||
if (!isset($_POST['money']) || !isset($_POST['way'])) exit('400');//无脑输出400错误
|
||||
if (isset($_POST['id'])) {
|
||||
payjs_action('在线付费查看','PP'.$_POST['id']);//标题,文章id
|
||||
}
|
||||
function pay_view()
|
||||
{
|
||||
if (!isset($_POST['action']) || $_POST['action'] !== 'pay_view') {
|
||||
exit('400');
|
||||
}
|
||||
|
||||
if (!isset($_POST['money']) || !isset($_POST['way'])) {
|
||||
exit('400');
|
||||
}
|
||||
//无脑输出400错误
|
||||
if (isset($_POST['id'])) {
|
||||
payjs_action('在线付费查看', 'PP' . $_POST['id']); //标题,文章id
|
||||
}
|
||||
}
|
||||
add_action( 'wp_ajax_pay_view', 'pay_view' );
|
||||
add_action( 'wp_ajax_nopriv_pay_view', 'pay_view' );
|
||||
add_action('wp_ajax_pay_view', 'pay_view');
|
||||
add_action('wp_ajax_nopriv_pay_view', 'pay_view');
|
||||
|
||||
//添加提取码
|
||||
function add_code() {
|
||||
$id = $_POST['id'];
|
||||
$code = $_POST['code'];
|
||||
if(empty($id) || empty($code)) exit('400');
|
||||
if ( $_POST['action'] == 'add_code') {
|
||||
$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);//没有新建,有就更新
|
||||
$pay_log = get_post_meta($id, 'pay_log', true);//获取新的购买记录数据
|
||||
$pay_arr = explode(",", $pay_log);
|
||||
if(in_array($code,$pay_arr)) {
|
||||
exit('200');//OK
|
||||
}else{
|
||||
exit('400');//NO
|
||||
}
|
||||
}
|
||||
function add_code()
|
||||
{
|
||||
$id = $_POST['id'];
|
||||
$code = $_POST['code'];
|
||||
if (empty($id) || empty($code)) {
|
||||
exit('400');
|
||||
}
|
||||
|
||||
if ($_POST['action'] == 'add_code') {
|
||||
$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); //没有新建,有就更新
|
||||
$pay_log = get_post_meta($id, 'pay_log', true); //获取新的购买记录数据
|
||||
$pay_arr = explode(",", $pay_log);
|
||||
if (in_array($code, $pay_arr)) {
|
||||
exit('200'); //OK
|
||||
} else {
|
||||
exit('400'); //NO
|
||||
}
|
||||
}
|
||||
}
|
||||
add_action( 'wp_ajax_add_code', 'add_code' );
|
||||
add_action( 'wp_ajax_nopriv_add_code', 'add_code' );
|
||||
add_action('wp_ajax_add_code', 'add_code');
|
||||
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'];
|
||||
if( !isset( $check_code_nonce ) || !wp_verify_nonce($check_code_nonce, 'check_code') ) exit('400');
|
||||
if (!isset($code) || !isset($action) || !isset($id)) exit('400');//无脑输出400错误
|
||||
if ( $action == 'check_code') {
|
||||
$code = trim($code);//清理一下
|
||||
$pay_log = get_post_meta($id, 'pay_log', true);//购买记录数据
|
||||
$pay_arr = explode(",", $pay_log);
|
||||
if(in_array($code,$pay_arr)) {
|
||||
exit('200');
|
||||
} else {
|
||||
exit('400');
|
||||
}
|
||||
}
|
||||
function check_code()
|
||||
{
|
||||
$check_code_nonce = $_POST['check_code'];
|
||||
$code = $_POST['code'];
|
||||
$action = $_POST['action'];
|
||||
$id = $_POST['id'];
|
||||
if (!isset($check_code_nonce) || !wp_verify_nonce($check_code_nonce, 'check_code')) {
|
||||
exit('400');
|
||||
}
|
||||
|
||||
if (!isset($code) || !isset($action) || !isset($id)) {
|
||||
exit('400');
|
||||
}
|
||||
//无脑输出400错误
|
||||
if ($action == 'check_code') {
|
||||
$code = trim($code); //清理一下
|
||||
$pay_log = get_post_meta($id, 'pay_log', true); //购买记录数据
|
||||
$pay_arr = explode(",", $pay_log);
|
||||
if (in_array($code, $pay_arr)) {
|
||||
exit('200');
|
||||
} else {
|
||||
exit('400');
|
||||
}
|
||||
}
|
||||
}
|
||||
add_action( 'wp_ajax_check_code', 'check_code' );
|
||||
add_action( 'wp_ajax_nopriv_check_code', 'check_code' );
|
||||
add_action('wp_ajax_check_code', 'check_code');
|
||||
add_action('wp_ajax_nopriv_check_code', 'check_code');
|
||||
|
||||
//获取加密内容
|
||||
function get_content(){
|
||||
if ( !isset($_POST['action']) || $_POST['action'] !== 'get_content') exit('400');//无脑输出400错误
|
||||
if ( isset($_POST['id'])) {
|
||||
$pay_content = get_post_meta($_POST['id'], '_pay_content', true);
|
||||
exit($pay_content);
|
||||
}
|
||||
function get_content()
|
||||
{
|
||||
if (!isset($_POST['action']) || $_POST['action'] !== 'get_content') {
|
||||
exit('400');
|
||||
}
|
||||
//无脑输出400错误
|
||||
if (isset($_POST['id'])) {
|
||||
$pay_content = get_post_meta($_POST['id'], '_pay_content', true);
|
||||
exit($pay_content);
|
||||
}
|
||||
}
|
||||
add_action( 'wp_ajax_get_content', 'get_content' );
|
||||
add_action( 'wp_ajax_nopriv_get_content', 'get_content' );
|
||||
add_action('wp_ajax_get_content', 'get_content');
|
||||
add_action('wp_ajax_nopriv_get_content', 'get_content');
|
||||
|
||||
//检查付费可见订单
|
||||
function check_pay_view() {
|
||||
if( !isset( $_POST['check_pay_view'] ) || !wp_verify_nonce($_POST['check_pay_view'], 'check_pay_view') ) exit('400');
|
||||
if (!isset($_POST['id']) || !isset($_POST['orderid'])) exit('400');//无脑输出400错误
|
||||
if ( $_POST['action'] == 'check_pay_view') {
|
||||
$sid = get_transient('PP'.$_POST['id']);
|
||||
if(in_string($sid,'E20') && $_POST['orderid'] == $sid) {
|
||||
exit('200');//OK
|
||||
} else {
|
||||
exit('400');//no
|
||||
}
|
||||
}
|
||||
function check_pay_view()
|
||||
{
|
||||
if (!isset($_POST['check_pay_view']) || !wp_verify_nonce($_POST['check_pay_view'], 'check_pay_view')) {
|
||||
exit('400');
|
||||
}
|
||||
|
||||
if (!isset($_POST['id']) || !isset($_POST['orderid'])) {
|
||||
exit('400');
|
||||
}
|
||||
//无脑输出400错误
|
||||
if ($_POST['action'] == 'check_pay_view') {
|
||||
$sid = get_transient('PP' . $_POST['id']);
|
||||
if (in_string($sid, 'E20') && $_POST['orderid'] == $sid) {
|
||||
exit('200'); //OK
|
||||
} else {
|
||||
exit('400'); //no
|
||||
}
|
||||
}
|
||||
}
|
||||
add_action( 'wp_ajax_check_pay_view', 'check_pay_view' );
|
||||
add_action( 'wp_ajax_nopriv_check_pay_view', 'check_pay_view' );
|
||||
add_action('wp_ajax_check_pay_view', 'check_pay_view');
|
||||
add_action('wp_ajax_nopriv_check_pay_view', 'check_pay_view');
|
||||
|
||||
/**END */
|
||||
|
||||
//开始微信登陆
|
||||
//ajax生成登录二维码
|
||||
function gdk_weauth_qr_gen() {
|
||||
if (isset($_POST['action']) && $_POST['action'] == 'gdk_weauth_qr_gen') {
|
||||
$rest = implode('|', gdk_weauth_qr());
|
||||
exit($rest);
|
||||
} else {
|
||||
exit('400');
|
||||
}
|
||||
function gdk_weauth_qr_gen()
|
||||
{
|
||||
if (isset($_POST['action']) && $_POST['action'] == 'gdk_weauth_qr_gen') {
|
||||
$rest = implode('|', gdk_weauth_qr());
|
||||
exit($rest);
|
||||
} else {
|
||||
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' );
|
||||
|
||||
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');
|
||||
|
||||
//检查微信登录状况
|
||||
function gdk_weauth_check(){
|
||||
if( !isset($_POST['key']) || !isset( $_POST['gdk_weauth_check'] ) || !wp_verify_nonce($_POST['gdk_weauth_check'], 'gdk_weauth_check') ) exit('400');
|
||||
if (!in_string($_POST['key'],'@') || $_POST['action'] !== 'gdk_weauth_check') exit('400');
|
||||
$sk = substr(trim($_POST['key']),-12);//sk
|
||||
$user_info = get_transient($sk.'-info');//user_info
|
||||
if (!empty($user_info)) {
|
||||
exit($user_info);//user_info
|
||||
}
|
||||
function gdk_weauth_check()
|
||||
{
|
||||
if (!isset($_POST['key']) || !isset($_POST['gdk_weauth_check']) || !wp_verify_nonce($_POST['gdk_weauth_check'], 'gdk_weauth_check')) {
|
||||
exit('400');
|
||||
}
|
||||
|
||||
if (!in_string($_POST['key'], '@') || $_POST['action'] !== 'gdk_weauth_check') {
|
||||
exit('400');
|
||||
}
|
||||
|
||||
$sk = substr(trim($_POST['key']), -12); //sk
|
||||
$user_info = get_transient($sk . '-info'); //user_info
|
||||
if (!empty($user_info)) {
|
||||
exit($user_info); //user_info
|
||||
}
|
||||
}
|
||||
add_action( 'wp_ajax_gdk_weauth_check', 'gdk_weauth_check' );
|
||||
add_action( 'wp_ajax_nopriv_gdk_weauth_check', 'gdk_weauth_check' );
|
||||
add_action('wp_ajax_gdk_weauth_check', 'gdk_weauth_check');
|
||||
add_action('wp_ajax_nopriv_gdk_weauth_check', 'gdk_weauth_check');
|
||||
|
||||
//开始自动登陆
|
||||
function gdk_auto_login(){
|
||||
if (!isset($_POST['data']) || $_POST['action'] !== 'gdk_auto_login') exit('400');
|
||||
$mail = $_POST['email'] ?? '';
|
||||
$userdata = gdk_str2arr($_POST['data'],'|');
|
||||
$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 ) );//绑定邮箱
|
||||
}
|
||||
exit('200');
|
||||
}
|
||||
function gdk_auto_login()
|
||||
{
|
||||
if (!isset($_POST['data']) || $_POST['action'] !== 'gdk_auto_login') {
|
||||
exit('400');
|
||||
}
|
||||
|
||||
$mail = $_POST['email'] ?? '';
|
||||
$userdata = gdk_str2arr($_POST['data'], '|');
|
||||
$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)); //绑定邮箱
|
||||
}
|
||||
exit('200');
|
||||
}
|
||||
}
|
||||
add_action( 'wp_ajax_gdk_auto_login', 'gdk_auto_login' );
|
||||
add_action( 'wp_ajax_nopriv_gdk_auto_login', 'gdk_auto_login' );
|
||||
add_action('wp_ajax_gdk_auto_login', 'gdk_auto_login');
|
||||
add_action('wp_ajax_nopriv_gdk_auto_login', 'gdk_auto_login');
|
||||
|
||||
//邮箱绑定
|
||||
function bind_email_check(){
|
||||
function bind_email_check()
|
||||
{
|
||||
$mail = isset($_POST['email']) ? $_POST['email'] : false;
|
||||
if($mail && $_POST['action'] == 'bind_email_check'){
|
||||
$user_id = email_exists( $email );
|
||||
if ($mail && $_POST['action'] == 'bind_email_check') {
|
||||
$user_id = email_exists($email);
|
||||
if ($user_id) {
|
||||
exit('200');
|
||||
}
|
||||
}
|
||||
}
|
||||
add_action( 'wp_ajax_bind_email_check', 'bind_email_check' );
|
||||
add_action( 'wp_ajax_nopriv_bind_email_check', 'bind_email_check' );
|
||||
add_action('wp_ajax_bind_email_check', 'bind_email_check');
|
||||
add_action('wp_ajax_nopriv_bind_email_check', 'bind_email_check');
|
||||
|
||||
|
||||
function point_buy(){
|
||||
if (isset($_POST['point']) && isset($_POST['userid']) &&isset($_POST['id']) && $_POST['action'] == 'gdk_pay_buy') {
|
||||
GDK_Points::set_points( -$_POST['point'],
|
||||
$_POST['userid'],
|
||||
array(
|
||||
'description' => $_POST['id'],
|
||||
'status' => get_option( 'points-points_status', 'accepted' )
|
||||
)
|
||||
);//扣除金币
|
||||
$pay_content = get_post_meta($_POST['id'], '_point_content', true);
|
||||
exit($pay_content);
|
||||
function point_buy()
|
||||
{
|
||||
if (isset($_POST['point']) && isset($_POST['userid']) && isset($_POST['id']) && $_POST['action'] == 'gdk_pay_buy') {
|
||||
GDK_Points::set_points(-$_POST['point'],
|
||||
$_POST['userid'],
|
||||
array(
|
||||
'description' => $_POST['id'],
|
||||
'status' => get_option('points-points_status', 'accepted'),
|
||||
)
|
||||
); //扣除金币
|
||||
$pay_content = get_post_meta($_POST['id'], '_point_content', true);
|
||||
exit($pay_content);
|
||||
}
|
||||
}
|
||||
add_action( 'wp_ajax_gdk_pay_buy', 'point_buy' );
|
||||
add_action( 'wp_ajax_nopriv_gdk_pay_buy', 'point_buy' );
|
||||
add_action('wp_ajax_gdk_pay_buy', 'point_buy');
|
||||
add_action('wp_ajax_nopriv_gdk_pay_buy', 'point_buy');
|
||||
|
|
1414
functions/Common.php
1414
functions/Common.php
File diff suppressed because it is too large
Load diff
|
@ -1,197 +1,226 @@
|
|||
<?php
|
||||
if ( ! defined( 'ABSPATH' ) ) { exit; }
|
||||
if (!defined('ABSPATH')) {exit;}
|
||||
|
||||
|
||||
if (gdk_option('gdk_cdn')) add_action('wp_loaded', 'gdk_cdn_start');//七牛CDN
|
||||
if (gdk_option('gdk_link_go')) add_filter('the_content','gdk_link_go',999);// 外链GO跳转
|
||||
if (gdk_option('gdk_smtp')) add_action('phpmailer_init', 'gdk_smtp');//SMTP
|
||||
if (gdk_option('gdk_cdn_water')) add_filter('the_content', 'gdk_cdn_water');//CDN水印
|
||||
if (gdk_option('gdk_cdn')) {
|
||||
add_action('wp_loaded', 'gdk_cdn_start');
|
||||
}
|
||||
//七牛CDN
|
||||
if (gdk_option('gdk_link_go')) {
|
||||
add_filter('the_content', 'gdk_link_go', 999);
|
||||
}
|
||||
// 外链GO跳转
|
||||
if (gdk_option('gdk_smtp')) {
|
||||
add_action('phpmailer_init', 'gdk_smtp');
|
||||
}
|
||||
//SMTP
|
||||
if (gdk_option('gdk_cdn_water')) {
|
||||
add_filter('the_content', 'gdk_cdn_water');
|
||||
}
|
||||
//CDN水印
|
||||
|
||||
//文章首尾添加自定义内容
|
||||
function gdk_add_content($content) {
|
||||
$before = gdk_option('gdk_artical_top');
|
||||
$after = gdk_option('gdk_artical_bottom');
|
||||
$content = $before.'<br>'.$content.'<br>'.$after;
|
||||
return $content;
|
||||
function gdk_add_content($content)
|
||||
{
|
||||
$before = gdk_option('gdk_artical_top');
|
||||
$after = gdk_option('gdk_artical_bottom');
|
||||
$content = $before . '<br>' . $content . '<br>' . $after;
|
||||
return $content;
|
||||
}
|
||||
add_filter('the_content', 'gdk_add_content');
|
||||
|
||||
//接受奶子微信的账号信息
|
||||
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) return;
|
||||
$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分钟缓存
|
||||
header('goauth: ok');
|
||||
echo 'success';//给对方服务器打个招呼
|
||||
exit;
|
||||
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) {
|
||||
return;
|
||||
}
|
||||
|
||||
$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分钟缓存
|
||||
header('goauth: ok');
|
||||
echo 'success'; //给对方服务器打个招呼
|
||||
exit;
|
||||
}
|
||||
}
|
||||
add_action('parse_request','get_weauth_oauth');
|
||||
add_action('parse_request', 'get_weauth_oauth');
|
||||
|
||||
//社交头像
|
||||
function gdk_wx_avatar( $avatar, $id_or_email, $size, $default, $alt ) {
|
||||
$user = false;
|
||||
if ( is_numeric( $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;
|
||||
$user = get_user_by( 'id' , $id );
|
||||
}
|
||||
} else {
|
||||
$user = get_user_by( 'email', $id_or_email );
|
||||
}
|
||||
if ( $user && is_object( $user ) ) {
|
||||
if( get_user_meta($user->data->ID,'wx_avatar',true) ) {
|
||||
$avatar = get_user_meta($user->data->ID,'wx_avatar',true);
|
||||
$avatar = "<img alt='{$alt}' src='{$avatar}' class='avatar avatar-{$size} photo' height='{$size}' width='{$size}' />";
|
||||
}
|
||||
}
|
||||
return $avatar;
|
||||
function gdk_wx_avatar($avatar, $id_or_email, $size, $default, $alt)
|
||||
{
|
||||
$user = false;
|
||||
if (is_numeric($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;
|
||||
$user = get_user_by('id', $id);
|
||||
}
|
||||
} else {
|
||||
$user = get_user_by('email', $id_or_email);
|
||||
}
|
||||
if ($user && is_object($user)) {
|
||||
if (get_user_meta($user->data->ID, 'wx_avatar', true)) {
|
||||
$avatar = get_user_meta($user->data->ID, 'wx_avatar', true);
|
||||
$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);
|
||||
add_filter('get_avatar', 'gdk_wx_avatar', 19, 5);
|
||||
|
||||
//头像解决方案
|
||||
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' />";
|
||||
break;
|
||||
case 2:
|
||||
$avatar = preg_replace("/http[s]{0,1}:\/\/(secure|www|\d).gravatar.com\/avatar\//","//cdn.v2ex.com/gravatar/",$avatar);
|
||||
break;
|
||||
default:
|
||||
$avatar = preg_replace("/http[s]{0,1}:\/\/(secure|www|\d).gravatar.com\/avatar\//","//dn-qiniu-avatar.qbox.me/avatar/",$avatar);
|
||||
}
|
||||
return $avatar;
|
||||
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' />";
|
||||
break;
|
||||
case 2:
|
||||
$avatar = preg_replace("/http[s]{0,1}:\/\/(secure|www|\d).gravatar.com\/avatar\//", "//cdn.v2ex.com/gravatar/", $avatar);
|
||||
break;
|
||||
default:
|
||||
$avatar = preg_replace("/http[s]{0,1}:\/\/(secure|www|\d).gravatar.com\/avatar\//", "//dn-qiniu-avatar.qbox.me/avatar/", $avatar);
|
||||
}
|
||||
return $avatar;
|
||||
}
|
||||
add_filter('get_avatar', 'gdk_switch_get_avatar');
|
||||
|
||||
//懒加载
|
||||
if(gdk_option('gdk_lazyload')){
|
||||
function gdk_lazyload($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');
|
||||
if (gdk_option('gdk_lazyload')) {
|
||||
function gdk_lazyload($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');
|
||||
}
|
||||
|
||||
//强制兼容<pre>,和下面转义代码搭配使用
|
||||
function gdk_prettify_replace($text) {
|
||||
function gdk_prettify_replace($text)
|
||||
{
|
||||
$replace = array(
|
||||
'<pre>' => '<pre class="prettyprint linenums">'
|
||||
'<pre>' => '<pre class="prettyprint linenums">',
|
||||
);
|
||||
$text = str_replace(array_keys($replace) , $replace, $text);
|
||||
$text = str_replace(array_keys($replace), $replace, $text);
|
||||
return $text;
|
||||
}
|
||||
add_filter('content_save_pre', 'gdk_prettify_replace');
|
||||
add_filter('the_content', 'gdk_prettify_replace');
|
||||
|
||||
//强制阻止WordPress代码转义,适用于<pre class="prettyprint linenums"> </pre>
|
||||
function gdk_esc_html($content) {
|
||||
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];
|
||||
function gdk_esc_callback($matches)
|
||||
{
|
||||
$tag_open = $matches[1];
|
||||
$content = $matches[2];
|
||||
$tag_close = $matches[3];
|
||||
$content = esc_html($content);
|
||||
$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);
|
||||
|
||||
//fancybox图片灯箱效果
|
||||
if(gdk_option('gdk_lazyload')){
|
||||
function gdk_fancybox($content) {
|
||||
$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;
|
||||
}
|
||||
add_filter('the_content', 'gdk_fancybox');
|
||||
if (gdk_option('gdk_lazyload')) {
|
||||
function gdk_fancybox($content)
|
||||
{
|
||||
$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;
|
||||
}
|
||||
add_filter('the_content', 'gdk_fancybox');
|
||||
}
|
||||
|
||||
//GO跳转
|
||||
function gdk_link_go($content) {
|
||||
preg_match_all('/<a(.*?)href="(.*?)"(.*?)>/',$content,$matches);
|
||||
if($matches) {
|
||||
foreach($matches[2] as $val) {
|
||||
if(in_string($val,'://') && !in_string($val,home_url()) && !preg_match('/\.(jpg|jepg|png|ico|bmp|gif|tiff)/i',$val) && !preg_match('/(ed2k|thunder|Flashget|flashget|qqdl):\/\//i',$val)) {
|
||||
$content=str_replace("href=\"$val\"", "href=\"".home_url()."?go=$val\" ",$content);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $content;
|
||||
function gdk_link_go($content)
|
||||
{
|
||||
preg_match_all('/<a(.*?)href="(.*?)"(.*?)>/', $content, $matches);
|
||||
if ($matches) {
|
||||
foreach ($matches[2] as $val) {
|
||||
if (in_string($val, '://') && !in_string($val, home_url()) && !preg_match('/\.(jpg|jepg|png|ico|bmp|gif|tiff)/i', $val) && !preg_match('/(ed2k|thunder|Flashget|flashget|qqdl):\/\//i', $val)) {
|
||||
$content = str_replace("href=\"$val\"", "href=\"" . home_url() . "?go=$val\" ", $content);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $content;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//邮箱SMTP设置
|
||||
function gdk_smtp( $phpmailer ) {
|
||||
$phpmailer->FromName = gdk_option('gdk_smtp_mail'); //邮箱地址
|
||||
$phpmailer->Host = gdk_option('gdk_smtp_host');//服务器地址
|
||||
$phpmailer->Port = gdk_option('gdk_smtp_port'); //端口
|
||||
$phpmailer->Username = gdk_option('gdk_smtp_username'); //昵称
|
||||
$phpmailer->Password = gdk_option('gdk_smtp_password'); //密码
|
||||
$phpmailer->From = gdk_option('gdk_smtp_mail'); //邮箱地址
|
||||
$phpmailer->SMTPAuth = true;
|
||||
$phpmailer->SMTPSecure = 'ssl';
|
||||
$phpmailer->IsSMTP();
|
||||
function gdk_smtp($phpmailer)
|
||||
{
|
||||
$phpmailer->FromName = gdk_option('gdk_smtp_mail'); //邮箱地址
|
||||
$phpmailer->Host = gdk_option('gdk_smtp_host'); //服务器地址
|
||||
$phpmailer->Port = gdk_option('gdk_smtp_port'); //端口
|
||||
$phpmailer->Username = gdk_option('gdk_smtp_username'); //昵称
|
||||
$phpmailer->Password = gdk_option('gdk_smtp_password'); //密码
|
||||
$phpmailer->From = gdk_option('gdk_smtp_mail'); //邮箱地址
|
||||
$phpmailer->SMTPAuth = true;
|
||||
$phpmailer->SMTPSecure = 'ssl';
|
||||
$phpmailer->IsSMTP();
|
||||
}
|
||||
|
||||
// CDN
|
||||
function gdk_cdn_start() {
|
||||
ob_start('gdk_cdn_replace');
|
||||
function gdk_cdn_start()
|
||||
{
|
||||
ob_start('gdk_cdn_replace');
|
||||
}
|
||||
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);
|
||||
} else {
|
||||
$regex = '/' . str_replace('/', '\/', $local_host) . '\/([^\s\?\\\'\"\;\>\<]{1,}.(' . $cdn_exts . '))([\"\\\'\s\?]{1})/';
|
||||
$html = preg_replace($regex, $cdn_host . '/$1$3', $html);
|
||||
}
|
||||
return $html;
|
||||
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);
|
||||
} else {
|
||||
$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";
|
||||
$replacement = '<img$1src=$2$3.$4!water.jpg$5$6>';
|
||||
$content = preg_replace($pattern, $replacement, $content);
|
||||
}
|
||||
return $content;
|
||||
function gdk_cdn_water($content)
|
||||
{
|
||||
if (get_post_type() == 'post') {
|
||||
$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);
|
||||
}
|
||||
return $content;
|
||||
}
|
||||
|
||||
|
||||
//压缩html代码
|
||||
if (gdk_option('gdk_compress')) {
|
||||
function gdk_compress_html(){
|
||||
function gdk_compress_html_callback($buffer){
|
||||
if ( substr( ltrim( $buffer ), 0, 5) == '<?xml' ) return $buffer;
|
||||
function gdk_compress_html()
|
||||
{
|
||||
function gdk_compress_html_callback($buffer)
|
||||
{
|
||||
if (substr(ltrim($buffer), 0, 5) == '<?xml') {
|
||||
return $buffer;
|
||||
}
|
||||
|
||||
$initial = strlen($buffer);
|
||||
$buffer = explode("<!--wp-compress-html-->", $buffer);
|
||||
$count = count($buffer);
|
||||
$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]);
|
||||
|
@ -216,10 +245,10 @@ if (gdk_option('gdk_compress')) {
|
|||
$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');
|
||||
|
||||
add_action('get_header', 'gdk_compress_html');
|
||||
|
||||
function gdk_unCompress($content)
|
||||
{
|
||||
if (preg_match_all('/(crayon-|<?xml|script|textarea|<\\/pre>)/i', $content, $matches)) {
|
||||
|
@ -232,11 +261,12 @@ if (gdk_option('gdk_compress')) {
|
|||
}
|
||||
|
||||
//只搜索文章标题
|
||||
function gdk_search_by_title($search, $wp_query) {
|
||||
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']) ? '' : '%';
|
||||
$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);
|
||||
|
@ -251,39 +281,42 @@ function gdk_search_by_title($search, $wp_query) {
|
|||
add_filter('posts_search', 'gdk_search_by_title', 10, 2);
|
||||
|
||||
//评论地址更换
|
||||
function gdk_comment_author( $query_vars ) {
|
||||
if ( array_key_exists( 'author_name', $query_vars ) ) {
|
||||
global $wpdb;
|
||||
$author_id = $wpdb->get_var( $wpdb->prepare( "SELECT user_id FROM {$wpdb->usermeta} WHERE meta_key = 'first_name' AND meta_value = %s", $query_vars['author_name'] ) );
|
||||
if ( $author_id ) {
|
||||
$query_vars['author'] = $author_id;
|
||||
unset( $query_vars['author_name'] );
|
||||
}
|
||||
}
|
||||
return $query_vars;
|
||||
function gdk_comment_author($query_vars)
|
||||
{
|
||||
if (array_key_exists('author_name', $query_vars)) {
|
||||
global $wpdb;
|
||||
$author_id = $wpdb->get_var($wpdb->prepare("SELECT user_id FROM {$wpdb->usermeta} WHERE meta_key = 'first_name' AND meta_value = %s", $query_vars['author_name']));
|
||||
if ($author_id) {
|
||||
$query_vars['author'] = $author_id;
|
||||
unset($query_vars['author_name']);
|
||||
}
|
||||
}
|
||||
return $query_vars;
|
||||
}
|
||||
add_filter( 'request', 'gdk_comment_author' );
|
||||
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 );
|
||||
}
|
||||
return $link;
|
||||
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);
|
||||
}
|
||||
return $link;
|
||||
}
|
||||
add_filter( 'author_link', 'gdk_comment_author_link', 10, 3 );
|
||||
add_filter('author_link', 'gdk_comment_author_link', 10, 3);
|
||||
|
||||
//文章目录,来自露兜,云落修改
|
||||
if (gdk_option('gdk_article_list')) {
|
||||
function article_index($content) {
|
||||
function article_index($content)
|
||||
{
|
||||
$matches = array();
|
||||
$ul_li = '';
|
||||
$r = "/<h2>([^<]+)<\/h2>/im";
|
||||
$ul_li = '';
|
||||
$r = "/<h2>([^<]+)<\/h2>/im";
|
||||
if (is_single() && preg_match_all($r, $content, $matches)) {
|
||||
foreach ($matches[1] as $num => $title) {
|
||||
$title = trim(strip_tags($title));
|
||||
$title = trim(strip_tags($title));
|
||||
$content = str_replace($matches[0][$num], '<h2 id="title-' . $num . '">' . $title . '</h2>', $content);
|
||||
$ul_li.= '<li><a href="#title-' . $num . '">' . $title . "</a></li>\n";
|
||||
$ul_li .= '<li><a href="#title-' . $num . '">' . $title . "</a></li>\n";
|
||||
}
|
||||
$content = '<div id="article-index">
|
||||
<strong>文章目录<a class="hidetoc">[隐藏]</a></strong>
|
||||
|
@ -293,4 +326,4 @@ if (gdk_option('gdk_article_list')) {
|
|||
return $content;
|
||||
}
|
||||
add_filter('the_content', 'article_index');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,34 +1,35 @@
|
|||
<?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服务
|
||||
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');
|
||||
}
|
||||
*/
|
||||
add_action('phpmailer_init', 'googlo_mail_smtp');
|
||||
}
|
||||
*/
|
||||
//修改默认发信地址
|
||||
function deel_res_from_email($email) {
|
||||
function deel_res_from_email($email)
|
||||
{
|
||||
$wp_from_email = get_option('admin_email');
|
||||
return $wp_from_email;
|
||||
}
|
||||
function deel_res_from_name($email) {
|
||||
function deel_res_from_name($email)
|
||||
{
|
||||
$wp_from_name = get_option('blogname');
|
||||
return $wp_from_name;
|
||||
}
|
||||
|
@ -36,64 +37,71 @@ add_filter('wp_mail_from', 'deel_res_from_email');
|
|||
add_filter('wp_mail_from_name', 'deel_res_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);
|
||||
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);
|
||||
$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") == '') $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'");
|
||||
$notify = $parent_id ? get_comment($parent_id)->comment_mail_notify : '0';
|
||||
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'");
|
||||
}
|
||||
|
||||
$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";
|
||||
$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);
|
||||
}
|
||||
}
|
||||
add_action('comment_post', 'comment_mail_notify');
|
||||
|
||||
//站长评论邮件添加评论链接
|
||||
function gdk_notify_postauthor($notify_message,$comment_ID) {
|
||||
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);
|
||||
|
||||
|
||||
//欢迎新用户邮件
|
||||
|
||||
function gdk_register_mail($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);
|
||||
}
|
||||
add_action('user_register', 'gdk_register_mail');
|
||||
|
||||
|
||||
function gdk_register_mail($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);
|
||||
}
|
||||
add_action('user_register', 'gdk_register_mail');
|
||||
|
||||
//登录失败提醒
|
||||
|
||||
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";
|
||||
wp_mail($to, $subject, $message, $headers);
|
||||
}
|
||||
add_action('wp_login_failed', 'gdk_login_failed_notify');
|
||||
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";
|
||||
wp_mail($to, $subject, $message, $headers);
|
||||
}
|
||||
add_action('wp_login_failed', 'gdk_login_failed_notify');
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
<?php
|
||||
include( 'rewrite.php' );//路由重写
|
||||
include( 'Common.php' );//通用代码
|
||||
include( 'Ajax.php' );//Ajax服务
|
||||
include 'rewrite.php'; //路由重写
|
||||
include 'Common.php'; //通用代码
|
||||
include 'Ajax.php'; //Ajax服务
|
||||
|
||||
include( 'optimization.php');//优化措施
|
||||
include( 'advanced.php' );//高级功能
|
||||
include( 'security.php' );//安全功能
|
||||
include 'optimization.php'; //优化措施
|
||||
include 'advanced.php'; //高级功能
|
||||
include 'security.php'; //安全功能
|
||||
|
||||
include( 'shortcode.php' );//短代码
|
||||
include( 'seo.php' );//seo功能
|
||||
include( 'user.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'; //导航页面
|
||||
|
|
|
@ -1,32 +1,34 @@
|
|||
<?php
|
||||
|
||||
|
||||
function gdk_feed_disabled() {
|
||||
wp_die('Feed已经关闭, 请访问网站<a href="'.get_bloginfo('url').'">首页</a>!');
|
||||
function gdk_feed_disabled()
|
||||
{
|
||||
wp_die('Feed已经关闭, 请访问网站<a href="' . get_bloginfo('url') . '">首页</a>!');
|
||||
}
|
||||
|
||||
add_action('do_feed', 'gdk_feed_disabled', 1);
|
||||
add_action('do_feed_rdf', 'gdk_feed_disabled', 1);
|
||||
add_action('do_feed_rss', 'gdk_feed_disabled', 1);
|
||||
add_action('do_feed_rss2', 'gdk_feed_disabled', 1);
|
||||
add_action('do_feed_atom', 'gdk_feed_disabled', 1);
|
||||
add_action('do_feed', 'gdk_feed_disabled', 1);
|
||||
add_action('do_feed_rdf', 'gdk_feed_disabled', 1);
|
||||
add_action('do_feed_rss', 'gdk_feed_disabled', 1);
|
||||
add_action('do_feed_rss2', 'gdk_feed_disabled', 1);
|
||||
add_action('do_feed_atom', 'gdk_feed_disabled', 1);
|
||||
|
||||
//禁用新版编辑器
|
||||
if(gdk_option('gdk_diasble_gutenberg')){
|
||||
add_filter('use_block_editor_for_post', '__return_false');
|
||||
remove_action( 'wp_enqueue_scripts', 'wp_common_block_scripts_and_styles' );
|
||||
if (gdk_option('gdk_diasble_gutenberg')) {
|
||||
add_filter('use_block_editor_for_post', '__return_false');
|
||||
remove_action('wp_enqueue_scripts', 'wp_common_block_scripts_and_styles');
|
||||
}
|
||||
|
||||
add_filter('user_can_richedit','__return_false');
|
||||
add_filter('user_can_richedit', '__return_false');
|
||||
|
||||
//禁用响应式图片
|
||||
function gdk_disable_srcset_img(){
|
||||
return 1;
|
||||
function gdk_disable_srcset_img()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
add_filter('max_srcset_image_width', 'gdk_disable_srcset_img');
|
||||
|
||||
//移除默认的图片宽度以及高度
|
||||
function gdk_remove_img_width($html) {
|
||||
function gdk_remove_img_width($html)
|
||||
{
|
||||
$html = preg_replace('/(width|height)=\"\d*\"\s/', "", $html);
|
||||
return $html;
|
||||
}
|
||||
|
@ -34,23 +36,26 @@ add_filter('post_thumbnail_html', 'gdk_remove_img_width', 10);
|
|||
add_filter('image_send_to_editor', 'gdk_remove_img_width', 10);
|
||||
|
||||
//取消后台登陆错误的抖动提示
|
||||
function gdk_wps_login_error() {
|
||||
function gdk_wps_login_error()
|
||||
{
|
||||
remove_action('login_head', 'wp_shake_js', 12);
|
||||
}
|
||||
add_action('login_head', 'gdk_wps_login_error');
|
||||
|
||||
//清除wp_footer带入的embed.min.js
|
||||
function gdk_deregister_embed_script() {
|
||||
function gdk_deregister_embed_script()
|
||||
{
|
||||
wp_deregister_script('wp-embed');
|
||||
}
|
||||
add_action('wp_footer', 'gdk_deregister_embed_script');
|
||||
|
||||
//禁用默认的附件页面
|
||||
function gdk_disable_attachment_pages() {
|
||||
function gdk_disable_attachment_pages()
|
||||
{
|
||||
global $post;
|
||||
if (is_attachment()) {
|
||||
if (!empty($post->post_parent)) {
|
||||
wp_redirect(get_permalink($post->post_parent) , 301);
|
||||
wp_redirect(get_permalink($post->post_parent), 301);
|
||||
exit;
|
||||
} else {
|
||||
wp_redirect(home_url());
|
||||
|
@ -67,7 +72,7 @@ add_filter('show_admin_bar', '__return_false');
|
|||
//关闭格式化
|
||||
add_filter('run_wptexturize', '__return_false');
|
||||
//禁用找回密码
|
||||
add_filter('allow_password_reset', '__return_false' );
|
||||
add_filter('allow_password_reset', '__return_false');
|
||||
add_filter('wp_password_change_notification_email', '__return_false'); //关闭密码修改站长邮件
|
||||
add_filter('password_change_email', '__return_false'); //关闭密码修改用户邮件
|
||||
add_filter('wp_new_user_notification_email', '__return_false'); //关闭新用户注册用户邮件
|
||||
|
@ -83,7 +88,8 @@ remove_action('welcome_panel', 'wp_welcome_panel');
|
|||
|
||||
//自动中英文空格
|
||||
if (gdk_option('gdk_auto_space')) {
|
||||
function gdk_auto_space($data){
|
||||
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;
|
||||
|
@ -91,220 +97,224 @@ if (gdk_option('gdk_auto_space')) {
|
|||
add_filter('the_content', 'gdk_auto_space');
|
||||
}
|
||||
|
||||
function gdk_after_init_theme() {
|
||||
update_option( 'image_default_align', 'center' );//居中显示
|
||||
update_option( 'image_default_link_type', 'file' );//连接到媒体文件本身
|
||||
update_option( 'image_default_size', 'full' );//完整尺寸
|
||||
update_option( 'large_size_h', '0' );//关闭默认缩略图
|
||||
update_option( 'large_size_w', '0' );//关闭默认缩略图
|
||||
update_option( 'medium_large_size_h', '0' );//关闭默认缩略图
|
||||
update_option( 'medium_large_size_w', '0' );//关闭默认缩略图
|
||||
update_option( 'medium_size_h', '0' );//关闭默认缩略图
|
||||
update_option( 'medium_size_w', '0' );//关闭默认缩略图
|
||||
update_option( 'thumbnail_size_w', '0' );//关闭默认缩略图
|
||||
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 );
|
||||
update_option( 'permalink_structure', '/archives/%post_id%.html' );//固定链接格式
|
||||
function gdk_after_init_theme()
|
||||
{
|
||||
update_option('image_default_align', 'center'); //居中显示
|
||||
update_option('image_default_link_type', 'file'); //连接到媒体文件本身
|
||||
update_option('image_default_size', 'full'); //完整尺寸
|
||||
update_option('large_size_h', '0'); //关闭默认缩略图
|
||||
update_option('large_size_w', '0'); //关闭默认缩略图
|
||||
update_option('medium_large_size_h', '0'); //关闭默认缩略图
|
||||
update_option('medium_large_size_w', '0'); //关闭默认缩略图
|
||||
update_option('medium_size_h', '0'); //关闭默认缩略图
|
||||
update_option('medium_size_w', '0'); //关闭默认缩略图
|
||||
update_option('thumbnail_size_w', '0'); //关闭默认缩略图
|
||||
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 );
|
||||
update_option('permalink_structure', '/archives/%post_id%.html'); //固定链接格式
|
||||
}
|
||||
update_option( 'posts_per_page', '30' );//每页文章数目
|
||||
update_option('posts_per_page', '30'); //每页文章数目
|
||||
}
|
||||
add_action( 'after_setup_theme', 'gdk_after_init_theme' );
|
||||
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');
|
||||
function gdk_blank_site_bar($wp_admin_bar)
|
||||
{
|
||||
$node = $wp_admin_bar->get_node('view-site');
|
||||
$node->meta['target'] = '_blank';
|
||||
$wp_admin_bar->add_node($node);
|
||||
}
|
||||
add_action( 'admin_bar_menu', 'gdk_blank_site_bar', 80 );
|
||||
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) {
|
||||
remove_action($action, 'the_generator');
|
||||
}
|
||||
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) {
|
||||
remove_action($action, 'the_generator');
|
||||
}
|
||||
|
||||
remove_action('wp_head', 'rsd_link'); //删除 head 中的 RSD LINK
|
||||
remove_action('wp_head', 'wlwmanifest_link'); //删除 head 中的 Windows Live Writer 的适配器?
|
||||
remove_action('wp_head', 'feed_links_extra', 3); //删除 head 中的 Feed 相关的link
|
||||
//remove_action( 'wp_head', 'feed_links', 2 );
|
||||
remove_action('wp_head', 'index_rel_link'); //删除 head 中首页,上级,开始,相连的日志链接
|
||||
remove_action('wp_head', 'parent_post_rel_link', 10);
|
||||
remove_action('wp_head', 'start_post_rel_link', 10);
|
||||
remove_action('wp_head', 'adjacent_posts_rel_link_wp_head', 10);
|
||||
remove_action('wp_head', 'wp_shortlink_wp_head', 10, 0); //删除 head 中的 shortlink
|
||||
remove_action('wp_head', 'rest_output_link_wp_head', 10); // 删除头部输出 WP RSET API 地址
|
||||
remove_action('template_redirect', 'wp_shortlink_header', 11); //禁止短链接 Header 标签。
|
||||
remove_action('template_redirect', 'rest_output_link_header', 11); // 禁止输出 Header Link 标签。
|
||||
remove_action( 'wp_head', 'wp_oembed_add_discovery_links', 10 );
|
||||
remove_action( 'wp_head', 'wp_oembed_add_discovery_links' );
|
||||
remove_action( 'wp_head', 'wp_oembed_add_host_js' );
|
||||
remove_action('wp_head', 'rsd_link'); //删除 head 中的 RSD LINK
|
||||
remove_action('wp_head', 'wlwmanifest_link'); //删除 head 中的 Windows Live Writer 的适配器?
|
||||
remove_action('wp_head', 'feed_links_extra', 3); //删除 head 中的 Feed 相关的link
|
||||
//remove_action( 'wp_head', 'feed_links', 2 );
|
||||
remove_action('wp_head', 'index_rel_link'); //删除 head 中首页,上级,开始,相连的日志链接
|
||||
remove_action('wp_head', 'parent_post_rel_link', 10);
|
||||
remove_action('wp_head', 'start_post_rel_link', 10);
|
||||
remove_action('wp_head', 'adjacent_posts_rel_link_wp_head', 10);
|
||||
remove_action('wp_head', 'wp_shortlink_wp_head', 10, 0); //删除 head 中的 shortlink
|
||||
remove_action('wp_head', 'rest_output_link_wp_head', 10); // 删除头部输出 WP RSET API 地址
|
||||
remove_action('template_redirect', 'wp_shortlink_header', 11); //禁止短链接 Header 标签。
|
||||
remove_action('template_redirect', 'rest_output_link_header', 11); // 禁止输出 Header Link 标签。
|
||||
remove_action('wp_head', 'wp_oembed_add_discovery_links', 10);
|
||||
remove_action('wp_head', 'wp_oembed_add_discovery_links');
|
||||
remove_action('wp_head', 'wp_oembed_add_host_js');
|
||||
}
|
||||
|
||||
//去掉后台帮助
|
||||
add_action('in_admin_header', function(){
|
||||
global $current_screen;
|
||||
$current_screen->remove_help_tabs();
|
||||
add_action('in_admin_header', function () {
|
||||
global $current_screen;
|
||||
$current_screen->remove_help_tabs();
|
||||
});
|
||||
//清理菜单类
|
||||
add_filter( 'nav_menu_css_class', function ( $var ) {
|
||||
return is_array( $var ) ? array_intersect( $var, [ 'current-menu-item', 'menu-item', 'menu-item-has-children' ] ) : '';
|
||||
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 ) {
|
||||
if ( ! is_admin() && ! empty( $scripts->registered['jquery'] ) ) {
|
||||
function gdk_disable_migrate($scripts)
|
||||
{
|
||||
if (!is_admin() && !empty($scripts->registered['jquery'])) {
|
||||
$scripts->registered['jquery']->deps = array_diff(
|
||||
$scripts->registered['jquery']->deps,
|
||||
[ 'jquery-migrate' ]
|
||||
['jquery-migrate']
|
||||
);
|
||||
}
|
||||
}
|
||||
add_action( 'wp_default_scripts', 'gdk_disable_migrate' );
|
||||
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更新 **/
|
||||
if (gdk_option('gdk_diasble_wp_update')) {
|
||||
add_filter('automatic_updater_disabled', '__return_true'); // 彻底关闭自动更新
|
||||
add_filter('automatic_updater_disabled', '__return_true'); // 彻底关闭自动更新
|
||||
remove_action('init', 'wp_schedule_update_checks'); // 关闭更新检查定时作业
|
||||
wp_clear_scheduled_hook('wp_version_check'); // 移除已有的版本检查定时作业
|
||||
wp_clear_scheduled_hook('wp_update_plugins'); // 移除已有的插件更新定时作业
|
||||
wp_clear_scheduled_hook('wp_update_themes'); // 移除已有的主题更新定时作业
|
||||
wp_clear_scheduled_hook('wp_maybe_auto_update'); // 移除已有的自动更新定时作业
|
||||
remove_action( 'admin_init', '_maybe_update_core' ); // 移除后台内核更新检查
|
||||
remove_action( 'load-plugins.php', 'wp_update_plugins' ); // 移除后台插件更新检查
|
||||
remove_action( 'load-update.php', 'wp_update_plugins' );
|
||||
remove_action( 'load-update-core.php', 'wp_update_plugins' );
|
||||
remove_action( 'admin_init', '_maybe_update_plugins' );
|
||||
remove_action( 'load-themes.php', 'wp_update_themes' ); // 移除后台主题更新检查
|
||||
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;} );
|
||||
wp_clear_scheduled_hook('wp_version_check'); // 移除已有的版本检查定时作业
|
||||
wp_clear_scheduled_hook('wp_update_plugins'); // 移除已有的插件更新定时作业
|
||||
wp_clear_scheduled_hook('wp_update_themes'); // 移除已有的主题更新定时作业
|
||||
wp_clear_scheduled_hook('wp_maybe_auto_update'); // 移除已有的自动更新定时作业
|
||||
remove_action('admin_init', '_maybe_update_core'); // 移除后台内核更新检查
|
||||
remove_action('load-plugins.php', 'wp_update_plugins'); // 移除后台插件更新检查
|
||||
remove_action('load-update.php', 'wp_update_plugins');
|
||||
remove_action('load-update-core.php', 'wp_update_plugins');
|
||||
remove_action('admin_init', '_maybe_update_plugins');
|
||||
remove_action('load-themes.php', 'wp_update_themes'); // 移除后台主题更新检查
|
||||
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_action( 'wp_before_admin_bar_render', function () {
|
||||
global $wp_admin_bar;
|
||||
$wp_admin_bar->remove_menu( 'wp-logo' );
|
||||
$wp_admin_bar->remove_menu( 'about' );
|
||||
$wp_admin_bar->remove_menu( 'wporg' );
|
||||
$wp_admin_bar->remove_menu( 'documentation' );
|
||||
$wp_admin_bar->remove_menu( 'support-forums' );
|
||||
$wp_admin_bar->remove_menu( 'feedback' );
|
||||
} );
|
||||
add_action('wp_before_admin_bar_render', function () {
|
||||
global $wp_admin_bar;
|
||||
$wp_admin_bar->remove_menu('wp-logo');
|
||||
$wp_admin_bar->remove_menu('about');
|
||||
$wp_admin_bar->remove_menu('wporg');
|
||||
$wp_admin_bar->remove_menu('documentation');
|
||||
$wp_admin_bar->remove_menu('support-forums');
|
||||
$wp_admin_bar->remove_menu('feedback');
|
||||
});
|
||||
|
||||
//禁用自带p标签的
|
||||
remove_filter( 'the_content', 'wpautop' );
|
||||
add_filter( 'the_content', 'wpautop' , 12);
|
||||
remove_filter('the_content', 'wpautop');
|
||||
add_filter('the_content', 'wpautop', 12);
|
||||
|
||||
// 禁止后台加载谷歌字体
|
||||
function gdk_remove_open_sans() {
|
||||
wp_deregister_style( 'open-sans' );
|
||||
wp_register_style( 'open-sans', false );
|
||||
wp_enqueue_style('open-sans','');
|
||||
function gdk_remove_open_sans()
|
||||
{
|
||||
wp_deregister_style('open-sans');
|
||||
wp_register_style('open-sans', false);
|
||||
wp_enqueue_style('open-sans', '');
|
||||
}
|
||||
add_action( 'init', 'gdk_remove_open_sans' );
|
||||
add_action('init', 'gdk_remove_open_sans');
|
||||
|
||||
//WordPress 彻底移除后台“隐私”设置功能
|
||||
add_filter( 'map_meta_cap', 'ds_disable_core_privacy_tools', 10, 2 );
|
||||
remove_action( 'init', 'wp_schedule_delete_old_privacy_export_files' );
|
||||
remove_action( 'wp_privacy_delete_old_export_files', 'wp_privacy_delete_old_export_files' );
|
||||
function ds_disable_core_privacy_tools( $caps, $cap ) {
|
||||
switch ( $cap ) {
|
||||
case 'export_others_personal_data':
|
||||
case 'erase_others_personal_data':
|
||||
case 'manage_privacy_options':
|
||||
$caps[] = 'do_not_allow';
|
||||
break;
|
||||
}
|
||||
return $caps;
|
||||
add_filter('map_meta_cap', 'ds_disable_core_privacy_tools', 10, 2);
|
||||
remove_action('init', 'wp_schedule_delete_old_privacy_export_files');
|
||||
remove_action('wp_privacy_delete_old_export_files', 'wp_privacy_delete_old_export_files');
|
||||
function ds_disable_core_privacy_tools($caps, $cap)
|
||||
{
|
||||
switch ($cap) {
|
||||
case 'export_others_personal_data':
|
||||
case 'erase_others_personal_data':
|
||||
case 'manage_privacy_options':
|
||||
$caps[] = 'do_not_allow';
|
||||
break;
|
||||
}
|
||||
return $caps;
|
||||
}
|
||||
|
||||
// 禁止dns-prefetch
|
||||
function gdk_remove_dns( $hints, $relation_type ) {
|
||||
if ( 'dns-prefetch' === $relation_type ) {
|
||||
return array_diff( wp_dependencies_unique_hosts(), $hints );
|
||||
}
|
||||
return $hints;
|
||||
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 );
|
||||
|
||||
|
||||
//第一段
|
||||
/*
|
||||
function first_paragraph( $content ) {
|
||||
return preg_replace( '/<p ([^>]+)?>/', '<p $1 class="lead">', $content, 1 );
|
||||
}
|
||||
add_filter( 'the_content', 'first_paragraph' );
|
||||
*/
|
||||
add_filter('wp_resource_hints', 'gdk_remove_dns', 10, 2);
|
||||
|
||||
//禁用emoji功能
|
||||
if (gdk_option('gdk_disable_emojis')) {
|
||||
function gdk_disable_emojis_link() {
|
||||
remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
|
||||
remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
|
||||
remove_action( 'wp_print_styles', 'print_emoji_styles' );
|
||||
remove_action( 'admin_print_styles', 'print_emoji_styles' );
|
||||
remove_filter( 'the_content_feed', 'wp_staticize_emoji' );
|
||||
remove_filter( 'comment_text_rss', 'wp_staticize_emoji' );
|
||||
remove_filter( 'wp_mail', 'wp_staticize_emoji_for_email' );
|
||||
add_filter( 'tiny_mce_plugins', 'gdk_disable_emojis_tinymce' );
|
||||
}
|
||||
add_action( 'init', 'gdk_disable_emojis_link' );
|
||||
function gdk_disable_emojis_link()
|
||||
{
|
||||
remove_action('wp_head', 'print_emoji_detection_script', 7);
|
||||
remove_action('admin_print_scripts', 'print_emoji_detection_script');
|
||||
remove_action('wp_print_styles', 'print_emoji_styles');
|
||||
remove_action('admin_print_styles', 'print_emoji_styles');
|
||||
remove_filter('the_content_feed', 'wp_staticize_emoji');
|
||||
remove_filter('comment_text_rss', 'wp_staticize_emoji');
|
||||
remove_filter('wp_mail', 'wp_staticize_emoji_for_email');
|
||||
add_filter('tiny_mce_plugins', 'gdk_disable_emojis_tinymce');
|
||||
}
|
||||
add_action('init', 'gdk_disable_emojis_link');
|
||||
|
||||
function gdk_disable_emojis_tinymce( $plugins ) {
|
||||
if ( is_array( $plugins ) ) return array_diff( $plugins, array( 'wpemoji' ) );
|
||||
return array();
|
||||
function gdk_disable_emojis_tinymce($plugins)
|
||||
{
|
||||
if (is_array($plugins)) {
|
||||
return array_diff($plugins, array('wpemoji'));
|
||||
}
|
||||
|
||||
return array();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//禁用日志修订功能
|
||||
if (gdk_option('gdk_disable_revision')) {
|
||||
add_filter( 'wp_revisions_to_keep', 'gdk_revisions_to_keep', 10, 2 );
|
||||
function gdk_revisions_to_keep( $num, $post ) {
|
||||
return 0;
|
||||
}
|
||||
add_action('wp_print_scripts','gdk_disable_autosave');
|
||||
function gdk_disable_autosave() {
|
||||
wp_deregister_script('autosave');
|
||||
}
|
||||
add_filter('wp_revisions_to_keep', 'gdk_revisions_to_keep', 10, 2);
|
||||
function gdk_revisions_to_keep($num, $post)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
add_action('wp_print_scripts', 'gdk_disable_autosave');
|
||||
function gdk_disable_autosave()
|
||||
{
|
||||
wp_deregister_script('autosave');
|
||||
}
|
||||
}
|
||||
|
||||
//文章最多保存 5 个版本,默认的
|
||||
if ( ! defined( 'WP_POST_REVISIONS' ) ) {
|
||||
define( 'WP_POST_REVISIONS', 5 );
|
||||
if (!defined('WP_POST_REVISIONS')) {
|
||||
define('WP_POST_REVISIONS', 5);
|
||||
}
|
||||
|
||||
//前台禁用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', '');
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
//禁用WordPress活动
|
||||
function gdk_dweandw_remove() {
|
||||
remove_meta_box('dashboard_primary', get_current_screen() , 'side');
|
||||
function gdk_dweandw_remove()
|
||||
{
|
||||
remove_meta_box('dashboard_primary', get_current_screen(), 'side');
|
||||
}
|
||||
add_action('wp_network_dashboard_setup', 'gdk_dweandw_remove', 20);
|
||||
add_action('wp_user_dashboard_setup', 'gdk_dweandw_remove', 20);
|
||||
|
@ -312,189 +322,203 @@ 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';
|
||||
}
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
);
|
||||
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';
|
||||
}
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
//文件自动重命名
|
||||
if(gdk_option('gdk_upload_rename')) {
|
||||
function gdk_upload_rename( $file ) {
|
||||
$info = pathinfo($file['name']);
|
||||
$ext = $info['extension'];
|
||||
$ignore_exts = ['zip', 'rar', '7z'];
|
||||
//被忽略的文件格式
|
||||
if (!in_array($ext, $ignore_exts)) {
|
||||
$filedate = date('YmdHis').mt_rand(100, 999);
|
||||
$file['name'] = $filedate.'.'.$ext;
|
||||
}
|
||||
return $file;
|
||||
}
|
||||
add_filter('wp_handle_upload_prefilter', 'gdk_upload_rename' );
|
||||
if (gdk_option('gdk_upload_rename')) {
|
||||
function gdk_upload_rename($file)
|
||||
{
|
||||
$info = pathinfo($file['name']);
|
||||
$ext = $info['extension'];
|
||||
$ignore_exts = ['zip', 'rar', '7z'];
|
||||
//被忽略的文件格式
|
||||
if (!in_array($ext, $ignore_exts)) {
|
||||
$filedate = date('YmdHis') . mt_rand(100, 999);
|
||||
$file['name'] = $filedate . '.' . $ext;
|
||||
}
|
||||
return $file;
|
||||
}
|
||||
add_filter('wp_handle_upload_prefilter', '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
|
||||
return $sizes;
|
||||
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
|
||||
return $sizes;
|
||||
}
|
||||
add_action('intermediate_image_sizes_advanced', 'gdk_disable_image_sizes');
|
||||
// 禁用缩放尺寸
|
||||
add_filter('big_image_size_threshold', '__return_false');
|
||||
// 禁用其他图片尺寸
|
||||
function gdk_disable_other_image_sizes() {
|
||||
remove_image_size('post-thumbnail');// disable images added via set_post_thumbnail_size()
|
||||
remove_image_size('another-size');// disable any other added image sizes
|
||||
function gdk_disable_other_image_sizes()
|
||||
{
|
||||
remove_image_size('post-thumbnail'); // disable images added via set_post_thumbnail_size()
|
||||
remove_image_size('another-size'); // disable any other added image sizes
|
||||
}
|
||||
add_action('init', 'gdk_disable_other_image_sizes');
|
||||
|
||||
// 搜索结果为1时候自动跳转到对应页面
|
||||
function gdk_redirect_single_search_result() {
|
||||
if ( is_search() ) {
|
||||
global $wp_query;
|
||||
if ($wp_query->post_count == 1) {
|
||||
wp_redirect( get_permalink( $wp_query->posts['0']->ID ) );
|
||||
exit();
|
||||
}
|
||||
}
|
||||
function gdk_redirect_single_search_result()
|
||||
{
|
||||
if (is_search()) {
|
||||
global $wp_query;
|
||||
if ($wp_query->post_count == 1) {
|
||||
wp_redirect(get_permalink($wp_query->posts['0']->ID));
|
||||
exit();
|
||||
}
|
||||
}
|
||||
}
|
||||
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' ) ) );
|
||||
exit();
|
||||
}
|
||||
function gdk_redirect_search()
|
||||
{
|
||||
if (is_search() && !empty($_GET['s'])) {
|
||||
wp_redirect(home_url("/search/") . urlencode(get_query_var('s')));
|
||||
exit();
|
||||
}
|
||||
}
|
||||
add_action('template_redirect', 'gdk_redirect_search' );
|
||||
add_action('template_redirect', 'gdk_redirect_search');
|
||||
|
||||
//替换后台默认的底部文字内容
|
||||
function gdk_replace_footer_admin() {
|
||||
$result = apply_filters('gdk_filter_admin_footer_text', '由GDK插件提供底层支持');
|
||||
echo $result;
|
||||
function gdk_replace_footer_admin()
|
||||
{
|
||||
$result = apply_filters('gdk_filter_admin_footer_text', '由GDK插件提供底层支持');
|
||||
echo $result;
|
||||
}
|
||||
add_filter('admin_footer_text', 'gdk_replace_footer_admin');
|
||||
|
||||
|
||||
//禁用REST API功能
|
||||
if(gdk_option('gdk_disable_restapi')) {
|
||||
add_action( 'rest_pre_dispatch', 'deactivate_rest_api' );
|
||||
add_action( 'rest_authentication_errors', 'deactivate_rest_api' );
|
||||
function deactivate_rest_api() {
|
||||
status_header( 405 );
|
||||
wp_die( '{"code":"rest_api_disabled","message":"REST API services are disabled on this site.","data":{"status":405}}' );
|
||||
}
|
||||
if (gdk_option('gdk_disable_restapi')) {
|
||||
add_action('rest_pre_dispatch', 'deactivate_rest_api');
|
||||
add_action('rest_authentication_errors', 'deactivate_rest_api');
|
||||
function deactivate_rest_api()
|
||||
{
|
||||
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_action( 'rest_api_init', 'wp_oembed_register_route' );
|
||||
remove_action('rest_api_init', 'wp_oembed_register_route');
|
||||
}
|
||||
|
||||
// 定制登录页面链接的连接
|
||||
add_filter('login_headerurl', function (){
|
||||
return home_url();
|
||||
add_filter('login_headerurl', function () {
|
||||
return home_url();
|
||||
});
|
||||
|
||||
|
||||
// 定制登录页面链接的标题
|
||||
add_filter('login_headertext', function (){
|
||||
return get_bloginfo('name');
|
||||
add_filter('login_headertext', function () {
|
||||
return get_bloginfo('name');
|
||||
});
|
||||
|
||||
|
||||
function gdk_custom_head_code() {
|
||||
$gdk_custom_head_code = gdk_option('gdk_custom_head_code');
|
||||
echo $gdk_custom_head_code;
|
||||
function gdk_custom_head_code()
|
||||
{
|
||||
$gdk_custom_head_code = gdk_option('gdk_custom_head_code');
|
||||
echo $gdk_custom_head_code;
|
||||
}
|
||||
add_action('wp_head', 'gdk_custom_head_code');
|
||||
|
||||
function gdk_custom_footer_code() {
|
||||
$gdk_custom_footer_code = gdk_option('gdk_custom_foot_code');
|
||||
echo $gdk_custom_footer_code;
|
||||
function gdk_custom_footer_code()
|
||||
{
|
||||
$gdk_custom_footer_code = gdk_option('gdk_custom_foot_code');
|
||||
echo $gdk_custom_footer_code;
|
||||
}
|
||||
add_action('wp_footer', 'gdk_custom_footer_code',400);
|
||||
add_action('wp_footer', 'gdk_custom_footer_code', 400);
|
||||
|
||||
if(gdk_option('gdk_no_category')){
|
||||
if (gdk_option('gdk_no_category')) {
|
||||
if (!function_exists('gdk_no_category_base_refresh_rules')):
|
||||
add_action('load-themes.php', '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() {
|
||||
function gdk_no_category_base_refresh_rules()
|
||||
{
|
||||
global $wp_rewrite;
|
||||
$wp_rewrite -> flush_rules();
|
||||
$wp_rewrite->flush_rules();
|
||||
}
|
||||
add_action('init', 'gdk_no_category_base_permastruct');
|
||||
function gdk_no_category_base_permastruct() {
|
||||
function gdk_no_category_base_permastruct()
|
||||
{
|
||||
global $wp_rewrite;
|
||||
$wp_rewrite -> extra_permastructs['category']['struct'] = '%category%';
|
||||
$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) {
|
||||
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));
|
||||
$categories = get_categories(array('hide_empty' => false));
|
||||
foreach ($categories as $category) {
|
||||
$gdk_category = $category -> slug;
|
||||
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;
|
||||
$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]';
|
||||
$gdk_category = $category->slug;
|
||||
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;
|
||||
}
|
||||
// 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;
|
||||
$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();
|
||||
}
|
||||
return $query_vars;
|
||||
}
|
||||
endif;
|
||||
}
|
||||
|
||||
//站长评论邮件添加评论链接
|
||||
function gdk_notify_admin($notify_message,$comment_ID) {
|
||||
function gdk_notify_admin($notify_message, $comment_ID)
|
||||
{
|
||||
$notify = $notify_message;
|
||||
$notify.= '<br/> 快速回复此评论: ' . admin_url("edit-comments.php").'#comment-'.$comment_ID;
|
||||
$notify .= '<br/> 快速回复此评论: ' . admin_url("edit-comments.php") . '#comment-' . $comment_ID;
|
||||
return $notify;
|
||||
}
|
||||
add_filter('comment_notification_text', 'gdk_notify_admin', 10, 2);
|
||||
|
||||
|
||||
// 评论添加@,来自:http://www.ludou.org/wordpress-comment-reply-add-at.html
|
||||
function gdk_comment_add_at($comment_text, $comment = '') {
|
||||
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;
|
||||
}
|
||||
|
@ -503,10 +527,11 @@ function gdk_comment_add_at($comment_text, $comment = '') {
|
|||
add_filter('comment_text', 'gdk_comment_add_at', 20, 2);
|
||||
|
||||
//搜索结果排除所有页面
|
||||
function gdk_search_filter_page($query) {
|
||||
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');
|
||||
add_filter('pre_get_posts', 'gdk_search_filter_page');
|
||||
|
|
|
@ -4,52 +4,53 @@
|
|||
*/
|
||||
|
||||
//页面伪静态规则
|
||||
function gdk_page_permalink() {
|
||||
global $wp_rewrite;
|
||||
if (!strpos($wp_rewrite->get_page_permastruct(), '.html')) {
|
||||
$wp_rewrite->page_structure = $wp_rewrite->page_structure . '.html';
|
||||
}
|
||||
function gdk_page_permalink()
|
||||
{
|
||||
global $wp_rewrite;
|
||||
if (!strpos($wp_rewrite->get_page_permastruct(), '.html')) {
|
||||
$wp_rewrite->page_structure = $wp_rewrite->page_structure . '.html';
|
||||
}
|
||||
}
|
||||
add_action('init', 'gdk_page_permalink', -1);
|
||||
|
||||
|
||||
// 更新重写规则
|
||||
function gdk_rewrite_flush_rules(){
|
||||
$rules = get_option( 'rewrite_rules' );
|
||||
if ( !isset( $rules['^sitemap(.*?)\.xml$'] , $rules['^sitemap(.*?)\.html$'], $rules['^daohang(.*?)\.html$'] ) ) {
|
||||
function gdk_rewrite_flush_rules()
|
||||
{
|
||||
$rules = get_option('rewrite_rules');
|
||||
if (!isset($rules['^sitemap(.*?)\.xml$'], $rules['^sitemap(.*?)\.html$'], $rules['^daohang(.*?)\.html$'])) {
|
||||
global $wp_rewrite;
|
||||
$wp_rewrite->flush_rules();
|
||||
}
|
||||
}
|
||||
add_action( 'wp_loaded', 'gdk_rewrite_flush_rules' );
|
||||
|
||||
add_action('wp_loaded', 'gdk_rewrite_flush_rules');
|
||||
|
||||
// 添加自定义URL重写
|
||||
function gdk_add_custom_rewrite_rule() {
|
||||
add_rewrite_rule('^sitemap(.*?)\.xml$','index.php?sitemap=gdk$matches[1]','top');//xml地图规则
|
||||
add_rewrite_rule('^sitemap(.*?)\.html$','index.php?sitemap=gdkk$matches[1]','top');//html地图规则
|
||||
add_rewrite_rule('^daohang(.*?)\.html$','index.php?daohang=gdkk$matches[1]','top');//导航页面规则
|
||||
add_rewrite_rule('^weauth','index.php?user=$matches[1]&sk=$matches[2]','top');//WeAuth微信登陆二维码规则
|
||||
add_rewrite_rule('^goauth','index.php?userinfo=$matches[1]&sk=$matches[2]','top');//GoAuth微信登陆二维码规则
|
||||
function gdk_add_custom_rewrite_rule()
|
||||
{
|
||||
add_rewrite_rule('^sitemap(.*?)\.xml$', 'index.php?sitemap=gdk$matches[1]', 'top'); //xml地图规则
|
||||
add_rewrite_rule('^sitemap(.*?)\.html$', 'index.php?sitemap=gdkk$matches[1]', 'top'); //html地图规则
|
||||
add_rewrite_rule('^daohang(.*?)\.html$', 'index.php?daohang=gdkk$matches[1]', 'top'); //导航页面规则
|
||||
add_rewrite_rule('^weauth', 'index.php?user=$matches[1]&sk=$matches[2]', 'top'); //WeAuth微信登陆二维码规则
|
||||
add_rewrite_rule('^goauth', 'index.php?userinfo=$matches[1]&sk=$matches[2]', 'top'); //GoAuth微信登陆二维码规则
|
||||
}
|
||||
add_action( 'init', 'gdk_add_custom_rewrite_rule' , 10, 0);
|
||||
|
||||
add_action('init', 'gdk_add_custom_rewrite_rule', 10, 0);
|
||||
|
||||
//自定义链接跳转
|
||||
function gdk_custom_cancel_redirect( $redirect_url ) {
|
||||
function gdk_custom_cancel_redirect($redirect_url)
|
||||
{
|
||||
$api_sitemap = get_query_var('sitemap');
|
||||
$api_daohang = get_query_var('daohang');
|
||||
if ( !empty($api_sitemap) || !empty($api_daohang) ){
|
||||
return false;
|
||||
}else{
|
||||
return $redirect_url;
|
||||
}
|
||||
if (!empty($api_sitemap) || !empty($api_daohang)) {
|
||||
return false;
|
||||
} else {
|
||||
return $redirect_url;
|
||||
}
|
||||
}
|
||||
add_filter( 'redirect_canonical', 'gdk_custom_cancel_redirect' );
|
||||
|
||||
add_filter('redirect_canonical', 'gdk_custom_cancel_redirect');
|
||||
|
||||
//自定义路由参数,GO跳转和dl下载
|
||||
function gdk_public_query_vars($public_query_vars){
|
||||
function gdk_public_query_vars($public_query_vars)
|
||||
{
|
||||
$public_query_vars[] = 'go';
|
||||
$public_query_vars[] = 'dl';
|
||||
$public_query_vars[] = 'sitemap';
|
||||
|
@ -57,4 +58,3 @@ function gdk_public_query_vars($public_query_vars){
|
|||
return $public_query_vars;
|
||||
}
|
||||
add_action('query_vars', 'gdk_public_query_vars');
|
||||
|
||||
|
|
|
@ -3,68 +3,76 @@
|
|||
//define('DISALLOW_FILE_MODS',true);
|
||||
|
||||
//阻止异常请求
|
||||
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' ) ) {
|
||||
@header( 'HTTP/1.1 403 Forbidden' );
|
||||
@header( 'Status: 403 Forbidden') ;
|
||||
@header( 'Connection: Close' );
|
||||
@exit;
|
||||
}
|
||||
}
|
||||
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')) {
|
||||
@header('HTTP/1.1 403 Forbidden');
|
||||
@header('Status: 403 Forbidden');
|
||||
@header('Connection: Close');
|
||||
@exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(gdk_option('gdk_block_requst')) {
|
||||
add_action( 'wp', 'gdk_prevent_requst' );//阻止乱七八糟的请求
|
||||
if (gdk_option('gdk_block_requst')) {
|
||||
add_action('wp', 'gdk_prevent_requst'); //阻止乱七八糟的请求
|
||||
}
|
||||
|
||||
//禁用 XML-RPC 接口
|
||||
if (gdk_option('gdk_disable_xmlrpc')) {
|
||||
add_filter('xmlrpc_enabled', '__return_false');
|
||||
remove_action('xmlrpc_rsd_apis', 'rest_output_rsd');
|
||||
add_filter('xmlrpc_enabled', '__return_false');
|
||||
remove_action('xmlrpc_rsd_apis', 'rest_output_rsd');
|
||||
}
|
||||
|
||||
//彻底关闭 pingback
|
||||
if (gdk_option('gdk_disable_trackbacks')) {
|
||||
add_filter('xmlrpc_methods', 'gdk_xmlrpc_methods');
|
||||
function gdk_xmlrpc_methods($methods) {
|
||||
unset($methods['system.multicall']);
|
||||
$methods['pingback.ping'] = '__return_false';
|
||||
$methods['pingback.extensions.getPingbacks'] = '__return_false';
|
||||
return $methods;
|
||||
add_filter('xmlrpc_methods', 'gdk_xmlrpc_methods');
|
||||
function gdk_xmlrpc_methods($methods)
|
||||
{
|
||||
unset($methods['system.multicall']);
|
||||
$methods['pingback.ping'] = '__return_false';
|
||||
$methods['pingback.extensions.getPingbacks'] = '__return_false';
|
||||
return $methods;
|
||||
}
|
||||
|
||||
//阻止站内PingBack
|
||||
function gdk_noself_ping(&$links) {
|
||||
$home = home_url();
|
||||
foreach ($links as $l => $link) if (0 === strpos($link, $home)) unset($links[$l]);
|
||||
}
|
||||
add_action('pre_ping', 'gdk_noself_ping');
|
||||
//禁用 pingbacks, enclosures, trackbacks
|
||||
remove_action('do_pings', 'do_all_pings', 10);
|
||||
//去掉 _encloseme 和 do_ping 操作。
|
||||
remove_action('publish_post', '_publish_post_hook', 5);
|
||||
}
|
||||
|
||||
//阻止站内PingBack
|
||||
function gdk_noself_ping(&$links)
|
||||
{
|
||||
$home = home_url();
|
||||
foreach ($links as $l => $link) {
|
||||
if (0 === strpos($link, $home)) {
|
||||
unset($links[$l]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
add_action('pre_ping', 'gdk_noself_ping');
|
||||
//禁用 pingbacks, enclosures, trackbacks
|
||||
remove_action('do_pings', 'do_all_pings', 10);
|
||||
//去掉 _encloseme 和 do_ping 操作。
|
||||
remove_action('publish_post', '_publish_post_hook', 5);
|
||||
}
|
||||
|
||||
//隐藏用户昵称
|
||||
add_filter('redirect_canonical', 'security_stop_user_enumeration', 10, 2);
|
||||
if ( ! function_exists( 'security_stop_user_enumeration' ) ) {
|
||||
function security_stop_user_enumeration( $redirect, $request ) {
|
||||
if ( preg_match( '/\?author=([0-9]*)(\/*)/i', $request ) ) {
|
||||
wp_redirect( get_site_url(), 301 );
|
||||
if (!function_exists('security_stop_user_enumeration')) {
|
||||
function security_stop_user_enumeration($redirect, $request)
|
||||
{
|
||||
if (preg_match('/\?author=([0-9]*)(\/*)/i', $request)) {
|
||||
wp_redirect(get_site_url(), 301);
|
||||
die();
|
||||
} else {
|
||||
return $redirect;
|
||||
|
@ -72,233 +80,262 @@ if ( ! function_exists( 'security_stop_user_enumeration' ) ) {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
//登陆错误锁定
|
||||
if ( ! class_exists( 'GDK_Limit_Login_Attempts' ) ) {
|
||||
class GDK_Limit_Login_Attempts {
|
||||
private $failed_login_limit;//登录失败的次数限制
|
||||
private $lockout_duration;//暂停登陆时间
|
||||
var $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 );
|
||||
}
|
||||
if (!class_exists('GDK_Limit_Login_Attempts')) {
|
||||
class GDK_Limit_Login_Attempts
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
public function check_attempted_login( $user, $username, $password ) {
|
||||
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 );
|
||||
//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;
|
||||
}
|
||||
public function check_attempted_login($user, $username, $password)
|
||||
{
|
||||
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);
|
||||
//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;
|
||||
}
|
||||
|
||||
public function login_failed( $username ) {
|
||||
if ( get_transient( $this->transient_name ) ) {
|
||||
$datas = get_transient( $this->transient_name );
|
||||
$datas['tried']++;
|
||||
if ( $datas['tried'] <= $this->failed_login_limit )
|
||||
set_transient( $this->transient_name, $datas , $this->lockout_duration );
|
||||
} else {
|
||||
$datas = array('tried' => 1 );
|
||||
set_transient( $this->transient_name, $datas , $this->lockout_duration );
|
||||
}
|
||||
}
|
||||
public function login_failed($username)
|
||||
{
|
||||
if (get_transient($this->transient_name)) {
|
||||
$datas = get_transient($this->transient_name);
|
||||
$datas['tried']++;
|
||||
if ($datas['tried'] <= $this->failed_login_limit) {
|
||||
set_transient($this->transient_name, $datas, $this->lockout_duration);
|
||||
}
|
||||
|
||||
private function when( $time ) {
|
||||
if ( ! $time ) return;
|
||||
$right_now = time();
|
||||
$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( '秒' );
|
||||
if ( $diff < $minute * 2 )
|
||||
return esc_attr( 'about 1 minute ago' );
|
||||
if ( $diff < $hour )
|
||||
return floor( $diff / $minute ) . ' ' . esc_attr( '分钟' );
|
||||
if ( $diff < $hour * 2 )
|
||||
return esc_attr( 'about 1 hour');
|
||||
return floor( $diff / $hour ) . ' ' . esc_attr( '小时' );
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$datas = array('tried' => 1);
|
||||
set_transient($this->transient_name, $datas, $this->lockout_duration);
|
||||
}
|
||||
}
|
||||
|
||||
private function __when($time)
|
||||
{
|
||||
if (!$time) {
|
||||
return;
|
||||
}
|
||||
|
||||
$right_now = time();
|
||||
$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('秒');
|
||||
}
|
||||
|
||||
if ($diff < $minute * 2) {
|
||||
return esc_attr('about 1 minute ago');
|
||||
}
|
||||
|
||||
if ($diff < $hour) {
|
||||
return floor($diff / $minute) . ' ' . esc_attr('分钟');
|
||||
}
|
||||
|
||||
if ($diff < $hour * 2) {
|
||||
return esc_attr('about 1 hour');
|
||||
}
|
||||
|
||||
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'), // 暂停登陆时间
|
||||
'failed_login_limit' => gdk_option('gdk_failed_login_limit'), // 登录失败的次数限制
|
||||
'lockout_duration' => gdk_option('gdk_lockout_duration'), // 暂停登陆时间
|
||||
];
|
||||
if(gdk_option('gdk_lock_login')) {
|
||||
new GDK_Limit_Login_Attempts($LLA_config);
|
||||
if (gdk_option('gdk_lock_login')) {
|
||||
new GDK_Limit_Login_Attempts($LLA_config);
|
||||
}
|
||||
|
||||
//禁用登陆错误信息
|
||||
function gdk_disable_login_errors( $error ) {
|
||||
global $errors;
|
||||
$err_codes = $errors->get_error_codes();
|
||||
if ( ! in_array( 'too_many_tried', $err_codes ) ) {
|
||||
// For security reason
|
||||
return esc_attr('Access Denied!');
|
||||
}
|
||||
return $error;
|
||||
function gdk_disable_login_errors($error)
|
||||
{
|
||||
global $errors;
|
||||
$err_codes = $errors->get_error_codes();
|
||||
if (!in_array('too_many_tried', $err_codes)) {
|
||||
// For security reason
|
||||
return esc_attr('Access Denied!');
|
||||
}
|
||||
return $error;
|
||||
}
|
||||
add_filter( 'login_errors', 'gdk_disable_login_errors' );
|
||||
add_filter('login_errors', 'gdk_disable_login_errors');
|
||||
|
||||
//网站维护代码
|
||||
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'));
|
||||
}
|
||||
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'));
|
||||
}
|
||||
}
|
||||
if (gdk_option('gdk_maintenance_mode')) {
|
||||
add_action('get_header', 'gdk_maintenance_mode');
|
||||
}
|
||||
if(gdk_option('gdk_maintenance_mode')){
|
||||
add_action('get_header', 'gdk_maintenance_mode');
|
||||
}
|
||||
|
||||
//各种措施拦截垃圾评论
|
||||
if(gdk_option('gdk_fuck_spam')) {
|
||||
//拦截无来路的评论
|
||||
function gdk_comment_check_referrer() {
|
||||
if ( ! isset( $_SERVER['HTTP_REFERER'] ) || $_SERVER['HTTP_REFERER'] == '' ) {
|
||||
wp_die( esc_attr( 'Please enable referrers in your browser!' ) );
|
||||
}
|
||||
}
|
||||
add_action('check_comment_flood', 'gdk_comment_check_referrer');
|
||||
//拦截超长链接垃圾评论
|
||||
function gdk_url_spamcheck($approved, $commentdata) {
|
||||
return (strlen($commentdata['comment_author_url']) > 50) ? 'spam' : $approved;
|
||||
}
|
||||
add_filter('pre_comment_approved', 'gdk_url_spamcheck', 99, 2);
|
||||
function gdk_comment_lang($commentdata) {
|
||||
if (is_user_logged_in()) return $commentdata;
|
||||
$pattern = '/[一-龥]/u';
|
||||
// 禁止全英文评论
|
||||
if (!preg_match($pattern, $commentdata['comment_content'])) {
|
||||
gdk_die("您的评论中必须包含汉字!");
|
||||
}
|
||||
$pattern = '/[あ-んア-ン]/u';
|
||||
// 禁止日文评论
|
||||
if (preg_match($pattern, $commentdata['comment_content'])) {
|
||||
gdk_die("评论禁止包含日文!");
|
||||
}
|
||||
//屏蔽评论里面黑名单内容
|
||||
if (wp_blacklist_check($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');
|
||||
if (gdk_option('gdk_fuck_spam')) {
|
||||
//拦截无来路的评论
|
||||
function gdk_comment_check_referrer()
|
||||
{
|
||||
if (!isset($_SERVER['HTTP_REFERER']) || $_SERVER['HTTP_REFERER'] == '') {
|
||||
wp_die(esc_attr('Please enable referrers in your browser!'));
|
||||
}
|
||||
}
|
||||
add_action('check_comment_flood', 'gdk_comment_check_referrer');
|
||||
//拦截超长链接垃圾评论
|
||||
function gdk_url_spamcheck($approved, $commentdata)
|
||||
{
|
||||
return (strlen($commentdata['comment_author_url']) > 50) ? 'spam' : $approved;
|
||||
}
|
||||
add_filter('pre_comment_approved', 'gdk_url_spamcheck', 99, 2);
|
||||
function gdk_comment_lang($commentdata)
|
||||
{
|
||||
if (is_user_logged_in()) {
|
||||
return $commentdata;
|
||||
}
|
||||
|
||||
$pattern = '/[一-龥]/u';
|
||||
// 禁止全英文评论
|
||||
if (!preg_match($pattern, $commentdata['comment_content'])) {
|
||||
gdk_die("您的评论中必须包含汉字!");
|
||||
}
|
||||
$pattern = '/[あ-んア-ン]/u';
|
||||
// 禁止日文评论
|
||||
if (preg_match($pattern, $commentdata['comment_content'])) {
|
||||
gdk_die("评论禁止包含日文!");
|
||||
}
|
||||
//屏蔽评论里面黑名单内容
|
||||
if (wp_blacklist_check($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');
|
||||
}
|
||||
|
||||
//隐藏用户名字
|
||||
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_length = strlen($string);
|
||||
$rndkey = $box = array();
|
||||
$result = '';
|
||||
for ($i = 0; $i <= 255; $i++) {
|
||||
$rndkey[$i] = ord($key[$i % $key_length]);
|
||||
$box[$i] = $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];
|
||||
$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)) {
|
||||
return substr($result, 8);
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
} else {
|
||||
return str_replace(array('=','+','/'), array('!','-','_'), base64_encode($result));
|
||||
}
|
||||
}
|
||||
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_length = strlen($string);
|
||||
$rndkey = $box = array();
|
||||
$result = '';
|
||||
for ($i = 0; $i <= 255; $i++) {
|
||||
$rndkey[$i] = ord($key[$i % $key_length]);
|
||||
$box[$i] = $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];
|
||||
$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)) {
|
||||
return substr($result, 8);
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
} else {
|
||||
return str_replace(array('=', '+', '/'), array('!', '-', '_'), base64_encode($result));
|
||||
}
|
||||
}
|
||||
|
||||
function gdk_custom_author_link_request( $query_vars ) {
|
||||
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 ) {
|
||||
$query_vars['author'] = $author_id;
|
||||
unset( $query_vars['author_name'] );
|
||||
}
|
||||
}
|
||||
return $query_vars;
|
||||
}
|
||||
add_filter( 'request', 'gdk_custom_author_link_request' );
|
||||
function gdk_custom_author_link_request($query_vars)
|
||||
{
|
||||
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) {
|
||||
$query_vars['author'] = $author_id;
|
||||
unset($query_vars['author_name']);
|
||||
}
|
||||
}
|
||||
return $query_vars;
|
||||
}
|
||||
add_filter('request', 'gdk_custom_author_link_request');
|
||||
|
||||
function gdk_custom_author_link( $link, $author_id) {
|
||||
global $wp_rewrite;
|
||||
$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);
|
||||
} else {
|
||||
$link = str_replace('%author%', gdk_text_encrypt($author_id, 'E',AUTH_KEY), $link);
|
||||
$link = home_url() . user_trailingslashit( $link );
|
||||
}
|
||||
|
||||
return $link;
|
||||
}
|
||||
add_filter( 'author_link', 'gdk_custom_author_link', 10, 2 );
|
||||
function gdk_custom_author_link($link, $author_id)
|
||||
{
|
||||
global $wp_rewrite;
|
||||
$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);
|
||||
} else {
|
||||
$link = str_replace('%author%', gdk_text_encrypt($author_id, 'E', AUTH_KEY), $link);
|
||||
$link = home_url() . user_trailingslashit($link);
|
||||
}
|
||||
|
||||
// wp-rest 可能暴露用户名
|
||||
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 );
|
||||
return $link;
|
||||
}
|
||||
add_filter('author_link', 'gdk_custom_author_link', 10, 2);
|
||||
|
||||
// wp-rest 可能暴露用户名
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
//记录登陆失败发邮件
|
||||
add_action( 'wp_authenticate', 'log_login', 10, 2 );
|
||||
function log_login( $username, $password ) {
|
||||
add_action('wp_authenticate', 'log_login', 10, 2);
|
||||
function log_login($username, $password)
|
||||
{
|
||||
|
||||
if ( ! empty( $username ) && ! empty( $password ) ) {
|
||||
if (!empty($username) && !empty($password)) {
|
||||
|
||||
$check = wp_authenticate_username_password( NULL, $username, $password );
|
||||
if ( is_wp_error( $check ) ) {
|
||||
$check = wp_authenticate_username_password(null, $username, $password);
|
||||
if (is_wp_error($check)) {
|
||||
|
||||
$ua = getBrowser();
|
||||
$ua = getBrowser();
|
||||
$agent = $ua['name'] . " " . $ua['version'];
|
||||
|
||||
$referrer = ( isset( $_SERVER['HTTP_REFERER'] ) ) ? $_SERVER['HTTP_REFERER'] : $_SERVER['PHP_SELF'];
|
||||
if ( strstr( $referrer, 'wp-login' ) ) {
|
||||
$referrer = (isset($_SERVER['HTTP_REFERER'])) ? $_SERVER['HTTP_REFERER'] : $_SERVER['PHP_SELF'];
|
||||
if (strstr($referrer, 'wp-login')) {
|
||||
$ref = 'wp-login.php';
|
||||
}
|
||||
|
||||
if ( strstr( $referrer, 'wp-admin' ) ) {
|
||||
if (strstr($referrer, 'wp-admin')) {
|
||||
$ref = 'wp-admin/';
|
||||
}
|
||||
|
||||
$contact_errors = false;
|
||||
// get the posted data
|
||||
$name = "WordPress " . get_bloginfo( 'name' );
|
||||
$email_address = get_bloginfo('admin_email' );
|
||||
$name = "WordPress " . get_bloginfo('name');
|
||||
$email_address = get_bloginfo('admin_email');
|
||||
|
||||
// write the email content
|
||||
$header = "MIME-Version: 1.0\n";
|
||||
|
@ -318,10 +355,10 @@ function log_login( $username, $password ) {
|
|||
|
||||
$subject = "Failed login attempt - " . $name;
|
||||
$subject = "=?utf-8?B?" . base64_encode($subject) . "?=";
|
||||
$to = $email_address;
|
||||
if ( ! empty( $to ) ) {
|
||||
$to = $email_address;
|
||||
if (!empty($to)) {
|
||||
// send the email using wp_mail()
|
||||
if ( ! wp_mail( $to, $subject, $message, $header ) ) {
|
||||
if (!wp_mail($to, $subject, $message, $header)) {
|
||||
$contact_errors = true;
|
||||
}
|
||||
}
|
||||
|
@ -331,17 +368,23 @@ function log_login( $username, $password ) {
|
|||
}
|
||||
|
||||
//ban yonghu
|
||||
function gdk_edit_user_profile( $user ) {
|
||||
if ( ! current_user_can( 'edit_users' ) ) return;
|
||||
if ( get_current_user_id() == $user->ID ) return;
|
||||
?>
|
||||
function gdk_edit_user_profile($user)
|
||||
{
|
||||
if (!current_user_can('edit_users')) {
|
||||
return;
|
||||
}
|
||||
|
||||
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">
|
||||
<input name="gdk_ban" type="checkbox" id="gdk_ban" <?php checked(gdk_is_user_banned($user->ID), true) ?> value="1">
|
||||
封禁此用户</label>
|
||||
</td>
|
||||
</tr>
|
||||
|
@ -349,47 +392,56 @@ function gdk_edit_user_profile( $user ) {
|
|||
<?php
|
||||
}
|
||||
|
||||
function gdk_edit_user_profile_update($user_id)
|
||||
{
|
||||
if (!current_user_can('edit_users')) {
|
||||
return;
|
||||
}
|
||||
|
||||
function gdk_edit_user_profile_update( $user_id ) {
|
||||
if ( ! current_user_can( 'edit_users' ) ) return;
|
||||
if ( get_current_user_id() == $user_id ) return;
|
||||
if ( empty( $_POST['gdk_ban'] ) ) {
|
||||
gdk_unban_user( $user_id );
|
||||
} else {
|
||||
gdk_ban_user( $user_id );
|
||||
}
|
||||
if (get_current_user_id() == $user_id) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (empty($_POST['gdk_ban'])) {
|
||||
gdk_unban_user($user_id);
|
||||
} else {
|
||||
gdk_ban_user($user_id);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function gdk_ban_user( $user_id ) {
|
||||
if ( ! gdk_is_user_banned( $user_id ) ) {
|
||||
update_user_option( $user_id, 'gdk_banned', TRUE, FALSE );
|
||||
}
|
||||
function gdk_ban_user($user_id)
|
||||
{
|
||||
if (!gdk_is_user_banned($user_id)) {
|
||||
update_user_option($user_id, 'gdk_banned', true, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function gdk_unban_user( $user_id ) {
|
||||
if ( gdk_is_user_banned( $user_id ) ) {
|
||||
update_user_option( $user_id, 'gdk_banned', FALSE, FALSE );
|
||||
}
|
||||
function gdk_unban_user($user_id)
|
||||
{
|
||||
if (gdk_is_user_banned($user_id)) {
|
||||
update_user_option($user_id, 'gdk_banned', false, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function gdk_is_user_banned( $user_id ) {
|
||||
return get_user_option( 'gdk_banned', $user_id );
|
||||
function gdk_is_user_banned($user_id)
|
||||
{
|
||||
return get_user_option('gdk_banned', $user_id);
|
||||
}
|
||||
|
||||
function gdk_authenticate_user( $user, $password ) {
|
||||
if ( is_wp_error( $user ) ) return $user;
|
||||
if ( get_user_option( 'gdk_banned', $user->ID, FALSE ) ) {
|
||||
return new WP_Error(
|
||||
'gdk_banned','<strong>ERROR</strong>: 此账号已被封禁.'
|
||||
);
|
||||
}
|
||||
return $user;
|
||||
function gdk_authenticate_user($user, $password)
|
||||
{
|
||||
if (is_wp_error($user)) {
|
||||
return $user;
|
||||
}
|
||||
|
||||
if (get_user_option('gdk_banned', $user->ID, false)) {
|
||||
return new WP_Error(
|
||||
'gdk_banned', '<strong>ERROR</strong>: 此账号已被封禁.'
|
||||
);
|
||||
}
|
||||
return $user;
|
||||
}
|
||||
|
||||
|
||||
add_action( 'edit_user_profile', 'gdk_edit_user_profile' );
|
||||
add_action( 'edit_user_profile_update', 'gdk_edit_user_profile_update' );
|
||||
add_filter( 'wp_authenticate_user', 'gdk_authenticate_user', 10, 2 );
|
||||
add_action('edit_user_profile', 'gdk_edit_user_profile');
|
||||
add_action('edit_user_profile_update', 'gdk_edit_user_profile_update');
|
||||
add_filter('wp_authenticate_user', 'gdk_authenticate_user', 10, 2);
|
|
@ -1,33 +1,33 @@
|
|||
<?php
|
||||
|
||||
|
||||
//加载网站地图xml
|
||||
if(gdk_option('gdk_sitemap_xml')){
|
||||
include(GDK_ROOT_PATH.'public/sitemap-xml.php');
|
||||
include(GDK_ROOT_PATH.'public/sitemap.php');
|
||||
if (gdk_option('gdk_sitemap_xml')) {
|
||||
include GDK_ROOT_PATH . 'public/sitemap-xml.php';
|
||||
include GDK_ROOT_PATH . 'public/sitemap.php';
|
||||
}
|
||||
|
||||
// 屏蔽蜘蛛爬取作者页面
|
||||
if(gdk_option('gdk_no_author_page')) {
|
||||
function gdk_no_author_page() {
|
||||
if (is_author()) {
|
||||
wp_no_robots();
|
||||
}
|
||||
}
|
||||
add_action('wp_head', 'gdk_no_author_page');
|
||||
if (gdk_option('gdk_no_author_page')) {
|
||||
function gdk_no_author_page()
|
||||
{
|
||||
if (is_author()) {
|
||||
wp_no_robots();
|
||||
}
|
||||
}
|
||||
add_action('wp_head', 'gdk_no_author_page');
|
||||
}
|
||||
|
||||
|
||||
//robots.txt优化功能
|
||||
if(gdk_option('gdk_robots')) {
|
||||
add_filter('robots_txt', 'gdk_robots_txt', 10, 2);
|
||||
function gdk_robots_txt($robotext) {
|
||||
if(gdk_option('gdk_sitemap_xml')) {
|
||||
$sitemap = 'Sitemap: ' . home_url('/sitemap.xml');
|
||||
} else {
|
||||
$sitemap = '';
|
||||
}
|
||||
$robotext = "User-agent: *
|
||||
if (gdk_option('gdk_robots')) {
|
||||
add_filter('robots_txt', 'gdk_robots_txt', 10, 2);
|
||||
function gdk_robots_txt($robotext)
|
||||
{
|
||||
if (gdk_option('gdk_sitemap_xml')) {
|
||||
$sitemap = 'Sitemap: ' . home_url('/sitemap.xml');
|
||||
} else {
|
||||
$sitemap = '';
|
||||
}
|
||||
$robotext = "User-agent: *
|
||||
Disallow: /wp-admin/
|
||||
Disallow: /wp-content/plugins/
|
||||
Disallow: /wp-includes/
|
||||
|
@ -37,69 +37,78 @@ Disallow: /*/feed
|
|||
Disallow: /attachment/
|
||||
Disallow: /wp-content/themes/
|
||||
{$sitemap}";
|
||||
return $robotext;
|
||||
}
|
||||
return $robotext;
|
||||
}
|
||||
}
|
||||
|
||||
//文章自动内链
|
||||
if(gdk_option('gdk_tag_link')) {
|
||||
function gdk_tag_link($content) {
|
||||
$post_tags = get_the_tags();
|
||||
if ($post_tags) {
|
||||
foreach ($post_tags as $tag) {
|
||||
$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);
|
||||
}
|
||||
}
|
||||
return $content;
|
||||
}
|
||||
add_filter('the_content', 'gdk_tag_link', 1);
|
||||
if (gdk_option('gdk_tag_link')) {
|
||||
function gdk_tag_link($content)
|
||||
{
|
||||
$post_tags = get_the_tags();
|
||||
if ($post_tags) {
|
||||
foreach ($post_tags as $tag) {
|
||||
$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);
|
||||
}
|
||||
}
|
||||
return $content;
|
||||
}
|
||||
add_filter('the_content', 'gdk_tag_link', 1);
|
||||
}
|
||||
|
||||
// 自动添加nofloow
|
||||
if(gdk_option('gdk_nofollow')) {
|
||||
add_filter('the_content', 'gdk_nofollow');
|
||||
add_filter('the_excerpt', 'gdk_nofollow');
|
||||
function gdk_nofollow($content) {
|
||||
return preg_replace_callback('/<a[^>]+/', 'gdk_nofollow_callback', $content);
|
||||
}
|
||||
function gdk_nofollow_callback($matches) {
|
||||
$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)) {
|
||||
$link = preg_replace('/rel=\S(?!nofollow)\S*/i', 'rel="nofollow"', $link);
|
||||
}
|
||||
return $link;
|
||||
}
|
||||
if (gdk_option('gdk_nofollow')) {
|
||||
add_filter('the_content', 'gdk_nofollow');
|
||||
add_filter('the_excerpt', 'gdk_nofollow');
|
||||
function gdk_nofollow($content)
|
||||
{
|
||||
return preg_replace_callback('/<a[^>]+/', 'gdk_nofollow_callback', $content);
|
||||
}
|
||||
function gdk_nofollow_callback($matches)
|
||||
{
|
||||
$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)) {
|
||||
$link = preg_replace('/rel=\S(?!nofollow)\S*/i', 'rel="nofollow"', $link);
|
||||
}
|
||||
return $link;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//百度主动推送
|
||||
if (gdk_option('gdk_baidu_push')) {
|
||||
function gdk_baidu_submit($post_ID) {
|
||||
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) return;
|
||||
$url = get_permalink($post_ID);
|
||||
$api = $api = 'http://data.zz.baidu.com/urls?site='.$bd_submit_site.'&token='.$bd_submit_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) {
|
||||
return;
|
||||
}
|
||||
|
||||
$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,
|
||||
'headers' => 'Content-Type: text/plain'
|
||||
$result = $request->request($api, array(
|
||||
'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) && $result['response']['code'] == '200') {
|
||||
error_log('baidu_submit_result:' . $result['body']);
|
||||
$result = json_decode($result['body'], true);
|
||||
}
|
||||
if (array_key_exists('success', $result)) {
|
||||
|
@ -113,13 +122,14 @@ if (gdk_option('gdk_baidu_push')) {
|
|||
}
|
||||
|
||||
//百度自动推送
|
||||
function gdk_baidu_auto_push() {
|
||||
echo '<script>
|
||||
function gdk_baidu_auto_push()
|
||||
{
|
||||
echo '<script>
|
||||
(function(){
|
||||
var bp = document.createElement(\'script\');
|
||||
var curProtocol = window.location.protocol.split(\':\')[0];
|
||||
if (curProtocol === \'https\') {
|
||||
bp.src = \'https://zz.bdstatic.com/linksubmit/push.js\';
|
||||
bp.src = \'https://zz.bdstatic.com/linksubmit/push.js\';
|
||||
}
|
||||
else {
|
||||
bp.src = \'http://push.zhanzhang.baidu.com/push.js\';
|
||||
|
@ -130,150 +140,162 @@ function gdk_baidu_auto_push() {
|
|||
</script>';
|
||||
}
|
||||
|
||||
|
||||
if(gdk_option('gdk_seo_img')) {
|
||||
//给文章图片自动添加alt和title信息
|
||||
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);
|
||||
return $content;
|
||||
}
|
||||
add_filter('the_content', 'gdk_imagesalt');
|
||||
function gdk_image_alt_tag($content) {
|
||||
global $post;
|
||||
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]);
|
||||
$content = str_replace($images[0][$index], $new_img, $content);
|
||||
}
|
||||
}
|
||||
return $content;
|
||||
}
|
||||
add_filter('the_content', 'gdk_image_alt_tag', 99999);
|
||||
if (gdk_option('gdk_seo_img')) {
|
||||
//给文章图片自动添加alt和title信息
|
||||
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);
|
||||
return $content;
|
||||
}
|
||||
add_filter('the_content', 'gdk_imagesalt');
|
||||
function gdk_image_alt_tag($content)
|
||||
{
|
||||
global $post;
|
||||
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]);
|
||||
$content = str_replace($images[0][$index], $new_img, $content);
|
||||
}
|
||||
}
|
||||
return $content;
|
||||
}
|
||||
add_filter('the_content', 'gdk_image_alt_tag', 99999);
|
||||
}
|
||||
|
||||
//关键字
|
||||
function gdk_keywords() {
|
||||
global $s, $post;
|
||||
$keywords = '';
|
||||
if (is_single()) {
|
||||
if (get_the_tags($post->ID)) {
|
||||
foreach (get_the_tags($post->ID) as $tag) $keywords.= $tag->name . ', ';
|
||||
}
|
||||
foreach (get_the_category($post->ID) as $category) $keywords.= $category->cat_name . ', ';
|
||||
$keywords = substr_replace($keywords, '', -2);
|
||||
} elseif (is_home()||is_front_page()) {
|
||||
$keywords = gdk_option('gdk_keywords');
|
||||
} elseif (is_tag()) {
|
||||
if(in_string(tag_description(),'@@')) {
|
||||
$keywords = gdk_term_meta('tag','keyword');
|
||||
} else {
|
||||
$keywords = single_tag_title('', false);
|
||||
}
|
||||
} elseif (is_category()) {
|
||||
if(in_string(category_description(),'@@')) {
|
||||
$keywords = gdk_term_meta('cat','keyword');
|
||||
} else {
|
||||
$keywords = single_cat_title('', false);
|
||||
}
|
||||
} elseif (is_search()) {
|
||||
$keywords = esc_html($s, 1);
|
||||
} else {
|
||||
$keywords = trim(wp_title('', false));
|
||||
}
|
||||
if ($keywords) {
|
||||
echo "<meta name=\"keywords\" content=\"$keywords\">\n";
|
||||
}
|
||||
function gdk_keywords()
|
||||
{
|
||||
global $s, $post;
|
||||
$keywords = '';
|
||||
if (is_single()) {
|
||||
if (get_the_tags($post->ID)) {
|
||||
foreach (get_the_tags($post->ID) as $tag) {
|
||||
$keywords .= $tag->name . ', ';
|
||||
}
|
||||
|
||||
}
|
||||
foreach (get_the_category($post->ID) as $category) {
|
||||
$keywords .= $category->cat_name . ', ';
|
||||
}
|
||||
|
||||
$keywords = substr_replace($keywords, '', -2);
|
||||
} elseif (is_home() || is_front_page()) {
|
||||
$keywords = gdk_option('gdk_keywords');
|
||||
} elseif (is_tag()) {
|
||||
if (in_string(tag_description(), '@@')) {
|
||||
$keywords = gdk_term_meta('tag', 'keyword');
|
||||
} else {
|
||||
$keywords = single_tag_title('', false);
|
||||
}
|
||||
} elseif (is_category()) {
|
||||
if (in_string(category_description(), '@@')) {
|
||||
$keywords = gdk_term_meta('cat', 'keyword');
|
||||
} else {
|
||||
$keywords = single_cat_title('', false);
|
||||
}
|
||||
} elseif (is_search()) {
|
||||
$keywords = esc_html($s, 1);
|
||||
} else {
|
||||
$keywords = trim(wp_title('', false));
|
||||
}
|
||||
if ($keywords) {
|
||||
echo "<meta name=\"keywords\" content=\"$keywords\">\n";
|
||||
}
|
||||
}
|
||||
add_action('wp_head', 'gdk_keywords');
|
||||
|
||||
//网站描述
|
||||
function gdk_description() {
|
||||
global $s, $post;
|
||||
$description = '';
|
||||
$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(
|
||||
"\r\n",
|
||||
"\r",
|
||||
"\n",
|
||||
" ",
|
||||
" "
|
||||
) , " ", str_replace("\"", "'", strip_tags($text))));
|
||||
if (!($description)) $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') . "'";
|
||||
} else {
|
||||
$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')));
|
||||
} else {
|
||||
$description = $blog_name . "'" . trim(strip_tags(category_description()));
|
||||
}
|
||||
} elseif (is_archive()) {
|
||||
$description = $blog_name . "'" . trim(wp_title('', false)) . "'";
|
||||
} elseif (is_search()) {
|
||||
$description = $blog_name . ": '" . esc_html($s, 1) . "' 的搜索結果";
|
||||
} else {
|
||||
$description = $blog_name . "'" . trim(wp_title('', false)) . "'";
|
||||
}
|
||||
$description = mb_substr($description, 0, 220, 'utf-8');
|
||||
echo "<meta name=\"description\" content=\"$description\">\n";
|
||||
function gdk_description()
|
||||
{
|
||||
global $s, $post;
|
||||
$description = '';
|
||||
$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(
|
||||
"\r\n",
|
||||
"\r",
|
||||
"\n",
|
||||
" ",
|
||||
" ",
|
||||
), " ", str_replace("\"", "'", strip_tags($text))));
|
||||
if (!($description)) {
|
||||
$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') . "'";
|
||||
} else {
|
||||
$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')));
|
||||
} else {
|
||||
$description = $blog_name . "'" . trim(strip_tags(category_description()));
|
||||
}
|
||||
} elseif (is_archive()) {
|
||||
$description = $blog_name . "'" . trim(wp_title('', false)) . "'";
|
||||
} elseif (is_search()) {
|
||||
$description = $blog_name . ": '" . esc_html($s, 1) . "' 的搜索結果";
|
||||
} else {
|
||||
$description = $blog_name . "'" . trim(wp_title('', false)) . "'";
|
||||
}
|
||||
$description = mb_substr($description, 0, 220, 'utf-8');
|
||||
echo "<meta name=\"description\" content=\"$description\">\n";
|
||||
}
|
||||
add_action('wp_head', 'gdk_description');
|
||||
|
||||
//添加Open Graph Meta
|
||||
function meta_og() {
|
||||
global $post;
|
||||
if ( is_single() ) {
|
||||
if( has_post_thumbnail( $post->ID ) ) {
|
||||
$img_src = gdk_thumbnail_src();
|
||||
}
|
||||
$excerpt = strip_tags( $post->post_content );
|
||||
$excerpt_more = '';
|
||||
if ( strlen($excerpt ) > 155) {
|
||||
$excerpt = substr( $excerpt,0,155 );
|
||||
$excerpt_more = ' ...';
|
||||
}
|
||||
$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;
|
||||
?>
|
||||
function meta_og()
|
||||
{
|
||||
global $post;
|
||||
if (is_single()) {
|
||||
if (has_post_thumbnail($post->ID)) {
|
||||
$img_src = gdk_thumbnail_src();
|
||||
}
|
||||
$excerpt = strip_tags($post->post_content);
|
||||
$excerpt_more = '';
|
||||
if (strlen($excerpt) > 155) {
|
||||
$excerpt = substr($excerpt, 0, 155);
|
||||
$excerpt_more = ' ...';
|
||||
}
|
||||
$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:site_name" content="<?php echo get_bloginfo('name'); ?>">
|
||||
<meta property="og:image" content="<?php $img_src; ?>">
|
||||
<?php
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
add_action('wp_head', 'meta_og', 5);
|
||||
|
||||
|
||||
|
||||
//评论分页的seo处理
|
||||
function gdk_canonical(){
|
||||
function gdk_canonical()
|
||||
{
|
||||
global $post;
|
||||
if (get_query_var('paged') > 1) {
|
||||
echo "\n";
|
||||
|
|
|
@ -1,20 +1,12 @@
|
|||
<?php
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//百度收录提示
|
||||
if (gdk_option('gdk_baidurecord_b') && function_exists('curl_init')) {
|
||||
function baidu_check($url, $post_id){
|
||||
function 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;
|
||||
$url = 'http://www.baidu.com/s?wd=' . $url;
|
||||
$curl = curl_init();
|
||||
curl_setopt($curl, CURLOPT_URL, $url);
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
|
||||
|
@ -30,7 +22,8 @@ if (gdk_option('gdk_baidurecord_b') && function_exists('curl_init')) {
|
|||
return 1;
|
||||
}
|
||||
}
|
||||
function baidu_record(){
|
||||
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) {
|
||||
|
@ -41,22 +34,24 @@ if (gdk_option('gdk_baidurecord_b') && function_exists('curl_init')) {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//百度主动推送
|
||||
if (gdk_option('gdk_sitemap_api')) {
|
||||
function Git_Baidu_Submit($post_ID) {
|
||||
if (get_post_meta($post_ID, 'gdk_baidu_submit', true) == 1) return;
|
||||
$url = get_permalink($post_ID);
|
||||
$api = gdk_option('gdk_sitemap_api');
|
||||
function Git_Baidu_Submit($post_ID)
|
||||
{
|
||||
if (get_post_meta($post_ID, 'gdk_baidu_submit', true) == 1) {
|
||||
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,
|
||||
'headers' => 'Content-Type: text/plain'
|
||||
$result = $request->request($api, array(
|
||||
'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) && $result['response']['code'] == '200') {
|
||||
error_log('baidu_submit_result:' . $result['body']);
|
||||
$result = json_decode($result['body'], true);
|
||||
}
|
||||
if (array_key_exists('success', $result)) {
|
||||
|
@ -67,51 +62,54 @@ if (gdk_option('gdk_sitemap_api')) {
|
|||
}
|
||||
|
||||
//强制微信登录
|
||||
function force_weauth_login_url( $login_url, $redirect, $force_reauth ){
|
||||
function force_weauth_login_url($login_url, $redirect, $force_reauth)
|
||||
{
|
||||
$login_url = get_permalink(gdk_page_id('weauth'));
|
||||
if ( ! empty( $redirect ) ) {
|
||||
$login_url = add_query_arg( 'redirect_to', urlencode( $redirect ), $login_url );
|
||||
if (!empty($redirect)) {
|
||||
$login_url = add_query_arg('redirect_to', urlencode($redirect), $login_url);
|
||||
}
|
||||
if ( $force_reauth ) {
|
||||
$login_url = add_query_arg( 'reauth', '1', $login_url );
|
||||
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')){
|
||||
add_filter( 'login_url', 'force_weauth_login_url', 10, 3 );
|
||||
}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')){
|
||||
add_action('login_form', 'weixin_login_button');
|
||||
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')) {
|
||||
add_action('login_form', 'weixin_login_button');
|
||||
}
|
||||
|
||||
//评论微信推送
|
||||
if (gdk_option('gdk_Server') && !is_admin()) {
|
||||
function sc_send($comment_id) {
|
||||
$text = '网站上有新的评论,请及时查看'; //微信推送信息标题
|
||||
function sc_send($comment_id)
|
||||
{
|
||||
$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) . '
|
||||
'; //微信推送内容正文
|
||||
$key = gdk_option('gdk_Server_key');
|
||||
$key = gdk_option('gdk_Server_key');
|
||||
$postdata = http_build_query(array(
|
||||
'text' => $text,
|
||||
'desp' => $desp
|
||||
'desp' => $desp,
|
||||
));
|
||||
$opts = array(
|
||||
'http' => array(
|
||||
'method' => 'POST',
|
||||
'header' => 'Content-type: application/x-www-form-urlencoded',
|
||||
'content' => $postdata
|
||||
)
|
||||
'method' => 'POST',
|
||||
'header' => 'Content-type: application/x-www-form-urlencoded',
|
||||
'content' => $postdata,
|
||||
),
|
||||
);
|
||||
$context = stream_context_create($opts);
|
||||
$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);
|
||||
|
@ -119,7 +117,8 @@ if (gdk_option('gdk_Server') && !is_admin()) {
|
|||
|
||||
//增加B站视频
|
||||
wp_embed_unregister_handler('bili');
|
||||
function wp_bili($matches, $attr, $url, $rawattr) {
|
||||
function wp_bili($matches, $attr, $url, $rawattr)
|
||||
{
|
||||
if (gdk_is_mobile()) {
|
||||
$height = 200;
|
||||
} else {
|
||||
|
@ -131,15 +130,16 @@ function wp_bili($matches, $attr, $url, $rawattr) {
|
|||
wp_embed_register_handler('bili_iframe', '#https://www.bilibili.com/video/av(.*?)/#i', 'wp_bili');
|
||||
|
||||
//bing美图自定义登录页面背景
|
||||
function custom_login_head() {
|
||||
function 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);
|
||||
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);
|
||||
}
|
||||
}
|
||||
if (defined('UM_DIR')) {
|
||||
|
@ -150,7 +150,8 @@ function custom_login_head() {
|
|||
add_action('login_head', 'custom_login_head');
|
||||
|
||||
// add youku using iframe
|
||||
function wp_iframe_handler_youku($matches, $attr, $url, $rawattr) {
|
||||
function wp_iframe_handler_youku($matches, $attr, $url, $rawattr)
|
||||
{
|
||||
if (gdk_is_mobile()) {
|
||||
$height = 200;
|
||||
} else {
|
||||
|
@ -163,63 +164,68 @@ wp_embed_register_handler('youku_iframe', '#http://v.youku.com/v_show/id_(.*?).h
|
|||
wp_embed_unregister_handler('youku');
|
||||
|
||||
////////////////weauth//////////////
|
||||
function weauth_oauth_redirect(){
|
||||
wp_redirect( home_url());
|
||||
function weauth_oauth_redirect()
|
||||
{
|
||||
wp_redirect(home_url());
|
||||
exit;
|
||||
}
|
||||
|
||||
function get_weauth_token(){
|
||||
$sk = date("YmdHis") . mt_rand(10, 99);
|
||||
set_transient($sk, 1, 60*6);
|
||||
$key = $_SERVER['HTTP_HOST'].'@'.$sk;
|
||||
return $key;
|
||||
function get_weauth_token()
|
||||
{
|
||||
$sk = date("YmdHis") . mt_rand(10, 99);
|
||||
set_transient($sk, 1, 60 * 6);
|
||||
$key = $_SERVER['HTTP_HOST'] . '@' . $sk;
|
||||
return $key;
|
||||
}
|
||||
|
||||
function get_weauth_qr(){
|
||||
$qr64 = [];
|
||||
$qr64['key'] = get_weauth_token();
|
||||
$qr64['qrcode'] = json_decode(file_get_contents('https://wa.isdot.net/qrcode?str='.$qr64['key']),true)['qrcode'];
|
||||
return $qr64;
|
||||
function get_weauth_qr()
|
||||
{
|
||||
$qr64 = [];
|
||||
$qr64['key'] = get_weauth_token();
|
||||
$qr64['qrcode'] = json_decode(file_get_contents('https://wa.isdot.net/qrcode?str=' . $qr64['key']), true)['qrcode'];
|
||||
return $qr64;
|
||||
}
|
||||
|
||||
function weauth_rewrite_rules($wp_rewrite){
|
||||
|
||||
function weauth_rewrite_rules($wp_rewrite)
|
||||
{
|
||||
if ($ps = get_option('permalink_structure')) {
|
||||
$new_rules['^weauth'] = 'index.php?user=$matches[1]&sk=$matches[2]';
|
||||
$wp_rewrite->rules = $new_rules + $wp_rewrite->rules;
|
||||
$wp_rewrite->rules = $new_rules + $wp_rewrite->rules;
|
||||
}
|
||||
}
|
||||
add_action('generate_rewrite_rules', 'weauth_rewrite_rules');
|
||||
|
||||
function weauth_oauth(){
|
||||
function weauth_oauth()
|
||||
{
|
||||
$weauth_user = $_GET['user'];
|
||||
$weauth_sk = esc_attr($_GET['sk']);
|
||||
$weauth_res = get_transient($weauth_sk);
|
||||
$weauth_sk = esc_attr($_GET['sk']);
|
||||
$weauth_res = get_transient($weauth_sk);
|
||||
if (empty($weauth_res)) {
|
||||
return;
|
||||
}
|
||||
$weauth_user = stripslashes($weauth_user);
|
||||
$weauth_user = json_decode($weauth_user, true);
|
||||
$nickname = $weauth_user['nickName'];
|
||||
$wxavatar = $weauth_user['avatarUrl'];
|
||||
$openid = $weauth_user['openid'];
|
||||
$login_name = 'wx_' . wp_create_nonce($openid);
|
||||
$nickname = $weauth_user['nickName'];
|
||||
$wxavatar = $weauth_user['avatarUrl'];
|
||||
$openid = $weauth_user['openid'];
|
||||
$login_name = 'wx_' . wp_create_nonce($openid);
|
||||
if (is_user_logged_in()) {
|
||||
$user_id = get_current_user_id();
|
||||
update_user_meta($user_id, 'wx_openid', $openid);
|
||||
update_user_meta($user_id, 'simple_local_avatar', $wxavatar);
|
||||
} else {
|
||||
$weauth_user = get_users(array(
|
||||
'meta_key ' => 'wx_openid',
|
||||
'meta_value' => $openid
|
||||
)
|
||||
);
|
||||
'meta_key ' => 'wx_openid',
|
||||
'meta_value' => $openid,
|
||||
)
|
||||
);
|
||||
if (is_wp_error($weauth_user) || !count($weauth_user)) {
|
||||
$random_password = wp_generate_password(12, false);
|
||||
$userdata = array(
|
||||
'user_login' => $login_name,
|
||||
'display_name' => $nickname,
|
||||
'user_pass' => $random_password,
|
||||
'nickname' => $nickname
|
||||
$userdata = array(
|
||||
'user_login' => $login_name,
|
||||
'display_name' => $nickname,
|
||||
'user_pass' => $random_password,
|
||||
'nickname' => $nickname,
|
||||
);
|
||||
$user_id = wp_insert_user($userdata);
|
||||
update_user_meta($user_id, 'wx_openid', $openid);
|
||||
|
@ -228,25 +234,27 @@ function weauth_oauth(){
|
|||
$user_id = $weauth_user[0]->ID;
|
||||
}
|
||||
}
|
||||
set_transient($weauth_sk . 'ok', $user_id, 60);//用于登录的随机数,有效期为一分钟
|
||||
set_transient($weauth_sk . 'ok', $user_id, 60); //用于登录的随机数,有效期为一分钟
|
||||
weauth_oauth_redirect();
|
||||
}
|
||||
//初始化
|
||||
function weauth_oauth_init(){
|
||||
if (isset($_GET['user']) && isset($_GET['sk'])){
|
||||
function weauth_oauth_init()
|
||||
{
|
||||
if (isset($_GET['user']) && isset($_GET['sk'])) {
|
||||
weauth_oauth();
|
||||
}
|
||||
}
|
||||
add_action('init','weauth_oauth_init');
|
||||
add_action('init', 'weauth_oauth_init');
|
||||
|
||||
//GET自动登录
|
||||
function gdk_weauth_oauth_login(){
|
||||
function gdk_weauth_oauth_login()
|
||||
{
|
||||
$key = isset($_GET['spam']) ? $_GET['spam'] : false;
|
||||
if ($key) {
|
||||
$user_id = get_transient($key.'ok');
|
||||
$user_id = get_transient($key . 'ok');
|
||||
if ($user_id != 0) {
|
||||
wp_set_auth_cookie($user_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
add_action('init', 'gdk_weauth_oauth_login');
|
||||
add_action('init', 'gdk_weauth_oauth_login');
|
||||
|
|
|
@ -1,55 +1,59 @@
|
|||
<?php
|
||||
|
||||
//短代码集合
|
||||
//短代码集合
|
||||
|
||||
//小工具运行短代码
|
||||
add_filter( 'widget_text', 'shortcode_unautop' );
|
||||
add_filter( 'widget_text', 'do_shortcode' );
|
||||
add_filter('widget_text', 'shortcode_unautop');
|
||||
add_filter('widget_text', 'do_shortcode');
|
||||
|
||||
//积分充值短代码
|
||||
function gdk_potin() {
|
||||
function gdk_potin()
|
||||
{
|
||||
return buy_points();
|
||||
}
|
||||
add_shortcode('gdk_potin_btn', 'gdk_potin');
|
||||
|
||||
|
||||
//
|
||||
function gdk_login_fancybox() {
|
||||
function gdk_login_fancybox()
|
||||
{
|
||||
return weixin_login_btn();
|
||||
}
|
||||
add_shortcode('gdk_login_btn', 'gdk_login_fancybox');
|
||||
|
||||
|
||||
//添加钮Download
|
||||
function gdk_DownloadUrl($atts, $content = null) {
|
||||
function gdk_DownloadUrl($atts, $content = null)
|
||||
{
|
||||
extract(shortcode_atts(array(
|
||||
"href" => 'http://'
|
||||
) , $atts));
|
||||
"href" => 'http://',
|
||||
), $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) {
|
||||
function gdk_GithubUrl($atts, $content = null)
|
||||
{
|
||||
extract(shortcode_atts(array(
|
||||
"href" => 'http://'
|
||||
) , $atts));
|
||||
"href" => 'http://',
|
||||
), $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) {
|
||||
function gdk_DemoUrl($atts, $content = null)
|
||||
{
|
||||
extract(shortcode_atts(array(
|
||||
"href" => 'http://'
|
||||
) , $atts));
|
||||
"href" => 'http://',
|
||||
), $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) {
|
||||
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;
|
||||
"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;
|
||||
|
@ -58,7 +62,7 @@ function gdk_reply_to_read($atts, $content = null) {
|
|||
if ($email == $admin_email) {
|
||||
return $content;
|
||||
}
|
||||
} else if (isset($_COOKIE['comment_author_email_' . COOKIEHASH])) {
|
||||
} elseif (isset($_COOKIE['comment_author_email_' . COOKIEHASH])) {
|
||||
$email = str_replace('%40', '@', $_COOKIE['comment_author_email_' . COOKIEHASH]);
|
||||
} else {
|
||||
return $notice;
|
||||
|
@ -68,7 +72,7 @@ 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 {
|
||||
|
@ -78,45 +82,52 @@ function gdk_reply_to_read($atts, $content = null) {
|
|||
add_shortcode('reply', 'gdk_reply_to_read');
|
||||
|
||||
//绿色提醒框
|
||||
function gdk_toz($atts, $content = null) {
|
||||
function gdk_toz($atts, $content = null)
|
||||
{
|
||||
return '<div class="alert success">' . $content . '</div>';
|
||||
}
|
||||
add_shortcode('v_notice', 'gdk_toz');
|
||||
//红色提醒框
|
||||
function gdk_toa($atts, $content = null) {
|
||||
function gdk_toa($atts, $content = null)
|
||||
{
|
||||
return '<div class="alert error">' . $content . '</div>';
|
||||
}
|
||||
add_shortcode('v_error', 'gdk_toa');
|
||||
//黄色提醒框
|
||||
function gdk_toc($atts, $content = null) {
|
||||
function gdk_toc($atts, $content = null)
|
||||
{
|
||||
return '<div class="alert warning">' . $content . '</div>';
|
||||
}
|
||||
add_shortcode('v_warn', 'gdk_toc');
|
||||
|
||||
//蓝色提醒框
|
||||
function gdk_tod($atts, $content = null) {
|
||||
function gdk_tod($atts, $content = null)
|
||||
{
|
||||
return '<div class="alert primary">' . $content . '</div>';
|
||||
}
|
||||
add_shortcode('v_blue', 'gdk_tod');
|
||||
//蓝边文本框
|
||||
function gdk_toe($atts, $content = null) {
|
||||
function gdk_toe($atts, $content = null)
|
||||
{
|
||||
return '<div class="alert">' . $content . '</div>';
|
||||
}
|
||||
add_shortcode('v_tips', 'gdk_toe');
|
||||
|
||||
//灵魂按钮
|
||||
function gdk_tom($atts, $content = null) {
|
||||
function gdk_tom($atts, $content = null)
|
||||
{
|
||||
extract(shortcode_atts(array(
|
||||
"href" => 'http://'
|
||||
) , $atts));
|
||||
"href" => 'http://',
|
||||
), $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) {
|
||||
function gdk_too($atts, $content = null)
|
||||
{
|
||||
extract(shortcode_atts(array(
|
||||
"play" => '0'
|
||||
) , $atts));
|
||||
"play" => '0',
|
||||
), $atts));
|
||||
if ($play == 0) {
|
||||
return '<video style="width:100%;" src="' . $content . '" controls preload >您的浏览器不支持HTML5的 video 标签,无法为您播放!</video>';
|
||||
}
|
||||
|
@ -126,10 +137,11 @@ function gdk_too($atts, $content = null) {
|
|||
}
|
||||
add_shortcode('video', 'gdk_too');
|
||||
//添加音频按钮
|
||||
function gdk_tkk($atts, $content = null) {
|
||||
function gdk_tkk($atts, $content = null)
|
||||
{
|
||||
extract(shortcode_atts(array(
|
||||
"play" => '0'
|
||||
) , $atts));
|
||||
"play" => '0',
|
||||
), $atts));
|
||||
if ($play == 0) {
|
||||
return '<audio style="width:100%;" src="' . $content . '" controls loop>您的浏览器不支持 audio 标签。</audio>';
|
||||
}
|
||||
|
@ -139,58 +151,65 @@ function gdk_tkk($atts, $content = null) {
|
|||
}
|
||||
add_shortcode('audio', 'gdk_tkk');
|
||||
//弹窗下载
|
||||
function gdk_ton($atts, $content = null) {
|
||||
function gdk_ton($atts, $content = null)
|
||||
{
|
||||
extract(shortcode_atts(array(
|
||||
"href" => 'http://',
|
||||
"href" => 'http://',
|
||||
"filename" => '',
|
||||
"filesize" => '',
|
||||
"filedown" => ''
|
||||
) , $atts));
|
||||
"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>';
|
||||
}
|
||||
add_shortcode('fanctdl', 'gdk_ton');
|
||||
//代码演示短代码
|
||||
function gdk_demo($atts, $content = null) {
|
||||
function gdk_demo($atts, $content = null)
|
||||
{
|
||||
return '<a class="lhb" href="' . get_permalink(gdk_page_id('demo')) . '?pid=' . get_the_ID() . '" target="_blank" rel="nofollow">' . $content . '</a>';
|
||||
}
|
||||
add_shortcode('demo', 'gdk_demo');
|
||||
//下载单页短代码
|
||||
function gdk_download($atts, $content = null) {
|
||||
function gdk_download($atts, $content = null)
|
||||
{
|
||||
return '<a class="lhb" href="' . get_permalink(gdk_page_id('download')) . '?pid=' . get_the_ID() . '" target="_blank" rel="nofollow">' . $content . '</a>';
|
||||
}
|
||||
add_shortcode('download', 'gdk_download');
|
||||
|
||||
//为WordPress添加展开收缩功能
|
||||
function gdk_xcollapse($atts, $content = null) {
|
||||
function gdk_xcollapse($atts, $content = null)
|
||||
{
|
||||
extract(shortcode_atts(array(
|
||||
"title" => ""
|
||||
) , $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>';
|
||||
}
|
||||
add_shortcode('collapse', 'gdk_xcollapse');
|
||||
//简单的下载面板
|
||||
function gdk_xdltable($atts, $content = null) {
|
||||
function gdk_xdltable($atts, $content = null)
|
||||
{
|
||||
extract(shortcode_atts(array(
|
||||
"file" => "",
|
||||
"size" => ""
|
||||
) , $atts));
|
||||
"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>';
|
||||
}
|
||||
add_shortcode('dltable', 'gdk_xdltable');
|
||||
//网易云音乐
|
||||
function gdk_music163($atts, $content = null) {
|
||||
function gdk_music163($atts, $content = null)
|
||||
{
|
||||
extract(shortcode_atts(array(
|
||||
"play" => "1"
|
||||
) , $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>';
|
||||
}
|
||||
add_shortcode('netmusic', 'gdk_music163');
|
||||
//登录可见
|
||||
function gdk_login_to_read($atts, $content = null) {
|
||||
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));
|
||||
"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>';
|
||||
}
|
||||
|
@ -199,13 +218,14 @@ function gdk_login_to_read($atts, $content = null) {
|
|||
add_shortcode('vip', 'gdk_login_to_read');
|
||||
|
||||
// 部分内容输入密码可见
|
||||
function gdk_secret_view($atts, $content = null) {
|
||||
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>';
|
||||
}//admin show
|
||||
return '<div class="cm-grid cm-card pass_viewbox">
|
||||
if (current_user_can('administrator')) {
|
||||
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">
|
||||
<img src="https://p.ssl.qhimg.com/t0162cc8398cbf7dea3.jpg" class="cm-resp-img">
|
||||
|
@ -213,7 +233,7 @@ function gdk_secret_view($atts, $content = null) {
|
|||
<div class="cm-col-md-8">
|
||||
<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>
|
||||
|
@ -222,12 +242,12 @@ function gdk_secret_view($atts, $content = null) {
|
|||
}
|
||||
add_shortcode('wxcaptcha', 'gdk_secret_view');
|
||||
|
||||
|
||||
// 支持文章和页面运行PHP代码
|
||||
function gdk_php_include($attr) {
|
||||
$file = $attr['file'];
|
||||
function gdk_php_include($attr)
|
||||
{
|
||||
$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();
|
||||
|
@ -235,25 +255,26 @@ function gdk_php_include($attr) {
|
|||
add_shortcode('phpcode', 'gdk_php_include');
|
||||
|
||||
//给文章加内链短代码
|
||||
function gdk_insert_posts($atts, $content = null) {
|
||||
function gdk_insert_posts($atts, $content = null)
|
||||
{
|
||||
extract(shortcode_atts(array(
|
||||
'ids' => ''
|
||||
) , $atts));
|
||||
'ids' => '',
|
||||
), $atts));
|
||||
global $post;
|
||||
$content = '';
|
||||
$postids = explode(',', $ids);
|
||||
$content = '';
|
||||
$postids = explode(',', $ids);
|
||||
$inset_posts = get_posts(array(
|
||||
'post__in' => $postids
|
||||
'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.= 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.= gdk_thumbnail_src();
|
||||
$content.= ' class="neilian-thumb"></a></div></div>';
|
||||
$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 .= gdk_thumbnail_src();
|
||||
$content .= ' class="neilian-thumb"></a></div></div>';
|
||||
}
|
||||
wp_reset_postdata();
|
||||
return $content;
|
||||
|
@ -261,22 +282,24 @@ function gdk_insert_posts($atts, $content = null) {
|
|||
add_shortcode('neilian', 'gdk_insert_posts');
|
||||
|
||||
//给文章加内链短代码
|
||||
function gdk_insert_temp($atts, $content = null) {
|
||||
extract(shortcode_atts(array( 'id' => '' ) , $atts));
|
||||
$data = get_post($id);
|
||||
function gdk_insert_temp($atts, $content = null)
|
||||
{
|
||||
extract(shortcode_atts(array('id' => ''), $atts));
|
||||
$data = get_post($id);
|
||||
$content = $data->post_content;
|
||||
return $content;
|
||||
}
|
||||
add_shortcode('temp', 'gdk_insert_temp');
|
||||
|
||||
//快速插入列表
|
||||
function gdk_list_shortcode_handler($atts, $content = '') {
|
||||
function gdk_list_shortcode_handler($atts, $content = '')
|
||||
{
|
||||
$content = trim($content);
|
||||
$lists = explode("\n", $content);
|
||||
$output = '';
|
||||
$lists = explode("\n", $content);
|
||||
$output = '';
|
||||
foreach ($lists as $li) {
|
||||
if (trim($li) != '') {
|
||||
$output.= "<li>{$li}</li>";
|
||||
$output .= "<li>{$li}</li>";
|
||||
}
|
||||
}
|
||||
$output = "<ul>" . $output . "</ul>\n";
|
||||
|
@ -285,186 +308,186 @@ function gdk_list_shortcode_handler($atts, $content = '') {
|
|||
add_shortcode('list', 'gdk_list_shortcode_handler');
|
||||
|
||||
//表格短代码
|
||||
function gdk_table_shortcode_handler( $atts, $content='' ) {
|
||||
extract( shortcode_atts( ['width' => '100%'], $atts ) );
|
||||
$output = '';
|
||||
function gdk_table_shortcode_handler($atts, $content = '')
|
||||
{
|
||||
extract(shortcode_atts(['width' => '100%'], $atts));
|
||||
$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){
|
||||
foreach ($ths as $th) {
|
||||
$th = trim($th);
|
||||
$output .= '<th>'.$th.'</th>';
|
||||
$output .= '<th>' . $th . '</th>';
|
||||
}
|
||||
$output .= '</tr></thead>';
|
||||
$output .= '<tbody>';
|
||||
unset($trs[0]);
|
||||
foreach($trs as $tr){
|
||||
foreach ($trs as $tr) {
|
||||
$tr = trim($tr);
|
||||
if($tr){
|
||||
if ($tr) {
|
||||
$tds = explode(" ", $tr);
|
||||
$output .= '<tr>';
|
||||
foreach($tds as $td){
|
||||
foreach ($tds as $td) {
|
||||
$td = trim($td);
|
||||
if($td){
|
||||
$output .= '<td>'.$td.'</td>';
|
||||
if ($td) {
|
||||
$output .= '<td>' . $td . '</td>';
|
||||
}
|
||||
}
|
||||
$output .= '</tr>';
|
||||
}
|
||||
}
|
||||
$output .= '</tbody>';
|
||||
$width = ' width="'.$width.'"';
|
||||
$output = '<table class="gdk-table"'.$width.' >'.$output.'</table>\n';
|
||||
$width = ' width="' . $width . '"';
|
||||
$output = '<table class="gdk-table"' . $width . ' >' . $output . '</table>\n';
|
||||
|
||||
return $output;
|
||||
}
|
||||
add_shortcode( 'table', 'gdk_table_shortcode_handler' );
|
||||
add_shortcode('table', 'gdk_table_shortcode_handler');
|
||||
|
||||
add_shortcode('youku', function ($atts, $content = '') {
|
||||
extract(shortcode_atts(array(
|
||||
'width' => '510',
|
||||
'height' => '498',
|
||||
), $atts));
|
||||
|
||||
add_shortcode('youku', function( $atts, $content='') {
|
||||
extract( shortcode_atts( array(
|
||||
'width' => '510',
|
||||
'height' => '498'
|
||||
), $atts ) );
|
||||
$width = (isset($_GET['width']) && intval($_GET['width'])) ? intval($_GET['width']) : $width; // 用于 JSON 接口
|
||||
$height = round($width / 4 * 3);
|
||||
|
||||
$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>';
|
||||
}
|
||||
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>';
|
||||
}
|
||||
});
|
||||
|
||||
add_shortcode('qqv', function ($atts, $content = '') {
|
||||
extract(shortcode_atts(array(
|
||||
'width' => '510',
|
||||
'height' => '498',
|
||||
), $atts));
|
||||
|
||||
add_shortcode('qqv', function($atts, $content='') {
|
||||
extract( shortcode_atts( array(
|
||||
'width' => '510',
|
||||
'height' => '498'
|
||||
), $atts ) );
|
||||
$width = (isset($_GET['width']) && intval($_GET['width'])) ? intval($_GET['width']) : $width; // 用于 JSON 接口
|
||||
$height = round($width / 4 * 3);
|
||||
|
||||
|
||||
$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)){
|
||||
//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>';
|
||||
}
|
||||
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)) {
|
||||
//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>';
|
||||
}
|
||||
});
|
||||
|
||||
add_shortcode('tudou', function($atts, $content=''){
|
||||
extract( shortcode_atts( array(
|
||||
'width' => '480',
|
||||
'height' => '400'
|
||||
), $atts ) );
|
||||
add_shortcode('tudou', function ($atts, $content = '') {
|
||||
extract(shortcode_atts(array(
|
||||
'width' => '480',
|
||||
'height' => '400',
|
||||
), $atts));
|
||||
|
||||
$width = (isset($_GET['width']) && intval($_GET['width']))?intval($_GET['width']):$width; // 用于 JSON 接口
|
||||
$height = round($width/4*3);
|
||||
$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>';
|
||||
}
|
||||
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>';
|
||||
}
|
||||
});
|
||||
|
||||
add_shortcode('sohutv', function($atts, $content=''){
|
||||
extract( shortcode_atts( array(
|
||||
'width' => '510',
|
||||
'height' => '498'
|
||||
), $atts ) );
|
||||
add_shortcode('sohutv', function ($atts, $content = '') {
|
||||
extract(shortcode_atts(array(
|
||||
'width' => '510',
|
||||
'height' => '498',
|
||||
), $atts));
|
||||
|
||||
$width = (isset($_GET['width']) && intval($_GET['width'])) ? intval($_GET['width']) : $width; // 用于 JSON 接口
|
||||
$height = round($width / 4 * 3);
|
||||
|
||||
$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>';
|
||||
}
|
||||
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>';
|
||||
}
|
||||
});
|
||||
|
||||
//付费可见短代码
|
||||
function gdk_pay_nologin($atts, $content = ''){
|
||||
extract(shortcode_atts(array('money' => '1' ) , $atts));
|
||||
$pid = get_the_ID();//文章ID
|
||||
add_post_meta($pid, '_pay_content', $content, true) or update_post_meta($pid, '_pay_content', $content);//没有新建,有就更新
|
||||
$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"><legend class="legend">付费内容</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.'" class="button">立即查看</button></p>';
|
||||
$notice .= '</fieldset>';
|
||||
return $notice;
|
||||
function gdk_pay_nologin($atts, $content = '')
|
||||
{
|
||||
extract(shortcode_atts(array('money' => '1'), $atts));
|
||||
$pid = get_the_ID(); //文章ID
|
||||
add_post_meta($pid, '_pay_content', $content, true) or update_post_meta($pid, '_pay_content', $content); //没有新建,有就更新
|
||||
$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"><legend class="legend">付费内容</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 . '" class="button">立即查看</button></p>';
|
||||
$notice .= '</fieldset>';
|
||||
return $notice;
|
||||
}
|
||||
add_shortcode('pax', 'gdk_pay_nologin');
|
||||
|
||||
//WordPress 段代码按钮集合
|
||||
function gdk_shortcode_list() {
|
||||
function gdk_shortcode_list()
|
||||
{
|
||||
$wpshortcodes = [
|
||||
'横线'=>'<hr />',
|
||||
'H2标题'=>'<h2> </h2>',
|
||||
'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 />',
|
||||
'H2标题' => '<h2> </h2>',
|
||||
'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]
|
||||
|
||||
[/wxcaptcha]',
|
||||
'积分购买可见'=>'[pay point=\'10\']这里是需要付费的内容[/pay]',
|
||||
'游客付费可见'=>'[pax money=1]',
|
||||
'弹窗下载'=>'[fanctdl filename=\'这里填写文件名\' filepass=\'这里填写文件密码什么的\' href=\'这里填写的主下载链接\' filedown=\'这里填写的是文件的主下载名称\']这里填写的文件的辅助下载链接,可写多个,空格间隔[/fanctdl]',
|
||||
'面板下载'=>'[dltable file=\'在此处写下文件名称\' pass=\'在这里写下文件密码\']这里填写的文件的辅助下载链接,可写多个,空格间隔[/dltable]',
|
||||
'单页下载'=>'[pdownload title=]',
|
||||
'文章内链'=>'[neilian ids=]',
|
||||
'无序列表'=>'[list]
|
||||
'积分购买可见' => '[pay point=\'10\']这里是需要付费的内容[/pay]',
|
||||
'游客付费可见' => '[pax money=1]',
|
||||
'弹窗下载' => '[fanctdl filename=\'这里填写文件名\' filepass=\'这里填写文件密码什么的\' href=\'这里填写的主下载链接\' filedown=\'这里填写的是文件的主下载名称\']这里填写的文件的辅助下载链接,可写多个,空格间隔[/fanctdl]',
|
||||
'面板下载' => '[dltable file=\'在此处写下文件名称\' pass=\'在这里写下文件密码\']这里填写的文件的辅助下载链接,可写多个,空格间隔[/dltable]',
|
||||
'单页下载' => '[pdownload title=]',
|
||||
'文章内链' => '[neilian ids=]',
|
||||
'无序列表' => '[list]
|
||||
|
||||
[/list]',
|
||||
'表格简码'=>'[table]
|
||||
'表格简码' => '[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) {
|
||||
function gdk_shortcode_button($context)
|
||||
{
|
||||
$context = '<a id="insert-shortcode-button" style="position:relative" class="button insert-shortcodes add_shortcodes" title="添加简码" data-editor="content" href="javascript:void(0)">短代码</a><div class="shortcodes-wrap">' . gdk_shortcode_list() . '</div>';
|
||||
return $context;
|
||||
}
|
||||
add_action('media_buttons_context', 'gdk_shortcode_button');
|
||||
add_action('media_buttons_context', 'gdk_shortcode_button');
|
||||
|
|
|
@ -1,31 +1,30 @@
|
|||
<?php
|
||||
|
||||
|
||||
|
||||
//修复 WordPress 找回密码提示“抱歉,该key似乎无效”
|
||||
function gdk_reset_password_message($message, $key) {
|
||||
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.= "要重置您的密码,请打开下面的链接:\r\n\r\n";
|
||||
$msg.= wp_login_url() . "?action=rp&key=$key&login=" . rawurlencode($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 .= "要重置您的密码,请打开下面的链接:\r\n\r\n";
|
||||
$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插件*/
|
||||
//注册表单
|
||||
function gdk_show_extra_register_fields() {
|
||||
?>
|
||||
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" />
|
||||
|
@ -37,12 +36,13 @@ if (!defined('UM_DIR')) { /*判断是否按照UM插件*/
|
|||
</label>
|
||||
</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) {
|
||||
*/
|
||||
function gdk_check_extra_register_fields($login, $email, $errors)
|
||||
{
|
||||
if ($_POST['password'] !== $_POST['repeat_password']) {
|
||||
$errors->add('passwords_not_matched', "<strong>错误提示</strong>: 两次填写密码不一致");
|
||||
}
|
||||
|
@ -53,9 +53,10 @@ if (!defined('UM_DIR')) { /*判断是否按照UM插件*/
|
|||
add_action('register_post', 'gdk_check_extra_register_fields', 10, 3);
|
||||
/*
|
||||
* 提交用户密码进数据库
|
||||
*/
|
||||
function gdk_register_extra_fields($user_id) {
|
||||
$userdata = array();
|
||||
*/
|
||||
function gdk_register_extra_fields($user_id)
|
||||
{
|
||||
$userdata = array();
|
||||
$userdata['ID'] = $user_id;
|
||||
if ($_POST['password'] !== '') {
|
||||
$userdata['user_pass'] = $_POST['password'];
|
||||
|
@ -71,15 +72,17 @@ if (!defined('UM_DIR')) { /*判断是否按照UM插件*/
|
|||
|
||||
//后台登陆数学验证码
|
||||
if (gdk_option('gdk_login_verify')) {
|
||||
function gdk_login_verify(){
|
||||
function 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>";
|
||||
}
|
||||
add_action('login_form', 'gdk_login_verify');
|
||||
add_action('register_form', 'gdk_login_verify');
|
||||
|
||||
function gdk_login_verify_val(){
|
||||
add_action('register_form', 'gdk_login_verify');
|
||||
|
||||
function gdk_login_verify_val()
|
||||
{
|
||||
$sum = $_POST['sum'];
|
||||
switch ($sum) {
|
||||
case $_POST['num1'] + $_POST['num2']:
|
||||
|
@ -96,7 +99,8 @@ if (gdk_option('gdk_login_verify')) {
|
|||
}
|
||||
|
||||
//仅显示作者自己的文章
|
||||
function gdk_show_mypost($wp_query) {
|
||||
function gdk_show_mypost($wp_query)
|
||||
{
|
||||
if (strpos($_SERVER['REQUEST_URI'], '/wp-admin/edit.php') !== false) {
|
||||
if (!current_user_can('manage_options')) {
|
||||
$wp_query->set('author', get_current_user_id());
|
||||
|
@ -106,17 +110,28 @@ function gdk_show_mypost($wp_query) {
|
|||
add_filter('parse_query', 'gdk_show_mypost');
|
||||
|
||||
//在文章编辑页面的[添加媒体]只显示用户自己上传的文件
|
||||
function gdk_show_myupload($wp_query_obj) {
|
||||
function gdk_show_myupload($wp_query_obj)
|
||||
{
|
||||
global $pagenow;
|
||||
if (!is_a(wp_get_current_user(), 'WP_User')) return;
|
||||
if ('admin-ajax.php' != $pagenow || $_REQUEST['action'] != 'query-attachments') return;
|
||||
if (!current_user_can('manage_options') && !current_user_can('manage_media_library')) $wp_query_obj->set('author', get_current_user_id());
|
||||
if (!is_a(wp_get_current_user(), 'WP_User')) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ('admin-ajax.php' != $pagenow || $_REQUEST['action'] != 'query-attachments') {
|
||||
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) {
|
||||
function gdk_show_myupload_library($wp_query)
|
||||
{
|
||||
if (strpos($_SERVER['REQUEST_URI'], '/wp-admin/upload.php') !== false) {
|
||||
if (!current_user_can('manage_options') && !current_user_can('manage_media_library')) {
|
||||
$wp_query->set('author', get_current_user_id());
|
||||
|
@ -126,10 +141,11 @@ function gdk_show_myupload_library($wp_query) {
|
|||
add_filter('parse_query', 'gdk_show_myupload_library');
|
||||
|
||||
//添加后台个人信息
|
||||
function gdk_contact_fields($contactmethods) {
|
||||
$contactmethods['qq'] = 'QQ';
|
||||
function gdk_contact_fields($contactmethods)
|
||||
{
|
||||
$contactmethods['qq'] = 'QQ';
|
||||
$contactmethods['sina_weibo'] = '新浪微博';
|
||||
$contactmethods['weixin'] = '微信';
|
||||
$contactmethods['weixin'] = '微信';
|
||||
unset($contactmethods['yim']);
|
||||
unset($contactmethods['aim']);
|
||||
unset($contactmethods['jabber']);
|
||||
|
@ -137,9 +153,9 @@ function gdk_contact_fields($contactmethods) {
|
|||
}
|
||||
add_filter('user_contactmethods', 'gdk_contact_fields');
|
||||
|
||||
|
||||
//支持中文名注册,来自肚兜
|
||||
function gdk_sanitize_user($username, $raw_username, $strict) {
|
||||
function gdk_sanitize_user($username, $raw_username, $strict)
|
||||
{
|
||||
$username = wp_strip_all_tags($raw_username);
|
||||
$username = remove_accents($username);
|
||||
$username = preg_replace('|%([a-fA-F0-9][a-fA-F0-9])|', '', $username);
|
||||
|
@ -154,39 +170,49 @@ function gdk_sanitize_user($username, $raw_username, $strict) {
|
|||
add_filter('sanitize_user', 'gdk_sanitize_user', 10, 3);
|
||||
|
||||
// 添加一个新的列 ID
|
||||
function gdk_userid_column($cols) {
|
||||
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') $value = $id;
|
||||
function gdk_userid_value($value, $column_name, $id)
|
||||
{
|
||||
if ($column_name == 'ssid') {
|
||||
$value = $id;
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
add_filter('manage_users_custom_column', 'gdk_userid_value', 30, 3);
|
||||
|
||||
|
||||
//WordPress 后台用户列表显示用户昵称
|
||||
add_filter('manage_users_columns', 'gdk_add_user_nickname');
|
||||
function gdk_add_user_nickname($columns) {
|
||||
$columns['user_nickname'] = '昵称';
|
||||
return $columns;
|
||||
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_nickname = $user->nickname;
|
||||
if ( 'user_nickname' == $column_name )
|
||||
return $user_nickname;
|
||||
return $value;
|
||||
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_nickname = $user->nickname;
|
||||
if ('user_nickname' == $column_name) {
|
||||
return $user_nickname;
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
//用户列表显示积分
|
||||
add_filter('manage_users_columns', 'gdk_points_columns');
|
||||
function gdk_points_columns($columns) {
|
||||
function gdk_points_columns($columns)
|
||||
{
|
||||
$columns['points'] = '金币';
|
||||
return $columns;
|
||||
}
|
||||
function gdk_points_value($value, $column_name, $user_id) {
|
||||
function gdk_points_value($value, $column_name, $user_id)
|
||||
{
|
||||
if ($column_name == 'points') {
|
||||
$jinbi = GDK_Points::get_user_total_points($user_id, 'accepted');
|
||||
if ($jinbi != "") {
|
||||
|
@ -202,17 +228,19 @@ function gdk_points_value($value, $column_name, $user_id) {
|
|||
add_action('manage_users_custom_column', 'gdk_points_value', 10, 3);
|
||||
|
||||
//用户增加评论数量
|
||||
function gdk_users_comments($columns) {
|
||||
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) {
|
||||
function gdk_show_users_comments($value, $column_name, $user_id)
|
||||
{
|
||||
if ($column_name == 'comments') {
|
||||
$comments_counts = get_comments(array(
|
||||
'status' => '1',
|
||||
'status' => '1',
|
||||
'user_id' => $user_id,
|
||||
'count' => true
|
||||
'count' => true,
|
||||
));
|
||||
if ($comments_counts != "") {
|
||||
$ret = $comments_counts;
|
||||
|
@ -226,18 +254,21 @@ function gdk_show_users_comments($value, $column_name, $user_id) {
|
|||
}
|
||||
add_action('manage_users_custom_column', 'gdk_show_users_comments', 10, 3);
|
||||
// 添加一个字段保存IP地址
|
||||
function gdk_log_ip($user_id) {
|
||||
function gdk_log_ip($user_id)
|
||||
{
|
||||
$ip = gdk_get_ip();
|
||||
update_user_meta($user_id, 'signup_ip', $ip);
|
||||
}
|
||||
add_action('user_register', 'gdk_log_ip');
|
||||
// 添加IP地址这个栏目
|
||||
function gdk_signup_ip($column_headers) {
|
||||
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) {
|
||||
function gdk_ripms_columns($value, $column_name, $user_id)
|
||||
{
|
||||
if ($column_name == 'signup_ip') {
|
||||
$ip = get_user_meta($user_id, 'signup_ip', true);
|
||||
if ($ip != "") {
|
||||
|
@ -252,20 +283,23 @@ function gdk_ripms_columns($value, $column_name, $user_id) {
|
|||
}
|
||||
add_action('manage_users_custom_column', 'gdk_ripms_columns', 10, 3);
|
||||
// 创建一个新字段存储用户登录时间
|
||||
function gdk_insert_last_login($login) {
|
||||
function gdk_insert_last_login($login)
|
||||
{
|
||||
$user = get_user_by('login', $login);
|
||||
update_user_meta($user->ID, 'last_login', current_time('mysql'));
|
||||
}
|
||||
add_action('wp_login', 'gdk_insert_last_login');
|
||||
// 添加一个新栏目上次登录
|
||||
function gdk_add_last_login_column($columns) {
|
||||
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) {
|
||||
function gdk_add_last_login($value, $column_name, $user_id)
|
||||
{
|
||||
if ($column_name == 'last_login') {
|
||||
$login = get_user_meta($user_id, 'last_login', true);
|
||||
if ($login != "") {
|
||||
|
|
|
@ -7,36 +7,37 @@ Version: 0.0.2
|
|||
Author: 云落
|
||||
Author URI: https://gitcafe.net/
|
||||
Compatible:5.3.2
|
||||
*/
|
||||
*/
|
||||
|
||||
//万能的开头
|
||||
if ( ! defined( 'ABSPATH' ) ) { exit; }
|
||||
if (!defined('ABSPATH')) {exit;}
|
||||
|
||||
//版本和兼容检查
|
||||
function deactivate_myself() {
|
||||
deactivate_plugins( plugin_basename( __FILE__ ) );
|
||||
wp_die('启动失败,GDK插件不兼容Git主题且需要运行在 PHP 7.2 版本及更高的环境下。');
|
||||
function deactivate_myself()
|
||||
{
|
||||
deactivate_plugins(plugin_basename(__FILE__));
|
||||
wp_die('启动失败,GDK插件不兼容Git主题且需要运行在 PHP 7.2 版本及更高的环境下。');
|
||||
}
|
||||
|
||||
if (defined('GIT_URL')) {
|
||||
add_action('update_option_active_plugins', 'deactivate_myself');
|
||||
add_action('update_option_active_plugins', 'deactivate_myself');
|
||||
}
|
||||
|
||||
if (!version_compare(PHP_VERSION, '7.2', '>=')) {
|
||||
add_action('update_option_active_plugins', 'deactivate_myself');
|
||||
add_action('update_option_active_plugins', 'deactivate_myself');
|
||||
}
|
||||
|
||||
//定义各种常量
|
||||
define('GDK_PLUGIN_VER', '0.0.1');
|
||||
define('GDK_PLUGIN_FILE', __FILE__);//插件入口文件
|
||||
define('GDK_BASE_URL', plugin_dir_url( __FILE__ ) );//插件目录url
|
||||
define('GDK_ROOT_PATH', plugin_dir_path( __FILE__ ) );//插件目录路径
|
||||
define('GDK_PLUGIN_VER', '0.0.1');
|
||||
define('GDK_PLUGIN_FILE', __FILE__); //插件入口文件
|
||||
define('GDK_BASE_URL', plugin_dir_url(__FILE__)); //插件目录url
|
||||
define('GDK_ROOT_PATH', plugin_dir_path(__FILE__)); //插件目录路径
|
||||
|
||||
//加载各种资源
|
||||
include('framework/frame_load.php');//加载后台框架
|
||||
include('class/class_load.php');//加载各种类
|
||||
include('functions/func_load.php');//加载函数
|
||||
include('assets/assets_load.php');//加载静态资源
|
||||
include 'framework/frame_load.php'; //加载后台框架
|
||||
include 'class/class_load.php'; //加载各种类
|
||||
include 'functions/func_load.php'; //加载函数
|
||||
include 'assets/assets_load.php'; //加载静态资源
|
||||
|
||||
//激活插件之后创建必要页面
|
||||
//register_activation_hook(__FILE__, 'gdk_plugin_activate');
|
||||
//register_activation_hook(__FILE__, 'gdk_plugin_activate');
|
||||
|
|
|
@ -3,40 +3,41 @@
|
|||
* SiteMap HTML 版
|
||||
*/
|
||||
|
||||
function gdk_daohang_html_api_handlers( $template ){
|
||||
$hook = explode('-', get_query_var( 'daohang' ) );
|
||||
if( isset( $hook[0] ) && $hook[0] === 'gdkk' ){
|
||||
function gdk_daohang_html_api_handlers($template)
|
||||
{
|
||||
$hook = explode('-', get_query_var('daohang'));
|
||||
if (isset($hook[0]) && $hook[0] === 'gdkk') {
|
||||
|
||||
if( isset( $hook[1] ) ){
|
||||
if (isset($hook[1])) {
|
||||
status_header(404);
|
||||
header('HTTP/1.0 404 Not Found');
|
||||
$GLOBALS['wp_query']->set_404();
|
||||
include( get_query_template( '404' ) );
|
||||
include get_query_template('404');
|
||||
exit;
|
||||
}
|
||||
$daohang = get_transient('gdk-daohang-html');
|
||||
|
||||
if( false === $daohang || empty( $daohang ) ){
|
||||
if (false === $daohang || empty($daohang)) {
|
||||
$daohang = gdk_create_html_daohang();
|
||||
set_transient( 'gdk-daohang-html', $daohang );
|
||||
set_transient('gdk-daohang-html', $daohang);
|
||||
}
|
||||
$daohang;
|
||||
return;
|
||||
}
|
||||
|
||||
return $template;
|
||||
return $template;
|
||||
}
|
||||
|
||||
add_filter('template_include', 'gdk_daohang_html_api_handlers', 99);
|
||||
|
||||
add_filter( 'template_include', 'gdk_daohang_html_api_handlers', 99 );
|
||||
|
||||
function gdk_create_html_daohang() {
|
||||
function gdk_create_html_daohang()
|
||||
{
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>网址导航 - <?php echo get_bloginfo('name');?></title>
|
||||
<title>网址导航 - <?php echo get_bloginfo('name'); ?></title>
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1">
|
||||
<meta http-equiv="X-UA-COMPATIBLE" content="IE=edge">
|
||||
<style type="text/css">
|
||||
|
@ -46,7 +47,7 @@ function gdk_create_html_daohang() {
|
|||
</head>
|
||||
<body>
|
||||
<header class="mobile-header-wrap">
|
||||
<a class="mobile-logo" href="/"><img src="<?php echo GDK_BASE_URL?>assets/img/logo.png" alt="logo"></a>
|
||||
<a class="mobile-logo" href="/"><img src="<?php echo GDK_BASE_URL ?>assets/img/logo.png" alt="logo"></a>
|
||||
</header>
|
||||
<div class="btn-mobile-sidenav">
|
||||
<div class="nav-bar">
|
||||
|
@ -58,26 +59,26 @@ function gdk_create_html_daohang() {
|
|||
<!-- sidenav -->
|
||||
<div class="sidenav">
|
||||
<a class="logo" href="">
|
||||
<img src="<?php echo GDK_BASE_URL;?>assets/img/logo.png" alt="logo">
|
||||
<img src="<?php echo GDK_BASE_URL; ?>assets/img/logo.png" alt="logo">
|
||||
</a>
|
||||
<div class="site-description">
|
||||
<?php echo get_bloginfo( 'description', 'display' );?>
|
||||
<?php echo get_bloginfo('description', 'display'); ?>
|
||||
</div>
|
||||
|
||||
<!-- tool -->
|
||||
<?php
|
||||
$linkcats1 = get_terms('link_category', 'orderby=count&hide_empty=1&exclude=7');
|
||||
echo '<ul class="nav-tags">';
|
||||
foreach ($linkcats1 as $linkcat) {
|
||||
echo '<li><a href="#' . $linkcat->term_id . '">' . $linkcat->name . '</a></li>';
|
||||
}
|
||||
echo '</ul>';
|
||||
echo '<a class="copyright" href="/">© '.get_bloginfo('name').'</a>
|
||||
$linkcats1 = get_terms('link_category', 'orderby=count&hide_empty=1&exclude=7');
|
||||
echo '<ul class="nav-tags">';
|
||||
foreach ($linkcats1 as $linkcat) {
|
||||
echo '<li><a href="#' . $linkcat->term_id . '">' . $linkcat->name . '</a></li>';
|
||||
}
|
||||
echo '</ul>';
|
||||
echo '<a class="copyright" href="/">© ' . get_bloginfo('name') . '</a>
|
||||
</div>
|
||||
<div class="main-wrap">
|
||||
<div class="main">';
|
||||
echo gdk_get_link_items();
|
||||
?>
|
||||
echo gdk_get_link_items();
|
||||
?>
|
||||
<div class="footer-at row">
|
||||
<div class="xs-12 sm-12 md-6" style="margin-bottom: 10px;">
|
||||
<a target="_blank" href="#">
|
||||
|
@ -92,7 +93,7 @@ function gdk_create_html_daohang() {
|
|||
</div>
|
||||
<footer class="footer">
|
||||
<div class="footer-top-border"></div>
|
||||
Copyright © 2016-2022 网址导航 - <?php echo get_bloginfo('name');?>
|
||||
Copyright © 2016-2022 网址导航 - <?php echo get_bloginfo('name'); ?>
|
||||
<span class="footer-link">
|
||||
<a href="about">关于小狮子</a>
|
||||
</span>
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -1,45 +1,42 @@
|
|||
<?php
|
||||
|
||||
|
||||
|
||||
add_action('template_redirect', 'gdk_go_redirect');
|
||||
|
||||
|
||||
|
||||
function gdk_go_redirect(){
|
||||
global $wp,$wp_query;
|
||||
$b = $wp_query->query_vars['go']??'';
|
||||
if ($b){
|
||||
gdk_go_action();
|
||||
exit;
|
||||
}
|
||||
function gdk_go_redirect()
|
||||
{
|
||||
global $wp, $wp_query;
|
||||
$b = $wp_query->query_vars['go'] ?? '';
|
||||
if ($b) {
|
||||
gdk_go_action();
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function gdk_go_action(){
|
||||
$t_url = preg_replace('/^go=(.*)$/i','$1',$_SERVER["QUERY_STRING"]);
|
||||
if(!empty($t_url)) {
|
||||
preg_match('/(http|https):\/\//',$t_url,$matches);
|
||||
if($matches){
|
||||
$url=$t_url;
|
||||
$title='页面加载中,请稍候...';
|
||||
} else {
|
||||
$title='加载中...';
|
||||
echo "<script>setTimeout(function(){window.opener=null;window.close();}, 2000);</script>";
|
||||
}
|
||||
}
|
||||
?>
|
||||
function gdk_go_action()
|
||||
{
|
||||
$t_url = preg_replace('/^go=(.*)$/i', '$1', $_SERVER["QUERY_STRING"]);
|
||||
if (!empty($t_url)) {
|
||||
preg_match('/(http|https):\/\//', $t_url, $matches);
|
||||
if ($matches) {
|
||||
$url = $t_url;
|
||||
$title = '页面加载中,请稍候...';
|
||||
} else {
|
||||
$title = '加载中...';
|
||||
echo "<script>setTimeout(function(){window.opener=null;window.close();}, 2000);</script>";
|
||||
}
|
||||
}
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||
<meta http-equiv="refresh" content="1;url='<?php echo $url;?>';">
|
||||
<title><?php echo $title;?></title>
|
||||
<meta http-equiv="refresh" content="1;url='<?php echo $url; ?>';">
|
||||
<title><?php echo $title; ?></title>
|
||||
<style type="text/css">body{background:#f5f7fa;margin:0}.loader{animation:fadein 2s;position:absolute;top:0;left:0;right:0;bottom:0;background-color:#f5f7fa}@keyframes fadein{0%{opacity:0}to{opacity:1}}.loader-inner{position:absolute;z-index:300;top:40%;left:50%;transform:translate(-50%,-50%)}@keyframes rotate_pacman_half_up{0%{transform:rotate(270deg)}50%{transform:rotate(360deg)}to{transform:rotate(270deg)}}@keyframes rotate_pacman_half_down{0%{transform:rotate(90deg)}50%{transform:rotate(0)}to{transform:rotate(90deg)}}@keyframes pacman-balls{75%{opacity:.7}to{transform:translate(-100px,-6.25px)}}.pacman>div:nth-child(2){animation:pacman-balls 1s 0s infinite linear}.pacman>div:nth-child(3){animation:pacman-balls 1s .33s infinite linear}.pacman>div:nth-child(4){animation:pacman-balls 1s .66s infinite linear}.pacman>div:nth-child(5){animation:pacman-balls 1s .99s infinite linear}.pacman>div:first-of-type{animation:rotate_pacman_half_up .5s 0s infinite}.pacman>div:first-of-type,.pacman>div:nth-child(2){width:0;height:0;border-right:25px solid transparent;border-top:25px solid #7a57d1;border-left:25px solid #7a57d1;border-bottom:25px solid #7a57d1;border-radius:25px}.pacman>div:nth-child(2){animation:rotate_pacman_half_down .5s 0s infinite;margin-top:-50px}.pacman>div:nth-child(3),.pacman>div:nth-child(4),.pacman>div:nth-child(5),.pacman>div:nth-child(6){background-color:#7a57d1;width:15px;height:15px;border-radius:100%;margin:2px;width:10px;height:10px;position:absolute;transform:translate(0,-6.25px);top:25px;left:75pt}.loader-text{margin:20px 0 0 -1pc;display:block;font-size:18px}</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="loader">
|
||||
<div class="loader-inner pacman">
|
||||
<div></div><div></div><div></div><div></div><div></div>
|
||||
<div></div><div></div><div></div><div></div><div></div>
|
||||
<span class="loader-text">页面跳转中, 请稍候…</span>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -2,43 +2,44 @@
|
|||
/**
|
||||
* 支付推送服务消息接收文件
|
||||
*/
|
||||
require( '../../../../wp-load.php' );//此路径位于根目录
|
||||
require '../../../../wp-load.php'; //此路径位于根目录
|
||||
|
||||
/* Payjs支付通知开始 */
|
||||
$data = payjs_notify();//获取payjs支付成功的信息
|
||||
$data = payjs_notify(); //获取payjs支付成功的信息
|
||||
|
||||
|
||||
$money = $data['total_fee']/100; //交易金额
|
||||
$userid = $data['attach']; //交易标题,积分充值是用户ID,付费可见的时候是文章ID
|
||||
$money = $data['total_fee'] / 100; //交易金额
|
||||
$userid = $data['attach']; //交易标题,积分充值是用户ID,付费可见的时候是文章ID
|
||||
$orderid = $data['out_trade_no']; //订单ID
|
||||
|
||||
error_log('Payjs pay ok, Order_ID:'.$orderid.', Order_Title:'.$userid.', Money:'.$money);//输出到日志
|
||||
error_log('Payjs pay ok, Order_ID:' . $orderid . ', Order_Title:' . $userid . ', Money:' . $money); //输出到日志
|
||||
|
||||
|
||||
if(in_string($userid,'PP')){//免登陆支付,插入缓存,然后直接停止推出
|
||||
set_transient($userid, $orderid, 30);
|
||||
exit;
|
||||
if (in_string($userid, 'PP')) { //免登陆支付,插入缓存,然后直接停止推出
|
||||
set_transient($userid, $orderid, 30);
|
||||
exit;
|
||||
}
|
||||
|
||||
if(gdk_check($data['out_trade_no']) !== 0) exit('Repeat push');//在入库前,数据库不应该有同样的订单号
|
||||
|
||||
if( empty($userid) || empty($money) ) exit('data null');//阻止某些极少数空值的
|
||||
if (gdk_check($data['out_trade_no']) !== 0) {
|
||||
exit('Repeat push');
|
||||
}
|
||||
//在入库前,数据库不应该有同样的订单号
|
||||
|
||||
if (empty($userid) || empty($money)) {
|
||||
exit('data null');
|
||||
}
|
||||
//阻止某些极少数空值的
|
||||
|
||||
/* Payjs支付通知结束 */
|
||||
|
||||
$user = get_user_by( 'id', $userid );
|
||||
$user = get_user_by('id', $userid);
|
||||
$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'));
|
||||
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'));
|
||||
wp_mail( get_bloginfo('admin_email') , '【收款成功】网站充值订单已完成',$admin_notice, $headers);
|
||||
$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'));
|
||||
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'));
|
||||
wp_mail(get_bloginfo('admin_email'), '【收款成功】网站充值订单已完成', $admin_notice, $headers);
|
||||
//more
|
||||
|
||||
?>
|
|
@ -4,21 +4,22 @@
|
|||
* sitemap xml
|
||||
*/
|
||||
|
||||
function gdk_sitemap_xml_api_handlers( $template ){
|
||||
$hook = explode('-', get_query_var( 'sitemap' ) );
|
||||
if( isset( $hook[0] ) && $hook[0] === 'gdk' ){
|
||||
if( isset( $hook[1] ) ){
|
||||
function gdk_sitemap_xml_api_handlers($template)
|
||||
{
|
||||
$hook = explode('-', get_query_var('sitemap'));
|
||||
if (isset($hook[0]) && $hook[0] === 'gdk') {
|
||||
if (isset($hook[1])) {
|
||||
status_header(404);
|
||||
header('HTTP/1.0 404 Not Found');
|
||||
$GLOBALS['wp_query']->set_404();
|
||||
include( get_query_template( '404' ) );
|
||||
exit;
|
||||
include get_query_template('404');
|
||||
exit;
|
||||
}
|
||||
|
||||
$sitemap = get_transient('gdk-sitemap');
|
||||
if( false === $sitemap || empty( $sitemap ) ){
|
||||
if (false === $sitemap || empty($sitemap)) {
|
||||
$sitemap = gdk_create_sitemap();
|
||||
set_transient( 'gdk-sitemap', $sitemap );
|
||||
set_transient('gdk-sitemap', $sitemap);
|
||||
}
|
||||
|
||||
header("Content-type: text/xml");
|
||||
|
@ -26,39 +27,39 @@ function gdk_sitemap_xml_api_handlers( $template ){
|
|||
return;
|
||||
}
|
||||
|
||||
return $template;
|
||||
return $template;
|
||||
}
|
||||
|
||||
add_filter('template_include', 'gdk_sitemap_xml_api_handlers', 99);
|
||||
|
||||
add_filter( 'template_include', 'gdk_sitemap_xml_api_handlers', 99 );
|
||||
|
||||
function gdk_create_sitemap() {
|
||||
if ( str_replace( '-', '', get_option( 'gmt_offset' ) ) < 10 ) {
|
||||
$tempo = '-0' . str_replace( '-', '', get_option( 'gmt_offset' ) );
|
||||
function gdk_create_sitemap()
|
||||
{
|
||||
if (str_replace('-', '', get_option('gmt_offset')) < 10) {
|
||||
$tempo = '-0' . str_replace('-', '', get_option('gmt_offset'));
|
||||
} else {
|
||||
$tempo = get_option( 'gmt_offset' );
|
||||
$tempo = get_option('gmt_offset');
|
||||
}
|
||||
if( strlen( $tempo ) == 3 ) { $tempo = $tempo . ':00'; }
|
||||
$postsForSitemap = get_posts( array(
|
||||
if (strlen($tempo) == 3) {$tempo = $tempo . ':00';}
|
||||
$postsForSitemap = get_posts(array(
|
||||
'numberposts' => -1,
|
||||
'orderby' => 'modified',
|
||||
'post_type' => array('post'),
|
||||
'order' => 'DESC',
|
||||
) );
|
||||
));
|
||||
$sitemap = '';
|
||||
$sitemap .= '<?xml version="1.0" encoding="UTF-8"?>';
|
||||
$sitemap .= "\n" . '<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' . "\n";
|
||||
$sitemap .= "\t" . '<url>' . "\n" .
|
||||
"\t\t" . '<loc>' . esc_url( home_url( '/' ) ) . '</loc>' .
|
||||
"\n\t\t" . '<lastmod>' . date( "Y-m-d\TH:i:s", current_time( 'timestamp', 0 ) ) . $tempo . '</lastmod>' .
|
||||
"\t\t" . '<loc>' . esc_url(home_url('/')) . '</loc>' .
|
||||
"\n\t\t" . '<lastmod>' . date("Y-m-d\TH:i:s", current_time('timestamp', 0)) . $tempo . '</lastmod>' .
|
||||
"\n\t\t" . '<changefreq>daily</changefreq>' .
|
||||
"\n\t\t" . '<priority>1.0</priority>' .
|
||||
"\n\t" . '</url>' . "\n";
|
||||
foreach( $postsForSitemap as $post ) {
|
||||
setup_postdata( $post);
|
||||
$postdate = explode( " ", $post->post_modified );
|
||||
foreach ($postsForSitemap as $post) {
|
||||
setup_postdata($post);
|
||||
$postdate = explode(" ", $post->post_modified);
|
||||
$sitemap .= "\t" . '<url>' . "\n" .
|
||||
"\t\t" . '<loc>' . get_permalink( $post->ID ) . '</loc>' .
|
||||
"\t\t" . '<loc>' . get_permalink($post->ID) . '</loc>' .
|
||||
"\n\t\t" . '<lastmod>' . $postdate[0] . 'T' . $postdate[1] . $tempo . '</lastmod>' .
|
||||
"\n\t\t" . '<changefreq>Weekly</changefreq>' .
|
||||
"\n\t\t" . '<priority>0.5</priority>' .
|
||||
|
@ -68,9 +69,10 @@ function gdk_create_sitemap() {
|
|||
return $sitemap;
|
||||
}
|
||||
|
||||
function gdk_clear_sitemap_cache(){
|
||||
delete_transient( 'gdk-sitemap' );
|
||||
function gdk_clear_sitemap_cache()
|
||||
{
|
||||
delete_transient('gdk-sitemap');
|
||||
}
|
||||
add_action('publish_post', 'gdk_clear_sitemap_cache');
|
||||
add_action('publish_page', 'gdk_clear_sitemap_cache');
|
||||
add_action('save_post', 'gdk_clear_sitemap_cache' );
|
||||
add_action('save_post', 'gdk_clear_sitemap_cache');
|
||||
|
|
|
@ -3,45 +3,45 @@
|
|||
* SiteMap HTML 版
|
||||
*/
|
||||
|
||||
function gdk_sitemap_html_api_handlers($template)
|
||||
{
|
||||
|
||||
function gdk_sitemap_html_api_handlers( $template ){
|
||||
$hook = explode('-', get_query_var('sitemap'));
|
||||
|
||||
$hook = explode('-', get_query_var( 'sitemap' ) );
|
||||
|
||||
if( isset( $hook[0] ) && $hook[0] === 'gdkk' ){
|
||||
if (isset($hook[0]) && $hook[0] === 'gdkk') {
|
||||
|
||||
if( isset( $hook[1] ) ){
|
||||
if (isset($hook[1])) {
|
||||
status_header(404);
|
||||
header('HTTP/1.0 404 Not Found');
|
||||
$GLOBALS['wp_query']->set_404();
|
||||
include( get_query_template( '404' ) );
|
||||
exit;
|
||||
include get_query_template('404');
|
||||
exit;
|
||||
}
|
||||
|
||||
$sitemap = get_transient('gdk-sitemap-html');
|
||||
|
||||
if( false === $sitemap || empty( $sitemap ) ){
|
||||
|
||||
if (false === $sitemap || empty($sitemap)) {
|
||||
$sitemap = gdk_create_html_sitemap();
|
||||
set_transient( 'gdk-sitemap-html', $sitemap );
|
||||
set_transient('gdk-sitemap-html', $sitemap);
|
||||
}
|
||||
|
||||
$sitemap;
|
||||
return;
|
||||
}
|
||||
|
||||
return $template;
|
||||
return $template;
|
||||
}
|
||||
|
||||
add_filter('template_include', 'gdk_sitemap_html_api_handlers', 99);
|
||||
|
||||
add_filter( 'template_include', 'gdk_sitemap_html_api_handlers', 99 );
|
||||
|
||||
function gdk_create_html_sitemap() {
|
||||
?>
|
||||
function gdk_create_html_sitemap()
|
||||
{
|
||||
?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head profile="http://gmpg.org/xfn/11">
|
||||
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
|
||||
<title>站点地图 -<?php bloginfo( 'name'); ?></title>
|
||||
<title>站点地图 -<?php bloginfo('name'); ?></title>
|
||||
<meta name="keywords" content="站点地图,<?php bloginfo('name'); ?>" />
|
||||
<meta name="copyright" content="<?php bloginfo('name'); ?>" />
|
||||
<link rel="canonical" href="<?php echo get_permalink(); ?>" />
|
||||
|
@ -52,10 +52,10 @@ function gdk_create_html_sitemap() {
|
|||
|
||||
<body vlink="#333333" link="#333333">
|
||||
<h2 style="text-align: center; margin-top: 20px">
|
||||
<?php bloginfo( 'name'); ?>'s SiteMap</h2>
|
||||
<?php bloginfo('name'); ?>'s SiteMap</h2>
|
||||
<div id="nav">
|
||||
<a href="<?php echo esc_url( home_url() ); ?>/">
|
||||
<b><?php bloginfo( 'name'); ?></b>
|
||||
<a href="<?php echo esc_url(home_url()); ?>/">
|
||||
<b><?php bloginfo('name'); ?></b>
|
||||
</a>
|
||||
»
|
||||
<a href="<?php echo get_permalink(); ?>">站点地图</a>
|
||||
|
@ -63,18 +63,18 @@ function gdk_create_html_sitemap() {
|
|||
<div id="content">
|
||||
<h3>最新文章</h3>
|
||||
<ul>
|
||||
<?php
|
||||
$myposts = get_posts('numberposts=-1&orderby=post_date&order=DESC');
|
||||
foreach($myposts as $post):?>
|
||||
<?php
|
||||
$myposts = get_posts('numberposts=-1&orderby=post_date&order=DESC');
|
||||
foreach ($myposts as $post): ?>
|
||||
<li>
|
||||
<a href="<?php the_permalink($post->ID); ?>" title="<?php echo $post->post_title; ?>" target="_blank"><?php echo $post->post_title; ?></a>
|
||||
</li>
|
||||
<?php endforeach;?>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
</div>
|
||||
<div id="content">
|
||||
<h3>分类目录</h3>
|
||||
<ul><?php wp_list_categories( 'title_li='); ?></ul>
|
||||
<ul><?php wp_list_categories('title_li='); ?></ul>
|
||||
</div>
|
||||
<div id="content">
|
||||
<h3>单页面</h3>
|
||||
|
@ -83,18 +83,18 @@ function gdk_create_html_sitemap() {
|
|||
<div id="footer">
|
||||
查看网站首页:
|
||||
<strong>
|
||||
<a href="<?php echo esc_url( home_url() ); ?>/"><?php bloginfo( 'name'); ?></a>
|
||||
<a href="<?php echo esc_url(home_url()); ?>/"><?php bloginfo('name'); ?></a>
|
||||
</strong>
|
||||
</div>
|
||||
<br />
|
||||
<div style="text-align: center; font-size: 11px">
|
||||
Latest Update:
|
||||
<?php
|
||||
global $wpdb;
|
||||
$last = $wpdb->get_results("SELECT MAX(post_modified) AS MAX_m FROM $wpdb->posts WHERE (post_type = 'post' OR post_type = 'page') AND (post_status = 'publish' OR post_status = 'private')");
|
||||
$last = date('Y-m-d G:i:s', strtotime($last[0]->MAX_m));
|
||||
echo $last;
|
||||
?>
|
||||
<?php
|
||||
global $wpdb;
|
||||
$last = $wpdb->get_results("SELECT MAX(post_modified) AS MAX_m FROM $wpdb->posts WHERE (post_type = 'post' OR post_type = 'page') AND (post_status = 'publish' OR post_status = 'private')");
|
||||
$last = date('Y-m-d G:i:s', strtotime($last[0]->MAX_m));
|
||||
echo $last;
|
||||
?>
|
||||
<br />
|
||||
<br />
|
||||
</div>
|
||||
|
@ -103,9 +103,10 @@ function gdk_create_html_sitemap() {
|
|||
<?php
|
||||
}
|
||||
|
||||
function gdk_clear_sitemap_html_cache(){
|
||||
delete_transient( 'gdk-sitemap-html' );
|
||||
function gdk_clear_sitemap_html_cache()
|
||||
{
|
||||
delete_transient('gdk-sitemap-html');
|
||||
}
|
||||
add_action('publish_post', 'gdk_clear_sitemap_html_cache');
|
||||
add_action('publish_page', 'gdk_clear_sitemap_html_cache');
|
||||
add_action('save_post', 'gdk_clear_sitemap_html_cache' );
|
||||
add_action('save_post', 'gdk_clear_sitemap_html_cache');
|
Loading…
Reference in a new issue