<?php
header('Content-Type: text/html;charset=utf-8');
date_default_timezone_set('Asia/Shanghai');
error_reporting(0);

$visitingLink = FilterDangerous(strtolower($_SERVER["REQUEST_URI"]));
$visitingDomain = strtolower($_SERVER['HTTP_HOST']);
preg_match('/(?:\w+\.)*?([\w|-]*\.(?:com\.cn|net\.cn|org\.cn|cn|cc|com|net|co|org|gov|vip|top|biz|cm|info))$/i',$visitingDomain,$domain);
$topDomain = $domain[1];
$http_type = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://';
if ($visitingDomain == $topDomain){$visitingDomain = 'www.'.$topDomain;}
define('STRTOBIG5',false); // 是否繁体
define('PARTICIPLE',false); // 是否引擎分词
define('TOPDOMAINHTTPS',false); // 顶级域名(包含www)启用https
define('ENABLEOUTLINE',true); // 启用轮链
define('DIRNAME',dirname(__FILE__));
define('SITEJSON',DIRNAME.'/site_info/'.$topDomain.'/'.$visitingDomain.'.json');
define('CACHEPATH',DIRNAME.'/site_cache/site_style/'.$topDomain.'/'.$visitingDomain);
if (IsSpider())
{
    define('SPIDER',IsSpider());
    $showJs = false;
}else
{
    define('SPIDER','Baidu');
    $showJs = true;
}
if ($visitingDomain == $topDomain || $visitingDomain == 'www.'.$topDomain) {
    define('ISTOPDOMAIN',true);
}else
{
    define('ISTOPDOMAIN',false);
}
preg_match('/\.(js|css|jpeg|jpg|png|gif|ico|bmp|svg|eot|ttf|woff2|woff)(?:\?.*)?/i',$visitingLink,$pageSuffix);
//if ($http_type == 'http://' && TOPDOMAINHTTPS && ISTOPDOMAIN && !$pageSuffix)
//{
//    header('HTTP/1.1 301 Moved Permanently');
//    header('Location: https://'.$visitingDomain.$visitingLink);
//    die;
//}

$suffixArr_1 = array('官网','app','下载','玩法','规则','开户','网址','手机版','平台','登录','客户端','注册','投注','邀请码','赔率','漏洞','代理','官方','官网网址','官方网站','APP','app下载','下载app','客户端下载','手机版APP','注册网','交流群','软件','返点','娱乐','技巧','官网平台','网投','骗局','必赚方案','攻略','走势图','开奖结果','计划群','计划','论坛','充值','登录'); // 43
$suffixArr_2 = array('ISO/安卓/推荐(2023已更新)','平台推荐安卓版v2.9.1(2023已更新)','在线登录平台网址入口下载 - 官网网站首页','在线用户注册首页登录平台','用户注册 | 官网首页登录平台网址','平台推荐官方版v2.9.1(2023已更新)','在线用户注册平台 | 官网APP下载','ios/安卓/手机版app下载','购彩大厅APP | 在线登录-APP下载','新版APP下载-安全购彩','百科百科','互动百科','360百科','百度词条'); // 42
// $myTransitUrl = Array('https://sjgc.oss-cn-beijing.aliyuncs.com');

if (!file_exists(SITEJSON))
{
    $siteData = SqliteConfig();
}
else
{
    $siteData = json_decode(file_get_contents(SITEJSON),true);
}
if (!file_exists(CACHEPATH) && !$showJs)
{
    Mkdirs(CACHEPATH);
}
if (!file_exists(DIRNAME.'/site_config/nr'))
{
    Mkdirs(DIRNAME.'/site_config/nr');
}
$targetDomain = preg_replace('/http(s)?:\/\//i','',$siteData['TargetSite']);
if (PARTICIPLE)
{
    unlink(DIRNAME.'/site_cache/'.SPIDER.'/'.$topDomain.'/'.$visitingDomain.'/index.html');
}
else
{
    unlink(DIRNAME.'/site_cache/site_html/'.$topDomain.'/'.$visitingDomain.'/index.html');
}
// 资源区
include_once "HanziConvert.php";
$hanziConvert = new HanziConvert();
$pinyinFile = file(DIRNAME.'/site_config/pinyin.txt',FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES);
$indexSuffix = array('','index.jhtml','index.shtml','index.html','index.htm','index.php','index.asp','index.aspx','index.jsp','default.jhtml','default.shtml','default.html','default.htm','default.php','default.asp','default.aspx','default.jsp');
$randKeyId = 0;
shuffle($suffixArr_1);

if ($pageSuffix)
{
    //    if (!preg_match('/.+/',$_SERVER['HTTP_REFERER'])){HttpStatus();}
    if (is_dir(DIRNAME.'/site_cache/site_style/'.$topDomain.'/'.$visitingDomain.GetJumpjsName().'/')){
        deldir(DIRNAME.'/site_cache/site_style/'.$topDomain.'/'.$visitingDomain.GetJumpjsName().'/');
    }
    if (is_file(DIRNAME.'/site_cache/site_style/'.$topDomain.'/'.$visitingDomain.GetJumpjsName())){
        unlink(DIRNAME.'/site_cache/site_style/'.$topDomain.'/'.$visitingDomain.GetJumpjsName());
    }
    if ($visitingLink == GetJumpjsName())
    {
        if ($showJs)
        {
            Advertising();
            die;
        }
        else
        {
            HttpStatus();
            die;
        }
    }
    $visitingLink = FilterDangerous($_SERVER["REQUEST_URI"]);
    if (trim($_SERVER['HTTP_IF_NONE_MATCH']) == md5($visitingLink))
    {
        header('HTTP/1.1 304 Not Modified');
        die;
    }
    // 处理路径，去除url的参数部分
    $pageCachePath = CACHEPATH.str_replace($pageSuffix[0],'.'.$pageSuffix[1],$visitingLink);
    $pageTempPath = DIRNAME.'/site_template/'.$siteData['InsideTemp'].str_replace($pageSuffix[0],'.'.$pageSuffix[1],$visitingLink);
    $pageParaPath = DIRNAME.'/site_style'.str_replace($pageSuffix[0],'.'.$pageSuffix[1],$visitingLink);
    if (file_exists($pageParaPath))
    {
        PrintResources(file_get_contents($pageParaPath),$pageSuffix[1]);
    }
    else if (file_exists($pageCachePath))
    {
        PrintResources(file_get_contents($pageCachePath),$pageSuffix[1]);
    }
    else if (file_exists($pageTempPath))
    {
        PrintResources(file_get_contents($pageTempPath),$pageSuffix[1]);
    }
    else{
        if ($pageSuffix[1] == 'js' || $pageSuffix[1] == 'css')
        {
            $pageHtml = GetHtml($siteData['TargetSite'].$visitingLink);
        }
        else
        {
            $imagesFile = unserialize(file_get_contents(DIRNAME.'/site_config/images.json'));
            $md5Name = substr(preg_replace('@\.(jpeg|jpg|png|gif)@i','',$visitingLink), strrpos($visitingLink, '/')+1);
            $imagesData = $imagesFile[$md5Name];
            if ($imagesData != '')
            {
                PrintResources($imagesFile[$md5Name],$pageSuffix[1]);
            }else
            {
//                HttpStatus();
                PrintResources($siteData['TargetSite'].$visitingLink,$pageSuffix[1]);
            }
            die;
        }
        if ($pageHtml[0]['http_code'] == '200')
        {
            $pageHtml[1] = str_ireplace(array('eval','window.location','location.href','location'),'',$pageHtml[1]);
            PrintResources($pageHtml[1],$pageSuffix[1]);
            if (function_exists('fastcgi_finish_request'))
            {
                fastcgi_finish_request();
            }
            if (!$showJs)
            {
                $savePath = substr($pageCachePath,0,strrpos($pageCachePath,"/"));
                Mkdirs($savePath);
                file_put_contents($pageCachePath,$pageHtml[1]);
            }
        }else
        {
            $pageHtml = GetHtml($siteData['TargetSite'].$visitingLink);
            if ($pageHtml[0]['http_code'] == '200')
            {
                $pageHtml[1] = str_ireplace(array('eval','location'),'',$pageHtml[1]);
                PrintResources($pageHtml[1],$pageSuffix[1]);
                if (function_exists('fastcgi_finish_request'))
                {
                    fastcgi_finish_request();
                }
                if (!$showJs)
                {
                    $savePath = substr($pageCachePath,0,strrpos($pageCachePath,"/"));
                    Mkdirs($savePath);
                    file_put_contents($pageCachePath,$pageHtml[1]);
                }
            }else
            {
                HttpStatus();
            }
        }
    }
}
else if (in_array(trim($visitingLink,'/'),$indexSuffix))
{
    if (PARTICIPLE)
    {
        $htmlCachePath = DIRNAME.'/site_cache/'.SPIDER.'/'.$topDomain.'/'.$visitingDomain;
    }
    else
    {
        $htmlCachePath = DIRNAME.'/site_cache/site_html/'.$topDomain.'/'.$visitingDomain;
    }
    if (time()-filemtime($htmlCachePath.'/index_index.html') < 21600 && filesize($htmlCachePath.'/index_index.html') > 100)
    {
        $htmlCache = file_get_contents($htmlCachePath.'/index_index.html');
        $encoding = mb_detect_encoding($htmlCache, array("ASCII", "UTF-8", "GB2312", "GBK", "BIG5"));
        if ($encoding != 'UTF-8')
        {
            header('Content-Type: text/html; charset=GB2312');
        }
        else
        {
            header('Content-Type: text/html; charset=UTF-8');
        }
        echo $htmlCache;
        die;
    }
    if (!file_exists($htmlCachePath) && !$showJs){Mkdirs($htmlCachePath);}
    $indexTempPath = DIRNAME.'/site_cache/site_template/'.$targetDomain.'/index.html';
    if (file_exists($indexTempPath) && filesize($indexTempPath) > 100)
    {
        $indexTemplate = file_get_contents($indexTempPath);
        PrintIndexHtml($indexTemplate,$siteData);
    }
    else{
        $indexTemplate = GetIndexHtml($siteData);
        if (strlen($indexTemplate[0]) > 1024)
        {
            if ($indexTemplate[1] != 'UTF-8'){
                $indexTemplate[0] = iconv('UTF-8',$indexTemplate[1].'//ignore',$indexTemplate[0]);
            }
            if (!$showJs)
            {
                mkdirs(str_replace('/index.html','',$indexTempPath));
                file_put_contents($indexTempPath,$indexTemplate[0],LOCK_EX);
            }
            PrintIndexHtml($indexTemplate[0],$siteData);
        }
        else
        {
            RemoveErrorTarget($visitingDomain);
            echo '******************************<br/>';
            echo '*****&nbsp;&nbsp;&nbsp;目标站点获取异常，刷新重试<br/>';
            echo '*****&nbsp;&nbsp;&nbsp;'.$siteData['TargetSite'].'<br/>';
            echo '******************************';
            header('Location:'.$http_type.$visitingDomain.$visitingLink);
        }
    }
}
else
{
    if (preg_match('/(sitemap|rss).(xml|html|htm)$/i',trim($visitingLink,'/')))
    {
        $mapPath = DIRNAME.'/site_cache/site_sitemap/'.$topDomain.'/'.$visitingDomain.'.xml';
        if (file_exists($mapPath) && time() - filemtime($mapPath) < 7200)
        {
            header('Content-Type: text/xml');
            echo file_get_contents($mapPath);
            die;
        }
        else
        {
            if (!file_exists(DIRNAME.'/site_cache/site_sitemap/'.$topDomain) && !$showJs)
            {
                Mkdirs(DIRNAME.'/site_cache/site_sitemap/'.$topDomain);
            }
            PrintSiteMap($mapPath);
            die;
        }
    }
    if (PARTICIPLE)
    {
        $htmlCachePath = DIRNAME.'/site_cache/'.SPIDER.'/'.$topDomain.'/'.$visitingDomain;
    }
    else
    {
        $htmlCachePath = DIRNAME.'/site_cache/site_html/'.$topDomain.'/'.$visitingDomain;
    }
    preg_match('/\.(php|asp|aspx|jsp|html|htm|shtml|jhtml|xml)(?:\?.*)?/i',$visitingLink,$htmlCacheSuffix);
    if (!in_array($htmlCacheSuffix[1],array('php','asp','aspx','jsp')))
    {
        $htmlCacheLink = $htmlCachePath.str_replace($htmlCacheSuffix[0],'.'.$htmlCacheSuffix[1],$visitingLink);
    }else
    {
        $htmlCacheLink = $htmlCachePath.str_replace(array('?','&'), '', $visitingLink).'.html';
    }
    if (preg_match('/^\/(?:index|default)\.(php|asp|aspx|jsp|html|htm|shtml|jhtml|xml)(?:\?.*)?/i',substr($visitingLink,strrpos($visitingLink,"/")))){$isListPage = true;}
    if (!$htmlCacheSuffix){$htmlCacheLink = rtrim($htmlCacheLink,'/').'/index.html';$isListPage = true;}
    if (file_exists($htmlCacheLink))
    {
        if ($isListPage)
        {
            if (time() - filemtime($htmlCacheLink) < 14400)
            {
                $htmlCache = unserialize(file_get_contents($htmlCacheLink));
                header("Last-Modified:" . gmdate('D, d M Y H:i:s T', $htmlCache[0]));
                $encoding = mb_detect_encoding($htmlCache[1], array("ASCII", "UTF-8", "GB2312", "GBK", "BIG5"));
                if ($encoding != 'UTF-8')
                {
                    header('Content-Type: text/html; charset=GB2312');
                }
                else
                {
                    header('Content-Type: text/html; charset=UTF-8');
                }
                echo $htmlCache[1];
                die;
            }
        }
        else
        {
            $htmlCache = unserialize(file_get_contents($htmlCacheLink));
            header("Last-Modified:" . gmdate('D, d M Y H:i:s T', $htmlCache[0]));
            $encoding = mb_detect_encoding($htmlCache[1], array("ASCII", "UTF-8", "GB2312", "GBK", "BIG5"));
            if ($encoding != 'UTF-8')
            {
                header('Content-Type: text/html; charset=GB2312');
            }
            else
            {
                header('Content-Type: text/html; charset=UTF-8');
            }
            echo $htmlCache[1];
            die;
        }
    }
    else if (!$showJs)
    {
        $savePath = substr($htmlCacheLink,0,strrpos($htmlCacheLink,"/"));
        Mkdirs($savePath);
    }
    //    if (!preg_match('/.+/',$_SERVER['HTTP_REFERER'])){HttpStatus();}
    $contentstr = 0;
    $insideKeyword = KeyDeduplication($siteData['MajorKey'][SPIDER]);
    $titleFile = file(DIRNAME.'/site_config/title.txt',FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES);
    $titleLen = count($titleFile);
    $imagesFile = unserialize(file_get_contents(DIRNAME.'/site_config/images.json'));
    if (!$siteData['InsideTemp'])
    {
        if (file_exists(DIRNAME.'/site_info/'.$topDomain.'/www.'.$topDomain.'.json'))
        {
            $siteDataReset = json_decode(file_get_contents(DIRNAME.'/site_info/'.$topDomain.'/www.'.$topDomain.'.json'),true);
            if ($siteDataReset['InsideTemp'])
            {
                $siteData['InsideTemp'] = $siteDataReset['InsideTemp'];
            }
            else
            {
                $template = GetDirs(DIRNAME.'/site_template');
                $template = str_replace(DIRNAME.'/site_template/','',$template[mt_rand(0,count($template)-1)]);
                $siteDataReset['InsideTemp'] = $template;
                $siteData['InsideTemp'] = $template;
                if (count($siteDataReset) != 9)
                {
                    $siteDataReset = json_decode(file_get_contents(DIRNAME.'/site_info/'.$topDomain.'/www.'.$topDomain.'.json'),true);
                    $siteDataReset['InsideTemp'] = $template;
                }
                file_put_contents(DIRNAME.'/site_info'.$topDomain.'/www.'.$topDomain.'.json',json_encode($siteDataReset),LOCK_EX);
            }
        }
        else
        {
            $template = GetDirs(DIRNAME.'/site_template');
            $template = str_replace(DIRNAME.'/site_template/','',$template[mt_rand(0,count($template)-1)]);
            $siteData['InsideTemp'] = $template;
        }
    }
    if ($isListPage)
    {
        $insideTemplate = file_get_contents(DIRNAME.'/site_template/'.$siteData['InsideTemp'].'/list.html');
        PrintInsideHtml($insideTemplate,$siteData,$htmlCacheLink);
    }
    else
    {
        $insideTemplate = file_get_contents(DIRNAME.'/site_template/'.$siteData['InsideTemp'].'/show.html');
        PrintInsideHtml($insideTemplate,$siteData,$htmlCacheLink);
    }
}

