Esempio n. 1
0
function tin_like_article()
{
    $pid = $_POST['pid'];
    $likes = get_post_meta($pid, 'tin_post_likes', true);
    $likes++;
    update_post_meta($pid, 'tin_post_likes', $likes);
    $uid = get_current_user_id();
    $return = 1;
    if ($uid) {
        $meta = get_user_meta($uid, 'tin_article_interaction', true);
        $meta = json_decode($meta);
        $now_date = date('Y-m-j');
        $credit = ot_get_option('tin_like_article_credit', 5);
        $times = ot_get_option('tin_like_article_credit_times', 5);
        $get = 0;
        if ($now_date != $meta->dated) {
            update_tin_credit($uid, $credit, 'add', 'tin_credit', sprintf(__('参与文章互动,获得%s积分', 'tinection'), $credit));
            $new_times = 1;
            $new_meta = json_encode(array('dated' => $now_date, 'times' => $new_times));
            update_user_meta($uid, 'tin_article_interaction', $new_meta);
            $get = 1;
        } else {
            if ($meta->times < $times) {
                update_tin_credit($uid, $credit, 'add', 'tin_credit', sprintf(__('参与文章互动,获得%s积分', 'tinection'), $credit));
                $new_times = $meta->times;
                $new_times++;
                $new_meta = json_encode(array('dated' => $now_date, 'times' => $new_times));
                update_user_meta($uid, 'tin_article_interaction', $new_meta);
                $get = 1;
            } else {
            }
        }
        $return = json_encode(array('get' => $get, 'credit' => $credit));
    }
    echo $return;
    exit;
}
Esempio n. 2
0
function tin_saledl_confirm_buy()
{
    $sid = $_POST['sid'];
    $pid = $_POST['pid'];
    $uid = $_POST['uid'];
    $saledl = get_post_meta($pid, 'tin_saledl', true);
    $saledlarray = explode(',', $saledl);
    $sidarray = explode('_', $sid);
    $sidarray[1] = isset($sidarray[1]) ? (int) $sidarray[1] : 1;
    $key = $sidarray[1] - 1;
    $saledlsinglearray = explode('|', $saledlarray[$key]);
    $saledlsinglearray[2] = isset($saledlsinglearray[2]) ? (int) $saledlsinglearray[2] : 0;
    $price = $saledlsinglearray[2];
    $credit = (int) get_user_meta($uid, 'tin_credit', true);
    if ($price <= $credit) {
        //查看是否购买防止重扣
        $hasbuy = get_tin_meta('buy_post_sdl', $uid);
        $hasbuyarray = explode(',', $hasbuy);
        if (!in_array($sid, $hasbuyarray)) {
            //扣除积分//发送站内信
            update_tin_credit($uid, $price, 'cut', 'tin_credit', '下载资源消费' . $price . '积分');
            //更新已消费积分
            if (get_user_meta($uid, 'tin_credit_void', true)) {
                $void = get_user_meta($uid, 'tin_credit_void', true);
                $void = $void + $price;
                update_user_meta($uid, 'tin_credit_void', $void);
            } else {
                add_user_meta($uid, 'tin_credit_void', $price, true);
            }
            //给资源发布者添加积分并更新积分消息记录
            tin_resource_dl_add_credit($uid, $pid, $sid);
            //默认下载奖励积分
            $author = get_post_field('post_author', $pid);
            update_tin_credit($author, $price, 'add', 'tin_credit', sprintf(__('你发布的文章《%1$s》中收费资源被其他用户下载,获得售价%2$s积分', 'tinection'), get_post_field('post_title', $pid), $price));
            //出售获得积分
            //添加用户已下载资源
            if (empty($hasbuy)) {
                update_tin_meta('buy_post_sdl', $sid, $uid);
            } else {
                $hasbuy .= ',' . $sid;
                update_tin_meta('buy_post_sdl', $hasbuy, $uid);
            }
            //更新资源购买次数
            $sourcemetakey = 'post_sdl_' . $sidarray[1];
            $sales = get_tin_meta($sourcemetakey, $pid) ? (int) get_tin_meta($sourcemetakey, $pid) : 0;
            $sales++;
            update_tin_meta($sourcemetakey, $sales, $pid);
            //发送邮件
            $user_info = get_userdata($uid);
            $to = $user_info->user_email;
            $title = '你在' . get_bloginfo('name') . '购买的内容';
            $saledlsinglearray[0] = isset($saledlsinglearray[0]) ? $saledlsinglearray[0] : '';
            $saledlsinglearray[1] = isset($saledlsinglearray[1]) ? $saledlsinglearray[1] : '';
            $saledlsinglearray[3] = isset($saledlsinglearray[3]) ? $saledlsinglearray[3] : '';
            $content = '<p>你在' . get_bloginfo('name') . '使用积分下载了以下内容:</p><p>' . $saledlsinglearray[0] . '</p><p>下载链接:<a href="' . $saledlsinglearray[1] . '" title="' . $saledlsinglearray[0] . '" target="_blank">' . $saledlsinglearray[1] . '</a></p><p>下载密码:' . $saledlsinglearray[3] . '</p><p>感谢你的来访与支持,祝生活愉快!</p>';
            $type = '付费下载';
            tin_basic_mail('', $to, $title, $content, $type);
            $success = 1;
            $credit = $credit - $price;
        } else {
            $success = 2;
        }
    } else {
        $success = 0;
    }
    $return = array('success' => $success, 'price' => $price, 'credit' => $credit);
    $return = json_encode($return);
    echo $return;
    exit;
}
Esempio n. 3
0
function add_user_credits_by_order($money, $user_id, $user_name, $from, $to)
{
    date_default_timezone_set('Asia/Shanghai');
    $ratio = ot_get_option('tin_cash_credit_ratio', 50);
    $credits = (int) ($ratio * $money);
    $admin_email = get_bloginfo('admin_email');
    $blogname = get_bloginfo('name');
    // add credits and msg
    update_tin_credit($user_id, $credits, 'add', 'tin_credit', sprintf(__('充值积分%1$s,花费%2$s元', 'tinection'), $credits, $money));
    // email
    $content = '<p>您已成功充值了' . $credits . '积分,当前积分为:' . $new_credits . ',如有任何疑问,请及时联系我们(Email:<a href="mailto:' . $admin_email . '" target="_blank">' . $admin_email . '</a>)。</p>';
    $html = store_email_template_wrap($user_name, $content);
    if (empty($from)) {
        $wp_email = 'no-reply@' . preg_replace('#^www\\.#', '', strtolower($_SERVER['SERVER_NAME']));
    } else {
        $wp_email = $from;
    }
    $title = '会员状态变更提醒';
    $fr = "From: \"" . $blogname . "\" <{$wp_email}>";
    $headers = "{$fr}\nContent-Type: text/html; charset=" . get_option('blog_charset') . "\n";
    wp_mail($to, $title, $html, $headers);
}
Esempio n. 4
0
function tin_daily_sign_callback()
{
    date_default_timezone_set('Asia/Shanghai');
    $msg = '';
    $success = 0;
    $credits = 0;
    if (!is_user_logged_in()) {
        $msg = '请先登录';
    } else {
        $user_info = wp_get_current_user();
        $date = date('Y-m-d H:i:s', time());
        $sign_date_meta = get_user_meta($user_info->ID, 'tin_daily_sign', true);
        $sign_date = date('Y-m-d', strtotime($sign_date_meta));
        $now_date = date('Y-m-d', time());
        if ($sign_date != $now_date) {
            update_user_meta($user_info->ID, 'tin_daily_sign', $date);
            $credits = ot_get_option('tin_daily_sign_credits', 10);
            $credit_msg = '每日签到赠送' . $credits . '积分';
            update_tin_credit($user_info->ID, $credits, 'add', 'tin_credit', $credit_msg);
            $success = 1;
            $msg = '签到成功,获得' . $credits . '积分';
        } else {
            $success = 1;
            $credits = 0;
        }
    }
    $return = array('msg' => $msg, 'success' => $success, 'credits' => $credits);
    echo json_encode($return);
    exit;
}
Esempio n. 5
0
function tin_pending_to_publish($post)
{
    $rec_post_num = (int) ot_get_option('tin_rec_post_num', '5');
    $rec_post_credit = (int) ot_get_option('tin_rec_post_credit', '50');
    $rec_post = (int) get_user_meta($post->post_author, 'tin_rec_post', true);
    if ($rec_post < $rec_post_num && $rec_post_credit) {
        //添加积分
        update_tin_credit($post->post_author, $rec_post_credit, 'add', 'tin_credit', sprintf(__('获得文章投稿奖励%1$s积分', 'tinection'), $rec_post_credit));
        //发送邮件
        $user_email = get_user_by('id', $post->post_author)->user_email;
        if (filter_var($user_email, FILTER_VALIDATE_EMAIL)) {
            $email_title = sprintf(__('你在%1$s上有新的文章发表', 'tinection'), get_bloginfo('name'));
            $email_content = sprintf(__('<h3>%1$s,你好!</h3><p>你的文章%2$s已经发表,快去看看吧!</p>', 'tinection'), get_user_by('id', $post->post_author)->display_name, '<a href="' . get_permalink($post->ID) . '" target="_blank">' . $post->post_title . '</a>');
            $message = tin_mail_template('投稿成功', $email_content);
            //~ wp_schedule_single_event( time() + 10, 'tin_send_email_event', array( $user_email , $email_title, $email_content ) );
            $wp_email = 'no-reply@' . preg_replace('#^www\\.#', '', strtolower($_SERVER['SERVER_NAME']));
            $from = "From: \"" . $name . "\" <{$wp_email}>";
            $headers = "{$from}\nContent-Type: text/html; charset=" . get_option('blog_charset') . "\n";
            wp_mail($user_email, $email_title, $message, $headers);
        }
    }
    update_user_meta($post->post_author, 'tin_rec_post', $rec_post + 1);
}
Esempio n. 6
0
if (isset($_POST['creditNonce']) && current_user_can('edit_users')) {
    if (!wp_verify_nonce($_POST['creditNonce'], 'credit-nonce')) {
        $message = __('安全认证失败,请重试!', 'tinection');
    } else {
        $c_user_id = $curauth->ID;
        if (isset($_POST['creditChange']) && sanitize_text_field($_POST['creditChange']) == 'add') {
            $c_do = 'add';
            $c_do_title = __('增加', 'tinection');
        } else {
            $c_do = 'cut';
            $c_do_title = __('减少', 'tinection');
        }
        $c_num = intval($_POST['creditNum']);
        $c_desc = sanitize_text_field($_POST['creditDesc']);
        $c_desc = empty($c_desc) ? '' : __('备注', 'tinection') . ' : ' . $c_desc;
        update_tin_credit($c_user_id, $c_num, $c_do, 'tin_credit', sprintf(__('%1$s将你的积分%2$s %3$s 分。%4$s', 'tinection'), $current_user->display_name, $c_do_title, $c_num, $c_desc));
        $message = sprintf(__('操作成功!已将%1$s的积分%2$s %3$s 分。', 'tinection'), $user_name, $c_do_title, $c_num);
    }
}
//~ 积分end
// 会员start
if (isset($_POST['promoteVipNonce']) && current_user_can('edit_users')) {
    if (!wp_verify_nonce($_POST['promoteVipNonce'], 'promotevip-nonce')) {
        $message = __('安全认证失败,请重试!', 'tinection');
    } else {
        if (isset($_POST['promotevip_type']) && sanitize_text_field($_POST['promotevip_type']) == '3') {
            $pv_type = 3;
            $pv_type_title = __('年费会员', 'tinection');
        } elseif (isset($_POST['promotevip_type']) && sanitize_text_field($_POST['promotevip_type']) == '2') {
            $pv_type = 2;
            $pv_type_title = __('季费会员', 'tinection');