Example #1
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;
}
Example #2
0
function tin_mail_dlusers()
{
    date_default_timezone_set('Asia/Shanghai');
    $mail = $_POST['mail'];
    $pid = $_POST['pid'];
    $name = get_bloginfo('name');
    $title = get_the_title($pid);
    $tlink = get_permalink($pid);
    $dlusers = get_tin_meta('tin_dlusers', 0);
    if (!empty($dlusers)) {
        $dlusersarray = explode(',', $dlusers);
        $hasmatch = 0;
        foreach ($dlusersarray as $dluser) {
            if ($dluser == $mail) {
                $hasmatch++;
            }
        }
        if ($hasmatch == 0) {
            $dlusers .= ',' . $mail;
        }
    } else {
        $dlusers = $mail;
    }
    update_tin_meta('tin_dlusers', $dlusers, $uid = 0);
    $content = '<p style="font-size:14px; font-family:Microsoft YaHei,微软雅黑,Arial;">您的博文<a style="font-size:14px; font-family:Microsoft YaHei,微软雅黑,Arial;" href=' . $tlink . '>《' . $title . '》</a>中有新用户下载了内容,其邮件地址为:</p>';
    $content .= '<p style="font-size:14px; font-family:Microsoft YaHei,微软雅黑,Arial;">' . $mail . '</p>';
    $content .= '<p style="font-size:14px; font-family:Microsoft YaHei,微软雅黑,Arial;">目前已记录的用户Email如下:</p><p style="font-size:14px; font-family:Microsoft YaHei,微软雅黑,Arial;word-wrap:break-word; word-break:break-all;">' . $dlusers . '</p>';
    $admin_email = get_bloginfo('admin_email');
    $to = $admin_email;
    $subject = $name . '中有新用户下载了内容';
    $message = tin_mail_template('下载记录', $content);
    //$wp_email = $admin_mail;
    $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($to, $subject, $message, $headers);
}
Example #3
0
function tin_newsletter_newspecial($title, $post)
{
    $special_id = get_tin_meta('special_id') ? (int) get_tin_meta('special_id') : 0;
    $latest = get_tin_meta('special', $special_id);
    if ($post !== $latest) {
        $special_id++;
        update_tin_meta('special', $post, $special_id);
        update_tin_meta('special_id', $special_id);
        $html = newsletter_posts_special($special_id, 1);
        //获取订阅用户
        $subscribers = get_tin_meta('tin_dl_users');
        $subscribers2 = get_tin_meta('tin_subscribers');
        if (!empty($subscribers)) {
            $subscribers .= ',' . $subscribers2;
        } else {
            $subscribers = $subscribers2;
        }
        $subscribers_array = explode(',', $subscribers);
        if (!empty($subscribers_array)) {
            $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";
            $title = get_bloginfo('name') . '邮件专刊(' . $title . ')';
            foreach ($subscribers_array as $subscriber) {
                wp_mail($subscriber, $title, $html, $headers);
            }
        } else {
            return;
        }
    } else {
        return;
    }
}
Example #4
0
} elseif (isset($_GET['action']) && $_GET['action'] == 'unsubscribe' && !isset($_GET['nonce'])) {
    $title = __('退订', 'tinection');
    $content = newsletter_unsubscribe_template();
} elseif (isset($_GET['action']) && $_GET['action'] == 'unsubscribe' && isset($_GET['email']) && isset($_GET['nonce'])) {
    $title = __('邮件订阅', 'tinection');
    $meta_key = 'unsubscribe_' . $_GET['email'];
    $nonce = get_tin_meta($meta_key) ? get_tin_meta($meta_key) : '';
    if ($nonce == $_GET['nonce']) {
        delete_tin_meta($meta_key);
        //删除用户邮箱
        $tin_dlusers = get_tin_meta('tin_dlusers');
        $tin_dlusers = tin_delete_string_specific_value(',', $tin_dlusers, $_GET['email']);
        update_tin_meta('tin_dlusers', $tin_dlusers);
        $tin_subscribers = get_tin_meta('tin_subscribers');
        $tin_subscribers = tin_delete_string_specific_value(',', $tin_subscribers, $_GET['email']);
        update_tin_meta('tin_subscribers', $tin_subscribers);
        $content = '<div style="min-height:300px;">' . __('退订成功!', 'tinection') . '</div>';
    } else {
        $content = '<div style="min-height:300px;">' . __('退订失败,你可能已经退订,或请重新再试!', 'tinection') . '</div>';
    }
} elseif (isset($_GET['action']) && $_GET['action'] == 'subscribe') {
    $title = __('邮件订阅', 'tinection');
    $content = newsletter_subscribe_template();
} else {
    $issue = $length;
    $title = __('邮件周刊(No.', 'tinection') . $issue . ')';
    $content = tin_past_issues_selection();
    $content .= newsletter_posts_issue($issue);
}
?>
<html>