function weixin_robot_credit_share_action_callback() { check_ajax_referer("weixin_share"); $weixin_openid = $_POST['weixin_openid']; if ($weixin_openid == false) { exit; } $share_type = $_POST['share_type']; $post_id = $_POST['post_id']; if ($weixin_openid && $share_type && $post_id) { if ($share_type == 'SendAppMessage') { $credit_change = weixin_robot_get_setting('weixin_SendAppMessage_credit'); $share_message = '发送文章给朋友'; } elseif ($share_type == 'ShareTimeline') { $credit_change = weixin_robot_get_setting('weixin_ShareTimeline_credit'); $share_message = '分享文章到朋友圈'; } elseif ($share_type == 'ShareWeibo') { $credit_change = weixin_robot_get_setting('weixin_ShareWeibo_credit'); $share_message = '分享文章到腾讯微博'; } elseif ($share_type == 'ShareFB') { $credit_change = weixin_robot_get_setting('weixin_SendAppMessage_credit'); $share_message = '分享文章到Facebook'; } global $wpdb; if ($wpdb->query($wpdb->prepare("SELECT * FROM {$wpdb->weixin_credits} WHERE weixin_openid=%s AND type=%s AND post_id=%d", $weixin_openid, $share_type, $post_id))) { $share_message = '你已经执行过该操作了'; } else { $credit_change = weixin_robot_add_credit(array('type' => $share_type, 'weixin_openid' => $weixin_openid, 'post_id' => $post_id, 'credit_change' => $credit_change, 'note' => $share_message)); if ($credit_change == 0) { $share_message = '你当日加分已经超过' . weixin_robot_get_setting('weixin_day_credit_limit') . '分了。'; } else { $share_message = $share_message . ',获取 ' . $credit_change . ' 积分!'; } } echo $share_message; } exit; }
function weixin_robot_credit_page() { global $plugin_page, $current_user; if (isset($_POST['weixin_robot_credit_nonce']) && wp_verify_nonce($_POST['weixin_robot_credit_nonce'], 'weixin_robot')) { $weixin_openid = stripslashes(trim($_POST['weixin_openid'])); $credit_change = stripslashes(trim($_POST['credit_change'])); $note = stripslashes(trim($_POST['note'])); if (empty($weixin_openid) || empty($credit_change)) { $err_msg = '微信 OpenID 和 积分不能为空'; } elseif (weixin_robot_get_user($weixin_openid, 'local') === false) { $err_msg = '微信OpenID不存在'; } elseif (!is_numeric($credit_change)) { $err_msg = '积分必须为数字'; } if (empty($err_msg)) { $args = array('type' => 'manual', 'weixin_openid' => $weixin_openid, 'operator_id' => $current_user->ID, 'credit_change' => $credit_change, 'exp_change' => 0, 'note' => $note); weixin_robot_add_credit($args); $succeed_msg = '修改成功'; } } ?> <div class="wrap"> <div id="icon-weixin-robot" class="icon32"><br></div> <h2> <?php if (isset($_GET['action']) && $_GET['action'] == 'add') { ?> 手工修改积分 <a href="<?php echo admin_url('admin.php?page=' . $plugin_page); ?> " class="add-new-h2">返回列表</a> <?php } else { ?> 微信积分记录 <a href="<?php echo admin_url('admin.php?page=' . $plugin_page); ?> &action=add" class="add-new-h2">手工修改</a> <?php } ?> </h2> <?php if (!empty($succeed_msg)) { ?> <div class="updated"> <p><?php echo $succeed_msg; ?> </p> </div> <?php } ?> <?php if (!empty($err_msg)) { ?> <div class="error" style="color:red;"> <p>错误:<?php echo $err_msg; ?> </p> </div> <?php } ?> <?php if (isset($_GET['action']) && $_GET['action'] == 'add') { weixin_robot_credit_add(); } else { weixin_robot_credit_list(); } ?> </div> <?php }