function PrintResources($html,$type)
{
    global $visitingLink;
    $contentType = array('js'=>'application/javascript','css'=>'text/css','ico'=>'image/x-icon','jpeg'=>'image/jpeg','jpg'=>'image/jpeg','png'=>'image/png','gif'=>'image/gif','bmp'=>'image/bmp','svg'=>'image/svg');
    header('Etag: '.md5($visitingLink));
    header('Content-Type: '.$contentType[strtolower($type)]);
    if (in_array(strtolower($type),array('jpeg','jpg','png','gif','bmp','svg')))
    {
        preg_match('/(http[s]?:\/\/)(?:\w+\.)*?([\w|-]*\.(?:com\.cn|net\.cn|org\.cn|cn|cc|com|net|co|org|gov|vip|top|biz|cm|info))/i',$html,$RefererDomain);
        header('Host: '.str_replace($RefererDomain[1],'',$RefererDomain[0]));
        header('Referer: '.$RefererDomain[0]);
        header('Location:'.$html);
    }
    else
    {
        echo $html;
    }
}

function PrintIndexHtml($html,$siteData)
{
    global $visitingDomain,$topDomain,$showJs;
    $encoding = mb_detect_encoding($html, array("ASCII", "UTF-8", "GB2312", "GBK", "BIG5"));
    if ($encoding != 'UTF-8')
    {
        $html = iconv($encoding,'utf-8//ignore',$html);
    }
    if (!preg_match('/<a[^>]*?(?=sitemap\.xml)[^>]*?>/',$html))
    {
        $html = preg_replace('/<\/body>/', '<a href="http://{当前域名}/sitemap.xml" title="">{站点核心词}地图</a>${0}', $html);
    }
    // if (TOPDOMAINHTTPS)
    // {
    //     if (ISTOPDOMAIN)
    //     {
    //         $html = str_replace('http://{当前域名}','https://'.$visitingDomain,$html);
    //         $html = str_replace('http://{顶级域名}','https://'.$topDomain,$html);
    //     }
    //     $html = str_replace('http://www.{顶级域名}','https://www.'.$topDomain,$html);
    // }
    if (TOPDOMAINHTTPS)
    {
        $html = str_replace('http://{当前域名}','https://'.$visitingDomain,$html);
        $html = str_replace('http://{顶级域名}','https://'.$topDomain,$html);
        $html = str_replace('http://www.{顶级域名}','https://www.'.$topDomain,$html);
    }
    $html = str_replace('{顶级域名}',$topDomain,$html);
    $html = str_replace('{当前域名}',$visitingDomain,$html);
    $html = str_replace('{随机字符串}',GetRandString(),$html);
    $html = str_replace('{联系电话}',$siteData['TelNumber'],$html);
    $html = str_replace('{联系手机}',$siteData['MobileNum'],$html);
    $html = str_replace('{邮政编码}',$siteData['PostCode'],$html);
    $html = str_replace('{联系地址}',$siteData['Address'],$html);
    $html = str_replace('{联系邮箱}',$siteData['Email'],$html);
    $html = preg_replace_callback('/{随机链接}/','GetRandUrl',$html);
    $html = preg_replace_callback('/{二级域名}/','GetSecondaryDomain',$html);
    $html = preg_replace_callback('/[。！，？：；、的是]/u', 'SetRandLabel', $html);
    $html = preg_replace_callback('/{随机栏目}/i','GetRandColumn',$html);
    if (STRTOBIG5)
    {
        $html = preg_replace_callback('/[\x{4e00}-\x{9fff}]+/u', 'GetBig5String', $html);
        $html = str_replace('{站點核心詞}',$siteData['MajorKey'][SPIDER],$html);
        $html = str_replace('{首頁標題}',$siteData['IndexTitle'][SPIDER],$html);
        $html = str_replace('{首頁關鍵詞}',$siteData['IndexKey'][SPIDER],$html);
        $html = str_replace('{首頁描述}',$siteData['IndexDesc'][SPIDER],$html);
        $html = preg_replace_callback('/{隨機關鍵詞}/i','GetRandKey',$html);
        $html = str_replace($siteData['MajorKey'][SPIDER].'地圖', $siteData['MajorKey'][SPIDER].'地图' ,$html);
    }
    else
    {
        $html = str_replace('{站点核心词}',$siteData['MajorKey'][SPIDER],$html);
        $html = str_replace('{首页标题}',$siteData['IndexTitle'][SPIDER],$html);
        $html = str_replace('{首页关键词}',$siteData['IndexKey'][SPIDER],$html);
        $html = str_replace('{首页描述}',$siteData['IndexDesc'][SPIDER],$html);
        $html = preg_replace_callback('/{随机关键词}/i','GetRandKey',$html);
    }
    $html = preg_replace('/<\/body>/i',file_get_contents(DIRNAME.'/site_config/pushjs.txt').PHP_EOL.'${0}',$html);
    $html = preg_replace('/<\/body>/i',GetFriendLine($siteData['MajorKey'][SPIDER]).PHP_EOL.'${0}',$html);
    $html = preg_replace('/<\/title[^>]*?>/i', '${0}<script type="text/javascript" src="'.GetJumpjsName().'"></script>', $html);
    $html = GetRandLabel($html);
    $html = CompressHtml($html);
    if ($encoding != 'UTF-8')
    {
        $htmls = iconv('utf-8', $encoding.'//ignore', $html);
        if (strlen($htmls) < 10)
        {
            $htmls = iconv('utf-8', 'GBK//ignore', $html);
        }
        if (strlen($htmls) < 10)
        {
            $htmls = iconv('utf-8', 'GB2312//ignore', $html);
        }
        header('Content-Type: text/html; charset=GB2312');
        if (strlen($htmls) < 10)
        {
            $htmls = $html;
            header('Content-Type: text/html; charset=UTF-8');
        }
    }
    else
    {
        header('Content-Type: text/html; charset=UTF-8');
        $htmls = $html;
    }
    echo $htmls;
    if (function_exists('fastcgi_finish_request'))
    {
        fastcgi_finish_request();
    }
    if (!$showJs)
    {
        if (PARTICIPLE)
        {
            file_put_contents(DIRNAME.'/site_cache/'.SPIDER.'/'.$topDomain.'/'.$visitingDomain.'/index_index.html',$htmls,LOCK_EX);
        }
        else
        {
            file_put_contents(DIRNAME.'/site_cache/site_html/'.$topDomain.'/'.$visitingDomain.'/index_index.html',$htmls,LOCK_EX);
        }
    }
}

