<?php
class luntan_index{
    public function init(){
        global $luntan_key;
        if(is_admin()){
            add_filter('plugin_action_links_'.LUNTAN_NAME, [$this,'luntan_plugin_action_links']);
            add_action('admin_menu', [$this,'luntan_addpages']);
             add_action( 'admin_enqueue_scripts', [$this,'luntan_ht_enqueue'] );
        }
        add_action( 'init', [$this,'luntan_menus'] );
        add_action('template_include', [$this,'luntan_template']);
        add_action( 'wp_enqueue_scripts', [$this,'luntan_enqueue'] );
        add_action('wp_logout', function () {
            wp_safe_redirect(home_url('/'));
            exit; // 确保代码停止执行
        });
        add_filter('luntan_dhdfkdksj', [$this,'luntan_dhdfkdksj']);
        add_filter('luntan_dssdd', [$this,'luntan_dssdd']);
        $luntan_key = apply_filters('luntan_dhdfkdksj',1);
        $this->luntan_tongji($luntan_key);
        add_filter('login_redirect', [$this,'luntan_custom_login_redirect'], 10, 3);
        add_action('admin_init',[$this,'luntan_redirect_subscribers_from_admin']);
        add_filter('sanitize_user', [$this,'luntan_allow_chinese_username'], 10, 3);
        add_filter('registration_errors', [$this,'luntan_chinese_username_error_message']);
        add_filter('user_registration_errors', [$this,'luntan_chinese_username_error_message']);
       
        
    }
    // 允许中文用户名注册
    public function luntan_allow_chinese_username($username, $raw_username, $strict) {
        // 中文用户名正则：允许汉字、字母、数字、下划线及连字符
        $allowed = preg_match('/^[\x{4e00}-\x{9fa5}a-zA-Z0-9_.-]+$/u', $raw_username);
        
        if ($allowed) {
            return $raw_username;
        }
        
        return $username;
    }
    
    
    // 修正中文用户名的验证错误提示
    public function luntan_chinese_username_error_message($errors) {
        if (isset($errors->errors['invalid_username'])) {
            foreach ($errors->errors['invalid_username'] as &$error) {
                $error = '用户名只能包含汉字、字母、数字、下划线、连字符和点。';
            }
        }
        return $errors;
    }
    public function luntan_redirect_subscribers_from_admin() {
        if (defined('DOING_AJAX') && DOING_AJAX) {
            return;
        }
        $current_url = isset($_SERVER['REQUEST_URI'])?sanitize_text_field( wp_unslash($_SERVER['REQUEST_URI'])):"";
        
        if ( strpos($current_url, '/wp-admin/')!== false  && current_user_can('subscriber')) {
            $luntan_url_guanli = get_option('luntan_url_guanli');
            if(isset($luntan_url_guanli['list']) && $luntan_url_guanli['list']){
                $luntan_url = $luntan_url_guanli['list'];
                $luntan_url_zx = $luntan_url_guanli['zhongxin'];
            }else{
                $luntan_url = 'ltwdsqht';
                $luntan_url_zx = 'ltwdsqht_zx';
            }
            wp_redirect('/'.$luntan_url_zx.'/#/userinfo');
            exit;
        }
    }
    public function luntan_custom_login_redirect($redirect_to, $requested_redirect_to, $user){
        if (isset($user->roles) && is_array($user->roles) && in_array('subscriber', $user->roles)) {
            $luntan_url_guanli = get_option('luntan_url_guanli');
            if(isset($luntan_url_guanli['list']) && $luntan_url_guanli['list']){
                $luntan_url = $luntan_url_guanli['list'];
                $luntan_url_zx = $luntan_url_guanli['zhongxin'];
            }else{
                $luntan_url = 'ltwdsqht';
                $luntan_url_zx = 'ltwdsqht_zx';
            }
            // 这里将跳转地址替换为你想要的URL
            $redirect_to = '/'.$luntan_url_zx.'/#/userinfo';
        }
        return $redirect_to;
    }
    public function luntan_ht_enqueue($hook){
        if( 'toplevel_page_luntan' != $hook ) return;
         require plugin_dir_path( LUNTAN_FILE ) . 'inc/assets_ht.php';
            
            foreach($assets as $key=>$val){
                if($val['type']=='css'){
                     wp_register_style(
                        $val['name'],
                        plugin_dir_url(LUNTAN_FILE). 'inc'. $val['url'],
                        array(), // 没有依赖的其他样式表
                        '1.0', // 样式表版本号，可根据实际情况更新
                        'all' // 适用于所有媒体类型
                    );
                    
                    // 排队加载（引入）已注册的样式表
                    wp_enqueue_style($val['name']);
                     
                }elseif($val['type']=='js'){
                    wp_register_script(
                    $val['name'],
                    plugin_dir_url(LUNTAN_FILE). 'inc'. $val['url'],
                    array(), // 没有依赖的其他脚本
                    '1.0', // 脚本版本号，可根据实际情况更新
                    true // 脚本在页脚加载
                );
                // 排队加载（引入）已注册的脚本
                wp_enqueue_script($val['name']);
                }
            }
            wp_register_script('luntan.js', false, [], LUNTAN_VERSION,false);
            wp_enqueue_script('luntan.js');
            $luntan_version  = esc_url_raw(admin_url('plugin-install.php?tab=plugin-information&plugin=luntan'));
            $luntan_url_guanli = get_option('luntan_url_guanli');
            if(isset($luntan_url_guanli['list']) && $luntan_url_guanli['list']){
                $luntan_url = $luntan_url_guanli['list'];
                $luntan_url_zx = $luntan_url_guanli['zhongxin'];
            }else{
                $luntan_url = 'ltwdsqht';
                $luntan_url_zx = 'ltwdsqht_zx';
            }
            wp_add_inline_script('luntan.js', 'var luntan_wztkj_url="'.esc_js(plugin_dir_url(LUNTAN_FILE)).'inc",luntan_nonce="'. esc_attr(wp_create_nonce('luntan')).'",luntan_ajax="'.esc_url(admin_url('admin-ajax.php')).'",luntan_version="'.esc_url_raw($luntan_version).'",luntan_logout ="'.wp_logout_url(home_url('/luntan')).'",luntan_url="/'.$luntan_url.'";', 'before');
        
    }
    public function luntan_addpages(){
        add_menu_page(__('论坛/帖子/问答/社区/话题','luntan'), __('论坛/帖子/问答/社区/话题','luntan'), 'manage_options', 'luntan', [$this,'luntan_toplevelpage'] );
        
    }
    public function luntan_toplevelpage(){
         echo "<div id='luntan_ht_wztkj-app'></div>";
         $this->luntan_post_name();
    }
    public function  luntan_post_name(){
        
        global $wpdb;
        $luntan_post = new luntan_post();
        $posts_table = $wpdb->posts;

        // 查询post_name为空且post_type为luntan的文章
        $results = $wpdb->get_results(
            $wpdb->prepare(
                "SELECT ID, post_title FROM $posts_table WHERE post_name = '' AND post_type = %s",
                'luntan'
            ),
            OBJECT
        );
        if(!empty($results)){
            foreach ($results as $result) {
                // 基于文章标题生成post_name，sanitize_title_with_dashes函数会处理特殊字符
            
                // 更新文章的post_name
                $updated = $wpdb->update(
                    $posts_table,
                    array('post_name' => $luntan_post->luntan_generate_short_code($result->post_title?sanitize_text_field(wp_unslash($result->post_title)):$result->ID.'wztkj'.wp_rand(1000,9999))),
                    array('ID' => $result->ID),
                );
            
                
            }
        }
    }
     public function luntan_dssdd($value){
        global $luntan_wzt_log;
        $url = luntan_index::luntan_url(0);
        $log = $luntan_wzt_log;
        $type = 1;
        $arr = [
            md5($url),
            md5($log),
            md5($type),
            md5($url.$log),
            md5($url.$type),
            md5($log.$url),
            md5($log.$type),
            md5($type.$url),
            md5($type.$log),
            md5($url.$log.$type),
            md5($url.$type.$log),
            md5($log.$url.$type),
            md5($log.$type.$url),
            md5($type.$url.$log),
            md5($type.$log.$url),
        ];
        return $arr;
    }
     public static function luntan_get_token(){
        $luntan_wzt_token1 = get_option('luntan_wzt_token1');
        $luntan_wzt_token2 = get_option('luntan_wzt_token2');
        $luntan_wzt_token3 = get_option('luntan_wzt_token3');
        return [$luntan_wzt_token1,$luntan_wzt_token2,$luntan_wzt_token3];
    }
    public static function luntan_sanitizing_key($key,$arr){
        foreach ($arr as $item) {
            if (strpos($key, $item) !== false) {
                return $key;
            }
        }
        return 0;
    }
    public static function luntan_sanitizing_date1($key){
        if (strlen($key) !== 104) {
            return false;
        }
    
        // 提取各部分
        $a = substr($key, 32, 2);
        $b = substr($key, 66, 2);
        $c = substr($key, 100, 4);
        $today = date_i18n('Ymd', current_time('timestamp'));
        $num = $c.$b.$a;
        if((int)$num>(int)$today){
            return $key;
        }
        return 0;
    }
    public static function luntan_sanitizing_date2($key){
        if (strlen($key) !== 104) {
            return false;
        }
    
        // 提取各部分
        $a = substr($key, 32, 2);
        $b = substr($key, 66, 2);
        $c = substr($key, 100, 4);
        $today = date_i18n('Ymd', current_time('timestamp'));
        $num = $c.$a.$b;
        if((int)$num>(int)$today){
            return $key;
        }
        return 0;
    }
    public static function luntan_sanitizing_date3($key){
        if (strlen($key) !== 104) {
            return false;
        }
    
        // 提取各部分
        $a = substr($key, 32, 4);
        $b = substr($key, 68, 2);
        $c = substr($key, 102, 2);
       
        $today = date_i18n('Ymd', current_time('timestamp'));
        $num = $a.$b.$c;
        if((int)$num>(int)$today){
            return $key;
        }
        return 0;
    }
    public function luntan_dhdfkdksj($value){
        $arr = self::luntan_get_token();
       
        $arr1 = apply_filters('luntan_dssdd',2);
        $key= 0;
        foreach($arr as $k=>$v){
            
            if(self::luntan_sanitizing_key($v,$arr1)){
                switch ($k) {
                    case 0:
                        $key = self::luntan_sanitizing_date1($v);
                        if($key){
                            break 2;
                        }else{
                            break;
                        }
                    case 1:
                        $key = self::luntan_sanitizing_date2($v);
                        if($key){
                            break 2;
                        }else{
                            break;
                        }
                    case 2:
                        $key = self::luntan_sanitizing_date3($v);
                        if($key){
                            break 2;
                        }else{
                            break;
                        }
                   
                }
            }
        }
        return $key;
    }
    public function luntan_plugin_action_links($links){
       $links[] = '<a href="' . admin_url( 'admin.php?page=luntan' ) . '">设置</a>';
        return $links;
    }
    public function luntan_menus(){
        $luntan_url_guanli = get_option('luntan_url_guanli');
        if(isset($luntan_url_guanli['list']) && $luntan_url_guanli['list']){
            $luntan_url = $luntan_url_guanli['list'];
            $luntan_url_zx = $luntan_url_guanli['zhongxin'];
        }else{
            $luntan_url = 'ltwdsqht';
            $luntan_url_zx = 'ltwdsqht_zx';
        }
        $luntan_wzt_center = get_option('luntan_wzt_center');
        
        $existing_page = get_page_by_path($luntan_url_zx, OBJECT, 'page');
        if($luntan_wzt_center){
            if (!$existing_page) {
                $page_data = [
                    'ID'           => $luntan_wzt_center, // 目标页面ID
                    'post_name'    => $luntan_url_zx, // 新的slug（链接部分）
                ];
                // 更新页面
                wp_update_post($page_data);
            }
        }else{
            if (!$existing_page) {
               $one_page_id = wp_insert_post([
                    'post_title'   => 'ForumHub论坛/帖子/问答/社区/话题',
                    'post_type'    => 'page',
                    'post_status'  => 'publish',
                    'post_name'    => $luntan_url_zx
                ]);
                if($luntan_wzt_center===false){
                    add_option('luntan_wzt_center',$one_page_id);
                }else{
                    update_option('luntan_wzt_center',$one_page_id);
                }
            }
        }
        
        
        $query1 = new WP_Query([
            'title' => '服务协议',
            'post_type' => 'page',
            'posts_per_page' => 1,
            'post_name'=>"fuwuxieyi"
            
        ]);
        
        if (!$query1->have_posts()) {
            wp_insert_post([
                'post_title' => '服务协议',
                'post_type'  => 'page',
                'post_status' => 'publish',
                'post_name'    => 'fuwuxieyi' 
            ]);
        }
        
    }
    public function luntan_template($template){
        global $wp_query;
        $luntan_url_guanli = get_option('luntan_url_guanli');
        if(isset($luntan_url_guanli['list']) && $luntan_url_guanli['list']){
            $luntan_url = $luntan_url_guanli['list'];
            $luntan_url_zx = $luntan_url_guanli['zhongxin'];
        }else{
            $luntan_url = 'ltwdsqht';
            $luntan_url_zx = 'ltwdsqht_zx';
        }
        if(is_page()){
            if (isset($wp_query->query) && isset($wp_query->query['pagename'])) {
                if($wp_query->query['pagename']==$luntan_url_zx){
                    $plugin_path = realpath(plugin_dir_path( __FILE__ ));
                    $template_path = $plugin_path. '/template/luntan_person.php';
                    return $template_path;
                }elseif($wp_query->query['pagename']=='fuwuxieyi'){
                    $plugin_path = realpath(plugin_dir_path( __FILE__ ));
                    $template_path = $plugin_path. '/template/luntan_xy.php';
                    return $template_path;
                }
            }
        }
        return $template;
    }
    public function luntan_block_enqueue(){
         if(luntan_is_block_theme()){
            
            if ( function_exists( 'wp_enqueue_block_support_styles' ) ) {
                wp_enqueue_block_support_styles( 'wp-block-library' );
            }
            // 加载主题的全局样式
            if (function_exists('wp_enqueue_global_styles')) {
                wp_enqueue_global_styles();
            }
            if (function_exists('wp_enqueue_global_styles_css_custom_properties')) {
                wp_enqueue_global_styles_css_custom_properties();
            }
            if (wp_theme_has_theme_json()) {
                wp_enqueue_style('global-styles');
            }
            // 加载核心块的样式（确保加载）
            wp_enqueue_style( 'wp-block-library' );
            wp_enqueue_style( 'wp-block-library-theme' );
            
            // 显式加载你使用的块（注意：要匹配核心注册的 handle）
            wp_enqueue_style( 'wp-block-navigation' );
            wp_enqueue_style( 'wp-block-site-title' );
            wp_enqueue_style( 'wp-block-group' );
            wp_enqueue_style( 'wp-block-paragraph' );
        
            // 加载全局样式（变量定义等）
            if ( function_exists( 'wp_get_global_stylesheet' ) ) {
                wp_add_inline_style( 'wp-block-library', wp_get_global_stylesheet() );
            }
            // wp_enqueue_script('wp-blocks');
            // wp_enqueue_script('wp-block-library');
            // wp_enqueue_script('wp-polyfill');
            
            // 加载导航菜单相关JS
            // wp_enqueue_script('wp-block-navigation');
            
            // 加载主题的JS
            // if (function_exists('wp_enqueue_global_styles')) {
                // wp_enqueue_script('wp-edit-blocks');
            // }
            
    
            // wp_enqueue_script('wp-interactivity');
        
            echo '<script type="importmap" id="wp-importmap">
            {"imports":{"@wordpress\/interactivity":"'.esc_url(luntan_index::luntan_url(1)).'\/wp-includes\/js\/dist\/script-modules\/interactivity\/index.min.js"}}
             </script>';
            wp_register_script( 'luntan_ndyd', esc_url(luntan_index::luntan_url(1)).'/wp-includes/js/dist/script-modules/block-library/navigation/view.min.js',  array('jquery'),'1.0', true);
            add_filter('script_loader_tag', function($tag, $handle) {
                if ($handle === 'luntan_ndyd') {
                    return str_replace('<script ', '<script type="module" ', $tag);
                }
                
                
                return $tag;
            }, 10, 2);
             
          
            wp_enqueue_script('luntan_ndyd');
        }
    }
    public function luntan_enqueue(){
        $luntan_url_guanli = get_option('luntan_url_guanli');
        if(isset($luntan_url_guanli['list']) && $luntan_url_guanli['list']){
            $luntan_url = $luntan_url_guanli['list'];
            $luntan_url_zx = $luntan_url_guanli['zhongxin'];
        }else{
            $luntan_url = 'ltwdsqht';
            $luntan_url_zx = 'ltwdsqht_zx';
        }
        if(is_page($luntan_url_zx)){
            require plugin_dir_path( LUNTAN_FILE ) . 'inc/assets.php';
            $this->luntan_block_enqueue();
            foreach($assets as $key=>$val){
                if($val['type']=='css'){
                     wp_register_style(
                        $val['name'],
                        plugin_dir_url(LUNTAN_FILE). 'inc'. $val['url'],
                        array(), // 没有依赖的其他样式表
                        LUNTAN_VERSION, // 样式表版本号，可根据实际情况更新
                        'all' // 适用于所有媒体类型
                    );
                    
                    // 排队加载（引入）已注册的样式表
                    wp_enqueue_style($val['name']);
                     
                }elseif($val['type']=='js'){
                    wp_register_script(
                    $val['name'],
                    plugin_dir_url(LUNTAN_FILE). 'inc'. $val['url'],
                    array(), // 没有依赖的其他脚本
                    LUNTAN_VERSION, // 脚本版本号，可根据实际情况更新
                    true // 脚本在页脚加载
                );
                
                // 排队加载（引入）已注册的脚本
                wp_enqueue_script($val['name']);
                }
            }
            wp_register_script('luntan.js', false, [], LUNTAN_VERSION,false);
            wp_enqueue_script('luntan.js');
            $luntan_version  = esc_url_raw(admin_url('plugin-install.php?tab=plugin-information&plugin=luntan'));
            if(isset($luntan_url_guanli['list']) && $luntan_url_guanli['list']){
                $luntan_url = $luntan_url_guanli['list'];
                $luntan_url_zx = $luntan_url_guanli['zhongxin'];
            }else{
                $luntan_url = 'ltwdsqht';
                $luntan_url_zx = 'ltwdsqht_zx';
            }
            wp_add_inline_script('luntan.js', 'var luntan_wztkj_url="'.plugin_dir_url(LUNTAN_FILE).'inc",luntan_nonce="'. esc_attr(wp_create_nonce('luntan')).'",luntan_ajax="'.esc_url(admin_url('admin-ajax.php')).'",luntan_logout ="'.wp_logout_url(home_url('/'.$luntan_url)).'",luntan_url="/'.$luntan_url.'";', 'before');
        }elseif(is_post_type_archive('luntan') || is_tax('luntan_cate')) {
            
            wp_enqueue_script('jquery');
            $this->luntan_block_enqueue();
            
            wp_register_script( 'luntan_archive_Script.js', plugin_dir_url( LUNTAN_FILE ).'inc/index/pageScript/luntan_archive_Script.js',  array('jquery'),'1.0', true);
            
            wp_enqueue_script('luntan_archive_Script.js');
           
            wp_enqueue_style( 'luntan_reset.css',  plugin_dir_url( LUNTAN_FILE ).'inc/index/assets/reset.css',false,LUNTAN_VERSION,'all');
            wp_enqueue_style( 'luntan_index.css',  plugin_dir_url( LUNTAN_FILE ).'inc/index/css/index.css',false,LUNTAN_VERSION,'all');
            wp_register_script('luntan.js', false, [], LUNTAN_VERSION,false);
            wp_enqueue_script('luntan.js');
            wp_add_inline_script('luntan.js', 'var luntan_wztkj_url="'.esc_js(plugin_dir_url(LUNTAN_FILE)).'inc",luntan_nonce="'. esc_attr(wp_create_nonce('luntan')).'",luntan_ajax="'.esc_url(admin_url('admin-ajax.php')).'",luntan_logout ="'.wp_logout_url(home_url('/'.$luntan_url)).'";', 'before');
             
        }elseif(is_singular('luntan')){
            
            wp_enqueue_script('jquery');
            $this->luntan_block_enqueue();
            wp_register_script( 'luntan_single_Script.js', plugin_dir_url( LUNTAN_FILE ).'inc/index/pageScript/luntan_single_Script.js', array('jquery'),'1.0', true);
            add_filter('script_loader_tag', function($tag, $handle) {
                if ($handle === 'luntan_single_Script.js') {
                    return str_replace('<script ', '<script type="module" ', $tag);
                }
                
                return $tag;
            }, 10, 2);
            wp_enqueue_script('luntan_single_Script.js');
            wp_localize_script('luntan_single_Script.js', 'luntan_single_Script_ID', array(
                'ID' => get_the_ID() 
            ));
            wp_enqueue_style( 'luntan_reset.css',  plugin_dir_url( LUNTAN_FILE ).'inc/index/assets/reset.css',false,LUNTAN_VERSION,'all');
             wp_enqueue_style( 'luntan_detail.css',  plugin_dir_url( LUNTAN_FILE ).'inc/index/css/detail.css',false,LUNTAN_VERSION,'all');
             wp_register_script('luntan.js', false, null, LUNTAN_VERSION,false);
            wp_enqueue_script('luntan.js');
            wp_add_inline_script('luntan.js', 'var luntan_wztkj_url="'.esc_js(plugin_dir_url(LUNTAN_FILE)).'inc",luntan_nonce="'. esc_attr(wp_create_nonce('luntan')).'",luntan_ajax="'.esc_url(admin_url('admin-ajax.php')).'",luntan_logout ="'.wp_logout_url(home_url('/'.$luntan_url)).'";', 'before');
        }
    }
    public function luntan_tongji($luntan_key){

        $luntan_tongji = get_option('luntan_tongji');
        if(!$luntan_tongji || (isset($luntan_tongji) && $luntan_tongji['time']<time()) ){
            $wp_version =  get_bloginfo('version');
            $data = luntan_index::luntan_url(0);
        	$url = "https://art.seohnzz.com/api/luntan/index?url={$data}&type=9&url1=".md5($data.'seohnzz.com')."&theme_version=".LUNTAN_VERSION."&php_version=".PHP_VERSION."&wp_version={$wp_version}&token={$luntan_key}";
        	$defaults = array(
                'timeout' => 120,
                'connecttimeout'=>120,
                'redirection' => 3,
                'user-agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36',
                'sslverify' => FALSE,
            );
            $result = wp_remote_get($url,$defaults);
            if($luntan_tongji!==false){
                update_option('luntan_tongji',['time'=>time()+7*3600*24]);
            }else{
                add_option('luntan_tongji',['time'=>time()+7*3600*24]);
            }
        }
    }
    public static function luntan_url($type=0){
        if($type==1){
            $url1 = get_option('siteurl');
            $url1 = wp_parse_url($url1);
            $url1 = $url1['scheme'].'://'.$url1['host'];
            return $url1;
        }else{
            $url1 = get_option('siteurl');
            $url1 = str_replace('https://','',$url1);
            $url1 = str_replace('http://','',$url1);
            $url1 = trim($url1,'/');
            $url1 = explode('/',$url1);
            return $url1[0];
        }
    }
     public static function pay_money(){
         global $luntan_wzt_log;
        if(!$luntan_wzt_log){
            return 0;
        }
        $data = luntan_index::luntan_url(0);
        
        $url = "https://art.seohnzz.com/api/index/pay_money?url={$data}&type=9&log={$luntan_wzt_log}";
        $defaults = array(
            'timeout' => 4000,
            'connecttimeout'=>4000,
            'redirection' => 3,
            'user-agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36',
            'sslverify' => FALSE,
        );
        $result = wp_remote_get($url,$defaults);
        
        if(!is_wp_error($result)){
            
            $content = wp_remote_retrieve_body($result);
            
            $content = json_decode($content,true);
            
            
            if(isset($content['status']) && $content['status']==1){
                if(isset($content['token1']) && $content['token1']){
                    $luntan_wzt_token1 = get_option('luntan_wzt_token1');
                    if($luntan_wzt_token1===false){
                        add_option('luntan_wzt_token1',$content['token1']);
                    }else{
                        update_option('luntan_wzt_token1',$content['token1']);
                    }
                }
                if(isset($content['token2']) && $content['token2']){
                    $luntan_wzt_token2 = get_option('luntan_wzt_token2');
                    if($luntan_wzt_token2===false){
                        add_option('luntan_wzt_token2',$content['token2']);
                    }else{
                        update_option('luntan_wzt_token2',$content['token2']);
                    }
                }
                if(isset($content['token3']) && $content['token3']){
                    $luntan_wzt_token3 = get_option('luntan_wzt_token3');
                    if($luntan_wzt_token3===false){
                        add_option('luntan_wzt_token3',$content['token3']);
                    }else{
                        update_option('luntan_wzt_token3',$content['token3']);
                    }
                }
                return 1;
            }elseif(isset($content['status']) && $content['status']==0){
                return 0;
            }else{
                $url = "https://wyc.seohnzz.com/index/index/pay_money?url={$data}&type=9";
            
                $result = wp_remote_get($url,$defaults);
                
                if(!is_wp_error($result)){
                    $content = wp_remote_retrieve_body($result);
                    
                    $content = json_decode($content,true);
                    if(isset($content['status']) && $content['status']==1){
                        return 1;
                    }
                    return 0;
                }else{
                   $url = "https://wyc.seohnzz.com/index/index/pay_money?url={$data}&type=9";
                    	$defaults = array(
                            'timeout' =>4000,
                            'connecttimeout'=>4000,
                            'redirection' => 3,
                            'user-agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36',
                            'sslverify' => FALSE,
                        );
                    	$result = wp_remote_get($url,$defaults);
                    	if(!is_wp_error($result)){
                            $content = wp_remote_retrieve_body($result);
                        	$content = json_decode($content,true);
                        	if(isset($content['status']) && $content['status']==1){
                        	    return 1;
                        	}
                    	}else{
                    	    return 0;
                    	}
                }
            }
        }else{
            
        
            $url = "https://wyc.seohnzz.com/index/index/pay_money?url={$data}&type=9";
            
                $result = wp_remote_get($url,$defaults);
                
                if(!is_wp_error($result)){
                    $content = wp_remote_retrieve_body($result);
                    
                    $content = json_decode($content,true);
                    if(isset($content['status']) && $content['status']==1){
                        return 1;
                    }
                    
                }
                
            return 0;
        }
            
    }
}