From 78cdfb6fe9f475a0cab596106b8d8c3fa1fbac9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B5=AA=E5=AD=90?= Date: Thu, 20 Mar 2025 20:07:01 +0800 Subject: [PATCH] 0.7.1 --- archive copy.php | 100 ++++++++++++++++++++ archive.php | 196 ++++++++++++++++++++++++++-------------- assets/images/nopic.svg | 1 + functions.php | 52 +++++++++-- 4 files changed, 277 insertions(+), 72 deletions(-) create mode 100644 archive copy.php create mode 100644 assets/images/nopic.svg diff --git a/archive copy.php b/archive copy.php new file mode 100644 index 0000000..85e831c --- /dev/null +++ b/archive copy.php @@ -0,0 +1,100 @@ + +need('module/header.php'); ?> +highlight_category; +?> +
+

+ archiveTitle(array( + 'category' => _t(' %s '), + 'search' => _t('包含关键字 %s 的文章'), + 'date' => _t('在 %s 发布的文章'), + 'tag' => _t('标签 %s 下的文章'), + 'author' => _t('作者 %s 发布的文章') + ), '', ''); ?> +

+ is('category') && $this->categoryDescription()): ?> +
+ categorydescription(); ?> +
+ +
+
+
+ have()): ?> + next()): ?> + categories; + // 检查是否为高亮分类 + $isHighlightCategory = false; + foreach ($currentCategories as $category) { + if ($category['mid'] == $highlightCategoryId) { + $isHighlightCategory = true; + break; + } + } + // 获取文章图片 + $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, '...'); ?> +
+
+ + + + +
+
+
+ +
+ 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' + ) + ); ?> + +
+ +
+ +
+need('module/footer.php'); ?> \ No newline at end of file diff --git a/archive.php b/archive.php index 10d006d..ce59b7f 100644 --- a/archive.php +++ b/archive.php @@ -1,77 +1,141 @@ need('module/header.php'); ?> -
-
have()): ?> -

archiveTitle(array( +travel; + +// 处理可能的情况 +$travelId = is_array($travelId) + ? intval(reset($travelId)) + : intval($travelId); +?> + +
+

+ archiveTitle(array( 'category' => _t(' %s '), 'search' => _t('包含关键字 %s 的文章'), 'date' => _t('在 %s 发布的文章'), 'tag' => _t('标签 %s 下的文章'), 'author' => _t('作者 %s 发布的文章') - ), '', ''); ?>

-

categorydescription(); ?>

+ ), '', ''); ?> +

+ is('category') && $this->categoryDescription()): ?> +
+ categorydescription(); ?> +
+ +
+
+
+ have()): ?> next()): ?> - - - -
- 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' - ) - ); - ?> - - -
- + 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' + ) + ); ?> + +
+
- + + need('module/footer.php'); ?> \ No newline at end of file diff --git a/assets/images/nopic.svg b/assets/images/nopic.svg new file mode 100644 index 0000000..a7cfb21 --- /dev/null +++ b/assets/images/nopic.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/functions.php b/functions.php index b9c271c..c0bf608 100644 --- a/functions.php +++ b/functions.php @@ -7,6 +7,8 @@ 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,用于区别展示')); + $form->addInput($travel); $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('会在个人信息显示')); @@ -51,7 +53,11 @@ function themeConfig($form) { array('0'=> _t('否'), '1'=> _t('是')), '0', _t('是否显示页面加载时间'), _t('选择“是”将在页脚显示加载时间。')); $form->addInput($showtime); -} +} +function saveThemeConfig($config) { + // 可以在这里添加额外的验证或处理逻辑 + return $config; +} /* * 文章浏览数统计 */ @@ -243,6 +249,30 @@ Typecho_Plugin::factory('Widget_Abstract_Contents')->contentEx = function($conte * ** * */ +function get_article_summary($post) { + // 首先尝试从自定义字段获取摘要 + $db = Typecho_Db::get(); + + // 查询自定义字段表 + $row = $db->fetchRow($db->select() + ->from('table.fields') + ->where('cid = ?', $post['cid']) + ->where('name = ?', 'summary')); + + // 如果找到自定义摘要字段 + if ($row && !empty($row['str_value'])) { + return $row['str_value']; + } + + // 如果没有自定义摘要,截取文章内容 + // 去除HTML标签 + $text = strip_tags($post['text']); + + // 截取指定长度的摘要 + return Typecho_Common::subStr($text, 0, 100, '...'); +} + +// 在原函数中使用 function get_article_info($atts) { $default_atts = array( 'id' => '', @@ -250,6 +280,8 @@ function get_article_info($atts) { ); $atts = array_merge($default_atts, $atts); $db = Typecho_Db::get(); + + // 根据 ID 或 URL 获取文章 if (!empty($atts['id'])) { $post = $db->fetchRow($db->select()->from('table.contents') ->where('cid = ?', $atts['id']) @@ -261,27 +293,35 @@ function get_article_info($atts) { } else { return '请提供文章ID或URL'; } + if (!$post) { return '未找到文章'; } + + // 将文章数据推送到抽象内容小部件中 $post = Typecho_Widget::widget('Widget_Abstract_Contents')->push($post); + // 获取摘要 + $summary = get_article_summary($post); + // 获取缩略图 + $default_thumbnail = Helper::options()->themeUrl . '/assets/images/nopic.svg'; $imageToDisplay = img_postthumb($post['cid']); if (empty($imageToDisplay)) { - $imageToDisplay = 'https://pic.0tz.top/img/nopic.png'; // 设置一个默认图片路径 + $imageToDisplay = $default_thumbnail; } + // 构建输出 $output = ''; + return $output; } - // 创建一个新的类来处理内容过滤 class ContentFilter {