Files

54 lines
2.6 KiB
PHP
Raw Permalink Normal View History

<?php
/**
* 单条评论(顶层 / 回复共用)
* 依赖外部变量:$c(评论行)、$ctType、$ctId
*/
$row = $c;
$canDelete = \App\Auth::isAdmin() || (int)$row['author_id'] === (int)\App\Auth::id();
$authorName = (string)($row['author_name'] ?? '');
if ($authorName === '') $authorName = '已注销用户';
?>
<div class="comment-item<?= $row['parent_id'] !== null ? ' comment-child' : '' ?>"
id="comment-<?= (int)$row['id'] ?>">
<div class="comment-head">
<?php if (!empty($row['author_avatar'])): ?>
<img src="<?= e($row['author_avatar']) ?>" alt="" class="avatar-sm">
<?php else: ?>
<span class="avatar-sm avatar-placeholder"><?= e(mb_substr($authorName, 0, 1)) ?></span>
<?php endif; ?>
<span class="comment-author"><?= e($authorName) ?></span>
<?php if (($row['author_role'] ?? '') === 'admin'): ?>
<span class="role-tag role-admin">管理员</span>
<?php endif; ?>
<span class="comment-time"><?= date('Y-m-d H:i', strtotime((string)$row['created_at'])) ?></span>
<?php if ($canDelete): ?>
<form method="post" action="<?= url('comments/destroy') ?>" class="comment-del-form"
onsubmit="return confirm('确定删除这条评论?它下面的回复也会一起删除。');">
<input type="hidden" name="_csrf" value="<?= e(csrf_token()) ?>">
<input type="hidden" name="id" value="<?= (int)$row['id'] ?>">
<input type="hidden" name="target_type" value="<?= e($ctType) ?>">
<input type="hidden" name="target_id" value="<?= (int)$ctId ?>">
<button type="submit" class="comment-del">删除</button>
</form>
<?php endif; ?>
</div>
<div class="comment-body"><?= nl2br(e($row['content'])) ?></div>
<details class="comment-reply-box">
<summary>回复</summary>
<form method="post" action="<?= url('comments/store') ?>" class="comment-form comment-form-inline">
<input type="hidden" name="_csrf" value="<?= e(csrf_token()) ?>">
<input type="hidden" name="target_type" value="<?= e($ctType) ?>">
<input type="hidden" name="target_id" value="<?= (int)$ctId ?>">
<input type="hidden" name="parent_id" value="<?= (int)$row['id'] ?>">
<textarea name="content" rows="2" maxlength="2000" required
placeholder="回复 <?= e($authorName) ?>…"></textarea>
<div class="form-actions">
<button type="submit" class="btn-sm btn-primary-sm">发表回复</button>
</div>
</form>
</details>
</div>