FeedLite 初始提交:通用轻量级反馈系统(PHP + SQLite,零依赖)

- 前台:问题列表 / 详情 / 发布与回复(趣味问答验证码、蜜罐、IP 限流)
- 后台:先审后显、站点设置(站点标题/描述、附件存储、OSS 参数)、操作日志
- 附件:关闭 / 本机硬盘 / 阿里云 OSS 浏览器直传(ECS 实例 RAM 角色)三种模式
- 品牌资源:全套图标(favicon.ico / SVG / PNG 各尺寸 / manifest)
- 安全:CSRF、session 加固、.htaccess 屏蔽敏感文件、口令仅存哈希
- 配置:config.example.php 为模板,config.php 不入库
This commit is contained in:
2026-09-28 20:34:37 +08:00
commit cede838b5e
42 changed files with 5911 additions and 0 deletions
+153
View File
@@ -0,0 +1,153 @@
<?php
/**
* 问题列表
*/
require __DIR__ . '/lib/bootstrap.php';
$pdo = fb_db();
$cats = fb_categories();
$statuses = fb_statuses();
$cat = isset($_GET['cat']) ? (string)$_GET['cat'] : '';
$st = isset($_GET['status']) ? (string)$_GET['status'] : '';
$q = isset($_GET['q']) ? trim((string)$_GET['q']) : '';
$sort = isset($_GET['sort']) ? (string)$_GET['sort'] : 'active';
if ($cat !== '' && !isset($cats[$cat])) { $cat = ''; }
if ($st !== '' && !isset($statuses[$st])) { $st = ''; }
if ($sort !== 'new') { $sort = 'active'; }
$where = [];
$args = [];
// 审核(先审后显):访客只看已通过审核的;管理员登录审核后台后可看全部
if (fb_moderation_on() && !fb_is_admin()) { $where[] = 'visible = 1'; }
if ($cat !== '') { $where[] = 'category = ?'; $args[] = $cat; }
if ($st !== '') { $where[] = 'status = ?'; $args[] = $st; }
if ($q !== '') {
$like = '%' . addcslashes($q, '%_\\') . '%';
$where[] = "(title LIKE ? ESCAPE '\\' OR body LIKE ? ESCAPE '\\')";
$args[] = $like;
$args[] = $like;
}
$wsql = $where ? (' WHERE ' . implode(' AND ', $where)) : '';
$order = ($sort === 'new') ? 'created_at DESC' : 'updated_at DESC';
$stc = $pdo->prepare('SELECT COUNT(*) FROM threads' . $wsql);
$stc->execute($args);
$total = (int)$stc->fetchColumn();
$pageSize = max(5, (int)fb_cfg('page_size', 20));
$pages = max(1, (int)ceil($total / $pageSize));
$page = isset($_GET['page']) ? (int)$_GET['page'] : 1;
if ($page < 1) { $page = 1; }
if ($page > $pages){ $page = $pages; }
$offset = ($page - 1) * $pageSize;
$sql = 'SELECT id, title, category, status, author_name, reply_count, created_at, updated_at,'
. ' substr(body, 1, 300) AS excerpt FROM threads'
. $wsql . ' ORDER BY ' . $order . ' LIMIT ' . $pageSize . ' OFFSET ' . $offset;
$sth = $pdo->prepare($sql);
$sth->execute($args);
$threads = $sth->fetchAll();
// 附件缩略图与数量(只在有附件时才有开销)
$tids = [];
foreach ($threads as $t) { $tids[] = (int)$t['id']; }
$attImgs = $tids ? fb_attach_map_images($pdo, $tids, 3) : [];
$attCount = $tids ? fb_attach_count_map($pdo, $tids) : [];
fb_layout_head('全部问题');
?>
<div class="page-head">
<div>
<h1>全部问题</h1>
<p class="muted"><?php echo e((string)fb_cfg('site_desc')); ?></p>
</div>
<a class="btn primary" href="new.php">我要反馈</a>
</div>
<div class="filters">
<div class="chips">
<a class="chip <?php echo $cat === '' ? 'on' : ''; ?>" href="<?php echo e(fb_qs(['cat' => null, 'page' => null]) ?: '?'); ?>">全部</a>
<?php foreach ($cats as $k => $v): ?>
<a class="chip <?php echo $cat === $k ? 'on' : ''; ?>" href="<?php echo e(fb_qs(['cat' => $k, 'page' => null])); ?>"><?php echo e($v); ?></a>
<?php endforeach; ?>
</div>
<form class="filter-row" method="get" action="">
<input type="hidden" name="cat" value="<?php echo e($cat); ?>">
<select name="status" onchange="this.form.submit()">
<option value="">全部状态</option>
<?php foreach ($statuses as $k => $v): ?>
<option value="<?php echo e($k); ?>" <?php echo $st === $k ? 'selected' : ''; ?>><?php echo e($v); ?></option>
<?php endforeach; ?>
</select>
<select name="sort" onchange="this.form.submit()">
<option value="active" <?php echo $sort === 'active' ? 'selected' : ''; ?>>按最新回复</option>
<option value="new" <?php echo $sort === 'new' ? 'selected' : ''; ?>>按最新发布</option>
</select>
<input type="search" name="q" value="<?php echo e($q); ?>" placeholder="搜索标题或内容…">
<button class="btn" type="submit">搜索</button>
</form>
</div>
<div class="list">
<?php if (!$threads): ?>
<div class="empty">
<p>还没有符合条件的问题。</p>
<p><a class="btn primary" href="new.php">来提第一个吧</a></p>
</div>
<?php else: ?>
<?php foreach ($threads as $t): ?>
<a class="item" href="thread.php?id=<?php echo (int)$t['id']; ?>">
<div class="item-top">
<span class="badge cat"><?php echo e(fb_category_label($t['category'])); ?></span>
<span class="badge st st-<?php echo e($t['status']); ?>"><?php echo e(fb_status_label($t['status'])); ?></span>
<span class="item-title"><?php echo e($t['title']); ?></span>
<span class="item-id" title="问题编号">#<?php echo (int)$t['id']; ?></span>
</div>
<p class="item-ex"><?php echo e(fb_excerpt($t['excerpt'], 120)); ?></p>
<?php if (!empty($attImgs[(int)$t['id']])): ?>
<div class="thumbs">
<?php foreach ($attImgs[(int)$t['id']] as $im): ?>
<img loading="lazy" alt="" src="<?php echo e(fb_attach_thumb_url($im['oss_key'], 200, isset($im['mime']) ? $im['mime'] : '')); ?>">
<?php endforeach; ?>
</div>
<?php endif; ?>
<div class="item-meta">
<span class="who"><?php echo e($t['author_name']); ?></span>
<span class="dot">·</span>
<span><?php echo e(fb_fmt_time($t['updated_at'])); ?></span>
<span class="dot">·</span>
<span><?php echo (int)$t['reply_count']; ?> 条回复</span>
<?php if (!empty($attCount[(int)$t['id']])): ?>
<span class="dot">·</span>
<span class="att-tag">附件 <?php echo (int)$attCount[(int)$t['id']]; ?></span>
<?php endif; ?>
</div>
</a>
<?php endforeach; ?>
<?php endif; ?>
</div>
<?php if ($pages > 1): ?>
<div class="pager">
<?php
$mk = function ($p) {
return e(fb_qs(['page' => $p <= 1 ? null : $p]) ?: '?');
};
?>
<?php if ($page > 1): ?>
<a class="btn" href="<?php echo $mk($page - 1); ?>">上一页</a>
<?php endif; ?>
<span class="pager-info">第 <?php echo (int)$page; ?> / <?php echo (int)$pages; ?> 页 · 共 <?php echo (int)$total; ?> 个问题</span>
<?php if ($page < $pages): ?>
<a class="btn" href="<?php echo $mk($page + 1); ?>">下一页</a>
<?php endif; ?>
</div>
<?php elseif ($total > 0): ?>
<div class="pager"><span class="pager-info">共 <?php echo (int)$total; ?> 个问题</span></div>
<?php endif; ?>
<?php
fb_layout_foot();