easyiit_cdn.php 21.2 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495
<?php
/**
 * Plugin Name: goodao CDN
 * Plugin URI: #
 * Description: goodao CDN
 * Version: 1.0.00
 * Author: #
 * Author URI: #
 */

define ( 'Easyiit_cdn_FILE', __FILE__);
define ( 'Easyiit_cdn_DIR', rtrim ( plugin_dir_path ( Easyiit_cdn_FILE ), '/' ) );
define ( 'Easyiit_cdn_URL', rtrim ( plugin_dir_url ( Easyiit_cdn_FILE ), '/' ) );

add_action('admin_menu', 'easyiit_cnd_init');

function easyiit_cnd_init() {
    add_menu_page('goodao CDN', 'goodao CDN', 7, 'easyiit_cdn');
    add_submenu_page('easyiit_cdn', '设置', '设置', 7, 'easyiit_cdn', 'easyiit_cdn_setting');
	
}
 
 
function easyiit_cdn_setting() {
$msg = '';
if(isset($_POST['dosubmit'])){
	$cdn_setting = $_POST['setting'];	
  	if($_POST['setting']['dir_name'] == ''){
    	$msg = '<p style="color: red;">设置失败,CDN文件夹名称不能为空</p>';
    }else{
    	update_option( "gd_cdn_setting", $cdn_setting );
    }
}
$cdn_setting = get_option("gd_cdn_setting");
?>
<script src="<?php echo Easyiit_cdn_URL;?>/include/jquery.min.1.9.2.js"></script>
<script src="<?php echo Easyiit_cdn_URL;?>/include/layer/layer.js"></script>
<div class="wrap">
<form id="posts-filter" method="post">
<?php if($msg){ echo $msg;}?>
<h2 class="title">CDN设置</h2>
<table class="form-table permalink-structure">
	<tbody>	
	<tr>
		<th>
			<label>CDN文件夹名称:</label>
		</th>
		<td>
			<input id='dir_name' name="setting[dir_name]" style="width:350px" value="<?php echo $cdn_setting['dir_name'];?>">
		</td>
    </tr>
    <tr>
		<th>
			<label>正式域名:</label>
		</th>
		<td>
			<input id='weburl' name="setting[weburl]" style="width:350px" value="<?php echo $cdn_setting['weburl'];?>">
		</td>
    </tr>
	<tr>
      	<th>
			<label>是否启用CDN:</label>
		</th>
		<td>
			<input type='radio' name="setting[active_cdn]" <?php if($cdn_setting['active_cdn'] == 1) echo 'checked';?> value="1"/>
          	<input type='radio' name="setting[active_cdn]" <?php if($cdn_setting['active_cdn'] == 0) echo 'checked';?> value="0"/>
		</td>
	</tr>
    <tr>
      	<th>
			<label>是否启用pagespeed:</label>
		</th>
		<td>
			<input type='radio' name="setting[active_pagespeed]" <?php if($cdn_setting['active_pagespeed'] == 1) echo 'checked';?> value="1"/>
          	<input type='radio' name="setting[active_pagespeed]" <?php if($cdn_setting['active_pagespeed'] == 0) echo 'checked';?> value="0"/>
		</td>
	</tr>
	
</tbody>
</table>

<p class="submit"><input type="submit" name="dosubmit" id="submit" class="button button-primary" value="保存更改"></p>
</form>
<input type='button' id='change_to_cdn' name="change_to_cdn" value="描述链接更新为CDN链接"><br/><br/>
<input type='button' id='change_to_loc'  name="change_to_loc" value="描述链接更新为本地链接"><br/><br/>
<input type='button' id='update_to_cdn'  name="update_to_cdn" value="更新图片到CDN"><br/><br/>
<input type='button' id='update_style_to_cdn'  name="update_style_to_cdn" value="更新静态文件到CDN"><br/><br/>
<input type='button' id='update_static_as_cdn'  name="update_static_as_cdn" value="更新静态文件路径为CDN"><br/><br/>
<input type='button' id='update_static_as_loc'  name="update_static_as_loc" value="更新静态文件路径为本地路径">
</div>
<script>
$(function(){
  	$("#change_to_cdn").click(function(){
      	var index = layer.load(1,{shade: [0.5, '#393D49']});
		$.get("/wp-admin/admin-ajax.php?action=easycdn_change_url&v=qqs&type=1", function(result){
            if(result == 200){
              	layer.close(index);
              	layer.msg('更新成功');
            }else{
              	layer.close(index);
              	layer.msg('更新失败,请稍后重试');
            }
        });
	});
  	$("#change_to_loc").click(function(){
      	var index = layer.load(1,{shade: [0.5, '#393D49']});
		$.get("/wp-admin/admin-ajax.php?action=easycdn_change_url&v=qqs&type=2", function(result){
            if(result == 200){
              	layer.close(index);
              	layer.msg('更新成功');
            }else{
              	layer.close(index);
              	layer.msg('更新失败,请稍后重试');
            }
        });
	});
  	$("#update_to_cdn").click(function(){
      	var index = layer.load(1,{shade: [0.5, '#393D49']});
		$.get("/wp-admin/admin-ajax.php?action=easycdn_update", function(result){
            if(result == 200){
              	layer.close(index);
              	layer.msg('更新成功');
            }else{
              	layer.close(index);
              	layer.msg('更新失败,请稍后重试');
            }
        });
	});
	$("#update_style_to_cdn").click(function(){
      	var index = layer.load(1,{shade: [0.5, '#393D49']});
		$.get("/wp-admin/admin-ajax.php?action=easycdn_zip", function(result){
            if(result == 200){
              	layer.close(index);
              	layer.msg('更新成功');
            }else{
              	layer.close(index);
              	layer.msg('更新失败,请稍后重试');
            }
        });
	});
	$("#update_static_as_cdn").click(function(){
      	var index = layer.load(1,{shade: [0.5, '#393D49']});
		$.get("/wp-admin/admin-ajax.php?action=easycdn_change_static_url", function(result){
            if(result == 200){
              	layer.close(index);
              	layer.msg('更新成功');
            }else{
              	layer.close(index);
              	layer.msg('更新失败,请稍后重试');
            }
        });
	});
	$("#update_static_as_loc").click(function(){
      	var index = layer.load(1,{shade: [0.5, '#393D49']});
		$.get("/wp-admin/admin-ajax.php?action=easycdn_change_static_url&type=2", function(result){
            if(result == 200){
              	layer.close(index);
              	layer.msg('更新成功');
            }else{
              	layer.close(index);
              	layer.msg('更新失败,请稍后重试');
            }
        });
	});
});
</script>
<div class="clear"></div>
<?php
}
//输出图片链接
add_action( 'wp_ajax_nopriv_easycdn', 'easyiit_cdn' );
add_action( 'wp_ajax_easycdn', 'easyiit_cdn' );
function easyiit_cdn() {
  	if(isset($_GET['v']) && $_GET['v'] == 'qqs'){
        $finish_time = get_option('gd_cdn_finish',true);
      	$cdn_setting = get_option("gd_cdn_setting");
        $dirname = $cdn_setting['dir_name'];
        $path = ABSPATH.'uploads';
        $files = get_all_files($path);
        $home_url = home_url();
        foreach($files as $k=>$file){
            if($finish_time > 1){
                $c_time = filemtime(urldecode($file));
                if($finish_time > $c_time){
                    unset($files[$k]);
                }else{
                    //$files[$k] = str_replace(ABSPATH,$home_url.'/',$file);
                  	$files[$k] = str_replace($path.'/','',$file);
                }
            }else{
                //$files[$k] = str_replace(ABSPATH,$home_url.'/',$file);
				$files[$k] = str_replace($path.'/','',$file);
            }
        }
        $data['dir'] = $dirname;
        $data['domain'] = home_url('/');
        $data['files'] = $files;
        $data['zip'] = array();
        if(file_exists(ABSPATH.'style.zip')){
        	$data['zip'][] = 'style.zip';
        }
        
        print_r(json_encode($data));exit;
    }else{
    	echo '';exit;
    }
}
//压缩style文件夹
add_action( 'wp_ajax_nopriv_easycdn_zip', 'easyiit_cdn_zip' );
add_action( 'wp_ajax_easycdn_zip', 'easyiit_cdn_zip' );
function easyiit_cdn_zip() {
    require_once(__DIR__.'/makezip.class.php');
  	$makeZip = new makezip();
  	//print_r(ABSPATH.'style.zip');exit;
	if(is_dir(ABSPATH.'style/')){
		$res = $makeZip->zip(ABSPATH.'style.zip',ABSPATH.'style/');
		if($res){
			if(strpos(home_url(),'quanqiusou.cn') !== false || strpos(home_url(),'goodao.net') !== false){
				$res_c = file_get_contents("http://imgcn.goodao.net/ajax_downzip.php?w=".urlencode(home_url('/')));
			}else{
				$res_c = file_get_contents("http://img.goodao.net/ajax_downzip.php?w=".urlencode(home_url('/')));
			}
			
			if($res_c == 200){
				echo 200;exit;
			}else{
				echo $res_c;exit;
			}
			
		}else{
			echo 1;exit;
		}
	}else{
		echo 2;exit;
	}
}

