Repository navigation
Expand file tree
/
Copy pathcomments.php
More file actions
executable file
·150 lines (139 loc) · 6.93 KB
/
Copy pathcomments.php
File metadata and controls
executable file
·150 lines (139 loc) · 6.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<?php
/**
* comments.php(含 Cloudflare Turnstile 集成,优先 CF,其次 Geetest)
*/
?>
<div class="padding blur" id="comments">
<?php $this->comments()->to($comments); ?>
<!--评论输入框-->
<?php if($this->allow('comment')): ?>
<div id="<?php $this->respondId(); ?>" class="respond">
<div class="cancel-comment-reply">
<?php $comments->cancelReply(); ?>
</div>
<h3 class="oneblog" id="response">
<div id="default-title"><i class="iconfont icon-memos"></i>发表留言</div>
<div id="reply-title" style="display:none">回复<div id="reply-target"></div>
</div>
</h3>
<form method="post" action="<?php $this->commentUrl() ?>" id="comment-form" role="form">
<?php if ($this->user->hasLogin()): ?>
<?php else: ?>
<div class="comment-author-info">
<div class="comment-md-3">
<label for="author"><?php _e('称呼'); ?><span class="required">*</span></label>
<input type="text" name="author" id="author" class="text" value="<?php $this->remember('author'); ?>" required />
</div>
<div class="comment-md-3">
<label for="mail"<?php if ($this->options->commentsRequireMail): ?><?php endif; ?>><?php _e('邮箱'); ?><span class="required">*</span></label>
<input type="email" name="mail" id="mail" class="text" value="<?php $this->remember('mail'); ?>"<?php if ($this->options->commentsRequireMail): ?> required<?php endif; ?> />
</div>
<div class="comment-md-3">
<label for="url"<?php if ($this->options->commentsRequireURL): ?> class="required"<?php endif; ?>><?php _e('网站'); ?></label>
<input type="url" name="url" id="url" class="text" placeholder="<?php _e('https://'); ?>" value="<?php $this->remember('url'); ?>"<?php if ($this->options->commentsRequireURL): ?> required<?php endif; ?> />
</div>
</div>
<!-- Cloudflare Turnstile: 前端 SiteKey(隐藏)与隐藏 token 字段 -->
<?php if ($this->options->CFSiteKey): ?>
<input type="hidden" id="cf-sitekey" value="<?php echo htmlspecialchars($this->options->CFSiteKey); ?>" />
<input type="hidden" name="cf_token" id="cf-token" value="" />
<script src="https://challenges.cloudflare.com/turnstile/v0/api.js" async defer></script>
<?php elseif ($this->options->GeetestID): ?>
<input type="hidden" id="geetest-captcha-id" value="<?php echo htmlspecialchars($this->options->GeetestID); ?>" />
<?php endif; ?>
<?php endif; ?>
<!-- 隐藏的textarea,实际提交用 -->
<textarea name="text" id="textarea" style="display:none;" required></textarea>
<!-- 可编辑div,表情预览和输入都在这里 -->
<div id="rich-editor" contenteditable="true" class="rich-editor"></div>
<div class="comment-submit">
<div class="emoji" title="添加表情">
<i id="emoji-btn" class="iconfont icon-emoji"></i>
<div id="emoji-picker" class="emoji-picker" style="display:none;">
<div class="emoji-categories">
<button type="button" class="emoji-category" data-category="emotion">表情</button>
<button type="button" class="emoji-category" data-category="special">特殊</button>
<button type="button" class="emoji-category" data-category="kaomoji">颜文字</button>
</div>
<div class="emoji-container">
<!-- 表情图标会动态加载到这里 -->
</div>
</div>
</div>
<button type="submit" class="submit" id="geetest-submit-btn"><?php _e('提交审核'); ?></button>
</div>
</form>
</div>
<?php else:?>
<div class="load">— END —</div>
<?php endif; ?>
<!--评论列表开始-->
<?php if ($comments->have()): ?>
<div class="line"></div>
<h3 class="oneblog"><?php $this->commentsNum(_t('<i class="iconfont icon-guestbook"></i>暂无留言'), _t('<i class="iconfont icon-guestbook"></i>读者留言<span>1</span>'), _t('<i class="iconfont icon-guestbook"></i>读者留言<span>%d</span>')); ?></h3>
<?php
function getParentAuthor($comments) {
$parent = $comments->parent;
if ($parent) {
static $cache = [];
if (array_key_exists($parent, $cache)) {
return $cache[$parent];
}
$db = Typecho_Db::get();
$row = $db->fetchRow($db->select()->from('table.comments')->where('coid = ?', $parent));
if ($row && isset($row['author'])) {
return $cache[$parent] = $row['author'];
}
return $cache[$parent] = null;
}
return null;
}
function threadedComments($comments, $options) {$commentLevelClass = $comments->levels > 0 ? 'comment-child' : 'comment-parent';?>
<li class="animate__animated animate__fadeIn depth-<?php echo $comments->levels + 1; ?> <?php echo $commentLevelClass;?>"> <!-- 添加深度类 -->
<div id="<?php $comments->theId(); ?>">
<div class="user">
<?php $email=htmlspecialchars($comments->mail, ENT_QUOTES, 'UTF-8'); $imgUrl = getGravatar($email);echo '<img class="avatar" src="'.$imgUrl.'">'; ?>
<div class="user-info">
<div class="name">
<?php echo comment_author_link($comments); ?>
<?php dengji(htmlspecialchars($comments->mail, ENT_QUOTES, 'UTF-8'));?>
<?php if ($comments->status === "waiting") : ?>
<span class="waiting">[ 审核中 ]</span>
<?php endif; ?>
</div>
<div class="date">
<span><?php $comments->date('Y-m-d H:i'); ?></span>
<span class="comment-reply" data-author="<?php echo htmlspecialchars($comments->author); ?>">
<?php $comments->reply(); ?>
</span>
</div>
</div>
</div>
<div class="<?= $comments->status === "waiting" ? 'waiting ' : '' ?>comment-box-<?php echo $comments->levels + 1; ?>">
<?php
if ($comments->levels > 0) {
$parentAuthor = getParentAuthor($comments);
if ($parentAuthor) {
echo '<span class="at-parent">@' . htmlspecialchars($parentAuthor) . '</span> ';
}
}
?>
<?= parseEmojis($comments->content); ?>
</div>
<!--子级评论列表-->
<?php if ($comments->children) { $comments->threadedComments($options);} ?>
</div>
</li>
<?php } ?>
<?php $comments->listComments(); ?>
<?php $comments->pageNav('', ''); ?>
<!-- 加载更多按钮,仅PC端显示,移动端隐藏 -->
<div class="load" id="load-more-comments">加载更多评论</div>
<!-- 原有加载提示 -->
<div id="loading-spinner" style="display: none;">
<div class="spinner"></div><span>加载中...</span>
</div>
<div class="load" id="no-more" style="display: none;">— 已加载全部评论 —</div>
<?php endif; ?>
<!--评论列表end-->
</div>