diff --git a/README.MD b/README.MD index 9745e40..a61d181 100644 --- a/README.MD +++ b/README.MD @@ -66,4 +66,17 @@ - 增加侧边栏显示的全局开关 - 修复代码块中的短代码解析问题 - - 新增一个随机文章阅读的独立页面 \ No newline at end of file + - 新增一个随机文章阅读的独立页面 + +- 2025.08.03 + + - 1.2.3 + + - 修复随机页面在 PJAX 模式下的缓存问题 + - 在随机页面添加缓存控制头,防止 PJAX 缓存 + - 在 JavaScript 中添加随机页面检测,强制刷新确保获取新文章 + - 修复后端登录验证问题,确保密码错误时返回正确的错误信息 + - 重新设计随机页面模板,添加完整的页面结构和加载动画 + - 修复随机页面重定向问题,使用 JavaScript 跳转避免缓存 + - 修复随机页面 JavaScript 错误,移除不存在的 InstantClick.preload 方法调用 + - 优化随机页面跳转逻辑,确保在 PJAX 模式下也能正常自动跳转 \ No newline at end of file diff --git a/page-random.php b/page-random.php index 0385412..0069a61 100644 --- a/page-random.php +++ b/page-random.php @@ -6,38 +6,113 @@ */ if (!defined('__TYPECHO_ROOT_DIR__')) exit; -$db = Typecho_Db::get(); +// 防止 PJAX 缓存,确保每次都是随机文章 +header('Cache-Control: no-cache, no-store, must-revalidate'); +header('Pragma: no-cache'); +header('Expires: 0'); +header('X-InstantClick: no-cache'); -// 统计符合条件的文章总数 -$countSql = $db->select('COUNT(*) AS count') - ->from('table.contents') - ->where('status = ?', 'publish') - ->where('type = ?', 'post') - ->where('created <= ?', time()); -$countResult = $db->fetchRow($countSql); -$total = $countResult['count']; - -if ($total > 0) { - // 随机选择一个偏移量 - $offset = mt_rand(0, $total - 1); - - // 根据偏移量获取一篇文章 - $sql = $db->select() +// 获取随机文章 +function getRandomPost() { + $db = Typecho_Db::get(); + + // 统计符合条件的文章总数 + $countSql = $db->select('COUNT(*) AS count') ->from('table.contents') ->where('status = ?', 'publish') ->where('type = ?', 'post') - ->where('created <= ?', time()) - ->limit(1) - ->offset($offset); + ->where('created <= ?', time()); + $countResult = $db->fetchRow($countSql); + $total = $countResult['count']; - $result = $db->fetchRow($sql); + if ($total > 0) { + // 随机选择一个偏移量 + $offset = mt_rand(0, $total - 1); - if (!empty($result)) { - $target = Typecho_Widget::widget('Widget_Abstract_Contents')->filter($result); - $this->response->redirect($target['permalink'], 307); + // 根据偏移量获取一篇文章 + $sql = $db->select() + ->from('table.contents') + ->where('status = ?', 'publish') + ->where('type = ?', 'post') + ->where('created <= ?', time()) + ->limit(1) + ->offset($offset); + + $result = $db->fetchRow($sql); + + if (!empty($result)) { + $target = Typecho_Widget::widget('Widget_Abstract_Contents')->filter($result); + return $target['permalink']; + } } + + return false; } -// 如果没有找到文章,重定向到首页 -$this->response->redirect($this->options->siteUrl, 307); -?> \ No newline at end of file +// 获取随机文章链接 +$randomPostUrl = getRandomPost(); + +$this->need('header.php'); +?> + +
+
+ options->showsidebar): ?> +
+ +
+ +
+
+

随机阅读

+
+
+
+
+ +

正在为您随机选择一篇文章...

+

请稍候,正在跳转中...

+
+
+ Loading... +
+
+
+
+
+ options->showsidebar): ?> + need('sidebar.php'); ?> + +
+
+ + + +need('footer.php'); ?> \ No newline at end of file diff --git a/page-says.php b/page-says.php index 31b9407..2e692ad 100644 --- a/page-says.php +++ b/page-says.php @@ -70,61 +70,61 @@ $this->need('header.php');
comments()->to($comments); ?> + user->hasLogin() && $this->user->group == 'administrator') : ?> +
+ +
+ + 有什么新鲜事 + +
+
+
+
+ +
+ + + + +
+
+ options->social): ?> + + + + +
+
+
+
+
+ have()): ?> - user->hasLogin() && $this->user->group == 'administrator') : ?> -
- -
- - 有什么新鲜事 - -
-
-
-
- -
- - - - -
-
- options->social): ?> - - - - -
-
-
-
-
- - - next()): ?> - options); ?> - - -
- pageNav('«', '»', 1, '...', array( - 'wrapTag' => 'ul', - 'wrapClass' => 'pagination comment-ajax-load', - 'itemTag' => 'li', - 'textTag' => 'span', - 'currentClass' => 'active', - 'prevClass' => 'prev', - 'nextClass' => 'next' - )); ?> -
- - + + next()): ?> + options); ?> + + +
+ pageNav('«', '»', 1, '...', array( + 'wrapTag' => 'ul', + 'wrapClass' => 'pagination comment-ajax-load', + 'itemTag' => 'li', + 'textTag' => 'span', + 'currentClass' => 'active', + 'prevClass' => 'prev', + 'nextClass' => 'next' + )); ?> +
+ + options->showsidebar): ?> need('sidebar.php'); ?>