<?php
if(!defined('ABSPATH'))exit;
class baiduseo_post{
    private $baiduseo_get_option;
    public function init(){
        $this->baiduseo_get_option = $this->baiduseo_get_option();
        foreach($this->baiduseo_get_option as $k=>$v){
            add_action('wp_ajax_'.$k, [$this,'baiduseo_ajax_post']);
        }
    }
    public function baiduseo_get_option(){
        return [
            'baiduseo_zhizhu'=>1,
            'baiduseo_seo'=>1,
            'baiduseo_zz'=>1, 
            'baiduseo_rank'=>1,  
            'baiduseo_zhizhu_clear'=>1,  
            'baiduseo_tag'=>1,  
            'baiduseo_tag_add'=>1,  
            'baiduseo_tag_pladd'=>1,  
            'baiduseo_neilian'=>1,  
            'baiduseo_neilian_delete'=>1,  
            'baiduseo_neilian_delete_all'=>1,  
            'baiduseo_reci'=>1,  
            'baiduseo_add_tag'=>1,  
            'baiduseo_add_pltag'=>1,
            'baiduseo_ptts'=>1, 
            'baiduseo_yindao_three'=>1, 
            'baiduseo_yindao_four'=>1, 
            'baiduseo_yindao_five'=>1, 
            'baiduseo_liuliang'=>1,
            'baiduseo_liuliang_delete'=>1,
            'baiduseo_301'=>0,
            'baiduseo_wyc'=>0,
            'baiduseo_youhua'=>0,
            'baiduseo_pingfen'=>0,
            'baiduseo_robots'=>0,
            'baiduseo_yindao'=>0,
            'baiduseo_aidk'=>0,
            'baiduseo_percent'=>0,
            'baiduseo_yindao_second'=>0,
            'baiduseo_yindao_first'=>0,
            'baiduseo_ai_lishis'=>0,
            'baiduseo_ai_lishiz'=>0,
            'baiduseo_ai_lishi'=>0,
            'baiduseo_shenhe'=>0,
            'baiduseo_address_delete'=>0,
            'baiduseo_add_link'=>0,
            'baiduseo_pingbi'=>0,
            'baiduseo_yanzheng'=>0,
            'baiduseo_gaixie'=>0,
            'baiduseo_kuaisu'=>0,
            'baiduseo_yuanchuang'=>0,
            'baiduseo_wycsc'=>0,
            'baiduseo_zhizhu_linkdelete'=>0,
            'baiduseo_linkhh'=>0,
            'baiduseo_5118_daochu'=>0,
            'baiduseo_5118'=>0,
            'baiduseo_shouquan'=>0,
            'baiduseo_seo_jc'=>1,
            'baiduseo_seo_jc_res'=>0,
        ];
    }
    public function baiduseo_seo_jc_res(){
        if(isset($_POST['nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['nonce'])),'baiduseo')){
            global $wpdb;
            $baiduseo_wzjc = get_option('baiduseo_wzjc');
            if($baiduseo_wzjc==1){
                $list = $wpdb->get_results('select * from '.$wpdb->prefix . 'baiduseo_wzjc ',ARRAY_A);
                $baiduseo_wzjc_count = get_option('baiduseo_wzjc_count');
                $baiduseo_wzjc_count['list'] = $list;
                $baiduseo_wzjc_num = get_option('baiduseo_wzjc_num');
                $baiduseo_wzjc_count = array_merge($baiduseo_wzjc_count,$baiduseo_wzjc_num);
                $baiduseo_wzjc_count['code'] =1;
                echo wp_json_encode($baiduseo_wzjc_count);exit;
            }elseif($baiduseo_wzjc===false){
                echo wp_json_encode(['code'=>0,'msg'=>'未进行检测过']);exit;
            }else{
                $this->baiduseo_wzjc();
            }
            
        }
        echo wp_json_encode(['code'=>0]);exit;
    }
    public function baiduseo_wzjc(){
        global $wpdb;
        $url = baiduseo_common::baiduseo_url(1);
        $result = wp_remote_post('https://api.seoceo.cn/api/Wzjc/get_wzjc',['body'=>['url'=>$url]]);
         if(!is_wp_error($result)){
            $result = wp_remote_retrieve_body($result);
            
            $result = json_decode($result,true);
            if($result['code']){
                $data = $result['data'];
                $baiduseo_wzjc_count = get_option('baiduseo_wzjc_count');
                if($baiduseo_wzjc_count===false){
                    add_option('baiduseo_wzjc_count',['url_count'=>(int)$data['url_count'],'error_count'=>(int)$data['error_count'],'error_leixing'=>(int)$data['error_leixing']]);
                }else{
                    update_option('baiduseo_wzjc_count',['url_count'=>(int)$data['url_count'],'error_count'=>(int)$data['error_count'],'error_leixing'=>(int)$data['error_leixing']]);
                }
                
                if(isset($data['list'])){
                    $wpdb->query("DELETE FROM " . $wpdb->prefix . "baiduseo_wzjc");
                    update_option('baiduseo_wzjc',1);
                    foreach($data['list'] as $k=>$v){
                        $res = $wpdb->insert($wpdb->prefix."baiduseo_wzjc",['url'=>sanitize_url(wp_unslash($v['url'])),'content'=>sanitize_text_field(wp_unslash($v['content'])),'level'=>(int)$v['level'],'txt'=>sanitize_text_field(wp_unslash($v['txt'])),'url1'=>sanitize_url(wp_unslash($v['url1']))]);
                    }
                    $data['code'] =1;
                }else{
                    $data['code'] =2;
                }
                $data['time'] = get_option('baiduseo_wzjc_num')['time'];
                
                echo wp_json_encode($data);exit;
                
                
               
            }
        }
        
    }
    public function baiduseo_seo_jc($log,$log1,$log2){
        if(isset($_POST['nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['nonce'])),'baiduseo')){
            if($log1['status']){
            }else{
                echo wp_json_encode(['msg'=>'请先授权','code'=>0]);exit;
            }
            if($log2['token']){
            }else{
                echo wp_json_encode(['msg'=>'请先授权','code'=>0]);exit;
            }
            $log3 = apply_filters('baiduseo_check4', true, $log1['token']);
            $log3 = json_decode($log3,true);
            $log4 = apply_filters('baiduseo_check5', true, $log1['token']);
            $log4 = json_decode($log4,true);
            $log5 = apply_filters('baiduseo_check6', true, $log1['token']);
            $log5 = json_decode($log5,true);
            
            
            
            
            $log3_code = is_array($log3) && isset($log3['code']) ? $log3['code'] : false; $log4_code = is_array($log4) &&  isset($log4['code']) ? $log4['code'] : false; $log5_code = is_array($log5)&&  isset($log5['code'])  ? $log5['code'] : false; if(!$log3_code && !$log4_code && !$log5_code ){
                $ss  = baiduseo_zz::pay_money();
                if(!$ss){
                     echo wp_json_encode(['msg'=>'请先授权','code'=>0]);exit;
                }
            }else{
                $log6 = apply_filters('baiduseo_check7', true, $log1['token'],$log2['token'],$log3['code'],$log4['code'],$log5['code']);
                if(!$log6){
                    $ss  = baiduseo_zz::pay_money();
                    if(!$ss){
                         echo wp_json_encode(['msg'=>'请先授权','code'=>0]);exit;
                    }
                }
            }
            
            $baiduseo_wzjc = get_option('baiduseo_wzjc');
            $baiduseo_wzjc_num = get_option('baiduseo_wzjc_num');
            $num = (int)$_POST['num'];
            
            $url = baiduseo_common::baiduseo_url(1);
            $result = wp_remote_post('https://api.seoceo.cn/api/Wzjc/add_renwu',['body'=>['num'=>$num,'url'=>$url]]);
            if(!is_wp_error($result)){
                $result = wp_remote_retrieve_body($result);
                
                $result = json_decode($result,true);
                
                if($result['code']){
                    if($baiduseo_wzjc===false){
                        add_option('baiduseo_wzjc',0);
                    }else{
                        update_option('baiduseo_wzjc',0);
                    }
                    if($baiduseo_wzjc_num===false){
                        add_option('baiduseo_wzjc_num',['num'=>$num,'time'=>current_time('Y-m-d H:i:s')]);
                    }else{
                        update_option('baiduseo_wzjc_num',['num'=>$num,'time'=>current_time('Y-m-d H:i:s')]);
                    }
                    echo wp_json_encode(['msg'=>'提交成功','code'=>1]);exit;
                }else{
                    echo wp_json_encode(['msg'=>'提交失败，请刷新页面后重试','code'=>0]);exit;
                }
            }
        }
        echo wp_json_encode(['code'=>0]);exit;
    }
    public function baiduseo_ajax_post(){
        if (!current_user_can('manage_options')) {
            echo wp_json_encode(['code'=>0]);exit;
        }
        if(isset($_POST['nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['nonce'])),'baiduseo')){
            $action = sanitize_text_field(wp_unslash($_POST['action']));
            $action1 = $this->baiduseo_get_option[$action];
            $log = apply_filters('baiduseo_check1', true, $action1);
            $log1 = apply_filters('baiduseo_check2', true, $action1);
            $log2 = apply_filters('baiduseo_check3', true, $action1);
            $this->$action($log,$log1,$log2);
            exit;
        }
        echo wp_json_encode(['code'=>0]);exit;
        
    }
    
    public function baiduseo_pingfen($log,$log1,$log2){
        if(isset($_POST['nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['nonce'])),'baiduseo')){
           $baiduseo_pingfen = get_option('baiduseo_pingfen');
            if($baiduseo_pingfen!==false){
               update_option('baiduseo_pingfen',isset($_POST['pingfen'])?(int)$_POST['pingfen']:0);
            }else{
               add_option('baiduseo_pingfen',isset($_POST['pingfen'])?(int)$_POST['pingfen']:0);
            }
            echo wp_json_encode(['code'=>1]);exit;
        }
        echo wp_json_encode(['code'=>0]);exit;
    }
    public function baiduseo_robots($log,$log1,$log2){
        if(isset($_POST['nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['nonce'])),'baiduseo')){
             if(isset($_POST['robots'])){
                baiduseo_seo::robots(sanitize_textarea_field(wp_unslash($_POST['robots'])));
            }
            echo wp_json_encode(['code'=>1]);exit;
        }
        echo wp_json_encode(['code'=>0]);exit;
    }
    public function baiduseo_yindao($log,$log1,$log2){
        if(isset($_POST['nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['nonce'])),'baiduseo')){
           $baiduseo_yindao = get_option('baiduseo_yindao');
           if($baiduseo_yindao!==false){
               update_option('baiduseo_yindao',1);
           }else{
               add_option('baiduseo_yindao',1);
           }
            echo wp_json_encode(['code'=>1]);exit;
        }
        echo wp_json_encode(['code'=>0]);exit;
    }
    public function baiduseo_liuliang_delete($log,$log1,$log2){
        if(isset($_POST['nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['nonce'])),'baiduseo')){
            global $wpdb;
            if($log1['status']){
            }else{
                echo wp_json_encode(['msg'=>'请先授权','code'=>0]);exit;
            }
            
            
            
            if($log2['token']){
            }else{
                echo wp_json_encode(['msg'=>'请先授权','code'=>0]);exit;
            }
            $log3 = apply_filters('baiduseo_check4', true, $log1['token']);
            $log3 = json_decode($log3,true);
            $log4 = apply_filters('baiduseo_check5', true, $log1['token']);
            $log4 = json_decode($log4,true);
            $log5 = apply_filters('baiduseo_check6', true, $log1['token']);
            $log5 = json_decode($log5,true);
            
            
            
            
            $log3_code = is_array($log3) && isset($log3['code']) ? $log3['code'] : false; $log4_code = is_array($log4) &&  isset($log4['code']) ? $log4['code'] : false; $log5_code = is_array($log5)&&  isset($log5['code'])  ? $log5['code'] : false; if(!$log3_code && !$log4_code && !$log5_code ){
                $ss  = baiduseo_zz::pay_money();
                if(!$ss){
                     echo wp_json_encode(['msg'=>'请先授权','code'=>0]);exit;
                }
            }else{
                $log6 = apply_filters('baiduseo_check7', true, $log1['token'],$log2['token'],$log3['code'],$log4['code'],$log5['code']);
                if(!$log6){
                    $ss  = baiduseo_zz::pay_money();
                    if(!$ss){
                         echo wp_json_encode(['msg'=>'请先授权','code'=>0]);exit;
                    }
                }
            }
           
            
            $res = $wpdb->query("DELETE FROM " . $wpdb->prefix . "baiduseo_liuliang");
            echo wp_json_encode(['msg'=>'操作成功','code'=>1]);exit;
        }
        echo wp_json_encode(['msg'=>'操作失败','code'=>0]);exit;
    }
    public function baiduseo_aidk($log,$log1,$log2){
        if(isset($_POST['nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['nonce'])),'baiduseo')){
            $codea = isset($_POST['codea'])?(int)$_POST['codea']:0;
            $msg = isset($_POST['msg'])?sanitize_text_field(wp_unslash($_POST['msg'])):'';
            $defaults = array(
                'timeout' => 10000,
                'connecttimeout'=>10000,
                '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,
            );
            $url1 = baiduseo_common::baiduseo_url(0);
            
           
            $result = wp_remote_get('https://api.seoceo.cn/api/index/zhongzhuan1?codea='.$codea.'&msg='.$msg.'&url='.$url1,$defaults);
            
            if(!is_wp_error($result)){
                $content = wp_remote_retrieve_body($result);
           
              
                //验证
                $content1 = json_decode($content,true);
               
                if($content1['code']==0){
                    echo wp_json_encode(['code'=>$content1['code'],'msg'=>esc_attr($content1['msg'])]);exit;
                   
                }elseif($content1['code']==1){
                    echo wp_json_encode(['code'=>$content1['code'],'data'=>str_replace("，",",",sanitize_text_field(wp_unslash($content1['data'])))]);exit;
                    exit;
                }elseif($content1['code']==2){
                    
                    echo wp_json_encode(['code'=>1,'data'=>sanitize_textarea_field(wp_unslash($content1['data']))]);exit;
                    exit;
                }else{
                    echo wp_json_encode(['code'=>0,'msg'=>'请求失败']);exit;
                    exit;
                }
                
            }
        }
        echo wp_json_encode(['msg'=>'操作失败','code'=>0]);exit;
    }
    public function baiduseo_liuliang($log,$log1,$log2){
        if(isset($_POST['nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['nonce'])),'baiduseo')){
            if($log1['status']){
                $open = isset($_POST['open'])?(int)$_POST['open']:0;
                $log = isset($_POST['log'])?(int)$_POST['log']:0;
            }else{
                echo wp_json_encode(['msg'=>'请先授权','code'=>0]);exit;
            }
            
            
            
            if($log2['token']){
                $pinci = isset($_POST['pinci'])?(int)$_POST['pinci']:0;
                $diyu = isset($_POST['diyu'])?(int)$_POST['diyu']:0;
            }else{
                echo wp_json_encode(['msg'=>'请先授权','code'=>0]);exit;
            }
            $log3 = apply_filters('baiduseo_check4', true, $log1['token']);
            $log3 = json_decode($log3,true);
            $log4 = apply_filters('baiduseo_check5', true, $log1['token']);
            $log4 = json_decode($log4,true);
            $log5 = apply_filters('baiduseo_check6', true, $log1['token']);
            $log5 = json_decode($log5,true);
            
            
            
            
            $log3_code = is_array($log3) && isset($log3['code']) ? $log3['code'] : false; $log4_code = is_array($log4) &&  isset($log4['code']) ? $log4['code'] : false; $log5_code = is_array($log5)&&  isset($log5['code'])  ? $log5['code'] : false; if(!$log3_code && !$log4_code && !$log5_code ){
                $ss  = baiduseo_zz::pay_money();
                if(!$ss){
                     echo wp_json_encode(['msg'=>'请先授权','code'=>0]);exit;
                }
            }else{
                $log6 = apply_filters('baiduseo_check7', true, $log1['token'],$log2['token'],$log3['code'],$log4['code'],$log5['code']);
                if(!$log6){
                    $ss  = baiduseo_zz::pay_money();
                    if(!$ss){
                         echo wp_json_encode(['msg'=>'请先授权','code'=>0]);exit;
                    }
                }
            }
            
            
            
            $baiduseo_wyc = get_option('baiduseo_liuliang');
            if($baiduseo_wyc!==false){
                $res = update_option('baiduseo_liuliang',['open'=>$open,'log'=>$log,'pinci'=>$pinci,'diyu'=>$diyu]);
            }else{
                $res = add_option('baiduseo_liuliang',['open'=>$open,'log'=>$log,'pinci'=>$pinci,'diyu'=>$diyu]);
            }
            baiduseo_set::baiduseo_set_option(baiduseo_kp::baiduseo_wzt_log(),'baiduseo_liuliang',['open'=>$open,'log'=>$log,'pinci'=>$pinci,'diyu'=>$diyu]);
            
            echo wp_json_encode(['msg'=>'保存成功','code'=>1]);exit;
            
        }
        echo wp_json_encode(['msg'=>'保存失败','code'=>0]);exit;
    }
    public function baiduseo_wyc($log,$log1,$log2){
        if(isset($_POST['nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['nonce'])),'baiduseo')){
            $wyc = isset($_POST['wyc'])?(int)$_POST['wyc']:0;
            $gx = isset($_POST['gx'])?(int)$_POST['gx']:0;
            $wyc_min = isset($_POST['wyc_min'])?(int)$_POST['wyc_min']:0;
            $baiduseo_wyc = get_option('baiduseo_wyc');
            if($baiduseo_wyc!==false){
               update_option('baiduseo_wyc',['wyc'=>$wyc,'gx'=>$gx,'wyc_min'=>$wyc_min]);
            }else{
                add_option('baiduseo_wyc',['wyc'=>$wyc,'gx'=>$gx,'wyc_min'=>$wyc_min]);
            }
            baiduseo_set::baiduseo_set_option(baiduseo_kp::baiduseo_wzt_log(),'baiduseo_wyc',['wyc'=>$wyc,'gx'=>$gx,'wyc_min'=>$wyc_min]);
            echo wp_json_encode(['msg'=>'保存成功','code'=>1]);exit;
            
        }
        echo wp_json_encode(['msg'=>'保存失败','code'=>0]);exit;
    }
    public function baiduseo_zhizhu($log,$log1,$log2){
        if(isset($_POST['nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['nonce'])),'baiduseo')){
             $baiduseo_wzt_log = baiduseo_kp::baiduseo_wzt_log();
            if(!$baiduseo_wzt_log){
                 echo wp_json_encode(['code'=>'0','msg'=>'请先授权']);exit;
            }
            if($log1['status']){
                 $list = [
                    'open'=>isset($_POST['open'])?(int)$_POST['open']:0,
                    'log'=>isset($_POST['log'])?(int)$_POST['log']:0,
                    'type'=>isset($_POST['type'])?sanitize_text_field(wp_unslash($_POST['type'])):0,
                ];
            }else{
                echo wp_json_encode(['msg'=>'请先授权','code'=>0]);exit;
            }
            
            
            
            if($log2['token']){
                $baiduseo_zhizhu = get_option('baiduseo_zhizhu');
            }else{
                echo wp_json_encode(['msg'=>'请先授权','code'=>0]);exit;
            }
            $log3 = apply_filters('baiduseo_check4', true, $log1['token']);
            $log3 = json_decode($log3,true);
            $log4 = apply_filters('baiduseo_check5', true, $log1['token']);
            $log4 = json_decode($log4,true);
            $log5 = apply_filters('baiduseo_check6', true, $log1['token']);
            $log5 = json_decode($log5,true);
            
            
            
            
            $log3_code = is_array($log3) && isset($log3['code']) ? $log3['code'] : false; $log4_code = is_array($log4) &&  isset($log4['code']) ? $log4['code'] : false; $log5_code = is_array($log5)&&  isset($log5['code'])  ? $log5['code'] : false; if(!$log3_code && !$log4_code && !$log5_code ){
                $ss  = baiduseo_zz::pay_money();
                if(!$ss){
                     echo wp_json_encode(['msg'=>'请先授权','code'=>0]);exit;
                }
            }else{
                $log6 = apply_filters('baiduseo_check7', true, $log1['token'],$log2['token'],$log3['code'],$log4['code'],$log5['code']);
                if(!$log6){
                    $ss  = baiduseo_zz::pay_money();
                    if(!$ss){
                         echo wp_json_encode(['msg'=>'请先授权','code'=>0]);exit;
                    }
                }
            }
           
           
           
            
            if($baiduseo_zhizhu!==false){
                update_option('baiduseo_zhizhu',$list);
            }else{
                add_option('baiduseo_zhizhu',$list);
            }
            baiduseo_set::baiduseo_set_option($baiduseo_wzt_log,'baiduseo_zhizhu',$list);
            echo wp_json_encode(['msg'=>'保存成功','code'=>1]);exit;
        }
        echo wp_json_encode(['msg'=>'保存失败','code'=>0]);exit;
    }
    public function baiduseo_ai_lishi($log,$log1,$log2){
        if(isset($_POST['nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['nonce'])),'baiduseo')){
            global $wpdb;
             $current_time = current_time( 'Y/m/d H:i:s');
             if(!isset($_POST['hexin'])){
                $_POST['hexin'] =''; 
             }
             if(!isset($_POST['guangjianci'])){
                $_POST['guangjianci'] =''; 
             }
             if(!isset($_POST['neirong'])){
                $_POST['neirong'] =''; 
             }
            $res = $wpdb->insert($wpdb->prefix."baiduseo_ai_lishi",['hexin'=>sanitize_text_field(wp_unslash($_POST['hexin'])),'guangjianci'=>sanitize_text_field(wp_unslash($_POST['guangjianci'])),'neirong'=>sanitize_text_field(wp_unslash($_POST['neirong'])),'riqi'=>$current_time,'jifen'=>'0.2']);
            if($res){
                echo wp_json_encode(['msg'=>'保存成功','code'=>1]);exit;
            }
        }
        echo wp_json_encode(['msg'=>'保存失败','code'=>0]);exit;
        
    }
    public function baiduseo_ai_lishiz($log,$log1,$log2){
        if(isset($_POST['nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['nonce'])),'baiduseo')){
            global $wpdb;
            $p1 = isset($_POST['pages'])?(int)$_POST['pages']:1;
            $start1 = ($p1-1)*20;
            $count = $wpdb->query(' select * from  '.$wpdb->prefix.'baiduseo_ai_lishi',ARRAY_A);
           
            $list = $wpdb->get_results($wpdb->prepare('select * from '.$wpdb->prefix . 'baiduseo_ai_lishi  order by id desc limit %d ,20',$start1),ARRAY_A);
           $jifen = baiduseo_kp::get_jifen();
            echo wp_json_encode(['code'=>1,'msg'=>'','count'=>$count,'data'=>$list,'pagesize'=>20,'total'=>ceil($count/20),'jifen'=>$jifen]);exit;
           
        }
         echo wp_json_encode(['code'=>0,'msg'=>'获取失败',]);exit;
        
    }
      public function baiduseo_ai_lishis($log,$log1,$log2){
           if(isset($_POST['nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['nonce'])),'baiduseo')){
            global $wpdb;
            $id  = isset($_POST['id'])?(int)$_POST['id']:0;
             $res = $wpdb->query($wpdb->prepare("DELETE FROM " . $wpdb->prefix . "baiduseo_ai_lishi where id=  %d",(int)$id));
             
            if($res){
                echo wp_json_encode(['code'=>1,'msg'=>'删除成功']);exit;
            }else{
                echo wp_json_encode(['code'=>0,'msg'=>'删除失败']);exit;
            }
        }
        echo wp_json_encode(['code'=>0,'msg'=>'删除失败']);exit;
      }
    public function baiduseo_5118_daochu($log,$log1,$log2){
        if(isset($_POST['nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['nonce'])),'baiduseo')){
            global $wpdb;
            $keywords = isset($_POST['keywords'])?sanitize_text_field(wp_unslash($_POST['keywords'])):'';
            $total = isset($_POST['total'])?(int)$_POST['total']:0;
            $long = isset($_POST['long'])?(int)$_POST['long']:0;
            $collect = 0;
            $bidword = isset($_POST['bidword'])?(int)$_POST['bidword']:0;
            $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,
            );
            $data =  baiduseo_common::baiduseo_url(1);
            $url = 'https://api.seoceo.cn/api/rank/daochu?keywords='.$keywords.'&total='.$total.'&long='.$long.'&collect='.$collect.'&bidword='.$bidword.'&url='.$data;
            
            $result = wp_remote_get($url,$defaults);
            
            if(!is_wp_error($result)){
                $level = wp_remote_retrieve_body($result);
                $level = json_decode($level,true);
               
                if(isset($level['code']) && $level['code']==1){
                    $res = $wpdb->insert($wpdb->prefix."baiduseo_long",['keywords'=>$keywords,'total'=>$total,'longs'=>$long,'collect'=>$collect,'bidword'=>$bidword]);
                    echo wp_json_encode(['code'=>1,'msg'=>'申请成功，请等待响应！']);exit;
                }elseif(isset($level['code']) && $level['code']==2){
                    echo wp_json_encode(['code'=>0,'msg'=>'申请失败，积分不足']);exit;
                }
            }
        }
        echo wp_json_encode(['code'=>0,'msg'=>'申请失败，请稍后重试！']);exit;
    }
    public function baiduseo_5118($log,$log1,$log2){
        if(isset($_POST['nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['nonce'])),'baiduseo')){
            $name = isset($_POST['name'])?sanitize_text_field(wp_unslash($_POST['name'])):'';
            $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,
            );
            $url = 'https://api.seoceo.cn/api/rank/word_vip?keywords='.$name;
            $result = wp_remote_get($url,$defaults);
            if(!is_wp_error($result)){
                $level = wp_remote_retrieve_body($result);
                echo wp_json_encode(['code'=>1,'data'=>$level]);exit;
                
            }
        }
        echo wp_json_encode(['code'=>0,'msg'=>'获取失败']);exit;
    }
    public function baiduseo_percent($log,$log1,$log2){
        if(isset($_POST['nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['nonce'])),'baiduseo')){
            $type = isset($_POST['type'])?(int)$_POST['type']:1; 
            if($type==1){
                $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,
                );
                $url = 'https://api.seoceo.cn/api/money/level1?url='.baiduseo_common::baiduseo_url(0);
                $result = wp_remote_get($url,$defaults);
                if(!is_wp_error($result)){
                    $level = wp_remote_retrieve_body($result);
                    $level = json_decode($level,true);
                    if($level['version']==BAIDUSEO_VERSION){
                        echo wp_json_encode(['code'=>1]);exit;
                    }else{
                        echo wp_json_encode(['code'=>0]);exit;
                    }
                    
                }
            }elseif($type==22){
                $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,
                );
                $data =  baiduseo_common::baiduseo_url(1);
                $url = "https://api.seoceo.cn/api/speed/title?url={$data}";
                $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['code']) && $content['code']==1){
                        echo wp_json_encode(['code'=>1]);exit;
                    }else{
                        echo wp_json_encode(['code'=>0]);exit;
                    }
                }else{
                    echo wp_json_encode(['code'=>0]);exit;
                }
            }elseif($type==2){
                $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,
                );
                $data =  baiduseo_common::baiduseo_url(1);
                $url = "https://api.seoceo.cn/api/speed/keywords?url={$data}";
                $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['code']) && $content['code']==1){
                        echo wp_json_encode(['code'=>1]);exit;
                    }else{
                        echo wp_json_encode(['code'=>0]);exit;
                    }
                }else{
                    echo wp_json_encode(['code'=>0]);exit;
                } 
               
            }elseif($type==3){
                $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,
                );
                $data =  baiduseo_common::baiduseo_url(1);
                $url = "https://api.seoceo.cn/api/speed/description?url={$data}";
                $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['code']) && $content['code']==1){
                        echo wp_json_encode(['code'=>1]);exit;
                    }else{
                        echo wp_json_encode(['code'=>0]);exit;
                    }
                }else{
                    echo wp_json_encode(['code'=>0]);exit;
                } 
            }elseif($type==4){
                $seo_alt_auto = get_option('seo_alt_auto');
                if($seo_alt_auto!==false){
                    echo wp_json_encode(['code'=>1]);exit;
                }else{
                    echo wp_json_encode(['code'=>0]);exit;
                }
            }elseif($type==5){
                $defaults = array(
                    'timeout' => 4000,
                    'redirection' => 4000,
                    '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,
                    );
                $site_url = baiduseo_common::baiduseo_url(0).'/';
                $site_url1 = baiduseo_common::baiduseo_url(1);
                $http_type = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://';
                $url = str_replace('www.','',$site_url);
                $url_301['url1'] = $url;
                $url1 = $http_type.$url;
                $url_301['url2'] = 'www.'.$url;
                $url2 = $http_type.'www.'.$url;
                $url_301['status'] = 0;
                $result = wp_remote_get($url1,$defaults);
                if(!is_wp_error($result)){
                  $http = (array)$result['http_response'];
                  
                  $url_301['re_url1'] = $http["\0*\0response"]->url;
                }else{
                   $url_301['re_url1'] =''; 
                }
                $result1 = wp_remote_get($url2,$defaults);
                if(!is_wp_error($result1)){
                  $http1 = (array)$result1['http_response'];
                  
                  
                  $url_301['re_url2'] = $http1["\0*\0response"]->url;
                }else{
                    $url_301['re_url2'] =''; 
                }
                
         
                
                if( trim($url_301['re_url2'],'/')==trim($site_url1,'/') || trim($url_301['re_url1'],'/')==trim($site_url1,'/')){
                    $url_301['status'] = 1;
                }else{
                    $url_301['status'] = 0;
                }
                if($url_301['status']==1){
                    echo wp_json_encode(['code'=>1]);exit;
                }else{
                    echo wp_json_encode(['code'=>0]);exit;
                }
               
            }elseif($type==6){
                $robots_path = ABSPATH . 'robots.txt';

                // 2. 检测文件是否存在且是普通文件（非目录）
                if (file_exists($robots_path) && is_file($robots_path)) {
                    echo wp_json_encode(['code'=>1]);exit;
                } else {
                   echo wp_json_encode(['code'=>0]);exit;
                }
            }elseif($type==7){
                $sitemap = get_option('seo_baidu_sitemap');
                if($sitemap!==false){
                    echo wp_json_encode(['code'=>1]);exit;
                }else{
                    echo wp_json_encode(['code'=>0]);exit;
                }
            }elseif($type==8){
                $baiduseo_zz = get_option('baiduseo_zz');
                if(is_array($baiduseo_zz) && isset($baiduseo_zz['pingtai'])){
                    echo wp_json_encode(['code'=>1]);exit;
                }else{
                    echo wp_json_encode(['code'=>0]);exit;
                }
            }elseif($type==9){
                $baiduseo_zz = get_option('baiduseo_zz');
                if(is_array($baiduseo_zz) && isset($baiduseo_zz['zz_link']) && $baiduseo_zz['zz_link']){
                    echo wp_json_encode(['code'=>1]);exit;
                }else{
                    echo wp_json_encode(['code'=>0]);exit;
                }
            }elseif($type==10){
                $baiduseo_zz = get_option('baiduseo_zz');
                if(is_array($baiduseo_zz) && isset($baiduseo_zz['bing_key']) && $baiduseo_zz['bing_key']){
                    echo wp_json_encode(['code'=>1]);exit;
                }else{
                    echo wp_json_encode(['code'=>0]);exit;
                }
            }elseif($type==11){
                $baiduseo_zz = get_option('baiduseo_zz');
                if(is_array($baiduseo_zz) && isset($baiduseo_zz['shenma_key']) && $baiduseo_zz['shenma_key']){
                    echo wp_json_encode(['code'=>1]);exit;
                }else{
                    echo wp_json_encode(['code'=>0]);exit;
                }
            }elseif($type==12){
                $baiduseo_zz = get_option('baiduseo_zz');
                if(is_array($baiduseo_zz) && isset($baiduseo_zz['toutiao_key']) && $baiduseo_zz['toutiao_key']){
                    echo wp_json_encode(['code'=>1]);exit;
                }else{
                    echo wp_json_encode(['code'=>0]);exit;
                }
            }elseif($type==13){
                $baidu3 = get_option('baiduseo_tag');
                if(isset($baidu3['auto']) && $baidu3['auto']==1){
                    echo wp_json_encode(['code'=>1]);exit;
                }else{
                    echo wp_json_encode(['code'=>0]);exit;
                }
            }elseif($type==14){
                $silian = get_option('seo_baidu_silian');
                if($silian!==false){
                    echo wp_json_encode(['code'=>1]);exit;
                }else{
                    echo wp_json_encode(['code'=>0]);exit;
                }
            }elseif($type==16){
                $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,
                );
                $data =  baiduseo_common::baiduseo_url(1);
                $url = "https://api.seoceo.cn/api/speed/wx_check?url={$data}";
                $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['code']) && $content['code']==1){
                        echo wp_json_encode(['code'=>1]);exit;
                    }else{
                        echo wp_json_encode(['code'=>0]);exit;
                    }
                }else{
                    echo wp_json_encode(['code'=>0]);exit;
                } 
            }elseif($type==17){
                $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,
                );
                $data =  baiduseo_common::baiduseo_url(1);
                $url = "https://api.seoceo.cn/api/speed/h1?url={$data}";
                $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['code']) && $content['code']==1){
                        echo wp_json_encode(['code'=>1]);exit;
                    }else{
                        echo wp_json_encode(['code'=>0]);exit;
                    }
                }else{
                    echo wp_json_encode(['code'=>0]);exit;
                } 
            }elseif($type==18){
                $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,
                );
                $data =  baiduseo_common::baiduseo_url(1);
                $url = "https://api.seoceo.cn/api/speed/iframe?url={$data}";
                $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['code']) && $content['code']==1){
                        echo wp_json_encode(['code'=>1]);exit;
                    }else{
                        echo wp_json_encode(['code'=>0]);exit;
                    }
                }else{
                    echo wp_json_encode(['code'=>0]);exit;
                } 
            }elseif($type==19){
                $defaults = array(
                    'timeout' => 40000,
                    'connecttimeout'=>40000,
                    '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,
                );
                $data =  baiduseo_common::baiduseo_url(1);
                $url = "https://jiekou.seoceo.cn/api/index/go_sd?url={$data}";
                $result = wp_remote_get($url,$defaults);
                if(!is_wp_error($result)){
                    $content = wp_remote_retrieve_body($result);
                    if($content){
                        echo wp_json_encode(['code'=>1,'msg'=>$content,'num'=>ceil($content/10)]);exit;
                    }else{
                        echo wp_json_encode(['code'=>0]);exit;
                    }
                }else{
                    echo wp_json_encode(['code'=>0]);exit;
                } 
            }elseif($type==20){
                $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,
                );
                $data =  baiduseo_common::baiduseo_url(1);
                $url = "https://api.seoceo.cn/api/speed/gn_yc?url={$data}";
                $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['code']) && $content['code']==1){
                        if($content['msg']>1.5){
                            $num =2;
                        }elseif($content['msg']>0.5 && $content<=1.5){
                            $num =4;
                        }else{
                            $num = 6;
                        }
                        echo wp_json_encode(['code'=>1,'msg'=>round($content['msg'],1).'s','num'=>$num]);exit;
                    }else{
                        echo wp_json_encode(['code'=>0]);exit;
                    }
                }else{
                    echo wp_json_encode(['code'=>0]);exit;
                } 
            }elseif($type==21){
                $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,
                );
                $data =  baiduseo_common::baiduseo_url(1);
                $url = "https://jiekou.seoceo.cn/api/index/gn_yc?url={$data}";
                $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['code']) && $content['code']==1){
                        if($content['msg']>1.5){
                            $num =1;
                        }elseif($content['msg']>0.5 && $content<=1.5){
                            $num =2;
                        }else{
                            $num = 4;
                        }
                        echo wp_json_encode(['code'=>1,'msg'=>round($content['msg'],1).'s','num'=>$num]);exit;
                    }else{
                        echo wp_json_encode(['code'=>0]);exit;
                    }
                }else{
                    echo wp_json_encode(['code'=>0]);exit;
                } 
            }
            
        }
    }
    public function baiduseo_yindao_five($log,$log1,$log2){
        if(isset($_POST['nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['nonce'])),'baiduseo')){
            $baiduseo_wzt_log = baiduseo_kp::baiduseo_wzt_log();
            if(!$baiduseo_wzt_log){
                 exit;
            }
            if($log1['status']){
            }else{
                echo wp_json_encode(['msg'=>'请先授权','code'=>0]);exit;
            }
            
            
            
            if($log2['token']){
            }else{
                echo wp_json_encode(['msg'=>'请先授权','code'=>0]);exit;
            }
            $log3 = apply_filters('baiduseo_check4', true, $log1['token']);
            $log3 = json_decode($log3,true);
            $log4 = apply_filters('baiduseo_check5', true, $log1['token']);
            $log4 = json_decode($log4,true);
            $log5 = apply_filters('baiduseo_check6', true, $log1['token']);
            $log5 = json_decode($log5,true);
            
            
            
            
            $log3_code = is_array($log3) && isset($log3['code']) ? $log3['code'] : false; $log4_code = is_array($log4) &&  isset($log4['code']) ? $log4['code'] : false; $log5_code = is_array($log5)&&  isset($log5['code'])  ? $log5['code'] : false; if(!$log3_code && !$log4_code && !$log5_code ){
                $ss  = baiduseo_zz::pay_money();
                if(!$ss){
                     echo wp_json_encode(['msg'=>'请先授权','code'=>0]);exit;
                }
            }else{
                $log6 = apply_filters('baiduseo_check7', true, $log1['token'],$log2['token'],$log3['code'],$log4['code'],$log5['code']);
                if(!$log6){
                    $ss  = baiduseo_zz::pay_money();
                    if(!$ss){
                         echo wp_json_encode(['msg'=>'请先授权','code'=>0]);exit;
                    }
                }
            }
            baiduseo_tag::baiduseo_tag_set($_POST);
            echo wp_json_encode(['msg'=>'保存成功','code'=>1]);exit;
        }
        echo wp_json_encode(['msg'=>'保存失败','code'=>0]);exit;
    }
    public function baiduseo_yindao_four($log,$log1,$log2){
          global $wpdb;
        
        if(isset($_POST['nonce']) && isset($_POST['action']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['nonce'])),'baiduseo')){
            $baiduseo_wzt_log = baiduseo_kp::baiduseo_wzt_log();
            if(!$baiduseo_wzt_log){
                echo wp_json_encode(['msg'=>'请先授权','code'=>0]);exit;
            }
             if($log1['status']){
                 $indexnow_key = isset($_POST['indexnow_key'])?sanitize_text_field(wp_unslash($_POST['indexnow_key'])):'';
            }else{
                echo wp_json_encode(['msg'=>'请先授权','code'=>0]);exit;
            }
            
            
            
            if($log2['token']){
                $seo_baidu_xzh =[                             
                    'zz_link'=>isset($_POST['zz_link'])?sanitize_url(wp_unslash($_POST['zz_link'])):'',                                   
                    'bing_key'=>isset($_POST['bing_key'])?sanitize_text_field(wp_unslash($_POST['bing_key'])):'', 
                    // 'shenma_key' =>isset($_POST['shenma_key'])?sanitize_url(wp_unslash($_POST['shenma_key'])):"",
                    'toutiao_key'=>isset($_POST['toutiao_key'])?sanitize_text_field(wp_unslash($_POST['toutiao_key'])):"",
                    'indexnow_key'=>$indexnow_key,
                    'google_api'=>isset($_POST['google_api'])?sanitize_textarea_field(wp_unslash($_POST['google_api'])):"",
                    // 'indexnow_pingtai'=>isset($_POST['indexnow_pingtai'])?sanitize_text_field(wp_unslash($_POST['indexnow_pingtai'])):"",
                    'post_type'=>isset($_POST['post_type'])?sanitize_text_field(wp_unslash($_POST['post_type'])):"",
                    // 'baiduseo_type'=>sanitize_text_field($_POST['baiduseo_type']),
                    // 'post_type'=>isset($_POST['bing_key'])?sanitize_text_field($_POST['post_type']),
                    'status'=>isset($_POST['status'])?sanitize_text_field(wp_unslash($_POST['status'])):'',
                    'pingtai'=>isset($_POST['pingtai'])?sanitize_text_field(wp_unslash($_POST['pingtai'])):'',
                    'guowai_num'=>isset($_POST['guowai_num'])?(int)$_POST['guowai_num']:0,
                    'bdpt_num'=>isset($_POST['bdpt_num'])?(int)$_POST['bdpt_num']:0,
                    'bing_num'=>isset($_POST['bing_num'])?(int)$_POST['bing_num']:0,
                    // 'sm_num'=>isset($_POST['sm_num'])?(int)$_POST['sm_num']:"",
                    // 'log'=>isset($_POST['log'])?sanitize_text_field(wp_unslash($_POST['log'])):"",
                    'bd_log'=>isset($_POST['bd_log'])?(int)$_POST['bd_log']:0,
                    'bd_log_show'=>isset($_POST['bd_log_show'])?(int)$_POST['bd_log_show']:0,
                    // 'bdks_log'=>isset($_POST['bdks_log'])?(int)$_POST['bdks_log']:"",
                    'bing_log'=>isset($_POST['bing_log'])?(int)$_POST['bing_log']:0,
                    'bing_log_show'=>isset($_POST['bing_log_show'])?(int)$_POST['bing_log_show']:0,
                     'seznam_log'=>isset($_POST['seznam_log'])?(int)$_POST['seznam_log']:0,
                    'seznam_log_show'=>isset($_POST['seznam_log_show'])?(int)$_POST['seznam_log_show']:0,
                    'indexNow_log'=>isset($_POST['indexNow_log'])?(int)$_POST['indexNow_log']:0,
                    'indexNow_log_show'=>isset($_POST['indexNow_log_show'])?(int)$_POST['indexNow_log_show']:0,
                      'indexNow_bing_log'=>isset($_POST['indexNow_bing_log'])?(int)$_POST['indexNow_bing_log']:0,
                    'indexNow_bing_log_show'=>isset($_POST['indexNow_bing_log_show'])?(int)$_POST['indexNow_bing_log_show']:0,
                    'guge_log'=>isset($_POST['guge_log'])?(int)$_POST['guge_log']:0,
                    'guge_log_show'=>isset($_POST['guge_log_show'])?(int)$_POST['guge_log_show']:0,
                      'yandex_log'=>isset($_POST['yandex_log'])?(int)$_POST['yandex_log']:0,
                    'yandex_log_show'=>isset($_POST['yandex_log_show'])?(int)$_POST['yandex_log_show']:0,  
                    'naver_log'=>isset($_POST['naver_log'])?(int)$_POST['naver_log']:0,
                    'naver_log_show'=>isset($_POST['naver_log_show'])?(int)$_POST['naver_log_show']:0,  
                    'yep_log'=>isset($_POST['yep_log'])?(int)$_POST['yep_log']:0,
                    'yep_log_show'=>isset($_POST['yep_log_show'])?(int)$_POST['yep_log_show']:0,
                    
                ];
            }else{
                echo wp_json_encode(['msg'=>'请先授权','code'=>0]);exit;
            }
            $log3 = apply_filters('baiduseo_check4', true, $log1['token']);
            $log3 = json_decode($log3,true);
            $log4 = apply_filters('baiduseo_check5', true, $log1['token']);
            $log4 = json_decode($log4,true);
            $log5 = apply_filters('baiduseo_check6', true, $log1['token']);
            $log5 = json_decode($log5,true);
            
            
            
            
            $log3_code = is_array($log3) && isset($log3['code']) ? $log3['code'] : false; $log4_code = is_array($log4) &&  isset($log4['code']) ? $log4['code'] : false; $log5_code = is_array($log5)&&  isset($log5['code'])  ? $log5['code'] : false; if(!$log3_code && !$log4_code && !$log5_code ){
                $ss  = baiduseo_zz::pay_money();
                if(!$ss){
                     echo wp_json_encode(['msg'=>'请先授权','code'=>0]);exit;
                }
            }else{
                $log6 = apply_filters('baiduseo_check7', true, $log1['token'],$log2['token'],$log3['code'],$log4['code'],$log5['code']);
                if(!$log6){
                    $ss  = baiduseo_zz::pay_money();
                    if(!$ss){
                         echo wp_json_encode(['msg'=>'请先授权','code'=>0]);exit;
                    }
                }
            }
            
            
            
            if($indexnow_key){
                WP_Filesystem();
                global $wp_filesystem;
                $wp_filesystem->put_contents (ABSPATH.'/'.$indexnow_key.'.txt',$indexnow_key);
            }
            
            $baidu = get_option('baiduseo_zz');
            if($baidu!==false){
                update_option('baiduseo_zz',$seo_baidu_xzh);
            }else{
                add_option('baiduseo_zz',$seo_baidu_xzh);
            }
            echo wp_json_encode(['msg'=>'保存成功','code'=>1]);exit;
        }
        
         echo wp_json_encode(['msg'=>'保存失败','code'=>0]);exit;
    }
    public function baiduseo_yindao_three($log,$log1,$log2){
        if(isset($_POST['nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['nonce'])),'baiduseo')){
           $baiduseo_wzt_log = baiduseo_kp::baiduseo_wzt_log();
            if(!$baiduseo_wzt_log){
                 echo wp_json_encode(['code'=>'0','msg'=>'请先授权']);exit;
            }
            if($log1['status']){
                $sitemap = get_option('seo_baidu_sitemap');
            }else{
                echo wp_json_encode(['msg'=>'请先授权','code'=>0]);exit;
            }
            
            
            
            if($log2['token']){
            }else{
                echo wp_json_encode(['msg'=>'请先授权','code'=>0]);exit;
            }
            $log3 = apply_filters('baiduseo_check4', true, $log1['token']);
            $log3 = json_decode($log3,true);
            $log4 = apply_filters('baiduseo_check5', true, $log1['token']);
            $log4 = json_decode($log4,true);
            $log5 = apply_filters('baiduseo_check6', true, $log1['token']);
            $log5 = json_decode($log5,true);
            
            
            
            
            $log3_code = is_array($log3) && isset($log3['code']) ? $log3['code'] : false; $log4_code = is_array($log4) &&  isset($log4['code']) ? $log4['code'] : false; $log5_code = is_array($log5)&&  isset($log5['code'])  ? $log5['code'] : false; if(!$log3_code && !$log4_code && !$log5_code ){
                $ss  = baiduseo_zz::pay_money();
                if(!$ss){
                     echo wp_json_encode(['msg'=>'请先授权','code'=>0]);exit;
                }
            }else{
                $log6 = apply_filters('baiduseo_check7', true, $log1['token'],$log2['token'],$log3['code'],$log4['code'],$log5['code']);
                if(!$log6){
                    $ss  = baiduseo_zz::pay_money();
                    if(!$ss){
                         echo wp_json_encode(['msg'=>'请先授权','code'=>0]);exit;
                    }
                }
            }
            
            
            if($sitemap!==false && !is_array($sitemap)){
                // $data = $sitemap;
                $data['level1'] = isset($_POST['level1'])?(int)$_POST['level1']:0;
                $data['level2'] = isset($_POST['level2'])?(int)$_POST['level2']:0;
                $data['level3'] = isset($_POST['level3'])?(int)$_POST['level3']:0;
                $data['level4'] = isset($_POST['level4'])?(int)$_POST['level4']:0;
                $data['level5'] = isset($_POST['level5'])?(int)$_POST['level5']:0;
                $data['type1'] = isset($_POST['type1'])?(int)$_POST['type1']:0;
                $data['type2'] = isset($_POST['type2'])?(int)$_POST['type2']:0;
                $data['type3'] = isset($_POST['type3'])?(int)$_POST['type3']:0;
                $data['type4'] = isset($_POST['type4'])?(int)$_POST['type4']:0;
                $data['type5'] = isset($_POST['type5'])?(int)$_POST['type5']:0;
                $data['page_time'] = isset($_POST['page_time'])?sanitize_text_field(wp_unslash($_POST['page_time'])):"";
                $data['post_time'] = isset($_POST['post_time'])?sanitize_text_field(wp_unslash($_POST['post_time'])):"";
                $data['tag_time'] = isset($_POST['tag_time'])?sanitize_text_field(wp_unslash($_POST['tag_time'])):"";
                $data['other_time'] = isset($_POST['other_time'])?sanitize_text_field(wp_unslash($_POST['other_time'])):"";
                $data['cate_time'] = isset($_POST['cate_time'])?sanitize_text_field(wp_unslash($_POST['cate_time'])):"";
                $data['sitemap_open'] = isset($_POST['sitemap_open'])?(int)$_POST['sitemap_open']:0;
                $data['silian_open'] = isset($_POST['silian_open'])?(int)$_POST['silian_open']:0;
                // $data['tag_open'] = isset($_POST['tag_open'])?(int)$_POST['tag_open']:0;
                
                update_option('seo_baidu_sitemap',$data);
            }elseif($sitemap!==false && is_array($sitemap)){
                $data = $sitemap;
                $data['level1'] = isset($_POST['level1'])?(int)$_POST['level1']:0;
                $data['level2'] = isset($_POST['level2'])?(int)$_POST['level2']:0;
                $data['level3'] = isset($_POST['level3'])?(int)$_POST['level3']:0;
                $data['level4'] = isset($_POST['level4'])?(int)$_POST['level4']:0;
                $data['level5'] = isset($_POST['level5'])?(int)$_POST['level5']:0;
                $data['type1'] = isset($_POST['type1'])?(int)$_POST['type1']:0;
                $data['type2'] = isset($_POST['type2'])?(int)$_POST['type2']:0;
                $data['type3'] = isset($_POST['type3'])?(int)$_POST['type3']:0;
                $data['type4'] = isset($_POST['type4'])?(int)$_POST['type4']:0;
                $data['type5'] = isset($_POST['type5'])?(int)$_POST['type5']:0;
                $data['page_time'] = isset($_POST['page_time'])?sanitize_text_field(wp_unslash($_POST['page_time'])):"";
                $data['post_time'] = isset($_POST['post_time'])?sanitize_text_field(wp_unslash($_POST['post_time'])):"";
                $data['tag_time'] = isset($_POST['tag_time'])?sanitize_text_field(wp_unslash($_POST['tag_time'])):"";
                $data['other_time'] = isset($_POST['other_time'])?sanitize_text_field(wp_unslash($_POST['other_time'])):"";
                $data['cate_time'] = isset($_POST['cate_time'])?sanitize_text_field(wp_unslash($_POST['cate_time'])):"";
                $data['sitemap_open'] = isset($_POST['sitemap_open'])?(int)$_POST['sitemap_open']:"";
                $data['silian_open'] = isset($_POST['silian_open'])?(int)$_POST['silian_open']:"";
                // $data['tag_open'] = isset($_POST['tag_open'])?(int)$_POST['tag_open']:0;
                
                update_option('seo_baidu_sitemap',$data);
            }else{
                $data['level1'] = isset($_POST['level1'])?(int)$_POST['level1']:0;
                $data['level2'] = isset($_POST['level2'])?(int)$_POST['level2']:0;
                $data['level3'] = isset($_POST['level3'])?(int)$_POST['level3']:0;
                $data['level4'] = isset($_POST['level4'])?(int)$_POST['level4']:0;
                $data['level5'] = isset($_POST['level5'])?(int)$_POST['level5']:0;
                $data['type1'] = isset($_POST['type1'])?(int)$_POST['type1']:0;
                $data['type2'] = isset($_POST['type2'])?(int)$_POST['type2']:0;
                $data['type3'] = isset($_POST['type3'])?(int)$_POST['type3']:0;
                $data['type4'] = isset($_POST['type4'])?(int)$_POST['type4']:0;
                $data['type5'] = isset($_POST['type5'])?(int)$_POST['type5']:0;
                $data['page_time'] = isset($_POST['page_time'])?sanitize_text_field(wp_unslash($_POST['page_time'])):"";
                $data['post_time'] = isset($_POST['post_time'])?sanitize_text_field(wp_unslash($_POST['post_time'])):"";
                $data['tag_time'] = isset($_POST['tag_time'])?sanitize_text_field(wp_unslash($_POST['tag_time'])):"";
                $data['other_time'] = isset($_POST['other_time'])?sanitize_text_field(wp_unslash($_POST['other_time'])):"";
                $data['cate_time'] = isset($_POST['cate_time'])?sanitize_text_field(wp_unslash($_POST['cate_time'])):"";
                $data['sitemap_open'] = isset($_POST['sitemap_open'])?(int)$_POST['sitemap_open']:"";
                $data['silian_open'] = isset($_POST['silian_open'])?(int)$_POST['silian_open']:"";
                // $data['tag_open'] = isset($_POST['tag_open'])?(int)$_POST['tag_open']:0;
                add_option('seo_baidu_sitemap',$data);  
            }
            baiduseo_set::baiduseo_set_option($baiduseo_wzt_log,'seo_baidu_sitemap',$data);
            
            baiduseo_seo::alt(isset($_POST['alt'])?(int)$_POST['alt']:0,isset($_POST['title'])?(int)$_POST['title']:0);
            if(isset($_POST['isrobots']) && $_POST['isrobots']==1){
                if(isset($_POST['robots']) && sanitize_textarea_field(wp_unslash($_POST['robots']))){
                    baiduseo_seo::robots(sanitize_textarea_field(wp_unslash($_POST['robots'])));
                }
            }
            if(isset($_POST['sitemap_open']) && (int)$_POST['sitemap_open']==1){
                baiduseo_seo::sitemap(1,1,1);
            }
            if((int)$_POST['silian_open']==1){
                baiduseo_seo::silian(1,1);
            }
            echo wp_json_encode(['code'=>1,'msg'=>'保存成功']);exit;
        }
         echo wp_json_encode(['msg'=>'保存失败','code'=>0]);exit;
    }
    public function baiduseo_yindao_second($log,$log1,$log2){
        if(isset($_POST['nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['nonce'])),'baiduseo')){
            $data = [
                'thumb'=>isset($_POST['thumb'])?(int)$_POST['thumb']:0,
                'head_dy'=>isset($_POST['head_dy'])?(int)$_POST['head_dy']:0,
                'xml_rpc'=>isset($_POST['xml_rpc'])?(int)$_POST['xml_rpc']:0,
                'feed'=>isset($_POST['feed'])?(int)$_POST['feed']:0,
                'post_thumb'=>isset($_POST['post_thumb'])?(int)$_POST['post_thumb']:0,
                'gravatar'=>isset($_POST['gravatar'])?(int)$_POST['gravatar']:0,
                'lan'=>isset($_POST['lan'])?(int)$_POST['lan']:0,
                'category'=>isset($_POST['category'])?(int)$_POST['category']:0,
                'listbtn'=>isset($_POST['listbtn'])?(int)$_POST['listbtn']:0,
                'wp_json'=>isset($_POST['wp_json'])?(int)$_POST['wp_json']:0,
                'art_cron'=>isset($_POST['art_cron'])?(int)$_POST['art_cron']:0,
            ];
           
            $baidu = get_option('baiduseo_youhua');
            if($baidu!==false){
                update_option('baiduseo_youhua',$data);
            }else{
                add_option('baiduseo_youhua',$data);
            }
            echo wp_json_encode(['msg'=>'保存成功','code'=>1]);exit;
        }
         echo wp_json_encode(['msg'=>'保存失败','code'=>0]);exit;
    }
    public function baiduseo_yindao_first($log,$log1,$log2){
        if(isset($_POST['nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['nonce'])),'baiduseo')){
            if(isset($_POST['title'])){
                update_option('blogname',sanitize_text_field(wp_unslash($_POST['title'])));
            }
            if(isset($_POST['subtitle'])){
                update_option('blogdescription',sanitize_text_field(wp_unslash($_POST['subtitle'])));
            }
            baiduseo_seo::seo_index(isset($_POST['keywords'])?sanitize_text_field(wp_unslash($_POST['keywords'])):'',isset($_POST['description'])?sanitize_textarea_field(wp_unslash($_POST['description'])):'');
            if(isset($_POST['cate_id'])){
                baiduseo_seo::cate_seo(isset($_POST['cate_keywords'])?sanitize_text_field(wp_unslash($_POST['cate_keywords'])):'',isset($_POST['cate_description'])?sanitize_textarea_field(wp_unslash($_POST['cate_description'])):'',(int)$_POST['cate_id']);
            }
            if(isset($_POST['page'])){
                baiduseo_seo::page_seo(isset($_POST['page_keywords'])?sanitize_text_field(wp_unslash($_POST['page_keywords'])):'',isset($_POST['page_description'])?sanitize_text_field(wp_unslash($_POST['page_description'])):'',(int)$_POST['page']);
            }
            echo wp_json_encode(['code'=>1]);exit;
            
        }
        echo wp_json_encode(['code'=>0]);exit;
    }
   
    public function baiduseo_reci($log,$log1,$log2){
        if(isset($_POST['nonce']) && isset($_POST['action']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['nonce'])),'baiduseo')){
           
            $type = isset($_POST['type'])?(int)$_POST['type']:0;
            $keyword = isset($_POST['keyword'])?sanitize_text_field(wp_unslash($_POST['keyword'])):'';
            $result = wp_remote_post('https://api.seoceo.cn/api/tag/index',['body'=>['type'=>$type,'keyword'=>$keyword,'url'=>baiduseo_common::baiduseo_url(0)]]);
           
            if(!is_wp_error($result)){
                $result = wp_remote_retrieve_body($result);
                $result = json_decode($result,true);
                
                if($result['code']){
                    $msg = array_map('sanitize_text_field',$result['msg']);
                    
                    echo wp_json_encode(['data'=>$msg,'code'=>1]);exit;
                }else{
                    echo wp_json_encode(['msg'=>'请先授权','code'=>0]);exit;
                }
            }
        }
        echo wp_json_encode(['msg'=>'获取失败','code'=>0]);exit;
    }
    public function baiduseo_address_delete($log,$log1,$log2){
        if(isset($_POST['nonce']) && isset($_POST['action']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['nonce'])),'baiduseo')){
            global $wpdb;
            $id  = isset($_POST['id'])?(int)$_POST['id']:0;
             $res = $wpdb->query($wpdb->prepare("DELETE FROM " . $wpdb->prefix . "wztkj_friends where id=  %d",(int)$id));
             
            if($res){
                echo wp_json_encode(['code'=>1,'msg'=>'删除成功']);exit;
            }else{
                echo wp_json_encode(['code'=>0,'msg'=>'删除失败']);exit;
            }
        }
         echo wp_json_encode(['code'=>0,'msg'=>'删除失败']);exit;
    }
    public function baiduseo_add_link($log,$log1,$log2){
        if(isset($_POST['nonce']) && isset($_POST['action']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['nonce'])),'baiduseo')){
            global $wpdb;
            $current_time = current_time( 'Y/m/d H:i:s');
            $re = $wpdb->insert($wpdb->prefix."wztkj_friends",['link'=>isset($_POST['address'])?sanitize_url(wp_unslash($_POST['address'])):'','keywords'=>isset($_POST['keywords'])?sanitize_text_field(wp_unslash($_POST['keywords'])):'','time'=>$current_time,'status1'=>5]);
            if($re){
                echo wp_json_encode(['code'=>1,'msg'=>'添加成功']);exit;
            }else{
                echo wp_json_encode(['code'=>0,'msg'=>'添加失败']);exit;
            }
        }
        echo wp_json_encode(['code'=>0,'msg'=>'添加失败']);exit;
    }
    public function baiduseo_shenhe($log,$log1,$log2){
        if(isset($_POST['nonce']) && isset($_POST['action']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['nonce'])),'baiduseo')){
            global $wpdb;
            $url = 'https://api.seoceo.cn/api/wztkj/shenhe';
            $link2 = isset($_POST['url'])?sanitize_url(wp_unslash($_POST['url'])):'';
            $link1 =  baiduseo_common::baiduseo_url(1);
            $result = wp_remote_post($url,['body'=>['data'=>['link1'=>$link1,'link2'=>$link2]]]);
            if(!is_wp_error($result)){
                $result = wp_remote_retrieve_body($result);
                if($result){
                    $wpdb->update($wpdb->prefix . 'wztkj_friends',['status3'=>2],['link'=>$link2]);
                    echo wp_json_encode(['msg'=>'操作成功，请等待处理！','code'=>1]);exit;
                }else{
                    echo wp_json_encode(['msg'=>'请求失败，请稍后重试！','code'=>0]);exit;
                }
            }else{
                echo wp_json_encode(['msg'=>'请求失败，请稍后重试！','code'=>0]);exit;
            }
        }
        echo wp_json_encode(['msg'=>'请求失败，请稍后重试！','code'=>0]);exit;
    }
    public function baiduseo_pingbi($log,$log1,$log2){
        if(isset($_POST['nonce']) && isset($_POST['action']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['nonce'])),'baiduseo')){
            global $wpdb;
            $url = 'https://api.seoceo.cn/api/wztkj/pb';
            $link2 = isset($_POST['url'])?sanitize_url(wp_unslash($_POST['url'])):'';
            $status =isset($_POST['status'])?(int)$_POST['status']:0;
            
            if($status==0){
                $sta = 1;
            }else{
                $sta = 0;
            }
            $link1 =  baiduseo_common::baiduseo_url(1);
            $result = wp_remote_post($url,['body'=>['data'=>['link1'=>$link1,'link2'=>$link2,'status'=>$sta]]]);
            if(!is_wp_error($result)){
                $result = wp_remote_retrieve_body($result);
                if($result){
                     
                    $wpdb->update($wpdb->prefix . 'wztkj_friends',['status1'=>$sta],['link'=>$link2]);
                    
                    echo wp_json_encode(['msg'=>'操作成功！','code'=>1]);exit;
                }else{
                    echo wp_json_encode(['msg'=>'请求失败，请稍后重试！','code'=>0]);exit;
                }
            }else{
                echo wp_json_encode(['msg'=>'请求失败，请稍后重试！','code'=>0]);exit;
            }
        }
        echo wp_json_encode(['msg'=>'请求失败，请稍后重试！','code'=>0]);exit;
    }
    public function baiduseo_yanzheng($log,$log1,$log2){
        if(isset($_POST['nonce']) && isset($_POST['action']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['nonce'])),'baiduseo')){
        $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,
        );
        $url = get_option('home');
        $result = wp_remote_get($url,$defaults);
        if(!is_wp_error($result)){
            $content = wp_remote_retrieve_body($result);
           
            if(is_string($content) && strpos($content,md5(baiduseo_common::baiduseo_url(0))) !== false){ 
             echo wp_json_encode(['code'=>1]);exit;
            }else{
             echo wp_json_encode(['code'=>0]);exit;
            }
           
        }
        }
        echo wp_json_encode(['code'=>0]);exit;
    }
    public function baiduseo_linkhh($log,$log1,$log2){
        if(isset($_POST['nonce']) && isset($_POST['action']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['nonce'])),'baiduseo')){
            
            $data['link'] = isset($_POST['link'])?(int)$_POST['link']:'';
            $data['keywords'] = isset($_POST['keywords'])?sanitize_text_field(wp_unslash($_POST['keywords'])):'';
            $data['hhtype'] = isset($_POST['hhtype'])?(int)$_POST['hhtype']:0;
            $data['hhtj'] = isset($_POST['hhtj'])?(int)$_POST['hhtj']:0;
            if(isset($_POST['level']) ){
                $data['level'] = array_map('intval',explode(',',sanitize_text_field(wp_unslash($_POST['level']))));
            }
            if(isset($_POST['cate'])){
                $data['cate'] = array_map('intval',explode(',',sanitize_text_field(wp_unslash($_POST['cate']))));
            }
            
            $data['ystype'] = isset($_POST['ystype'])?(int)$_POST['ystype']:0;
            $data['kqtype'] = isset($_POST['kqtype'])?(int)$_POST['kqtype']:0;
            $data['yswidth'] = isset($_POST['yswidth'])?sanitize_text_field(wp_unslash($_POST['yswidth'])):'';
            $data['mobilewidth'] = isset($_POST['mobilewidth'])?sanitize_text_field(wp_unslash($_POST['mobilewidth'])):'';
            
            $wztkj_linkhh = get_option('baiduseo_linkhh');
            if($wztkj_linkhh!==false){
                $res = update_option('baiduseo_linkhh',$data);
            }else{
                add_option('baiduseo_linkhh',$data);
            }
            echo wp_json_encode(['code'=>1]);exit;
            
        }
       echo wp_json_encode(['code'=>0]);exit;
    }
    public function baiduseo_ptts($log,$log1,$log2){
         if(isset($_POST['nonce']) && isset($_POST['action']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['nonce'])),'baiduseo')){
            if($log1['status']){
            }else{
                echo wp_json_encode(['msg'=>'请先授权','code'=>0]);exit;
            }
            
            
            
            if($log2['token']){
                 $id = isset($_POST['id'])?(int)$_POST['id']:0;
                $url = get_permalink($id);
                $currnetTime= current_time( 'Y-m-d H:i:s');
                $baiduseo_zz = get_option('baiduseo_zz');
                $urls =explode(',',$url);
            }else{
                echo wp_json_encode(['msg'=>'请先授权','code'=>0]);exit;
            }
            $log3 = apply_filters('baiduseo_check4', true, $log1['token']);
            $log3 = json_decode($log3,true);
            $log4 = apply_filters('baiduseo_check5', true, $log1['token']);
            $log4 = json_decode($log4,true);
            $log5 = apply_filters('baiduseo_check6', true, $log1['token']);
            $log5 = json_decode($log5,true);
            
            
            
            
            $log3_code = is_array($log3) && isset($log3['code']) ? $log3['code'] : false; $log4_code = is_array($log4) &&  isset($log4['code']) ? $log4['code'] : false; $log5_code = is_array($log5)&&  isset($log5['code'])  ? $log5['code'] : false; if(!$log3_code && !$log4_code && !$log5_code ){
                $ss  = baiduseo_zz::pay_money();
                if(!$ss){
                     echo wp_json_encode(['msg'=>'请先授权','code'=>0]);exit;
                }
            }else{
                $log6 = apply_filters('baiduseo_check7', true, $log1['token'],$log2['token'],$log3['code'],$log4['code'],$log5['code']);
                if(!$log6){
                    $ss  = baiduseo_zz::pay_money();
                    if(!$ss){
                         echo wp_json_encode(['msg'=>'请先授权','code'=>0]);exit;
                    }
                }
            }
           
            //查询选择推送的方式
              
                    
            if(isset($baiduseo_zz['pingtai']) && is_string($baiduseo_zz['pingtai']) &&  strpos($baiduseo_zz['pingtai'],'1')!==false){
                baiduseo_zz::bdts($urls);
            }
            if(isset($baiduseo_zz['pingtai']) && is_string($baiduseo_zz['pingtai']) && strpos($baiduseo_zz['pingtai'],'2')!==false){
                baiduseo_zz::bing($urls);
            }
            if(isset($baiduseo_zz['pingtai']) && is_string($baiduseo_zz['pingtai']) && strpos($baiduseo_zz['pingtai'],'4')!==false){
        
                baiduseo_zz::google($url);
            }
              if(isset($baiduseo_zz['pingtai']) && is_string($baiduseo_zz['pingtai']) && strpos($baiduseo_zz['pingtai'],'5')!==false){
        
                baiduseo_zz::indexnow($urls,0,0,6);
            }
              if(isset($baiduseo_zz['pingtai']) && is_string($baiduseo_zz['pingtai']) && strpos($baiduseo_zz['pingtai'],'6')!==false){
        
                baiduseo_zz::indexnow($urls,0,0,6);
            }
              if(isset($baiduseo_zz['pingtai']) && is_string($baiduseo_zz['pingtai']) && strpos($baiduseo_zz['pingtai'],'7')!==false){
        
                baiduseo_zz::indexnow($urls,0,0,7);
            }
              if(isset($baiduseo_zz['pingtai']) && is_string($baiduseo_zz['pingtai']) && strpos($baiduseo_zz['pingtai'],'8')!==false){
        
                baiduseo_zz::indexnow($urls,0,0,8);
            }
              if(isset($baiduseo_zz['pingtai']) && is_string($baiduseo_zz['pingtai']) && strpos($baiduseo_zz['pingtai'],'9')!==false){
        
                baiduseo_zz::indexnow($urls,0,0,9);
            }
              if(isset($baiduseo_zz['pingtai']) && is_string($baiduseo_zz['pingtai']) && strpos($baiduseo_zz['pingtai'],'10')!==false){
        
                baiduseo_zz::indexnow($urls,0,0,10);
            }
            
                
            
      
            echo wp_json_encode(['msg'=>1]);exit;
           
        }
    }
    public function baiduseo_neilian_delete_all($log,$log1,$log2){
        if(isset($_POST['nonce']) && isset($_POST['action']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['nonce'])),'baiduseo')){
           
            global $wpdb;
            $res = $wpdb->query("DELETE FROM " . $wpdb->prefix . "baiduseo_neilian ");
             if($res){
                echo wp_json_encode(['code'=>1,'msg'=>'清空成功']);exit;
            }
        }
        echo wp_json_encode(['code'=>0,'msg'=>'清空失败']);exit;
    }
    public function baiduseo_neilian_delete($log,$log1,$log2){
      
        if(isset($_POST['nonce']) && isset($_POST['action']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['nonce'])),'baiduseo')){
            $dele = isset($_POST['dele'])?array_map('intval',explode(',',sanitize_text_field(wp_unslash($_POST['dele'])))):[];
            if(!empty($dele) && is_array($dele)){
                global $wpdb;
                foreach($dele as $key=>$val){
                 $res = $wpdb->query($wpdb->prepare("DELETE FROM " . $wpdb->prefix . "baiduseo_neilian where id=  %d",(int)$val));
                }
            }
            if($res){
                echo wp_json_encode(['code'=>1,'msg'=>'删除成功']);exit;
            }
            
        }
        echo wp_json_encode(['code'=>0,'msg'=>'删除失败']);exit;
    }
    public function baiduseo_shouquan($log,$log1,$log2){
        if(isset($_POST['nonce']) && isset($_POST['action']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['nonce'])),'baiduseo')){
            $key = isset($_POST['key'])?sanitize_text_field(wp_unslash($_POST['key'])):'';
            
            $data =  baiduseo_common::baiduseo_url(0);
            $url1 = isset($_SERVER['SERVER_NAME'])?sanitize_text_field(wp_unslash($_SERVER['SERVER_NAME'])):'';
            $url = 'https://api.seoceo.cn/api/money/log2?url='.$data.'&url1='.$url1.'&key='.$key.'&type=1';
            $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);
                if($content){
                    $baiduseo_wzt_log = get_option('baiduseo_wzt_log');
                    if($baiduseo_wzt_log!==false){
                        update_option('baiduseo_wzt_log',$key);
                    }else{
                        add_option('baiduseo_wzt_log',$key);
                    }
                    baiduseo_seo::pay_money();
                    echo wp_json_encode(['code'=>1]);exit;
                }
            }
            
            
        }
        echo wp_json_encode(['code'=>0]);exit;
    }
    public function baiduseo_neilian($log,$log1,$log2){
        if(isset($_POST['nonce']) && isset($_POST['action']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['nonce'])),'baiduseo')){
            global $wpdb;
            $baiduseo_wzt_log = baiduseo_kp::baiduseo_wzt_log();
            if(!$baiduseo_wzt_log){
                echo wp_json_encode(['code'=>0,'msg'=>'请先授权']);exit;
            }
                 if($log1['status']){
            }else{
                echo wp_json_encode(['msg'=>'请先授权','code'=>0]);exit;
            }
            
            
            
            if($log2['token']){
                 $id = isset($_POST['id'])?(int)$_POST['id']:0;
                $url = get_permalink($id);
                $currnetTime= current_time( 'Y-m-d H:i:s');
                $baiduseo_zz = get_option('baiduseo_zz');
                $urls =explode(',',$url);
            }else{
                echo wp_json_encode(['msg'=>'请先授权','code'=>0]);exit;
            }
            $log3 = apply_filters('baiduseo_check4', true, $log1['token']);
            $log3 = json_decode($log3,true);
            $log4 = apply_filters('baiduseo_check5', true, $log1['token']);
            $log4 = json_decode($log4,true);
            $log5 = apply_filters('baiduseo_check6', true, $log1['token']);
            $log5 = json_decode($log5,true);
            
            
            
            
            $log3_code = is_array($log3) && isset($log3['code']) ? $log3['code'] : false; $log4_code = is_array($log4) &&  isset($log4['code']) ? $log4['code'] : false; $log5_code = is_array($log5)&&  isset($log5['code'])  ? $log5['code'] : false; if(!$log3_code && !$log4_code && !$log5_code ){
                $ss  = baiduseo_zz::pay_money();
                if(!$ss){
                     echo wp_json_encode(['msg'=>'请先授权','code'=>0]);exit;
                }
            }else{
                $log6 = apply_filters('baiduseo_check7', true, $log1['token'],$log2['token'],$log3['code'],$log4['code'],$log5['code']);
                if(!$log6){
                    $ss  = baiduseo_zz::pay_money();
                    if(!$ss){
                         echo wp_json_encode(['msg'=>'请先授权','code'=>0]);exit;
                    }
                }
            }
            $id = isset($_POST['id'])?(int)$_POST['id']:0;
            if(isset($_POST['keywords'])){
                $data['keywords'] = sanitize_text_field(wp_unslash($_POST['keywords']));
            }
            if(isset($_POST['link'])){
                $data['link'] = sanitize_text_field(wp_unslash($_POST['link']));
            }
            if(isset($_POST['target'])){
                $data['target'] = (int)$_POST['target'];
            }
            if(isset($_POST['nofollow'])){
                $data['nofollow'] = (int)$_POST['nofollow'];
            }
            if(isset($_POST['sort'])){
                $data['sort'] = (int)$_POST['sort'];
            }
            $res = $wpdb->update($wpdb->prefix . 'baiduseo_neilian',$data,['id'=>(int)$id]);
            if($res){
                
                echo wp_json_encode(['code'=>1,'msg'=>'修改成功']);exit;
                
            }
        }
        echo wp_json_encode(['code'=>0,'msg'=>'修改失败']);exit;
    }

    public function baiduseo_gaixie($log,$log1,$log2){
        if(isset($_POST['nonce']) && isset($_POST['action']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['nonce'])),'baiduseo')){
            global $wpdb;
            $id = isset($_POST['id'])?(int)$_POST['id']:0;
            $url = 'https://api.seoceo.cn/api/kp/jifen?url='.baiduseo_common::baiduseo_url(0);
            $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)){
                $jifen = wp_remote_retrieve_body($result);
                $jifen =$jifen?$jifen:0;
            }else{
                $jifen = 0;
            }
            
            if($jifen>=0.28){
                $post = $wpdb->get_results($wpdb->prepare("SELECT * FROM ".$wpdb->prefix ."posts  where ID=%d ",$id),ARRAY_A);
                
                foreach($post as $ke=>$va){
                    $url = 'https://wyc.seoceo.cn/api/wyc/wyc_50';
                    $va['url'] = get_option('siteurl');
                    $va['tongxun'] = baiduseo_common::baiduseo_tongxun();
                    $result = wp_remote_post($url,['body'=>$va]);
                    $content = wp_remote_retrieve_body($result);
                		        
                    $content = json_decode($content,true);
    		        if(isset($content['content']) && $content['content'] && isset($content['wp_id']) && $content['wp_id']){
    		            
                        $wpdb->update($wpdb->prefix . 'posts',['post_content'=>wp_kses_post($content['content'])],['id'=>$content['wp_id']]);
    		        }
                    $post_extend = get_post_meta( $id, 'baiduseo', true );
                    if($post_extend){
                        $post_extend['status'] = 3;
                       update_post_meta( $id,'baiduseo', $post_extend ); 
                    }else{
                        add_post_meta($id,'baiduseo',['status'=>3] );
                    }
                    break;
                }
                echo wp_json_encode(['msg'=>'1']);exit;
            }else{
                echo wp_json_encode(['msg'=>0]);exit;
            }
            
        }
    }
    public function baiduseo_kuaisu($log,$log1,$log2){
        if(isset($_POST['nonce']) && isset($_POST['action']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['nonce'])),'baiduseo')){
            
            $id = isset($_POST['id'])?(int)$_POST['id']:0;
            $urls[] = get_permalink($id);
            baiduseo_zz::bddayts1($urls);
        }
    }
    public function baiduseo_yuanchuang($log,$log1,$log2){
        
        if(isset($_POST['nonce']) && isset($_POST['action']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['nonce'])),'baiduseo')){
            $id = isset($_POST['id'])?(int)$_POST['id']:0;
            $url = 'https://api.seoceo.cn/api/kp/jifen?url='.baiduseo_common::baiduseo_url(0);
            $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)){
                $jifen = wp_remote_retrieve_body($result);
                $jifen =$jifen?$jifen:0;
            }else{
                $jifen = 0;
            }
            if($jifen>0.28){
                $total =2;
            }else{
                $baiduseo_wzt_log = baiduseo_kp::baiduseo_wzt_log();
                if($baiduseo_wzt_log){
                     global $baiduseo_key;
                    if(!$baiduseo_key){ 
                        $log = baiduseo_zz::pay_money();
                        if($log){
                            $total = 1;
                        }else{
                            $total = 0;
                        }
                    }else{
                        $total = 1;
                    }
                   
                }else{
                    $total = 0;
                }
            }
            if($total==0){
                $baiduseo_jifen = get_option('baiduseo_jifen');
                if($baiduseo_jifen!==false){
                    $timezone_offet = get_option( 'gmt_offset');
                    if(isset($baiduseo_jifen['addtime']) && $baiduseo_jifen['addtime']>strtotime(gmdate('Y-m-d 00:00:00'))-$timezone_offet*3600){
                        
                        if(isset($baiduseo_jifen['sy']) && $baiduseo_jifen['sy']<1){
                            echo wp_json_encode(['msg'=>0,'data'=>'当日服务器压力大，请明天再试']);exit;
                        }else{
                            update_option('baiduseo_jifen',['sy'=>$baiduseo_jifen['sy']-1,'kc_total'=>1+$baiduseo_jifen['kc_total'],'addtime'=>time()]);
                        }
                    }else{
                        update_option('baiduseo_jifen',['sy'=>2,'kc_total'=>1+$baiduseo_jifen['kc_total'],'addtime'=>time()]);
                    }
                }else{
                    add_option('baiduseo_jifen',['sy'=>2,'kc_total'=>1,'addtime'=>time()]);
                }
            }
            $post_extend = get_post_meta( $id, 'baiduseo', true );
            $current_time = current_time( 'Y/m/d H:i:s');
            if($post_extend){
               update_post_meta( $id,'baiduseo',  ['status'=>2,'tjtime'=>$current_time] ); 
            }else{
                add_post_meta($id,'baiduseo',['status'=>2,'tjtime'=>$current_time] );
            }
            $content = get_post($id)->post_content;
            $url = 'https://wyc.seoceo.cn/api/wyc/wp_wyc?id='.$id.'&content='.$content.'&url='.get_option('siteurl').'&like=9&tongxun='.baiduseo_common::baiduseo_tongxun();
            $result = wp_remote_get($url,$defaults);
            if(!is_wp_error($result)){
                 $result = wp_remote_retrieve_body($result);
                 if($result){
                    echo wp_json_encode(['msg'=>'1']);exit;
                 }else{
                     echo wp_json_encode(['msg'=>0,'data'=>'当日服务器压力大，请明天再试']);exit;
                 }
            }else{
                $result = wp_remote_post('https://wyc.seoceo.cn/api/wyc/wp_wyc',['body'=>['id'=>$id,'content'=>$content,'url'=>get_option('siteurl'),'like'=>9,'tongxun'=>baiduseo_common::baiduseo_tongxun()],'headers'=>[
                    '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]]);
                if(!is_wp_error($result)){
                     $result = wp_remote_retrieve_body($result);
                     if($result){
                        echo wp_json_encode(['msg'=>'1']);exit;
                     }else{
                         echo wp_json_encode(['msg'=>0,'data'=>'当日服务器压力大，请明天再试']);exit;
                     }
                }
                echo wp_json_encode(['msg'=>'0','data'=>'提交失败请稍后重试！']);exit;
            }
        }
        echo wp_json_encode(['msg'=>'0','data'=>'提交失败！']);exit;
    }
public function baiduseo_tag_pladd($log,$log1,$log2) {
    
  

    // 2. 安全校验（快速失败）
    if (!isset($_POST['nonce']) || !isset($_POST['action']) || !wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['nonce'])), 'baiduseo')) {
        $this->jsonExit(['msg' => '安全校验失败', 'code' => 0]);
    }
      // 1. 基础配置：使用传递的num参数+超时保护
    $num = isset($_POST['num']) ? (int)$_POST['num'] : 5; 
    $page = isset($_POST['page']) ? max(1, (int)$_POST['page']) : 1;
    $tag_num = isset($_POST['tag_num']) ? max(0, (int)$_POST['tag_num']) : 0;

    // 3. 文章类型处理（快速过滤）
    $name_str = isset($_POST['name']) ? sanitize_text_field(wp_unslash($_POST['name'])) : '';
    $valid_post_types = $this->getValidPostTypes($name_str);
    if (empty($valid_post_types)) {
        $this->jsonExit(['msg' => '没有有效的文章类型', 'code' => 0]);
    }

    global $wpdb;

    // 4. 授权校验（仅第一页）
    if ($page === 1 && !$this->checkAuth()) {
        $this->jsonExit(['msg' => '请先授权', 'code' => 0]);
    }

    // 5. 预计算总数+分页
    $total = $this->getTotalPosts($valid_post_types);
    if ($total === 0) {
        $this->jsonExit(['msg' => '没有需要处理的已发布文章', 'code' => 0]);
    }
    $start = ($page - 1) * $num;
    if ($start >= $total) {
        $this->jsonExit(['msg' => '操作完成', 'code' => 0]);
    }

    // 6. 预缓存所有必要数据
    $preCache = $this->preCacheData($wpdb, $valid_post_types, $start, $num);
    if (empty($preCache['posts'])) {
        $this->jsonExit(['msg' => '操作完成', 'code' => 0]);
    }

    // 7. 循环处理文章（单篇超时保护）
    $processed = 0;
    foreach ($preCache['posts'] as $post) {
        $this->processSinglePost($wpdb, $post, $tag_num, $preCache);
        $processed++;
    }

    // 8. 进度计算+终止判断
    $current_total = ($page - 1) * $num + $processed;
    $is_complete = $current_total >= $total || count($preCache['posts']) < $num;
    if ($is_complete) {
        $this->jsonExit(['msg' => '操作完成', 'code' => 1, 'percent' => '100%']);
    }

    // 9. 返回下一页进度
    $this->jsonExit([
        'num' => $num, 'percent' => round(100 * $current_total / $total, 2) . '%',
        'page' => $page + 1, 'tag_num' => $tag_num, 'code' => 1
    ]);
}

