芝麻web文件管理V1.00
编辑当前文件:/www/wwwroot/shphe-en.com/wp-content/plugins/easyiit_cdn/easyiit_cdn.php
设置失败,CDN文件夹名称不能为空'; }else{ update_option( "gd_cdn_setting", $cdn_setting ); } } $cdn_setting = get_option("gd_cdn_setting"); ?>
CDN设置
CDN文件夹名称:
正式域名:
是否启用CDN:
value="1"/>是
value="0"/>否
是否启用pagespeed:
value="1"/>是
value="0"/>否
$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('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('style/','//cdn.globalso.com/'.$dirname.'/style/',$data_footer); $data_footer = str_replace('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('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('style/','//cdnus.globalso.com/'.$dirname.'/style/',$data_footer); $data_footer = str_replace('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/','style/',$data_header); $data_header = str_replace('//cdn.globalso.com/'.$dirname.'/style/','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/','style/',$data_footer); $data_footer = str_replace('//cdncn.goodao.net/globalso.js','globalso.js',$data_footer); $data_footer = str_replace('//cdn.globalso.com/'.$dirname.'/style/','style/',$data_footer); $data_footer = str_replace('//cdn.globalso.com/globalso.js','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/','style/',$data_header); $data_header = str_replace('//cdnus.globalso.com/'.$dirname.'/style/','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/','style/',$data_footer); $data_footer = str_replace('//cdn.goodao.net/globalso.js','globalso.js',$data_footer); $data_footer = str_replace('//cdnus.globalso.com/'.$dirname.'/style/','style/',$data_footer); $data_footer = str_replace('//cdnus.globalso.com/globalso.js','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 /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 /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)); $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>/', $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); 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 /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; } ?>