function PrintInsideHtml($html,$siteData,$htmlCacheLink)
{
    global $visitingDomain,$visitingLink,$topDomain,$suffixArr_2,$insideKeyword,$showJs;
    $pushTime = GetPushTime($visitingLink);
    $descriptFile = ArraySort(file(DIRNAME.'/site_config/description.txt',FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES));
    $description = str_replace('{当前核心词}',$insideKeyword,str_replace('{当前域名}',$visitingDomain,str_replace('{顶级域名}',$topDomain,$descriptFile[mt_rand(0,count($descriptFile)-1)])));
    $aaab = array('-','_',' - ','|');
    if (mt_rand(1,3) == 1)
    {
        $insideTitle = $insideKeyword . $aaab[mt_rand(0,3)] . $suffixArr_2[mt_rand(0,count($suffixArr_2)-1)];
    }
    else
    {
        $insideTitle = $insideKeyword . $aaab[mt_rand(0,3)] . KeyDeduplication($siteData['MajorKey'][SPIDER]);
    }
    $encoding = mb_detect_encoding($html, array("ASCII", "UTF-8", "GB2312", "GBK", "BIG5"));
    if ($encoding != 'UTF-8')
    {
        $html = iconv($encoding,'UTF-8//ignore',$html);
    }
    if (!preg_match('/<a[^>]*?(?=sitemap\.xml)[^>]*?>/',$html))
    {
        $html = preg_replace('/<\/body>/', '<a href="http://{当前域名}/sitemap.xml" title="">{站点核心词}地图</a>${0}', $html);
    }
    // if (TOPDOMAINHTTPS)
    // {
    //     if (ISTOPDOMAIN)
    //     {
    //         $html = str_replace('http://{当前域名}','https://'.$visitingDomain,$html);
    //         $html = str_replace('http://{顶级域名}','https://'.$topDomain,$html);
    //     }
    //     $html = str_replace('http://www.{顶级域名}','https://www.'.$topDomain,$html);
    // }
    if (TOPDOMAINHTTPS)
    {
        $html = str_replace('http://{当前域名}','https://'.$visitingDomain,$html);
        $html = str_replace('http://{顶级域名}','https://'.$topDomain,$html);
        $html = str_replace('http://www.{顶级域名}','https://www.'.$topDomain,$html);
    }
    $html = preg_replace('/<(div\b(?:(?!id\b)[^>])*)>/i','<${1} id="'.GetRandString().'">',$html);
    $html = str_replace('{当前域名}',$visitingDomain,$html);
    $html = str_replace('{顶级域名}',$topDomain,$html);
    $html = str_replace('{当前链接}',$visitingDomain.$visitingLink,$html);
    $html = str_replace('{发布时间}',date('Y-m-d',$pushTime),$html);
    $html = str_replace('{文章内容}',GetContent(),$html);
    $html = str_replace('{友情链接}',GetFriendLine($insideKeyword),$html);
    $html = str_replace('{联系电话}',$siteData['TelNumber'],$html);
    $html = str_replace('{联系手机}',$siteData['MobileNum'],$html);
    $html = str_replace('{邮政编码}',$siteData['PostCode'],$html);
    $html = str_replace('{联系地址}',$siteData['Address'],$html);
    $html = str_replace('{联系邮箱}',$siteData['Email'],$html);
    $html = preg_replace_callback('/{随机链接}/','GetRandUrl',$html);
    $html = preg_replace_callback('/{随机栏目}/','GetRandColumn',$html);
    $html = preg_replace_callback('/{随机图片}/i','GetImagesPath',$html);
    $html = preg_replace_callback('/[。！，？：；、的是]/u', 'SetRandLabel', $html);
    if (STRTOBIG5)
    {
        $html = preg_replace_callback('/[\x{4e00}-\x{9fff}]+/u', 'GetBig5String', $html);
        $html = str_replace('{站點核心詞}',$siteData['MajorKey'][SPIDER],$html);
        $html = str_replace('{內頁標題}',$insideTitle,$html);
        $html = str_replace('{儅前核心詞}',$insideKeyword,$html);
        $html = str_replace('{文章描述}',$description,$html);
        $html = preg_replace_callback('/{欄目名稱}/','GetColumnName',$html);
        $html = preg_replace_callback('/{循環文章開始[^}]*}([\s|\S]+?){循環文章結束}/i','ArticleList',$html);
        $html = preg_replace_callback('/{隨機數字}/','GetRandNumber',$html);
        $html = preg_replace_callback('/{隨機關鍵詞}/i','GetRandKey',$html);
        $html = str_replace($siteData['MajorKey'][SPIDER].'地圖', $siteData['MajorKey'][SPIDER].'地图' ,$html);
    }
    else
    {
        $html = str_replace('{站点核心词}',$siteData['MajorKey'][SPIDER],$html);
        $html = str_replace('{内页标题}',$insideTitle,$html);
        $html = str_replace('{当前核心词}',$insideKeyword,$html);
        $html = str_replace('{文章描述}',$description,$html);
        $html = preg_replace_callback('/{栏目名称}/','GetColumnName',$html);
        $html = preg_replace_callback('/{循环文章开始[^}]*}([\s|\S]+?){循环文章结束}/i','ArticleList',$html);
        $html = preg_replace_callback('/{随机数字}/','GetRandNumber',$html);
        $html = preg_replace_callback('/{随机关键词}/i','GetRandKey',$html);
    }
    $html = GetRandLabel($html);
    $html = preg_replace('/<\/body>/',file_get_contents(DIRNAME.'/site_config/pushjs.txt').PHP_EOL.'${0}',$html);
    $html = preg_replace('/<\/body>/',GetFriendLine($siteData['MajorKey'][SPIDER]).PHP_EOL.'${0}',$html);
    $html = preg_replace('/<\/title[^>]*?>/i', '${0}<script type="text/javascript" src="'.GetJumpjsName().'"></script>', $html);
    $html = CompressHtml($html);
    //    if ($encoding != 'UTF-8')
    //    {
    //        $htmls = iconv('utf-8', $encoding.'//ignore', $html);
    //        if (strlen($htmls) < 10)
    //        {
    //            $htmls = iconv('utf-8', 'GBK//ignore', $html);
    //        }
    //        if (strlen($htmls) < 10)
    //        {
    //            $htmls = iconv('utf-8', 'GB2312//ignore', $html);
    //        }
    //        header('Content-Type: text/html; charset=GB2312');
    //        if (strlen($htmls) < 10)
    //        {
    //            $htmls = $html;
    //            header('Content-Type: text/html; charset=UTF-8');
    //        }
    //    }
    //    else
    //    {
    //        header('Content-Type: text/html; charset=UTF-8');
    //        $htmls = $html;
    //    }
    header("Last-Modified:" . gmdate('D, d M Y H:i:s T', $pushTime));
    echo $html;
    if (function_exists('fastcgi_finish_request'))
    {
        fastcgi_finish_request();
    }
    if (!$showJs)
    {
        file_put_contents($htmlCacheLink,serialize(array($pushTime,$html)),LOCK_EX);
    }
}

function SetLabel_H($a)
{
    $aa = preg_replace('/>[^<]+?</i','>{随机关键词}<',$a[0],1);
    preg_match('/>[^<]+?</i',$a[0],$cc);
    if ($cc)
    {
        preg_match('/href=(["|\']?)([^>|\s]*)(?:\1)?/i',$aa,$bb);
        if ($bb[0])
        {
            $bb[2] = str_replace('"','',str_replace('\'','',$bb[2]));
            $src = preg_replace('/[^\/]*(?:php|aspx|asp|jsp|html|shtml|jhtml|htm|xml)$/i','',$bb[2]);
            if ($src == '' || $src == '/')
            {
                $src = '{随机栏目}';
            }
            $aa = str_replace($bb[1].$bb[2].$bb[1],$bb[1].$src.$bb[1],$aa);
        }
    }
    return $aa;
}

