forked from liaocp666/Jasmine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomments.php
193 lines (191 loc) · 9.6 KB
/
comments.php
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
<?php if (!defined("__TYPECHO_ROOT_DIR__")) {
exit();
}
function threadedComments($comments, $options)
{
$commentClass = "";
if ($comments->authorId) {
if ($comments->authorId == $comments->ownerId) {
$commentClass .= " comment-by-author";
} else {
$commentClass .= " comment-by-user";
}
}
?>
<li id="<?php $comments->theId(); ?>"
class="flex flex-col gap-y-4 py-7 border-b-2 border-stone-100 dark:border-neutral-600 comment-body<?php
if ($comments->levels > 0) {
echo " comment-child";
$comments->levelsAlt(" comment-level-odd", " comment-level-even");
} else {
echo " comment-parent";
}
$comments->alt(" comment-odd", " comment-even");
echo $commentClass;
?>">
<div class="flex w-full gap-x-2 grow">
<?php if ($comments->authorId == $comments->ownerId) { ?>
<img class="rounded w-[50px] h-[50px] object-cover" width="50" height="50"
src="<?php echo getAvatarByMail($comments->mail, true); ?>"
loading="lazy"
alt="<?php $comments->author; ?>">
<?php } else { ?>
<img class="rounded w-[50px] h-[50px] object-cover" width="50" height="50"
src="<?php echo getAvatarByMail($comments->mail); ?>"
loading="lazy"
alt="<?php $comments->author; ?>">
<?php } ?>
<div class="flex flex-col w-full">
<div class="flex justify-between">
<div class="whitespace-nowrap"><span class="author-name ">
<?php getCommentAuthor($comments); ?>
<?php if ($comments->authorId == $comments->ownerId) { ?>
<span class="small author-icon">(作者) </span>
<?php } ?>
</span>
<span
class="small text-sm dark:text-gray-400"> <?php echo getHumanizedDate(
$comments->created
); ?>
</span>
<?php if ($comments->status == "waiting") { ?>
<span class="small dark:text-gray-300">
- 您的评论正等待审核!
</span>
<?php } ?>
</div>
<div class="comments-reply bg-black text-white rounded px-2 text-sm py-1 whitespace-nowrap" data-no-instant>
<?php $comments->reply("回复"); ?>
</div>
</div>
<div class="comment-content dark:text-gray-400 break-all">
<?php echo getCommentAt($comments->coid); ?> <?php $comments->content(); ?>
</div>
</div>
</div>
<?php if ($comments->children) { ?>
<div class="comment-children">
<?php $comments->threadedComments($options); ?>
</div>
<?php } ?>
</li>
<?php
}
?>
<div class="">
<div id="comments" data-no-instant>
<?php $this->comments()->to($comments); ?>
<?php if ($this->allow("comment")): ?>
<div id="<?php $this->respondId(); ?>" class="respond">
<form method="post" action="<?php $this->commentUrl(); ?>" id="comment-form" role="form"
class="flex flex-col gap-y-2"
data-no-instant>
<?php if (!$this->user->hasLogin()): ?>
<div class="flex flex-row md:flex-nowrap flex-wrap w-full gap-x-2 gap-y-2 grid grid-cols-3">
<input name="author" type="text"
class="dark:!bg-[#0d1117] dark:border-black dark:!text-gray-400 col-span-3 md:col-span-1 border-[#ced4da] border rounded px-2 py-2"
placeholder="昵称" required
value="<?php $this->remember("author"); ?>" required/>
<input name="mail" type="email"
class="dark:!bg-[#0d1117] dark:border-black dark:!text-gray-400 col-span-3 md:col-span-1 border-[#ced4da] border rounded px-2 py-2"
placeholder="邮箱" required
value="<?php $this->remember("mail"); ?>" <?php if (
$this->options->commentsRequireMail
): ?> required<?php endif; ?>/>
<input type="url" name="url" id="url"
class="dark:!bg-[#0d1117] dark:border-black dark:!text-gray-400 col-span-3 md:col-span-1 border-[#ced4da] border rounded px-2 py-2"
placeholder="网址"
value="<?php $this->remember("url"); ?>"<?php if (
$this->options->commentsRequireURL
): ?> required<?php endif; ?> />
<?php $security = $this->widget("Widget_Security"); ?>
<input type="hidden" name="_"
value="<?php echo $security->getToken($this->request->getReferer()); ?>"/>
</div>
<?php endif; ?>
<div class="basis-full">
<textarea rows="6" cols="40" name="text" id="textarea"
class="w-full border-[#ced4da] border rounded px-2 py-2 dark:!bg-[#0d1117] dark:border-black dark:!text-gray-400"
required
placeholder="请输入评论内容"><?php $this->remember("text"); ?></textarea>
</div>
<div class="flex justify-between items-center">
<div class="comments-curren-user flex gap-x-2">
<?php if ($this->user->hasLogin()): ?>
<img class="img-thumbnail rounded me-1" width="50" height="50"
src="<?php echo getAvatarByMail($this->user->mail, true); ?>"
loading="lazy"
alt="<?php $this->user->screenName(); ?>">
<div class="flex flex-col">
<span class=""><?php $this->user->screenName(); ?></span>
<span>
<a class="jasmine-primary-bg text-white rounded px-1 text-sm "
href="<?php $this->options->logoutUrl(); ?>"
title="注销">注销</a>
</span>
</div>
<?php endif; ?>
</div>
<div class="">
<?php $comments->cancelReply(); ?>
<button type="submit"
class="bg-black text-white rounded px-2 py-1 ml-2 "><?php _e(
"提交评论"
); ?></button>
</div>
</div>
</form>
</div>
<?php endif; ?>
<?php if ($comments->have()): ?>
<?php $comments->listComments(); ?>
<?php $comments->pageNav("上一页", "下一页", 0, ".."); ?>
<?php endif; ?>
</div>
</div>
<script>window.TypechoComment = {
dom: function (id) {
return document.getElementById(id)
}, create: function (tag, attr) {
var el = document.createElement(tag);
for (var key in attr) {
el.setAttribute(key, attr[key])
}
return el
}, reply: function (cid, coid) {
console.log(cid);
var comment = this.dom(cid), response = this.dom("<?php $this->respondId(); ?>"),
input = this.dom("comment-parent"),
form = "form" == response.tagName ? response : response.getElementsByTagName("form")[0],
textarea = response.getElementsByTagName("textarea")[0];
if (null == input) {
input = this.create("input", {"type": "hidden", "name": "parent", "id": "comment-parent"});
form.appendChild(input)
}
input.setAttribute("value", coid);
console.log(form);
if (null == this.dom("comment-form-place-holder")) {
var holder = this.create("div", {"id": "comment-form-place-holder"});
response.parentNode.insertBefore(holder, response)
}
comment.appendChild(response);
this.dom("cancel-comment-reply-link").style.display = "";
this.dom("cancel-comment-reply-link").className += "btn btn-dark btn-sm";
if (null != textarea && "text" == textarea.name) {
textarea.focus()
}
return false
}, cancelReply: function () {
var response = this.dom("<?php $this->respondId(); ?>"), holder = this.dom("comment-form-place-holder"),
input = this.dom("comment-parent");
if (null != input) {
input.parentNode.removeChild(input)
}
if (null == holder) {
return true
}
this.dom("cancel-comment-reply-link").style.display = "none";
holder.parentNode.insertBefore(response, holder);
return false
}
};</script>