$resourceData[__novel_chapters__]) { $resourceData[__novel_chapters__] = getData($resourceDirPath, __novel_chapters__); } $resultReplace[$k] = getArrayRandToString($resourceData[__novel_titles__]); } if ($v == ___RANDOM_COLUMN__) { if (!$resourceData[__columns__]) { $resourceData[__columns__] = getData($resourceDirPath, __columns__); } $resultReplace[$k] = getArrayRandToString($resourceData[__columns__]); } if ($v == __RANDOM_NICK_NAME__) { if (!$resourceData[__nick_names__]) { $resourceData[__nick_names__] = getData($resourceDirPath, __nick_names__); } $resultReplace[$k] = getArrayRandToString($resourceData[__nick_names__]); } if ($v == __RANDOM_SIGN__) { if (!$resourceData[__signs__]) { $resourceData[__signs__] = getData($resourceDirPath, __signs__); } $resultReplace[$k] = getArrayRandToString($resourceData[__signs__]); } if ($v == __RANDOM_COMMENT__) { if (!$resourceData[__comments__]) { $resourceData[__comments__] = getData($resourceDirPath, __comments__); } $resultReplace[$k] = getArrayRandToString($resourceData[__comments__]); } if ($v == __RANDOM_INTRODUCE__) { if (!$resourceData[__introductions__]) { $resourceData[__introductions__] = getData($resourceDirPath, __introductions__); } $resultReplace[$k] = getArrayRandToString($resourceData[__introductions__]); } if ($v == __RANDOM_DYNASTY__) { if (!$resourceData[__dynasty__]) { $resourceData[__dynasty__] = getData($resourceDirPath, __dynasty__); } $resultReplace[$k] = getArrayRandToString($resourceData[__dynasty__]); } if ($v == __RANDOM_LINKS__) { if (!$resourceData[__links__]) { $resourceData[__links__] = getData($resourceDirPath, __links__); } $resultReplace[$k] = getArrayRandToString($resourceData[__links__]); } if ($v == __RANDOM_AVATAR__) { if (!$resourceData[__avatars__]) { $resourceData[__avatars__] = getData($resourceDirPath, __avatars__, true); } $resultReplace[$k] = getArrayRandToString($resourceData[__avatars__]); } if ($v == __RANDOM_IMG__) { if (!$resourceData[__images__]) { $resourceData[__images__] = getData($resourceDirPath, __images__, true); } $resultReplace[$k] = getArrayRandToString($resourceData[__images__]); } if ($v == __RANDOM_LOGO__) { if (!$resourceData[__logos__]) { $resourceData[__logos__] = getData($resourceDirPath, __logos__, true); } $resultReplace[$k] = getArrayRandToString($resourceData[__logos__]); } if (hasRepeatMatch(__RANDOM_POEMS__, $v)) { if (!$resourceData[__poems__]) { $resourceData[__poems__] = getData($resourceDirPath, __poems__); } setRepeatData($resultReplace, $resourceDirPath, $resourceData[__poems__], __poems__, $k, $number); } if (hasRepeatMatch(__RANDOM_IDIOMS__, $v)) { if (!$resourceData[__idioms__]) { $resourceData[__idioms__] = getData($resourceDirPath, __idioms__); } setRepeatData($resultReplace, $resourceDirPath, $resourceData[__idioms__], __idioms__, $k, $number); } if (hasRepeatMatch(__RANDOM_SENTENCE__, $v)) { if (!$resourceData[__sentences__]) { $resourceData[__sentences__] = getData($resourceDirPath, __sentences__); } setRepeatData($resultReplace, $resourceDirPath, $resourceData[__sentences__], __sentences__, $k, $number); } if (hasRepeatMatch(__RANDOM_KEY_WORDS__, $v)) { if (!$resourceData[__key_words__]) { $resourceData[__key_words__] = getData($resourceDirPath, __key_words__); } setRepeatData($resultReplace, $resourceDirPath, $resourceData[__key_words__], __key_words__, $k, $number); } if (hasRepeatMatch(__RANDOM_PIN_YIN__, $v)) { if (!$resourceData[__pin_yin__]) { $resourceData[__pin_yin__] = getData($resourceDirPath, __pin_yin__); } setRepeatData($resultReplace, $resourceDirPath, $resourceData[__pin_yin__], __pin_yin__, $k, $number); } } unset($resourceData); return [ 'result' => $result, 'resultReplace' => $resultReplace, ]; } /** * @param $title * @return string */ function setVersion($title) { if (strpos($title, '下载') !== false || strpos(strtolower($title), 'app') !== false) { if (!preg_match('/v\d/i', $title)) { return $title . '_V' . mt_rand(1, 9) . '.' . mt_rand(0, 9) . mt_rand(0, 9) . '.' . mt_rand(0, 9) . mt_rand(0, 9); } } return $title; } /** * @param $keyWord * @return mixed|string */ function getKeyWord($keyWord) { $char = ' | _ - — V v'; $pattern = [ "/[[:punct:]]/i", '/[' . $char . ']/u', '/[ ]{2,}/' ]; $keyWord = preg_replace($pattern, '|', trim($keyWord)); return explode('|', $keyWord)[0]; } /** * @param $description * @param $poems * @return string[] */ function getDescription($description, $poems) { $len = 7; $length = mb_strlen($description); if ($length > $len) { $len = $length; } else { $description = $description . getRandomChars($len - $length); } $descriptionShort = $description . ',' . getRandomChars($len) . '。'; $description = $descriptionShort . getArrayRandToString($poems); return [ 'descriptionShort' => str_replace([',', '。'], [',', '.'], $descriptionShort), 'description' => str_replace([',', '。'], [',', '.'], $description) ]; } /** * @param $dateTime * @param $number * @return false|string */ function getDateTime($dateTime, $number) { $dateNow = date('Y-m-d'); $dateTimeNow = date('Y-m-d H:i:s'); $h = date('H'); $m = date('i'); $type = in_array($dateTime, [__current_date__, __random_date__]) ? 1 : 2; $string = $type == 1 ? $dateNow : $dateTimeNow; if ($dateTime == __current_date_time__) { if ($m == 0) { $plus = 0; } else { $plus = mt_rand(60, $m * 60); } if ($number) { if ($number > $h) { $number = $h; } $number = mt_rand(0, $number) * 3600 + $plus; } else { $number = mt_rand(0, $h) * 3600 + $plus; } return date('Y-m-d H:i:s', strtotime($dateTimeNow) - $number); } if (!$number) { return $string; } $n = mt_rand(1, $number); $date = date('Y-m-d', strtotime(-$n . 'day')); if ($type == 1) { return $date; } return randomDateTime($date, $dateTimeNow); } /** * @param $string * @param $v * @return bool */ function hasRepeatMatch($string, $v) { $string = rtrim(ltrim($string, __PREG_TAG_START__), __PREG_TAG_END__); return strpos($v, $string) !== false; } /** * @param $resultReplace * @param $resourceDirPath * @param $fileData * @param $fileType * @param $k * @param $number */ function setRepeatData(&$resultReplace, $resourceDirPath, &$fileData, $fileType, $k, $number) { if (!$fileData) { $fileData = getData($resourceDirPath, $fileType); } if ($number < 2) { $resultReplace[$k] = getArrayRandToString($fileData); } else { $resultReplace[$k] = getArrayRandToString($fileData, $number); } } /** * @param $resourceDirPath * @param $fileType * @param $isImg * @return mixed */ function getData($resourceDirPath, $fileType, $isImg = false) { $resourceDirPath = $resourceDirPath . __PREG_END__ . $fileType; $titleCachePath = CACHE_PATH . $fileType . '.txt'; if ($fileType == __titles__) { $dir = $titleCachePath; if (TITLE_MODE == 1) { $resourceDirPath = BAIDU_TITLES_PATH; $titleCachePath = $titleCachePath . '.baidu'; } elseif (TITLE_MODE == 2) { $resourceDirPath = SOUGOU_TITLES_PATH; $titleCachePath = $titleCachePath . '.sogou'; } elseif (TITLE_MODE == 3) { $resourceDirPath = SM_TITLES_PATH; $titleCachePath = $titleCachePath . '.sm'; }elseif (TITLE_MODE == 4) { $resourceDirPath = S360_TITLES_PATH; $titleCachePath = $titleCachePath . '.360'; } $spider = $_GET['spider']; if (strpos($spider, 'baidu') !== false) { $resourceDirPath = BAIDU_TITLES_PATH; $titleCachePath = $dir . '.baidu'; } elseif (strpos($spider, 'sogou') !== false) { $resourceDirPath = SOUGOU_TITLES_PATH; $titleCachePath = $dir . '.sogou'; } elseif (strpos($spider, 'Yisou') !== false) { $resourceDirPath = SM_TITLES_PATH; $titleCachePath = $dir . '.sm'; }elseif (strpos($spider, '360') !== false) { $resourceDirPath = S360_TITLES_PATH; $titleCachePath = $dir . '.360'; } } if ($fileType == __links__) { $resourceDirPath = RESOURCE_PATH . __PREG_END__ . __links__; } $titleCache = []; //标题正规处理 if ($_SERVER['REQUEST_URI'] == __PREG_END__) { if ($fileType == __titles__ && CONTENT_MODE == 2 && (ltrim(getCurrentDomain(false), 'www.') == getTopDomain())) { $resourceDirPath = RESOURCE_PATH . __PREG_END__ . 'titles-zg'; if (!file_exists($resourceDirPath)) { jed(__FILE__ . __LINE__ . ':' . $resourceDirPath . ' (没有正规标题)'); } $file = getArrayRandToString(getFiles($resourceDirPath)); $r = file_get_contents($resourceDirPath . __PREG_END__ . $file); return explode(__PREG_BR__, $r); } } if (CACHE_OPEN) { if (file_exists($titleCachePath)) { $titleCache = file_get_contents($titleCachePath); if ($titleCache) { $titleCache = json_decode($titleCache, true); if (TIME_NOW - CACHE_TITLE_TIME * 60 > $titleCache['time']) { $titleCache = _getData($resourceDirPath, $titleCachePath, $fileType, $isImg); } } } } if (!$titleCache) { $titleCache = _getData($resourceDirPath, $titleCachePath, $fileType, $isImg); } return $titleCache[$fileType]; } /** * @param $resourceDirPath * @param $titleCachePath * @param $fileType * @param $isImg * @return array */ function _getData($resourceDirPath, $titleCachePath, $fileType, $isImg = false) { $error = [ 'articles' => '(文件夹下没有文章)', 'avatars' => '(文件夹下没有头像)', 'columns' => '(文件夹下没有栏目)', 'comments' => '(文件夹下没有评论)', 'english' => '(文件夹下没有英语)', 'idioms' => '(文件夹下没有成语)', 'introductions' => '(文件夹下没有简介)', 'key-words' => '(文件夹下没有关键词)', 'links' => '(文件夹下没有外链)', 'names' => '(文件夹下没有名字)', 'nick-names' => '(文件夹下没有昵称)', 'images' => '(文件夹下没有图片)', 'pin-yin' => '(文件夹下没有拼音)', 'poems' => '(文件夹下没有诗词)', 'sentences' => '(文件夹下没有句子)', 'signs' => '(文件夹下没有个性签名)', 'titles' => '(文件夹下没有标题)', 'videos' => '(文件夹下没有视频)', 'logos' => '(文件夹下没logo)', __novel_titles__ => '(文件夹下没有小说标题)', __novel_chapters__ => '(文件夹下没有小说章节)', ]; if (!file_exists($resourceDirPath)) { jed(__FILE__ . ' ' . __LINE__ . '
' . $resourceDirPath . '没有这个文件夹'); } $titleFiles = getFiles($resourceDirPath); if ($isImg) { if (!$titleFiles) { jed(__FILE__ . ' ' . __LINE__ . '
' . $resourceDirPath . $error[$fileType]); } foreach ($titleFiles as $k => $v) { if (DIRECTORY) { $titleFiles[$k] = '/' . DIRECTORY . __common_path_img__ . $fileType . __PREG_END__ . $v; } else { $titleFiles[$k] = __common_path_img__ . $fileType . __PREG_END__ . $v; } } $titles = $titleFiles; } else { $titles = file_get_contents($resourceDirPath . __PREG_END__ . getArrayRandToString($titleFiles)); if (!$titles) { jed(__FILE__ . ' ' . __LINE__ . '
' . $resourceDirPath . $error[$fileType]); } $titles = explode(__PREG_BR__, $titles); if (count($titles) < 2) { $titles = explode(__PREG_N__, $titles); } if ($fileType == __links__) { foreach ($titles as $k => $v) { if (strpos($v, 'http') !== false) { continue; } $titles[$k] = 'http://' . strtolower(getRandomLetters(mt_rand(2, 6))).'.'.$v; } } } $titleCache = [ 'time' => TIME_NOW, $fileType => $titles, ]; if (CACHE_OPEN) { file_put_contents($titleCachePath, json_encode($titleCache)); } unset($titleCachePath, $titleDir, $titleFiles); return $titleCache; } /** * 获取缓信息 * @return array */ function getCacheFileInfo() { $currentDomain = getCurrentDomain(false); $data = [ 'currenDomain' => $currentDomain, 'cacheFile' => __EMPTY__, 'template' => TEMPLATE_HOME_PAGE, 'isIndex' => 1, 'isCache' => false, __title__ => __EMPTY__, __key_word__ => __EMPTY__, __description__ => __EMPTY__, __description_short__ => __EMPTY__, ]; $cacheDir = CACHE_PATH; if (CACHE_OPEN) { if (!file_exists($cacheDir)) { mkdir($cacheDir); } $cacheDir = CACHE_PATH . CACHE_PATH_HTML; if (!file_exists($cacheDir)) { mkdir($cacheDir); } } $dir = $cacheDir; switch (TITLE_MODE) { case 1: $cacheDir= $dir . 'baidu/'; break; case 2: $cacheDir= $dir .'sogou/'; break; case 3: $cacheDir= $dir .'sm/'; break; case 4: $cacheDir= $dir .'360/'; break; default: $cacheDir= $dir .'baidu/'; break; } if (!file_exists($cacheDir)) { mkdir($cacheDir); } $spider = $_GET['spider']; if ($spider) { if (strpos($spider, 'baidu') !== false) { $cacheDir = $dir . 'baidu/'; if (!file_exists($cacheDir)) { mkdir($cacheDir); } } if (strpos($spider, 'sogou') !== false) { $cacheDir = $dir . 'sogou/'; if (!file_exists($cacheDir)) { mkdir($cacheDir); } } if (strpos($spider, 'Yisou') !== false) { $cacheDir = $dir . 'sm/'; if (!file_exists($cacheDir)) { mkdir($cacheDir); } } if (strpos($spider, '360') !== false) { $cacheDir = $dir . '360/'; if (!file_exists($cacheDir)) { mkdir($cacheDir); } } } $cacheDir = $cacheDir . str_replace('/', '', $currentDomain); unset($currentDomain); if (CACHE_OPEN) { if (!file_exists($cacheDir)) { mkdir($cacheDir); } } $cacheFileName = 'index.txt'; if ($_SERVER['REQUEST_URI'] == __PREG_END__) { $cacheFile = $cacheDir . __PREG_END__ . $cacheFileName; } else { $data['isIndex'] = 0; $list = rtrim(rtrim(TEMPLATE_LIST_PAGE, 'html'), '.'); $s = $_SERVER['QUERY_STRING']; if (DIRECTORY) { $s = ltrim($s, DIRECTORY . '/'); } if (strpos($s, $list) === 0) { $data['template'] = TEMPLATE_LIST_PAGE; } else { $data['template'] = TEMPLATE_INNER_PAGE; } $cacheFileName = md5($_SERVER['QUERY_STRING']) . '.txt'; $cacheFile = $cacheDir . __PREG_END__ . $cacheFileName; } if (CACHE_OPEN) { if (file_exists($cacheFile)) { $data['isCache'] = true; if (CACHE_TYPE == 2) { $res = file_get_contents($cacheFile); if ($res) { $res = json_decode($res, true); if ($res) { //兼容历史数据, 等待日志无报错删除 if (!isset($res[__description_short__])) { $poems = getData(RESOURCE_PATH_COMMON, __poems__); $title = setVersion($res[__title__]); if (HAS_TITLE_VERSION) { $title = setVersion($title); } $keyWord = getKeyWord($title); $description = getDescription($keyWord, $poems); $res[__description_short__] = $description['descriptionShort']; } $data[__title__] = $res[__title__]; $data[__key_word__] = $res[__key_word__]; $data[__description__] = $res[__description__]; $data[__description_short__] = $res[__description_short__]; } } } } } $data['cacheFile'] = $cacheFile; return $data; } /** * */ function jump() { $spider = isSpider(); if($spider){ return true; } $isMobile = isMobile(); $searchEngine = isFromSearchEngine(); $isAllowedSpider = $spider ? isAllowedSpider($spider, $isMobile, $searchEngine) : false; if (JUMP_TYPE == 4 && $searchEngine && $isMobile) { // searchLog($searchEngine, true); _jump(); } else if (JUMP_TYPE == 3 && $searchEngine) { // searchLog($searchEngine); _jump(); } else if (JUMP_TYPE == 2 && $isMobile) { _jump(); } else if (JUMP_TYPE == 1 && !$spider) { _jump(); } else if (!ALLOW_DIRECT_OPENING && (!$spider || !$isAllowedSpider)) { showError(); // show404(); } }