木漏茶室源码下载中心
整站 PHP 源码:可浏览文件、复制路径、下载单文件或打包 ZIP。
发布版本 v6.25.232
升级后自动生成独立源码包,下载中心只发送这份冻结包
已排除 config.php / 用户数据 / 上传文件 / 升级备份
COMMUNITY DEPLOYMENTS
已经跑起来的木漏茶室
从源码下载中心下载、完成安装并回传验证的站外站点。每个站点只计 1 次部署下载量;已记录站点会实时读取名称、版本、Logo 与在线状态,本机、内网和证书异常站点无法完成回传。
实时检测
2
个站点已部署
木
木漏茶室
mlcs.xnn.lol · v6.25.232
访问 ↗
2026.11.21
在线
木
木漏茶室
mlcs.nbnb.mom · v6.25.232
访问 ↗
2026.11.20
在线
已展示全部 2 个站点。
admin/posts.php
9.4 KB · 发布包 v6.25.232
<?php
/**
* 后台 · 帖子管理
*/
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
check_csrf();
$act = input('act');
if ($act === 'bulk_delete') {
$ids = $_POST['ids'] ?? [];
$ids = array_values(array_unique(array_filter(array_map('intval', is_array($ids) ? $ids : [$ids]))));
$done = 0;
foreach (array_slice($ids, 0, 100) as $bid) {
$bp = DB::one('SELECT * FROM ' . DB::table('posts') . ' WHERE id = ?', [$bid]);
if (!$bp) { continue; }
if (is_superadmin(user_by_id((int) $bp['user_id'])) && !is_superadmin(current_user())) { continue; }
post_delete($bid);
$done++;
}
audit_log('bulk_delete_posts', $done . ' 篇');
flash('已批量删除 ' . $done . ' 篇帖子');
redirect(admin_url('posts', array_filter(['p' => input('p'), 'q' => input('q'), 'cat' => input('cat'), 'status' => input('status')])));
}
$pid = (int) input('pid');
$post = DB::one('SELECT * FROM ' . DB::table('posts') . ' WHERE id = ?', [$pid]);
if (!$post) {
flash('帖子不存在', 'err');
redirect(admin_url('posts'));
}
$authorSuper = is_superadmin(user_by_id((int) $post['user_id']));
$actorSuper = is_superadmin(current_user());
if ($authorSuper && !$actorSuper) {
flash('超级管理员的帖子不能由管理员置顶、加精、隐藏、锁定或删除', 'err');
redirect(admin_url('posts', array_filter(['p' => input('p'), 'q' => input('q'), 'cat' => input('cat')])));
}
if ($act === 'lock') {
$newLocked = (int) ($post['is_locked'] ?? 0) === 1 ? 0 : 1;
DB::run('UPDATE ' . DB::table('posts') . ' SET is_locked = ? WHERE id = ?', [$newLocked, $pid]);
flash($newLocked ? '帖子已上锁,只有管理员和超级管理员可以评论' : '帖子已解锁,所有登录用户都可以评论');
} elseif ($act === 'top') {
$newTop = (int) $post['is_top'] === 1 ? 0 : 1;
DB::run('UPDATE ' . DB::table('posts') . ' SET is_top = ?, top_at = ? WHERE id = ?', [$newTop, $newTop ? now() : '', $pid]);
flash('置顶状态已更新');
} elseif ($act === 'feature') {
DB::run('UPDATE ' . DB::table('posts') . ' SET is_featured = ? WHERE id = ?', [(int) $post['is_featured'] === 1 ? 0 : 1, $pid]);
flash('精华状态已更新');
} elseif ($act === 'hide') {
DB::run('UPDATE ' . DB::table('posts') . ' SET status = ? WHERE id = ?', [(int) $post['status'] === 1 ? 0 : 1, $pid]);
flash('帖子可见状态已切换');
} elseif ($act === 'delete') {
post_delete($pid);
audit_log('delete_post', '帖子 #' . $pid);
flash('帖子及其附件文件已一起删除');
}
redirect(admin_url('posts', array_filter(['p' => input('p'), 'q' => input('q'), 'cat' => input('cat')])));
}
$q = trim((string) input('q', ''));
$cat = (int) input('cat', 0);
$status = input('status', '');
$where = ['1'];
$params = [];
if ($q !== '') {
$where[] = 'p.title LIKE ?';
$params[] = '%' . $q . '%';
}
if ($cat > 0) {
$where[] = 'p.cat_id = ?';
$params[] = $cat;
}
if (in_array($status, ['1', '0', '2', '3'], true)) {
$where[] = 'p.status = ?';
$params[] = (int) $status;
}
$whereSql = implode(' AND ', $where);
$total = (int) DB::val('SELECT COUNT(*) FROM ' . DB::table('posts') . ' p WHERE ' . $whereSql, $params, 0);
$pager = paginate($total, 20);
$posts = DB::all('SELECT p.*, u.nickname, u.username, u.avatar, u.role, c.name AS cat_name,
(SELECT COUNT(*) FROM ' . DB::table('comments') . ' c1 WHERE c1.post_id = p.id AND c1.status = 1) AS comment_count,
(SELECT COUNT(*) FROM ' . DB::table('likes') . ' l WHERE l.post_id = p.id) AS like_count
FROM ' . DB::table('posts') . ' p
LEFT JOIN ' . DB::table('users') . ' u ON u.id = p.user_id
LEFT JOIN ' . DB::table('categories') . ' c ON c.id = p.cat_id
WHERE ' . $whereSql . ' ORDER BY p.is_top DESC, p.top_at DESC, p.id DESC
LIMIT ' . $pager['limit'] . ' OFFSET ' . $pager['offset'], $params);
$categories = DB::all('SELECT * FROM ' . DB::table('categories') . ' ORDER BY sort ASC, id ASC');
?>
<div class="admin-head">
<div><h1>帖子管理</h1><p>共 <?= $total ?> 篇 · 可置顶、加精、隐藏、锁定与删除</p></div>
<form method="get" class="admin-search multi">
<input type="hidden" name="page" value="admin"><input type="hidden" name="s" value="posts">
<select name="cat">
<option value="0">全部板块</option>
<?php foreach ($categories as $c): ?><option value="<?= (int) $c['id'] ?>" <?= $cat === (int) $c['id'] ? 'selected' : '' ?>><?= e($c['name']) ?></option><?php endforeach; ?>
</select>
<select name="status">
<option value="">全部状态</option>
<option value="1" <?= $status === '1' ? 'selected' : '' ?>>已发布</option>
<option value="0" <?= $status === '0' ? 'selected' : '' ?>>已隐藏</option>
<option value="2" <?= $status === '2' ? 'selected' : '' ?>>审核中</option>
<option value="3" <?= $status === '3' ? 'selected' : '' ?>>已驳回</option>
</select>
<input type="search" name="q" value="<?= e($q) ?>" placeholder="搜索标题">
<button class="btn-mini" type="submit">筛选</button>
</form>
</div>
<section class="panel">
<form method="post" class="bulk-review-bar" id="bulkPostsForm" data-confirm="确定批量删除选中的帖子?">
<?= csrf_field() ?>
<input type="hidden" name="act" value="bulk_delete">
<span class="muted">勾选帖子后可批量删除(超级管理员帖子仅超管可删)</span>
<button class="btn-mini danger" type="submit">批量删除</button>
</form>
<div class="admin-table">
<div class="at-head"><span>帖子</span><span>作者</span><span>数据</span><span>状态</span><span>时间</span><span>操作</span></div>
<?php foreach ($posts as $p): ?>
<?php $postAuthorSuper = is_superadmin($p); $canModeratePost = !$postAuthorSuper || is_superadmin(current_user()); ?>
<div class="at-row">
<div class="at-main">
<?php if ($canModeratePost): ?><label class="bulk-check"><input type="checkbox" name="ids[]" value="<?= (int) $p['id'] ?>" form="bulkPostsForm"> 选择</label><?php endif; ?>
<a href="<?= e(page_url('post', ['id' => $p['id']])) ?>"><?= e(post_display_title($p, 80)) ?></a>
<span><?= e($p['cat_name'] ?: '未分类') ?><?php if ($p['password'] !== ''): ?> · 🔒 密码帖<?php endif; ?></span>
</div>
<div class="at-user small">
<?= avatar_html($p, 'at-avatar') ?>
<span><?= e(display_name($p)) ?></span>
</div>
<span class="muted"><?= (int) $p['views'] ?> 阅 · <?= (int) $p['like_count'] ?> 赞 · <?= (int) $p['comment_count'] ?> 评</span>
<span class="at-flags">
<?php if ((int) $p['is_top'] === 1): ?><span class="tag top">顶</span><?php endif; ?>
<?php if ((int) $p['is_featured'] === 1): ?><span class="tag feat">精</span><?php endif; ?>
<?php if ((int) ($p['is_locked'] ?? 0) === 1): ?><span class="tag locked">🔒 锁</span><?php endif; ?>
<span class="status-pill <?= (int) $p['status'] === 1 ? 'ok' : 'bad' ?>"><?= e(post_status_text($p['status'])) ?></span>
</span>
<span class="muted"><?= e(substr($p['created_at'], 0, 10)) ?></span>
<span class="at-ops">
<?php if ($canModeratePost): ?>
<a class="btn-mini ghost" href="<?= e(page_url('compose', ['id' => $p['id']])) ?>">编辑</a>
<form method="post" class="inline-form"><?= csrf_field() ?><input type="hidden" name="act" value="lock"><input type="hidden" name="pid" value="<?= (int) $p['id'] ?>"><button class="link-btn" type="submit"><?= (int) ($p['is_locked'] ?? 0) === 1 ? '🔓 解锁' : '🔒 上锁' ?></button></form>
<form method="post" class="inline-form"><?= csrf_field() ?><input type="hidden" name="act" value="top"><input type="hidden" name="pid" value="<?= (int) $p['id'] ?>"><button class="link-btn" type="submit"><?= (int) $p['is_top'] === 1 ? '取消顶' : '置顶' ?></button></form>
<form method="post" class="inline-form"><?= csrf_field() ?><input type="hidden" name="act" value="feature"><input type="hidden" name="pid" value="<?= (int) $p['id'] ?>"><button class="link-btn" type="submit"><?= (int) $p['is_featured'] === 1 ? '取消精' : '加精' ?></button></form>
<form method="post" class="inline-form"><?= csrf_field() ?><input type="hidden" name="act" value="hide"><input type="hidden" name="pid" value="<?= (int) $p['id'] ?>"><button class="link-btn" type="submit"><?= (int) $p['status'] === 1 ? '隐藏' : '显示' ?></button></form>
<form method="post" class="inline-form" data-confirm="删除这篇帖子?"><?= csrf_field() ?><input type="hidden" name="act" value="delete"><input type="hidden" name="pid" value="<?= (int) $p['id'] ?>"><button class="link-btn danger" type="submit">删除</button></form>
<?php else: ?>
<span class="muted">超级管理员内容 · 仅超管可操作</span>
<?php endif; ?>
</span>
</div>
<?php endforeach; ?>
<?php if (!$posts): ?><?php empty_state('没有符合条件的帖子'); ?><?php endif; ?>
</div>
<?= pager_html($pager, 'admin', array_filter(['s' => 'posts', 'q' => $q !== '' ? $q : null, 'cat' => $cat ?: null, 'status' => $status !== '' ? $status : null])) ?>
</section>