//改变header和footer的路径为cdn路径
add_action( 'wp_ajax_nopriv_easycdn_change_static_url', 'easyiit_cdn_change_static_url' );
add_action( 'wp_ajax_easycdn_change_static_url', 'easyiit_cdn_change_static_url' );
function easyiit_cdn_change_static_url() {
	if(isset($_GET['type'])){
		$type = $_GET['type'];
	}else{
		$type = 1;
	}
	$theme_dir = get_stylesheet_directory();
	$cdn_setting = get_option("gd_cdn_setting");
    $dirname = $cdn_setting['dir_name'];
	if($type == 1){
		if(strpos(home_url(),'quanqiusou.cn') !== false || strpos(home_url(),'goodao.net') !== false){
			$data_header = file_get_contents($theme_dir.'/header.php');
			$data_header = str_replace('<?php echo home_url("/"); ?>style/','//cdn.globalso.com/'.$dirname.'/style/',$data_header);
			file_put_contents($theme_dir.'/header.php',$data_header);
			$data_footer = file_get_contents($theme_dir.'/footer.php');
			$data_footer = str_replace('<?php echo home_url("/"); ?>style/','//cdn.globalso.com/'.$dirname.'/style/',$data_footer);
			$data_footer = str_replace('<?php echo home_url("/"); ?>globalso.js','//cdn.globalso.com/globalso.js',$data_footer);
			file_put_contents($theme_dir.'/footer.php',$data_footer);

		}else{
			$data_header = file_get_contents($theme_dir.'/header.php');
			$data_header = str_replace('<?php echo home_url("/"); ?>style/','//cdnus.globalso.com/'.$dirname.'/style/',$data_header);
			file_put_contents($theme_dir.'/header.php',$data_header);
			$data_footer = file_get_contents($theme_dir.'/footer.php');
			$data_footer = str_replace('<?php echo home_url("/"); ?>style/','//cdnus.globalso.com/'.$dirname.'/style/',$data_footer);
			$data_footer = str_replace('<?php echo home_url("/"); ?>globalso.js','//cdnus.globalso.com/globalso.js',$data_footer);
			file_put_contents($theme_dir.'/footer.php',$data_footer);
		}
		echo 200;exit;
	}else{
		if(strpos(home_url(),'quanqiusou.cn') !== false || strpos(home_url(),'goodao.net') !== false){
			$data_header = file_get_contents($theme_dir.'/header.php');
			$data_header = str_replace('//cdncn.goodao.net/'.$dirname.'/style/','<?php echo home_url("/"); ?>style/',$data_header);
			$data_header = str_replace('//cdn.globalso.com/'.$dirname.'/style/','<?php echo home_url("/"); ?>style/',$data_header);
			file_put_contents($theme_dir.'/header.php',$data_header);
			$data_footer = file_get_contents($theme_dir.'/footer.php');
			$data_footer = str_replace('//cdncn.goodao.net/'.$dirname.'/style/','<?php echo home_url("/"); ?>style/',$data_footer);
			$data_footer = str_replace('//cdncn.goodao.net/globalso.js','<?php echo home_url("/"); ?>globalso.js',$data_footer);
			$data_footer = str_replace('//cdn.globalso.com/'.$dirname.'/style/','<?php echo home_url("/"); ?>style/',$data_footer);
			$data_footer = str_replace('//cdn.globalso.com/globalso.js','<?php echo home_url("/"); ?>globalso.js',$data_footer);
			file_put_contents($theme_dir.'/footer.php',$data_footer);
		}else{
			$data_header = file_get_contents($theme_dir.'/header.php');
			$data_header = str_replace('//cdn.goodao.net/'.$dirname.'/style/','<?php echo home_url("/"); ?>style/',$data_header);
			$data_header = str_replace('//cdnus.globalso.com/'.$dirname.'/style/','<?php echo home_url("/"); ?>style/',$data_header);
			file_put_contents($theme_dir.'/header.php',$data_header);
			$data_footer = file_get_contents($theme_dir.'/footer.php');
			$data_footer = str_replace('//cdn.goodao.net/'.$dirname.'/style/','<?php echo home_url("/"); ?>style/',$data_footer);
			$data_footer = str_replace('//cdn.goodao.net/globalso.js','<?php echo home_url("/"); ?>globalso.js',$data_footer);
			$data_footer = str_replace('//cdnus.globalso.com/'.$dirname.'/style/','<?php echo home_url("/"); ?>style/',$data_footer);
			$data_footer = str_replace('//cdnus.globalso.com/globalso.js','<?php echo home_url("/"); ?>globalso.js',$data_footer);
			file_put_contents($theme_dir.'/footer.php',$data_footer);
		}
		
		echo 200;exit;
	}
	
}
function get_all_files($dir){
  $files = array();
    if(@$handle = opendir($dir)) { //注意这里要加一个@,不然会有warning错误提示:)
      while(($file = readdir($handle)) !== false) {
        if($file != ".." && $file != ".") { //排除根目录;
          if(is_dir($dir."/".$file)) { //如果是子文件夹,就进行递归
            	//$files[$file] = get_all_files($dir."/".$file);
          } else { //不然就将文件的名字存入数组
              if((strpos('GeoIPv6.dat',$file) === false) || (strpos('GeoIP.dat',$file) === false)){
                   $files[] = $dir.'/'.urlencode($file);
              }
          }
        }
      }
      closedir($handle);
      return $files;
    }
}
//完成图片同步回调
add_action( 'wp_ajax_nopriv_easycdn_finish', 'easyiit_cdn_callback' );
add_action( 'wp_ajax_easycdn_finish', 'easyiit_cdn_callback' );
function easyiit_cdn_callback() {
  	if(isset($_GET['code']) && $_GET['code'] == 200){
    	update_option( "gd_cdn_finish", time() );
      	echo 200;exit;
    }else{
    	echo '- -!';exit;
    }
}
//更新描述图片地址
add_action( 'wp_ajax_nopriv_easycdn_change_url', 'easyiit_cdn_change_descurl' );
add_action( 'wp_ajax_easycdn_change_url', 'easyiit_cdn_change_descurl' );
function easyiit_cdn_change_descurl() {
  	if(isset($_GET['v']) && $_GET['v'] == 'qqs'){
      	global $wpdb;
      	$cdn_setting = get_option("gd_cdn_setting");
      	if($_GET['type'] == 1){
			if(strpos(home_url(),'quanqiusou.cn') !== false || strpos(home_url(),'goodao.net') !== false){
				$sql = "UPDATE `wp_posts` SET `post_content` = replace( `post_content` , '".home_url('/')."uploads/', '//cdncn.goodao.net/".$cdn_setting['dir_name']."/')";
			}else{
				$sql = "UPDATE `wp_posts` SET `post_content` = replace( `post_content` , '".home_url('/')."uploads/', '//cdn.goodao.net/".$cdn_setting['dir_name']."/')";
			}
        	
          	$wpdb->query($sql);
          	echo 200;exit;
        }else{
			if(strpos(home_url(),'quanqiusou.cn') !== false || strpos(home_url(),'goodao.net') !== false){
				$sql = "UPDATE `wp_posts` SET `post_content` = replace( `post_content` , '//cdncn.goodao.net/".$cdn_setting['dir_name']."/' ,'".home_url('/')."uploads/')";
			}else{
				$sql = "UPDATE `wp_posts` SET `post_content` = replace( `post_content` , '//cdn.goodao.net/".$cdn_setting['dir_name']."/' ,'".home_url('/')."uploads/')";
			}
          	
          	$wpdb->query($sql);
          	echo 200;exit;
        }
    }else{
    	echo 1;exit;
    }
}
//手动更新图片
add_action( 'wp_ajax_nopriv_easycdn_update', 'easyiit_cdn_update' );
add_action( 'wp_ajax_easycdn_update', 'easyiit_cdn_update' );
function easyiit_cdn_update() {
  	$home_url = home_url();
	if(strpos($home_url,'quanqiusou.cn') !== false || strpos($home_url,'goodao.net') !== false){
	    $type = 1;
	    if(isset($_GET['ftype']) && $_GET['ftype']){
	        $type = $_GET['ftype'];
	    }
	    if($type == 1){
	        $data = curl_zgj($home_url.'/wp-admin/admin-ajax.php?action=wpfc_delete_cache');
        }else{
            /* 执行rsync同步cdn start */
            $domain = parse_url(home_url());
            if(strpos($domain['host'],'goodao.net') !== false || strpos($domain['host'],'quanqiusou.cn') !== false){
                $shell_ar = file_get_contents("http://www.quanqiusou.cn/extend_api/api/rsync.txt");
                $shell_ar = explode("\n",$shell_ar);
                foreach ($shell_ar as $v){
                    if($v){
                        $v = trim($v);
                        if(strpos($v,$domain['host']) !== false || strpos($v,str_replace('.','_',$domain['host'])) !== false){
                            $ar_info = explode('|',$v);
                            if($type == 2) {
                                shell_exec('rsync -avu --progress --password-file=/etc/rsync.passwd /www/wwwroot/'.$ar_info[0].'/style/ root@1.116.183.193::cdn-'.$ar_info[2].'-style &> /dev/null &');
                            }elseif($type == 3){
                                shell_exec('rsync -avu --progress --password-file=/etc/rsync.passwd /www/wwwroot/'.$ar_info[0].'/uploads/ root@1.116.183.193::cdn-'.$ar_info[2].'-uploads &> /dev/null &');
                            }
                        }
                    }
                }
            }
            /* 执行rsync同步cdn end */
        }
        
      	echo 200;exit;
	}else{
	    if(strpos($home_url,'https://') !== false){
        	$http = 'https';
        }else{
        	$http = 'http';
        }
      	$ch = curl_init();
        $timeout = 60;
		curl_setopt ($ch, CURLOPT_URL, $http.'://img.goodao.net/ajax_deal_update.php?v=qqs&url='.$home_url);
		curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER,false);//这个是重点。
        curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER,false);// https请求 不验证证书和hosts
        curl_setopt ($ch, CURLOPT_USERAGENT,'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_0) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.56 Safari/535.11');
        curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
        $file_contents = curl_exec($ch);
        curl_close($ch);
      	echo 200;exit;
	}
}

