CHUNK1AX
[LT]?php if (!defined(‘ABSPATH’)) {die;} // Cannot access directly. /** * RiPro是一个优秀的主题,首页拖拽布局,高级筛选,自带会员生态系统,超全支付接口,你喜欢的样子我都有! * 正版唯一购买地址,全自动授权下载使用:https://ritheme.com/ * 作者唯一QQ:200933220 (油条) * 承蒙您对本主题的喜爱,我们愿向小三一样,做大哥的女人,做大哥网站中最想日的一个。 * 能理解使用盗版的人,但是不能接受传播盗版,本身主题没几个钱,主题自有支付体系和会员体系,盗版风险太高,鬼知道那些人乱动什么代码,无利不起早。 * 开发者不易,感谢支持,更好的更用心的等你来调教 */ //**切换暗黑风格 function tap_dark() { $is_ripro_dark = !empty($_POST[‘is_ripro_dark’]) ? intval($_POST[‘is_ripro_dark’]) : 0; $_SESSION[‘is_ripro_dark’] = $is_ripro_dark; echo $_SESSION[‘is_ripro_dark’]; exit(); } add_action(‘wp_ajax_tap_dark’, ‘tap_dark’); add_action(‘wp_ajax_nopriv_tap_dark’, ‘tap_dark’); //**切换博客模式 function blog_style() { $is_blog_style = ($_POST[‘is_blog_style’] == ‘0’) ? 1 : 0; $_SESSION[‘is_blog_style’] = $is_blog_style; echo $_SESSION[‘is_blog_style’]; exit(); } add_action(‘wp_ajax_blog_style’, ‘blog_style’); add_action(‘wp_ajax_nopriv_blog_style’, ‘blog_style’); function get_bigger_img() { //新版本海报抛弃传统的php后端生产模式,使用js前段绘图,不占用服务器资源 性能出众 参考灵感来自wpcom.cn和b2的html2canvasjs技术 header(‘Content-type:application/html; Charset=utf-8’); global $current_user; $post_id = !empty($_POST[‘id’]) ? (int)$_POST[‘id’] : 0; $post = get_post($post_id); if ($current_user->ID>0) { // 生出带参数的推广文章链接 $afflink = add_query_arg(array(‘ref’ => $current_user->ID), get_the_permalink($post_id)); } else { $afflink = get_the_permalink($post_id); } if (!$post) {exit(‘参数错误’);} $img_u = _get_post_thumbnail_url($post_id); $img_t = get_template_directory_uri() . ‘/timthumb.php?src=’ . $img_u . ‘&h=300&w=400&zc=1&a=c&q=80&s=1’; // $imageInfo = getimagesize($img_t); // $b64 = base64_encode(file_get_contents($img_t)); // switch ($imageInfo[2]) { //判读图片类型 // case 1: $img_type = “gif”; // break; // case 2: $img_type = “jpg”; // break; // case 3: $img_type = “png”; // break; // } // $img_base64 = ‘data:image/’ . $img_type . ‘;base64,’ . $b64; echo ‘[LT]div id=”poster-html” class=”poster-html”>’; echo ‘[LT]div class=”poster-header”>’; echo ‘[LT]img src=”‘.$img_t.'”>’; echo ‘[LT]h2 class=”poster-title”>’.get_the_title($post_id).'[LT]/h2>’; echo ‘[LT]/div>’; echo ‘[LT]div class=”poster-body”>’; echo ‘[LT]div class=”poster-meta”>’; echo ‘[LT]div class=”poster-author”>’.get_avatar($post->post_author).get_the_author_meta( ‘display_name’, $post->post_author).'[LT]/div>’; echo ‘[LT]div class=”poster-data”>’.$post->post_date.'[LT]/div>’; echo ‘[LT]/div>’; echo ‘[LT]div class=”poster-text”>’.wp_trim_words(strip_shortcodes($post->post_content),120,’…’).'[LT]/div>’; echo ‘[LT]/div>’; echo ‘[LT]div class=”poster-footer”>’; echo ‘[LT]div class=”poster-logo”>’; echo ‘[LT]img src=”‘._cao(‘poster_logo’).'”>’; echo ‘[LT]p>’._cao(‘poster_desc’).'[LT]/p>’; echo ‘[LT]/div>’; echo ‘[LT]div class=”poster-qrcode”>’; echo ‘[LT]img src=”‘.getQrcode($afflink).'”>’; echo ‘[LT]/div>’; echo ‘[LT]/div>’; echo ‘[LT]/div>’; echo ‘[LT]div class=”poster-canvas”>[LT]/div>’; echo ‘[LT]a class=”poster-down btn” href=”” download=”‘.get_the_title($post_id).’.png”>[LT]i class=”fa fa-spinner fa-spin”>[LT]/i> ‘.esc_html__(‘海报生成中’,’rizhuti-v2′).'[LT]/a>’; exit; } add_action(‘wp_ajax_nopriv_get_bigger_img’, ‘get_bigger_img’); add_action(‘wp_ajax_get_bigger_img’, ‘get_bigger_img’); /** * [ajax_getcat_post 分类文章获取] * @Author Dadong2g * @DateTime 2020-03-05T19:56:17+0800 * @return [type] [html str] */ function ajax_getcat_post() { global $wp_query; header(‘Content-type:application/html; Charset=utf-8’); // $paged = !empty($_POST[‘paged’]) ? esc_sql($_POST[‘paged’]) : 1; $cat = !empty($_POST[‘cat’]) ? (int)$_POST[‘cat’] : ”; ///////////// $is_cao_site_list_blog = is_cao_site_list_blog(); if ($is_cao_site_list_blog) { $latest_layout = ‘bloglist’; }else{ $latest_layout = _cao( ‘latest_layout’, ‘grid’ ); } ///////////// $args = array( ‘cat’ => $cat, ‘post_status’ => ‘publish’, ); $data = new WP_Query($args); if ($data->have_posts()) { while ( $data->have_posts() ) : $data->the_post(); get_template_part( ‘parts/template-parts/content’, $latest_layout ); endwhile; }else{ get_template_part( ‘parts/template-parts/content’, ‘none’ ); } wp_reset_postdata(); exit(); } add_action(‘wp_ajax_ajax_getcat_post’, ‘ajax_getcat_post’); add_action(‘wp_ajax_nopriv_ajax_getcat_post’, ‘ajax_getcat_post’); /** * [ajax_search AJAX搜索] * @Author Dadong2g * @DateTime 2019-08-21T23:35:34+0800 * @return [type] [JSON Arr] */ function ajax_search() { global $wp_query; header(‘Content-type:application/json; Charset=utf-8’); $text = !empty($_POST[‘text’]) ? esc_sql($_POST[‘text’]) : null; $args = array(‘s’ => $text,’posts_per_page’ => 5); $array_posts = array (); $data = new WP_Query($args); while ( $data->have_posts() ) : $data->the_post(); array_push($array_posts, array(“title”=>get_the_title(),”url”=>get_permalink(),”img”=>_get_post_timthumb_src() )); endwhile; echo json_encode($array_posts); exit(); } add_action(‘wp_ajax_ajax_search’, ‘ajax_search’); add_action(‘wp_ajax_nopriv_ajax_search’, ‘ajax_search’); function get_mpweixin_qr() { header(‘Content-type:application/json; Charset=utf-8’); $wxConfig = _cao(‘oauth_mpweixin’); $CaoMpWeixin = new CaoMpWeixin($wxConfig); echo json_encode($CaoMpWeixin->getLoginQr());exit; } add_action(‘wp_ajax_get_mpweixin_qr’, ‘get_mpweixin_qr’); add_action(‘wp_ajax_nopriv_get_mpweixin_qr’, ‘get_mpweixin_qr’); function check_mpweixin_qr() { header(‘Content-type:application/json; Charset=utf-8’); $scene_id = !empty($_POST[‘scene_id’]) ? sanitize_text_field( wp_unslash( $_POST[ ‘scene_id’ ] ) ) : null; global $current_user; $current_user_id =$current_user->ID; // 查询数据库 global $wpdb, $mpwx_log_table_name; $res = $wpdb->get_row($wpdb->prepare(“SELECT * FROM $mpwx_log_table_name WHERE scene_id = %s “, esc_sql($scene_id))); if (($res->create_time+180)[LT]time()) { echo json_encode(array(‘status’ => 0));exit; //180秒内有效 } // 查询openid $_prefix = ‘mpweixin’; $_openid_meta_key = ‘open_’ . $_prefix . ‘_openid’; $user_exist = $wpdb->get_var($wpdb->prepare(“SELECT user_id FROM $wpdb->usermeta WHERE meta_key=%s AND meta_value=%s”, $_openid_meta_key, $res->openid)); if (!$current_user_id && !empty($res) && $res->scene_id == $scene_id && !empty($res->openid)) { if(!empty($user_exist)){ wp_set_auth_cookie($user_exist, true, false); $user = get_user_by(‘id’, $user_exist); do_action(‘wp_login’, $user->user_login, $user); // 保证挂载的action执行 } $status = 1; }else{ $status = 0; } echo json_encode(array(‘status’ => $status));exit; } add_action(‘wp_ajax_check_mpweixin_qr’, ‘check_mpweixin_qr’); add_action(‘wp_ajax_nopriv_check_mpweixin_qr’, ‘check_mpweixin_qr’); /** * [user_login 用户登录] * @Author Dadong2g * @DateTime 2019-06-02T15:34:38+0800 * @return [type] [description] */ function user_login() { header(‘Content-type:application/json; Charset=utf-8’); $username = !empty($_POST[‘username’]) ? esc_sql($_POST[‘username’]) : null; $password = !empty($_POST[‘password’]) ? esc_sql($_POST[‘password’]) : null; $rememberme = !empty($_POST[‘rememberme’]) ? esc_sql($_POST[‘rememberme’]) : null; if (_cao(‘is_close_wplogin’)) { echo json_encode(array(‘status’ => ‘0’, ‘msg’ => ‘仅开放社交账号登录’));exit; } $login_data = array(); $login_data[‘user_login’] = $username; $login_data[‘user_password’] = $password; $login_data[‘remember’] = false; if (isset($rememberme) && $rememberme == ‘1’) { $login_data[‘remember’] = true; } if (!$username || !$password) { echo json_encode(array(‘status’ => ‘0’, ‘msg’ => ‘请输入登录账号/密码’));exit; } //是否腾讯验证 if (_cao(‘is_captcha_qq’,’0′) && @$_SESSION[‘is_tencentcaptcha’] == 0) { $_SESSION[‘is_tencentcaptcha’] = 0; echo json_encode(array(‘status’ => ‘0’, ‘msg’ => ‘安全验证失败’));exit; } $user_verify = wp_signon($login_data, false); if (is_wp_error($user_verify)) { echo json_encode(array(‘status’ => ‘0’, ‘msg’ => ‘用户名或密码错误’));exit; } else { echo json_encode(array(‘status’ => ‘1’, ‘msg’ => ‘登录成功’));exit; } exit(); } add_action(‘wp_ajax_user_login’, ‘user_login’); add_action(‘wp_ajax_nopriv_user_login’, ‘user_login’); /** * [user_register 注册新用户] * @Author Dadong2g * @DateTime 2019-06-02T15:34:30+0800 * @return [type] [description] */ function user_register() { header(‘Content-type:application/json; Charset=utf-8’); $user_name = !empty($_POST[‘user_name’]) ? sanitize_user($_POST[‘user_name’]) : null; $user_email = !empty($_POST[‘user_email’]) ? apply_filters(‘user_registration_email’, $_POST[‘user_email’]) : null; $user_pass = !empty($_POST[‘user_pass’]) ? esc_sql($_POST[‘user_pass’]) : null; $user_pass2 = !empty($_POST[‘user_pass2’]) ? esc_sql($_POST[‘user_pass2’]) : null; if (!$user_name || !$user_email || !$user_pass) { echo json_encode(array(‘status’ => ‘0’, ‘msg’ => ‘注册信息错误’));exit; } if (_cao(‘is_close_wpreg’)) { echo json_encode(array(‘status’ => ‘0’, ‘msg’ => ‘仅开放社交账号注册’));exit; } if (!validate_username($user_name)) { echo json_encode(array(‘status’ => ‘0’, ‘msg’ => ‘用户名包含无效字符’));exit; } if (username_exists($user_name)) { echo json_encode(array(‘status’ => ‘0’, ‘msg’ => ‘该用户名已被注册’));exit; } if (!is_email($user_email)) { echo json_encode(array(‘status’ => ‘0’, ‘msg’ => ‘邮箱地址错误’));exit; } if (email_exists($user_email)) { echo json_encode(array(‘status’ => ‘0’, ‘msg’ => ‘邮箱已经被注册’));exit; } if (strlen($user_pass) [LT] 6) { echo json_encode(array(‘status’ => ‘0’, ‘msg’ => ‘密码长度不得小于6位’));exit; } if ($user_pass != $user_pass2) { echo json_encode(array(‘status’ => ‘0’, ‘msg’ => ‘两次输入的密码不一致’));exit; } // 是否需要邮箱验证 if (_cao(‘is_email_reg_cap’)) { if (empty($_POST[‘captcha’]) || empty($_SESSION[‘CAO_code_captcha’]) || trim(strtolower($_POST[‘captcha’])) != $_SESSION[‘CAO_code_captcha’]) { echo json_encode(array(‘status’ => ‘0’, ‘msg’ => ‘验证码错误’));exit; } if ($_SESSION[‘CAO_code_captcha_email’] != $user_email) { echo json_encode(array(‘status’ => ‘0’, ‘msg’ => ‘验证码与邮箱不对应’));exit; } } //是否腾讯验证 if (_cao(‘is_captcha_qq’,’0′) && @$_SESSION[‘is_tencentcaptcha’] == 0) { $_SESSION[‘is_tencentcaptcha’] = 0; echo json_encode(array(‘status’ => ‘0’, ‘msg’ => ‘安全验证失败’));exit; } // 验证通过 $nweUserData = array( ‘ID’ => ”, ‘user_login’ => $user_name, ‘user_pass’ => $user_pass, ‘user_email’ => $user_email, ‘role’ => get_option(‘default_role’), ); $user_id = wp_insert_user($nweUserData); if (is_wp_error($user_id)) { echo json_encode(array(‘status’ => ‘0’, ‘msg’ => ‘注册失败,请重试’));exit; } else { wp_set_auth_cookie($user_id, true, false); wp_set_current_user($user_id); //发送邮件 $message = __(‘注册成功!’) . “rnrn”; $message .= sprintf(__(‘用户名: %s’), $user_name) . “rnrn”; //$message .= sprintf(__(‘密码: %s’), $user_pass) . “rnrn”; if (_cao(‘is_mail_nitfy_reg’)) { _sendMail($user_email, ‘注册信息’, $message); } echo json_encode(array(‘status’ => ‘1’, ‘msg’ => ‘注册成功’));exit; } exit(); } add_action(‘wp_ajax_user_register’, ‘user_register’); add_action(‘wp_ajax_nopriv_user_register’, ‘user_register’); /** * [sessioncode 生产验证码] * @Author Dadong2g * @DateTime 2019-06-02T15:34:20+0800 * @param [type] $email [description] * @return [type] [description] */ function sessioncode($email) { $originalcode = ‘0,1,2,3,4,5,6,7,8,9’; $originalcode = explode(‘,’, $originalcode); $countdistrub = 10; $_dscode = “”; $counts = 6; for ($j = 0; $j [LT] $counts; $j++) { $dscode = $originalcode[rand(0, $countdistrub – 1)]; $_dscode .= $dscode; } $_SESSION[‘CAO_code_captcha’] = strtolower($_dscode); $_SESSION[‘CAO_code_captcha_email’] = $email; $message = ‘验证码:’ . $_dscode; $send_email = _sendMail($email, ‘验证码’, $message); if ($send_email) { return true; } return false; } /** * [captcha_email 验证邮箱] * @Author Dadong2g * @DateTime 2019-06-02T15:34:06+0800 * @return [type] [description] */ function captcha_email() { header(‘Content-type:application/json; Charset=utf-8’); global $wpdb; $user_email = !empty($_POST[‘user_email’]) ? esc_sql($_POST[‘user_email’]) : null; $user_email = apply_filters(‘user_registration_email’, $user_email); $user_email = $wpdb->_escape(trim($user_email)); if (email_exists($user_email)) { echo json_encode(array(‘status’ => ‘0’, ‘msg’ => ‘邮箱已存在’));exit; } else { $send_email = sessioncode($user_email); if ($send_email) { echo json_encode(array(‘status’ => ‘1’, ‘msg’ => ‘发送成功’));exit; } else { echo json_encode(array(‘status’ => ‘0’, ‘msg’ => ‘发送失败’));exit; } } exit(); } add_action(‘wp_ajax_captcha_email’, ‘captcha_email’); add_action(‘wp_ajax_nopriv_captcha_email’, ‘captcha_email’); //腾讯防水墙 function tencentcaptcha() { header(‘Content-type:application/json; Charset=utf-8’); if(!empty($_SERVER[“HTTP_CLIENT_IP”])){ $cip = $_SERVER[“HTTP_CLIENT_IP”]; }else if(!empty($_SERVER[“HTTP_X_FORWARDED_FOR”])){ $cip = $_SERVER[“HTTP_X_FORWARDED_FOR”]; }else if(!empty($_SERVER[“REMOTE_ADDR”])){ $cip = $_SERVER[“REMOTE_ADDR”]; }else{ $cip = ”; } preg_match(“/[d.]{7,15}/”, $cip, $cips); $cip = isset($cips[0]) ? $cips[0] : ‘unknown’; unset($cips); $AppSecretKey = _cao(‘captcha_qq_secretkey’,”); $appid = !empty($_POST[‘appid’]) ? $_POST[‘appid’] : null; $Ticket = !empty($_POST[‘Ticket’]) ? $_POST[‘Ticket’] : null; $Randstr = !empty($_POST[‘Randstr’]) ? $_POST[‘Randstr’] : null; $UserIP = $cip; $url = “https://ssl.captcha.qq.com/ticket/verify”; $params = array( “aid” => $appid, “AppSecretKey” => $AppSecretKey, “Ticket” => $Ticket, “Randstr” => $Randstr, “UserIP” => $UserIP ); $paramstring = http_build_query($params); $geturl = $url.’?’.$paramstring; $content = tx_http_curl($geturl); $result = json_decode($content,true); if($result){ if($result[‘response’] == 1){ $_SESSION[‘is_tencentcaptcha’] = 1; echo json_encode(array(‘status’ => ‘1’, ‘msg’ => ‘验证通过’));exit; }else{ $_SESSION[‘is_tencentcaptcha’] = 0; echo json_encode(array(‘status’ => ‘0’, ‘msg’ => $result[‘err_msg’]));exit; } }else{ $_SESSION[‘is_tencentcaptcha’] = 0; echo json_encode(array(‘status’ => ‘0’, ‘msg’ => ‘请求失败’));exit; } exit(); } add_action(‘wp_ajax_tencentcaptcha’, ‘tencentcaptcha’); add_action(‘wp_ajax_nopriv_tencentcaptcha’, ‘tencentcaptcha’); function tx_http_curl($url,$type=’get’,$res=’json’,$arr=”){ //1.初始化curl $ch = curl_init(); //2.设置curl的参数 curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); if($type == ‘post’){ curl_setopt($ch, CURLOPT_POST,1); curl_setopt($ch, CURLOPT_POSTFIELDS, $arr); } //3.采集 $output = curl_exec($ch); //4.关闭 curl_close($ch); if($res==’json’){ if(curl_error($ch)){ //请求失败,返回错误信息 return curl_error($ch); }else{ //请求成功,返回信息 return $output; } } } /** * @package caozhuti */ /** * [isLoginCheck 登陆状态验证] * @Author Dadong2g * @DateTime 2019-05-31T13:12:49+0800 * @return boolean [description] */ function isLoginCheck() { if (!is_user_logged_in()) { header(‘Allow: POST’); header(‘HTTP/1.1 503 Method Not Allowed’); header(‘Content-Type: text/plain’); exit; } } //投稿 write_post function cao_write_post() { header(‘Content-type:application/json; Charset=utf-8’); global $current_user; $uid = $current_user->ID; isLoginCheck(); //检测登录 $nonce = !empty($_POST[‘nonce’]) ? $_POST[‘nonce’] : null; if ($nonce && !wp_verify_nonce($nonce, ‘caoclick-‘ . $uid)) { echo json_encode(array(‘status’ => ‘0’, ‘msg’ => ‘非法请求’));exit; } $edit_id = !empty($_POST[‘edit_id’]) ? (int)sanitize_text_field(trim($_POST[‘edit_id’])) : 0; $post_title = !empty($_POST[‘post_title’]) ? sanitize_text_field(trim($_POST[‘post_title’])) : ”; $post_content = !empty($_POST[‘post_content’]) ? trim($_POST[‘post_content’]) : ”; $post_excerpt = !empty($_POST[‘post_excerpt’]) ? sanitize_text_field(trim($_POST[‘post_excerpt’])) : ”; $post_cat = !empty($_POST[‘post_cat’]) ? (int)sanitize_text_field(trim($_POST[‘post_cat’])) : 1; $cao_status = !empty($_POST[‘cao_status’]) ? trim($_POST[‘cao_status’]) : 0; $cao_status = ($cao_status == ‘fee’) ? 1 : 0; $cao_price = !empty($_POST[‘cao_price’]) ? (int)sanitize_text_field(trim($_POST[‘cao_price’])) : 0; $cao_vip_rate = !empty($_POST[‘cao_vip_rate’]) ? sanitize_text_field(trim($_POST[‘cao_vip_rate’])) : 1; $cao_pwd = !empty($_POST[‘cao_pwd’]) ? sanitize_text_field(trim($_POST[‘cao_pwd’])) : ”; $cao_downurl = !empty($_POST[‘cao_downurl’]) ? esc_url(trim($_POST[‘cao_downurl’])) : ”; $post_status = !empty($_POST[‘post_status’]) ? $_POST[‘post_status’] : ”; $post_status = in_array($post_status, array(‘publish’, ‘draft’, ‘pending’)) ? $post_status : ‘draft’; if (!_cao(‘is_all_publish_posts’) && !current_user_can(‘publish_posts’)) { echo json_encode(array(‘status’ => ‘0’, ‘msg’ => ‘您没有权限发布或修改文章’));exit; } if(strlen($post_content) [LT] 100) { echo json_encode(array(‘status’ => ‘0’, ‘msg’ => ‘文章内容最低100个字符’));exit; } // 如果是编辑 if ($edit_id > 0) { // 插入文章 $new_post = wp_update_post( array( //Return: The ID of the post if the post is successfully updated in the database. Otherwise returns 0 ‘ID’ => $edit_id, ‘post_title’ => $post_title, ‘post_excerpt’ => $post_excerpt, ‘post_content’ => $post_content, ‘post_status’ => $post_status, ‘post_author’ => get_current_user_id(), ‘post_category’ => array($post_cat) ) ); }else{ // 插入文章 $new_post = wp_insert_post( array( ‘post_title’ => $post_title, ‘post_excerpt’ => $post_excerpt, ‘post_content’ => $post_content, ‘post_status’ => $post_status, ‘post_author’ => get_current_user_id(), ‘post_category’ => array($post_cat), ‘tags_input’ => ” ) ); } if($new_post instanceof WP_Error) { echo json_encode(array(‘status’ => ‘0’, ‘msg’ => ‘网络错误,请重试或联系管理员’));exit; } // 如果是直接发布的 挂钩 用于后期添加 if ($post_status == ‘publish’) { do_action(‘cao_immediate_to_publish’, $new_post); } // 更新Meta $_cao_status = ($cao_status>0) ? 1 : 0 ; update_post_meta($new_post, ‘cao_status’, $_cao_status); update_post_meta($new_post, ‘cao_price’, $cao_price); update_post_meta($new_post, ‘cao_vip_rate’, $cao_vip_rate); update_post_meta($new_post, ‘cao_pwd’, $cao_pwd); update_post_meta($new_post, ‘cao_downurl’, $cao_downurl); update_post_meta($new_post, ‘post_style’, ‘sidebar’); echo json_encode(array(‘status’ => ‘1’, ‘msg’ => ‘提交成功,审核后公开’));exit; } add_action(‘wp_ajax_cao_write_post’, ‘cao_write_post’); add_action(‘wp_ajax_nopriv_cao_write_post’, ‘cao_write_post’); // 上传头像avatar_photo function update_avatar_photo() { if (_cao(‘disabled_up_ava’)) { echo json_encode(array(‘status’ => ‘0’, ‘msg’ => ‘头像功能关闭’));exit; } header(‘Content-type:application/json; Charset=utf-8’); global $current_user; $uid = $current_user->ID; isLoginCheck(); //检测登录 $nonce = !empty($_POST[‘nonce’]) ? $_POST[‘nonce’] : null; $file = !empty($_FILES[‘file’]) ? $_FILES[‘file’] : null; if ($nonce && !wp_verify_nonce($nonce, ‘caoclick-‘ . $uid)) { echo json_encode(array(‘status’ => ‘0’, ‘msg’ => ‘非法请求’));exit; } $allowMime = array(‘image/jpg’, ‘image/gif’, ‘image/png’, ‘image/bmp’, ‘image/pjpeg’, “image/jpeg”); if (!in_array($file[‘type’], $allowMime)) { echo json_encode(array(‘status’ => ‘0’, ‘msg’ => ‘图片类型错误’));exit; } //如果扩展名是图片,就进行检测 $this_img = @getimagesize($file[‘tmp_name’]);//读取图片信息 if (empty($this_img)) { echo json_encode(array(‘status’ => ‘0’, ‘msg’ => ‘图片类型错误’));exit; } $typearr = array(1 => ‘gif’, 2 => ‘jpg’, 3 => ‘png’); $this_type = $typearr[$this_img[2]]; if (!in_array($this_type, $typearr)) { echo json_encode(array(‘status’ => ‘0’, ‘msg’ => ‘图片类型错误’));exit; } if($file[‘type’]==”image/gif”){ $img=@imagecreatefromgif($file[‘tmp_name’]); }elseif($file[‘type’]==”image/png” || $file[‘type’]==”image/x-png”){ $img=@imagecreatefrompng($file[‘tmp_name’]); }else{ $img=@imagecreatefromjpeg($file[‘tmp_name’]); } if($img==false){ echo json_encode(array(‘status’ => ‘0’, ‘msg’ => ‘图片类型错误’));exit; } if (is_uploaded_file($file[‘tmp_name’]) && is_user_logged_in()) { $picname = $file[‘name’]; $picsize = $file[‘size’]; $arrType = array(‘image/jpg’, ‘image/gif’, ‘image/png’, ‘image/bmp’, ‘image/pjpeg’, “image/jpeg”); $userid = $uid; $rand = (rand(10, 100)); if ($picname != “”) { if ($picsize > 200400) { echo json_encode(array(‘status’ => ‘0’, ‘msg’ => ‘头像最大限制200KB’));exit; } elseif (!in_array($file[‘type’], $arrType)) { echo json_encode(array(‘status’ => ‘0’, ‘msg’ => ‘图片类型错误’));exit; } else { /////////////////////// $upload_dir = wp_upload_dir(); $poster_dir = $upload_dir[‘basedir’] . ‘/avatar/’; if (!is_dir($poster_dir)) { wp_mkdir_p($poster_dir); } //获取文件后缀 $_filesubstr = substr(strrchr($file[‘name’], ‘.’), 1); if (!in_array($_filesubstr, $typearr)) { echo json_encode(array(‘status’ => ‘0’, ‘msg’ => ‘图片类型错误’));exit; } $filename = ‘avatar-‘ . $userid . ‘.’ .$_filesubstr; $_file = $poster_dir . $filename; if(!move_uploaded_file($file[‘tmp_name’], $_file)){ echo json_encode(array(‘status’ => ‘0’, ‘msg’ => ‘上传失败’));exit; } //unlink($file); $src = $upload_dir[‘baseurl’] . ‘/avatar/’ . $filename; // 是否开启CDN兼容 if (_cao(‘disabled_wp_cdn’) && _cao(‘_wp_cdn_domain’) ) { $src = str_replace(_cao(‘_wp_cdn_domain’),esc_url(home_url(‘/’)),$src); } error_reporting(0); if (is_wp_error($src)) { echo json_encode(array(‘status’ => ‘0’, ‘msg’ => ‘上传失败’));exit; }else{ update_user_meta($userid, ‘user_custom_avatar’, $src); echo json_encode(array(‘status’ => ‘1’, ‘msg’ => ‘上传成功’));exit; } } } } echo json_encode(array(‘status’ => ‘0’, ‘msg’ => ‘文件错误’));exit; } add_action(‘wp_ajax_update_avatar_photo’, ‘update_avatar_photo’); /** * [update_img 新增文件类型验证安全] * @Author Dadong2g * @DateTime 2019-10-25T20:20:45+0800 * @return [type] [description] */ function update_img() { header(‘Content-type:application/json; Charset=utf-8’); global $current_user; $uid = $current_user->ID; isLoginCheck(); //检测登录 $nonce = !empty($_POST[‘nonce’]) ? $_POST[‘nonce’] : null; $file = !empty($_FILES[‘file’]) ? $_FILES[‘file’] : null; if ($nonce && !wp_verify_nonce($nonce, ‘caoclick-‘ . $uid)) { echo json_encode(array(‘status’ => ‘0’, ‘msg’ => ‘非法请求’));exit; } $file_index = mb_strrpos($file[“name”],’.’); //扩展名定位 //图片验证 $is_img = getimagesize($file[“tmp_name”]); if(!$is_img && true){ echo json_encode(array(‘status’ => ‘0’, ‘msg’ => ‘上传文件类型错误’));exit; } //图片类型验证 $image_type = [‘image/jpg’, ‘image/gif’, ‘image/png’, ‘image/bmp’, ‘image/pjpeg’, “image/jpeg”]; if(!in_array($file[‘type’], $image_type) && true){ echo json_encode(array(‘status’ => ‘0’, ‘msg’ => ‘禁止上传非图片类型文件’));exit; } //图片后缀验证 $postfix = [‘.png’,’.jpg’,’.jpeg’,’pjpeg’,’gif’,’bmp’]; $file_postfix = strtolower(mb_substr($file[“name”], $file_index)); if(!in_array($file_postfix, $postfix) && true){ echo json_encode(array(‘status’ => ‘0’, ‘msg’ => ‘上传后缀不允许’));exit; } if ( !empty( $file ) ) { // 获取上传目录信息 $wp_upload_dir = wp_upload_dir(); // 将上传的图片文件移动到上传目录 md5纯命名图片 $basename = _new_filename($file[‘name’]); $filename = $wp_upload_dir[‘path’] . ‘/’ . $basename; $re = rename( $file[‘tmp_name’], $filename ); $attachment = array( ‘guid’ => $wp_upload_dir[‘url’] . ‘/’ . $basename, ‘post_mime_type’ => $file[‘type’], ‘post_title’ => preg_replace( ‘/.[^.]+$/’, ”, $basename ), ‘post_content’ => ”, ‘post_status’ => ‘inherit’ ); $attach_id = wp_insert_attachment( $attachment, $filename ); require_once( ABSPATH . ‘wp-admin/includes/image.php’ ); $attach_data = wp_generate_attachment_metadata( $attach_id, $filename ); wp_update_attachment_metadata( $attach_id, $attach_data ); // 返回图片地址和状态 echo json_encode( array(‘errno’ => ‘0’, ‘data’ => array(wp_get_attachment_url( $attach_id )) ) );exit; } // 返回图片地址和状态 echo json_encode(array(‘errno’ => ‘1’, ‘data’ => array()));exit; } add_action(‘wp_ajax_update_img’, ‘update_img’); add_action(‘wp_ajax_nopriv_update_img’, ‘update_img’); /** * [cdk_pay 卡密充值] * @Author Dadong2g * @DateTime 2019-06-02T15:33:58+0800 * @return [type] [description] */ function cdk_pay() { header(‘Content-type:application/json; Charset=utf-8’); global $current_user; $uid = $current_user->ID; isLoginCheck(); //检测登录 $cdkcode = !empty($_POST[‘cdkcode’]) ? sanitize_text_field( wp_unslash( $_POST[ ‘cdkcode’ ]