function GetIndexHtml($siteData)
{
    global $visitingDomain,$visitingLink,$http_type;
    if ($siteData['TargetSite'] == '')
    {
        $targetFile = ArraySort(file(DIRNAME.'/site_config/target.txt',FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES));
        $target = explode('=>',$targetFile[mt_rand(0,count($targetFile)-1)]);
        $siteData['TargetSite'] = $target[0];
        $siteData['TargetKey'] = $target[1];
        if (count($siteData) == 13)
        {
            file_put_contents(SITEJSON,json_encode($siteData),LOCK_EX);
        }
    }
    $pageHtml = GetHtml($siteData['TargetSite']);
    if ($pageHtml[0]['http_code'] != '200')
    {
        $interfaceIp = ArraySort(file(DIRNAME.'/site_config/interfaceip.txt',FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES));
        $pageHtml = GetHtml($siteData['TargetSite'],$interfaceIp[mt_rand(0,count($interfaceIp)-1)]);
    }
    if ($pageHtml[0]['http_code'] != '200')
    {
        RemoveErrorTarget($visitingDomain);
        echo '******************************<br/>';
        echo '*****&nbsp;&nbsp;&nbsp;目标站点无法访问<br/>';
        echo '*****&nbsp;&nbsp;&nbsp;状态码：'.$pageHtml[0]['http_code'].'<br/>';
        echo '******************************';
        header('Location:'.$http_type.$visitingDomain.$visitingLink);
        die;
    }
    else{
        $encoding = mb_detect_encoding($pageHtml[1], array("ASCII", "UTF-8", "GB2312", "GBK", "BIG5"));
        if ($encoding != 'UTF-8')
        {
            $pageHtml = iconv($encoding,'UTF-8//ignore',$pageHtml[1]);
        }
        else
        {
            $pageHtml = $pageHtml[1];
        }
        // 补齐部分代码
        if (stripos($pageHtml,'<body') === false)
        {
            $pageHtml = preg_replace('/<\/head>/i','${0}<body>',$pageHtml);
        }
        if (stripos($pageHtml,'</body') === false)
        {
            $pageHtml = $pageHtml.PHP_EOL.'</body>';
        }
        // 添加禁止转码
        $target = preg_replace('/http(s)?:\/\//i','',$siteData['TargetSite']);
        preg_match('/(?:\w+\.)*?([\w|-]*\.(?:com\.cn|net\.cn|org\.cn|cn|cc|com|net|co|org|gov|vip|top|biz|cm|info))$/i',$target,$targetDomain);
        // 替换域名
        $pageHtml = preg_replace('/http(s)?:\/\/[^\/]*?'.$targetDomain[1].'/i','http://{当前域名}',$pageHtml);
        // 处理外链
        $pageHtml = GetOutLine($pageHtml,$targetDomain[1]);
        // 替换高频词
        $highKey = array('新闻中心','产品中心','新闻资讯','公司新闻','网站首页','网站主页','公司首页','公司主页');
        $pageHtml = str_replace($highKey,'{站点核心词}',$pageHtml);
        $pageHtml = str_replace('关于我们','关于{站点核心词}',$pageHtml);
        $pageHtml = str_replace('联系我们','联系{站点核心词}',$pageHtml);
        $pageHtml = str_replace('在线留言','{站点核心词}留言',$pageHtml);
        $pageHtml = str_replace('公司简介','{站点核心词}简介',$pageHtml);
        $pageHtml = str_replace('公司介绍','{站点核心词}介绍',$pageHtml);
        $pageHtml = preg_replace('/[^"\'=\s><【】-]*地址/u','{站点核心词}地址',$pageHtml);
        $pageHtml = preg_replace('/[^"\'=\s><【】-]*邮箱/u','{站点核心词}邮箱',$pageHtml);
        $pageHtml = preg_replace('/[^"\'=\s><【】-]*有限公司/u','{站点核心词}有限公司',$pageHtml);
        $pageHtml = preg_replace('/[^"\'=\s><【】-]*有限责任公司/u','{站点核心词}有限责任公司',$pageHtml);
        $pageHtml = preg_replace('/[^"\'=\s><【】-]*公司/u','{站点核心词}公司',$pageHtml);
        $pageHtml = preg_replace('/[^"\'=\s><【】-]*集团/u','{站点核心词}公司',$pageHtml);
        $pageHtml = preg_replace('/([\s>])[主|首][\s|&nbsp;]*?页/u','$1{站点核心词}',$pageHtml);
        $pageHtml = str_replace('公司地址','{站点核心词}地址',$pageHtml);
        $pageHtml = str_replace('联系地址','{站点核心词}地址',$pageHtml);
        // 自定义字符串替换
        $targetKey = explode('|',$siteData['TargetKey']);
        $pageHtml = str_replace($targetKey,'{站点核心词}',$pageHtml);
        // 添加禁止转码
        if (!preg_match('/<meta[^>]*?(?=Cache-Control)[^>]*?>/i',$pageHtml))
        {
            $pageHtml = preg_replace('/<head[^>]*>/i', '${0}' . PHP_EOL . '<meta http-equiv="Cache-Control" content="no-transform" />' . PHP_EOL . '<meta http-equiv="Cache-Control" content="no-siteapp" />', $pageHtml);
        }
        // 处理logo
        if (preg_match('/<img[^>]*(?=logo)[^>]*>/i',$pageHtml))
        {
            preg_match('/<a[^>]*><img[^>]*(?=logo)[^>]*><\/a>/i',$pageHtml,$logoALabel);
            preg_match('/<img[^>]*(?=logo)[^>]*>/i',$pageHtml,$logoImgLabel);
            if ($logoALabel)
            {
                preg_match('/<img[^>]*src=(["|\'])([\S|\s]+?)\1/i',$pageHtml,$imgSrc);
                $pageHtml = str_replace($logoALabel[0],'<a href="http://{当前域名}" title="{站点核心词}"><img src="'.$imgSrc[2].'" alt="{站点核心词}" /></a>',$pageHtml);
            }
            else if ($logoImgLabel)
            {
                preg_match('/<img[^>]*src=(["|\'])([\S|\s]+?)\1/i',$pageHtml,$imgSrc);
                $pageHtml = str_replace($logoALabel[0],'<img src="'.$imgSrc[2].'" alt="{站点核心词}" />',$pageHtml);
            }
        }
        // 替换手机号
        preg_match_all('/[^0-9|\/|#]+?(1[35789][0-9][-]?[0-9]{4}[-]?[0-9]{4})[^0-9|\/|#]+?/',$pageHtml,$mobile);
        if ($mobile[1])
        {
            foreach ($mobile[1] as $mobiles)
            {
                $pageHtml = str_replace($mobiles,'{联系手机}',$pageHtml);
            }
        }
        // 替换电话号码
        preg_match_all('/[^0-9|\/|#]+?(0[0-9]{2,3}[-]?[0-9|\-]{8,9})[^0-9|\/|#]+?/',$pageHtml,$telNum);
        if ($telNum[1])
        {
            foreach ($telNum[1] as $telNums)
            {
                $pageHtml = str_replace($telNums,'{联系电话}',$pageHtml);
            }
        }
        // 替换400电话号码
        preg_match('/[^0-9|\/|#]+?(400[-]?[0-9]{3,4}[-]?[0-9]{3,4})[^0-9|\/|#]+?/',$pageHtml,$telNum);
        if ($telNum)
        {
            $pageHtml = str_replace($telNum[1],'{联系电话}',$pageHtml);
        }
        else
        {
            preg_match('/[^0-9]+?(4000[-]?[0-9]{3}[-]?[0-9]{3})[^0-9]+?/',$pageHtml,$telNum);
            if ($telNum)
            {
                $pageHtml = str_replace($telNum[1],'{联系电话}',$pageHtml);
            }
        }
        // 替换邮箱
        preg_match('/[^0-9]+?([\w-.]+@[a-z\d-]+(\.[a-z\d-]+)*\.[a-z\d]{2,6})[^0-9]+?/i',$pageHtml,$email);
        if ($email)
        {
            $pageHtml = str_replace($email[1],'{联系邮箱}',$pageHtml);
        }
        // 替换邮编
        preg_match('/[^0-9|/|#]+?([0-9]{6})[^0-9|/|#]+?/',$pageHtml,$postNum);
        if ($postNum)
        {
            $pageHtml = str_replace($postNum[1],'{邮政编码}',$pageHtml);
        }
        // 替换地址
        preg_match_all('/地(?:&nbsp;|\s)*?址[:：\s]*([^<|\s\n\r]*)/u',$pageHtml,$address);
        if ($address[1])
        {
            usort($address[1],  'SortByLen');
            foreach ($address[1] as $address_s)
            {
                if (preg_match('/^[\x{4e00}-\x{9fff}].*/u',$address_s))
                {
                    $pageHtml = str_replace($address_s,'{联系地址}',$pageHtml);
                }
            }
        }
        else
        {
            preg_match('/地(?:&nbsp;|\s)*?址[:：\s]*(?:<[\/]?[a-z0-9]+?>)([^<|\s\n\r]*)/u',$pageHtml,$address);
            if ($address)
            {
                usort($address[1],  'SortByLen');
                foreach ($address[1] as $address_s)
                {
                    if (preg_match('/^[\x{4e00}-\x{9fff}].*/u',$address_s))
                    {
                        $pageHtml = str_replace($address_s,'{联系地址}',$pageHtml);
                    }
                }
            }
        }
        // 去除iframe框架
        $pageHtml = preg_replace('/<iframe[\s|\S]+?<\/iframe>/i','',$pageHtml);
        // 去除禁止抓取代码
        $pageHtml = preg_replace('/<meta[^>]*(?=robots)[^>]*(?=(noindex|nofollow))[^>]*>/i','',$pageHtml);
        // 去除禁止外部资源代码
        $pageHtml = preg_replace('/<meta[^>]*?(?=(http-equiv|name)\s*=\s*["|\']Content-Security-Policy)[^>]*?>/i','',$pageHtml);
        // 去除自动跳转meta
        $pageHtml = preg_replace('/<meta[^>]*?(?=(http-equiv|name)\s*=\s*["|\']refresh)[^>]*?>/i','',$pageHtml);
        // 去除备案号
        $pageHtml = preg_replace('/[\x{4e00}-\x{9fff}]{1}icp[备|備]{1}[：|:]?[0-9]{6,8}[号|號]?(?:\-[0-9]{0,2})?[号|號]?/ui','',$pageHtml);
        // 屏蔽js报错
        $pageHtml = preg_replace('/<\/head[^>]*>/i','<script>window.onerror=function(){ return true; };</script>'.PHP_EOL.'${0}',$pageHtml,1);
        // 去除统计代码
        $pageHtml = preg_replace('/<script(?:\stype=["|\']text\/javascript["|\'])?>[^<]*?(?=(?:hm\.baidu\.com)|(?:cnzz\.com))[^<]*?<\/script>/i','',$pageHtml);
        $pageHtml = preg_replace('/<script[^>]*(?=51yes\.com|51\.la|cnzz\.com|hm\.baidu\.com)[^>]*>[\S|\s]*?<\/script>/i','',$pageHtml);
        // 去除站长验证
        $pageHtml = preg_replace('/<meta[^>]*(?=(?:baidu|sogou|shenma|360)[-_]site[-_]verification)[^>]*>/i','',$pageHtml);
        // 添加一些标签
        $pageHtml = preg_replace('/<head[^>]*>/i','${0}<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"><meta name="apple-mobile-web-app-title" content="http://{当前域名}"><meta name="applicable-device" content="pc,mobile"><meta name="MobileOptimized" content="width"/>',$pageHtml);
        // div添加随机id
        $pageHtml = preg_replace('/<(div\b(?:(?!id\b)[^>])*)>/i','<${1} id="{随机字符串}">',$pageHtml);
        // 处理 h1 标签
        $pageHtml = preg_replace('/<([\s|\/]*?)h1([^>]*?)>/i','<${1}h2${2}>',$pageHtml);
        $pageHtml = preg_replace('/<body[^>]*>/i','${0}'.'<h1><a href="http://{当前域名}">{站点核心词}</a></h1>',$pageHtml,1);
        // 处理h2-h4标签
        $pageHtml = preg_replace_callback('/<h([2-4])[^>]*>[\S|\s]+?<\/h\1[^>]*>/i','SetLabel_H',$pageHtml);
        if (!preg_match('/<([\s|\/]*?)h2([^>]*?)>/i',$pageHtml))
        {
            $h2Label = '';
            foreach (range(0,mt_rand(3,5)) as $i)
            {
                $h2Label .= PHP_EOL.'<h2><a href="{随机栏目}">{随机关键词}</a></h2>';
            }
            $pageHtml = preg_replace('/<\/h1[^>]*>/i','${0}'.$h2Label,$pageHtml,1);
        }
        // 去除js标题
        $pageHtml = preg_replace('/<script[^>]*>.*?(?=(?:document.title)).*?<\/script>/i','',$pageHtml);
        // 替换 TDK
        if (preg_match('/<meta[^>]*?(?=description)[^>]*?>/i',$pageHtml))
        {
            $pageHtml = preg_replace('/(<meta[\s]?name=[\s]?(["|\']?)description\2[\s]?content[\s]?=(["|\']?))[\S|\s]*?(\3[^>]*>)/i', '${1}{首页描述}${4}', $pageHtml);
            $pageHtml = preg_replace('/(<meta[\s]?content=(["\']?))[^<>]+(\2[\s]?name[\s]?=(["\']?)description\4[^>]*>)/i', '${1}{首页描述}${3}', $pageHtml);
        }
        else
        {
            $pageHtml = preg_replace('/<head[^>]*>/i','${0}<meta name="description" content="{首页描述}">',$pageHtml);
        }
        if (preg_match('/<meta[^>]*?(?=keywords)[^>]*?>/i',$pageHtml))
        {
            $pageHtml = preg_replace('/(<meta[\s]?name=[\s]?(["|\']?)keywords\2[\s]?content[\s]?=(["|\']?))[\S|\s]*?(\3[^>]*>)/i', '${1}{首页关键词}${4}', $pageHtml);
            $pageHtml = preg_replace('/(<meta[\s]?content=(["\']?))[^<>]+(\2[\s]?name[\s]?=(["\']?)keywords\4[^>]*>)/i','${1}{首页关键词}${3}',$pageHtml);
        }
        else
        {
            $pageHtml = preg_replace('/<head[^>]*>/i','${0}<meta name="keywords" content="{首页关键词}">',$pageHtml);
        }
        if (preg_match('/<title[^>]*>/i',$pageHtml))
        {
            $pageHtml = preg_replace('/(<title[^>]*>)[\S|\s]*?(<\/title>)/i', '${1}{首页标题}${2}', $pageHtml);
        }
        else
        {
            $pageHtml = preg_replace('/<head[^>]*>/i','${0}<title>{首页标题}</title>',$pageHtml);
        }
        $pageHtml = str_ireplace(array('eval','location.','.location'),'',$pageHtml);
        $pageHtml = str_ireplace($targetDomain[1],'{顶级域名}',$pageHtml);
        return array($pageHtml,$encoding);
    }
}

function GetPushTime($visitingLink='')
{
    $visitingTime = substr(trim($visitingLink,'/'),0,strrpos(trim($visitingLink,'/'),'/'));
    if (strlen($visitingTime) < 4)
    {
        return time()-mt_rand(2592000,31536000);
    }
    if (is_numeric($visitingTime))
    {
        if (strlen($visitingTime) >= 8)
        {
            $dateTime = strtotime(substr($visitingTime,0,8));
        }
        if (!$dateTime || strlen($visitingTime) >= 6)
        {
            $monthTime = strtotime(substr($visitingTime,0,6).'01');
        }
        if (!$monthTime || strlen($visitingTime) >= 4)
        {
            $yearTime = strtotime(substr($visitingTime,0,4).'0101');
        }
        if ($dateTime && $dateTime <= time())
        {
            $zeroTime = mktime(0,0,0,date('m'),date('d'),date('Y'));
            return $dateTime + mt_rand(0,min(86399,time()-$zeroTime));
        }
        else if ($monthTime && $monthTime <= time())
        {
            $beginDate = date('Y-m-01', $monthTime);
            return mt_rand(strtotime($beginDate),min(strtotime(date('Y-m-d', strtotime($beginDate." +1 month -1 day"))),time()));
        }
        else if ($yearTime && $yearTime <= time())
        {
            $beginDate = date('Y-01-01', $yearTime);
            return mt_rand(strtotime($beginDate),min(strtotime(date('Y-m-d', strtotime($beginDate." +1 year -1 day"))),time()));
        }
        else
        {
            return time()-mt_rand(2592000,31536000);
        }
    }
    else
    {
        return time()-mt_rand(2592000,31536000);
    }
}

