7 Commits

Author SHA1 Message Date
浪子 a6883c5ce7 0.7.1
在后台撰写文章增加一个批量插入附件的按钮
2025-04-07 10:55:57 +08:00
浪子 4dce3365b6 0.7.1 2025-04-07 09:14:37 +08:00
浪子 26e2c5b40c 0.7.1 2025-04-02 11:37:35 +08:00
浪子 c5eb0aa112 0.7.1
更新说明
2025-03-27 10:03:28 +08:00
浪子 cd3933ea53 0.7.1 2025-03-27 09:36:15 +08:00
浪子 482e9a1e93 0.7.1
修复了一个<div>未闭合的bug

优化分页和加载更多逻辑
2025-03-26 09:14:45 +08:00
浪子 13c3587762 add
显示详细的时间
2025-03-25 18:43:19 +08:00
27 changed files with 294 additions and 510 deletions
+6
View File
@@ -7,6 +7,12 @@
## 更新日志 & 预览
### 0.7.1
- 调整了赞赏的样式,同时填写支付宝和微信收款码的图片地址即可显示
- 调整文章列表的加载方式
- 调整了文件的结构
### 0.7.0
根据原版更新,修复了一些问题,并添加了一些功能
+3 -18
View File
@@ -1,5 +1,5 @@
<?php if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?>
<?php $this->need('module/header.php'); ?>
<?php $this->need('header.php'); ?>
<header class="archive--header">
<h2 class="post--single__title">
<?php $this->archiveTitle(array(
@@ -37,25 +37,10 @@ $memosId = is_numeric($memosId) ? intval($memosId) : null;
<?php $this->need('module/postlist.php'); ?>
<?php endif; ?>
<!-- 分页导航 -->
<?php $this->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'
)
); ?>
<?php $this->need('module/paging.php'); ?>
<?php else: ?>
<!-- 无结果 -->
<?php $this->need('module/notfound.php'); ?>
<?php endif; ?>
</div>
<?php $this->need('module/footer.php'); ?>
<?php $this->need('footer.php'); ?>
-146
View File
@@ -1,146 +0,0 @@
.donate-panel {
position: relative;
display: inline-block;
}
.button--like {
background: none;
border: none;
padding: 0;
cursor: pointer;
transition: transform 0.3s ease;
}
.button--like:hover {
transform: scale(1.1);
}
.icon--default {
fill: #666;
transition: fill 0.3s ease;
}
.button--like:hover .icon--default {
fill: #ff4081;
}
#qrcode-panel {
position: absolute;
bottom: 100%;
left: 50%;
transform: translateX(-50%);
background: white;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
padding: 15px;
margin-bottom: 10px;
display: none;
animation: fadeIn 0.3s ease;
min-width: 240px;
}
@keyframes fadeIn {
from {
opacity: 0;
transform: translate(-50%, 10px);
}
to {
opacity: 1;
transform: translate(-50%, 0);
}
}
.qrcode-body {
text-align: center;
}
.donate-memo {
margin-bottom: 10px;
position: relative;
}
#donate-close {
position: absolute;
right: -5px;
top: -5px;
cursor: pointer;
font-size: 12px;
color: #666;
padding: 2px 5px;
border-radius: 3px;
}
#donate-close:hover {
color: #ff4081;
}
.donate-qrpay img {
max-width: 240px;
height: auto;
display: block;
margin: 0 auto;
transition: opacity 0.3s ease;
}
/* 支付方式切换按钮样式 */
.donate-methods {
display: flex;
justify-content: center;
margin-bottom: 15px;
gap: 10px;
}
.donate-method-btn {
padding: 5px 15px;
border: none;
border-radius: 15px;
cursor: pointer;
background: #f5f5f5;
color: #666;
font-size: 14px;
transition: all 0.3s ease;
}
.donate-method-btn.active {
background: #ff4081;
color: white;
}
.donate-method-btn:hover {
background: #ff4081;
color: white;
}
/* QR码容器样式 */
.qr-container {
position: relative;
height: 100%;
width: 100%;
margin: 0 auto;
}
.qr-image {
position: absolute;
top: 0;
left: 0;
opacity: 0;
visibility: hidden;
transition: opacity 0.3s ease, visibility 0.3s ease;
}
.qr-image.active {
opacity: 1;
visibility: visible;
}
/* 小三角形 */
#qrcode-panel:after {
content: '';
position: absolute;
bottom: -8px;
left: 50%;
transform: translateX(-50%);
border-left: 8px solid transparent;
border-right: 8px solid transparent;
border-top: 8px solid white;
}
+2 -2
View File
@@ -17,7 +17,7 @@
is_single = false;
post_id = 0;
is_archive = false;
VERSION = "0.7.0";
VERSION = "0.7.1";
constructor() {
super();
this.initCopyright();
@@ -46,7 +46,7 @@
}
initCopyright() {
const copyright = `<div class="site--footer__info">由<a href="https://www.typecho.org" target="_blank">Typecho</a> 驱动 <br>
Theme <a href="https://fatesinger.com/101971" target="_blank">farallon</a> by bigfa &nbsp;<br>Made with<a href="https://www.imsun.org" target="_blank"> Sun</a> / version ${this.VERSION}
Theme <a href="https://fatesinger.com/101971" target="_blank">farallon</a> by bigfa &nbsp;<br>Made with<a href="https://www.imsun.org" target="_blank">jkjoy</a> / version ${this.VERSION}
</div>`;
document.querySelector(".site--footer__content").insertAdjacentHTML("afterend", copyright);
document.querySelector(".icon--copryrights").addEventListener("click", () => {
-65
View File
@@ -1,65 +0,0 @@
document.addEventListener('DOMContentLoaded', function() {
const donateBtn = document.getElementById('donate-btn');
const qrcodePanel = document.getElementById('qrcode-panel');
const donateClose = document.getElementById('donate-close');
const methodBtns = document.querySelectorAll('.donate-method-btn');
const qrImages = document.querySelectorAll('.qr-image');
let isVisible = false;
// 切换支付方式
function switchPayMethod(method) {
// 更新按钮状态
methodBtns.forEach(btn => {
btn.classList.remove('active');
if (btn.dataset.method === method) {
btn.classList.add('active');
}
});
// 更新二维码显示
qrImages.forEach(img => {
img.classList.remove('active');
if (img.dataset.method === method) {
img.classList.add('active');
}
});
}
// 点击打赏按钮切换二维码显示状态
function toggleQRCode(event) {
event.stopPropagation();
isVisible = !isVisible;
qrcodePanel.style.display = isVisible ? 'block' : 'none';
}
// 点击关闭按钮隐藏二维码
function hideQRCode(event) {
event.stopPropagation();
isVisible = false;
qrcodePanel.style.display = 'none';
}
// 点击二维码面板之外的地方隐藏二维码
function handleDocumentClick(event) {
if (isVisible && !qrcodePanel.contains(event.target) && !donateBtn.contains(event.target)) {
isVisible = false;
qrcodePanel.style.display = 'none';
}
}
// 绑定事件监听器
donateBtn.addEventListener('click', toggleQRCode);
donateClose.addEventListener('click', hideQRCode);
document.addEventListener('click', handleDocumentClick);
// 绑定支付方式切换按钮事件
methodBtns.forEach(btn => {
btn.addEventListener('click', (e) => {
const method = e.target.dataset.method;
switchPayMethod(method);
});
});
// 初始化显示第一个支付方式
switchPayMethod('wechat');
});
+19 -14
View File
@@ -1,13 +1,13 @@
document.addEventListener('click', function (e) {
// 检查点击的元素是否是 .post-read-more a
// 检查点击的元素是否是 .loadmore a
if (e.target.closest('.loadmore a')) {
e.preventDefault();
var btn = e.target.closest('.loadmore a');
var nextPage = btn.getAttribute('href');
var nextPage = btn.getAttribute('href');
// 防止重复点击
if (btn.classList.contains('loading')) return false;
btn.classList.add('loading');
btn.textContent = '加载中...';
btn.textContent = '加载中...';
// 发起 AJAX 请求
fetch(nextPage)
.then(response => {
@@ -19,18 +19,23 @@ document.addEventListener('click', function (e) {
.then(data => {
// 创建一个临时的 DOM 元素来解析返回的 HTML
var parser = new DOMParser();
var htmlDoc = parser.parseFromString(data, 'text/html');
// 找到新的文章
var newPosts = htmlDoc.querySelectorAll('.post--item');
// 找到新的"加载更多"按钮
var newBtn = htmlDoc.querySelector('.nav-links a');
// 获取文章列表容器和加载更多按钮
var postReadMore = document.querySelector('.nav-links');
var articleList = document.querySelector('.articleList');
var htmlDoc = parser.parseFromString(data, 'text/html');
// 调试代码:检查选择器
console.log('Searching for #loadpost:', htmlDoc.querySelectorAll('#loadpost'));
console.log('Searching for .nav-links:', htmlDoc.querySelector('.nav-links'));
// 找到新的文章和按钮
var newPosts = htmlDoc.querySelectorAll('#loadpost');
var newBtn = htmlDoc.querySelector('.nav-links a');
// 更健壮的元素选择
var articleList = document.querySelector('#loadposts') ||
document.querySelector('.posts-container') ||
document.body;
var postReadMore = document.querySelector('.nav-links');
if (newPosts.length > 0) {
newPosts.forEach(post => {
articleList.insertBefore(post, postReadMore);
});
// 使用 appendChild 替代 insertBefore
articleList.appendChild(post);
});
// 新文章淡入效果
Array.from(newPosts).forEach(post => {
post.style.opacity = 0;
@@ -39,7 +44,7 @@ document.addEventListener('click', function (e) {
post.style.opacity = 1;
}, 10);
});
}
}
// 更新"加载更多"按钮或移除它
if (newBtn) {
btn.setAttribute('href', newBtn.getAttribute('href'));
View File
+60 -14
View File
@@ -52,8 +52,10 @@ function themeConfig($form) {
$form->addInput($cnavatar);
$midimg = new Typecho_Widget_Helper_Form_Element_Text('midimg', NULL, '/img/', _t('填写分类图片路径,以"/"结尾'), _t('默认使用网站根目录下的img文件夹,也可以填写绝对或者CDN地址,自动匹配目录下以分类ID为文件名的mid.jpg格式的图片'));
$form->addInput($midimg);
$donate = new Typecho_Widget_Helper_Form_Element_Text('donate', NULL, NULL, _t('赞赏二维码'), _t('不填写则不显示'));
$form->addInput($donate);
$wxpay = new Typecho_Widget_Helper_Form_Element_Text('wxpay', NULL, 'https://blog.loliko.cn/images/wechatpay.png', _t('微信收款码'), _t('赞赏二维码'));
$form->addInput($wxpay);
$alipay= new Typecho_Widget_Helper_Form_Element_Text('alipay', NULL, 'https://blog.loliko.cn/images/alipay.png', _t('支付宝收款码'), _t('赞赏二维码'));
$form->addInput($alipay);
$addhead = new Typecho_Widget_Helper_Form_Element_Textarea('addhead', NULL, NULL, _t('Head内代码用于网站验证等'), _t('支持HTML'));
$form->addInput($addhead);
$tongji = new Typecho_Widget_Helper_Form_Element_Textarea('tongji', NULL, NULL, _t('统计代码'), _t('支持HTML'));
@@ -71,18 +73,6 @@ function themeFields($layout) {
$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);
}
/*
@@ -459,4 +449,60 @@ function commentApprove($widget, $email = NULL)
$result['commentNum'] = $commentNum;
}
return $result;
}
/**
* 修改附件插入功能
*/
// 添加批量插入按钮的JavaScript
Typecho_Plugin::factory('admin/write-post.php')->bottom = array('MyHelper', 'addBatchInsertButton');
Typecho_Plugin::factory('admin/write-page.php')->bottom = array('MyHelper', 'addBatchInsertButton');
class MyHelper {
public static function addBatchInsertButton() {
?>
<script>
$(document).ready(function() {
// 添加批量插入按钮
var batchButton = $('<button type="button" class="btn primary" id="batch-insert">批量插入所有附件</button>');
$('#file-list').before(batchButton);
// 修改单个附件的插入格式
Typecho.insertFileToEditor = function(title, url, isImage) {
var textarea = $('#text'), sel = textarea.getSelection(),
insertContent = isImage ? '![' + title + '](' + url + ')' :
'[' + title + '](' + url + ')';
textarea.replaceSelection(insertContent);
textarea.focus();
};
// 批量插入功能
$('#batch-insert').click(function() {
var content = '';
$('#file-list li').each(function() {
var $this = $(this),
title = $this.find('.insert').text(),
url = $this.data('url'),
isImage = $this.data('image') == 1;
content += isImage ? '![' + title + '](' + url + ')\n' :
'[' + title + '](' + url + ')\n';
});
var textarea = $('#text');
var pos = textarea.getSelection();
var newContent = textarea.val();
if (pos.start === pos.end) {
newContent = newContent.substring(0, pos.start) + content + newContent.substring(pos.start);
} else {
newContent = newContent.substring(0, pos.start) + content + newContent.substring(pos.end);
}
textarea.val(newContent);
textarea.focus();
});
});
</script>
<?php
}
}
+5 -5
View File
@@ -55,10 +55,10 @@ if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?>
<div class="inner">
<nav>
<ul>
<?php $this->widget('Widget_Contents_Page_List')->to($pages); ?>
<?php while($pages->next()): ?>
<li><a <?php if($this->is('page', $pages->slug)): ?> class="current"<?php endif; ?> href="<?php $pages->permalink(); ?>" title="<?php $pages->title(); ?>"><?php $pages->title(); ?></a></li>
<?php endwhile; ?>
<?php $this->widget('Widget_Contents_Page_List')->to($pages); ?>
<?php while($pages->next()): ?>
<li><a <?php if($this->is('page', $pages->slug)): ?> class="current"<?php endif; ?> href="<?php $pages->permalink(); ?>" title="<?php $pages->title(); ?>"><?php $pages->title(); ?></a></li>
<?php endwhile; ?>
</ul>
</nav>
<!-- 这年头谁会用站内的搜索啊 -->
@@ -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">
</path>
</svg>
</header>
</header>
+8 -120
View File
@@ -3,128 +3,16 @@
* 一款单栏主题. 移植自HUGO主题 Farallon 原作者 bigfa
* @package Farallon
* @author 老孙
* @version 0.7.0
* @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 = " <span class='sticky--post'> 置顶 </span> "; // 置顶标题的 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);
}
?>
<?php $this->need('module/header.php');?>
if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?>
<?php $this->need('module/sticky.php'); ?>
<?php $this->need('header.php');?>
<main class="site--main">
<div class="articleList">
<?php $this->need('module/postlist.php'); ?>
<?php if ($this->options->loadmore): ?>
<?php
$this->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'
)
);
?>
<?php else:?>
<?php
$nextPage = $this->_currentPage + 1;
$totalPages = ceil($this->getTotal() / $this->parameter->pageSize);
if ($this->_currentPage < $totalPages): ?>
<div class="nav-links">
<span class="loadmore"><?php $this->pageLink('加载更多', 'next'); ?></span>
<div class="articleList">
<?php $this->need('module/postlist.php'); ?>
<?php $this->need('module/paging.php'); ?>
</div>
<?php endif; ?>
<script src="<?php $this->options->themeUrl('assets/js/loadmore.js'); ?>"></script>
<?php endif; ?>
</div>
</main>
<?php $this->need('module/footer.php'); ?>
<?php $this->need('footer.php'); ?>
+4 -2
View File
@@ -1,6 +1,7 @@
<?php if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?>
<div id="loadposts">
<?php while($this->next()): ?>
<article class="post--item post--item__status" itemtype="http://schema.org/Article" itemscope="itemscope">
<article id="loadpost" class="post--item post--item__status" itemtype="http://schema.org/Article" itemscope="itemscope">
<div class="content">
<header>
<img src="<?php $this->options->logoUrl() ?>" class="avatar" width="48" height="48" />
@@ -14,4 +15,5 @@
</div>
</div>
</article>
<?php endwhile; ?>
<?php endwhile; ?>
</div>
+31
View File
@@ -0,0 +1,31 @@
<?php if ($this->options->loadmore): ?>
<?php
$this->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'
)
);
?>
<?php else:?>
<?php
$nextPage = $this->_currentPage + 1;
$totalPages = ceil($this->getTotal() / $this->parameter->pageSize);
if ($this->_currentPage < $totalPages):
?>
<div class="nav-links">
<span class="loadmore"><?php $this->pageLink('加载更多', 'next'); ?></span>
</div>
<script src="<?php $this->options->themeUrl('assets/js/loadmore.js'); ?>"></script>
<?php endif; ?>
<?php endif; ?>
+10 -6
View File
@@ -1,10 +1,10 @@
<div id="loadposts">
<?php while($this->next()): ?>
<?php
// 获取当前文章的分类
$categories = $this->categories;
$memosMid = $this->options->memos; // 获取主题设置中的说说分类 mid
$isMemos = false;
// 检查当前文章是否属于说说分类
foreach ($categories as $category) {
if ($category['mid'] == $memosMid) {
@@ -12,26 +12,28 @@
break;
}
}
// 根据是否为说说分类使用不同的显示模板
if ($isMemos):
?>
<div id="loadpost">
<article class="post--item post--item__status" itemtype="http://schema.org/Article" itemscope="itemscope">
<div class="content">
<header>
<img src="<?php $this->options->logoUrl() ?>" class="avatar" width="48" height="48" />
<a datetime='<?php $this->date('Y-m-d'); ?>' class="humane--time" href="<?php $this->permalink() ?>"
itemprop="datePublished">
<?php $this->date('Y-m-d'); ?>
<?php $this->date('Y-m-d H:i'); ?>
</a>
</header>
<div class="description" itemprop="about">
<?php $this->excerpt(200, '...'); ?>
</div>
</div>
</article>
</article>
</div>
<?php else: ?>
<article class="post--item">
<div id="loadpost">
<article class="post--item" id="loadpost">
<div class="content">
<h2 class="post--title">
<a href="<?php $this->permalink() ?>">
@@ -79,5 +81,7 @@
</a>
<?php endif; ?>
</article>
</div>
<?php endif; ?>
<?php endwhile; ?>
<?php endwhile; ?>
</div>
+3 -1
View File
@@ -1,8 +1,9 @@
<?php if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?>
<div class="related--content">
<?php $this->related(6)->to($relatedPosts); ?>
<?php if ($relatedPosts->have()): ?>
<h3 class="related--posts__title">相关文章</h3>
<div class="post--single__related">
<?php $this->related(6)->to($relatedPosts); ?>
<?php while ($relatedPosts->next()): ?>
<div class="post--single__related__item">
<a href="<?php $relatedPosts->permalink(); ?>">
@@ -18,4 +19,5 @@
</div>
<?php endwhile; ?>
</div>
<?php endif; ?>
</div>
+85
View File
@@ -0,0 +1,85 @@
<?php if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?>
<?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 = " <span class='sticky--post'> 置顶 </span> "; // 置顶标题的 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);
}
?>
+4 -3
View File
@@ -1,5 +1,5 @@
<?php if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?>
<div class="post--cards">
<div class="post--cards" id="loadposts">
<?php while($this->next()): ?>
<?php // 获取文章图片
$default_thumbnail = Helper::options()->themeUrl . '/assets/images/nopic.svg';
@@ -13,7 +13,7 @@
$imageToDisplay = $firstImage;
}
?>
<article class="post--card">
<article class="post--card" id="loadpost" itemscope itemtype="http://schema.org/Article">
<img src="<?php echo $imageToDisplay; ?>" alt="<?php $this->title() ?>" class="cover" itemprop="image"/>
<div class="content">
<h2 class="post--title">
@@ -34,4 +34,5 @@
</div>
</div>
</article>
<?php endwhile; ?>
<?php endwhile; ?>
</div>
+2 -2
View File
@@ -5,7 +5,7 @@
* @package custom
*/
if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?>
<?php $this->need('./module/header.php'); ?>
<?php $this->need('header.php'); ?>
<section class="site--main">
<header class="archive--header">
<h1 class="post--single__title"><?php $this->title() ?></h1>
@@ -57,4 +57,4 @@ if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?>
?>
</div>
</section>
<?php $this->need('./module/footer.php'); ?>
<?php $this->need('footer.php'); ?>
+2 -2
View File
@@ -5,7 +5,7 @@
* @package custom
*/
if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?>
<?php $this->need('./module/header.php'); ?>
<?php $this->need('header.php'); ?>
<div class="site--main">
<header class="archive--header">
<h1 class="post--single__title"><?php $this->title() ?></h1>
@@ -33,4 +33,4 @@ if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?>
<?php endwhile; ?>
</section>
</div>
<?php $this->need('./module/footer.php'); ?>
<?php $this->need('footer.php'); ?>
+2 -2
View File
@@ -5,7 +5,7 @@
* @package custom
*/
if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?>
<?php $this->need('./module/header.php'); ?>
<?php $this->need('header.php'); ?>
<script src="<?php $this->options->themeUrl('assets/js/db.js'); ?>"></script>
<section class="site--main">
<header class="archive--header">
@@ -28,4 +28,4 @@ new Douban({
</script>
</div>
</section>
<?php $this->need('./module/footer.php'); ?>
<?php $this->need('footer.php'); ?>
+5 -39
View File
@@ -5,20 +5,17 @@
* @package custom
*/
if (!defined('__TYPECHO_ROOT_DIR__')) exit;
$this->need('./module/header.php');
$this->need('header.php');
?>
<div class="site--main site--main__gears">
<header class="archive--header">
<h1 class="post--single__title"><?php $this->title() ?></h1>
</header>
<div id="goods" class="good--list">
<?php
// 获取内容并解析
$content = $this->content;
$goods = parseGoodsTable($content);
if (!empty($goods)) {
foreach ($goods as $item): ?>
<div class="good--item">
@@ -44,31 +41,7 @@ $this->need('./module/header.php');
<?php $this->need('./module/comments.php'); ?>
<?php endif; ?>
</div>
<style>
.img40 {
height: 137px;
width: auto;
object-fit: cover;
}
.img-spacer {
width: 100%;
aspect-ratio: 1;
overflow: hidden;
}
.brand {
font-weight: 500;
margin-bottom: 5px;
}
.no-goods {
grid-column: 1 / -1;
text-align: center;
padding: 20px;
background: #f5f5f5;
border-radius: 8px;
}
</style>
<style>.img40{height:137px;width:auto;object-fit:cover;}.img-spacer{width:100%;aspect-ratio:1;overflow:hidden;}.brand{font-weight:500;margin-bottom:5px;}.no-goods{grid-column:1 / -1;text-align:center;padding:20px;background:#f5f5f5;border-radius:8px;}</style>
<?php
/**
* 解析商品表格数据
@@ -77,25 +50,20 @@ $this->need('./module/header.php');
*/
function parseGoodsTable($content) {
$goods = array();
// 创建DOM对象
$dom = new DOMDocument();
libxml_use_internal_errors(true); // 禁用libxml错误
$dom->loadHTML(mb_convert_encoding($content, 'HTML-ENTITIES', 'UTF-8'), LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
libxml_clear_errors();
// 查找表格
$tables = $dom->getElementsByTagName('table');
if ($tables->length > 0) {
$table = $tables->item(0); // 获取第一个表格
$rows = $table->getElementsByTagName('tr');
$rows = $table->getElementsByTagName('tr');
// 跳过表头行
for ($i = 1; $i < $rows->length; $i++) {
$row = $rows->item($i);
$cells = $row->getElementsByTagName('td');
$cells = $row->getElementsByTagName('td');
// 确保有足够的单元格
if ($cells->length >= 5) {
$item = array(
@@ -113,9 +81,7 @@ function parseGoodsTable($content) {
}
}
}
return $goods;
}
$this->need('./module/footer.php');
$this->need('footer.php');
?>
+4 -8
View File
@@ -5,7 +5,7 @@
* @package custom
*/
if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?>
<?php $this->need('./module/header.php'); ?>
<?php $this->need('header.php'); ?>
<section class="site--main">
<header class="archive--header">
<h1 class="post--single__title"><?php $this->title() ?></h1>
@@ -13,17 +13,13 @@ if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?>
</header>
<div class="template--linksWrap">
<ul class="link-items">
<?php
Links_Plugin::output('<li class="link-item"><a class="link-item-inner effect-apollo" href="{url}" target="_blank">
<span class="sitename"><strong>{name}</strong>{title}</span>
</a></li>');
?>
<?php Links_Plugin::output('<li class="link-item"><a class="link-item-inner effect-apollo" href="{url}" target="_blank"><span class="sitename"><strong>{name}</strong>{title}</span></a></li>'); ?>
</ul>
</div>
<article class="post--single">
<?php if ($this->allow('comment')): ?>
<?php $this->need('./module/comments.php'); ?>
<?php $this->need('module/comments.php'); ?>
<?php endif; ?>
</article>
</section>
<?php $this->need('./module/footer.php'); ?>
<?php $this->need('footer.php'); ?>
+2 -2
View File
@@ -5,7 +5,7 @@
* @package custom
*/
if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?>
<?php $this->need('./module/header.php'); ?>
<?php $this->need('header.php'); ?>
<div class="site--main">
<header class="archive--header">
<h1 class="post--single__title"><?php $this->title() ?></h1>
@@ -148,4 +148,4 @@ img {
}
</style>
</div>
<?php $this->need('./module/footer.php'); ?>
<?php $this->need('footer.php'); ?>
+3 -9
View File
@@ -5,7 +5,7 @@
* @package custom
*/
if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?>
<?php $this->need('./module/header.php'); ?>
<?php $this->need('header.php'); ?>
<div class="site--main">
<header class="archive--header">
<h1 class="post--single__title"><?php $this->title() ?></h1>
@@ -16,7 +16,7 @@ if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?>
$memos = $this->fields->memos ? $this->fields->memos : 'https://memos.imsun.org';
$memosID = $this->fields->memosID ? $this->fields->memosID : '1';
$memosnum = $this->fields->memosnum ? $this->fields->memosnum : '20';
?>
?>
<article class="post--single">
<script src="<?php $this->options->themeUrl('assets/js/marked.min.js'); ?>"></script>
<link rel="stylesheet" href="<?php $this->options->themeUrl('assets/css/lightbox.min.css'); ?>">
@@ -32,7 +32,6 @@ const limit = 10; // 每页条数
let url = '<?php echo $memos; ?>';
let memosID = '<?php echo $memosID; ?>';
let memosnum = '<?php echo $memosnum; ?>';
function loadMemos(page) {
fetch(`${url}/api/v1/memo?creatorId=${memosID}&rowStatus=NORMAL&limit=${limit}&offset=${(page - 1) * limit}`)
.then(res => res.json())
@@ -64,7 +63,6 @@ function loadMemos(page) {
// 这里可以添加一些用户提示错误发生的 HTML 更新
});
}
function Format(item) {
let date = getTime(new Date(item.createdTs * 1000).toString()),
content = item.content,
@@ -94,7 +92,6 @@ function Format(item) {
text: text.replace(/\[(.*?)\]\((.*?)\)/g, '[链接]' + `${imgs?'[图片]':''}`)
}
}
// 页面时间格式化
function getTime(time) {
let d = new Date(time),
@@ -105,16 +102,13 @@ function getTime(time) {
if (new Date().getFullYear() == ls[0]) return ls[1] + '月' + ls[2] + '日 ' + ls[3] +':'+ ls[4]
else return ls[0] + '年' + ls[1] + '月' + ls[2] + '日 ' + ls[3] +':'+ ls[4]
}
// 初始加载第一页
loadMemos(currentPage);
// 点击“加载更多”按钮时加载下一页
document.getElementById('loadmore').addEventListener('click', function() {
currentPage++;
loadMemos(currentPage);
});
</script>
<style>
div pre code {
@@ -169,4 +163,4 @@ img {
}
</style>
</div>
<?php $this->need('./module/footer.php'); ?>
<?php $this->need('footer.php'); ?>
+11 -11
View File
@@ -5,7 +5,7 @@
* @package custom
*/
if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?>
<?php $this->need('./module/header.php'); ?>
<?php $this->need('header.php'); ?>
<link rel="stylesheet" href="<?php $this->options->themeUrl('assets/css/neodb.css'); ?>">
<script src="<?php $this->options->themeUrl('assets/js/neodb.js'); ?>"></script>
<section class="site--main">
@@ -15,14 +15,14 @@ if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?>
</header>
<div class="site--main">
<div class="neodb-container"></div>
<?php $neodb = $this->fields->neodb ? $this->fields->neodb : 'https://neodb.imsun.org'; ?>
<script>
const neodb = new NeoDB({
container: ".neodb-container",
baseAPI: "<?php echo $neodb; ?>/api",
types: ["book", "movie", "tv", "music", "game"],
});
</script>
</div>
<?php $neodb = $this->fields->neodb ? $this->fields->neodb : 'https://neodb.imsun.org'; ?>
<script>
const neodb = new NeoDB({
container: ".neodb-container",
baseAPI: "<?php echo $neodb; ?>/api",
types: ["book", "movie", "tv", "music", "game"],
});
</script>
</div>
</section>
<?php $this->need('./module/footer.php'); ?>
<?php $this->need('footer.php'); ?>
+2 -2
View File
@@ -5,7 +5,7 @@
* @package custom
*/
if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?>
<?php $this->need('./module/header.php'); ?>
<?php $this->need('header.php'); ?>
<section class="site--main">
<header class="archive--header">
<h1 class="post--single__title"><?php $this->title() ?></h1>
@@ -30,4 +30,4 @@ if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?>
<?php endif; ?>
</div>
</section>
<?php $this->need('./module/footer.php'); ?>
<?php $this->need('footer.php'); ?>
+2 -2
View File
@@ -1,5 +1,5 @@
<?php if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?>
<?php $this->need('./module/header.php'); ?>
<?php $this->need('header.php'); ?>
<section class="site--main">
<header class="archive--header">
<h1 class="post--single__title"><?php $this->title() ?></h1>
@@ -14,5 +14,5 @@
<?php endif; ?>
</article>
</section>
<?php $this->need('module/footer.php'); ?>
<?php $this->need('footer.php'); ?>
+19 -35
View File
@@ -1,13 +1,6 @@
<?php if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?>
<?php $this->need('module/header.php'); ?>
<style>
#toc {font-size:14px;padding:10px 15px;background-color:var(--farallon-background-gray);border-radius:10px;margin-bottom:20px}
#toc summary{cursor:pointer}
#toc toc-title{font-weight:600}
#toc ul{padding-left:10px;margin-bottom:10px}
#toc ul li::before{content:"·";margin-right:5px}
#toc ul li>ul{margin-left:10px;font-size:12px}
</style>
<?php $this->need('header.php'); ?>
<style>#toc{font-size:14px;padding:10px 15px;background-color:var(--farallon-background-gray);border-radius:10px;margin-bottom:20px}#toc summary{cursor:pointer}#toc toc-title{font-weight:600}#toc ul{padding-left:10px;margin-bottom:10px}#toc ul li::before{content:"·";margin-right:5px}#toc ul li>ul{margin-left:10px;font-size:12px}</style>
<main class="site--main">
<article class="post--single">
<ul class="meta">
@@ -45,33 +38,24 @@
</div>
<h2 class="post--single__title"><?php $this->title() ?></h2>
<div class="post--single__content graph" ><?php $this->content(); ?></div>
<?php if($this->options->donate): ?>
<?php if($this->options->wxpay): ?>
<!--打赏 -->
<div class="post--single__action">
<link rel="stylesheet" href="<?php $this->options->themeUrl('assets/css/donate.css'); ?>">
<script type="text/javascript" src="<?php $this->options->themeUrl('assets/js/donate.js'); ?>"></script>
<div class="donate-panel">
<div id="donate-btn">
<button class="button--like">
<svg class="icon--default" viewBox="0 0 1024 1024" width="32" height="32">
<path
d="M332.8 249.6c38.4 0 83.2 19.2 108.8 44.8L467.2 320 512 364.8 556.8 320l25.6-25.6c32-32 70.4-44.8 108.8-44.8 19.2 0 38.4 6.4 57.6 12.8 44.8 25.6 70.4 57.6 76.8 108.8 6.4 44.8-6.4 89.6-38.4 121.6L512 774.4 236.8 492.8C204.8 460.8 185.6 416 192 371.2c6.4-44.8 38.4-83.2 76.8-108.8C288 256 313.6 249.6 332.8 249.6L332.8 249.6M332.8 185.6C300.8 185.6 268.8 192 243.2 204.8 108.8 275.2 89.6 441.6 185.6 537.6l281.6 281.6C480 832 499.2 838.4 512 838.4s32-6.4 38.4-19.2l281.6-281.6c96-96 76.8-262.4-57.6-332.8-25.6-12.8-57.6-19.2-89.6-19.2-57.6 0-115.2 25.6-153.6 64L512 275.2 486.4 249.6C448 211.2 390.4 185.6 332.8 185.6L332.8 185.6z">
</path>
</svg>
</button>
</div>
<div id="qrcode-panel" style="display: none;">
<div class="qrcode-body">
<div class="hidden">
<span id="donate-close">关闭</span>
</div>
<div class="donate-qrpay">
<img id="wxqr" src="<?php $this->options->donate() ?>" />
</div>
</div>
</div>
</div>
<button class="button--like" onclick="openModal()">
<svg class="icon--default" viewBox="0 0 1024 1024" width="32" height="32"><path d="M332.8 249.6c38.4 0 83.2 19.2 108.8 44.8L467.2 320 512 364.8 556.8 320l25.6-25.6c32-32 70.4-44.8 108.8-44.8 19.2 0 38.4 6.4 57.6 12.8 44.8 25.6 70.4 57.6 76.8 108.8 6.4 44.8-6.4 89.6-38.4 121.6L512 774.4 236.8 492.8C204.8 460.8 185.6 416 192 371.2c6.4-44.8 38.4-83.2 76.8-108.8C288 256 313.6 249.6 332.8 249.6L332.8 249.6M332.8 185.6C300.8 185.6 268.8 192 243.2 204.8 108.8 275.2 89.6 441.6 185.6 537.6l281.6 281.6C480 832 499.2 838.4 512 838.4s32-6.4 38.4-19.2l281.6-281.6c96-96 76.8-262.4-57.6-332.8-25.6-12.8-57.6-19.2-89.6-19.2-57.6 0-115.2 25.6-153.6 64L512 275.2 486.4 249.6C448 211.2 390.4 185.6 332.8 185.6L332.8 185.6z"></path></svg>
</button>
</div>
<!-- 弹窗 -->
<div class="modal" id="modal" onclick="closeModal()">
<div class="modal-content" onclick="event.stopPropagation()">
<span class="close-btn" onclick="closeModal()">&times;</span>
<p>如果觉得文章对你有帮助,可以请作者喝杯咖啡 ☕️</p>
<img src="<?php $this->options->wxpay() ?>" alt="微信二维码">
<img src="<?php $this->options->alipay() ?>" alt="支付宝二维码">
</div>
</div>
<script>function openModal(){document.getElementById('modal').style.display='flex'}function closeModal(){document.getElementById('modal').style.display='none'}</script>
<style>.button--like{background:none;border:none;padding:0;cursor:pointer;transition:transform 0.3s ease;}.button--like:hover{transform:scale(1.1);}.icon--default{fill:#666;transition:fill 0.3s ease;}.button--like:hover .icon--default{fill:#ff4081;}.modal{display:none;position:fixed;top:0;left:0;width:100%;height:100%;background-color:rgba(0,0,0,0.1);justify-content:center;align-items:center;z-index:1000;}.modal-content{background-color:white;padding:20px;border-radius:10px;text-align:center;position:relative;}.modal-content img{width:200px;height:200px;margin-top:10px;}.close-btn{position:absolute;top:10px;right:10px;cursor:pointer;font-size:20px;color:#888;}</style>
<?php endif; ?>
<!-- 复制链接 -->
<?php if($this->options->showshare): ?>
@@ -126,7 +110,7 @@
<?php $this->need('module/related.php'); ?>
<?php endif; ?>
<?php if ($this->allow('comment')): ?>
<?php $this->need('./module/comments.php'); ?>
<?php $this->need('module/comments.php'); ?>
<?php endif; ?>
<!--翻页-->
<nav class="navigation post-navigation is-active">
@@ -145,4 +129,4 @@
<script src="<?php $this->options->themeUrl('assets/js/post.js'); ?>"></script>
<link rel="stylesheet" href="<?php $this->options->themeUrl('assets/css/lightbox.min.css'); ?>">
<script src="<?php $this->options->themeUrl('assets/js/lightbox-plus-jquery.min.js'); ?>"></script>
<?php $this->need('module/footer.php'); ?>
<?php $this->need('footer.php'); ?>