diff --git a/archive.php b/archive.php index 8cae77b..49d7269 100644 --- a/archive.php +++ b/archive.php @@ -1,13 +1,5 @@ need('module/header.php'); ?> -travel; -// 处理可能的情况 -$travelId = is_array($travelId) - ? intval(reset($travelId)) - : intval($travelId); -?>

archiveTitle(array( @@ -18,101 +10,33 @@ $travelId = is_array($travelId) 'author' => _t('作者 %s 发布的文章') ), '', ''); ?>

- is('category') && $this->categoryDescription()): ?>
- categorydescription(); ?> + getDescription(); ?>
-
+travel; +$memosId = Helper::options()->memos; +// 安全地获取当前分类 mid +$currentCategory = isset($this->categories[0]['mid']) ? intval($this->categories[0]['mid']) : null; +// 转换为整型(如果需要) +$travelId = is_numeric($travelId) ? intval($travelId) : null; +$memosId = is_numeric($memosId) ? intval($memosId) : null; +?> have()): ?> - -
- next()): ?> - categories, function($carry, $category) use ($travelId) { - return $carry || (intval($category['mid']) === $travelId); - }, false); - if ($istravel): - // 获取文章图片 - $default_thumbnail = Helper::options()->themeUrl . '/assets/images/nopic.svg'; - $firstImage = img_postthumb($this->cid); - if (empty($firstImage)) { - $firstImage = $default_thumbnail; - } - $cover = $this->fields->cover; - $imageToDisplay = $cover; - if (empty($imageToDisplay)) { - $imageToDisplay = $firstImage; - } - ?> -
- <?php $this->title() ?> -
-

- - title() ?> - -

-
- excerpt(20, '...'); ?> -
-
- - - - -
-
-
- - -
- - next()): ?> - categories, function($carry, $category) use ($travelId) { - return $carry || (intval($category['mid']) === $travelId); - }, false); - if (!$istravel): - ?> -
-
-

- title() ?> -

