$title, 'articlePath' => $articlePath, 'template' => $template]; $linksAndKeywords[] = ['link' => $url, 'keyword' => $title]; } // 获取配置信息 // 查模板文件是否存在,如果不存在则使用默认模板 $defaultTemplate =$moban_index; // 查默认模板文件是否存?if (!file_exists($defaultTemplate)) { header("HTTP/1.0 500 Internal Server Error"); echo "错误Q模板文?'$defaultTemplate' 不存?; exit(); } $template = file_get_contents($moban_index); // 替换模板中的链接和关键词 $template = replaceLinksAndKeywords($template, $linksAndKeywords); //echo $finalContent; // 函数定义 function quchu($http_url) { if (stristr($http_url, "http")) { $http_url = trim($http_url); $http_url = str_ireplace("https://", "", $http_url); $http_url = str_ireplace("http://", "", $http_url); $http_url = str_ireplace($_SERVER['HTTP_HOST'], "", $http_url); } return $http_url; } // 替换模板中的其他标签 // 辅助函数Q判断字W串中是否包含HTML标签 function containsHtml($string) { return preg_match('/<[^>]+>/', $string); } // 从指定数l中随机选择一个元?function getRandomElement($array) { if (empty($array)) { return ''; } return $array[array_rand($array)]; } // 辅助函数Q读取文件内容ƈ为每一行添?p>标签Q如果需要) function readFileContent($filePath) { // d文g内容Q按行分? $lines = file($filePath, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); if (empty($lines)) { return ''; // 如果文g为空Q则q回I字W串 } // Ҏ一行进行处理,查是否需要添?p>标签 $processedLines = array_map(function($line) { // 查当前行是否包含HTML标签 if (!containsHtml($line)) { // 如果没有HTML标签Q则d
标签 return "
{$line}
"; } // 如果已经有HTML标签Q则保持原样 return $line; }, $lines); return implode("\n", $processedLines); } // d目录下的所有文件内容ƈ随机q回其中一?function readDirectoryContent($directoryPath) { if (!is_dir($directoryPath)) { return ''; } $files = glob("$directoryPath/*"); if (empty($files)) { return ''; } // 随机选择一个文件ƈd其内? $randomFile = $files[array_rand($files)]; return readFileContent($randomFile); } // 获取操作pȝcd function getOsType() { return strtoupper(substr(PHP_OS, 0, 3)) === 'WIN' ? 'WINDOWS' : 'LINUX'; } // d目录下的所有匹配文件ƈ随机q回其中一个文件的全部内容 function readRandomFileContentFromDirectory($directoryPath) { // 获取所有匹配的文g $files = glob($directoryPath); if (empty($files)) { return ''; // 如果没有扑ֈM文gQ则q回I字W串 } // 随机选择一个文? $randomFile = $files[array_rand($files)]; // d随机选择的文件内? return readFileContent($randomFile); } // d目录下的所有匹配文件ƈ随机q回其中一个文件的随机一行内?function readRandomLineFromRandomFileInDirectory($directoryPath) { // 获取所有匹配的文g $files = glob($directoryPath); if (empty($files)) { return ''; // 如果没有扑ֈM文gQ则q回I字W串 } // 随机选择一个文? $randomFile = $files[array_rand($files)]; // d随机选择的文件内容,按行分割 $lines = file($randomFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); if (empty($lines)) { return ''; // 如果文g为空Q则q回I字W串 } // 随机选择一? return getRandomElement($lines); } // 解析文章内容q处理自定义标签 function parseArticle($path) { // d文章内容 $lines = file($path, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); $replacements = []; $osType = getOsType(); foreach ($lines as $line) { if (strpos($line, '=') !== false) { list($tag, $content) = explode('=', $line, 2); // 使用2来限制分割次? // 查是否ؓ直接替换标签 if (!strpos($content, '*') && !strpos($content, '/') && !strpos($content, '\\')) { $replacements[$tag] = $content; continue; } // Ҏ操作pȝ调整路径分隔W? $normalizedPath = str_replace(['/', '\\'], DIRECTORY_SEPARATOR, $content); // 保文g路径的编码ؓ UTF-8 q{换ؓ GBKQ如果需要) if ($osType === 'WINDOWS') { $normalizedPath = mb_convert_encoding($normalizedPath, 'GBK', 'UTF-8'); } // 获取l对路径 $absolutePath = realpath($normalizedPath); // 查是否是囄文g路径 if (preg_match('/\.(jpg|jpeg|gif)$/', $content)) { $replacements[$tag] = $content; } // 处理 {内容} 标签Q读取整个文件内Ҏ随机选择一个文件ƈd其全部内? elseif (strpos($tag, '{') === 0 && strpos($tag, '}') === strlen($tag) - 1) { if (strpos($content, '*') !== false) { $replacements[$tag] = readRandomFileContentFromDirectory($content); } else { if ($absolutePath && file_exists($absolutePath)) { $replacements[$tag] = readFileContent($absolutePath); } else { // 如果路径不存在,但看h像是囄文g路径Q直接返回\? if (preg_match('/\.(jpg|jpeg|gif)$/', $content)) { $replacements[$tag] = $content; } else { // 如果没有通配W和路径W号Q直接替换内? $replacements[$tag] = $content; } } } } // 处理 <...> 标签Q随机选择一个文件ƈd光Z行内? elseif (strpos($tag, '<') === 0 && strpos($tag, '>') === strlen($tag) - 1) { if (strpos($content, '*') !== false) { $replacements[$tag] = readRandomLineFromRandomFileInDirectory($content); } else { if ($absolutePath && file_exists($absolutePath)) { $contentLines = file($absolutePath, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); if (!empty($contentLines)) { $replacements[$tag] = $contentLines[array_rand($contentLines)]; } } else { // 如果路径不存在,但看h像是囄文g路径Q直接返回\? if (preg_match('/\.(jpg|jpeg|gif)$/', $content)) { $replacements[$tag] = $content; } else { // 如果没有通配W和路径W号Q直接替换内? $replacements[$tag] = $content; } } } } // 处理其他文g路径 else { if ($absolutePath && file_exists($absolutePath)) { $fileExtension = pathinfo($absolutePath, PATHINFO_EXTENSION); // 处理囄文g if (in_array($fileExtension, ['jpg', 'jpeg', 'gif'])) { $replacements[$tag] = $absolutePath; } // 处理文本文g elseif (in_array($fileExtension, ['txt'])) { if (strpos($tag, '<') === 0) { // 单行 $contentLines = file($absolutePath, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); if (!empty($contentLines)) { $replacements[$tag] = $contentLines[array_rand($contentLines)]; } } elseif (strpos($tag, '{') === 0) { // 全文 $replacements[$tag] = readFileContent($absolutePath); } } } else { // 如果路径不存在,但看h像是囄文g路径Q直接返回\? if (preg_match('/\.(jpg|jpeg|gif)$/', $content)) { $replacements[$tag] = $content; } else { // 如果没有通配W和路径W号Q直接替换内? $replacements[$tag] = $content; } } } } } return $replacements; } function replaceTags($template, $replacements, $title) { // 替换模板中的标签 $template = str_replace('',$webname, $template); $template = str_replace('<备案?', $beianhao, $template); $template = str_replace('<来源>', $laiyuan, $template); // 定义常见姓氏数组 $surnames = [ '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, 'U?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, 'H?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, 'D?, '|?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, 'q?, '?, '?, 'I?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, 'c?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, 'U?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, 'l?, '?, '?, '~?, 'q?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, 'z?, '?, '?, '?, '?, '?, '?, '?, '?, 'E?, '?, '?, '?, '?, '?, '?, '?, '荀', '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, 'p?, '?, '?, 'D?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, 'U?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, 'W?, '?, '?, '?, '?, '?, '?, 'q?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '怀', '?, '?, '?, '?, '?, '?, 'c?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '冀', '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, 'q?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, 'l?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, 'q?, '?, '?, '?, '?, 'D?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, 'a?, '?, '?, '?, '', '?, 'I?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, 'U?, '?, '?, '?, '?, '?, '?, '?, '?, '万俟', '叔R', '上官', 'Ƨ阳', '夏侯', '诸葛', 'Mh', '东方', '赫连', '皇甫', '迟', '公羊', '澹台', '公冶', '宗政', 'Ȯ阳', '淳于', '单于', '太叔', '甛_', '公孙', '仲孙', '轩辕', '令狐', '钟离', '宇文', '长孙', '慕容', '鲜于', '闾丘', '司徒', '司空', '亓官', '司寇', '仉督', '子R', '颛孙', '端木', '巫马', '公西', '漆雕', '乐正', '壤驷', '公良', '拓跋', '夹谷', '宰父', 'h', 'D干', 'N', '东郭', '南门', '呼g', '舌', '微生', '公户', '公玉', '公A', '梁丘', '公仲', '公上', '公门', '公山', '公坚', '左丘', '公伯', '襉K', '公祖', 'W五', '公乘', '贯丘', '公皙', '南宫', '公厘', '东里', '东宫', '仲长', '子书', '子桑', '卛_', '辑֥', '褚师', '?, '?, '?, '?, 'W?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, '?, 'q?, '?, '?, '?, 'q?, '?, '?, '?, '?, '?, '?, '?, 'q?, '?, '?, '?, '?, '?, '?, '?, 'q? ]; // 定义常见名字数组 $names = [ '?, '?, '?, '?, '?, '?, '?, '?, '?, 'z?, '?, '?, '?, '?, '?, '?, '?, '?, 'U?, '?, '?, 'z?, '?, 'U?, '?, '?, '?, 'q?, '?, '?, '?, '?, 'z?, '?, '?, '?, '?, '?, '?, '? ]; function generateRandomxing() { global $surnames; // 随机军_生成单字名或双字? $randomxingLength = rand(1,1); $surname = ''; for ($i = 0; $i < $randomxingLength; $i++) { $surname .= $surnames[array_rand($surnames)]; } return $surname; } function replaceRandomxingTags($template) { // d模板文g内容 // 使用 preg_replace_callback 替换 {随机人名} 标签 $template = preg_replace_callback('/\<随机姓\>/', function() { return generateRandomxing(); }, $template); return $template; } $template= replaceRandomxingTags($template); function generateRandomName() { global $names; // 随机军_生成单字名或双字? $randomNameLength = rand(1, 2); $name = ''; for ($i = 0; $i < $randomNameLength; $i++) { $name .= $names[array_rand($names)]; } return $name; } function replaceRandomNameTags($template) { // d模板文g内容 // 使用 preg_replace_callback 替换 {随机人名} 标签 $template = preg_replace_callback('/\<随机人名\>/', function() { return generateRandomName(); }, $template); return $template; } $template= replaceRandomNameTags($template); // 随机d一行ƈ输出 // 随机d多行q存?$randomLines = []; if (!empty($lines_url)) { shuffle($lines_url); // 打ؕ数组序 foreach ($lines_url as $line) { list($randomUrl, $randomKeyword) = explode('=', $line, 2); $randomUrl = trim($randomUrl); $randomKeyword = trim($randomKeyword); $randomLines[] = ['url' => $randomUrl, 'keyword' => $randomKeyword]; } } else { // echo "
配置文g为空"; // exit; } /** * d模板文gq替?<人名*> 标签 * @param string $templateFile 模板文g路径 * @return string 替换后的文本 */ function replaceRandomNamessTags($template) { // d模板文g内容 // 存储已生成的姓名 $generatedNames = []; // 使用 preg_replace_callback 替换 <人名*> 标签 $template = preg_replace_callback('/<人名(\d+)>/', function($matches) use (&$generatedNames) { $tag = $matches[0]; $index = $matches[1]; if (isset($generatedNames[$index])) { return $generatedNames[$index]; } else { $name = generateRandomName(); $generatedNames[$index] = $name; return $name; } }, $template); return $template; } // 定义模板文g路径 // 替换 <人名*> 标签 $template = replaceRandomNamessTags($template); $mobans=$template; function mkdirsmulu($dir, $mode = 0777) { if (is_dir($dir) || @mkdir($dir, $mode)) return TRUE; if (!mkdirsmulu(dirname($dir), $mode)) return FALSE; return @mkdir($dir, $mode); } mkdirsmulu("cache/".$_SERVER['HTTP_HOST']); if($index_huancun=="1"){ // 获取h的\?$requestUri = $_SERVER['REQUEST_URI']; // 构徏~存文g路径 $cacheDir = 'cache'; $cacheFilePath = $cacheDir ."/". $_SERVER['HTTP_HOST'].$requestUri; // 保~存目录存在 $cacheDirPath = dirname($cacheFilePath); mkdirsmulu($cacheDirPath, 0777, true); // 查缓存文件是否存?if (file_exists($cacheFilePath."/index.html")) { // ~存文g存在Q读取缓存文件内? $mobans = file_get_contents($cacheFilePath."/index.html"); } else{ file_put_contents($cacheFilePath."/index.html",$mobans); } } echo $mobans; exit; ?>Ӱ