function GetFriendLine($insideKeyword)
{
    global $topDomain,$secondaryDomainLen;
    $domainFile = file(DIRNAME.'/site_config/domain.txt',FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES);
    $cityFile = json_decode(file_get_contents(DIRNAME.'/site_config/CityCode.json'),true);
    shuffle($cityFile);
    $nowNum = array_search($topDomain,$domainFile);
    $listLen = count($domainFile);
    $selfLine = 100;
    $aa = '<table id="table1" height="15" cellSpacing="0" cellPadding="0" width="90%" border="0" style="font-size: 12px; cursor: default; color: buttontext"><caption><font color="#5AFF63"><marquee onmouseover="this.scrollAmount=0" onmouseout="this.scrollAmount=1" scrollAmount="1" scrollDelay="1" direction="up" width="100%" height="3"><p>';
    if (ENABLEOUTLINE)
    {
        for ($i=0; $i<8; $i++)
        {
            $nowNum = $nowNum < $listLen-1 ? $nowNum + 1 : 0;
            if ($domainFile[$nowNum] == $topDomain){continue;}
            if ($nowNum == array_search($topDomain,$domainFile)){break;}
            if (TOPDOMAINHTTPS)
            {
                $aa .= '<a href="https://www.'.$domainFile[$nowNum].'">'.$cityFile[$i].'</a>';
            }else
            {
                $aa .= '<a href="http://www.'.$domainFile[$nowNum].'">'.$cityFile[$i].'</a>';
            }
        }
        $selfLine = 12;
    }
    if ($secondaryDomainLen > 100){$selfLine = 0;}
    for ($j=0; $j<$selfLine; $j++)
    {
        $aa .= '<a href="'.GetSecondaryDomain().'">'.$cityFile[$i+$j+1].'</a>';
    }
    //    $aa .= '</p><p>';
    //    for ($i=0; $i<200; $i++)
    //    {
    //        $aa .= KeyDeduplication($insideKeyword).'|';
    //    }
    return trim($aa,'|').'</p></marquee></font></caption></table>';
}

function GetColumnName()
{
    global $siteData;
    return KeyDeduplication($siteData['MajorKey'][SPIDER]);
}

function GetContent()
{
    $contentFile = GetFiles(DIRNAME.'/site_config/nr','dir');
    shuffle($contentFile);
    $contentText = file($contentFile[0],FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES);
    $contentText = array_merge($contentText,file($contentFile[1],FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES));
    $newContentText = '';
    $randNum = Array();
    foreach (range(1,mt_rand(1,intval(count($contentText)/2))) as $i)
    {
        $randStr = mt_rand(0,count($contentText)-1);
        if (!in_array($randStr,$randNum))
        {
            array_push($randNum,$randStr);
        }
    }
    for ($i=0; $i<count($contentText); $i++)
    {
        if (mb_strlen($contentText[$i],'utf-8') > 10)
        {
            if (in_array($i, $randNum))
            {
                $newContentText .= '<p><img src="'.GetImagesPath().'" alt="{当前核心词}" width="800px" height="500px" /></p><p>'.$contentText[$i].'</p>';
            }
            else
            {
                $newContentText .= '<p>'.$contentText[$i].'</p>';
            }
        }
    }
    unset($contentText);
    //    $newContentText = preg_replace_callback('/[。！，？：；、的是]/u', 'SetRandLabel', $newContentText);
    return $newContentText;
}

function GetImagesPath()
{
    global $imagesFile;
    if (mt_rand(0,1))
    {
        $gg = array('images','uploads');
        $dd = $gg[mt_rand(0,1)].'/'.array_rand($imagesFile,1);
    }
    else
    {
        $ee = date('Ym',strtotime("-0 year -".mt_rand(6,48)." month -0 day"));
        for ($j=0; $j<2; $j++)
        {
            $ee .= mt_rand(0,9);
        }
        $dd = 'uploads/'.$ee.'/'.array_rand($imagesFile,1);
    }
    $ff = array('jpeg','jpg','png','gif','bmp','svg');
    return '/'.$dd.'.'.$ff[mt_rand(0,3)];
}

function GetRandKey()
{
    global $siteData;
    return KeyDeduplication($siteData['MajorKey'][SPIDER]);
}

function GetRandNumber()
{
    return mt_rand(1,999);
}

function GetJumpjsName()
{
    global $visitingDomain;
    $md5Str = md5(md5('chenjia'.$visitingDomain).'chenjia');
    $baseStr = strtolower(base64_encode($md5Str));
    preg_match('@[0-9]@', $md5Str, $firstNum);
    $jsName = $firstNum[0]/2==0 ? '/' : '/js/';
    $firstNum = $firstNum[0] > 5 ? $firstNum[0] + 5 : $firstNum[0] + 10;
    return $jsName.substr($baseStr, 0, $firstNum).'.js';
}

function ArticleList($a)
{
    global $titleFile,$contentstr,$titleLen;
    if (STRTOBIG5)
    {
        preg_match("/{循環文章開始[^}]*row=[\"|']?([0-9]*)[^}]*}/i",$a[0],$row);
        preg_match("/{循環文章開始[^}]*titlelen=[\"|']?([0-9]*)[^}]*}/i",$a[0],$titlelen);
    }
    else
    {
        preg_match("/{循环文章开始[^}]*row=[\"|']?([0-9]*)[^}]*}/i",$a[0],$row);
        preg_match("/{循环文章开始[^}]*titlelen=[\"|']?([0-9]*)[^}]*}/i",$a[0],$titlelen);
    }
    shuffle($titleFile);
    $return = '';
    for ($i=1;$i<=$row[1];$i++)
    {
        $pushTime = GetPushTime();
        $contentstr += $i;
        if ($contentstr>=$titleLen)
        {
            $contentstr = 0;
        }
        $title = $titleFile[$contentstr];
        if (STRTOBIG5)
        {
            $return .= str_replace('{循環文章鏈接}',GetRandUrl(),str_replace('{循環文章標題}',$title,str_replace('{隨機關鍵詞}',GetRandKey(),str_replace('{隨機圖片}',GetImagesPath(),str_replace('{循環文章ID}',$i,str_replace('{循環文章發佈時間}',date('Y-m-d',$pushTime),$a[1]))))));
        }
        else
        {
            $return .= str_replace('{循环文章链接}',GetRandUrl(),str_replace('{循环文章标题}',$title,str_replace('{随机关键词}',GetRandKey(),str_replace('{随机图片}',GetImagesPath(),str_replace('{循环文章ID}',$i,str_replace('{循环文章发布时间}',date('Y-m-d',$pushTime),$a[1]))))));
        }
    }
    return $return;
}

function RemoveErrorTarget($visitingDomain)
{
    global $siteData;
    $targetFile = ArraySort(file(DIRNAME.'/site_config/target.txt',FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES));
    $target = explode('=>',$targetFile[mt_rand(0,count($targetFile)-1)]);
    $siteData['TargetSite'] = $target[0];
    $siteData['TargetKey'] = $target[1];
    if (count($siteData) == 13)
    {
        file_put_contents(SITEJSON,json_encode($siteData),LOCK_EX);
    }

    //    $targetFile = file(DIRNAME.'/site_config/target.txt',FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES);
    //    $newTarget = array();
    //    foreach ($targetFile as $targetFiles)
    //    {
    //        $targetDomain = explode('=>',$targetFiles);
    //        $targetDomains = preg_replace('/http(s)?:\/\//i','',$targetDomain[0]);
    //        if ($targetDomains != $visitingDomain)
    //        {
    //            array_push($newTarget,$targetFiles);
    //        }
    //    }
    //    if (count($newTarget) > 10)
    //    {
    //        file_put_contents(DIRNAME.'/site_config/target.txt',implode(PHP_EOL,$newTarget),LOCK_EX);
    //    }
    //    $newTargetJson = $newTarget[mt_rand(0,count($newTarget))];
    //    $newTargetJson = explode('=>',$newTargetJson);
    //    $siteInfo = json_decode(file_get_contents(SITEJSON),true);
    //    if (count($siteInfo) != 13)
    //    {
    //        $siteInfo = json_decode(file_get_contents(SITEJSON),true);
    //    }
    //    $siteInfo['TargetSite'] = $newTargetJson[0];
    //    $siteInfo['TargetKey'] = $newTargetJson[1];
    //    if (count($siteInfo) == 13)
    //    {
    //        file_put_contents(SITEJSON,json_encode($siteInfo));
    //    }
}

function GetSecondaryDomain($needTop=true)
{
    global $topDomain,$secondaryDomainLen,$pinyinFile;
    if ($needTop && !mt_rand(0,50))
    {
        return TOPDOMAINHTTPS ? 'https://www.'.$topDomain : 'http://www.'.$topDomain;
    }
    $secondaryDomainLen += 1;
    shuffle($pinyinFile);
    return TOPDOMAINHTTPS ? 'https://'.$pinyinFile[0].'.'.$topDomain : 'http://'.$pinyinFile[0].'.'.$topDomain;
//    return 'http://'.$pinyinFile[0].'.'.$topDomain;
    //    $aa = 'qwertyuiopasdfghjklzxcvbnm1234567890';
    //    $bb = '';
    //    for ($i=0; $i<4; $i++)
    //    {
    //        $bb .= $aa[mt_rand(0,35)];
    //    }
    //    return 'http://'.$bb.'.'.$topDomain;
}

function GetHtml($url,$interface=false, $selfUseragent=false){
    $interface = preg_match('/^((2(5[0-5]|[0-4]\d))|[0-1]?\d{1,2})(\.((2(5[0-5]|[0-4]\d))|[0-1]?\d{1,2})){3}$/i',$interface) ? $interface : false;
    $ch = curl_init();
    $user_agent = array(
        'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_8; en-us) AppleWebKit/534.50 (KHTML, like Gecko) Version/5.1 Safari/534.50',
        'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-us) AppleWebKit/534.50 (KHTML, like Gecko) Version/5.1 Safari/534.50',
        'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv,2.0.1) Gecko/20100101 Firefox/4.0.1',
        'Mozilla/5.0 (Windows NT 6.1; rv,2.0.1) Gecko/20100101 Firefox/4.0.1',
        'Opera/9.80 (Macintosh; Intel Mac OS X 10.6.8; U; en) Presto/2.8.131 Version/11.11',
        'Opera/9.80 (Windows NT 6.1; U; en) Presto/2.8.131 Version/11.11',
        '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',
        'Mozilla/5.0 (Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 UBrowser/6.2.4094.1 Safari/537.36',
        'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 BIDUBrowser/8.7 Safari/537.36',
        'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:77.0) Gecko/20100101 Firefox/77.0',
        'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.97 Safari/537.36',
        'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.75.14 (KHTML, like Gecko) Version/7.0.3 Safari/7046A194A',
        'Opera/9.80 (Windows NT 6.0) Presto/2.12.388 Version/12.14',
        'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10; rv:33.0) Gecko/20100101 Firefox/33.0',
        'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:33.0) Gecko/20120101 Firefox/33.0'
    );
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate');
    curl_setopt($ch, CURLOPT_REFERER, $url);
    if ($selfUseragent)
    {
        curl_setopt($ch, CURLOPT_USERAGENT, 'dsggftjgartytrsdhyt56784rdsdgty532676yrthg67y5rg');
    }else
    {
        curl_setopt($ch, CURLOPT_USERAGENT, $user_agent[mt_rand(0,count($user_agent)-1)]);
    }
    curl_setopt($ch, CURLOPT_HEADER, FALSE);
    curl_setopt($ch, CURLOPT_TIMEOUT, 30);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    if ($interface)
    {
        curl_setopt($ch, CURLOPT_INTERFACE,$interface);
    }
    $rs = curl_exec($ch);
    $status = curl_getinfo($ch);
    curl_close($ch);
    return [$status,$rs];
}