-
- fields->summary - ? $this->fields->summary - : $this->excerpt(180); - ?> -
-
- - - - - - - - category(','); ?> - - commentsNum('0 ', '1 ', '%d '); ?> -
-
-
- - + + + need('module/travel.php'); ?> + + + need('module/memos.php'); ?> + + + need('module/postlist.php'); ?> + + pageNav( ' ', ' ', @@ -130,14 +54,8 @@ $travelId = is_array($travelId) ) ); ?> -
- -
- + + need('module/notfound.php'); ?> +
need('module/footer.php'); ?> \ No newline at end of file diff --git a/functions.php b/functions.php index bea14fa..40146ac 100644 --- a/functions.php +++ b/functions.php @@ -7,8 +7,10 @@ function themeConfig($form) { $form->addInput($icoUrl); $sticky = new Typecho_Widget_Helper_Form_Element_Text('sticky', NULL, NULL, _t('置顶文章cid'), _t('多篇文章以`|`符号隔开'), _t('会在首页展示置顶文章。')); $form->addInput($sticky); - $travel = new Typecho_Widget_Helper_Form_Element_Text('travel', NULL, '3', _t('travel分类 Mid'), _t('多个分类以`|`符号隔开'), _t('指定分类ID,用于区别展示')); + $travel = new Typecho_Widget_Helper_Form_Element_Text('travel', NULL, NULL, _t('travel分类 Mid'), _t('填写分类的mid'), _t('指定分类ID,用于足迹分类展示')); $form->addInput($travel); + $memos = new Typecho_Widget_Helper_Form_Element_Text('memos', NULL, NULL, _t('说说分类 Mid'), _t('填写分类的mid'), _t('指定分类ID,用于说说分类展示')); + $form->addInput($memos); $instagramurl = new Typecho_Widget_Helper_Form_Element_Text('instagramurl', NULL, 'https://Instagram.com/', _t('Instagram'), _t('会在个人信息显示')); $form->addInput($instagramurl); $telegramurl = new Typecho_Widget_Helper_Form_Element_Text('telegramurl', NULL, 'https://t.me/', _t('电报'), _t('会在个人信息显示')); @@ -62,6 +64,24 @@ function saveThemeConfig($config) { // 可以在这里添加额外的验证或处理逻辑 return $config; } +function themeFields($layout) { + $summary= new Typecho_Widget_Helper_Form_Element_Textarea('summary', NULL, NULL, _t('文章摘要'), _t('自定义摘要')); + $layout->addItem($summary); + $cover= new Typecho_Widget_Helper_Form_Element_Text('cover', NULL, NULL, _t('文章封面'), _t('自定义文章封面')); + $layout->addItem($cover); + $douban= new Typecho_Widget_Helper_Form_Element_Text('douban', NULL, NULL, _t('豆瓣API'), _t('自定义页面豆瓣API')); + $layout->addItem($douban); + $neodb= new Typecho_Widget_Helper_Form_Element_Text('neodb', NULL, NULL, _t('NeoDB API'), _t('自定义页面NeoDB API')); + $layout->addItem($neodb); + $tooot= new Typecho_Widget_Helper_Form_Element_Text('tooot', NULL, NULL, _t('Mastodon API'), _t('自定义页面Mastodon API')); + $layout->addItem($tooot); + $memos= new Typecho_Widget_Helper_Form_Element_Text('memos', NULL, NULL, _t('Memos地址'), _t(' 自定义页面Memos地址')); + $layout->addItem($memos); + $memosID= new Typecho_Widget_Helper_Form_Element_Text('memosID', NULL, NULL, _t('Memos ID'), _t('自定义页面Memos ID')); + $layout->addItem($memosID); + $memosnum= new Typecho_Widget_Helper_Form_Element_Text('memosnum', NULL, NULL, _t('Memos数量'), _t('自定义页面Memos数量')); + $layout->addItem($memosnum); +} /* * 文章浏览数统计 */ diff --git a/index.php b/index.php index ea62bc6..b1727ed 100644 --- a/index.php +++ b/index.php @@ -6,12 +6,125 @@ * @version 0.7.0 * @link https://www.imsun.org */ +// 确保退出安全 if (!defined('__TYPECHO_ROOT_DIR__')) exit; -$this->need('module/header.php'); +/** 文章置顶 */ +$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); +} ?> +need('module/header.php');?>
need('module/postlist.php'); ?> +options->loadmore): ?> + pageNav( + ' ', + ' ', + 1, + '...', + array( + 'wrapTag' => 'nav', + 'wrapClass' => 'nav-links nav-links__comment', + 'itemTag' => '', + 'textTag' => 'span', + 'itemClass' => 'page-numbers', + 'currentClass' => 'page-numbers current', + 'prevClass' => 'hidden', + 'nextClass' => 'hidden' + ) + ); + ?> + + _currentPage + 1; +$totalPages = ceil($this->getTotal() / $this->parameter->pageSize); +if ($this->_currentPage < $totalPages): ?> + + + +
need('module/footer.php'); ?> \ No newline at end of file diff --git a/module/memos.php b/module/memos.php new file mode 100644 index 0000000..aef0375 --- /dev/null +++ b/module/memos.php @@ -0,0 +1,17 @@ + +next()): ?> +
+
+
+ + ' class="humane--time" href="permalink() ?>" + itemprop="datePublished"> + date('Y-m-d'); ?> + +
+
+ excerpt(200, '...'); ?> +
+
+
+ \ No newline at end of file diff --git a/module/notfound.php b/module/notfound.php new file mode 100644 index 0000000..834e2ce --- /dev/null +++ b/module/notfound.php @@ -0,0 +1,8 @@ +
+ +
\ No newline at end of file diff --git a/module/postlist.php b/module/postlist.php index 0feb79b..6fc8b18 100644 --- a/module/postlist.php +++ b/module/postlist.php @@ -1,89 +1,3 @@ -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); -} -?> next()): ?>
@@ -149,34 +63,4 @@ foreach ($normalPosts as $normalPost) {
- - options->loadmore): ?> - pageNav( - ' ', - ' ', - 1, - '...', - array( - 'wrapTag' => 'nav', - 'wrapClass' => 'nav-links nav-links__comment', - 'itemTag' => '', - 'textTag' => 'span', - 'itemClass' => 'page-numbers', - 'currentClass' => 'page-numbers current', - 'prevClass' => 'hidden', - 'nextClass' => 'hidden' - ) - ); - ?> - - _currentPage + 1; -$totalPages = ceil($this->getTotal() / $this->parameter->pageSize); -if ($this->_currentPage < $totalPages): ?> - - - - \ No newline at end of file + \ No newline at end of file diff --git a/module/travel.php b/module/travel.php new file mode 100644 index 0000000..8dfe0f7 --- /dev/null +++ b/module/travel.php @@ -0,0 +1,37 @@ + +themeUrl . '/assets/images/nopic.svg'; + $firstImage = img_postthumb($this->cid); + if (empty($firstImage)) { + $firstImage = $default_thumbnail; + } + $cover = $this->fields->cover; + $imageToDisplay = $cover; + if (empty($imageToDisplay)) { + $imageToDisplay = $firstImage; + } +?> +
+next()): ?> +
+ <?php $this->title() ?> +
+

+ + title() ?> + +

+
+ excerpt(20, '...'); ?> +
+
+ + + + +
+
+
+ \ No newline at end of file