Example #1
0
function tin_credit_to_void($user_id, $num, $msg = '')
{
    if (!is_numeric($user_id) || !is_numeric($num)) {
        return;
    }
    $credit = (int) get_user_meta($user_id, 'tin_credit', true);
    $num = (int) $num;
    if ($credit < $num) {
        return 'less';
    }
    $cut = update_user_meta($user_id, 'tin_credit', $credit - $num);
    $credit_void = (int) get_user_meta($user_id, 'tin_credit_void', true);
    $add = update_user_meta($user_id, 'tin_credit_void', $credit_void + $num);
    add_tin_message($user_id, 'credit', current_time('mysql'), $msg ? $msg : sprintf(__('消费了%s积分', 'tinection'), $num));
    return 0;
}
Example #2
0
function comment_mail_notify($comment_id, $comment_object)
{
    if ($comment_object->comment_approved != 1 || !empty($comment_object->comment_type)) {
        return;
    }
    date_default_timezone_set('Asia/Shanghai');
    $admin_notify = '1';
    // admin 要不要收回复通知 ( '1'=要 ; '0'=不要 )
    $admin_email = get_bloginfo('admin_email');
    // $admin_email 可改为你指定的 e-mail.
    $comment = get_comment($comment_id);
    $comment_author = trim($comment->comment_author);
    $comment_date = trim($comment->comment_date);
    $comment_link = htmlspecialchars(get_comment_link($comment_id));
    $comment_content = nl2br($comment->comment_content);
    $comment_author_email = trim($comment->comment_author_email);
    $parent_id = $comment->comment_parent ? $comment->comment_parent : '';
    $parent_email = trim(get_comment($parent_id)->comment_author_email);
    $post = get_post($comment_object->comment_post_ID);
    $post_author_email = get_user_by('id', $post->post_author)->user_email;
    $wp_email = 'no-reply@' . preg_replace('#^www.#', '', strtolower($_SERVER['SERVER_NAME']));
    // e-mail 发出点, no-reply 可改为可用的 e-mail.
    $from = "From: \"" . get_option('blogname') . "\" <{$wp_email}>";
    $headers = "{$from}\nContent-Type: text/html; charset=" . get_option('blog_charset') . "\n";
    $blogname = get_option("name");
    $bloghome = get_option("home");
    $send_email = array();
    global $wpdb;
    if ($wpdb->query("Describe {$wpdb->comments} comment_mail_notify") == '') {
        $wpdb->query("ALTER TABLE {$wpdb->comments} ADD COLUMN comment_mail_notify TINYINT NOT NULL DEFAULT 0;");
    }
    if (isset($_POST['comment_mail_notify'])) {
        $wpdb->query("UPDATE {$wpdb->comments} SET comment_mail_notify='1' WHERE comment_ID='{$comment_id}'");
    }
    $notify = $parent_id ? get_comment($parent_id)->comment_mail_notify : '0';
    $spam_confirmed = $comment->comment_approved;
    //给父级评论提醒
    if ($parent_id != '' && $spam_confirmed != 'spam' && $notify == '1' && $parent_email != $comment_author_email) {
        $parent_author = trim(get_comment($parent_id)->comment_author);
        $parent_comment_date = trim(get_comment($parent_id)->comment_date);
        $parent_comment_content = nl2br(get_comment($parent_id)->comment_content);
        $send_email[] = array('address' => $parent_email, 'uid' => $comment_object->comment_parent, 'title' => sprintf(__('%1$s在%2$s中回复你', 'tinection'), $comment_object->comment_author, $post->post_title), 'type' => sprintf(__('评论提醒', 'tinection')), 'content' => sprintf(__('<style>img{max-width:100%;}</style><p>%1$s,您好!</p><p>您于%2$s在文章《%3$s》上发表评论: </p><p style="border-bottom:#ddd 1px solid;border-left:#ddd 1px solid;padding-bottom:20px;background-color:#eee;margin:15px 0px;padding-left:20px;padding-right:20px;border-top:#ddd 1px solid;border-right:#ddd 1px solid;padding-top:20px">%4$s</p>
<p>%5$s 于%6$s 给您的回复如下: </p><p style="border-bottom:#ddd 1px solid;border-left:#ddd 1px solid;padding-bottom:20px;background-color:#eee;margin:15px 0px;padding-left:20px;padding-right:20px;border-top:#ddd 1px solid;border-right:#ddd 1px solid;padding-top:20px">%7$s</p>
<p>您可以点击 <a style="color:#00bbff;text-decoration:none" href="%8$s" target="_blank">查看回复的完整內容</a></p>', 'tinection'), $parent_author, $parent_comment_date, $post->post_title, $parent_comment_content, $comment_author, $comment_date, $comment_content, $comment_link));
    }
    //给文章作者的通知
    if ($post_author_email != $comment_author_email && $post_author_email != $parent_email) {
        $send_email[] = array('address' => $post_author_email, 'uid' => $post->post_author, 'title' => sprintf(__('%1$s在%2$s中回复你', 'tinection'), $comment_object->comment_author, $post->post_title), 'type' => sprintf(__('文章评论', 'tinection')), 'content' => sprintf(__('<style>img{max-width:100%;}</style>%1$s在文章<a href="%2$s" target="_blank">%3$s</a>中发表了回复,快去看看吧:<br><p style="padding:10px 0;background-color:#eee;margin-top:10px;"> %4$s </p>', 'tinection'), $comment_object->comment_author, htmlspecialchars(get_comment_link($comment_id)), $post->post_title, $comment_object->comment_content));
    }
    //给管理员通知
    if ($post_author_email != $admin_email && $parent_id != $admin_email && ($admin_notify = '1')) {
        $send_email[] = array('address' => $admin_email, 'uid' => 0, 'title' => sprintf(__('%1$s上的文章有了新的回复', 'tinection'), get_bloginfo('name')), 'type' => sprintf(__('站点管理', 'tinection')), 'content' => sprintf(__('<style>img{max-width:100%;}</style>%1$s回复了文章<a href="%2$s" target="_blank">%3$s</a>,快去看看吧:<br> %4$s', 'tinection'), $comment_object->comment_author, htmlspecialchars(get_comment_link($comment_id)), $post->post_title, $comment_object->comment_content));
    }
    if ($send_email) {
        foreach ($send_email as $email) {
            $content = tin_mail_template($email['type'], $email['content']);
            // 添加消息通知
            if (intval($email['uid']) > 0) {
                add_tin_message($email['uid'], 'unread', current_time('mysql'), $email['title'], $email['content']);
            }
            // 如果有设置邮箱就发送邮件通知
            if (filter_var($email['address'], FILTER_VALIDATE_EMAIL)) {
                wp_mail($email['address'], $email['title'], $content, $headers);
            }
        }
    }
}
 function tin_open_login($openid = '', $token = '', $type = 'qq', $name = '')
 {
     $cookie_name = tin_redirect_cookie_name();
     $redirect = isset($_COOKIE[$cookie_name]) ? urldecode($_COOKIE[$cookie_name]) : home_url();
     $die_title = '请重试或报告管理员';
     $redirect_text = '<p>' . $die_title . ' </p><p><a href="' . $redirect . '">点击返回</a></p>';
     $user_ID = get_current_user_id();
     $id_field = 'tin_' . $type . '_openid';
     $token_field = 'tin_' . $type . '_access_token';
     global $wpdb;
     $user_exist = $wpdb->get_var("SELECT user_id FROM {$wpdb->usermeta} WHERE meta_key='{$id_field}' AND meta_value='{$openid}' ");
     if (is_user_logged_in()) {
         if (isset($user_exist) && (int) $user_exist > 0) {
             wp_die($name . ' 已有绑定账号,请绑定其他账号或先解除原有账号。 ' . $redirect_text, $die_title);
         } else {
             update_user_meta($user_ID, $id_field, $openid);
             update_user_meta($user_ID, $token_field, $token);
             header('Location:' . $redirect);
             exit;
         }
     } else {
         if (isset($user_exist) && (int) $user_exist > 0) {
             $insert_user_id = $user_exist;
             $is_new_user = 0;
         } else {
             $user_login = strtoupper(substr($type, 0, 1)) . $openid;
             $insert_user_id = wp_insert_user(array('user_login' => $user_login, 'nickname' => $name, 'display_name' => $name, 'user_pass' => wp_generate_password()));
             $is_new_user = 1;
         }
         if (is_wp_error($insert_user_id)) {
             wp_die('登录失败! ' . $redirect_text, $die_title);
         } else {
             update_user_meta($insert_user_id, $id_field, $openid);
             update_user_meta($insert_user_id, $token_field, $token);
             if ($type == 'weixin') {
                 update_user_meta($insert_user_id, 'tin_weixin_refresh_token', $refresh_token);
                 update_user_meta($insert_user_id, 'tin_weixin_headimgurl', $headimgurl);
             }
             if ($is_new_user) {
                 update_user_meta($insert_user_id, 'tin_avatar', $type);
                 wp_update_user(array('ID' => $insert_user_id, 'role' => ot_get_option('tin_open_role')));
                 add_tin_message($insert_user_id, 'unread', current_time('mysql'), __('请完善账号信息', 'tinection'), sprintf(__('欢迎来到%1$s,请<a href="%2$s">完善资料</a>,其中电子邮件尤为重要,许多信息都将通过电子邮件通知您!', 'tinection'), get_bloginfo('name'), admin_url('profile.php')));
             }
             update_user_meta($insert_user_id, 'tin_latest_login', current_time('mysql'));
             wp_set_current_user($insert_user_id, $user_login);
             wp_set_auth_cookie($insert_user_id);
             do_action('wp_login', $user_login);
             header('Location:' . $redirect);
             exit;
         }
     }
 }
Example #4
0
        $message = __('安全认证失败,请重试!', 'tinection');
    } else {
        $promote_id = intval($_POST['promote_id']);
        delete_tin_promotecode($promote_id);
        $message = __('操作成功!已成功删除指定优惠码', 'tinection');
    }
}
//~ 优惠码end
//~ 私信start
$get_pm = isset($_POST['pm']) ? trim($_POST['pm']) : '';
if (isset($_POST['pmNonce']) && $get_pm && is_user_logged_in()) {
    if (!wp_verify_nonce($_POST['pmNonce'], 'pm-nonce')) {
        $message = __('安全认证失败,请重试!', 'tinection');
    } else {
        $pm_title = json_encode(array('pm' => $curauth->ID, 'from' => $current_user->ID));
        if (add_tin_message($curauth->ID, 'unrepm', '', $pm_title, $get_pm)) {
            $message = __('发送成功!', 'tinection');
        }
    }
}
//~ 私信end
//~ 页码start
$paged = max(1, get_query_var('page'));
$number = get_option('posts_per_page', 10);
$offset = ($paged - 1) * $number;
//~ 页码end
$item_html = '<li class="tip">' . __('没有找到记录', 'tinection') . '</li>';
//~ 个人资料
if ($oneself) {
    $user_id = $curauth->ID;
    $avatar = $user_info->tin_avatar;