From 4dce3365b6a67e4d765f6d693f6671c388cb418f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B5=AA=E5=AD=90?= Date: Mon, 7 Apr 2025 09:14:37 +0800 Subject: [PATCH] 0.7.1 --- header.php | 2 +- index.php | 87 ++-------------------------------------------- module/related.php | 4 ++- module/sticky.php | 85 ++++++++++++++++++++++++++++++++++++++++++++ page-links.php | 8 ++--- 5 files changed, 93 insertions(+), 93 deletions(-) create mode 100644 module/sticky.php diff --git a/header.php b/header.php index 1a79453..61559b9 100644 --- a/header.php +++ b/header.php @@ -77,4 +77,4 @@ if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?> d="M20.067 18.933l-4.157-4.157a6 6 0 1 0-.884.884l4.157 4.157a.624.624 0 1 0 .884-.884zM6.5 11c0-2.62 2.13-4.75 4.75-4.75S16 8.38 16 11s-2.13 4.75-4.75 4.75S6.5 13.62 6.5 11z"> - \ No newline at end of file + \ No newline at end of file diff --git a/index.php b/index.php index 9998722..3650e30 100644 --- a/index.php +++ b/index.php @@ -6,91 +6,8 @@ * @version 0.7.1 * @link https://www.imsun.org */ -// 确保退出安全 -if (!defined('__TYPECHO_ROOT_DIR__')) exit; -/** 文章置顶 */ -$sticky = $this->options->sticky; // 置顶的文章id,多个用|隔开 -$db = Typecho_Db::get(); -$pageSize = $this->options->pageSize; -if ($sticky && !empty(trim($sticky))) { - $sticky_cids = array_filter(explode('|', $sticky)); // 分割文本并过滤空值 - if (!empty($sticky_cids)) { - $sticky_html = " 置顶 "; // 置顶标题的 html - // 清空原有文章的队列 - $this->row = []; - $this->stack = []; - $this->length = 0; - // 获取总数,并排除置顶文章数量 - if (isset($this->currentPage) && $this->currentPage == 1) { - $totalOriginal = $this->getTotal(); - $stickyCount = count($sticky_cids); - $this->setTotal(max($totalOriginal - $stickyCount, 0)); - // 构建置顶文章的查询 - $selectSticky = $this->select()->where('type = ?', 'post'); - foreach ($sticky_cids as $i => $cid) { - if ($i == 0) - $selectSticky->where('cid = ?', $cid); - else - $selectSticky->orWhere('cid = ?', $cid); - } - // 获取置顶文章 - $stickyPosts = $db->fetchAll($selectSticky); - // 压入置顶文章到文章队列 - foreach ($stickyPosts as &$stickyPost) { - $stickyPost['title'] .= $sticky_html; - $this->push($stickyPost); - } - $standardPageSize = $pageSize - count($stickyPosts); - } else { - $standardPageSize = $pageSize; - } - // 构建正常文章查询,排除置顶文章 - $selectNormal = $this->select() - ->where('type = ?', 'post') - ->where('status = ?', 'publish') - ->where('created < ?', time()) - ->order('created', Typecho_Db::SORT_DESC) - ->page(isset($this->currentPage) ? $this->currentPage : 1, $standardPageSize); - foreach ($sticky_cids as $cid) { - $selectNormal->where('table.contents.cid != ?', $cid); - } - } else { - // 如果sticky_cids为空,使用默认查询 - $selectNormal = $this->select() - ->where('type = ?', 'post') - ->where('status = ?', 'publish') - ->where('created < ?', time()) - ->order('created', Typecho_Db::SORT_DESC) - ->page(isset($this->currentPage) ? $this->currentPage : 1, $pageSize); - } -} else { - // 如果没有置顶文章,使用默认查询 - $selectNormal = $this->select() - ->where('type = ?', 'post') - ->where('status = ?', 'publish') - ->where('created < ?', time()) - ->order('created', Typecho_Db::SORT_DESC) - ->page(isset($this->currentPage) ? $this->currentPage : 1, $pageSize); -} -// 登录用户显示私密文章 -if ($this->user->hasLogin()) { - $uid = $this->user->uid; - if ($uid) { - $selectNormal->orWhere('authorId = ? AND status = ?', $uid, 'private'); - } -} -$normalPosts = $db->fetchAll($selectNormal); -// 如果之前没有清空队列(没有置顶文章的情况),现在清空 -if (empty($sticky) || empty(trim($sticky)) || empty($sticky_cids)) { - $this->row = []; - $this->stack = []; - $this->length = 0; -} -// 压入正常文章到文章队列 -foreach ($normalPosts as $normalPost) { - $this->push($normalPost); -} -?> +if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?> +need('module/sticky.php'); ?> need('header.php');?>
diff --git a/module/related.php b/module/related.php index 79c2361..6c90e8f 100644 --- a/module/related.php +++ b/module/related.php @@ -1,8 +1,9 @@ \ No newline at end of file diff --git a/module/sticky.php b/module/sticky.php new file mode 100644 index 0000000..689cc9f --- /dev/null +++ b/module/sticky.php @@ -0,0 +1,85 @@ + +options->sticky; // 置顶的文章id,多个用|隔开 +$db = Typecho_Db::get(); +$pageSize = $this->options->pageSize; +if ($sticky && !empty(trim($sticky))) { + $sticky_cids = array_filter(explode('|', $sticky)); // 分割文本并过滤空值 + if (!empty($sticky_cids)) { + $sticky_html = " 置顶 "; // 置顶标题的 html + // 清空原有文章的队列 + $this->row = []; + $this->stack = []; + $this->length = 0; + // 获取总数,并排除置顶文章数量 + if (isset($this->currentPage) && $this->currentPage == 1) { + $totalOriginal = $this->getTotal(); + $stickyCount = count($sticky_cids); + $this->setTotal(max($totalOriginal - $stickyCount, 0)); + // 构建置顶文章的查询 + $selectSticky = $this->select()->where('type = ?', 'post'); + foreach ($sticky_cids as $i => $cid) { + if ($i == 0) + $selectSticky->where('cid = ?', $cid); + else + $selectSticky->orWhere('cid = ?', $cid); + } + // 获取置顶文章 + $stickyPosts = $db->fetchAll($selectSticky); + // 压入置顶文章到文章队列 + foreach ($stickyPosts as &$stickyPost) { + $stickyPost['title'] .= $sticky_html; + $this->push($stickyPost); + } + $standardPageSize = $pageSize - count($stickyPosts); + } else { + $standardPageSize = $pageSize; + } + // 构建正常文章查询,排除置顶文章 + $selectNormal = $this->select() + ->where('type = ?', 'post') + ->where('status = ?', 'publish') + ->where('created < ?', time()) + ->order('created', Typecho_Db::SORT_DESC) + ->page(isset($this->currentPage) ? $this->currentPage : 1, $standardPageSize); + foreach ($sticky_cids as $cid) { + $selectNormal->where('table.contents.cid != ?', $cid); + } + } else { + // 如果sticky_cids为空,使用默认查询 + $selectNormal = $this->select() + ->where('type = ?', 'post') + ->where('status = ?', 'publish') + ->where('created < ?', time()) + ->order('created', Typecho_Db::SORT_DESC) + ->page(isset($this->currentPage) ? $this->currentPage : 1, $pageSize); + } +} else { + // 如果没有置顶文章,使用默认查询 + $selectNormal = $this->select() + ->where('type = ?', 'post') + ->where('status = ?', 'publish') + ->where('created < ?', time()) + ->order('created', Typecho_Db::SORT_DESC) + ->page(isset($this->currentPage) ? $this->currentPage : 1, $pageSize); +} +// 登录用户显示私密文章 +if ($this->user->hasLogin()) { + $uid = $this->user->uid; + if ($uid) { + $selectNormal->orWhere('authorId = ? AND status = ?', $uid, 'private'); + } +} +$normalPosts = $db->fetchAll($selectNormal); +// 如果之前没有清空队列(没有置顶文章的情况),现在清空 +if (empty($sticky) || empty(trim($sticky)) || empty($sticky_cids)) { + $this->row = []; + $this->stack = []; + $this->length = 0; +} +// 压入正常文章到文章队列 +foreach ($normalPosts as $normalPost) { + $this->push($normalPost); +} +?> \ No newline at end of file diff --git a/page-links.php b/page-links.php index 7f3796c..66b1943 100644 --- a/page-links.php +++ b/page-links.php @@ -13,16 +13,12 @@ if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?>
allow('comment')): ?> - need('./module/comments.php'); ?> + need('module/comments.php'); ?>