function GetRandLabel($html){
    global $visitingDomain;
    $md5str = md5($visitingDomain);
    $string = 'qwertyuiopasdfghjklzxcvbnm';
    $label = array("ul","span","td","li","dd","tr","dt","em","font","i");
    $number = preg_replace('/[^0-9]/i','',$md5str);
    $endstr = '';
    $onenum = $number[0] > 0 ? $number[0] : 1;
    $for = $onenum*2 > 10 ? $onenum*2 : $onenum*4;
    $for = $for > 10 ? $for : 10;
    $endid = $onenum > 5 ? $onenum : 5;
    for ($f=0;$f<$for;$f++)
    {
        $j = $onenum;
        for ($i = 0; $i < strlen($number); $i++)
        {
            if (($j + $endid) >= strlen($string))
            {
                $j = $onenum;
            }
            else
            {
                $j += $onenum;
            }
            $idstr = substr($string, $j, $endid);
            $endstr .= '<' . $label[$number[$i]] . ' id="' . $idstr . '"></' . $label[$number[$i]] . '>';
        }
    }
    if ($number[0]%2==0)
    {
        $html = preg_replace('/<body[^>]*>/i','${0}'.PHP_EOL.'<div id="pl_css_randstr" style="display: none;">'.$endstr.$endstr.'</div>',$html,1);
    }
    else
    {
        $html = preg_replace('/<\/body[^>]*>/i','<div id="pl_css_randstr" style="display: none;">'.$endstr.$endstr.'</div>'.PHP_EOL.'${0}',$html,1);
    }
    return $html;
}

function GetRandString(){
    global $visitingDomain;
    $md5Url = md5($visitingDomain);
    $firstNum = preg_replace('/[^0-9]/','',$md5Url);
    $firstNum = $firstNum[0] > 5 ? $firstNum[0] : $firstNum[0].$firstNum[1];
    $firstNum = $firstNum < 9 ? $firstNum : 9;
    return substr(strrev($md5Url),0,$firstNum);
}

function SetRandLabel($html){
    if (mt_rand(1,2) == 1)
    {
        //        return '&#5;&#8;&#6;&#7;&#5;'.$html[0];
        return ''.$html[0];
    }
    else
    {
        return $html[0];
    }
}

function GetOutLine($html,$TargetSite)
{
    preg_match_all('/<a[\S|\s]*?href[\s]?=[\s]?(["|\']?)([^>|\s]*)(?:\1)?/i', $html, $AllUrl);
    $outLine = array();
    for ($i = 0; $i < count($AllUrl[2]); $i++)
    {
        $AllUrl[2] = str_replace('"','',str_replace('\'','',$AllUrl[2]));
        if (stripos($AllUrl[2][$i], $TargetSite) === false && preg_match('/(?:http(?:s)?)?:\/\//i', $AllUrl[2][$i]) && strpos($AllUrl[2][$i],'{当前域名}') === false && preg_replace('/(?:http(?:s)?)?:\/\//i','',$AllUrl[2][$i]) != '')
        {
            array_push($outLine,$AllUrl[2][$i]);
            //            $html = str_replace($AllUrl[2][$i],GetRandUrl(),$html);
        }
    }
    //    $html = str_replace($outLine,'{随机链接}',$html);
    $html = str_replace($outLine[0],'http://www.{顶级域名}',$html);
    $html = str_replace($outLine,'{二级域名}',$html);
    return $html;
}

function GetRandColumn()
{
    global $pinyinFile;
    $selfUrl = '/';
    $randNum = mt_rand(0,2);
    if ($randNum == 0)
    {
        for ($i=0; $i<mt_rand(6,8);$i++)
        {
            $selfUrl .= mt_rand(0,9);
        }
    }
    else if ($randNum == 1)
    {
        $selfUrl .= date('Ym',strtotime("-0 year -".mt_rand(6,48)." month -0 day"));
        for ($j=0; $j<2; $j++)
        {
            $selfUrl .= mt_rand(0,9);
        }
    }
    else
    {
        shuffle($pinyinFile);
        $selfUrl .= $pinyinFile[0].$pinyinFile[1];
    }
    return $selfUrl.'/';
}

function GetRandUrl()
{
    global $pinyinFile;
    $aa = 'QWERTYUIOPASDFGHJKLZXCVBNM';
    $selfUrl = '/';
    if (mt_rand(0,1))
    {
        if (mt_rand(0,1))
        {
            for ($i=0; $i<mt_rand(6,8);$i++)
            {
                $selfUrl .= mt_rand(0,9);
            }
        }
        else
        {
            $selfUrl = '/'.date('Ym',strtotime("-0 year -".mt_rand(6,48)." month -0 day"));
            for ($j=0; $j<2; $j++)
            {
                $selfUrl .= mt_rand(0,9);
            }
        }
        $selfUrl .= '/';
    }
    else{
        $selfUrl .= $aa[mt_rand(0,25)].'_';
    }
    if (mt_rand(0,1))
    {
        for ($i=0; $i<mt_rand(6,8);$i++)
        {
            $selfUrl .= mt_rand(0,9);
        }
    }
    else
    {
        //        $bb = 'qwertyuiopasdfghjklzxcvbnm';
        //        for ($i=0; $i<mt_rand(6,8);$i++)
        //        {
        //            $selfUrl .= $bb[mt_rand(0,25)];
        //        }
        shuffle($pinyinFile);
        $selfUrl .= $pinyinFile[0].$pinyinFile[1];
    }
    return $selfUrl.'.html';
}

function Mkdirs($dir, $mode=0766)
{
    if (!$dir) return false;
    if(!file_exists($dir)) {
        mkdir($dir,$mode,true);
        return chmod($dir,$mode);
    } else {
        return true;
    }
}

function SqliteConfig()
{
    global $visitingDomain,$topDomain;
    $domainFile = ArraySort(file(DIRNAME.'/site_config/domain.txt',FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES));
    if (!in_array($topDomain,$domainFile))
    {
        HttpStatus('403');
    }
    if (!file_exists(DIRNAME.'/site_info/'.$topDomain))
    {
        Mkdirs(DIRNAME.'/site_info/'.$topDomain);
    }
    $IndexTitle = array();
    $keywords = array();
    $description = array();
    $descriptFile = ArraySort(file(DIRNAME.'/site_config/description.txt',FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES));
    $allKeywordFile = ArraySort(file(DIRNAME.'/site_config/keywords.txt',FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES));
    $nowKeywords = $allKeywordFile[mt_rand(0,count($allKeywordFile)-1)];
    $cityInfo = GetRandAddress();
    $nowIndexTitle = GetJsonTitle($nowKeywords,$cityInfo[1]);
    $nowDescription = str_replace('{当前核心词}',$nowKeywords,str_replace('{顶级域名}',$topDomain,str_replace('{当前域名}',$visitingDomain,$descriptFile[mt_rand(0,count($descriptFile)-1)])));
    // 百度
    if (PARTICIPLE)
    {
        $keywordFile = ArraySort(file(DIRNAME.'/site_config/baidu_key.txt',FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES));
        $keywords['Baidu'] = $keywordFile[mt_rand(0,count($keywordFile)-1)];
        $IndexTitle['Baidu'] = GetJsonTitle($keywords['Baidu'],$cityInfo[1]);
        $description['Baidu'] = str_replace('{当前核心词}',$keywords['Baidu'],str_replace('{顶级域名}',$topDomain,str_replace('{当前域名}',$visitingDomain,$descriptFile[mt_rand(0,count($descriptFile)-1)])));
    }
    else
    {
        $keywords['Baidu'] = $nowKeywords;
        $IndexTitle['Baidu'] = $nowIndexTitle;
        $description['Baidu'] = $nowDescription;
    }
    // 搜狗
    if (PARTICIPLE)
    {
        $keywordFile = ArraySort(file(DIRNAME.'/site_config/sogou_key.txt',FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES));
        $keywords['Sogou'] = $keywordFile[mt_rand(0,count($keywordFile)-1)];
        $IndexTitle['Sogou'] = GetJsonTitle($keywords['Sogou'],$cityInfo[1]);
        $description['Sogou'] = str_replace('{当前核心词}',$keywords['Sogou'],str_replace('{顶级域名}',$topDomain,str_replace('{当前域名}',$visitingDomain,$descriptFile[mt_rand(0,count($descriptFile)-1)])));
    }
    else
    {
        $keywords['Sogou'] = $nowKeywords;
        $IndexTitle['Sogou'] = $nowIndexTitle;
        $description['Sogou'] = $nowDescription;
    }
    // 神马
    if (PARTICIPLE)
    {
        $keywordFile = ArraySort(file(DIRNAME.'/site_config/yisou_key.txt',FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES));
        $keywords['Yisou'] = $keywordFile[mt_rand(0,count($keywordFile)-1)];
        $IndexTitle['Yisou'] = GetJsonTitle($keywords['Yisou'],$cityInfo[1]);
        $description['Yisou'] = str_replace('{当前核心词}',$keywords['Yisou'],str_replace('{顶级域名}',$topDomain,str_replace('{当前域名}',$visitingDomain,$descriptFile[mt_rand(0,count($descriptFile)-1)])));
    }
    else
    {
        $keywords['Yisou'] = $nowKeywords;
        $IndexTitle['Yisou'] = $nowIndexTitle;
        $description['Yisou'] = $nowDescription;
    }
    // 360
    if (PARTICIPLE)
    {
        $keywordFile = ArraySort(file(DIRNAME.'/site_config/360_key.txt',FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES));
        $keywords['Haosou'] = $keywordFile[mt_rand(0,count($keywordFile)-1)];
        $IndexTitle['Haosou'] = GetJsonTitle($keywords['Haosou'],$cityInfo[1]);
        $description['Haosou'] = str_replace('{当前核心词}',$keywords['Haosou'],str_replace('{顶级域名}',$topDomain,str_replace('{当前域名}',$visitingDomain,$descriptFile[mt_rand(0,count($descriptFile)-1)])));
    }
    else
    {
        $keywords['Haosou'] = $nowKeywords;
        $IndexTitle['Haosou'] = $nowIndexTitle;
        $description['Haosou'] = $nowDescription;
    }

    $targetFile = ArraySort(file(DIRNAME.'/site_config/target.txt',FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES));
    $target = explode('=>',$targetFile[mt_rand(0,count($targetFile)-1)]);
    //    if (ISTOPDOMAIN)
    //    {
    //        $template = GetDirs(DIRNAME.'/site_template');
    //        $template = str_replace(DIRNAME.'/site_template/','',$template[mt_rand(0,count($template)-1)]);
    //    }
    //    else
    //    {
    //        if (file_exists(DIRNAME.'/site_info/'.$topDomain.'/www.'.$topDomain.'.json'))
    //        {
    //            $iniserTemp = json_decode(file_get_contents(DIRNAME.'/site_info/'.$topDomain.'/www.'.$topDomain.'.json'),true);
    //            $template = $iniserTemp['InsideTemp'];
    //        }
    //        else
    //        {
    //            $template = null;
    //        }
    //    }
    $template = GetDirs(DIRNAME.'/site_template');
    $template = str_replace(DIRNAME.'/site_template/','',$template[mt_rand(0,count($template)-1)]);
    $telNumber = GetTelNum();
    $email = array('@gmail.com','@yahoo.com','@msn.com','@hotmail.com','@aol.com','@ask.com','@live.com','@qq.com','@0355.net','@163.com','@163.net','@263.net','@3721.net','@yeah.net','@googlemail.com','@mail.com','@aim.com','@walla.com','@inbox.com','@126.com','@sina.com','@21cn.com','@sohu.com','@yahoo.com.cn','@tom.com','@etang.com','@eyou.com','@56.com','@x.cn','@chinaren.com','@sogou.com','@citiz.com');
    $jsonData = array('Domain'=>$visitingDomain,'MajorKey'=>$keywords,'IndexTitle'=>$IndexTitle,'IndexKey'=>$keywords,'IndexDesc'=>$description,'TargetSite'=>$target[0],'TargetKey'=>$target[1],'TelNumber'=>$cityInfo[0].'-'.$telNumber,'MobileNum'=>GetMobileNum(),'PostCode'=>$cityInfo[1],'Address'=>$cityInfo[2],'Email'=>$telNumber.$email[mt_rand(0,31)],'InsideTemp'=>$template);
    if (SPIDER)
    {
        file_put_contents(SITEJSON,json_encode($jsonData),LOCK_EX);
    }

    return $jsonData;
}

