48 lines
2.1 KiB
PHP
48 lines
2.1 KiB
PHP
<?php
|
|
require_once __DIR__ . "/../includes/functions.php";
|
|
require_once __DIR__ . "/../includes/auth.php";
|
|
$adminPage = "comments";
|
|
$pageTitle = "评论管理";
|
|
require __DIR__ . "/_layout.php";
|
|
|
|
if (isset($_GET["del"])) {
|
|
$cid = (int)$_GET["del"];
|
|
db()->prepare("DELETE FROM comments WHERE id=?")->execute([$cid]);
|
|
header("Location: comment.php?deleted=1"); exit;
|
|
}
|
|
$page = isset($_GET["page"]) ? max(1,(int)$_GET["page"]) : 1;
|
|
$per = 15;
|
|
$total = (int)db()->query("SELECT COUNT(*) FROM comments")->fetchColumn();
|
|
$pages = max(1,(int)ceil($total/$per));
|
|
$page = min($page,$pages);
|
|
$off = ($page-1)*$per;
|
|
$stmt = db()->prepare("SELECT cm.*, a.title AS atitle FROM comments cm LEFT JOIN articles a ON a.id=cm.article_id ORDER BY cm.created_at DESC LIMIT ? OFFSET ?");
|
|
$stmt->bindValue(1,$per,PDO::PARAM_INT);
|
|
$stmt->bindValue(2,$off,PDO::PARAM_INT);
|
|
$stmt->execute();
|
|
$list = $stmt->fetchAll();
|
|
?>
|
|
<div class="admin-head"><h1>评论管理</h1></div>
|
|
<?php if (isset($_GET["deleted"])) { ?><div class="msg ok">删除成功</div><?php } ?>
|
|
<div class="card glass">
|
|
<table class="admin-table">
|
|
<thead><tr><th style="width:40px">ID</th><th>评论内容</th><th>昵称</th><th>文章</th><th>时间</th><th>操作</th></tr></thead>
|
|
<tbody>
|
|
<?php if(!$list): ?><tr><td colspan="6" class="text-muted">暂无评论</td></tr><?php endif; ?>
|
|
<?php foreach($list as $c): ?>
|
|
<tr>
|
|
<td><?php echo $c["id"]; ?></td>
|
|
<td><?php echo e(mb_strimwidth($c["content"],0,60,"...")); ?></td>
|
|
<td><?php echo e($c["author"]); ?></td>
|
|
<td class="text-muted"><?php echo e(mb_strimwidth($c["atitle"] ?? "已删除",0,20,"...")); ?></td>
|
|
<td class="text-muted"><?php echo e($c["created_at"]); ?></td>
|
|
<td><div class="actions"><a href="?del=<?php echo $c["id"]; ?>" data-confirm="确定删除该评论?">删除</a></div></td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
</tbody>
|
|
</table>
|
|
<div class="pagination">
|
|
<?php for($i=1;$i<=$pages;$i++): ?><a class="<?php echo $i===$page?"current":""; ?>" href="?page=<?php echo $i; ?>"><?php echo $i; ?></a><?php endfor; ?>
|
|
</div>
|
|
</div>
|
|
<?php require __DIR__ . "/_tail.php"; ?>
|