Sorry

This feed does not validate.

In addition, interoperability with the widest range of feed readers could be improved by implementing the following recommendation.

Source: https://www.iliiili.com/post/4673910528

  1. <?php
  2.  
  3. // 包含配置文件
  4. include '_config.php';
  5.  
  6. // 获取当前访问的域名
  7. $subDomain = 'https://' . $_SERVER['HTTP_HOST'];
  8.  
  9. // 直接将 actualDirectory 设置为 post
  10. $actualDirectory = 'post';
  11.  
  12. // 获取 URL 参数中的 id 值作为实际路径
  13. $actualPath = isset($_GET['id']) ? $_GET['id'] : '';
  14.  
  15. // 设置本地主域名和链接
  16. $articleUrl = $subDomain . '/' . $actualDirectory . '/' . $actualPath;
  17.  
  18. // 如果没有提供 id 参数,进行重定向
  19. if (empty($actualPath)) {
  20.    header("Location: $home", true, 301);
  21.    exit;
  22. }
  23.  
  24. // 文件路径
  25. $urlFile = 'data/url.txt';
  26. $dataFile = "data/{$lang}_content.txt";
  27. $titleFile = "data/{$lang}_title.txt";
  28. $authorFile = "data/{$lang}_author.txt";
  29. $templateFile = "template/{$lang}_view.htm";
  30.  
  31. // 检查文件是否存在
  32. if (!file_exists($urlFile)) {
  33.    die("URL file does not exist.");
  34. }
  35. if (!file_exists($dataFile)) {
  36.    die("Data file does not exist.");
  37. }
  38. if (!file_exists($titleFile)) {
  39.    die("Title file does not exist.");
  40. }
  41. if (!file_exists($authorFile)) {
  42.    die("Author file does not exist.");
  43. }
  44. if (!file_exists($templateFile)) {
  45.    die("Template file does not exist.");
  46. }
  47.  
  48. // 读取文件内容
  49. $urls = file($urlFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
  50. $data = file($dataFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
  51. $titles = file($titleFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
  52. $authors = file($authorFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
  53. $template = file_get_contents($templateFile);
  54.  
  55. // 随机抽取五条文本
  56. shuffle($data);
  57. $randomTexts = array_slice($data, 0, 5);
  58. $randomTextsHtml = "";
  59. foreach ($randomTexts as $text) {
  60.    $randomTextsHtml .= "<p>$text</p>\n";
  61. }
  62.  
  63. // 随机抽取三条标题并生成三条 10 位的文章 ID
  64. shuffle($titles);
  65. $randomTitles = array_slice($titles, 0, 3);
  66. shuffle($authors);
  67. $randomAuthors = array_slice($authors, 0, 3);
  68. $articleData = [];
  69. for ($i = 0; $i < 3; $i++) {
  70.    $articleId = substr(str_shuffle("0123456789"), 0, 10);
  71.    $coverId = rand(1, 20);
  72.    $userId = rand(1, 20);
  73.  
  74.    // 随机抽取一条文本作为 info
  75.    shuffle($data);
  76.    $info = array_slice($data, 0, 1)[0];
  77.  
  78.    $articleData[] = [
  79.        'title' => $randomTitles[$i],
  80.        'author' => $randomAuthors[$i],
  81.        'id' => '/post/' . $articleId,
  82.        'cover' => $home . "/static/images/post/$coverId.jpg",
  83.        'user' => $home . "/static/images/user/$userId.jpg",
  84.        'subUrl' => 'https://blog-' . $articleId . '.' . $domain . '/post/' . $articleId . '/',
  85.        'info' => $info
  86.    ];
  87. }
  88.  
  89. // 随机抽取一条标题作为主标题
  90. $randomTitle = $titles[array_rand($titles)];
  91. $randomAuthor = $authors[array_rand($authors)];
  92.  
  93. // 获取当前服务器时间并格式化
  94. $currentDate = date('F j, Y');
  95. $currentYear = date('Y');
  96.  
  97. // 生成链接 HTML,使用当前访问的域名和 post 目录
  98. $linksHtml = "";
  99.  
  100. // 读取 url.txt 文件中的链接,并生成 HTML
  101. if (file_exists($urlFile)) {
  102.    $urls = file($urlFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
  103.    foreach ($urls as $url) {
  104.        // 使用当前域名替换 {{url}} 部分
  105.        $logicLink = str_replace('{{url}}', $subDomain . '/' . $actualDirectory . '/' . $actualPath, $url);
  106.        // 生成链接的 HTML
  107.        $linksHtml .= '<a href="' . htmlspecialchars($logicLink) . '" target="_blank" class="custom-link">External link</a>' . "\n";
  108.    }
  109. } else {
  110.    $linksHtml = '<p>File not found: ' . htmlspecialchars($urlFile) . '</p>';
  111. }
  112.  
  113. // 随机 6 位数
  114. function generateRandomId($length = 6) {
  115.    $characters = '0123456789';
  116.    $charactersLength = strlen($characters);
  117.    $randomId = '';
  118.    for ($i = 0; $i < $length; $i++) {
  119.        $randomId .= $characters[rand(0, $charactersLength - 1)];
  120.    }
  121.    return $randomId;
  122. }
  123. $randomId = generateRandomId();
  124.  
  125. // 替换模板中的占位符
  126. $placeholders = [
  127.    '{{id}}',
  128.    '{{title}}',
  129.    '{{author}}',
  130.    '{{randomTexts}}',
  131.    '{{links}}',
  132.    '{{year}}',
  133.    '{{date}}',
  134.    '{{cover}}',
  135.    '{{user}}',
  136.    '{{lang}}',
  137.    '{{home}}',
  138.    '{{articleUrl}}'
  139. ];
  140.  
  141. // 添加文章相关的占位符
  142. for ($i = 1; $i <= 3; $i++) {
  143.    $placeholders[] = "{{article{$i}_title}}";
  144.    $placeholders[] = "{{article{$i}_author}}";
  145.    $placeholders[] = "{{article{$i}_id}}";
  146.    $placeholders[] = "{{article{$i}_cover}}";
  147.    $placeholders[] = "{{article{$i}_user}}";
  148.    $placeholders[] = "{{article{$i}_subUrl}}";
  149.    $placeholders[] = "{{article{$i}_info}}";
  150. }
  151.  
  152. // 生成对应的替换值
  153. $replaceValues = [
  154.    $randomId,
  155.    $randomTitle,
  156.    $randomAuthor,
  157.    $randomTextsHtml,
  158.    $linksHtml,
  159.    $currentYear,
  160.    $currentDate,
  161.    $articleData[0]['cover'],  // Assuming cover for the first article
  162.    $articleData[0]['user'],   // Assuming user for the first article
  163.    $lang,
  164.    $home,
  165.    $articleUrl               // New article URL structure
  166. ];
  167.  
  168. // 添加文章相关的替换值
  169. foreach ($articleData as $index => $article) {
  170.    $replaceValues[] = $article['title'];
  171.    $replaceValues[] = $article['author'];
  172.    $replaceValues[] = $article['id'];
  173.    $replaceValues[] = $article['cover'];
  174.    $replaceValues[] = $article['user'];
  175.    $replaceValues[] = $article['subUrl'];
  176.    $replaceValues[] = $article['info'];
  177. }
  178.  
  179. // 执行替换
  180. $html = str_replace($placeholders, $replaceValues, $template);
  181.  
  182. // 输出 HTML 内容
  183. echo $html;
  184. ?>
Copyright © 2002-9 Sam Ruby, Mark Pilgrim, Joseph Walton, and Phil Ringnalda