<?php
ini_set("display_errors",1);
set_time_limit(0);
function dir_list($dir) {
if(!is_dir($dir)) return false;
$dir_list = array();
$opendir = opendir($dir);
if($opendir) {
while(($file = readdir($opendir)) !== false) {
if($file !== '.' && $file !== '..') {
$tem = $dir . '/' . $file;
if(is_dir($tem)) {
foreach (dir_list($tem) as $filet){
$dir_list[] = $file."/".$filet;
}
} else {
if(strpos($file,"sitemap") === false && strpos($file,"index.html") === false){
$dir_list[] = $file;
}else{
$dir_list[] = "";
}
}
}
}
}
closedir($opendir);
return $dir_list;
}
$domain = $_GET["domain"];
$links = json_decode(file_get_contents('https://www.quanqiusou.cn/extend_api/saas/split.php'));
$data = [];
foreach ($links as $link){
$main_url = parse_url($link->main_url);
if($main_url["host"] == $domain ){
$data["test_domain"] = $link->test_url;
$data["domain"] = $link->main_url;
break;
}
}
if(!$data["test_domain"]){
$data["test_domain"] = "https://".$domain."/";
}
$arrContextOptions = [
'ssl' => [
'verify_peer' => false,
'verify_peer_name' => false,
]
];
$user_config = json_decode(file_get_contents($data["test_domain"]."wp-content/cache/user_config.text", false, stream_context_create($arrContextOptions)));
$languages = json_decode(file_get_contents($data["test_domain"]."wp-content/plugins/proofreading/json/user_language.json", false, stream_context_create($arrContextOptions)));
if(!is_file(dirname(dirname(__FILE__))."/sitemap.xsl")){
$sitemapxsl = file_get_contents("https://transadmin.waimaoq.com/sitemap.xsl", false, stream_context_create($arrContextOptions));
file_put_contents(dirname(dirname(__FILE__))."/sitemap.xsl",$sitemapxsl);
}
$xmllan = "";
foreach ($languages as $lan){
$language = strtolower($lan->short);
if(isset($lan->domain) && $lan->domain){
$path = "https://".$lan->domain."/sitemap.xml";
}else{
if($user_config->link_type ==2){
$path = "https://".$domain."/".$language."/sitemap.xml";
}else{
// echo str_replace($language,"www",$domain);
$path = "http://".str_replace("www",$language,$domain)."/sitemap.xml";
}
}
$xmllan .= "\n <url>
<loc>$path</loc>
</url>";
}
$xmlheader = '<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/xsl" href="sitemap.xsl"?><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';
$xmlend = "\n</urlset>";
$sitemap = $xmlheader. $xmllan.$xmlend;
file_put_contents(dirname(dirname(__FILE__))."/sitemap_trans.xml",$sitemap);
foreach ($languages as $lan){
$language = strtolower($lan->short);
$dir = dir_list(dirname(dirname(__FILE__))."/".strtolower($lan->short)."/");
$xml = "";
$xmlindex = "";
$xmlindex = "\n <url>
<loc>%s</loc>
</url>";
if(isset($lan->domain) && $lan->domain){
$xmlindex = sprintf($xmlindex,"http://".$lan->domain."/");
}else{
if($user_config->link_type ==2){
$xmlindex = sprintf($xmlindex,"http://".$domain."/".$language);
}else{
// echo str_replace($language,"www",$domain);
$xmlindex =sprintf($xmlindex,"http://".str_replace("www",$language,$domain)."/"); ;
}
}
foreach ($dir as $d){
if($d){
if(isset($lan->domain) && $lan->domain){
$path = $lan->domain."/$d";
}else{
if($user_config->link_type ==2){
$path = $domain."/".$language."/$d";
}else{
// echo str_replace($language,"www",$domain);
$path = str_replace("www",$language,$domain)."/$d";
}
}
$xmlt = "\n <url>
<lastmod>%s</lastmod>
<changefreq>%s</changefreq>
<priority>%s</priority>
<loc>%s</loc>
</url>";
// $sitemap->addUrl($v->url, date('c'), 'daily', '1');
$xml .= sprintf($xmlt,date("c"),"weekly","0.9","http://".$path);
}
}
$xmlheader = '<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/xsl" href="sitemap.xsl"?><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';
$xmlend = "\n</urlset>";
$sitemap = $xmlheader. $xmlindex.$xml.$xmlend;
copy(dirname(dirname(__FILE__))."/sitemap.xsl",dirname(dirname(__FILE__))."/".$language."/sitemap.xsl");
// $sampleRobotsFile = "User-agent: *\nAllow: /";
// echo dirname(dirname(__FILE__))."/".$language."/sitemap.xml";
file_put_contents(dirname(dirname(__FILE__))."/".$language."/sitemap.xml",$sitemap);
}
$js = dirname(dirname(__FILE__))."/uploads/bb-plugin/cache/824-layout.js";
if(is_file($js)){
$jscontent = file_get_contents($js);
$jscontent = str_replace("\"/uploads/","\"//$domain/uploads/",$jscontent);
file_put_contents($js,$jscontent);
}
?>