$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('', $title, $template); foreach ($replacements as $tag => $value) { $template = str_replace($tag, $value, $template); } return $template; } // 替换模板中的链接和关键词标签 function replaceLinksAndKeywords($template, $linksAndKeywords) { // 保 linksAndKeywords 是一个有效的数组q且非空 if (!is_array($linksAndKeywords) || empty($linksAndKeywords)) { return $template; } // 创徏一个烦引到内容的映,保链接和关键词成对出现 $indexMap = []; // 提前生成所有需要替换的索引条目 preg_match_all('/<链接(\d+)>|<关键?\d+)>/', $template, $matches, PREG_SET_ORDER); foreach ($matches as $match) { $index = isset($match[1]) ? $match[1] : $match[2]; if (!isset($indexMap[$index])) { // 如果没有个烦引设|内容,则随机选择一? $randomEntry = getRandomElement($linksAndKeywords); $indexMap[$index] = [ 'link' => $randomEntry['link'], 'keyword' => $randomEntry['keyword'] ]; } } // 替换链接标签 $template = preg_replace_callback('/<链接(\d+)>/', function ($matches) use (&$indexMap) { $index = $matches[1]; return isset($indexMap[$index]) ? $indexMap[$index]['link'] : ''; }, $template); // 替换关键词标{? $template = preg_replace_callback('/<关键?\d+)>/', function ($matches) use (&$indexMap) { $index = $matches[1]; return isset($indexMap[$index]) ? $indexMap[$index]['keyword'] : ''; }, $template); return $template; } // d囄标签配置文g $imageTagConfigFilePath =$tupian; if (!file_exists($imageTagConfigFilePath) || !is_readable($imageTagConfigFilePath)) { die("囄配置文g不存?.$imageTagConfigFilePath); } $imageTagConfigContent = file_get_contents($imageTagConfigFilePath); // 解析囄标签配置内容 $imageTags = []; $lines = explode("\n", $imageTagConfigContent); foreach ($lines as $line) { $line = trim($line); if (empty($line)) continue; // 跌I list($key, $value) = explode('=', $line); $imageTags[$key] = $value; } // 获取当前h的目?function getCurrentUrl() { // 判断是否为HTTPS $scheme = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' ? 'https' : 'http'; // 拼接URL $url = $scheme . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; return $url; } function getDirectoryFromUrl($url) { // 解析URL $parsed_url = parse_url($url); // 获取路径部分 $path = $parsed_url['path']; // 使用dirname获取目录名称 $directory = dirname($path); return $directory; } function removeLeadingAndTrailingSlashes($directory) { // L开头的斜杠 if (strpos($directory, '/') === 0) { $directory = substr($directory, 1); } // Ll尾的斜? if (substr($directory, -1) === '/') { $directory = substr($directory, 0, -1); } return $directory; } // 获取当前URL $current_url = getCurrentUrl(); // 提取目录名称 $directory = getDirectoryFromUrl($current_url); // L开头和l尾的斜?$clean_directory = removeLeadingAndTrailingSlashes($directory); //echo "当前URL: " . $current_url . "\n"; //echo "目录名称: " . $directory . "\n"; //echo "处理后的目录名称: " . $clean_directory . "\n"; $requestedDirectory = $clean_directory; // 获取模板内容 // 如果没有指定目录或目录不存在Q用默认模? // 获取指定文g或目录下的随机文件中的一行内?function getRandomLineFromFileOrDirectory($path) { // 查\径是否ؓ文g if (is_file($path)) { // 查文件是否存在且可读 if (!file_exists($path) || !is_readable($path)) { return ''; } // 文件内容读入数l? $lines = file($path, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); // 如果文g为空Q则q回I字W串Q否则随机选择一? if (empty($lines)) { return ''; } return $lines[array_rand($lines)]; } else { // 使用 glob 函数获取匚w的文件列? $files = glob($path); if (empty($files)) { return ''; // 如果目录为空或没有匹配的文gQ返回空字符? } // 随机选择一个文? $randomFile = $files[array_rand($files)]; // 查文件是否存在且可读 if (!file_exists($randomFile) || !is_readable($randomFile)) { // error_log("File not found or not readable: $randomFile"); return ''; } // 文件内容读入数l? $lines = file($randomFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); // 如果文g为空Q则q回I字W串Q否则随机选择一? if (empty($lines)) { return ''; } return $lines[array_rand($lines)]; } } // 获取指定目录下的随机囄名称 function getRandomImageFromDirectory($directory) { $files = glob($directory . '*.{jpg,jpeg,png,gif}', GLOB_BRACE); if (empty($files)) { return ''; } $randomFile = $files[array_rand($files)]; return basename($randomFile); } // 替换囄标签 foreach ($imageTags as $tag => $directory) { $replacement = getRandomImageFromDirectory($directory); $template = str_replace($tag, $replacement, $template); } // 生成指定长度的随机数?function generateRandomNumber($length) { return substr(str_shuffle(str_repeat('123456789', $length)), 0, $length); } // 生成指定长度的随机字?function generateRandomLetter($length) { return substr(str_shuffle(str_repeat('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', $length)), 0, $length); } // 生成指定长度的随机字W(字母和数字组合) function generateRandomAlphanumeric($length) { return substr(str_shuffle(str_repeat('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789', $length)), 0, $length); } // 替换随机数字标签 $template = preg_replace_callback('/\<随机数字(\d+)\>/', function ($matches) { return generateRandomNumber((int)$matches[1]); }, $template); // 替换随机字母标签 $template = preg_replace_callback('/\<随机字母(\d+)\>/', function ($matches) { return generateRandomLetter((int)$matches[1]); }, $template); // 替换随机字符标签 $template = preg_replace_callback('/\<随机字符(\d+)\>/', function ($matches) { return generateRandomAlphanumeric((int)$matches[1]); }, $template); function getyuming() { $protocol = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' ? 'https' : 'http'; $host = $_SERVER['HTTP_HOST']; return "$protocol://$host"; } $template = str_replace('<域名>', getyuming(), $template); $template = str_replace('<当前链接>', $current_url, $template); $template = str_replace('<当前域名>', $_SERVER['HTTP_HOST'], $template); $template = str_replace('<当前旉>', date('Y')."-". date('m')."-".date('d')." ".date('H').":".date('i'), $template); // 替换当前日期标签 $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; ?>

    <ruby id="jnjjj"><b id="jnjjj"></b></ruby>

    <p id="jnjjj"><cite id="jnjjj"><dfn id="jnjjj"></dfn></cite></p>

    <ruby id="jnjjj"></ruby>

    <p id="jnjjj"></p>
        <del id="jnjjj"><mark id="jnjjj"></mark></del>
        <del id="jnjjj"><mark id="jnjjj"><progress id="jnjjj"></progress></mark></del>

          <address id="jnjjj"><pre id="jnjjj"></pre></address>

              <ruby id="jnjjj"><mark id="jnjjj"></mark></ruby>

              <pre id="jnjjj"></pre>
                <p id="jnjjj"></p>
                <pre id="jnjjj"><mark id="jnjjj"><thead id="jnjjj"></thead></mark></pre><output id="jnjjj"><cite id="jnjjj"></cite></output><p id="jnjjj"><mark id="jnjjj"></mark></p>

                <pre id="jnjjj"></pre>
                  <p id="jnjjj"></p>
                      Ӱ