File "deal_featured.php"

Full Path: /www/wwwroot/shphe-en.com/admin/deal_featured.php
File size: 4.15 KB
MIME-type: --
Charset: utf-8

<?php 
require_once( dirname(__FILE__) . '/../wp-load.php' ); 
if( is_user_logged_in() ) {
global $wpdb;
function curl_c($url,$method='get',$data=[]){
    if($method == 'post'){
        $data = json_encode($data);
    }
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_POST, 1);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
	curl_setopt($ch, CURLOPT_HEADER, false);
	curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
	curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.246');
	curl_setopt($ch, CURLOPT_AUTOREFERER, true);
	curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
	if($method == 'post'){
    	curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    	curl_setopt($ch, CURLOPT_HTTPHEADER, array(
            "Content-Type: application/json; charset=utf-8",
            "Content-Length: " . strlen($data))
          );
	}
	curl_setopt($ch, CURLOPT_TIMEOUT, 30);
	curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
	curl_setopt($ch, CURLOPT_SSLVERSION, 'all');
	curl_setopt($ch, CURLOPT_ENCODING, 'gzip');
	$content = curl_exec($ch);
	curl_close($ch);
	return $content;
}

if(isset($_POST['dosubmit'])){
	$urls = $_POST['urls'];
	if(empty($urls)){
	    echo '<div id="setting-error-settings_updated" class="updated settings-error"><p><strong>链接列表不能为空</strong></p></div>';
	}else{
	    $ar_urls = explode("\n",$urls);
	    $home_url = home_url('/');
	    $ar_home_url = explode('/',$home_url);
	    $cnt = $all_cnt = 0;
	    $data = [];
	    if(count($ar_urls) > 1000){
	        echo '<div id="setting-error-settings_updated" class="updated settings-error"><p><strong>一次删除的产品数量不能大于1000条</strong></p></div>';
	    }else{
    	    foreach ($ar_urls as $v){
    	        $v = trim($v);
    	        if(empty($v)){
    	            continue;
    	        }
    	        $tmp_url = explode('/',$v);
    	        $guid_url = str_replace($tmp_url[2],$ar_home_url[2],$v);
    	        if(strpos($guid_url,'/') === false){
    	            continue;
    	        }
    	        $data[] = $tmp_url[3];
                
    	        $post = $wpdb->get_row("SELECT a.ID FROM `wp_posts` as a INNER JOIN wp_term_relationships as b ON a.ID=b.object_id WHERE b.term_taxonomy_id=635 AND a.post_type='post' and a.post_status='publish' and a.guid='".$guid_url."'",ARRAY_A);
    	        if($post){
    	            $cnt++;
    	            wp_delete_post($post['ID'],1);
    	            if(strpos($home_url,'goodao.net')!== false || strpos($home_url,'quanqiusou.cn')!== false){
                        $dir = '/www/wwwroot/'.$ar_home_url[2].'/wp-content/cache/all/'.$tmp_url[3].'/';
                        $file = $dir.'index.html';
                        if(file_exists($file)){
                            unlink($file);
                        }
                        if(is_dir($dir)){
                            rmdir($dir);
                        }
                    }
    	        }
    	        $all_cnt++;
    	    }
    	    if($data && (strpos($home_url,'goodao.net')!== false || strpos($home_url,'quanqiusou.cn')!== false)){
        	    $token = md5('qqs'.date("Y-m-d"));
        	    $del_url = 'https://'.$tmp_url[2].'/del_html.php?token='.$token;
                $res = curl_c($del_url,'post',$data);
    	    }
    	    echo '<div id="setting-error-settings_updated" class="updated settings-error"><p><strong>共提交('.$all_cnt.')个,删除成功('.$cnt.')个。</strong></p></div>';
    	    curl_c($home_url.'wp-admin/admin-ajax.php?action=easy_create_sitemap_xml');
	    }
	}
}

?>
<div class="wrap">
<form id="logins-filter" method="post">
<h2 class="title">删除featured产品链接</h2>
<table class="form-table permalink-structure">
	<tbody>		 

	<tr>
		<th>
			<label>featured产品链接:<br/>(一行一个)</label>
		</th>
		<td>
		    <textarea name="urls" rows="25" cols="130"></textarea>
		</td>
	</tr>

	
	
    </tbody>
</table>

<p class="submit" style="margin-left: 156px"><input type="submit" name="dosubmit" id="submit" class="button button-primary" value="删除"></p>
</form>
</div>

<?php }else{ echo '请登录';}?>