// 辅助方法：预缓存数据（使用传递的$num）
private function preCacheData($wpdb, $valid_post_types, $start, $num) {
    $cache = ['posts' => [], 'tax_cache' => [], 'tags_cache' => []];
    $valid_post_types = (array)$valid_post_types;
    $valid_post_types = array_filter($valid_post_types); 
    $placeholders = implode(',', array_fill(0, count($valid_post_types), '%s'));

    // 预缓存文章列表（LIMIT使用传递的$num）
    $cache['posts'] = $wpdb->get_results($wpdb->prepare(
        "SELECT ID, post_type, post_content FROM {$wpdb->prefix}posts 
         WHERE post_status='publish' AND post_type IN ($placeholders) 
         ORDER BY ID DESC LIMIT %d, %d",
        array_merge($valid_post_types, [$start, $num])
    ), ARRAY_A);

    // 预缓存标签分类法和标签数据（逻辑不变）
    foreach ($valid_post_types as $pt) {
        $taxes = get_object_taxonomies($pt, 'names');
        $cache['tax_cache'][$pt] = '';
        foreach ($taxes as $tax) {
            if (!is_taxonomy_hierarchical($tax)) {
                $cache['tax_cache'][$pt] = $tax;
                break;
            }
        }
    }
    foreach ($cache['tax_cache'] as $pt => $tax) {
        if (empty($tax)) continue;
        $cache['tags_cache'][$tax] = $wpdb->get_results(
            $wpdb->prepare(
                "SELECT t.term_id, t.name, tt.term_taxonomy_id 
                 FROM {$wpdb->prefix}terms t 
                 JOIN {$wpdb->prefix}term_taxonomy tt ON t.term_id=tt.term_id 
                 WHERE tt.taxonomy=%s",
                $tax
            ),
            ARRAY_A
        );
    }
    return $cache;
}
// 辅助方法：快速过滤有效文章类型
private function getValidPostTypes($name_str) {
    $post_types = array_filter(explode(',', $name_str));
    $valid = [];
    foreach ($post_types as $type) {
        $type = trim($type);
        if (post_type_exists($type)) {
            $valid[] = $type;
        }
    }
    return $valid;
}
// 辅助方法：授权校验（独立拆分，避免嵌套）
private function checkAuth() {
    global $baiduseo_key;
    $baiduseo_wzt_log = baiduseo_kp::baiduseo_wzt_log();
    if (!$baiduseo_wzt_log) {
        return false;
    }
    if (!$baiduseo_key && !baiduseo_zz::pay_money()) {
        return false;
    }
    return true;
}
// 辅助方法：预计算文章总数（避免循环内重复调用wp_count_posts）
private function getTotalPosts($valid_post_types) {
    $total = 0;
    foreach ($valid_post_types as $pt) {
        $count = wp_count_posts($pt);
        $total += isset($count->publish) ? (int)$count->publish : 0;
    }
    return $total;
}
// 辅助方法：单篇文章处理（极简逻辑，仅保留核心步骤）
private function processSinglePost($wpdb, $post, $tag_num, $preCache) {
    $post_id = $post['ID'];
    $pt = $post['post_type'];
    $tax = $preCache['tax_cache'][$pt];
    if (empty($tax) || empty($preCache['tags_cache'][$tax])) {
        return;
    }

    // 1. 快速获取已有标签数量（用JOIN+LIMIT 1优化）
    $existing = $wpdb->get_var(
        $wpdb->prepare(
            "SELECT COUNT(*) FROM {$wpdb->prefix}term_relationships tr 
             JOIN {$wpdb->prefix}term_taxonomy tt ON tr.term_taxonomy_id=tt.term_taxonomy_id 
             WHERE tr.object_id=%d AND tt.taxonomy=%s LIMIT 1",
            $post_id, $tax
        )
    );
    $existing = (int)$existing;
    if ($existing === $tag_num) {
        return;
    }

    // 2. 标签添加/减少（极简逻辑）
    if ($existing < $tag_num) {
        $this->fastAddTags($wpdb, $post_id, $existing, $tag_num, $preCache['tags_cache'][$tax], $post['post_content']);
    } else {
        $this->fastRemoveTags($wpdb, $post_id, $existing, $tag_num, $tax);
    }
}
// 辅助方法：快速添加标签（无重复查询，无复杂正则）
private function fastAddTags($wpdb, $post_id, $existing, $tag_num, $tags, $post_content) {
    $need = $tag_num - $existing;
    $added = 0;
    $insert_sql = [];

    foreach ($tags as $tag) {
        if ($added >= $need) break;
        // 简化匹配：仅匹配纯文本关键词（避免复杂负向断言，提升性能）
        if (strpos(strtolower($post_content), strtolower($tag['name'])) === false) {
            continue;
        }
        // 检查是否已关联（用WHERE EXISTS优化）
        $has = $wpdb->get_var(
            $wpdb->prepare(
                "SELECT 1 FROM {$wpdb->prefix}term_relationships 
                 WHERE object_id=%d AND term_taxonomy_id=%d LIMIT 1",
                $post_id, $tag['term_taxonomy_id']
            )
        );
        if ($has) continue;

        $insert_sql[] = $wpdb->prepare("(%d,%d)", $post_id, $tag['term_taxonomy_id']);
        $added++;
    }

    // 批量插入（仅1次数据库交互）
    if (!empty($insert_sql)) {
        $wpdb->query(
            "INSERT INTO {$wpdb->prefix}term_relationships (object_id, term_taxonomy_id) 
             VALUES " . implode(',', $insert_sql)
        );
    }
}
// 辅助方法：快速删除标签（批量操作，无循环更新）
private function fastRemoveTags($wpdb, $post_id, $existing, $tag_num, $tax) {
    $need = $existing - $tag_num;
    // 批量获取要删除的关联ID（按ID倒序，保留旧标签）
    $tt_ids = $wpdb->get_col(
        $wpdb->prepare(
            "SELECT tr.term_taxonomy_id FROM {$wpdb->prefix}term_relationships tr 
             JOIN {$wpdb->prefix}term_taxonomy tt ON tr.term_taxonomy_id=tt.term_taxonomy_id 
             WHERE tr.object_id=%d AND tt.taxonomy=%s 
             ORDER BY tr.object_id  DESC LIMIT %d",
            $post_id, $tax, $need
        )
    );
    if (empty($tt_ids)) return;

    // 批量删除（仅1次数据库交互）
    $wpdb->query(
        $wpdb->prepare(
            "DELETE FROM {$wpdb->prefix}term_relationships 
             WHERE object_id=%d AND term_taxonomy_id IN (" . implode(',', array_fill(0, count($tt_ids), '%d')) . ")",
            array_merge([$post_id], $tt_ids)
        )
    );
}
// 辅助方法：统一JSON输出（避免重复代码，确保输出格式正确）
private function jsonExit($data) {
    header('Content-Type: application/json; charset=utf-8');
    echo wp_json_encode($data);
    exit;
}


