mirror of
https://github.com/yunluo/gdk.git
synced 2024-06-19 22:15:11 +02:00
积分可见功能
This commit is contained in:
parent
f449e96cc4
commit
36b0871ab3
|
@ -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);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -63,50 +63,37 @@ class GDK_Points_Shortcodes {
|
||||||
public static function pay($atts, $content = null) {
|
public static function pay($atts, $content = null) {
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
$user_id = get_current_user_id();
|
$user_id = get_current_user_id();
|
||||||
$description = get_the_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=" . $description . " AND status='accepted' LIMIT 0, 3;", ARRAY_A )['description']; //验证是否支付
|
$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));
|
extract(shortcode_atts(['point' => "10"], $atts));
|
||||||
$notice = '';
|
$notice = '';
|
||||||
$pay_content = get_post_meta($description, 'pay_content', true);
|
add_post_meta($pid, '_point_content', $content, true) or update_post_meta($pid, '_point_content', $content);//没有新建,有就更新
|
||||||
if (!empty($pay_content) && $pay_content != $content) {
|
|
||||||
update_post_meta($description, 'pay_content', $content, true);
|
|
||||||
} else {
|
|
||||||
add_post_meta($description, 'pay_content', $content, true);
|
|
||||||
}
|
|
||||||
if (is_user_logged_in()) {
|
if (is_user_logged_in()) {
|
||||||
if ($result == $description || current_user_can('administrator')) {
|
if ($result == $pid || current_user_can('administrator')) {
|
||||||
$notice.= '<div class="alert alert-info"">';
|
$notice.= '<div class="cm-alert success">';
|
||||||
$notice.= $content;
|
$notice.= $content;
|
||||||
$notice.= '</div>';
|
$notice.= '</div>';
|
||||||
} else {
|
} else {
|
||||||
if (GDK_Points::get_user_total_points($user_id, 'accepted') < $point) {
|
if (GDK_Points::get_user_total_points($user_id, 'accepted') < $point) {
|
||||||
$notice.= '<div class="alert alert-info"">';
|
$notice.= '<fieldset id="hide_notice" class="fieldset"><legend class="legend">付费内容</legend>';
|
||||||
$notice.= '<p style="color:red;">本段内容需要支付 ' . $point . '金币查看</p>';
|
$notice.= '<p>当前隐藏内容需要支付</p><span class="cm-coin">'.$point.'金币</span>';
|
||||||
$notice.= '<p style="color:red;">您当前拥有 <em><strong>' . GDK_Points::get_user_total_points($user_id, 'accepted') . '</strong></em> 金币,您的金币不足,请充值</p>';
|
$notice.= '<p>您当前拥有<span class="red">'.GDK_Points::get_user_total_points($user_id, 'accepted').'</span>金币,金币不足,请充值</p>';
|
||||||
$notice.= '<p><a class="lhb" href="' . get_permalink(gdk_page_id('chongzhi')) . '" target="_blank" rel="nofollow" data-original-title="立即充值" title="">立即充值</a></p>';
|
$notice.= buy_points();
|
||||||
$notice.= '</div>';
|
$notice.= '</fieldset>';
|
||||||
} else {
|
} else {
|
||||||
$notice.= '<div id="pay_notice" class="alert alert-info"">';
|
$notice.= '<fieldset id="hide_notice" class="fieldset"><legend class="legend">付费内容</legend>';
|
||||||
$notice.= '<p style="color:red;">本段内容需要付费查看,您当前拥有 <em><strong>' . GDK_Points::get_user_total_points($user_id, 'accepted') . '</strong></em> 金币</p>';
|
$notice.= '<p>当前隐藏内容需要支付</p><span class="cm-coin">'.$point.'金币</span>';
|
||||||
$notice.= '<p><a class="lhb" style="cursor: pointer;" onclick="pay_point();">点击购买</a></p>';
|
$notice.= '<p>您当前拥有<span class="red">'.GDK_Points::get_user_total_points($user_id, 'accepted').'</span>金币</p>';
|
||||||
$notice.= '</div>';
|
$notice.= '<p><button class="cm-btn primary" id="pay_points" data-point="'.$point.'" data-userid="'.$user_id.'" data-action="gdk_pay_buy" data-id="'.$pid.'">点击购买</button></p>';
|
||||||
$notice.= '<p id="pay_success"></p>';
|
$notice.= '</fieldset>';
|
||||||
echo '<script type="text/javascript">
|
|
||||||
function pay_point() {
|
|
||||||
ajax.post("' . admin_url('admin-ajax.php') . '", "action=gdk_pay_buy&point=' . $point . '&userid=' . $user_id . '&id=' . $description . '", function(n) {
|
|
||||||
null != n && (document.getElementById("pay_notice").style.display = "none", document.getElementById("pay_success").innerHTML = "<div class=\"alert alert-info\">" + n + "</div>");
|
|
||||||
});
|
|
||||||
}</script>';
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
global $wp;
|
$notice.= '<fieldset id="hide_notice" class="fieldset"><legend class="legend">付费内容</legend>';
|
||||||
$current_url = home_url(add_query_arg([] , $wp->request));
|
$notice.= '<p>当前隐藏内容需要支付</p><span class="cm-coin">'.$point.'金币</span>';
|
||||||
$login_uri = '<a href="' . esc_url(wp_login_url($current_url)) . '" data-original-title="点击登录">点击登录</a>';
|
$notice.= '<p>您当前尚未登陆,请登陆后查看</p>';
|
||||||
$notice.= '<div class="alert alert-info"">';
|
$notice.= weixin_login_btn();
|
||||||
$notice.= '<p style="color:red;">查看本段内容需要支付 ' . $point . ' 金币</p>';
|
$notice.= '</fieldset>';
|
||||||
$notice.= '<p style="color:red;">您尚未登录,请 ' . $login_uri . ' 或者 <a href="' . esc_url(wp_registration_url()) . '">立即注册</a> </p>';
|
|
||||||
$notice.= '</div>';
|
|
||||||
}
|
}
|
||||||
return $notice;
|
return $notice;
|
||||||
}
|
}
|
||||||
|
|
|
@ -259,3 +259,19 @@ function bind_email_check(){
|
||||||
add_action( 'wp_ajax_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' );
|
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' );
|
|
@ -5,6 +5,7 @@
|
||||||
* 获取摘要
|
* 获取摘要
|
||||||
*/
|
*/
|
||||||
function gdk_print_excerpt($length, $post = null, $echo = true, $more = '...') {
|
function gdk_print_excerpt($length, $post = null, $echo = true, $more = '...') {
|
||||||
|
|
||||||
global $post;
|
global $post;
|
||||||
$text = $post->post_excerpt;
|
$text = $post->post_excerpt;
|
||||||
|
|
||||||
|
@ -144,7 +145,7 @@ function nc_like_init($key, $direct = false)
|
||||||
if ($action == 'do') {
|
if ($action == 'do') {
|
||||||
$expire = time() + 99999999;
|
$expire = time() + 99999999;
|
||||||
if (!isset($_COOKIE[$key.'_'.$id]) || $direct) {
|
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)) {
|
if (!$lh_raters || !is_numeric($lh_raters)) {
|
||||||
update_post_meta($id, $key, 1);
|
update_post_meta($id, $key, 1);
|
||||||
} else {
|
} else {
|
||||||
|
@ -155,7 +156,7 @@ function nc_like_init($key, $direct = false)
|
||||||
if ($action == 'undo' && !$direct) {
|
if ($action == 'undo' && !$direct) {
|
||||||
$expire = time() - 1;
|
$expire = time() - 1;
|
||||||
if (isset($_COOKIE[$key.'_'.$id])) {
|
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));
|
update_post_meta($id, $key, ($lh_raters - 1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -997,7 +998,7 @@ function buy_points(){
|
||||||
</p>
|
</p>
|
||||||
</form>';
|
</form>';
|
||||||
}else{// no login
|
}else{// no login
|
||||||
$result = '<div class=\'cm-alert error\'>本页面需要您登录才可以操作,请先 <a target="_blank" href="'.esc_url( wp_login_url( get_permalink() ) ).'">点击登录</a> 或者<a href="'.esc_url( wp_registration_url() ).'">立即注册</a></div>';
|
$result = '<div class=\'cm-alert error\'>本页面需要您登录才可以操作,请先 '.weixin_login_btn().' 或者<a href="'.esc_url( wp_registration_url() ).'">立即注册</a></div>';
|
||||||
}
|
}
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
@ -1059,7 +1060,7 @@ function weixin_login_btn(){
|
||||||
$result .= '<script>window.localStorage.setItem(\'ls-bind\',1);</script>';
|
$result .= '<script>window.localStorage.setItem(\'ls-bind\',1);</script>';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$result .= '<p>您已登陆</p><p>您的ID是:'.$user_id.'</p><p>您的昵称是:'.$user->nickname.'</p>';
|
//$result .= '<p>您已登陆</p><p>您的ID是:'.$user_id.'</p><p>您的昵称是:'.$user->nickname.'</p>';
|
||||||
}
|
}
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
@ -1129,13 +1130,6 @@ function editorial_hover_color( $hex, $steps ) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get minified css and removed space
|
* Get minified css and removed space
|
||||||
*
|
|
||||||
* @since 1.2.5
|
|
||||||
*/
|
|
||||||
/**
|
|
||||||
* Minify CSS
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
*/
|
||||||
function pwd_minify_css( $css ) {
|
function pwd_minify_css( $css ) {
|
||||||
|
|
||||||
|
@ -1220,7 +1214,8 @@ function gdk_tag_dropdown(){
|
||||||
return $gdk_option_tag;
|
return $gdk_option_tag;
|
||||||
}
|
}
|
||||||
|
|
||||||
function base64EncodeImage ($image_file) {
|
//转化图片为base64格式
|
||||||
|
function base64img ($image_file) {
|
||||||
$base64_image = '';
|
$base64_image = '';
|
||||||
$image_info = getimagesize($image_file);
|
$image_info = getimagesize($image_file);
|
||||||
$image_data = file_get_contents($image_file);
|
$image_data = file_get_contents($image_file);
|
||||||
|
|
|
@ -202,7 +202,9 @@ 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();
|
$pid = get_the_ID();
|
||||||
add_post_meta($pid, '_pass_content', $content, true) or update_post_meta($pid, '_pass_content', $content);
|
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 '<fieldset class="fieldset"><legend class="legend">隐藏内容</legend><p>' . $content . '</p></fieldset>';
|
||||||
|
}//admin show
|
||||||
return '<div class="cm-grid cm-card pass_viewbox">
|
return '<div class="cm-grid cm-card pass_viewbox">
|
||||||
<div class="cm-row">
|
<div class="cm-row">
|
||||||
<div class="cm-col-md-4">
|
<div class="cm-col-md-4">
|
||||||
|
|
Loading…
Reference in a new issue