diff --git a/assets/js/gdk.js b/assets/js/gdk.js index c65b2e7..7afdd9b 100644 --- a/assets/js/gdk.js +++ b/assets/js/gdk.js @@ -541,6 +541,24 @@ 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") + + }; + $.post(ajax.url, ajax_data, function (b) { + b = $.trim(b); + if ('' !== b) { + show_hide_content('#hide_notice', b); + } + }); + }); diff --git a/class/points/class-points-shortcodes.php b/class/points/class-points-shortcodes.php index 42c947b..264032d 100644 --- a/class/points/class-points-shortcodes.php +++ b/class/points/class-points-shortcodes.php @@ -63,50 +63,37 @@ class GDK_Points_Shortcodes { public static function pay($atts, $content = null) { global $wpdb; $user_id = get_current_user_id(); - $description = get_the_ID(); - $result = $wpdb->get_row("SELECT description FROM " . GDK_Points_Database::points_get_table("users") . " WHERE user_id=" . $user_id . " AND description=" . $description . " AND status='accepted' LIMIT 0, 3;", ARRAY_A )['description']; //验证是否支付 + $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 = ''; - $pay_content = get_post_meta($description, 'pay_content', true); - if (!empty($pay_content) && $pay_content != $content) { - update_post_meta($description, 'pay_content', $content, true); - } else { - add_post_meta($description, 'pay_content', $content, true); - } + add_post_meta($pid, '_point_content', $content, true) or update_post_meta($pid, '_point_content', $content);//没有新建,有就更新 if (is_user_logged_in()) { - if ($result == $description || current_user_can('administrator')) { - $notice.= '
'; + if ($result == $pid || current_user_can('administrator')) { + $notice.= '
'; $notice.= $content; - $notice.= '
'; + $notice.= '
'; } else { if (GDK_Points::get_user_total_points($user_id, 'accepted') < $point) { - $notice.= '
'; - $notice.= '

本段内容需要支付 ' . $point . '金币查看

'; - $notice.= '

您当前拥有 ' . GDK_Points::get_user_total_points($user_id, 'accepted') . ' 金币,您的金币不足,请充值

'; - $notice.= '

立即充值

'; - $notice.= '
'; + $notice.= '
付费内容'; + $notice.= '

当前隐藏内容需要支付

'.$point.'金币'; + $notice.= '

您当前拥有'.GDK_Points::get_user_total_points($user_id, 'accepted').'金币,金币不足,请充值

'; + $notice.= buy_points(); + $notice.= '
'; } else { - $notice.= '
'; - $notice.= '

本段内容需要付费查看,您当前拥有 ' . GDK_Points::get_user_total_points($user_id, 'accepted') . ' 金币

'; - $notice.= '

点击购买

'; - $notice.= '
'; - $notice.= '

'; - echo ''; + $notice.= '
付费内容'; + $notice.= '

当前隐藏内容需要支付

'.$point.'金币'; + $notice.= '

您当前拥有'.GDK_Points::get_user_total_points($user_id, 'accepted').'金币

'; + $notice.= '

'; + $notice.= '
'; } } } else { - global $wp; - $current_url = home_url(add_query_arg([] , $wp->request)); - $login_uri = '点击登录'; - $notice.= '
'; - $notice.= '

查看本段内容需要支付 ' . $point . ' 金币

'; - $notice.= '

您尚未登录,请 ' . $login_uri . ' 或者 立即注册

'; - $notice.= '
'; + $notice.= '
付费内容'; + $notice.= '

当前隐藏内容需要支付

'.$point.'金币'; + $notice.= '

您当前尚未登陆,请登陆后查看

'; + $notice.= weixin_login_btn(); + $notice.= '
'; } return $notice; } diff --git a/functions/Ajax.php b/functions/Ajax.php index 5aa7798..bd0850e 100644 --- a/functions/Ajax.php +++ b/functions/Ajax.php @@ -259,3 +259,19 @@ function 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); + } +} +add_action( 'wp_ajax_gdk_pay_buy', 'point_buy' ); +add_action( 'wp_ajax_nopriv_gdk_pay_buy', 'point_buy' ); \ No newline at end of file diff --git a/functions/Common.php b/functions/Common.php index 5be2f25..42859d1 100644 --- a/functions/Common.php +++ b/functions/Common.php @@ -5,6 +5,7 @@ * 获取摘要 */ function gdk_print_excerpt($length, $post = null, $echo = true, $more = '...') { + global $post; $text = $post->post_excerpt; @@ -144,7 +145,7 @@ function nc_like_init($key, $direct = false) if ($action == 'do') { $expire = time() + 99999999; if (!isset($_COOKIE[$key.'_'.$id]) || $direct) { - setcookie($key.'_'.$id, $id, $expire, '/', $domain, false); + gdk_set_cookie($key.'_'.$id, $id, $expire); if (!$lh_raters || !is_numeric($lh_raters)) { update_post_meta($id, $key, 1); } else { @@ -155,7 +156,7 @@ function nc_like_init($key, $direct = false) if ($action == 'undo' && !$direct) { $expire = time() - 1; if (isset($_COOKIE[$key.'_'.$id])) { - setcookie($key.'_'.$id, $id, $expire, '/', $domain, false); + gdk_set_cookie($key.'_'.$id, $id, $expire); update_post_meta($id, $key, ($lh_raters - 1)); } } @@ -997,7 +998,7 @@ function buy_points(){

'; }else{// no login - $result = '
本页面需要您登录才可以操作,请先 点击登录 或者立即注册
'; + $result = '
本页面需要您登录才可以操作,请先 '.weixin_login_btn().' 或者立即注册
'; } return $result; } @@ -1059,7 +1060,7 @@ function weixin_login_btn(){ $result .= ''; } } - $result .= '

您已登陆

您的ID是:'.$user_id.'

您的昵称是:'.$user->nickname.'

'; + //$result .= '

您已登陆

您的ID是:'.$user_id.'

您的昵称是:'.$user->nickname.'

'; } return $result; } @@ -1129,13 +1130,6 @@ function editorial_hover_color( $hex, $steps ) { /** * Get minified css and removed space - * - * @since 1.2.5 - */ -/** - * Minify CSS - * - * @since 1.0.0 */ function pwd_minify_css( $css ) { @@ -1220,7 +1214,8 @@ function gdk_tag_dropdown(){ return $gdk_option_tag; } -function base64EncodeImage ($image_file) { +//转化图片为base64格式 +function base64img ($image_file) { $base64_image = ''; $image_info = getimagesize($image_file); $image_data = file_get_contents($image_file); diff --git a/functions/shortcode.php b/functions/shortcode.php index aa9ae68..47a7e16 100644 --- a/functions/shortcode.php +++ b/functions/shortcode.php @@ -202,7 +202,9 @@ add_shortcode('vip', 'gdk_login_to_read'); 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' ) || gdk_is_weixin()) { return $content; }//admin show + if ( current_user_can( 'administrator' ) ) { + return '
隐藏内容

' . $content . '

'; + }//admin show return '