$showHtml = preg_replace(__PREG_WELL__ . $v . __PREG_WELL__, $resultReplace, $showHtml, 1); } unset($matchResult); return $showHtml; } /** * 资源文件 * @return array */ function getResourceData($cacheFileInfo) { $titles = getData(RESOURCE_PATH, __titles__); $poems = getData(RESOURCE_PATH_COMMON, __poems__); $baiduPush = getBaiduPush(); $title = __EMPTY__; $keyWord = __EMPTY__; $description = __EMPTY__; $descriptionShort = __EMPTY__; if (CACHE_OPEN && CACHE_TYPE == 2) { $title = $cacheFileInfo[__title__]; $keyWord = $cacheFileInfo[__key_word__]; $description = $cacheFileInfo[__description__]; $descriptionShort = $cacheFileInfo[__description_short__]; } if (!$title) { if ($_SERVER['REQUEST_URI'] == __PREG_END__ && CONTENT_MODE == 2 && (ltrim(getCurrentDomain(false), 'www.') == getTopDomain())) { $descInfo = isset($_GET['topDomainDesc']) ? $_GET['topDomainDesc'] : getDefaultDesc($cacheFileInfo['templateDir']); $title = $descInfo['title']; $keyWord = $descInfo['keyWord']; $description = $descInfo['description']; } else { $isSetVersion = false; $title = getArrayRandToString($titles); if (HAS_TITLE_VERSION) { $titleSet = setVersion($title); if ($title != $titleSet) { $isSetVersion = true; } $title = $titleSet; } $keyWord = getKeyWord($title); $description = getDescription($keyWord, $poems); $descriptionShort = $description['descriptionShort']; if (DESCRIPTION_SUFFIX) { $str = str_replace('{标题}', $keyWord, DESCRIPTION_SUFFIX); } $description = strToUnicode($str . ' ' . $description['description']); $keyWord = strToUnicode($keyWord); $length = strlen($title); if ($_GET['spider'] && TITLE_SUFFIX && !$isSetVersion) { if (strpos($_GET['spider'], 'sogou') !== false) { if (strpos($title, '中国') === false && strpos($title, '公司') === false && ($length < TITLE_SUFFIX_NUM)) { $title .= getTitleSuffix(); } } } } $title = strToUnicode($title); } if (CACHE_OPEN && CACHE_TYPE == 2 && !$cacheFileInfo['isCache']) { $cacheData = [ __title__ => $title, __key_word__ => $keyWord, __description__ => $description, __description_short__ => $descriptionShort ]; file_put_contents($cacheFileInfo['cacheFile'], json_encode($cacheData)); } $static = json_decode(file_get_contents(STATIC_RESOURCE_PATH), true); $top_domain = getTopDomain(); $areaList = getArea(); // $hotWords = getHotWords(); $movieType = [ '动作电影', '爱情电影', '科幻电影', '恐怖电影', '喜剧电影', '电视剧', '国产电影', '香港电影', '美国电影', '韩国电影', '综艺节目电影', '动漫电影', '最近更新', '热播排行', ]; return [ __top_domain__ => $top_domain, __top_domain_url__ => __HTTP_PREFIX__ . $top_domain, __current_domain__ => getCurrentDomain(), __title__ => $title, __titles__ => $titles, __novel_titles__ => [], __novel_chapters__ => [], __key_word__ => $keyWord, __description__ => $description, __description_short__ => $descriptionShort, __names__ => [], __poems__ => $poems, __idioms__ => [], __key_words__ => [], __columns__ => [], __nick_names__ => [], __signs__ => [], __comments__ => [], __avatars__ => [], __images__ => [], __logos__ => [], __introductions__ => [], __pin_yin__ => [], __links__ => [], __dynasty__ => $static[__dynasty__], __baidu_push__ => $baiduPush, '__RANDOM_P__' => $areaList['province'], '__RANDOM_C__' => $areaList['city'], '__RANDOM_A__' => $areaList['area'], '__MOVIE_TYPE__' => $movieType, // '__HOT_BD__' => $hotWords['bd'], // '__HOT_WB__' => $hotWords['wb'], // '__HOT_DY__' => $hotWords['dy'], // '__HOT__' => array_merge($hotWords['bd'], $hotWords['wb'], $hotWords['dy']), ]; } function getHotWords(){ $array = [ 'bd' => [1,2,3], 'wb' => [1,2,3], 'dy' => [1,2,3], ]; $bd = RESOURCE_PATH_COMMON.'/hotwords/bd.txt'; $wb = RESOURCE_PATH_COMMON.'/hotwords/wb.txt'; $dy = RESOURCE_PATH_COMMON.'/hotwords/dy.txt'; if(file_exists($bd)){ $bd = file_get_contents($bd); $bd = explode("\r\n", $bd); if(count($bd) < 2){ $bd = explode("\n", $bd); } $array['bd'] = $bd; } if(file_exists($wb)){ $wb = file_get_contents($wb); $wb = explode("\r\n", $wb); if(count($bd) < 2){ $wb = explode("\n", $wb); } $array['wb'] = $wb; } if(file_exists($dy)){ $dy = file_get_contents($dy); $dy = explode("\r\n", $dy); if(count($dy) < 2){ $dy = explode("\n", $dy); } $array['dy'] = $dy; } return $array; } function getTitleSuffix() { if (!TITLE_SUFFIX) { return ''; } if ((int)TITLE_SUFFIX == 0) { return TITLE_SUFFIX; } $resourceDirPath = RESOURCE_PATH . __PREG_END__ . 'titles-suffix'; if (!file_exists($resourceDirPath)) { jed(__FILE__ . __LINE__ . ':' . $resourceDirPath . ' (没有标题后缀)'); } $file = getArrayRandToString(getFiles($resourceDirPath)); $r = file_get_contents($resourceDirPath . __PREG_END__ . $file); $array = ['-', '|', '_']; return getArrayRandToString($array) . getArrayRandToString(explode(__PREG_BR__, $r)); } /** * 默认首页信息 * @param $templateDir * @return array|string[] */ function getDefaultDesc($templateDir) { $info = []; if (TOP_DOMAIN_DESC == 1) { $topDomain = str_replace('/', '', getTopDomain()); $siteBindInfo = []; $siteBindInfoPath = CACHE_PATH . 'siteBind.json'; if (file_exists($siteBindInfoPath)) { $siteBindInfo = file_get_contents($siteBindInfoPath); if ($siteBindInfo) { $siteBindInfo = json_decode($siteBindInfo, true); if ($siteBindInfo) { $info = $siteBindInfo[$topDomain]; } } } if (!$info) { $resourceDirPath = RESOURCE_PATH . __PREG_END__ . 'titles-top-zg'; if (!file_exists($resourceDirPath)) { jed(__FILE__ . __LINE__ . ':' . $resourceDirPath . ' (没有正规标题)'); } $file = getArrayRandToString(getFiles($resourceDirPath)); $r = file_get_contents($resourceDirPath . __PREG_END__ . $file); $title = getArrayRandToString(explode(__PREG_BR__, $r)); $resourceDirPath = RESOURCE_PATH . __PREG_END__ . 'key-words-zg'; if (!file_exists($resourceDirPath)) { jed(__FILE__ . __LINE__ . ':' . $resourceDirPath . ' (没有正规关键词)'); } $file = getArrayRandToString(getFiles($resourceDirPath)); $r = file_get_contents($resourceDirPath . __PREG_END__ . $file); $keyWord = getArrayRandToString(explode(__PREG_BR__, $r)); $resourceDirPath = RESOURCE_PATH . __PREG_END__ . 'description-zg'; if (!file_exists($resourceDirPath)) { jed(__FILE__ . __LINE__ . ':' . $resourceDirPath . ' (没有正规关键词)'); } $file = getArrayRandToString(getFiles($resourceDirPath)); $r = file_get_contents($resourceDirPath . __PREG_END__ . $file); $description = getArrayRandToString(explode(__PREG_BR__, $r)); $info = [ 'title' => $title, 'keyWord' => $keyWord, 'description' => $title . ' ' . $description, ]; $siteBindInfo[$topDomain] = $info; if (CACHE_OPEN) { file_put_contents($siteBindInfoPath, json_encode($siteBindInfo), FILE_APPEND); } } } else { switch ($templateDir) { case 'shici': $info = [ 'title' => '不见天涯', 'keyWord' => '古诗文学,诗词歌赋,全民写诗', 'description' => '曾经的诗词歌赋,吟诗作对,杯酒笙歌,遇见你之后,诗中是你,画中是你,歌中是你,文中是你,脑中是你,心中是你,爱的人必须像你。吟诗作对,诗词歌赋,有兴趣的朋友进来,写写诗,做做对,评论区见。嘿嘿嘿', ]; break; case 'dushu': $info = [ 'title' => '新兴小说', 'keyWord' => '读好书,小说网网,免费小说', 'description' => '专业中文图书,在线免费小说,为读书爱好者提供各种题材的全本免费小说,古典文学人文学,世界文学,校园小说,都市小说,网络小说,恐怖惊悚小说,推理小说,科幻小说,古代小说,现代近代文学,外国文学等', ]; break; case 'xiaozhong': $info = [ 'title' => '小众圈子', 'keyWord' => '生活圈子,行业信息,新闻咨询,论坛,评论交流,交友', 'description' => '什么样的圈子,才可以决定你人生的命运,和优秀的人在一起真的很重要.我们的生活就似是一个圆圈,人们每天围着属于自己的圈子不停转.每一天我们总会与各种各样的人打交道、拓宽视野,学习他人的经验.', ]; break; case 'faxing': $info = [ 'title' => '发型站-发型图片与诗词', 'keyWord' => '发型站,发型设计,发型展示,发型图片与诗词,形容头发美丽的诗词', 'description' => '发型站(www.faxingzhan.com)的宗旨是潮流我做主,打造最全面的发型设计网站,开拓2021最新流行发型设计与脸型搭配的技巧,邀你共同去创作时尚潮流元素,分享最新美发造型与男生女生发型图片。形容头发美丽的诗词', ]; break; default: $info = [ 'title' => SITE_NAME, 'keyWord' => SITE_NAME, 'description' => SITE_NAME, ]; } $info = [ 'title' => SITE_NAME ? SITE_NAME : $info['title'], 'keyWord' => $info['keyWord'], 'description' => $info['title'] . ' ' . $info['description'], ]; } foreach ($info as $k => $v) { $info[$k] = strToUnicode($v); } $_GET['topDomainDesc'] = $info; return $info; } /** * @param $showHtml * @param $cacheFileInfo * @return array */ function getContentResource($showHtml, $cacheFileInfo) { $resourceData = getResourceData($cacheFileInfo); $searchList = getSearchList(); preg_match_all(__PREG_WELL__ . $searchList . __PREG_WELL__, $showHtml, $result); $result = $result[0]; $resourceDirPath = RESOURCE_PATH_COMMON; $resultReplace = []; foreach ($result as $k => $v) { $number = getNumberInString($v); if ($v == __TOP_DOMAIN__) { $resultReplace[$k] = $resourceData[__top_domain__]; } if ($v == __TOP_DOMAIN_URL__) { $resultReplace[$k] = $resourceData[__top_domain_url__]; } if ($v == __CURRENT_DOMAIN__) { $resultReplace[$k] = $resourceData[__current_domain__]; } if ($v == ___RANDOM_DOMAIN_URI__) { $resultReplace[$k] = getCurrentDomain(true, 2); } if ($v == __LIST_DOMAIN_URL__) { $resultReplace[$k] = getCurrentDomain(true, 2, true); } if ($v == ___RANDOM_FAN_DOMAIN__) { $resultReplace[$k] = getFanDomain(); } if (hasRepeatMatch(___CURRENT_DATE__, $v)) { $resultReplace[$k] = getDateTime(__current_date__, $number); } if (hasRepeatMatch(___CURRENT_DATE_TIME__, $v)) { $resultReplace[$k] = getDateTime(__current_date_time__, $number); } if (hasRepeatMatch(___RANDOM_DATE__, $v)) { $resultReplace[$k] = getDateTime(__random_date__, $number); } if (hasRepeatMatch(___RANDOM_DATE_TIME__, $v)) { $resultReplace[$k] = getDateTime(__random_date_time__, $number); } if (hasRepeatMatch(___RANDOM_NUMBER__, $v)) { $resultReplace[$k] = getRandomNumber($number); } if (hasRepeatMatch(___RANDOM_LETTER__, $v)) { $resultReplace[$k] = getRandomLetters($number); } if (hasRepeatMatch(___RANDOM_CH__, $v)) { $resultReplace[$k] = getRandomChars($number); } if ($v == __TITLE__) { $resultReplace[$k] = $resourceData[__title__]; } if ($v == __KEY_WORD__) { $resultReplace[$k] = $resourceData[__key_word__]; } if ($v == __DESCRIPTION__) { $resultReplace[$k] = $resourceData[__description__]; } if ($v == __DESCRIPTION_SHORT__) { $resultReplace[$k] = $resourceData[__description_short__]; } if ($v == __BAIDU_PUSH__) { $resultReplace[$k] = $resourceData[__baidu_push__]; } if ($v == __RANDOM_TITLE__) { $title = getArrayRandToString($resourceData[__titles__]); $length = strlen($title); $isSetVersion = false; if (strpos($title, '下载') !== false || strpos(strtolower($title), 'app') !== false) { if (!preg_match('/v\d/i', $title)) { $isSetVersion = true; } } if ($_GET['spider'] && TITLE_SUFFIX && !$isSetVersion) { if (strpos($_GET['spider'], 'sogou') !== false) { if (strpos($title, '中国') === false && strpos($title, '公司') === false && ($length < TITLE_SUFFIX_NUM)) { $title .= getTitleSuffix(); } } } $resultReplace[$k] = $title; } // if ($v == __HOT_BD__) { // $resultReplace[$k] = getArrayRandToString($resourceData['__HOT_BD__']); // } // if ($v == __HOT_WB__) { // $resultReplace[$k] = getArrayRandToString($resourceData['__HOT_WB__']); // } // if ($v == __HOT_DY__) { // $resultReplace[$k] = getArrayRandToString($resourceData['__HOT_DY__']); // } // if ($v == __HOT__) { // $resultReplace[$k] = getArrayRandToString($resourceData['__HOT__']); // } if ($v == __MOVIE_TYPE__) { $resultReplace[$k] = getArrayRandToString($resourceData['__MOVIE_TYPE__']); } if ($v == __RANDOM_C__) { $resultReplace[$k] = getArrayRandToString($resourceData['__RANDOM_C__']); } if ($v == __RANDOM_A__) { $resultReplace[$k] = getArrayRandToString($resourceData['__RANDOM_A__']); } if ($v == __RANDOM_NAME__) { if (!$resourceData[__names__]) { $resourceData[__names__] = getData($resourceDirPath, __names__); } $resultReplace[$k] = getArrayRandToString($resourceData[__names__]); } if ($v == ___NOVEL_TITLES__) { if (!$resourceData[__novel_titles__]) { $resourceData[__novel_titles__] = getData($resourceDirPath, __novel_titles__); } $resultReplace[$k] = getArrayRandToString($resourceData[__novel_titles__]); } if ($v == ___NOVEL_CHAPTERS__) { if (!$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(); } }