diff --git a/assets/assets_load.php b/assets/assets_load.php index 235bf6d..29c0035 100644 --- a/assets/assets_load.php +++ b/assets/assets_load.php @@ -1,13 +1,15 @@ wp_create_nonce('pui-nonce'))); + wp_localize_script('paste-upload-image', 'pui_vars', ['pui_nonce' => wp_create_nonce('pui-nonce')]); } } add_action('admin_enqueue_scripts', 'gdk_admin_enqueue_script'); @@ -15,33 +17,33 @@ add_action('admin_enqueue_scripts', 'gdk_admin_enqueue_script'); function gdk_enqueue_script_frontend() { if (!is_admin()) { - wp_enqueue_style( 'uikit', 'https://cdn.jsdelivr.net/npm/uikit@3.7.4/dist/css/uikit.min.css', false, GDK_PLUGIN_VER, 'all' ); + wp_enqueue_style('uikit', 'https://cdn.jsdelivr.net/npm/uikit@3.7.4/dist/css/uikit.min.css', false, GDK_PLUGIN_VER, 'all'); - wp_enqueue_style('gdk', GDK_BASE_URL . 'assets/css/gdk.css', false, GDK_PLUGIN_VER, 'all'); + wp_enqueue_style('gdk', GDK_BASE_URL.'assets/css/gdk.css', false, GDK_PLUGIN_VER, 'all'); wp_deregister_script('jquery'); wp_enqueue_script('jquery', 'https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.min.js', false, GDK_PLUGIN_VER, true); //加载自定义jQuery2.0.3 - // Comment Reply - if (is_singular() && comments_open() && get_option('thread_comments')) { - wp_enqueue_script('comment-reply'); - } - - wp_enqueue_script('libs', GDK_BASE_URL . 'assets/js/libs.min.js', ['jquery'], GDK_PLUGIN_VER, true); + // Comment Reply + if (is_singular() && comments_open() && get_option('thread_comments')) { + wp_enqueue_script('comment-reply'); + } + + wp_enqueue_script('libs', GDK_BASE_URL.'assets/js/libs.min.js', ['jquery'], GDK_PLUGIN_VER, true); wp_enqueue_script('uikit', 'https://cdn.jsdelivr.net/npm/uikit@3.7.4/dist/js/uikit.min.js', [], GDK_PLUGIN_VER, true); wp_enqueue_script('uikit-icon', 'https://cdn.jsdelivr.net/npm/uikit@3.7.4/dist/js/uikit-icons.min.js', [], GDK_PLUGIN_VER, true); - wp_enqueue_script('gdk', GDK_BASE_URL . 'assets/js/gdk.js', ['jquery'], GDK_PLUGIN_VER, true); + wp_enqueue_script('gdk', GDK_BASE_URL.'assets/js/gdk.js', ['jquery'], GDK_PLUGIN_VER, true); wp_localize_script('gdk', 'gdk', [ - 'ajaxurl' => admin_url('admin-ajax.php'), - 'pass_nonce' => wp_create_nonce('pass_nonce'), - 'pay_points' => wp_create_nonce('pay_points'), - 'check_pay_points' => wp_create_nonce('check_pay_points'), - 'check_pay_view' => wp_create_nonce('check_pay_view'), - 'check_code' => wp_create_nonce('check_code'), + 'ajaxurl' => admin_url('admin-ajax.php'), + 'pass_nonce' => wp_create_nonce('pass_nonce'), + 'pay_points' => wp_create_nonce('pay_points'), + 'check_pay_points' => wp_create_nonce('check_pay_points'), + 'check_pay_view' => wp_create_nonce('check_pay_view'), + 'check_code' => wp_create_nonce('check_code'), 'gdk_weauth_qr_gen' => wp_create_nonce('gdk_weauth_qr_gen'), - 'gdk_weauth_check' => wp_create_nonce('gdk_weauth_check'), - 'gdk_payjs_alipay' => gdk_option('gdk_payjs_alipay'), - 'user_id' => get_current_user_id(), - 'msg_nonce' => wp_create_nonce('msg_nonce'), + 'gdk_weauth_check' => wp_create_nonce('gdk_weauth_check'), + 'gdk_payjs_alipay' => gdk_option('gdk_payjs_alipay'), + 'user_id' => get_current_user_id(), + 'msg_nonce' => wp_create_nonce('msg_nonce'), ]); } } @@ -51,63 +53,115 @@ add_action('wp_enqueue_scripts', 'gdk_enqueue_script_frontend'); function gdk_admin_script() { ?> - - + - div>a:nth-child(20) { + background: #f6003c; + border-color: #f6003c; + color: #fff + } + + .wp-block { + max-width: 45pc + } + + .wp-block[data-align=wide] { + max-width: 810pt + } + + .wp-block[data-align=full] { + max-width: none + } + + #activity-widget #the-comment-list .avatar { + width: 50px + } + + .form-field-download_name, + .form-field-download_size { + width: 45%; + float: left + } + + .form-field-download_link { + clear: both + } + +mchid = $config['mchid']; - $this->key = $config['key']; - $api_url = $config['api_url'] ?? 'https://payjs.cn/api/'; - - $this->api_url_native = $api_url . 'native'; - $this->api_url_cashier = $api_url . 'cashier'; - $this->api_url_mweb = $api_url . 'mweb'; - $this->api_url_close = $api_url . 'close'; - $this->api_url_check = $api_url . 'check'; + $this->key = $config['key']; + $api_url = $config['api_url'] ?? 'https://payjs.cn/api/'; + $this->api_url_native = $api_url.'native'; + $this->api_url_cashier = $api_url.'cashier'; + $this->api_url_mweb = $api_url.'mweb'; + $this->api_url_close = $api_url.'close'; + $this->api_url_check = $api_url.'check'; } // 扫码支付 public function native(array $data) { $this->url = $this->api_url_native; + return $this->post($data); } + // MWEB(H5) 支付 public function mweb(array $data) { $this->url = $this->api_url_mweb; + return $this->post($data); } + // 收银台模式 public function cashier(array $data) { $this->url = $this->api_url_cashier; - $data = $this->sign($data); - $url = $this->url . '?' . http_build_query($data); - return $url; + $data = $this->sign($data); + + return $this->url.'?'.http_build_query($data); } // 检查订单 public function check($payjs_order_id) { $this->url = $this->api_url_check; - $data = ['payjs_order_id' => $payjs_order_id]; + $data = ['payjs_order_id' => $payjs_order_id]; + return $this->post($data); } @@ -57,11 +63,11 @@ class GDK_Payjs public function notify() { $data = $_POST; - if ($this->checkSign($data) === true) { + if (true === $this->checkSign($data)) { return $data; - } else { - exit("验签失败"); } + + exit('验签失败'); } // 数据签名 @@ -70,7 +76,8 @@ class GDK_Payjs $data['mchid'] = $this->mchid; array_filter($data); ksort($data); - $data['sign'] = strtoupper(md5(urldecode(http_build_query($data) . '&key=' . $this->key))); + $data['sign'] = strtoupper(md5(urldecode(http_build_query($data).'&key='.$this->key))); + return $data; } @@ -81,15 +88,17 @@ class GDK_Payjs unset($data['sign']); array_filter($data); ksort($data); - $sign = strtoupper(md5(urldecode(http_build_query($data) . '&key=' . $this->key))); + $sign = strtoupper(md5(urldecode(http_build_query($data).'&key='.$this->key))); + return $in_sign == $sign ? true : false; } // 数据发送 - public function post($data) { - $data = $this->sign($data); + public function post($data) + { + $data = $this->sign($data); $ch = curl_init(); - curl_setopt($ch, CURLOPT_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS ); + curl_setopt($ch, CURLOPT_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS); curl_setopt($ch, CURLOPT_URL, $this->url); curl_setopt($ch, CURLOPT_USERAGENT, 'HTTP CLIENT'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); @@ -99,7 +108,7 @@ class GDK_Payjs curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); $rst = curl_exec($ch); curl_close($ch); + return json_decode($rst, true); } - } diff --git a/class/aq_resizer.php b/class/aq_resizer.php index 5a39714..0e2da8f 100644 --- a/class/aq_resizer.php +++ b/class/aq_resizer.php @@ -7,57 +7,59 @@ * Author : Syamil MJ * Author URI : http://aquagraphite.com * License : WTFPL - http://sam.zoy.org/wtfpl/ - * Documentation : https://github.com/sy4mil/Aqua-Resizer/ + * Documentation : https://github.com/sy4mil/Aqua-Resizer/. + * + * @param string $url - (required) must be uploaded using wp media uploader + * @param int $width - (required) + * @param int $height - (optional) + * @param bool $crop - (optional) default to soft crop + * @param bool $single - (optional) returns an array if false + * @param bool $upscale - (optional) resizes smaller images * - * @param string $url - (required) must be uploaded using wp media uploader - * @param int $width - (required) - * @param int $height - (optional) - * @param bool $crop - (optional) default to soft crop - * @param bool $single - (optional) returns an array if false - * @param bool $upscale - (optional) resizes smaller images * @uses wp_upload_dir() * @uses image_resize_dimensions() * @uses wp_get_image_editor() * - * @return str|array + * @return array|string */ - if (!class_exists('Aq_Resize')) { class Aq_Exception extends Exception - {} + { + } class Aq_Resize { - /** - * The singleton instance - */ - private static $__instance = null; - /** * Should an Aq_Exception be thrown on error? * If false (default), then the error will just be logged. */ public $throwOnError = false; + /** + * The singleton instance. + */ + private static $__instance; /** - * No initialization allowed + * No initialization allowed. */ private function __construct() - {} + { + } /** - * No cloning allowed + * No cloning allowed. */ private function __clone() - {} + { + } /** - * For your custom default usage you may want to initialize an Aq_Resize object by yourself and then have own defaults + * For your custom default usage you may want to initialize an Aq_Resize object by yourself and then have own defaults. */ public static function getInstance() { - if (self::$instance == null) { - self::$instance = new self; + if (null == self::$instance) { + self::$instance = new self(); } return self::$instance; @@ -65,6 +67,13 @@ if (!class_exists('Aq_Resize')) { /** * Run, forest. + * + * @param mixed $url + * @param null|mixed $width + * @param null|mixed $height + * @param null|mixed $crop + * @param mixed $single + * @param mixed $upscale */ public function process($url, $width = null, $height = null, $crop = null, $single = true, $upscale = false) { @@ -80,17 +89,17 @@ if (!class_exists('Aq_Resize')) { // Caipt'n, ready to hook. if (true === $upscale) { - add_filter('image_resize_dimensions', array($this, 'aq_upscale'), 10, 6); + add_filter('image_resize_dimensions', [$this, 'aq_upscale'], 10, 6); } // Define upload path & dir. $upload_info = wp_upload_dir(); - $upload_dir = $upload_info['basedir']; - $upload_url = $upload_info['baseurl']; + $upload_dir = $upload_info['basedir']; + $upload_url = $upload_info['baseurl']; - $http_prefix = "http://"; - $https_prefix = "https://"; - $relative_prefix = "//"; // The protocol-relative URL + $http_prefix = 'http://'; + $https_prefix = 'https://'; + $relative_prefix = '//'; // The protocol-relative URL /* if the $url scheme differs from $upload_url scheme, make them match if the schemes differe, images don't show up. */ @@ -99,42 +108,42 @@ if (!class_exists('Aq_Resize')) { } elseif (!strncmp($url, $http_prefix, strlen($http_prefix))) { //if url begins with http:// make $upload_url begin with http:// as well $upload_url = str_replace($https_prefix, $http_prefix, $upload_url); } elseif (!strncmp($url, $relative_prefix, strlen($relative_prefix))) { //if url begins with // make $upload_url begin with // as well - $upload_url = str_replace(array(0 => "$http_prefix", 1 => "$https_prefix"), $relative_prefix, $upload_url); + $upload_url = str_replace([0 => "{$http_prefix}", 1 => "{$https_prefix}"], $relative_prefix, $upload_url); } // Check if $img_url is local. if (false === strpos($url, $upload_url)) { - throw new Aq_Exception('图片必须是本地图片: ' . $url); + throw new Aq_Exception('图片必须是本地图片: '.$url); } // Define path of image. $rel_path = str_replace($upload_url, '', $url); - $img_path = $upload_dir . $rel_path; + $img_path = $upload_dir.$rel_path; // Check if img path exists, and is an image indeed. if (!file_exists($img_path) or !getimagesize($img_path)) { - throw new Aq_Exception('图片不存在或者不是一个图片文件: ' . $img_path); + throw new Aq_Exception('图片不存在或者不是一个图片文件: '.$img_path); } // Get image info. - $info = pathinfo($img_path); - $ext = $info['extension']; + $info = pathinfo($img_path); + $ext = $info['extension']; list($orig_w, $orig_h) = getimagesize($img_path); // Get image size after cropping. - $dims = image_resize_dimensions($orig_w, $orig_h, $width, $height, $crop); + $dims = image_resize_dimensions($orig_w, $orig_h, $width, $height, $crop); $dst_w = $dims[4]; $dst_h = $dims[5]; // Return the original image only if it exactly fits the needed measures. if (!$dims || (((null === $height && $orig_w == $width) xor (null === $width && $orig_h == $height)) xor ($height == $orig_h && $width == $orig_w))) { $img_url = $url; - $dst_w = $orig_w; - $dst_h = $orig_h; + $dst_w = $orig_w; + $dst_h = $orig_h; } else { // Use this to check if cropped image already exists, so we can return that instead. - $suffix = "{$dst_w}x{$dst_h}"; - $dst_rel_path = str_replace('.' . $ext, '', $rel_path); + $suffix = "{$dst_w}x{$dst_h}"; + $dst_rel_path = str_replace('.'.$ext, '', $rel_path); $destfilename = "{$upload_dir}{$dst_rel_path}-{$suffix}.{$ext}"; if (!$dims || (true == $crop && false == $upscale && ($dst_w < $width || $dst_h < $height))) { @@ -142,34 +151,32 @@ if (!class_exists('Aq_Resize')) { throw new Aq_Exception('Unable to resize image because image_resize_dimensions() failed'); } // Else check if cache exists. - elseif (file_exists($destfilename) && getimagesize($destfilename)) { + if (file_exists($destfilename) && getimagesize($destfilename)) { $img_url = "{$upload_url}{$dst_rel_path}-{$suffix}.{$ext}"; } // Else, we resize the image and return the new resized image url. else { - $editor = wp_get_image_editor($img_path); if (is_wp_error($editor) || is_wp_error($editor->resize($width, $height, $crop))) { - throw new Aq_Exception('Unable to get WP_Image_Editor: ' . - $editor->get_error_message() . ' (is GD or ImageMagick installed?)'); + throw new Aq_Exception('Unable to get WP_Image_Editor: '. + $editor->get_error_message().' (is GD or ImageMagick installed?)'); } $resized_file = $editor->save(); if (!is_wp_error($resized_file)) { $resized_rel_path = str_replace($upload_dir, '', $resized_file['path']); - $img_url = $upload_url . $resized_rel_path; + $img_url = $upload_url.$resized_rel_path; } else { - throw new Aq_Exception('Unable to save resized image file: ' . $editor->get_error_message()); + throw new Aq_Exception('Unable to save resized image file: '.$editor->get_error_message()); } - } } // Okay, leave the ship. if (true === $upscale) { - remove_filter('image_resize_dimensions', array($this, 'aq_upscale')); + remove_filter('image_resize_dimensions', [$this, 'aq_upscale']); } // Return the output. @@ -178,29 +185,35 @@ if (!class_exists('Aq_Resize')) { $image = $img_url; } else { // array return. - $image = array( + $image = [ 0 => $img_url, 1 => $dst_w, 2 => $dst_h, - ); + ]; } return $image; } catch (Aq_Exception $ex) { - error_log('Aq_Resize.process() error: ' . $ex->getMessage()); + error_log('Aq_Resize.process() error: '.$ex->getMessage()); if ($this->throwOnError) { // Bubble up exception. throw $ex; - } else { - // Return false, so that this patch is backwards-compatible. - return false; } + // Return false, so that this patch is backwards-compatible. + return false; } } /** - * Callback to overwrite WP computing of thumbnail measures + * Callback to overwrite WP computing of thumbnail measures. + * + * @param mixed $default + * @param mixed $orig_w + * @param mixed $orig_h + * @param mixed $dest_w + * @param mixed $dest_h + * @param mixed $crop */ public function aq_upscale($default, $orig_w, $orig_h, $dest_w, $dest_h, $crop) { @@ -211,8 +224,8 @@ if (!class_exists('Aq_Resize')) { // Here is the point we allow to use larger image size than the original one. $aspect_ratio = $orig_w / $orig_h; - $new_w = $dest_w; - $new_h = $dest_h; + $new_w = $dest_w; + $new_h = $dest_h; if (!$new_w) { $new_w = intval($new_h * $aspect_ratio); @@ -230,27 +243,34 @@ if (!class_exists('Aq_Resize')) { $s_x = floor(($orig_w - $crop_w) / 2); $s_y = floor(($orig_h - $crop_h) / 2); - return array(0, 0, (int)$s_x, (int)$s_y, (int)$new_w, (int)$new_h, (int)$crop_w, (int)$crop_h); + return [0, 0, (int) $s_x, (int) $s_y, (int) $new_w, (int) $new_h, (int) $crop_w, (int) $crop_h]; } } } if (!function_exists('aq_resize')) { - /** * This is just a tiny wrapper function for the class above so that there is no - * need to change any code in your own WP themes. Usage is still the same :) + * need to change any code in your own WP themes. Usage is still the same :). + * + * @param mixed $url + * @param null|mixed $width + * @param null|mixed $height + * @param null|mixed $crop + * @param mixed $single + * @param mixed $upscale */ function aq_resize($url, $width = null, $height = null, $crop = null, $single = true, $upscale = false) { - /* WPML Fix */ + // WPML Fix if (defined('ICL_SITEPRESS_VERSION')) { global $sitepress; $url = $sitepress->convert_url($url, $sitepress->get_default_language()); } - /* WPML Fix */ + // WPML Fix $aq_resize = Aq_Resize::getInstance(); + return $aq_resize->process($url, $width, $height, $crop, $single, $upscale); } } diff --git a/class/class_load.php b/class/class_load.php index bc6a427..dd2f353 100644 --- a/class/class_load.php +++ b/class/class_load.php @@ -3,11 +3,13 @@ include 'local_avatars.php'; //本地头像 include 'updates.php'; //在线更新 -include( 'widget_cache.php' );//小工具缓存 + +include 'widget_cache.php'; //小工具缓存 include 'Payjs.php'; //支付功能 + include 'points/points.php'; //积分功能 include 'aq_resizer.php'; //缩略图功能 -include 'wechat.php'; //微信功能 +include 'wechat.php'; //微信功能 diff --git a/class/local_avatars.php b/class/local_avatars.php index 7f3d3ba..3f1bd9d 100644 --- a/class/local_avatars.php +++ b/class/local_avatars.php @@ -4,70 +4,76 @@ class gdk_local_avatars { private $__user_id_being_edited; + public function __construct() { - add_action('admin_init', array( + add_action('admin_init', [ $this, 'admin_init', - )); - add_action('show_user_profile', array( + ]); + add_action('show_user_profile', [ $this, 'edit_user_profile', - )); - add_action('edit_user_profile', array( + ]); + add_action('edit_user_profile', [ $this, 'edit_user_profile', - )); - add_action('personal_options_update', array( + ]); + add_action('personal_options_update', [ $this, 'edit_user_profile_update', - )); - add_action('edit_user_profile_update', array( + ]); + add_action('edit_user_profile_update', [ $this, 'edit_user_profile_update', - )); - add_filter('get_avatar', array( + ]); + add_filter('get_avatar', [ $this, 'get_avatar', - ), 10, 5); - add_filter('avatar_defaults', array( + ], 10, 5); + add_filter('avatar_defaults', [ $this, 'avatar_defaults', - )); + ]); } + public function admin_init() { - register_setting('discussion', 'gdk_local_avatars_caps', array( + register_setting('discussion', 'gdk_local_avatars_caps', [ $this, 'sanitize_options', - )); - add_settings_field('basic-user-avatars-caps', '本地上传头像权限管理', array( + ]); + add_settings_field('basic-user-avatars-caps', '本地上传头像权限管理', [ $this, 'avatar_settings_field', - ), 'discussion', 'avatars'); + ], 'discussion', 'avatars'); } + public function avatar_settings_field($args) { - $options = get_option('gdk_local_avatars_caps'); - ?> - - + +ID; } elseif (is_object($id_or_email) && !empty($id_or_email->user_id)) { - $user_id = (int)$id_or_email->user_id; + $user_id = (int) $id_or_email->user_id; } if (empty($user_id)) { @@ -79,41 +85,43 @@ checked($options['gdk_local_avatars_caps'], 1); ?>/>仅具有头像上传权限 return $avatar; } - $size = (int)$size; + $size = (int) $size; if (empty($alt)) { $alt = get_the_author_meta('display_name', $user_id); } if (empty($local_avatars[$size])) { - $upload_path = wp_upload_dir(); + $upload_path = wp_upload_dir(); $avatar_full_path = str_replace($upload_path['baseurl'], $upload_path['basedir'], $local_avatars['full']); - $image = wp_get_image_editor($avatar_full_path); + $image = wp_get_image_editor($avatar_full_path); if (!is_wp_error($image)) { $image->resize($size, $size, true); $image_sized = $image->save(); } $local_avatars[$size] = is_wp_error($image_sized) ? $local_avatars[$size] = $local_avatars['full'] : str_replace($upload_path['basedir'], $upload_path['baseurl'], $image_sized['path']); update_user_meta($user_id, 'simple_local_avatar', $local_avatars); - } elseif (substr($local_avatars[$size], 0, 4) != 'http') { + } elseif ('http' != substr($local_avatars[$size], 0, 4)) { $local_avatars[$size] = home_url($local_avatars[$size]); } $author_class = is_author($user_id) ? ' current-author' : ''; - $avatar = ""; + $avatar = ""; + return apply_filters('simple_local_avatar', $avatar); } + public function edit_user_profile($profileuser) { ?> -
- |
- 头像
+
|
+
---|
您的金币金额被管理员调整,请查收!
如果您的金币金额有异常,请您在第一时间和我们取得联系哦,联系邮箱:' . get_bloginfo('admin_email') . '
'; - $message = mail_temp($mail_title, $mail_cotent, home_url(), get_bloginfo('name')); +如果您的金币金额有异常,请您在第一时间和我们取得联系哦,联系邮箱:'.get_bloginfo('admin_email').'
'; + $message = gdk_mail_temp($mail_title, $mail_cotent, home_url(), get_bloginfo('name')); $headers = "Content-Type:text/html;charset=UTF-8\n"; - wp_mail($usermail, 'Hi,' . $username . ',金币账户金额变动通知!', $message, $headers); + wp_mail($usermail, 'Hi,'.$username.',金币账户金额变动通知!', $message, $headers); } } - $alert = "金币已更新"; + $alert = '金币已更新'; } - if (isset($_GET["action"])) { - $action = $_GET["action"]; - if ($action !== null) { + if (isset($_GET['action'])) { + $action = $_GET['action']; + if (null !== $action) { switch ($action) { case 'edit': - if (isset($_GET['point_id']) && ($_GET['point_id'] !== null)) { + if (isset($_GET['point_id']) && (null !== $_GET['point_id'])) { return self::points_admin_points_edit(intval($_GET['point_id'])); - } else { - return self::points_admin_points_edit(); } + + return self::points_admin_points_edit(); + break; + case 'delete': - if ($_GET['point_id'] !== null) { + if (null !== $_GET['point_id']) { if (current_user_can('administrator')) { GDK_Points::remove_points($_GET['point_id']); global $wpdb; - $wcu_sql = "DELETE FROM " . GDK_Points_Database::points_get_table("users") . " WHERE status = 'removed'"; + $wcu_sql = 'DELETE FROM '.GDK_Points_Database::points_get_table('users')." WHERE status = 'removed'"; $wpdb->query($wcu_sql); - $alert = "金币已删除"; + $alert = '金币已删除'; } } + break; } } } - if ($alert != "") { - echo 'No users
'; } + return $output; } + public static function points_user_points($atts, $content = null) { - $output = ""; - $options = shortcode_atts(['id' => ""], + $output = ''; + $options = shortcode_atts( + ['id' => ''], $atts ); extract($options); - if ($id == "") { + if ('' == $id) { $id = get_current_user_id(); } - if ($id !== 0) { + if (0 !== $id) { $points = GDK_Points::get_user_total_points($id, 'accepted'); $output .= $points; } + return $output; } - /*付费可见短代码开始*/ + // 付费可见短代码开始 public static function pay($atts, $content = null) { - $content = do_shortcode($content); + $content = do_shortcode($content); global $wpdb; $user_id = get_current_user_id(); - $pid = get_the_ID(); - $result = $wpdb->get_row("SELECT description FROM " . GDK_Points_Database::points_get_table("users") . " WHERE user_id=" . $user_id . " AND description=" . $pid . " AND status='accepted' LIMIT 0, 3;", ARRAY_A)['description']; //验证是否支付 - extract(shortcode_atts(['point' => "10"], $atts)); + $pid = get_the_ID(); + $result = $wpdb->get_row('SELECT description FROM '.GDK_Points_Database::points_get_table('users').' WHERE user_id='.$user_id.' AND description='.$pid." AND status='accepted' LIMIT 0, 3;", ARRAY_A)['description']; //验证是否支付 + extract(shortcode_atts(['point' => '10'], $atts)); $notice = ''; add_post_meta($pid, '_point_content', $content, true) or update_post_meta($pid, '_point_content', $content); //没有新建,有就更新 if (is_user_logged_in()) { @@ -82,45 +86,50 @@ class GDK_Points_Shortcodes } else { if (GDK_Points::get_user_total_points($user_id, 'accepted') < $point) { $notice .= ''; } else { $notice .= ''; } } } else { $notice .= ''; } + return $notice; } - /*付费可见短代码结束*/ + + // 付费可见短代码结束 /** * Shortcode. 显示用户的金币细节 + * + * @param mixed $atts + * @param null|mixed $content */ public static function points_user_points_details($atts, $content = null) { $options = shortcode_atts( [ - 'user_id' => '', - 'order_by' => 'point_id', - 'order' => 'DESC', + 'user_id' => '', + 'order_by' => 'point_id', + 'order' => 'DESC', 'description' => true, ], $atts ); extract($options); date_default_timezone_set('Asia/Shanghai'); - if (is_string($description) && (($description == '0') || (strtolower($description) == 'false'))) { + if (is_string($description) && (('0' == $description) || ('false' == strtolower($description)))) { $description = false; } @@ -131,29 +140,33 @@ class GDK_Points_Shortcodes global $wp_query; $curauth = $wp_query->get_queried_object(); $user_id = $curauth->ID; - $points = GDK_Points::get_points_by_user($user_id); - $output = '日期时间' . - ' | 金币 | ' . - '类别 | ' . - '状态 | ' . - $desc_th . + $points = GDK_Points::get_points_by_user($user_id); + $output = '
---|
日期时间'. + ' | 金币 | '. + '类别 | '. + '状态 | '. + $desc_th. '' . $point->description . ' | '; + $desc_td = ''.$point->description.' | '; } - if ($point->points > 0) {$leibie = '充值';} elseif ($point->points < 0) {$leibie = '消费';} - $output .= '
---|---|---|---|
' . $point->datetime . ' | ' . - '' . $point->points . ' | ' . - '' . $leibie . ' | ' . - '' . $point->status . ' | ' . - $desc_td . + if ($point->points > 0) { + $leibie = '充值'; + } elseif ($point->points < 0) { + $leibie = '消费'; + } + $output .= '
'.$point->datetime.' | '. + ''.$point->points.' | '. + ''.$leibie.' | '. + ''.$point->status.' | '. + $desc_td. '
BENCHMARK | |||
till '.$markerId.': | '.number_format($thisTime-$lastTime, 6).'s | ||
till '.$markerId.': | '.number_format($thisTime - $lastTime, 6).'s | ||
TOTAL: | '.number_format($lastTime-$startTime, 6).'s | ||
TOTAL: | '.number_format($lastTime - $startTime, 6).'s |
- get_field_id('wc_cache'); ?>" name="get_field_name('wc_cache'); ?>" type="checkbox" /> - -
- + "thumb", - "title" => "自定义缩略图", - "description" => "这里可以输入您的自定义缩略图链接", - "type" => "text", - "scope" => ['post'], - "capability" => "edit_posts", - ), - array( - "name" => "download_name", - "title" => "单页下载文件名字", - "description" => "这里可以输入您的下载文件的名字", - "type" => "text", - "scope" => ['post'], - "capability" => "edit_posts", - ), - array( - "name" => "download_size", - "title" => "单页下载文件大小", - "description" => "这里可以输入您的下载文件的大小,可以加上单位,比如:233KB或者233MB", - "type" => "text", - "scope" => ['post'], - "capability" => "edit_posts", - ), - array( - "name" => "download_link", - "title" => "单页下载下载链接", - "description" => "按照链接,名字,备注的格式,注意中间是用英文逗号,换行可添加多个,举个栗子:https://www.baidu.com,百度官网,中国最大的搜索引擎网站
",
- "type" => "textarea",
- "scope" => ['post'],
- "capability" => "edit_posts",
- ),
- );
+ public $customFields = [
+ [
+ 'name' => 'thumb',
+ 'title' => '自定义缩略图',
+ 'description' => '这里可以输入您的自定义缩略图链接',
+ 'type' => 'text',
+ 'scope' => ['post'],
+ 'capability' => 'edit_posts',
+ ],
+ [
+ 'name' => 'download_name',
+ 'title' => '单页下载文件名字',
+ 'description' => '这里可以输入您的下载文件的名字',
+ 'type' => 'text',
+ 'scope' => ['post'],
+ 'capability' => 'edit_posts',
+ ],
+ [
+ 'name' => 'download_size',
+ 'title' => '单页下载文件大小',
+ 'description' => '这里可以输入您的下载文件的大小,可以加上单位,比如:233KB或者233MB',
+ 'type' => 'text',
+ 'scope' => ['post'],
+ 'capability' => 'edit_posts',
+ ],
+ [
+ 'name' => 'download_link',
+ 'title' => '单页下载下载链接',
+ 'description' => '按照链接,名字,备注的格式,注意中间是用英文逗号,换行可添加多个,举个栗子:https://www.baidu.com,百度官网,中国最大的搜索引擎网站
',
+ 'type' => 'textarea',
+ 'scope' => ['post'],
+ 'capability' => 'edit_posts',
+ ],
+ ];
+
/**
- * PHP 5 Constructor
+ * PHP 5 Constructor.
*/
public function __construct()
{
- add_action('admin_menu', array($this, 'createCustomFields'));
- add_action('save_post', array($this, 'saveCustomFields'), 1, 2);
+ add_action('admin_menu', [$this, 'createCustomFields']);
+ add_action('save_post', [$this, 'saveCustomFields'], 1, 2);
}
+
/**
- * 创建一组你自己的自定义栏目
+ * 创建一组你自己的自定义栏目.
*/
public function createCustomFields()
{
if (function_exists('add_meta_box')) {
foreach ($this->postTypes as $postType) {
- add_meta_box('my-custom-fields', '文章选项', array($this, 'displayCustomFields'), $postType, 'normal', 'high');
+ add_meta_box('my-custom-fields', '文章选项', [$this, 'displayCustomFields'], $postType, 'normal', 'high');
}
}
}
+
/**
* 在文章发布页显示出来面板
*/
public function displayCustomFields()
{
- global $post;
- ?>
- 设置已保存。
设置已重置。