This feed does not validate.
In addition, interoperability with the widest range of feed readers could be improved by implementing the following recommendation.
help]
[<?php
// 包含配置文件
include '_config.php';
// 获取当前访问的域名
$subDomain = 'https://' . $_SERVER['HTTP_HOST'];
// 直接将 actualDirectory 设置为 post
$actualDirectory = 'post';
// 获取 URL 参数中的 id 值作为实际路径
$actualPath = isset($_GET['id']) ? $_GET['id'] : '';
// 设置本地主域名和链接
$articleUrl = $subDomain . '/' . $actualDirectory . '/' . $actualPath;
// 如果没有提供 id 参数,进行重定向
if (empty($actualPath)) {
header("Location: $home", true, 301);
exit;
}
// 文件路径
$urlFile = 'data/url.txt';
$dataFile = "data/{$lang}_content.txt";
$titleFile = "data/{$lang}_title.txt";
$authorFile = "data/{$lang}_author.txt";
$templateFile = "template/{$lang}_view.htm";
// 检查文件是否存在
if (!file_exists($urlFile)) {
die("URL file does not exist.");
}
if (!file_exists($dataFile)) {
die("Data file does not exist.");
}
if (!file_exists($titleFile)) {
die("Title file does not exist.");
}
if (!file_exists($authorFile)) {
die("Author file does not exist.");
}
if (!file_exists($templateFile)) {
die("Template file does not exist.");
}
// 读取文件内容
$urls = file($urlFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
$data = file($dataFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
$titles = file($titleFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
$authors = file($authorFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
$template = file_get_contents($templateFile);
// 随机抽取五条文本
shuffle($data);
$randomTexts = array_slice($data, 0, 5);
$randomTextsHtml = "";
foreach ($randomTexts as $text) {
$randomTextsHtml .= "<p>$text</p>\n";
}
// 随机抽取三条标题并生成三条 10 位的文章 ID
shuffle($titles);
$randomTitles = array_slice($titles, 0, 3);
shuffle($authors);
$randomAuthors = array_slice($authors, 0, 3);
$articleData = [];
for ($i = 0; $i < 3; $i++) {
$articleId = substr(str_shuffle("0123456789"), 0, 10);
$coverId = rand(1, 20);
$userId = rand(1, 20);
// 随机抽取一条文本作为 info
shuffle($data);
$info = array_slice($data, 0, 1)[0];
$articleData[] = [
'title' => $randomTitles[$i],
'author' => $randomAuthors[$i],
'id' => '/post/' . $articleId,
'cover' => $home . "/static/images/post/$coverId.jpg",
'user' => $home . "/static/images/user/$userId.jpg",
'subUrl' => 'https://blog-' . $articleId . '.' . $domain . '/post/' . $articleId . '/',
'info' => $info
];
}
// 随机抽取一条标题作为主标题
$randomTitle = $titles[array_rand($titles)];
$randomAuthor = $authors[array_rand($authors)];
// 获取当前服务器时间并格式化
$currentDate = date('F j, Y');
$currentYear = date('Y');
// 生成链接 HTML,使用当前访问的域名和 post 目录
$linksHtml = "";
// 读取 url.txt 文件中的链接,并生成 HTML
if (file_exists($urlFile)) {
$urls = file($urlFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
foreach ($urls as $url) {
// 使用当前域名替换 {{url}} 部分
$logicLink = str_replace('{{url}}', $subDomain . '/' . $actualDirectory . '/' . $actualPath, $url);
// 生成链接的 HTML
$linksHtml .= '<a href="' . htmlspecialchars($logicLink) . '" target="_blank" class="custom-link">External link</a>' . "\n";
}
} else {
$linksHtml = '<p>File not found: ' . htmlspecialchars($urlFile) . '</p>';
}
// 随机 6 位数
function generateRandomId($length = 6) {
$characters = '0123456789';
$charactersLength = strlen($characters);
$randomId = '';
for ($i = 0; $i < $length; $i++) {
$randomId .= $characters[rand(0, $charactersLength - 1)];
}
return $randomId;
}
$randomId = generateRandomId();
// 替换模板中的占位符
$placeholders = [
'{{id}}',
'{{title}}',
'{{author}}',
'{{randomTexts}}',
'{{links}}',
'{{year}}',
'{{date}}',
'{{cover}}',
'{{user}}',
'{{lang}}',
'{{home}}',
'{{articleUrl}}'
];
// 添加文章相关的占位符
for ($i = 1; $i <= 3; $i++) {
$placeholders[] = "{{article{$i}_title}}";
$placeholders[] = "{{article{$i}_author}}";
$placeholders[] = "{{article{$i}_id}}";
$placeholders[] = "{{article{$i}_cover}}";
$placeholders[] = "{{article{$i}_user}}";
$placeholders[] = "{{article{$i}_subUrl}}";
$placeholders[] = "{{article{$i}_info}}";
}
// 生成对应的替换值
$replaceValues = [
$randomId,
$randomTitle,
$randomAuthor,
$randomTextsHtml,
$linksHtml,
$currentYear,
$currentDate,
$articleData[0]['cover'], // Assuming cover for the first article
$articleData[0]['user'], // Assuming user for the first article
$lang,
$home,
$articleUrl // New article URL structure
];
// 添加文章相关的替换值
foreach ($articleData as $index => $article) {
$replaceValues[] = $article['title'];
$replaceValues[] = $article['author'];
$replaceValues[] = $article['id'];
$replaceValues[] = $article['cover'];
$replaceValues[] = $article['user'];
$replaceValues[] = $article['subUrl'];
$replaceValues[] = $article['info'];
}
// 执行替换
$html = str_replace($placeholders, $replaceValues, $template);
// 输出 HTML 内容
echo $html;
?>