forked from liaocp666/Jasmine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomments.php
173 lines (172 loc) · 8.9 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
<?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="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="d-flex flex-start mb-3 comment-main">
<?php if ($comments->authorId == $comments->ownerId) { ?>
<img class="rounded shadow-1-strong me-2 lazyload" width="50" height="50"
data-original="<?php echo getAvatarByMail($comments->mail, true); ?>"
src="data:image/gif;base64,R0lGODdhAQABAPAAAMPDwwAAACwAAAAAAQABAAACAkQBADs="
alt="<?php $comments->author; ?>">
<?php } else { ?>
<img class="rounded shadow-1-strong me-2 lazyload" width="50" height="50"
data-original="<?php echo getAvatarByMail($comments->mail); ?>"
src="data:image/gif;base64,R0lGODdhAQABAPAAAMPDwwAAACwAAAAAAQABAAACAkQBADs="
alt="<?php $comments->author; ?>">
<?php } ?>
<div class="flex-grow-1 flex-shrink-1">
<div>
<div class="d-flex justify-content-between align-items-center">
<div><span class="author-name">
<?php getCommentAuthor($comments); ?>
<?php if ($comments->authorId == $comments->ownerId) { ?>
<span class="small author-icon">(作者) </span>
<?php } ?>
</span>
<span class="small"> <?php echo getCommentAt($comments->coid) ?> - <?php echo getHumanizedDate($comments->created); ?>
</span>
<?php if ($comments->status == 'waiting') { ?>
<span class="small">
- 您的评论正等待审核!
</span>
<?php } ?>
</div>
<div class="comments-reply" data-no-instant>
<?php $comments->reply('回复'); ?>
</div>
</div>
<div class="comment-content">
<?php $comments->content(); ?>
</div>
</div>
</div>
</div>
<?php if ($comments->children) { ?>
<div class="comment-children d-flex flex-start">
<?php $comments->threadedComments($options); ?>
</div>
<?php } ?>
</li>
<?php } ?>
<div class="col-12">
<div id="comments" data-no-instant>
<?php $this->comments()->to($comments); ?>
<?php if ($this->allow('comment')): ?>
<div id="<?php $this->respondId(); ?>" class="respond mb-5">
<form method="post" action="<?php $this->commentUrl() ?>" id="comment-form" role="form" class="mb-3" data-no-instant>
<?php if (!$this->user->hasLogin()): ?>
<div class="d-flex flex-row gap-2 mb-2">
<input name="author" type="text" class="form-control" placeholder="昵称" required
value="<?php $this->remember('author'); ?>" required/>
<input name="mail" type="email" class="form-control" placeholder="邮箱" required
value="<?php $this->remember('mail'); ?>" <?php if ($this->options->commentsRequireMail): ?> required<?php endif; ?>/>
<input type="url" name="url" id="url" class="form-control"
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="d-flex mb-3">
<div class="form-floating w-100">
<textarea rows="8" cols="50" name="text" id="textarea"
class="form-control comments-textarea"
required
placeholder="请输入评论内容"><?php $this->remember('text'); ?></textarea>
<label for="floatingTextarea">请输入评论内容</label>
</div>
</div>
<div class="d-flex align-items-center justify-content-between">
<div class="comments-curren-user d-flex align-items-center align-content-center">
<?php if ($this->user->hasLogin()): ?>
<img class="img-thumbnail rounded me-1" width="50" height="50"
src="<?php echo getAvatarByMail($this->user->mail, true); ?>"
alt="<?php $this->user->screenName(); ?>">
<div class="d-flex flex-column">
<span><?php $this->user->screenName(); ?></span>
<span>
<a class="a-btn btn" href="<?php $this->options->logoutUrl(); ?>"
title="注销">注销</a>
</span>
</div>
<?php endif; ?>
</div>
<div class="d-flex gap-2 align-content-end justify-content-end">
<?php $comments->cancelReply(); ?>
<button type="submit" class="btn btn-dark btn-sm"><?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>