//生成sitemap文件
add_action( 'wp_ajax_nopriv_easy_create_sitemap_xml', 'easy_sitemap_xml' );
add_action( 'wp_ajax_easy_create_sitemap_xml', 'easy_sitemap_xml' );
function easy_sitemap_xml() {
  	$home_url = home_url('/');
  	$home_url_nohttp = str_replace('https:','',str_replace('http:','',$home_url));
  	$home_url_no = home_url();
  	$cdn_setting = get_option("gd_cdn_setting");
  	$weburl_nohttp = str_replace('https:','',str_replace('http:','',$cdn_setting['weburl']));
  	$sitemap_index = curl_zgj($home_url.'sitemap.xml');
  	if(strpos($sitemap_index,'urlset xmlns=') !== false){
  	    if(!is_dir(ABSPATH.'wp-content/cache/all/')){
  	        mkdir(ABSPATH.'wp-content/cache/all/',0755);
  	    }
  	    $sitemap_index_data = $sitemap_index;
  	    if(!file_exists(ABSPATH.'wp-content/cache/all/sitemap.xsl')){
  	        $data_xml_sytle_s = curl_zgj($home_url.'wp-content/plugins/all-in-one-seo-pack/sitemap.xsl');
			file_put_contents(ABSPATH.'wp-content/cache/all/sitemap.xsl',$data_xml_sytle_s);
  	    }
  	    if(!file_exists(get_home_path().'wp-content/cache/all/sitemap_translate.xsl')){
			$data_xml_sytle = curl_zgj($home_url.'wp-content/plugins/prisna-wp-translate/styles/sitemap.xsl');
			file_put_contents(ABSPATH.'wp-content/cache/all/sitemap_translate.xsl',$data_xml_sytle);
		}
		
  	    $sitemap_index_data = str_replace('wp-content/plugins/all-in-one-seo-pack/sitemap.xsl','sitemap.xsl',$sitemap_index_data);
  	    $sitemap_index_data = str_replace($home_url,$cdn_setting['weburl'],$sitemap_index_data);
  	    $sitemap_index_data = str_replace($home_url_nohttp,$weburl_nohttp,$sitemap_index_data);
  	    file_put_contents(ABSPATH.'wp-content/cache/all/sitemap.xml',$sitemap_index_data);
  	    $isMatched = preg_match_all('/<loc>(.*)<\/loc>/', $sitemap_index, $matches);
  	    if(is_array($matches[1])){
  	        foreach ($matches[1] as $v){
  	            $tmp_pa = parse_url($v);
          	    $sitemap_t = curl_zgj($v);
          	    $sitemap_t = str_replace('wp-content/plugins/all-in-one-seo-pack/sitemap.xsl','sitemap.xsl',$sitemap_t);
          	    $sitemap_t = str_replace($home_url_nohttp,$weburl_nohttp,$sitemap_t);
				$sitemap_t = str_replace($home_url,$cdn_setting['weburl'],$sitemap_t);
				$sitemap_t = str_replace($home_url_no.'<',$cdn_setting['weburl'].'<',$sitemap_t);
          	    file_put_contents(ABSPATH.'wp-content/cache/all'.$tmp_pa['path'],$sitemap_t);
          	}
  	    }
  	    $sitemapx_translate = curl_zgj($home_url.'sitemap-translate.xml');
  	    $sitemapx_translate = str_replace($home_url,$cdn_setting['weburl'],$sitemapx_translate);
  	    $sitemapx_translate = str_replace($cdn_setting['weburl'].'wp-content/plugins/prisna-wp-translate/styles/sitemap.xsl',$cdn_setting['weburl'].'sitemap_translate.xsl',$sitemapx_translate);
  	    file_put_contents(ABSPATH.'wp-content/cache/all/sitemap-translate.xml',$sitemapx_translate);
		/* 执行rsync同步到正式站 start */
		$domain = parse_url(home_url());
		if(strpos($domain['host'],'goodao.net') !== false || strpos($domain['host'],'quanqiusou.cn') !== false){
			$shell_ar = file_get_contents("http://www.quanqiusou.cn/extend_api/api/rsync.txt");
			$shell_ar = explode("\n",$shell_ar);
			foreach ($shell_ar as $v){
				if($v){
					$v = trim($v);
					if(strpos($v,$domain['host']) !== false){
						$ar_info = explode('|',$v);
						shell_exec('rsync -avu --progress --password-file=/etc/rsync.passwd /www/wwwroot/'.$ar_info[0].'/wp-content/cache/all/ root@'.$ar_info[1].' &> /dev/null &');
					}
				}
			}
		}
		/* 执行rsync同步到正式站 end */
  	}
  	echo 200;exit;
}


function curl_zgj($url){
	$ch = curl_init($url);
	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, 50);
	curl_setopt($ch, CURLOPT_TIMEOUT, 50);
	curl_setopt($ch, CURLOPT_MAXREDIRS, 50);
	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
	curl_setopt($ch, CURLOPT_SSLVERSION, 'all');
	$content = curl_exec($ch);
	curl_close($ch);
	return $content;
}
?>