// 其他辅助方法（getValidPostTypes、checkAuth、getTotalPosts、processSinglePost、fastAddTags、fastRemoveTags、jsonExit）逻辑保持不变
public function baiduseo_add_pltag($log,$log1,$log2){
    // 验证请求合法性
    if(isset($_POST['nonce']) && isset($_POST['action']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['nonce'])),'baiduseo')){
        $type = isset($_POST['type'])?(int)$_POST['type']:0;
        $keywords_str = isset($_POST['keywords'])?sanitize_text_field(wp_unslash($_POST['keywords'])):'';
        $name_str = isset($_POST['name'])?sanitize_text_field(wp_unslash($_POST['name'])):''; // 逗号分割的文章类型
        
        global $wpdb;
        $baiduseo_wzt_log = baiduseo_kp::baiduseo_wzt_log();
        // 授权验证
        if(!$baiduseo_wzt_log || !baiduseo_zz::pay_money()){
            echo wp_json_encode(['msg'=>'请先授权','code'=>0]);
            exit;
        }
        
        // 处理文章类型：解析并验证合法性
        $valid_post_types = [];
        if(!empty($name_str)){
            $post_types = array_filter(array_map('trim', explode(',', $name_str)));
            $registered_types = get_post_types(['public' => true], 'names');
            $valid_post_types = array_intersect($post_types, $registered_types);
        }
      
        
        // 处理标签关键词：解析为数组
        $keywords = [];
        if(!empty($keywords_str)){
            $keywords = array_map('sanitize_text_field', explode(',', $keywords_str));
            $keywords = array_filter($keywords); // 过滤空值
        }
        if(empty($keywords)){
            echo wp_json_encode(['msg'=>'请传入有效标签关键词','code'=>0]);
            exit;
        }
        
        $baiduseo_tag_manage = get_option('baiduseo_tag');
        $has_success = false; // 标记是否有标签处理成功
        
        // 操作类型1：批量处理标签（动态匹配文章类型的标签分类法）
        if($type == 1){
            foreach ($valid_post_types as $target_post_type) {
                // 获取当前文章类型支持的标签分类法（非层级分类法）
                $taxonomies = get_object_taxonomies($target_post_type, 'objects');
                $tag_taxonomies = [];
                if(!empty($taxonomies)){
                    foreach ($taxonomies as $tax) {
                        if(!$tax->hierarchical && taxonomy_exists($tax->name)){
                            $tag_taxonomies[] = $tax->name;
                        }
                    }
                }
                if(empty($tag_taxonomies)) continue; // 无支持的标签分类法，跳过当前文章类型
                
                foreach ($keywords as $val) {
                    foreach ($tag_taxonomies as $tag_taxonomy) {
                        // 检查标签是否已存在
                        $terms = $wpdb->get_results(
                            $wpdb->prepare(
                                'SELECT a.* FROM '.$wpdb->prefix.'terms AS a 
                                LEFT JOIN '.$wpdb->prefix.'term_taxonomy AS b ON a.term_id = b.term_id 
                                WHERE b.taxonomy = %s AND a.name = %s',
                                $tag_taxonomy,
                                $val
                            ),
                            ARRAY_A
                        );
                        
                        if(empty($terms)){
                            // 创建标签
                            $term = wp_insert_term($val, $tag_taxonomy);
                            if(is_wp_error($term)) continue;
                            
                            $term_id = $term['term_id'];
                            $term_taxonomy_id = $term['term_taxonomy_id'];
                            
                            // 处理标签别名（slug）
                            if(!isset($baiduseo_tag_manage['taglink']) || !$baiduseo_tag_manage['taglink']){
                                $wpdb->update($wpdb->prefix.'terms', ['slug' => $term_id], ['term_id' => $term_id]);
                            }else{
                                $wpdb->update($wpdb->prefix.'terms', ['slug' => baiduseo_kp::baiduseo_generate_short_code($val)], ['term_id' => $term_id]);
                            }
                            
                            // 自动关联文章
                            if($baiduseo_tag_manage && isset($baiduseo_tag_manage['auto']) && $baiduseo_tag_manage['auto']){
                                $articles = $wpdb->get_results(
                                    $wpdb->prepare(
                                        "SELECT * FROM {$wpdb->prefix}posts 
                                        WHERE post_status = 'publish' AND post_type = %s 
                                        ORDER BY ID DESC LIMIT 1000",
                                        $target_post_type
                                    ),
                                    ARRAY_A
                                );
                                if(!empty($articles)){
                                    $max_tags = isset($baiduseo_tag_manage['num']) && $baiduseo_tag_manage['num'] > 0 && $baiduseo_tag_manage['num'] != 11 
                                        ? $baiduseo_tag_manage['num'] 
                                        : PHP_INT_MAX;
                                    $skip_headings = isset($baiduseo_tag_manage['hremove']) && $baiduseo_tag_manage['hremove'] == 1;
                                    
                                    foreach($articles as $article){
                                        // 检查当前分类法下的标签数量
                                        $current_tag_count = $wpdb->get_var(
                                            $wpdb->prepare(
                                                'SELECT COUNT(*) FROM '.$wpdb->prefix.'term_relationships AS a 
                                                LEFT JOIN '.$wpdb->prefix.'term_taxonomy AS b ON a.term_taxonomy_id = b.term_taxonomy_id 
                                                WHERE b.taxonomy = %s AND a.object_id = %d',
                                                $tag_taxonomy,
                                                $article['ID']
                                            )
                                        );
                                        if($current_tag_count >= $max_tags) continue;
                                        
                                        // 内容匹配正则
                                        $pattern = $skip_headings 
                                            ? '{(?!((<.*?)|(<a.*?)|(<h[1-6].*?>)))('.baiduseo_tag::BaiduSEO_preg($val).')(?!(([^<>]*?)>)|([^>]*?<\/a>)|([^>]*?<\/h[1-6]>))}i'
                                            : '{(?!((<.*?)|(<a.*?)))('.baiduseo_tag::BaiduSEO_preg($val).')(?!(([^<>]*?)>)|([^>]*?<\/a>))}i';
                                        
                                        if(preg_match($pattern, $article['post_content'], $matches)){
                                            $wpdb->insert(
                                                $wpdb->prefix.'term_relationships',
                                                ['object_id' => $article['ID'], 'term_taxonomy_id' => $term_taxonomy_id]
                                            );
                                            $wpdb->query(
                                                $wpdb->prepare(
                                                    'UPDATE '.$wpdb->prefix.'term_taxonomy 
                                                    SET count = count + 1 
                                                    WHERE term_taxonomy_id = %d',
                                                    $term_taxonomy_id
                                                )
                                            );
                                        }
                                    }
                                }
                            }
                        }
                        $has_success = true;
                    }
                }
            }
        }
        // 操作类型2：批量处理内链
        elseif($type == 2){
            foreach($keywords as $val){
                $existing = $wpdb->get_results(
                    $wpdb->prepare(
                        "SELECT * FROM ".$wpdb->prefix."baiduseo_neilian WHERE keywords = %s",
                        $val
                    ),
                    ARRAY_A
                );
                if(empty($existing)){
                    $wpdb->insert($wpdb->prefix."baiduseo_neilian", ['keywords' => $val, 'link' => '/']);
                }
            }
            $has_success = true;
        }
        
        echo wp_json_encode(['msg'=>'批量处理成功','code'=>1]);
        exit;
    }
    echo wp_json_encode(['msg'=>'操作失败','code'=>0]);
    exit;
}
    public function baiduseo_add_tag($log,$log1,$log2){
        // 验证请求合法性
        if(isset($_POST['nonce']) && isset($_POST['action']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['nonce'])),'baiduseo')){
            $keyword = isset($_POST['keyword'])?sanitize_text_field(wp_unslash($_POST['keyword'])):'';
            $type = isset($_POST['type'])?(int)$_POST['type']:0;
            $name_str = isset($_POST['name'])?sanitize_text_field(wp_unslash($_POST['name'])):'';
            
            global $wpdb;
            $baiduseo_wzt_log = baiduseo_kp::baiduseo_wzt_log();
            // 授权验证
            if(!$baiduseo_wzt_log){
                echo wp_json_encode(['msg'=>'请先授权','code'=>0]);
                exit;
            }
            if($log1['status']){
                $valid_post_types = [];
                if(!empty($name_str)){
                    $post_types = array_filter(array_map('trim', explode(',', $name_str)));
                    $registered_types = get_post_types(['public' => true], 'names');
                    $valid_post_types = array_intersect($post_types, $registered_types);
                }
            }else{
                echo wp_json_encode(['msg'=>'请先授权','code'=>0]);exit;
            }
            
            
            
            if($log2['token']){
                 $id = isset($_POST['id'])?(int)$_POST['id']:0;
                $url = get_permalink($id);
                $currnetTime= current_time( 'Y-m-d H:i:s');
                $baiduseo_zz = get_option('baiduseo_zz');
                $urls =explode(',',$url);
            }else{
                echo wp_json_encode(['msg'=>'请先授权','code'=>0]);exit;
            }
            $log3 = apply_filters('baiduseo_check4', true, $log1['token']);
            $log3 = json_decode($log3,true);
            $log4 = apply_filters('baiduseo_check5', true, $log1['token']);
            $log4 = json_decode($log4,true);
            $log5 = apply_filters('baiduseo_check6', true, $log1['token']);
            $log5 = json_decode($log5,true);
            
            
            
            
            $log3_code = is_array($log3) && isset($log3['code']) ? $log3['code'] : false; $log4_code = is_array($log4) &&  isset($log4['code']) ? $log4['code'] : false; $log5_code = is_array($log5)&&  isset($log5['code'])  ? $log5['code'] : false; if(!$log3_code && !$log4_code && !$log5_code ){
                $ss  = baiduseo_zz::pay_money();
                if(!$ss){
                     echo wp_json_encode(['msg'=>'请先授权','code'=>0]);exit;
                }
            }else{
                $log6 = apply_filters('baiduseo_check7', true, $log1['token'],$log2['token'],$log3['code'],$log4['code'],$log5['code']);
                if(!$log6){
                    $ss  = baiduseo_zz::pay_money();
                    if(!$ss){
                         echo wp_json_encode(['msg'=>'请先授权','code'=>0]);exit;
                    }
                }
            }
            
            // 处理文章类型：解析并验证合法性
            
            if(empty($valid_post_types)){
                $valid_post_types = ['post'];
            }
            
            // 操作类型1：循环处理每个文章类型，查询其支持的标签分类法
            if($type == 1){
                $has_success = false; // 标记是否有成功处理的分类法
                
                foreach ($valid_post_types as $target_post_type) {
                    // 步骤1：查询当前文章类型支持的所有分类法
                    $taxonomies = get_object_taxonomies($target_post_type, 'objects');
                    if(empty($taxonomies)){
                        continue; // 无关联分类法，跳过
                    }
                    
                    // 步骤2：筛选出“标签类型”的分类法（非层级分类法：hierarchical=false）
                    $tag_taxonomies = [];
                    foreach ($taxonomies as $tax) {
                        // 标签的核心特征：非层级（与分类目录区分）
                        if(!$tax->hierarchical && taxonomy_exists($tax->name)){
                            $tag_taxonomies[] = $tax->name;
                        }
                    }
                    
                    if(empty($tag_taxonomies)){
                        continue; // 无支持的标签分类法，跳过当前文章类型
                    }
                    
                    // 步骤3：遍历当前文章类型支持的所有标签分类法，处理标签
                    foreach ($tag_taxonomies as $tag_taxonomy) {
                        // 检查该分类法下标签是否已存在
                        $terms = $wpdb->get_results(
                            $wpdb->prepare(
                                'SELECT a.* FROM '.$wpdb->prefix.'terms AS a 
                                LEFT JOIN '.$wpdb->prefix.'term_taxonomy AS b ON a.term_id = b.term_id 
                                WHERE b.taxonomy = %s AND a.name = %s',
                                $tag_taxonomy,
                                $keyword
                            ),
                            ARRAY_A
                        );
                        
                        // 标签不存在则创建
                        if(empty($terms)){
                            $term = wp_insert_term(
                                $keyword,
                                $tag_taxonomy
                            );
                            
                            if(is_wp_error($term)){
                                continue; // 创建失败，跳过当前分类法
                            }
                            
                            $term_id = $term['term_id'];
                            $term_taxonomy_id = $term['term_taxonomy_id'];
                            
                            // 处理标签别名（slug）
                            $baiduseo_tag_manage = get_option('baiduseo_tag');
                            if(!isset($baiduseo_tag_manage['taglink']) || !$baiduseo_tag_manage['taglink']){
                                $wpdb->update($wpdb->prefix.'terms', ['slug' => $term_id], ['term_id' => $term_id]);
                            }else{
                                $wpdb->update($wpdb->prefix.'terms', ['slug' => baiduseo_kp::baiduseo_generate_short_code($keyword)], ['term_id' => $term_id]);
                            }
                            
                            // 给当前文章类型的文章添加标签关联
                            if($baiduseo_tag_manage && isset($baiduseo_tag_manage['auto']) && $baiduseo_tag_manage['auto']){
                                // 仅查询当前文章类型的已发布文章
                                $articles = $wpdb->get_results(
                                    $wpdb->prepare(
                                        "SELECT * FROM {$wpdb->prefix}posts 
                                        WHERE post_status = 'publish' AND post_type = %s 
                                        ORDER BY ID DESC LIMIT 1000",
                                        $target_post_type
                                    ),
                                    ARRAY_A
                                );
                                
                                if(!empty($articles)){
                                    $max_tags = isset($baiduseo_tag_manage['num']) && $baiduseo_tag_manage['num'] > 0 && $baiduseo_tag_manage['num'] != 11 
                                        ? $baiduseo_tag_manage['num'] 
                                        : PHP_INT_MAX;
                                    $skip_headings = isset($baiduseo_tag_manage['hremove']) && $baiduseo_tag_manage['hremove'] == 1;
                                    
                                    foreach($articles as $article){
                                        // 检查当前分类法下的标签数量
                                        $current_tag_count = $wpdb->get_var(
                                            $wpdb->prepare(
                                                'SELECT COUNT(*) FROM '.$wpdb->prefix.'term_relationships AS a 
                                                LEFT JOIN '.$wpdb->prefix.'term_taxonomy AS b ON a.term_taxonomy_id = b.term_taxonomy_id 
                                                WHERE b.taxonomy = %s AND a.object_id = %d',
                                                $tag_taxonomy,
                                                $article['ID']
                                            )
                                        );
                                        if($current_tag_count >= $max_tags){
                                            continue;
                                        }
                                        
                                        // 内容匹配规则
                                        $pattern = $skip_headings 
                                            ? '{(?!((<.*?)|(<a.*?)|(<h[1-6].*?>)))('.baiduseo_tag::BaiduSEO_preg($keyword).')(?!(([^<>]*?)>)|([^>]*?<\/a>)|([^>]*?<\/h[1-6]>))}i'
                                            : '{(?!((<.*?)|(<a.*?)))('.baiduseo_tag::BaiduSEO_preg($keyword).')(?!(([^<>]*?)>)|([^>]*?<\/a>))}i';
                                        
                                        if(preg_match($pattern, $article['post_content'], $matches)){
                                            $wpdb->insert(
                                                $wpdb->prefix.'term_relationships',
                                                ['object_id' => $article['ID'], 'term_taxonomy_id' => $term_taxonomy_id]
                                            );
                                            $wpdb->query(
                                                $wpdb->prepare(
                                                    'UPDATE '.$wpdb->prefix.'term_taxonomy 
                                                    SET count = count + 1 
                                                    WHERE term_taxonomy_id = %d',
                                                    $term_taxonomy_id
                                                )
                                            );
                                        }
                                    }
                                }
                            }
                        }
                        $has_success = true; // 标记当前分类法处理成功
                    }
                }
                
                // 反馈处理结果
                if ($has_success) {
                    echo wp_json_encode(['msg'=>'标签处理成功','code'=>1]);
                } else {
                    echo wp_json_encode(['msg'=>'所有文章类型均无支持的标签分类法或处理失败','code'=>0]);
                }
                exit;
            }
            // 操作类型2：处理内链（保持原有逻辑）
            elseif($type == 2){
                $existing = $wpdb->get_results(
                    $wpdb->prepare(
                        "SELECT * FROM ".$wpdb->prefix."baiduseo_neilian WHERE keywords = %s",
                        $keyword
                    ),
                    ARRAY_A
                );
                if(empty($existing)){
                    $wpdb->insert($wpdb->prefix."baiduseo_neilian", ['keywords' => $keyword, 'link' => '/']);
                }
                echo wp_json_encode(['msg'=>'内链处理成功','code'=>1]);
                exit;
            }
        }
        
        echo wp_json_encode(['msg'=>'操作失败','code'=>0]);
        exit;
    }
    public function baiduseo_tag_add($log,$log1,$log2){
         if (isset($_POST['nonce']) && isset($_POST['action']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['nonce'])), 'baiduseo')) {
        // 处理多文章类型参数（逗号分割）
        //判断是标签还是内敛
        if(!isset($_POST['name']) && isset($_POST['content']) && is_string($_POST['content']) &&  strpos($_POST['content'],',') === false){
            echo wp_json_encode(['msg' => '格式不正确，请更正后尝试。', 'code' => 0]);
                    exit;
        }
        $post_type_str = isset($_POST['name']) ? sanitize_text_field(wp_unslash($_POST['name'])) : '';
        $post_types = array_filter(explode(',', $post_type_str)); // 分割并过滤空值
        $valid_taxonomies = []; // 存储格式：[['post_type' => 'xxx', 'taxonomy' => 'yyy'], ...]
    
        // 遍历文章类型，动态获取其支持的标签分类法（非层级分类法）
        foreach ($post_types as $type) {
            $type = trim($type);
            if (!post_type_exists($type)) {
                continue; // 跳过无效文章类型
            }
    
            // 获取该文章类型支持的所有分类法（返回分类法对象数组）
            $tax_objects = get_object_taxonomies($type, 'objects');
            if (empty($tax_objects)) {
                continue; // 无关联分类法，跳过
            }
    
            // 筛选出“非层级分类法”（标签本质是 non-hierarchical 分类法）
            foreach ($tax_objects as $taxonomy => $tax_obj) {
                if (!$tax_obj->hierarchical && taxonomy_exists($taxonomy)) {
                    $valid_taxonomies[] = [
                        'post_type' => $type,
                        'taxonomy' => $taxonomy
                    ];
                }
            }
        }
    
        // 若没有有效标签分类法，返回错误
        
    
        // 原有验证逻辑
       
            if (isset($_POST['content']) && sanitize_textarea_field(wp_unslash($_POST['content']))) {
                $baiduseo_wzt_log = baiduseo_kp::baiduseo_wzt_log();
                if (!$baiduseo_wzt_log) {
                    echo wp_json_encode(['msg' => '请先授权', 'code' => 0]);
                    exit;
                }
                $log = baiduseo_zz::pay_money();
                if (!$log) {
                    echo wp_json_encode(['msg' => '请先授权', 'code' => 0]);
                    exit;
                }
                $content = explode("\n", sanitize_textarea_field(wp_unslash($_POST['content'])));
                $baiduseo_tag_manage = get_option('baiduseo_tag');
                if (!empty($content)) {
                    global $wpdb;
    
                    foreach ($content as $key => $val) {
                        $tag = explode(',', $val);
                        if (isset($tag[1])) {
                            // 处理带链接的关键词（保持原有逻辑）
                            $existing = $wpdb->get_results(
                                $wpdb->prepare(
                                    "SELECT * FROM ".$wpdb->prefix."baiduseo_neilian WHERE keywords = %s",
                                    $tag[0]
                                ),
                                ARRAY_A
                            );
                            if(empty($existing)){
                                $wpdb->insert($wpdb->prefix."baiduseo_neilian", ['keywords' => $tag[0], 'link' => $tag[1]]);
                            }else{
                                $wpdb->update($wpdb->prefix."baiduseo_neilian", ['keywords' => $tag[0], 'link' => $tag[1]],['id'=>$existing[0]['id']]);
                            }
                            
                        } else {
                            if (empty($valid_taxonomies)) {
                                echo wp_json_encode(['code' => 0, 'msg' => '请选择关联的板块后尝试操作！']);
                                exit;
                            }
                            // 对每个有效标签分类法，分别处理标签
                            foreach ($valid_taxonomies as $item) {
                                $post_type = $item['post_type'];
                                $taxonomy = $item['taxonomy'];
    
                                // 检查该分类法下是否已存在该标签
                                $terms = $wpdb->get_results($wpdb->prepare(
                                    'select a.* from ' . $wpdb->prefix . 'terms as a 
                                    left join ' . $wpdb->prefix . 'term_taxonomy as b on a.term_id = b.term_id 
                                    where b.taxonomy = %s and a.name = %s',
                                    $taxonomy, // 动态获取的标签分类法（如 post_tag、product_tag 等）
                                    $tag[0]
                                ), ARRAY_A);
    
                                if (!$terms) {
                                    // 在当前分类法下创建标签
                                    $term = wp_insert_term(
                                        $tag[0],    // 标签名称
                                        $taxonomy   // 动态标签分类法
                                    );
    
                                    // 处理标签创建失败（如重复创建的错误）
                                    if (is_wp_error($term)) {
                                        continue;
                                    }
    
                                    $term_id = $term['term_id'];
                                    $term_taxonomy_id = $term['term_taxonomy_id'];
    
                                    // 处理标签别名（slug）
                                    if (!isset($baiduseo_tag_manage['taglink']) || !$baiduseo_tag_manage['taglink']) {
                                        $wpdb->update($wpdb->prefix . 'terms', ['slug' => $term_id], ['term_id' => $term_id]);
                                    } else {
                                        $wpdb->update(
                                            $wpdb->prefix . 'terms',
                                            ['slug' => baiduseo_kp::baiduseo_generate_short_code($tag[0])],
                                            ['term_id' => $term_id]
                                        );
                                    }
    
                                    // 自动关联标签到对应文章类型的文章
                                    if ($baiduseo_tag_manage && isset($baiduseo_tag_manage['auto']) && $baiduseo_tag_manage['auto']) {
                                        // 查询当前文章类型的已发布文章
                                        $articles = $wpdb->get_results(
                                            $wpdb->prepare(
                                                'select * from ' . $wpdb->prefix . 'posts 
                                                where post_status = "publish" and post_type = %s 
                                                order by ID desc limit 1000',
                                                $post_type
                                            ),
                                            ARRAY_A
                                        );
    
                                        if (!isset($baiduseo_tag_manage['num']) || !$baiduseo_tag_manage['num'] || $baiduseo_tag_manage['num'] == 11) {
                                            foreach ($articles as $article) {
                                                $this->bind_tag_to_article($article, $term_taxonomy_id, $taxonomy, $tag[0], $baiduseo_tag_manage, $wpdb);
                                            }
                                        } else {
                                            foreach ($articles as $article) {
                                                // 检查文章在当前分类法下的已有标签数量
                                                $tag_count = $wpdb->query($wpdb->prepare(
                                                    'select * from ' . $wpdb->prefix . 'term_relationships as a 
                                                    left join ' . $wpdb->prefix . 'term_taxonomy as b on a.term_taxonomy_id = b.term_taxonomy_id 
                                                    where b.taxonomy = %s and a.object_id = %d',
                                                    $taxonomy,
                                                    $article['ID']
                                                ));
                                                if ($tag_count >= $baiduseo_tag_manage['num']) {
                                                    break;
                                                }
                                                $this->bind_tag_to_article($article, $term_taxonomy_id, $taxonomy, $tag[0], $baiduseo_tag_manage, $wpdb);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            } else {
                echo wp_json_encode(['code' => 0, 'msg' => '请输入关键词']);
                exit;
            }
            echo wp_json_encode(['code' => 1, 'msg' => '添加成功']);
            exit;
        }
        echo wp_json_encode(['code' => 0, 'msg' => '添加失败']);
        exit;
    }
    
    // 封装标签与文章的关联逻辑
    private function bind_tag_to_article($article, $term_taxonomy_id, $taxonomy, $tag_name, $baiduseo_tag_manage, $wpdb) {
        // 根据配置生成匹配规则（跳过标签/标题内的关键词）
        if (isset($baiduseo_tag_manage['hremove']) && $baiduseo_tag_manage['hremove'] == 1) {
            $pattern = '{(?!((<.*?)|(<a.*?)|(<h[1-6].*?>)))(' . baiduseo_tag::BaiduSEO_preg($tag_name) . ')(?!(([^<>]*?)>)|([^>]*?<\/a>)|([^>]*?<\/h[1-6]>))}i';
        } else {
            $pattern = '{(?!((<.*?)|(<a.*?)))(' . baiduseo_tag::BaiduSEO_preg($tag_name) . ')(?!(([^<>]*?)>)|([^>]*?<\/a>))}i';
        }
    
        // 匹配文章内容中的关键词，成功则关联标签
        if (preg_match($pattern, $article['post_content'], $matches)) {
            // 关联标签到文章
            $wpdb->insert(
                $wpdb->prefix . "term_relationships",
                ['object_id' => $article['ID'], 'term_taxonomy_id' => $term_taxonomy_id]
            );
    
            // 更新标签的引用计数
            $term_taxonomy = $wpdb->get_results($wpdb->prepare(
                'select * from ' . $wpdb->prefix . 'term_taxonomy where term_taxonomy_id = %d',
                $term_taxonomy_id
            ), ARRAY_A);
            if (!empty($term_taxonomy)) {
                $count = $term_taxonomy[0]['count'] + 1;
                $wpdb->update(
                    $wpdb->prefix . 'term_taxonomy',
                    ['count' => $count],
                    ['term_taxonomy_id' => $term_taxonomy_id]
                );
            }
        }
    }
    public function baiduseo_rank($log,$log1,$log2){
        if(isset($_POST['nonce']) && isset($_POST['action']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['nonce'])),'baiduseo')){
            $baiduseo_wzt_log = baiduseo_kp::baiduseo_wzt_log();
            if(!$baiduseo_wzt_log){
                echo wp_json_encode(['msg'=>'请先授权','code'=>0]);exit;
            }
            if($log1['status']){
                $baiduseo_rank = get_option('baiduseo_rank');
            }else{
                echo wp_json_encode(['msg'=>'请先授权','code'=>0]);exit;
            }
            
            
            
            if($log2['token']){
                
            }else{
                echo wp_json_encode(['msg'=>'请先授权','code'=>0]);exit;
            }
            $log3 = apply_filters('baiduseo_check4', true, $log1['token']);
            $log3 = json_decode($log3,true);
            $log4 = apply_filters('baiduseo_check5', true, $log1['token']);
            $log4 = json_decode($log4,true);
            $log5 = apply_filters('baiduseo_check6', true, $log1['token']);
            $log5 = json_decode($log5,true);
            
            
            
            
            $log3_code = is_array($log3) && isset($log3['code']) ? $log3['code'] : false; $log4_code = is_array($log4) &&  isset($log4['code']) ? $log4['code'] : false; $log5_code = is_array($log5)&&  isset($log5['code'])  ? $log5['code'] : false; if(!$log3_code && !$log4_code && !$log5_code ){
                $ss  = baiduseo_zz::pay_money();
                if(!$ss){
                     echo wp_json_encode(['msg'=>'请先授权','code'=>0]);exit;
                }
            }else{
                $log6 = apply_filters('baiduseo_check7', true, $log1['token'],$log2['token'],$log3['code'],$log4['code'],$log5['code']);
                if(!$log6){
                    $ss  = baiduseo_zz::pay_money();
                    if(!$ss){
                         echo wp_json_encode(['msg'=>'请先授权','code'=>0]);exit;
                    }
                }
            }
            
            
            $ur=  baiduseo_common::baiduseo_url(0);
            $url = 'https://api.seoceo.cn/api/rank/get_rank?url='.$ur.'&http='.get_option('siteurl');
            $defaults = array(
                'timeout' => 4000,
                'redirection' => 4000,
                '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);
            $result = wp_remote_retrieve_body($result);
            if($result){
                $result = json_decode($result,true);
                if($result['code']){
                    if($baiduseo_rank!==false){
                        update_option('baiduseo_rank',$result['data']);
                    }else{
                        add_option('baiduseo_rank',$result['data']);
                    }
                    echo wp_json_encode(['code'=>1,'data'=>$result['data']]);exit;
                }else{
                    echo wp_json_encode(['code'=>0,'msg'=>'24小时只能查询一次']);exit;
                }
            }else{
                echo wp_json_encode(['code'=>0,'msg'=>'查询失败']);exit;
            }
            
            
        }
        echo wp_json_encode(['code'=>0]);exit;
    }
    public function baiduseo_301($log,$log1,$log2){
        if(isset($_POST['nonce']) && isset($_POST['action']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['nonce'])),'baiduseo')){
            $site_url = baiduseo_common::baiduseo_url(0).'/';
            $site_url1 = baiduseo_common::baiduseo_url(1);
            $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,
            );
            $http_type = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://';
            $url = str_replace('www.','',$site_url);
            
            $url1 = $http_type.$url;
            $url2 = $http_type.'www.'.$url;
            $url_301['status'] = 0;
            $result = wp_remote_get($url1,$defaults);
            if(!is_wp_error($result)){
              $http = (array)$result['http_response'];
              
              $url_301['re_url1'] = $http["\0*\0response"]->url;
            }else{
               $url_301['re_url1'] =''; 
            }
            $result1 = wp_remote_get($url2,$defaults);
            if(!is_wp_error($result1)){
              $http1 = (array)$result1['http_response'];
              
              
              $url_301['re_url2'] = $http1["\0*\0response"]->url;
            }else{
                $url_301['re_url2'] ='';
            }
           
             if( trim($url_301['re_url2'],'/')==trim($site_url1,'/') || trim($url_301['re_url1'],'/')==trim($site_url1,'/')){
                echo wp_json_encode(['msg'=>'恭喜您，您的301状态正常，无需设置！','code'=>1]);exit; 
            }else{
                echo wp_json_encode(['code'=>0]);exit; 
            }
        
        }
        echo wp_json_encode(['code'=>0]);exit; 
    }
    public function baiduseo_zhizhu_clear($log,$log1,$log2){
        if(isset($_POST['nonce']) && isset($_POST['action']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['nonce'])),'baiduseo')){
            $baiduseo_wzt_log = baiduseo_kp::baiduseo_wzt_log();
            if(!$baiduseo_wzt_log){
                  echo wp_json_encode(['msg'=>'请先授权','code'=>0]);exit;
            }
            if($log1['status']){
                
            }else{
                echo wp_json_encode(['msg'=>'请先授权','code'=>0]);exit;
            }
            
            
            
            if($log2['token']){
                
            }else{
                echo wp_json_encode(['msg'=>'请先授权','code'=>0]);exit;
            }
            $log3 = apply_filters('baiduseo_check4', true, $log1['token']);
            $log3 = json_decode($log3,true);
            $log4 = apply_filters('baiduseo_check5', true, $log1['token']);
            $log4 = json_decode($log4,true);
            $log5 = apply_filters('baiduseo_check6', true, $log1['token']);
            $log5 = json_decode($log5,true);
            
            
            
            
            $log3_code = is_array($log3) && isset($log3['code']) ? $log3['code'] : false; $log4_code = is_array($log4) &&  isset($log4['code']) ? $log4['code'] : false; $log5_code = is_array($log5)&&  isset($log5['code'])  ? $log5['code'] : false; if(!$log3_code && !$log4_code && !$log5_code ){
                $ss  = baiduseo_zz::pay_money();
                if(!$ss){
                     echo wp_json_encode(['msg'=>'请先授权','code'=>0]);exit;
                }
            }else{
                $log6 = apply_filters('baiduseo_check7', true, $log1['token'],$log2['token'],$log3['code'],$log4['code'],$log5['code']);
                if(!$log6){
                    $ss  = baiduseo_zz::pay_money();
                    if(!$ss){
                         echo wp_json_encode(['msg'=>'请先授权','code'=>0]);exit;
                    }
                }
            }
            global $wpdb;
            $res = $wpdb->query( "DELETE FROM " . $wpdb->prefix . "baiduseo_zhizhu  " );
            if($res){
            echo wp_json_encode(['code'=>1]);exit; 
            }
        }
        echo wp_json_encode(['msg'=>'删除失败','code'=>0]);exit;
    }
    public function baiduseo_zhizhu_linkdelete($log,$log1,$log2){
        if(isset($_POST['nonce']) && isset($_POST['action']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['nonce'])),'baiduseo')){
            global $wpdb;
            $id = isset($_POST['id'])?(int)$_POST['id']:0;
           
            $res = $wpdb->query($wpdb->prepare("DELETE FROM " . $wpdb->prefix . "baiduseo_zhizhu where id=%d",$id));
            echo wp_json_encode(['code'=>1]);exit; 
        }
         echo wp_json_encode(['code'=>0]);exit; 
    }
    public function baiduseo_tag($log,$log1,$log2){
        if(isset($_POST['nonce']) && isset($_POST['action']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['nonce'])),'baiduseo')){
           $baiduseo_wzt_log = baiduseo_kp::baiduseo_wzt_log();
            if(!$baiduseo_wzt_log){
                 echo wp_json_encode(['msg'=>'请先授权','code'=>0]);exit;
            }
            if($log1['status']){
                
            }else{
                echo wp_json_encode(['msg'=>'请先授权','code'=>0]);exit;
            }
            
            
            
            if($log2['token']){
                
            }else{
                echo wp_json_encode(['msg'=>'请先授权','code'=>0]);exit;
            }
            $log3 = apply_filters('baiduseo_check4', true, $log1['token']);
            $log3 = json_decode($log3,true);
            $log4 = apply_filters('baiduseo_check5', true, $log1['token']);
            $log4 = json_decode($log4,true);
            $log5 = apply_filters('baiduseo_check6', true, $log1['token']);
            $log5 = json_decode($log5,true);
            
            
            
            
            $log3_code = is_array($log3) && isset($log3['code']) ? $log3['code'] : false; $log4_code = is_array($log4) &&  isset($log4['code']) ? $log4['code'] : false; $log5_code = is_array($log5)&&  isset($log5['code'])  ? $log5['code'] : false; if(!$log3_code && !$log4_code && !$log5_code ){
                $ss  = baiduseo_zz::pay_money();
                if(!$ss){
                     echo wp_json_encode(['msg'=>'请先授权','code'=>0]);exit;
                }
            }else{
                $log6 = apply_filters('baiduseo_check7', true, $log1['token'],$log2['token'],$log3['code'],$log4['code'],$log5['code']);
                if(!$log6){
                    $ss  = baiduseo_zz::pay_money();
                    if(!$ss){
                         echo wp_json_encode(['msg'=>'请先授权','code'=>0]);exit;
                    }
                }
            }
            baiduseo_tag::baiduseo_tag_set($_POST);
            
        }
        echo wp_json_encode(['msg'=>'保存失败','code'=>0]);exit;
    }

    public function baiduseo_youhua($log,$log1,$log2){
        if(isset($_POST['nonce']) && isset($_POST['action']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['nonce'])),'baiduseo')){
            $data = [
                'thumb'=>isset($_POST['thumb'])?(int)$_POST['thumb']:0,
                'head_dy'=>isset($_POST['head_dy'])?(int)$_POST['head_dy']:0,
                'xml_rpc'=>isset($_POST['xml_rpc'])?(int)$_POST['xml_rpc']:0,
                'feed'=>isset($_POST['feed'])?(int)$_POST['feed']:0,
                'post_thumb'=>isset($_POST['post_thumb'])?(int)$_POST['post_thumb']:0,
                'gravatar'=>isset($_POST['gravatar'])?(int)$_POST['gravatar']:0,
                'lan'=>isset($_POST['lan'])?(int)$_POST['lan']:0,
                'category'=>isset($_POST['category'])?(int)$_POST['category']:0,
                'listbtn'=>isset($_POST['listbtn'])?(int)$_POST['listbtn']:0,
                'wp_json'=>isset($_POST['wp_json'])?(int)$_POST['wp_json']:0,
                'art_cron'=>isset($_POST['art_cron'])?(int)$_POST['art_cron']:0,
            ];
            $baidu = get_option('baiduseo_youhua');
            if($baidu!==false){
                update_option('baiduseo_youhua',$data);
            }else{
                add_option('baiduseo_youhua',$data);
            }
            echo wp_json_encode(['msg'=>'保存成功','code'=>1]);exit;
        }
        echo wp_json_encode(['msg'=>'保存失败','code'=>0]);exit;
    }
    public function baiduseo_zz($log,$log1,$log2){
        
        
        if(isset($_POST['nonce']) && isset($_POST['action']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['nonce'])),'baiduseo')){
            global $wpdb;
            $baiduseo_wzt_log = baiduseo_kp::baiduseo_wzt_log();
            if(!$baiduseo_wzt_log){
                echo wp_json_encode(['msg'=>'请先授权','code'=>0]);exit;
            }
            if($log1['status']){
                
            }else{
                echo wp_json_encode(['msg'=>'请先授权','code'=>0]);exit;
            }
            
            
            
            if($log2['token']){
                
            }else{
                echo wp_json_encode(['msg'=>'请先授权','code'=>0]);exit;
            }
            $log3 = apply_filters('baiduseo_check4', true, $log1['token']);
            $log3 = json_decode($log3,true);
            $log4 = apply_filters('baiduseo_check5', true, $log1['token']);
            $log4 = json_decode($log4,true);
            $log5 = apply_filters('baiduseo_check6', true, $log1['token']);
            $log5 = json_decode($log5,true);
            
            
            
            
            $log3_code = is_array($log3) && isset($log3['code']) ? $log3['code'] : false; $log4_code = is_array($log4) &&  isset($log4['code']) ? $log4['code'] : false; $log5_code = is_array($log5)&&  isset($log5['code'])  ? $log5['code'] : false; if(!$log3_code && !$log4_code && !$log5_code ){
                $ss  = baiduseo_zz::pay_money();
                if(!$ss){
                     echo wp_json_encode(['msg'=>'请先授权','code'=>0]);exit;
                }
            }else{
                $log6 = apply_filters('baiduseo_check7', true, $log1['token'],$log2['token'],$log3['code'],$log4['code'],$log5['code']);
                if(!$log6){
                    $ss  = baiduseo_zz::pay_money();
                    if(!$ss){
                         echo wp_json_encode(['msg'=>'请先授权','code'=>0]);exit;
                    }
                }
            }
            $indexnow_key = isset($_POST['indexnow_key'])?sanitize_text_field(wp_unslash($_POST['indexnow_key'])):'';
            
            $seo_baidu_xzh =[                            
                'zz_link'=>isset($_POST['zz_link'])?sanitize_url(wp_unslash($_POST['zz_link'])):'',                                   
                'bing_key'=>isset($_POST['bing_key'])?sanitize_text_field(wp_unslash($_POST['bing_key'])):'', 
                // 'shenma_key' =>isset($_POST['shenma_key'])?sanitize_url(wp_unslash($_POST['shenma_key'])):"",
                'toutiao_key'=>isset($_POST['toutiao_key'])?sanitize_text_field(wp_unslash($_POST['toutiao_key'])):"",
                'indexnow_key'=>$indexnow_key,
                'google_api'=>isset($_POST['google_api'])?sanitize_textarea_field(wp_unslash($_POST['google_api'])):"",
                // 'indexnow_pingtai'=>isset($_POST['indexnow_pingtai'])?sanitize_text_field(wp_unslash($_POST['indexnow_pingtai'])):"",
                'post_type'=>isset($_POST['post_type'])?sanitize_text_field(wp_unslash($_POST['post_type'])):"",
                // 'baiduseo_type'=>sanitize_text_field($_POST['baiduseo_type']),
                // 'post_type'=>isset($_POST['bing_key'])?sanitize_text_field($_POST['post_type']),
                'status'=>isset($_POST['status'])?sanitize_text_field(wp_unslash($_POST['status'])):'',
                'pingtai'=>isset($_POST['pingtai'])?sanitize_text_field(wp_unslash($_POST['pingtai'])):'',
                'guowai_num'=>isset($_POST['guowai_num'])?(int)$_POST['guowai_num']:0,
                'bdpt_num'=>isset($_POST['bdpt_num'])?(int)$_POST['bdpt_num']:0,
                'bing_num'=>isset($_POST['bing_num'])?(int)$_POST['bing_num']:0,
                // 'sm_num'=>isset($_POST['sm_num'])?(int)$_POST['sm_num']:"",
                // 'log'=>isset($_POST['log'])?sanitize_text_field(wp_unslash($_POST['log'])):"",
                'bd_log'=>isset($_POST['bd_log'])?(int)$_POST['bd_log']:0,
                'bd_log_show'=>isset($_POST['bd_log_show'])?(int)$_POST['bd_log_show']:0,
                // 'bdks_log'=>isset($_POST['bdks_log'])?(int)$_POST['bdks_log']:"",
                'bing_log'=>isset($_POST['bing_log'])?(int)$_POST['bing_log']:0,
                'bing_log_show'=>isset($_POST['bing_log_show'])?(int)$_POST['bing_log_show']:0,
                 'seznam_log'=>isset($_POST['seznam_log'])?(int)$_POST['seznam_log']:0,
                'seznam_log_show'=>isset($_POST['seznam_log_show'])?(int)$_POST['seznam_log_show']:0,
                'indexNow_log'=>isset($_POST['indexNow_log'])?(int)$_POST['indexNow_log']:0,
                'indexNow_log_show'=>isset($_POST['indexNow_log_show'])?(int)$_POST['indexNow_log_show']:0,
                  'indexNow_bing_log'=>isset($_POST['indexNow_bing_log'])?(int)$_POST['indexNow_bing_log']:0,
                'indexNow_bing_log_show'=>isset($_POST['indexNow_bing_log_show'])?(int)$_POST['indexNow_bing_log_show']:0,
                'guge_log'=>isset($_POST['guge_log'])?(int)$_POST['guge_log']:0,
                'guge_log_show'=>isset($_POST['guge_log_show'])?(int)$_POST['guge_log_show']:0,
                  'yandex_log'=>isset($_POST['yandex_log'])?(int)$_POST['yandex_log']:0,
                'yandex_log_show'=>isset($_POST['yandex_log_show'])?(int)$_POST['yandex_log_show']:0,  
                'naver_log'=>isset($_POST['naver_log'])?(int)$_POST['naver_log']:0,
                'naver_log_show'=>isset($_POST['naver_log_show'])?(int)$_POST['naver_log_show']:0,  
                'yep_log'=>isset($_POST['yep_log'])?(int)$_POST['yep_log']:0,
                'yep_log_show'=>isset($_POST['yep_log_show'])?(int)$_POST['yep_log_show']:0,
                'status'=>sanitize_text_field(wp_unslash($_POST['status'])),
                
            ];
            if($indexnow_key){
                WP_Filesystem();
                global $wp_filesystem;
                $res = $wp_filesystem->put_contents (ABSPATH.'/'.$indexnow_key.'.txt',$indexnow_key);
                
            }
            
            $baidu = get_option('baiduseo_zz');
            if($baidu!==false){
                update_option('baiduseo_zz',$seo_baidu_xzh);
            }else{
                add_option('baiduseo_zz',$seo_baidu_xzh);
            }
            baiduseo_set::baiduseo_set_option($baiduseo_wzt_log,'baiduseo_zz',$seo_baidu_xzh);
            echo wp_json_encode(['msg'=>'保存成功','code'=>1]);exit;
        }
        
         echo wp_json_encode(['msg'=>'保存失败','code'=>0]);exit;
       
        
            
            
    }
    public function baiduseo_seo($log,$log1,$log2){
       
        if(isset($_POST['nonce']) && isset($_POST['action']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['nonce'])),'baiduseo')){
            $baiduseo_wzt_log = baiduseo_kp::baiduseo_wzt_log();
            if(!$baiduseo_wzt_log){
                 echo wp_json_encode(['code'=>'0','msg'=>'请先授权']);exit;
            }
            if($log1['status']){
                
            }else{
                echo wp_json_encode(['msg'=>'请先授权','code'=>0]);exit;
            }
            
            
            
            if($log2['token']){
                
            }else{
                echo wp_json_encode(['msg'=>'请先授权','code'=>0]);exit;
            }
            $log3 = apply_filters('baiduseo_check4', true, $log1['token']);
            $log3 = json_decode($log3,true);
            $log4 = apply_filters('baiduseo_check5', true, $log1['token']);
            $log4 = json_decode($log4,true);
            $log5 = apply_filters('baiduseo_check6', true, $log1['token']);
            $log5 = json_decode($log5,true);
            
            
            
            
            $log3_code = is_array($log3) && isset($log3['code']) ? $log3['code'] : false; $log4_code = is_array($log4) &&  isset($log4['code']) ? $log4['code'] : false; $log5_code = is_array($log5)&&  isset($log5['code'])  ? $log5['code'] : false; if(!$log3_code && !$log4_code && !$log5_code ){
                $ss  = baiduseo_zz::pay_money();
                if(!$ss){
                     echo wp_json_encode(['msg'=>'请先授权','code'=>0]);exit;
                }
            }else{
                $log6 = apply_filters('baiduseo_check7', true, $log1['token'],$log2['token'],$log3['code'],$log4['code'],$log5['code']);
                if(!$log6){
                    $ss  = baiduseo_zz::pay_money();
                    if(!$ss){
                         echo wp_json_encode(['msg'=>'请先授权','code'=>0]);exit;
                    }
                }
            }
           baiduseo_seo::seo_index(isset($_POST['keywords'])?sanitize_text_field(wp_unslash($_POST['keywords'])):'',isset($_POST['description'])?sanitize_textarea_field(wp_unslash($_POST['description'])):'');
           
            if(isset($_POST['cate'])){
                baiduseo_seo::cate_seo(isset($_POST['cate_keywords'])?sanitize_text_field(wp_unslash($_POST['cate_keywords'])):'',isset($_POST['cate_description'])?sanitize_textarea_field(wp_unslash($_POST['cate_description'])):'',(int)$_POST['cate']);
            }
            if(isset($_POST['page'])){
                baiduseo_seo::page_seo(isset($_POST['page_keywords'])?sanitize_text_field(wp_unslash($_POST['page_keywords'])):'',isset($_POST['page_description'])?sanitize_text_field(wp_unslash($_POST['page_description'])):'',(int)$_POST['page']);
            }
            if(isset($_POST['page_404']) && (int)$_POST['page_404']){
                baiduseo_seo::page_404();
            }else{
                $seo_301_404_url = get_option('seo_301_404_url');
                if($seo_301_404_url!=false){
                    update_option('seo_301_404_url',['404_url'=>0]);
                }else{
                    add_option('seo_301_404_url',['404_url'=>0]);
                }
            }
            if(isset($_POST['robots'])){
                baiduseo_seo::robots(sanitize_textarea_field(wp_unslash($_POST['robots'])));
            }
            
            $sitemap = get_option('seo_baidu_sitemap');
            if($sitemap!==false && !is_array($sitemap)){
                // $data = $sitemap;
                 $data['level1'] = isset($_POST['level1'])?(int)$_POST['level1']:0;
                $data['level2'] = isset($_POST['level2'])?(int)$_POST['level2']:0;
                $data['level3'] = isset($_POST['level3'])?(int)$_POST['level3']:0;
                $data['level4'] = isset($_POST['level4'])?(int)$_POST['level4']:0;
                $data['level5'] = isset($_POST['level5'])?(int)$_POST['level5']:0;
                $data['type1'] = isset($_POST['type1'])?(int)$_POST['type1']:0;
                $data['type2'] = isset($_POST['type2'])?(int)$_POST['type2']:0;
                $data['type3'] = isset($_POST['type3'])?(int)$_POST['type3']:0;
                $data['type4'] = isset($_POST['type4'])?(int)$_POST['type4']:0;
                $data['type5'] = isset($_POST['type5'])?(int)$_POST['type5']:0;
                $data['page_time'] = isset($_POST['page_time'])?sanitize_text_field(wp_unslash($_POST['page_time'])):"";
                $data['post_time'] = isset($_POST['post_time'])?sanitize_text_field(wp_unslash($_POST['post_time'])):"";
                $data['tag_time'] = isset($_POST['tag_time'])?sanitize_text_field(wp_unslash($_POST['tag_time'])):"";
                $data['other_time'] = isset($_POST['other_time'])?sanitize_text_field(wp_unslash($_POST['other_time'])):"";
                $data['cate_time'] = isset($_POST['cate_time'])?sanitize_text_field(wp_unslash($_POST['cate_time'])):"";
                $data['sitemap_open'] = isset($_POST['sitemap_open'])?(int)$_POST['sitemap_open']:"";
                $data['silian_open'] = isset($_POST['silian_open'])?(int)$_POST['silian_open']:"";
                $data['tag_open'] = isset($_POST['tag_open'])?(int)$_POST['tag_open']:0;
                update_option('seo_baidu_sitemap',$data);
            }elseif($sitemap!==false && is_array($sitemap)){
                $data = $sitemap;
                $data['level1'] = isset($_POST['level1'])?(int)$_POST['level1']:0;
                $data['level2'] = isset($_POST['level2'])?(int)$_POST['level2']:0;
                $data['level3'] = isset($_POST['level3'])?(int)$_POST['level3']:0;
                $data['level4'] = isset($_POST['level4'])?(int)$_POST['level4']:0;
                $data['level5'] = isset($_POST['level5'])?(int)$_POST['level5']:0;
                $data['type1'] = isset($_POST['type1'])?(int)$_POST['type1']:0;
                $data['type2'] = isset($_POST['type2'])?(int)$_POST['type2']:0;
                $data['type3'] = isset($_POST['type3'])?(int)$_POST['type3']:0;
                $data['type4'] = isset($_POST['type4'])?(int)$_POST['type4']:0;
                $data['type5'] = isset($_POST['type5'])?(int)$_POST['type5']:0;
                $data['page_time'] = isset($_POST['page_time'])?sanitize_text_field(wp_unslash($_POST['page_time'])):"";
                $data['post_time'] = isset($_POST['post_time'])?sanitize_text_field(wp_unslash($_POST['post_time'])):"";
                $data['tag_time'] = isset($_POST['tag_time'])?sanitize_text_field(wp_unslash($_POST['tag_time'])):"";
                $data['other_time'] = isset($_POST['other_time'])?sanitize_text_field(wp_unslash($_POST['other_time'])):"";
                $data['cate_time'] = isset($_POST['cate_time'])?sanitize_text_field(wp_unslash($_POST['cate_time'])):"";
                $data['sitemap_open'] = isset($_POST['sitemap_open'])?(int)$_POST['sitemap_open']:"";
                $data['silian_open'] = isset($_POST['silian_open'])?(int)$_POST['silian_open']:"";
                $data['tag_open'] = isset($_POST['tag_open'])?(int)$_POST['tag_open']:0;
                update_option('seo_baidu_sitemap',$data);
            }else{
                 $data['level1'] = isset($_POST['level1'])?(int)$_POST['level1']:0;
                $data['level2'] = isset($_POST['level2'])?(int)$_POST['level2']:0;
                $data['level3'] = isset($_POST['level3'])?(int)$_POST['level3']:0;
                $data['level4'] = isset($_POST['level4'])?(int)$_POST['level4']:0;
                $data['level5'] = isset($_POST['level5'])?(int)$_POST['level5']:0;
                $data['type1'] = isset($_POST['type1'])?(int)$_POST['type1']:0;
                $data['type2'] = isset($_POST['type2'])?(int)$_POST['type2']:0;
                $data['type3'] = isset($_POST['type3'])?(int)$_POST['type3']:0;
                $data['type4'] = isset($_POST['type4'])?(int)$_POST['type4']:0;
                $data['type5'] = isset($_POST['type5'])?(int)$_POST['type5']:0;
                $data['page_time'] = isset($_POST['page_time'])?sanitize_text_field(wp_unslash($_POST['page_time'])):"";
                $data['post_time'] = isset($_POST['post_time'])?sanitize_text_field(wp_unslash($_POST['post_time'])):"";
                $data['tag_time'] = isset($_POST['tag_time'])?sanitize_text_field(wp_unslash($_POST['tag_time'])):"";
                $data['other_time'] = isset($_POST['other_time'])?sanitize_text_field(wp_unslash($_POST['other_time'])):"";
                $data['cate_time'] = isset($_POST['cate_time'])?sanitize_text_field(wp_unslash($_POST['cate_time'])):"";
                $data['sitemap_open'] = isset($_POST['sitemap_open'])?(int)$_POST['sitemap_open']:"";
                $data['silian_open'] = isset($_POST['silian_open'])?(int)$_POST['silian_open']:"";
                $data['tag_open'] = isset($_POST['tag_open'])?(int)$_POST['tag_open']:0;
                add_option('seo_baidu_sitemap',$data);  
            }
            baiduseo_set::baiduseo_set_option($baiduseo_wzt_log,'seo_baidu_sitemap',$data);
            baiduseo_seo::alt(isset($_POST['alt'])?(int)$_POST['alt']:0,isset($_POST['title'])?(int)$_POST['title']:0);
            unset($data, $log3, $log4, $log5, $sitemap);
            if(isset($_POST['sitemap_open']) && (int)$_POST['sitemap_open']==1){
            baiduseo_seo::sitemap(1,1,1);
            }
            if(isset($_POST['silian_open']) && (int)$_POST['silian_open']==1){
                baiduseo_seo::silian(1,1);
            }
            echo wp_json_encode(['msg'=>'','code'=>1]);exit;
        }else{
             echo wp_json_encode(['msg'=>'','code'=>0]);exit;
        }
    }

    public function baiduseo_wycsc($log,$log1,$log2){
        if(isset($_POST['nonce']) &&  wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['nonce'])),'baiduseo')){
            $id = isset($_POST['id'])?(int)$_POST['id']:'';
            delete_post_meta($id,'baiduseo');
            echo wp_json_encode(['code'=>'1','msg'=>'删除成功']);exit;
        }
        echo wp_json_encode(['code'=>'0','msg'=>'删除失败']);exit;
    }
}