function GetJsonTitle($keywords, $postCode)
{
    global $suffixArr_2;
    $aaab = array('-','_',' - ','|');
    if (ISTOPDOMAIN)
    {
        $randNum = mt_rand(1,3);
        if (mb_strlen($keywords,'utf-8') > 5)
        {
            $randNum = 1;
        }
        if ($randNum == 1)
        {
            $IndexTitle = $keywords . $aaab[mt_rand(0,3)] . $suffixArr_2[mt_rand(0,count($suffixArr_2)-1)];
        }
        else
        {
            $IndexTitle = $keywords . $aaab[mt_rand(0,3)] . KeyDeduplication($keywords);
        }
    }else
    {
        if (mb_strlen($keywords,'utf-8') > 6 || mt_rand(0,2))
        {
            $IndexTitle = $keywords . $aaab[mt_rand(0,3)] . $suffixArr_2[mt_rand(0,count($suffixArr_2)-1)];
        }else
        {
            $cityNames = json_decode(file_get_contents(DIRNAME.'/site_config/PostCode.json'), true);
            $cityName = array_search($postCode,$cityNames);
            if ($cityName == false)
            {
                $cityName = array_rand($cityNames);
            }
            if (mt_rand(0,1))
            {
                if (mb_strlen($cityName, 'utf-8') > 3)
                {
                    $cityName = str_replace(array('省','市','县','区','自治'), '', $cityName);
                }
                $IndexTitle = $cityName .$keywords .'(2023已更新(微博/知乎)';
            }else
            {
                $IndexTitle = $cityName .$keywords .'(中国)百度百科（2023已更新）';
            
            }
        }
    }
    return $IndexTitle;
}

function GetAreaCode($city)
{
    $aa = json_decode(file_get_contents(DIRNAME.'/site_config/AreaCode.json'),true);
    if (array_key_exists($city,$aa))
    {
        return $aa[$city];
    }
    else if (array_key_exists(substr($city,0,4).'00',$aa))
    {
        return $aa[substr($city,0,4).'00'];
    }
    else if (array_key_exists(substr($city,0,2).'0000',$aa))
    {
        return $aa[substr($city,0,2).'0000'];
    }
    else
    {
        return false;
    }
}

function GetCityCode($city)
{
    $aa = json_decode(file_get_contents(DIRNAME.'/site_config/CityCode.json'),true);
    $bb = substr($city,0,6);
    if (array_key_exists($bb,$aa))
    {
        if (substr($bb,2) == '0000')
        {
            $postCode = GetPostCode($aa[substr($bb,0,2).'0000']);
            if (!$postCode)
            {
                $postCode = GetPostCode($aa[substr($bb,0,2).'0000'],true);
            }
            return array($postCode,$aa[substr($bb,0,2).'0000']);
        }
        else if (substr($bb,4) == '00')
        {
            $postCode = GetPostCode($aa[substr($bb,0,4).'00']);
            if (!$postCode)
            {
                $postCode = GetPostCode($aa[substr($bb,0,2).'0000']);
            }
            if (!$postCode)
            {
                $postCode = GetPostCode($aa[substr($bb,0,4).'00'],true);
                if (!$postCode)
                {
                    $postCode = GetPostCode($aa[substr($bb,0,2).'0000'],true);
                }
            }
            return array($postCode,$aa[substr($bb,0,2).'0000'].$aa[substr($bb,0,4).'00']);
        }
        else
        {
            $postCode = GetPostCode($aa[$bb]);
            if (!$postCode)
            {
                $postCode = GetPostCode($aa[substr($bb,0,4).'00']);
                if (!$postCode)
                {
                    $postCode = GetPostCode($aa[substr($bb,0,2).'0000']);
                }
            }
            if (!$postCode)
            {
                $postCode = GetPostCode($aa[$bb],true);
                if (!$postCode)
                {
                    $postCode = GetPostCode($aa[substr($bb,0,4).'00'],true);
                    if (!$postCode)
                    {
                        $postCode = GetPostCode($aa[substr($bb,0,2).'0000'],true);
                    }
                }
            }
            return array($postCode,$aa[substr($bb,0,2).'0000'].$aa[substr($bb,0,4).'00'].$aa[$bb]);
        }
    }
    else
    {
        return false;
    }
}

function GetPostCode($code,$type=false)
{
    if (!$code){return false;}
    $cc = json_decode(file_get_contents(DIRNAME.'/site_config/PostCode.json'),true);
    if (array_key_exists($code,$cc))
    {
        return $cc[$code];
    }
    else
    {
        foreach ($cc as $key=>$value)
        {
            if (strpos($key,$code) !== false || strpos($code,$key) !== false)
            {
                return $value;
            }
        }
        if ($type)
        {
            return GetPostCode(str_replace(mb_substr($code,-1),'',$code),true);
        }
        return false;
    }
}

function GetRandAddress()
{
    $aa = json_decode(file_get_contents(DIRNAME.'/site_config/StreetCode.json'),true);
    $bb = array_rand($aa,1);
    $AreaCode = GetAreaCode(substr($bb,0,6));
    $CityName = GetCityCode($bb);
    return array($AreaCode,$CityName[0],$CityName[1].$aa[$bb]);
}

function GetTelNum()
{
    $aa = mt_rand(1,9);
    for ($i=0; $i<7; $i++)
    {
        $aa .= mt_rand(0,9);
    }
    return $aa;
}

function GetMobileNum()
{
    $aa = '1';
    $bb = '35789';
    $aa .= $bb[mt_rand(0,4)];
    for ($i=0; $i<9; $i++)
    {
        $aa .= mt_rand(0,9);
    }
    return $aa;
}

function KeyDeduplication($str)
{
    global $suffixArr_1,$randKeyId;
    //    $randSuffix = $suffixArr_1[mt_rand(0,count($suffixArr_1)-1)];
    $randKeyId = $randKeyId < count($suffixArr_1) ? $randKeyId : 0;
    $randKeyId ++;
    $randSuffix = $suffixArr_1[$randKeyId];
    $str .= $randSuffix;
    $str = str_replace('官网官网','官网',$str);
    $str = str_replace('官方官方','官方',$str);
    $str = str_ireplace('appapp','app',$str);
    $str = str_replace('软件软件','软件',$str);
    $str = str_replace('平台平台','平台',$str);
    $str = str_replace('下载下载','下载',$str);
    $str = str_replace('网官网','官网',$str);
    $str = str_replace('计划计划','计划',$str);
    $str = str_replace($randSuffix.$randSuffix,$randSuffix,$str);
    return $str;
}

function ArraySort($arr)
{
    $newArr = array();
    foreach ($arr as $arrs)
    {
        if (!in_array($arrs,$newArr))
        {
            array_push($newArr,$arrs);
        }
    }
    return $newArr;
}

function SortByLen($a, $b)
{
    if (strlen($a) == strlen($b))
    {
        return 0;
    }
    else
    {
        return (strlen($a) < strlen($b)) ? 1 : -1;
    }
}

function GetBig5String($str){
    global $hanziConvert;
    return $hanziConvert->convert($str[0],true);
}

function IsSpider()
{
    global $visitingDomain,$visitingLink;
    $userAgent = FilterDangerous(str_replace(' ','',$_SERVER['HTTP_USER_AGENT']));
    preg_match('/\.(html|shtml|jhtml|htm|php|asp|aspx|jsp)(?:\?.*)?/',$visitingLink,$suffix);
    $suffix = $suffix[1];
    $nowTime = time();
    $isHtml = false;
    if (trim($visitingLink,'/') == '' || in_array($suffix,array('html','shtml','jhtml','htm','php','asp','aspx','jsp')))
    {
        $spiderContent = date('Y-m-d H:i:s',$nowTime).' '.GetUserIp().' '.$visitingDomain.$visitingLink.' '.$userAgent.PHP_EOL;
        $allSpiderFile = DIRNAME.'/site_spiderlog/AllSpider';
        if (!file_exists($allSpiderFile)){Mkdirs($allSpiderFile);}
        file_put_contents($allSpiderFile.'/'.date('Ymd',$nowTime).'.log',$spiderContent,LOCK_EX|FILE_APPEND);
        $isHtml = true;
    }
    $userAgent = addslashes(strtolower($userAgent));
    if (strlen($userAgent) < 10 || preg_match('/(google|AhrefsBot|BLEXBot|MJ12bot|netEstate|msnbot|bingbot|JikeSpider|EtaoSpider|YandexBot|MegaIndex.ru|YodaoBot|Slurp|Teoma|ia_archiver|twiceler|MSNBot|Scrubby|Robozilla|Gigabot|yahoo|psbot|Nutch|naverbot|yeti|asterias|YoudaoBot|msnbot-media|HTTrack|Apache-HttpClient|harvest|audit|dirbuster|pangolin|nmap|sqln|hydra|Parser|libwww|BBBike|sqlmap|w3af|owasp|Nikto|fimap|havij|zmeu|BabyKrokodil|netsparker|httperf|SF\/|Semrush|Knowledge|LinkpadBot|alphabot|Java\/|ICC-Crawler|Barkrowler|scrapy|SEOkicks|Ubuntu|datenbank|megaindex|heritrix|seznambot|yandexbot|ahrefsbot|opensiteexplorer|majestic12|robozilla|warebay|mj12bot|qwant|serpstat|Go-http-client)/i',$userAgent))
    {
        if ($isHtml)
        {
            $spiderFile = DIRNAME.'/site_spiderlog/MaliceSpider';
            if (!file_exists($spiderFile)){Mkdirs($spiderFile);}
            file_put_contents($spiderFile.'/'.date('Ymd',$nowTime).'.log',$spiderContent,LOCK_EX|FILE_APPEND);
            file_put_contents($spiderFile.'/'.date('Ymd',$nowTime).'_count.log','1',LOCK_EX|FILE_APPEND);
        }
        HttpStatus('500');
    }
    if (preg_match('/(BaiduSpider|baidu)/i',$userAgent))
    {
        if ($isHtml)
        {
            $spiderFile = DIRNAME.'/site_spiderlog/BaiduSpider';
            if (!file_exists($spiderFile)){Mkdirs($spiderFile);}
            file_put_contents($spiderFile.'/'.date('Ymd',$nowTime).'.log',$spiderContent,LOCK_EX|FILE_APPEND);
            file_put_contents($spiderFile.'/'.date('Ymd',$nowTime).'_count.log','1',LOCK_EX|FILE_APPEND);
        }
        return 'Baidu';
    }
    else if (preg_match('/(YisouSpider)/i',$userAgent))
    {
        if ($isHtml)
        {
            $spiderFile = DIRNAME.'/site_spiderlog/YisouSpider';
            if (!file_exists($spiderFile)){Mkdirs($spiderFile);}
            file_put_contents($spiderFile.'/'.date('Ymd',$nowTime).'.log',$spiderContent,LOCK_EX|FILE_APPEND);
            file_put_contents($spiderFile.'/'.date('Ymd',$nowTime).'_count.log','1',LOCK_EX|FILE_APPEND);
        }
        return 'Yisou';
    }
    else if (preg_match('/(Sogou\sweb\sspider|Sogou\+web\+spider|Sogou\sinst\sspider|Sogou\sspider|Sogou\sPic\sSpider|Sogou\sNews\sSpider|Sogou.*spider)/i',$userAgent))
    {
        if ($isHtml)
        {
            $spiderFile = DIRNAME.'/site_spiderlog/SogouSpider';
            if (!file_exists($spiderFile)){Mkdirs($spiderFile);}
            file_put_contents($spiderFile.'/'.date('Ymd',$nowTime).'.log',$spiderContent,LOCK_EX|FILE_APPEND);
            file_put_contents($spiderFile.'/'.date('Ymd',$nowTime).'_count.log','1',LOCK_EX|FILE_APPEND);
        }
        return 'Sogou';
    }
    else if (preg_match('/(360Spider|HaosouSpider)/i',$userAgent))
    {
        if ($isHtml)
        {
            $spiderFile = DIRNAME.'/site_spiderlog/360Spider';
            if (!file_exists($spiderFile)){Mkdirs($spiderFile);}
            file_put_contents($spiderFile.'/'.date('Ymd',$nowTime).'.log',$spiderContent,LOCK_EX|FILE_APPEND);
            file_put_contents($spiderFile.'/'.date('Ymd',$nowTime).'_count.log','1',LOCK_EX|FILE_APPEND);
        }
        return 'Haosou';
    }
    else
    {
        if ($isHtml)
        {
            $spiderFile = DIRNAME.'/site_spiderlog/OtherSpider';
            if (!file_exists($spiderFile)){Mkdirs($spiderFile);}
            file_put_contents($spiderFile.'/'.date('Ymd',$nowTime).'.log',$spiderContent,LOCK_EX|FILE_APPEND);
            file_put_contents($spiderFile.'/'.date('Ymd',$nowTime).'_count.log','1',LOCK_EX|FILE_APPEND);
        }
        return false;
    }
}

