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 '******************************
';
echo '***** 目標站點獲取異常,刷新重試
';
echo '***** '.$siteData['TargetSite'].'
';
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('/]*?(?=sitemap\.xml)[^>]*?>/',$html))
{
$html = preg_replace('/<\/body>/', '{站點核心詞}地圖${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}', $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('/]*?(?=sitemap\.xml)[^>]*?>/',$html))
{
$html = preg_replace('/<\/body>/', '{站點核心詞}地圖${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}', $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('/>[^<]+?{隨機關鍵詞}<',$a[0],1);
preg_match('/>[^<]+?|\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 '******************************
';
echo '***** 目標站點無法訪問
';
echo '***** 狀態碼:'.$pageHtml[0]['http_code'].'
';
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,'