2016-07-18 16:39:37 +00:00
|
|
|
|
<?php
|
2022-11-06 02:26:21 +00:00
|
|
|
|
requireLib('bootstrap5');
|
|
|
|
|
requireLib('mathjax');
|
|
|
|
|
requireLib('hljs');
|
2023-01-31 07:09:12 +00:00
|
|
|
|
requireLib('pdf.js');
|
2022-11-06 02:26:21 +00:00
|
|
|
|
requirePHPLib('form');
|
2022-03-17 04:00:03 +00:00
|
|
|
|
|
2022-11-11 23:10:34 +00:00
|
|
|
|
Auth::check() || redirectToLogin();
|
2022-11-06 02:26:21 +00:00
|
|
|
|
UOJBlog::init(UOJRequest::get('id')) || UOJResponse::page404();
|
|
|
|
|
UOJBlog::cur()->belongsToUserBlog() || UOJResponse::page404();
|
|
|
|
|
UOJBlog::cur()->userCanView(Auth::user()) || UOJResponse::page403();
|
|
|
|
|
|
|
|
|
|
$blog = UOJBlog::info();
|
|
|
|
|
|
|
|
|
|
function getCommentContentToDisplay($comment) {
|
|
|
|
|
if (!$comment['is_hidden']) {
|
|
|
|
|
return $comment['content'];
|
|
|
|
|
} else {
|
|
|
|
|
return '<span class="text-muted">【' . HTML::escape($comment['reason_to_hide']) . '】</span>';
|
2022-03-17 04:00:03 +00:00
|
|
|
|
}
|
2022-11-06 02:26:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-02-01 12:39:24 +00:00
|
|
|
|
$comment_form = new UOJForm('comment');
|
|
|
|
|
$comment_form->addTextArea('comment', [
|
|
|
|
|
'label' => '内容',
|
|
|
|
|
'validator_php' => function ($comment) {
|
2022-11-21 12:14:47 +00:00
|
|
|
|
if (!Auth::check()) {
|
2022-11-06 02:26:21 +00:00
|
|
|
|
return '请先登录';
|
|
|
|
|
}
|
|
|
|
|
if (!$comment) {
|
|
|
|
|
return '评论不能为空';
|
|
|
|
|
}
|
|
|
|
|
if (strlen($comment) > 1000) {
|
|
|
|
|
return '不能超过1000个字节';
|
|
|
|
|
}
|
|
|
|
|
return '';
|
|
|
|
|
},
|
2023-02-01 12:39:24 +00:00
|
|
|
|
]);
|
2022-11-06 02:26:21 +00:00
|
|
|
|
$comment_form->handle = function () {
|
2023-02-01 12:39:24 +00:00
|
|
|
|
global $blog, $comment_form;
|
2022-11-06 02:26:21 +00:00
|
|
|
|
$comment = HTML::escape($_POST['comment']);
|
|
|
|
|
|
|
|
|
|
list($comment, $referrers) = uojHandleAtSign($comment, "/post/{$blog['id']}");
|
|
|
|
|
|
|
|
|
|
DB::insert([
|
|
|
|
|
"insert into blogs_comments",
|
|
|
|
|
"(poster, blog_id, content, reply_id, post_time)",
|
|
|
|
|
"values", DB::tuple([Auth::id(), $blog['id'], $comment, 0, DB::now()])
|
|
|
|
|
]);
|
|
|
|
|
$comment_id = DB::insert_id();
|
|
|
|
|
|
|
|
|
|
$rank = DB::selectCount([
|
|
|
|
|
"select count(*) from blogs_comments",
|
|
|
|
|
"where", [
|
|
|
|
|
"blog_id" => $blog['id'],
|
|
|
|
|
"reply_id" => 0,
|
|
|
|
|
["id", "<", $comment_id]
|
|
|
|
|
]
|
|
|
|
|
]);
|
|
|
|
|
$page = floor($rank / 20) + 1;
|
2022-10-08 06:10:14 +00:00
|
|
|
|
|
2022-11-06 02:26:21 +00:00
|
|
|
|
$uri = getLongTablePageUri($page) . '#' . "comment-{$comment_id}";
|
2022-11-11 23:11:49 +00:00
|
|
|
|
$user_link = UOJUser::getLink(Auth::user());
|
2022-11-06 02:26:21 +00:00
|
|
|
|
|
|
|
|
|
foreach ($referrers as $referrer) {
|
|
|
|
|
$content = $user_link . ' 在博客 ' . $blog['title'] . ' 的评论里提到你:<a href="' . $uri . '">点击此处查看</a>';
|
|
|
|
|
sendSystemMsg($referrer, '有人提到你', $content);
|
2016-07-18 16:39:37 +00:00
|
|
|
|
}
|
2022-11-06 02:26:21 +00:00
|
|
|
|
|
|
|
|
|
if ($blog['poster'] !== Auth::id()) {
|
|
|
|
|
$content = $user_link . ' 回复了您的博客 ' . $blog['title'] . ' :<a href="' . $uri . '">点击此处查看</a>';
|
|
|
|
|
sendSystemMsg($blog['poster'], '博客新回复通知', $content);
|
2016-07-18 16:39:37 +00:00
|
|
|
|
}
|
2022-09-29 14:02:56 +00:00
|
|
|
|
|
2022-11-06 02:26:21 +00:00
|
|
|
|
UOJBlog::cur()->updateActiveTime();
|
|
|
|
|
$comment_form->succ_href = getLongTablePageRawUri($page);
|
|
|
|
|
};
|
2023-02-01 12:39:24 +00:00
|
|
|
|
$comment_form->config['ctrl_enter_submit'] = true;
|
2022-11-06 02:26:21 +00:00
|
|
|
|
$comment_form->runAtServer();
|
2022-10-03 01:35:29 +00:00
|
|
|
|
|
2023-02-01 12:39:24 +00:00
|
|
|
|
$reply_form = new UOJForm('reply');
|
2022-11-06 02:26:21 +00:00
|
|
|
|
$reply_form->addHidden(
|
|
|
|
|
'reply_id',
|
|
|
|
|
'0',
|
|
|
|
|
function ($reply_id, &$vdata) {
|
|
|
|
|
global $blog;
|
|
|
|
|
if (!validateUInt($reply_id) || $reply_id == 0) {
|
|
|
|
|
return '您要回复的对象不存在';
|
2022-10-03 01:35:29 +00:00
|
|
|
|
}
|
2022-11-06 02:26:21 +00:00
|
|
|
|
$comment = UOJBlogComment::query($reply_id);
|
2023-02-01 12:04:48 +00:00
|
|
|
|
if (!$comment || $comment->info['blog_id'] != $blog['id']) {
|
2022-11-06 02:26:21 +00:00
|
|
|
|
return '您要回复的对象不存在';
|
2016-07-18 16:39:37 +00:00
|
|
|
|
}
|
2022-11-06 02:26:21 +00:00
|
|
|
|
$vdata['parent'] = $comment;
|
|
|
|
|
return '';
|
|
|
|
|
},
|
|
|
|
|
null
|
|
|
|
|
);
|
2023-02-01 12:39:24 +00:00
|
|
|
|
$reply_form->addTextArea('reply_comment', [
|
|
|
|
|
'label' => '内容',
|
|
|
|
|
'validator_php' => function ($comment) {
|
2022-11-06 02:26:21 +00:00
|
|
|
|
if (!Auth::check()) {
|
|
|
|
|
return '请先登录';
|
2016-07-18 16:39:37 +00:00
|
|
|
|
}
|
2022-11-06 02:26:21 +00:00
|
|
|
|
if (!$comment) {
|
|
|
|
|
return '评论不能为空';
|
2016-07-18 16:39:37 +00:00
|
|
|
|
}
|
2022-11-06 02:26:21 +00:00
|
|
|
|
if (strlen($comment) > 140) {
|
|
|
|
|
return '不能超过140个字节';
|
2016-07-18 16:39:37 +00:00
|
|
|
|
}
|
2022-11-06 02:26:21 +00:00
|
|
|
|
return '';
|
|
|
|
|
},
|
2023-02-01 12:39:24 +00:00
|
|
|
|
]);
|
2022-11-06 02:26:21 +00:00
|
|
|
|
$reply_form->handle = function (&$vdata) {
|
2023-02-01 12:39:24 +00:00
|
|
|
|
global $blog, $reply_form;
|
2022-11-06 02:26:21 +00:00
|
|
|
|
$comment = HTML::escape($_POST['reply_comment']);
|
|
|
|
|
|
|
|
|
|
list($comment, $referrers) = uojHandleAtSign($comment, "/post/{$blog['id']}");
|
|
|
|
|
|
|
|
|
|
$reply_id = $_POST['reply_id'];
|
|
|
|
|
|
|
|
|
|
DB::insert([
|
|
|
|
|
"insert into blogs_comments",
|
|
|
|
|
"(poster, blog_id, content, reply_id, post_time)",
|
|
|
|
|
"values", DB::tuple([Auth::id(), $blog['id'], $comment, $reply_id, DB::now()])
|
|
|
|
|
]);
|
|
|
|
|
$comment_id = DB::insert_id();
|
|
|
|
|
|
|
|
|
|
$rank = DB::selectCount([
|
|
|
|
|
"select count(*) from blogs_comments",
|
|
|
|
|
"where", [
|
|
|
|
|
"blog_id" => $blog['id'],
|
|
|
|
|
"reply_id" => 0,
|
|
|
|
|
["id", "<", $reply_id]
|
|
|
|
|
]
|
|
|
|
|
]);
|
|
|
|
|
$page = floor($rank / 20) + 1;
|
|
|
|
|
|
|
|
|
|
$uri = getLongTablePageUri($page) . '#' . "comment-{$reply_id}";
|
2022-11-11 23:11:49 +00:00
|
|
|
|
$user_link = UOJUser::getLink(Auth::user());
|
2022-11-06 02:26:21 +00:00
|
|
|
|
|
|
|
|
|
foreach ($referrers as $referrer) {
|
|
|
|
|
$content = $user_link . ' 在博客 ' . $blog['title'] . ' 的评论里提到你:<a href="' . $uri . '">点击此处查看</a>';
|
|
|
|
|
sendSystemMsg($referrer, '有人提到你', $content);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$parent = $vdata['parent'];
|
|
|
|
|
$notified = [];
|
|
|
|
|
if ($parent->info['poster'] !== Auth::id()) {
|
|
|
|
|
$notified[] = $parent->info['poster'];
|
|
|
|
|
$content = $user_link . ' 回复了您在博客 ' . $blog['title'] . ' 下的评论 :<a href="' . $uri . '">点击此处查看</a>';
|
|
|
|
|
sendSystemMsg($parent->info['poster'], '评论新回复通知', $content);
|
|
|
|
|
}
|
|
|
|
|
if ($blog['poster'] !== Auth::id() && !in_array($blog['poster'], $notified)) {
|
|
|
|
|
$notified[] = $blog['poster'];
|
|
|
|
|
$content = $user_link . '回复了您的博客 ' . $blog['title'] . ' :<a href="' . $uri . '">点击此处查看</a>';
|
|
|
|
|
sendSystemMsg($blog['poster'], '博客新回复通知', $content);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UOJBlog::cur()->updateActiveTime();
|
|
|
|
|
|
|
|
|
|
$reply_form->succ_href = getLongTablePageRawUri($page);
|
|
|
|
|
};
|
2023-02-01 12:39:24 +00:00
|
|
|
|
$reply_form->config['ctrl_enter_submit'] = true;
|
2022-11-06 02:26:21 +00:00
|
|
|
|
$reply_form->runAtServer();
|
|
|
|
|
|
|
|
|
|
$comments_pag = new Paginator([
|
|
|
|
|
'col_names' => ['*'],
|
|
|
|
|
'table_name' => 'blogs_comments',
|
|
|
|
|
'cond' => 'blog_id = ' . $blog['id'] . ' and reply_id = 0',
|
|
|
|
|
'tail' => 'order by id asc',
|
|
|
|
|
'page_len' => 20
|
|
|
|
|
]);
|
|
|
|
|
?>
|
2016-07-18 16:39:37 +00:00
|
|
|
|
<?php echoUOJPageHeader(HTML::stripTags($blog['title']) . ' - 博客') ?>
|
2022-11-06 02:26:21 +00:00
|
|
|
|
<?php UOJBlog::cur()->echoView(['show_title_only' => isset($_GET['page']) && $_GET['page'] != 1]) ?>
|
|
|
|
|
|
2022-09-29 14:02:56 +00:00
|
|
|
|
<h2>
|
|
|
|
|
评论
|
|
|
|
|
<i class="bi bi-chat-fill"></i>
|
|
|
|
|
</h2>
|
2022-11-06 02:26:21 +00:00
|
|
|
|
|
2016-07-18 16:39:37 +00:00
|
|
|
|
<div class="list-group">
|
2022-11-06 02:26:21 +00:00
|
|
|
|
<?php if ($comments_pag->isEmpty()) : ?>
|
|
|
|
|
<div class="list-group-item text-muted">暂无评论</div>
|
|
|
|
|
<?php else : ?>
|
|
|
|
|
<?php foreach ($comments_pag->get() as $comment) :
|
|
|
|
|
$poster = UOJUser::query($comment['poster']);
|
|
|
|
|
$esc_email = HTML::escape($poster['email']);
|
|
|
|
|
$asrc = HTML::avatar_addr($poster, 80);
|
|
|
|
|
|
|
|
|
|
$replies = DB::selectAll([
|
|
|
|
|
"select id, poster, content, post_time, is_hidden, reason_to_hide from blogs_comments",
|
|
|
|
|
"where", ["reply_id" => $comment['id']],
|
|
|
|
|
"order by id"
|
|
|
|
|
]);
|
|
|
|
|
foreach ($replies as $idx => $reply) {
|
2023-01-14 10:24:36 +00:00
|
|
|
|
$reply_user = UOJUser::query($reply['poster']);
|
|
|
|
|
$replies[$idx]['poster_realname'] = $reply_user['realname'];
|
|
|
|
|
$replies[$idx]['poster_username_color'] = UOJUser::getUserColor($reply_user);
|
2022-11-06 02:26:21 +00:00
|
|
|
|
$replies[$idx]['content'] = getCommentContentToDisplay($reply);
|
|
|
|
|
}
|
|
|
|
|
$replies_json = json_encode($replies);
|
2022-09-18 04:58:35 +00:00
|
|
|
|
?>
|
2022-11-06 02:26:21 +00:00
|
|
|
|
<div id="comment-<?= $comment['id'] ?>" class="list-group-item">
|
|
|
|
|
<div class="d-flex">
|
|
|
|
|
<div class="comtposterbox mr-3 flex-shrink-0">
|
|
|
|
|
<a href="<?= HTML::url('/user/' . $poster['username']) ?>" class="d-none d-sm-block text-decoration-none">
|
|
|
|
|
<img class="media-object img-rounded" src="<?= $asrc ?>" alt="avatar" />
|
2022-09-29 14:02:56 +00:00
|
|
|
|
</a>
|
2022-11-06 02:26:21 +00:00
|
|
|
|
</div>
|
|
|
|
|
<div id="comment-body-<?= $comment['id'] ?>" class="comtbox flex-grow-1 ms-3">
|
|
|
|
|
<div class="row">
|
2022-11-11 23:11:49 +00:00
|
|
|
|
<div class="col-sm-6"><?= UOJUser::getLink($poster['username']) ?></div>
|
2022-11-06 02:26:21 +00:00
|
|
|
|
<div class="col-sm-6 text-end"><?= ClickZans::getBlock('BC', $comment['id'], $comment['zan']) ?></div>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="comtbox1"><?= $comment['content'] ?></div>
|
|
|
|
|
<ul class="list-inline mb-0 text-end">
|
|
|
|
|
<li>
|
|
|
|
|
<small class="text-muted">
|
|
|
|
|
<?= $comment['post_time'] ?>
|
|
|
|
|
</small>
|
|
|
|
|
</li>
|
|
|
|
|
<li>
|
|
|
|
|
<a class="text-decoration-none" id="reply-to-<?= $comment['id'] ?>" href="#">
|
|
|
|
|
回复
|
|
|
|
|
</a>
|
|
|
|
|
</li>
|
|
|
|
|
</ul>
|
|
|
|
|
<?php if ($replies) : ?>
|
|
|
|
|
<div id="replies-<?= $comment['id'] ?>" class="comtbox5"></div>
|
|
|
|
|
<?php endif ?>
|
|
|
|
|
<script type="text/javascript">
|
|
|
|
|
showCommentReplies('<?= $comment['id'] ?>', <?= $replies_json ?>);
|
|
|
|
|
</script>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2016-07-18 16:39:37 +00:00
|
|
|
|
</div>
|
2022-11-06 02:26:21 +00:00
|
|
|
|
<?php endforeach ?>
|
|
|
|
|
<?php endif ?>
|
2016-07-18 16:39:37 +00:00
|
|
|
|
</div>
|
|
|
|
|
<?= $comments_pag->pagination() ?>
|
|
|
|
|
|
2019-09-10 02:15:20 +00:00
|
|
|
|
<h3 class="mt-4">发表评论</h3>
|
2022-09-29 14:02:56 +00:00
|
|
|
|
<p>可以用 @mike 来提到 mike 这个用户,mike 会被高亮显示。如果你真的想打“@”这个字符,请用“@@”。</p>
|
2016-07-18 16:39:37 +00:00
|
|
|
|
<?php $comment_form->printHTML() ?>
|
|
|
|
|
|
|
|
|
|
<div id="div-form-reply" style="display:none">
|
|
|
|
|
<?php $reply_form->printHTML() ?>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<?php echoUOJPageFooter() ?>
|