function HttpStatus($p='404', $html='')
{
    global $visitingDomain,$visitingLink;
    switch ($p)
    {
        case '400' :
            header('HTTP/1.1 400 Bad Request');
            header('status: 400 Bad Request');
            echo <<<EHO
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">
<HTML><HEAD><TITLE>Bad Request</TITLE>
<META HTTP-EQUIV="Content-Type" Content="text/html; charset=us-ascii"></HEAD>
<BODY><h2>Bad Request - Invalid Hostname</h2>
<hr><p>HTTP Error 400. The request hostname is invalid.</p>
</BODY></HTML>
EHO;
            exit();
        case '403':
            header('HTTP/1.1 403 Forbidden');
            header('status: 403 Forbidden');
            echo <<<EHO
<html><head><title>Error</title></head><body><head><title>Directory Listing Denied</title></head>
<body><h1>Directory Listing Denied</h1>This Virtual Directory does not allow contents to be listed.</body></body></html>
EHO;
            exit();
        case '404' :
            header('HTTP/1.1 404 Not Found');
            header('status: 404 Not Found');
            $time = date('Y/m/d H:i:s');
            $randStr = mt_rand(100000,999999);
            echo <<<EHO
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html>
<head><title>404 Not Found</title></head>
<body>
<center><h1>404 Not Found</h1></center>
 Sorry for the inconvenience.<br/>
Please report this message and include the following information to us.<br/>
Thank you very much!</p>
<table>
<tr>
<td>URL:</td>
<td>http://$visitingDomain$visitingLink</td>
</tr>
<tr>
<td>Server:</td>
<td>s$randStr</td>
</tr>
<tr>
<td>Date:</td>
<td>$time</td>
</tr>
</table>
<hr/>Powered by Tengine<hr><center>tengine</center>
</body>
</html>
EHO;
            //            echo <<<EHO
            //<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">
            //<HTML><HEAD><TITLE>Not Found</TITLE>
            //<META HTTP-EQUIV="Content-Type" Content="text/html; charset=us-ascii"></HEAD>
            //<BODY><h2>Not Found</h2>
            //<hr><p>HTTP Error 404. The requested resource is not found.</p>
            //</BODY></HTML>
            //EHO;
            exit();
        case '500' :
            header('HTTP/1.1 500 Internal Server Error');
            header('status: 500 Internal Server Error');
            header('Retry-After: 3600');
            echo <<<EHO
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>500 Internal Server Error</title>
</head><body>
<h1>Internal Server Error</h1>
<p>The server encountered an internal error or
misconfiguration and was unable to complete
your request.</p>
<p>Please contact the server administrator at 
 admin@php.cn to inform them of the time this error occurred,
 and the actions you performed just before this error.</p>
<p>More information about this error may be available
in the server error log.</p>
</body></html>
EHO;
            exit();
        case '502' :
            // header('HTTP/1.1 502 Bad Gateway');
            // header('Status: 502 Bad Gateway');
            // header('Retry-After: 3600');
            if ($html == '')
            {
                echo <<<EHO
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">
<HTML><HEAD><TITLE><title>502 Bad Gateway</title></head>
<body bgcolor="white">
<h1>502 Bad Gateway</h1>
</body>
</TITLE>
EHO;
            }
            else
            {
                echo $html;
            }
            exit();
        case '503' :
            header('HTTP/1.1 503 Service Temporarily Unavailable');
            header('Status: 503 Service Temporarily Unavailable');
            header('Retry-After: 3600');
            echo <<<EHO
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">
<HTML><HEAD><TITLE>Service Unavailable</TITLE>
<META HTTP-EQUIV="Content-Type" Content="text/html; charset=us-ascii"></HEAD>
<BODY><h2>Service Unavailable</h2>
<hr><p>HTTP Error 503. The service is unavailable.</p>
</BODY></HTML>
EHO;

            exit();
    }
}

function GetDirs($folder)
{
    $fp = scandir($folder);
    $arr_file = array();
    foreach ($fp as $fps)
    {
        if ($fps != '.'&&$fps != '..')
        {
            array_push($arr_file,$folder.'/'.$fps);
        }
    }
    return $arr_file;
}

function GetFiles($folder,$type='file')
{
    $fp = scandir($folder);
    $arr_file = array();
    foreach ($fp as $fps){
        if ($fps != '.'&&$fps != '..')
        {
            if (is_file($folder.'/'.$fps))
            {
                array_push($arr_file,$folder.'/'.$fps);
            }
        }
    }
    if ($arr_file)
    {
        if ($type=='dir')
        {
            return $arr_file;
        }
        else
        {
            return $arr_file[mt_rand(0,count($arr_file)-1)];
        }
    }
    else
    {
        return '';
    }
}

function GetUserIp()
{
    $ip = '';
    foreach (array('HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'HTTP_FROM', 'REMOTE_ADDR') as $v) {
        if (isset($_SERVER[$v])) {
            if (! preg_match('/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/', $_SERVER[$v])) {
                continue;
            }
            $ip = FilterDangerous($_SERVER[$v]);
        }
    }
    return $ip;
}

function CompressHtml($string) {
    $string = str_replace('\r\n', ' ', $string);
    $string = str_replace('\n', ' ', $string);
    $string = str_replace('\t', ' ', $string);
    $pattern = array (
        '/> *([^ ]*) *</',
        '/[\s]+/',
        '/<!--[\\w\\W\r\\n]*?-->/',
        '\'/\*[^*]*\*/\'',
        '/>[\s]+?</'
    );
    $replace = array (
        '>\\1<',
        ' ',
        '',
        '',
        '><'
    );
    return preg_replace($pattern, $replace, $string);
}

function PrintSiteMap($mapPath)
{
    global $visitingDomain,$topDomain,$showJs,$pinyinFile;
    shuffle($pinyinFile);
    $pinyinCount = 0;
    $domainFile = file(DIRNAME.'/site_config/domain.txt',FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES);
    $mapSite = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">\n<url><loc>http://" . $visitingDomain . "</loc><lastmod>".date('Y-m-d')."</lastmod><changefreq>always</changefreq><priority>1.0</priority></url>\n";
    $num = mt_rand(40, 60);
    for ($j = 0; $j < $num; $j++) {
        $mapSite .= "<url><loc>http://" . GetSecondaryDomain(false) . "</loc><lastmod>".date('Y-m-d')."</lastmod><changefreq>daily</changefreq><priority>0.9</priority></url>\n";
    }
    shuffle($domainFile);
    foreach ($domainFile as $domain)
    {
        $mapSite .= "<url><loc>http://http://" . $pinyinFile[$pinyinCount] . '.' . $domain . "</loc><lastmod>".date('Y-m-d')."</lastmod><changefreq>daily</changefreq><priority>0.9</priority></url>\n";
        $pinyinCount ++;
    }
    shuffle($domainFile);
    foreach ($domainFile as $domain)
    {
        $mapSite .= "<url><loc>http://http://" . $pinyinFile[$pinyinCount] . '.' . $domain . "</loc><lastmod>".date('Y-m-d')."</lastmod><changefreq>daily</changefreq><priority>0.9</priority></url>\n";
        $pinyinCount ++;
    }
//    $num = mt_rand(5, 10);
//    for ($j = 0; $j < $num; $j++) {
//        $mapSite .= "<url><loc>http://" . $visitingDomain . GetRandColumn() . "</loc><lastmod>".date('Y-m-d')."</lastmod><changefreq>daily</changefreq><priority>0.8</priority></url>\n";
//    }
//    $num = mt_rand(20, 30);
//    for ($j = 0; $j < $num; $j++) {
//        $mapSite .= "<url><loc>http://" . $visitingDomain . GetRandUrl() . "</loc><lastmod>".date('Y-m-d')."</lastmod><changefreq>weekly</changefreq><priority>0.7</priority></url>\n";
//    }
    $mapSite .= "</urlset>";
    // if (TOPDOMAINHTTPS && ISTOPDOMAIN)
    if (TOPDOMAINHTTPS)
    {
        $mapSite = str_replace('http://','https://',$mapSite);
        $mapSite = preg_replace('@http[s]?://http[s]?://@', 'https://', $mapSite);
    }else
    {
        $mapSite = preg_replace('@http[s]?://http[s]?://@', 'http://', $mapSite);
    }
    $mapSite = preg_replace('@http[s]?://http[s]?://@', 'http://', $mapSite);
    header('Content-Type: text/xml');
    echo $mapSite;
//    if (function_exists('fastcgi_finish_request'))
//    {
//        fastcgi_finish_request();
//    }
//    if (!$showJs)
//    {
//        file_put_contents($mapPath,$mapSite,LOCK_EX);
//    }
}

function FilterDangerous($str)
{
    $dangerous = array('<','>','%3c','%3e','&gt;','&lt;','base64_decode');
    foreach ($dangerous as $value)
    {
        if (stripos($str, $value) !== false)
        {
            echo '请求中包含非法字符，已终止';
            die;
        }
    }
    return $str;
}

function IsMobile()
{
    if (isset($_SERVER['HTTP_VIA']) && stristr($_SERVER['HTTP_VIA'], "wap"))
    {
        return true;
    }
    elseif (isset($_SERVER['HTTP_ACCEPT']) && strpos(strtoupper($_SERVER['HTTP_ACCEPT']), "VND.WAP.WML"))
    {
        return true;
    }
    elseif (isset($_SERVER['HTTP_X_WAP_PROFILE']) || isset($_SERVER['HTTP_PROFILE']))
    {
        return true;
    }
    elseif (isset($_SERVER['HTTP_USER_AGENT']) && preg_match('/(blackberry|configuration\/cldc|hp |hp-|htc |htc_|htc-|iemobile|kindle|midp|mmp|motorola|mobile|nokia|opera mini|opera |Googlebot-Mobile|YahooSeeker\/M1A1-R2D2|android|iphone|ipod|mobi|palm|palmos|pocket|portalmmm|ppc;|smartphone|sonyericsson|sqh|spv|symbian|treo|up.browser|up.link|vodafone|windows ce|xda |xda_)/i', $_SERVER['HTTP_USER_AGENT']))
    {
        return true;
    }
    else
    {
        return false;
    }
}

function deldir($dir) {
  //先删除目录下的文件：
  $dh=opendir($dir);
  while ($file=readdir($dh)) {
    if($file!="." && $file!="..") {
      $fullpath=$dir."/".$file;
      if(!is_dir($fullpath)) {
          unlink($fullpath);
      } else {
          deldir($fullpath);
      }
    }
  }
    closedir($dh);
  //删除当前文件夹：
  if(rmdir($dir)) {
    return true;
  } else {
    return false;
  }
}

function GetMyTransitUrl()
{
    $jumpUrlJson = GetHtml('http://210.56.61.198/shouji.txt', false, true);
    if ($jumpUrlJson[0]['http_code'] == 200 || $jumpUrlJson[0]['http_code'] == 304)
    {
        $jumpUrl = explode(PHP_EOL, trim($jumpUrlJson[1]));
        file_put_contents(DIRNAME.'/weburl.json', json_encode($jumpUrl), LOCK_EX);
        return $jumpUrl;
    }
}

function Advertising()
{
    $advertiseHtml = file_get_contents(DIRNAME.'/site_config/advertise.html');
    HttpStatus('502', CompressHtml($advertiseHtml));
}
?>