多软件区分:邮件按软件换色+图标+软件名;补提交回执邮件

用户要求:多软件并存时,用「颜色 + 图标 + 名字」三重区分,
邮件也要跟着所属软件变,一眼能看出是哪款软件的来信。

1. software 表加 icon / download_url 字段(幂等迁移)
   - icon 存单个字符(emoji / 汉字 / 字母),不存图片路径:
     前端与邮件用同一个字符渲染,天然一致,不用再管一套上传与权限
   - 没配 icon 时取名首字兜底,任何地方都不出现空图标
   - 后台软件编辑加图标快选(12 个常用 emoji)

2. 邮件配色改为跟随软件(fb_mail_brand 取 fb_software_colors)
   - 头部色条、按钮、引用块色条、徽标全部跟着软件走
   - 邮件头部改为「图标色块 + 软件名」,下面再小字标站点名
   - 主题行统一加【软件名】前缀,不点开就能分辨

3. 新增 receipt 事件:提交后立即给提问人发「已收到、待审核、请耐心等待」
   - 独立开关 notify.receipt_enabled(与「回复通知」是两件事)
   - 新增 7 处调用前的静默 return 也一并写日志

4. reply 邮件补上下文:原提问摘要 + 本次回复,像博客评论通知
5. status=resolved 文案改为「已完成并上线」,配了下载地址时给下载按钮

验证:多软件配色/图标/前缀全部通过(含反向验证),XSS 转义通过,
空图标兜底通过;页面顶栏、页头、选择器图标渲染正确。
This commit is contained in:
2026-11-03 08:00:50 +08:00
parent e43f2ce67a
commit 738c6c09ff
12 changed files with 451 additions and 52 deletions
+37 -8
View File
@@ -280,21 +280,41 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['act'])) {
$msg = '#' . $id . ' 已删除。'; $msg = '#' . $id . ' 已删除。';
} elseif ($act === 'mail_test') { } elseif ($act === 'mail_test') {
// 发送测试邮件:只验证 SMTP 通不通,不改任何配置 // 发送测试邮件:只验证 SMTP 通不通,不改任何配置。
// 可选 sw=<软件id>:按那个软件的样子渲染(配色 / 图标 / 软件名),
// 便于在后台直接预览「不同软件的邮件长什么样」。
$to = trim((string)(isset($_POST['to']) ? $_POST['to'] : '')); $to = trim((string)(isset($_POST['to']) ? $_POST['to'] : ''));
if ($to === '') { $to = trim((string)fb_cfg('admin_email', '')); } if ($to === '') { $to = trim((string)fb_cfg('admin_email', '')); }
if ($to === '') { $to = trim((string)fb_cfg('smtp.user', '')); }
if (!filter_var($to, FILTER_VALIDATE_EMAIL)) { if (!filter_var($to, FILTER_VALIDATE_EMAIL)) {
$msg = '请填写有效的收件邮箱。'; $msg = '请填写有效的收件邮箱。';
$msgType = 'error'; $msgType = 'error';
} else { } else {
$sc = (array)fb_cfg('smtp', []); $sc = (array)fb_cfg('smtp', []);
$site = (string)fb_cfg('site_name', '轻反馈'); $site = (string)fb_cfg('site_name', '轻反馈');
$body = '<p>这是一封来自 <b>' . htmlspecialchars($site, ENT_QUOTES, 'UTF-8')
. '</b> 的测试邮件。</p>' // 选中的软件(没选就用默认软件,保证测试邮件也带软件标识)
. '<p>如果你收到了它,说明 SMTP 配置正确,回复通知可以正常发出。</p>' $swId = (int)(isset($_POST['sw']) ? $_POST['sw'] : 0);
. '<p style="color:#888;font-size:12px">发送时间:' $swRow = $swId > 0 ? fb_software($swId) : fb_default_software();
. date('Y-m-d H:i:s') . '</p>';
list($ok, $err) = fb_smtp_send($sc, $to, '【' . $site . '】邮件测试', $body); // 用真实的回执模板发,比一句「测试邮件」更能看出实际效果
$fake = [
'id' => 0,
'software_id' => $swRow ? (int)$swRow['id'] : 0,
'title' => '这是一封测试邮件,用来检查排版与配色',
'body' => "这是测试用的反馈正文。\n如果你收到这封信,说明 SMTP 配置正确,配色与图标也应当对应「"
. ($swRow ? (string)$swRow['name'] : '默认软件') . "」。\n\n发送时间:" . date('Y-m-d H:i:s'),
'author_name' => '测试',
'author_email' => $to,
'author_phone' => '',
'status' => 'open',
'visible' => 1,
];
list($subject, $html) = fb_notify_render('receipt', $fake,
['software' => $swRow], $to);
$subject = '【测试】' . $subject;
list($ok, $err) = fb_smtp_send($sc, $to, $subject, $html);
if ($ok) { if ($ok) {
$msg = '测试邮件已发出,请查收 ' . $to . '(也看一下垃圾箱)。'; $msg = '测试邮件已发出,请查收 ' . $to . '(也看一下垃圾箱)。';
$msgType = 'ok'; $msgType = 'ok';
@@ -574,6 +594,7 @@ function fb_admin_save_settings() {
$save('notify.enabled', (int)(bool)$post('notify.enabled')); $save('notify.enabled', (int)(bool)$post('notify.enabled'));
$save('notify.on_every_reply', (int)(bool)$post('notify.on_every_reply')); $save('notify.on_every_reply', (int)(bool)$post('notify.on_every_reply'));
$save('notify.admin_new_thread', (int)(bool)$post('notify.admin_new_thread')); $save('notify.admin_new_thread', (int)(bool)$post('notify.admin_new_thread'));
$save('notify.receipt_enabled', (int)(bool)$post('notify.receipt_enabled'));
// 冷却秒数留空 = 用默认 300(config 里的出厂值)。注意 0 是合法值(表示不限制), // 冷却秒数留空 = 用默认 300(config 里的出厂值)。注意 0 是合法值(表示不限制),
// 所以要用「空串」而不是「0」来区分"没填"和"填了 0" // 所以要用「空串」而不是「0」来区分"没填"和"填了 0"
@@ -1317,13 +1338,21 @@ fb_layout_head('管理后台', ['robots' => 'noindex,nofollow']);
<div class="mail-test"> <div class="mail-test">
<span class="muted" style="font-size:13.5px">配好后先发一封测试邮件确认能通:</span> <span class="muted" style="font-size:13.5px">配好后先发一封测试邮件确认能通:</span>
<input type="email" id="mailTestTo" placeholder="收件邮箱,默认发给自己" <input type="email" id="mailTestTo" placeholder="收件邮箱,默认发给自己"
value="<?php echo e((string)fb_cfg('admin_email', '')); ?>"> value="<?php echo e((string)fb_cfg('admin_email', '') !== '' ? (string)fb_cfg('admin_email', '') : (string)fb_cfg('smtp.user', '')); ?>">
<select id="mailTestSw" title="按哪个软件的样子发送">
<?php foreach (fb_softwares(true) as $swOne): ?>
<option value="<?php echo (int)$swOne['id']; ?>"><?php echo e((string)$swOne['name']); ?></option>
<?php endforeach; ?>
</select>
<button type="button" class="btn" id="mailTestBtn" data-csrf="<?php echo e(fb_csrf_token()); ?>">发送测试邮件</button> <button type="button" class="btn" id="mailTestBtn" data-csrf="<?php echo e(fb_csrf_token()); ?>">发送测试邮件</button>
<span id="mailTestOut" class="mail-test-out"></span> <span id="mailTestOut" class="mail-test-out"></span>
</div> </div>
<p class="hint" style="margin:6px 0 0">测试邮件用的是「提交回执」模板,会带上所选软件的图标与配色 —— 可以直接看出不同软件的邮件长什么样。</p>
<?php endif; ?> <?php endif; ?>
<h3 style="margin:20px 0 8px;font-size:15px">通知规则</h3> <h3 style="margin:20px 0 8px;font-size:15px">通知规则</h3>
<label class="check"><input type="checkbox" name="notify_receipt_enabled" value="1"<?php echo fb_cfg('notify.receipt_enabled', true) ? ' checked' : ''; ?>> 提交后立即给提交人发「已收到」回执
<span class="hint" style="display:block;margin-left:24px">告诉对方反馈已送达、正在等审核,请耐心等待。提交完就让用户干等着是最容易丢信任的环节。</span></label>
<label class="check"><input type="checkbox" name="notify_enabled" value="1"<?php echo fb_cfg('notify.enabled', true) ? ' checked' : ''; ?>> 有人回复时通知提交人</label> <label class="check"><input type="checkbox" name="notify_enabled" value="1"<?php echo fb_cfg('notify.enabled', true) ? ' checked' : ''; ?>> 有人回复时通知提交人</label>
<label class="check"><input type="checkbox" name="notify_on_every_reply" value="1"<?php echo fb_cfg('notify.on_every_reply', false) ? ' checked' : ''; ?>> 每次回复都通知(默认只在官方回复时通知,避免刷屏)</label> <label class="check"><input type="checkbox" name="notify_on_every_reply" value="1"<?php echo fb_cfg('notify.on_every_reply', false) ? ' checked' : ''; ?>> 每次回复都通知(默认只在官方回复时通知,避免刷屏)</label>
<?php <?php
+32
View File
@@ -772,12 +772,42 @@
} }
} }
/* ---------- 图标快选(后台软件编辑) ---------- */
function bindIconPicker() {
var boxes = document.querySelectorAll('.icon-presets');
for (var i = 0; i < boxes.length; i++) {
(function (box) {
// 图标输入框是「图标快选」的前一个兄弟里的 input[name=icon]
var field = box.parentNode;
var input = field ? field.querySelector('input[name=icon]') : null;
if (!input) { return; }
var btns = box.querySelectorAll('.icon-preset');
function syncOn(v) {
for (var k = 0; k < btns.length; k++) {
var same = (btns[k].getAttribute('data-icon') || '') === v;
if (same) { btns[k].classList.add('on'); } else { btns[k].classList.remove('on'); }
}
}
for (var j = 0; j < btns.length; j++) {
btns[j].addEventListener('click', function () {
input.value = this.getAttribute('data-icon') || '';
syncOn(input.value);
});
}
input.addEventListener('input', function () { syncOn(this.value); });
syncOn(input.value);
})(boxes[i]);
}
}
/* ---------- 邮件测试发送(后台设置页) ---------- */ /* ---------- 邮件测试发送(后台设置页) ---------- */
function bindMailTest() { function bindMailTest() {
var btn = document.getElementById('mailTestBtn'); var btn = document.getElementById('mailTestBtn');
if (!btn) { return; } if (!btn) { return; }
var out = document.getElementById('mailTestOut'); var out = document.getElementById('mailTestOut');
var to = document.getElementById('mailTestTo'); var to = document.getElementById('mailTestTo');
var swSel = document.getElementById('mailTestSw');
btn.addEventListener('click', function () { btn.addEventListener('click', function () {
var addr = to ? (to.value || '').trim() : ''; var addr = to ? (to.value || '').trim() : '';
if (!addr) { if (!addr) {
@@ -793,6 +823,7 @@
fd.append('csrf', btn.getAttribute('data-csrf') || ''); fd.append('csrf', btn.getAttribute('data-csrf') || '');
fd.append('act', 'mail_test'); fd.append('act', 'mail_test');
fd.append('to', addr); fd.append('to', addr);
if (swSel && swSel.value) { fd.append('sw', swSel.value); }
fetch('admin.php', { method: 'POST', body: fd, credentials: 'same-origin' }) fetch('admin.php', { method: 'POST', body: fd, credentials: 'same-origin' })
.then(function (r) { return r.text(); }) .then(function (r) { return r.text(); })
@@ -821,6 +852,7 @@
bindAdminToggle(); bindAdminToggle();
bindWontfixPanel(); bindWontfixPanel();
bindColorPicker(); bindColorPicker();
bindIconPicker();
bindMailTest(); bindMailTest();
bindInlineValidate(); // ★ 必须在 bindNoDoubleSubmit 之前 bindInlineValidate(); // ★ 必须在 bindNoDoubleSubmit 之前
bindNoDoubleSubmit(); bindNoDoubleSubmit();
+38
View File
@@ -116,6 +116,44 @@ main.wrap{padding-top:24px; padding-bottom:40px; min-height:60vh}
margin-top:14px; padding-top:14px; border-top:1px dashed var(--line); margin-top:14px; padding-top:14px; border-top:1px dashed var(--line);
} }
/* ---------- 软件标识:图标 + 名字(多软件区分的主视觉) ----------
* 邮件模板里也有一套等价的 table 写法,两边的观感要对得上:
* 圆角色块 + 居中字符 + 紧跟软件名。 */
.sw-badge{display:inline-flex; align-items:center; gap:7px; min-width:0; vertical-align:middle}
.sw-badge-ic{
display:inline-flex; align-items:center; justify-content:center;
border-radius:7px; color:#fff; font-weight:600; flex:none;
line-height:1; letter-spacing:0; box-shadow:0 1px 2px rgba(15,25,45,.18);
}
.sw-badge-nm{
font-weight:600; font-size:14px; color:var(--fg);
overflow:hidden; text-overflow:ellipsis; white-space:nowrap;
}
.sw-badge-sm .sw-badge-nm{font-size:13px}
.sw-badge-lg .sw-badge-nm{font-size:17px}
/* 页头大标题位置放软件标识:清掉 h1 的行高影响,让图标与文字垂直居中 */
.page-h1-sw{margin:0; font-size:0; line-height:0}
.page-h1-sw .sw-badge-nm{font-size:22px; font-weight:700; color:var(--fg)}
/* 提交页顶部的软件上下文条 */
.sw-context{
display:flex; align-items:center; gap:10px; flex-wrap:wrap;
margin:0 0 16px; padding:11px 14px; border-radius:11px;
background:var(--brand-soft); border:1px solid var(--line);
}
.sw-context .sw-badge-nm{color:var(--fg)}
/* 后台软件编辑:图标快选 */
.icon-presets{display:flex; gap:4px; flex-wrap:wrap; margin-top:8px}
.icon-preset{
width:34px; height:34px; border:1px solid var(--line-strong); border-radius:9px;
background:var(--card); cursor:pointer; font-size:17px; line-height:1; padding:0;
display:inline-flex; align-items:center; justify-content:center;
}
.icon-preset:hover{border-color:var(--brand); background:var(--brand-soft)}
/* 选中态的 chip 里,图标底衬白、字符取软件色,避免同色糊在一起 */
.chip.on .sw-badge-ic{background:#fff !important; color:var(--brand) !important; box-shadow:none}
.chip.on .sw-badge-nm{color:#fff}
.chip .sw-badge-ic{box-shadow:none}
/* ---------- 主题色选择器 ---------- */ /* ---------- 主题色选择器 ---------- */
.sw-dot{ .sw-dot{
display:inline-block; width:10px; height:10px; border-radius:50%; display:inline-block; width:10px; height:10px; border-radius:50%;
+6 -2
View File
@@ -82,7 +82,11 @@ fb_layout_head($sw ? ((string)$sw['name']) : $headTitle, ['software' => $sw]);
<div class="page-head"> <div class="page-head">
<div> <div>
<h1><?php echo e($sw ? (string)$sw['name'] : '全部问题'); ?></h1> <?php if ($sw): ?>
<h1 class="page-h1-sw"><?php echo fb_software_badge($sw, 'lg'); ?></h1>
<?php else: ?>
<h1>全部问题</h1>
<?php endif; ?>
<?php <?php
$siteDesc = (string)fb_cfg('site_desc'); $siteDesc = (string)fb_cfg('site_desc');
$swNote = ($sw && !empty($sw['note'])) ? (string)$sw['note'] : ''; $swNote = ($sw && !empty($sw['note'])) ? (string)$sw['note'] : '';
@@ -98,7 +102,7 @@ fb_layout_head($sw ? ((string)$sw['name']) : $headTitle, ['software' => $sw]);
<div class="chips"> <div class="chips">
<?php foreach ($swList as $s): ?> <?php foreach ($swList as $s): ?>
<a class="chip <?php echo ($sw && (int)$s['id'] === (int)$sw['id']) ? 'on' : ''; ?>" <a class="chip <?php echo ($sw && (int)$s['id'] === (int)$sw['id']) ? 'on' : ''; ?>"
href="<?php echo e(fb_qs(['sw' => (string)$s['slug'], 'cat' => null, 'page' => null]) ?: ('?sw=' . e(urlencode((string)$s['slug'])))); ?>"><?php echo e((string)$s['name']); ?></a> href="<?php echo e(fb_qs(['sw' => (string)$s['slug'], 'cat' => null, 'page' => null]) ?: ('?sw=' . e(urlencode((string)$s['slug'])))); ?>"><?php echo fb_software_badge($s, 'sm'); ?></a>
<?php endforeach; ?> <?php endforeach; ?>
</div> </div>
</div> </div>
+27 -5
View File
@@ -29,8 +29,10 @@ function fb_admin_taxonomy_action($pdo, $act, $post) {
if (fb_software($slug)) { return ['英文标识「' . $slug . '」已被占用,换一个。', 'error']; } if (fb_software($slug)) { return ['英文标识「' . $slug . '」已被占用,换一个。', 'error']; }
$sort = (int)$pdo->query('SELECT COALESCE(MAX(sort_order),0)+1 FROM software')->fetchColumn(); $sort = (int)$pdo->query('SELECT COALESCE(MAX(sort_order),0)+1 FROM software')->fetchColumn();
$color = fb_color_norm(isset($post['color']) ? $post['color'] : ''); $color = fb_color_norm(isset($post['color']) ? $post['color'] : '');
$pdo->prepare('INSERT INTO software(slug,name,note,color,sort_order,enabled,created_at) VALUES(?,?,?,?,?,1,?)') $icon = fb_sw_icon_norm(isset($post['icon']) ? $post['icon'] : '');
->execute([$slug, $name, $note !== '' ? $note : null, $color, $sort, $now]); $dl = fb_sw_url_norm(isset($post['download_url']) ? $post['download_url'] : '');
$pdo->prepare('INSERT INTO software(slug,name,note,color,icon,download_url,sort_order,enabled,created_at) VALUES(?,?,?,?,?,?,?,1,?)')
->execute([$slug, $name, $note !== '' ? $note : null, $color, $icon, $dl, $sort, $now]);
$newId = (int)$pdo->lastInsertId(); $newId = (int)$pdo->lastInsertId();
// 新软件默认给一组常见分类,省得空着没法发帖 // 新软件默认给一组常见分类,省得空着没法发帖
$i = 0; $i = 0;
@@ -54,8 +56,10 @@ function fb_admin_taxonomy_action($pdo, $act, $post) {
$other = fb_software($slug); $other = fb_software($slug);
if ($other && (int)$other['id'] !== $id) { return ['英文标识「' . $slug . '」已被其他软件占用。', 'error']; } if ($other && (int)$other['id'] !== $id) { return ['英文标识「' . $slug . '」已被其他软件占用。', 'error']; }
$color = fb_color_norm(isset($post['color']) ? $post['color'] : ''); $color = fb_color_norm(isset($post['color']) ? $post['color'] : '');
$pdo->prepare('UPDATE software SET name=?, slug=?, note=?, color=?, sort_order=? WHERE id=?') $icon = fb_sw_icon_norm(isset($post['icon']) ? $post['icon'] : '');
->execute([$name, $slug, $note !== '' ? $note : null, $color, $dl = fb_sw_url_norm(isset($post['download_url']) ? $post['download_url'] : '');
$pdo->prepare('UPDATE software SET name=?, slug=?, note=?, color=?, icon=?, download_url=?, sort_order=? WHERE id=?')
->execute([$name, $slug, $note !== '' ? $note : null, $color, $icon, $dl,
(int)(isset($post['sort_order']) ? $post['sort_order'] : $sw['sort_order']), $id]); (int)(isset($post['sort_order']) ? $post['sort_order'] : $sw['sort_order']), $id]);
return ['软件「' . $name . '」已保存。', 'ok']; return ['软件「' . $name . '」已保存。', 'ok'];
} }
@@ -264,7 +268,8 @@ function fb_admin_taxonomy_page($pdo, $editSw, $editCat) {
echo ' <div class="tax-main">'; echo ' <div class="tax-main">';
list($swC, $swCd, $swCs) = fb_software_colors($sw); list($swC, $swCd, $swCs) = fb_software_colors($sw);
echo ' <span class="sw-dot" style="background:' . e($swC) . '" title="' . e($swC) . '"></span>'; echo ' <span class="sw-dot" style="background:' . e($swC) . '" title="' . e($swC) . '"></span>';
echo ' <a class="tax-name" href="admin.php?tab=taxonomy&sw=' . $sid . '">' . e((string)$sw['name']) . '</a>'; echo ' <a class="tax-name" href="admin.php?tab=taxonomy&sw=' . $sid . '">'
. fb_software_badge($sw, 'sm') . '</a>';
echo ' <span class="tax-slug">' . e((string)$sw['slug']) . '</span>'; echo ' <span class="tax-slug">' . e((string)$sw['slug']) . '</span>';
if (!$on) { echo ' <span class="badge st">已停用</span>'; } if (!$on) { echo ' <span class="badge st">已停用</span>'; }
echo ' <span class="tax-meta">' . $nCat . ' 个分类 · ' . $nTh . ' 条反馈</span>'; echo ' <span class="tax-meta">' . $nCat . ' 个分类 · ' . $nTh . ' 条反馈</span>';
@@ -310,6 +315,23 @@ function fb_admin_taxonomy_page($pdo, $editSw, $editCat) {
. '<input type="text" name="note" maxlength="120" value="' . '<input type="text" name="note" maxlength="120" value="'
. e($esw ? (string)($esw['note'] === null ? '' : $esw['note']) : '') . '"></label>'; . e($esw ? (string)($esw['note'] === null ? '' : $esw['note']) : '') . '"></label>';
// 图标:一个字符即可(emoji / 汉字 / 字母),配合主题色一起区分软件
$curIcon = $esw ? (string)(isset($esw['icon']) ? $esw['icon'] : '') : '';
$iconSug = ['📅', '🔐', '🔑', '📝', '🎵', '📷', '🌤', '🧭', '📦', '⚙️', '🗂', '💬'];
echo ' <label class="field"><span>图标<i class="hint">一个字符:emoji 或汉字/字母。列表、页头与邮件里都会带上它</i></span>'
. '<input type="text" name="icon" maxlength="8" value="' . e($curIcon) . '" placeholder="例如 📅">'
. '<span class="icon-presets">';
foreach ($iconSug as $ic) {
echo '<button type="button" class="icon-preset" data-icon="' . e($ic) . '">' . e($ic) . '</button>';
}
echo '</span></label>';
// 下载地址:状态改成「已解决」时,邮件里会给用户一个去下新版的按钮
echo ' <label class="field"><span>下载地址<i class="hint">可留空。填了之后「已解决」的通知邮件里会多一个「下载最新版」按钮</i></span>'
. '<input type="url" name="download_url" maxlength="300" value="'
. e($esw ? (string)(isset($esw['download_url']) ? $esw['download_url'] : '') : '')
. '" placeholder="https://..."></label>';
// 主题色:前台按软件换色,用短链接进不同软件一眼就能区分 // 主题色:前台按软件换色,用短链接进不同软件一眼就能区分
$curColor = $esw ? fb_color_norm((string)$esw['color']) : ''; $curColor = $esw ? fb_color_norm((string)$esw['color']) : '';
$sugColor = $curColor !== '' ? $curColor : fb_color_default_for($esw ? (int)$esw['id'] : 0); $sugColor = $curColor !== '' ? $curColor : fb_color_default_for($esw ? (int)$esw['id'] : 0);
+1 -1
View File
@@ -8,7 +8,7 @@ if (!defined('FB_ROOT')) {
define('FB_ROOT', dirname(__DIR__)); define('FB_ROOT', dirname(__DIR__));
// 静态资源版本号:改 assets/ 下的 css/js 后把这个数字 +1, // 静态资源版本号:改 assets/ 下的 css/js 后把这个数字 +1,
// 让浏览器与 CDN 缓存失效。全站只此一处,别再往页面里写死数字。 // 让浏览器与 CDN 缓存失效。全站只此一处,别再往页面里写死数字。
if (!defined('FB_ASSET_V')) { define('FB_ASSET_V', 16); } if (!defined('FB_ASSET_V')) { define('FB_ASSET_V', 17); }
} }
/* ------------------------------------------------------------------ /* ------------------------------------------------------------------
+11
View File
@@ -324,6 +324,17 @@ SQL
if (!isset($swNames['color'])) { if (!isset($swNames['color'])) {
$pdo->exec("ALTER TABLE software ADD COLUMN color TEXT NOT NULL DEFAULT ''"); $pdo->exec("ALTER TABLE software ADD COLUMN color TEXT NOT NULL DEFAULT ''");
} }
/* ---- 软件增加图标(多软件并存时靠「图标 + 名字 + 颜色」三重区分)----
* 存一个字符即可:优先 emoji(日历 📅 / 锁 🔐 / 密码 🔑),也接受单个汉字或字母。
* 不存图片路径,避免再管一套上传 / 存储 / 权限 —— 邮件里也用同一个字符渲染,
* 前端与邮件天然一致,不会出现「页面有图标、邮件没有」的割裂。 */
if (!isset($swNames['icon'])) {
$pdo->exec("ALTER TABLE software ADD COLUMN icon TEXT NOT NULL DEFAULT ''");
}
/* ---- 软件增加下载地址(状态「已解决」的邮件里给用户一个去下新版的入口)---- */
if (!isset($swNames['download_url'])) {
$pdo->exec("ALTER TABLE software ADD COLUMN download_url TEXT NOT NULL DEFAULT ''");
}
/* ---- threads 增加两列(老 category 文本列保留,不删)---- */ /* ---- threads 增加两列(老 category 文本列保留,不删)---- */
$cols = $pdo->query('PRAGMA table_info(threads)')->fetchAll(); $cols = $pdo->query('PRAGMA table_info(threads)')->fetchAll();
+12
View File
@@ -51,10 +51,22 @@ function fb_layout_head($title, array $opt = []) {
<body> <body>
<header class="topbar"> <header class="topbar">
<div class="wrap"> <div class="wrap">
<?php
/* 顶栏品牌位:当前在哪個软件下,就显示那个软件的「图标 + 名字」,
* 而不是一直挂着站点大标题 —— 多软件共用一套反馈系统,
* 用户要一眼看清「我现在是在给哪个软件提问题」。 */
$curSw = isset($opt['software']) && is_array($opt['software']) ? $opt['software'] : null;
?>
<?php if ($curSw): ?>
<a class="brand-mini" href="./" title="<?php echo e($site); ?>">
<?php echo fb_software_badge($curSw, 'md'); ?>
</a>
<?php else: ?>
<a class="brand-mini" href="./" title="<?php echo e($site); ?>"> <a class="brand-mini" href="./" title="<?php echo e($site); ?>">
<span class="logo-mark" role="img" aria-label="轻反馈图标"></span> <span class="logo-mark" role="img" aria-label="轻反馈图标"></span>
<span class="brand-text"><?php echo e($site); ?></span> <span class="brand-text"><?php echo e($site); ?></span>
</a> </a>
<?php endif; ?>
<div class="spacer"></div> <div class="spacer"></div>
<a class="navlink hide-sm" href="./">全部问题</a> <a class="navlink hide-sm" href="./">全部问题</a>
<?php if (fb_admin_logged_in()): ?><a class="navlink" href="admin.php">管理后台</a><?php endif; ?> <?php if (fb_admin_logged_in()): ?><a class="navlink" href="admin.php">管理后台</a><?php endif; ?>
+186 -29
View File
@@ -144,14 +144,67 @@ if (!function_exists('fb_mail_esc')) {
} }
if (!function_exists('fb_mail_brand')) { if (!function_exists('fb_mail_brand')) {
/** 取站点主色,用于邮件头与按钮。跟随「软件主题色」体系,但邮件里只用主色与浅底 */ /**
* 邮件主色。
*
* 🔴 多软件站点的核心要求:邮件颜色必须跟「这条反馈属于哪个软件」一致,
* 否则用户在收件箱里根本分不清是哪个软件的来信。
* 取值顺序:
* ① 调用方显式传入的软件行(fb_mail_layout(['software' => ...]))
* ② 当前全局软件($GLOBALS['__fb_mail_sw'],由 fb_notify_render 设置)
* ③ 配置里的 mail_brand_color(单软件站点的老配置,保持兼容)
* ④ 兜底蓝
*/
function fb_mail_brand() { function fb_mail_brand() {
$sw = null;
if (isset($GLOBALS['__fb_mail_sw']) && is_array($GLOBALS['__fb_mail_sw'])) {
$sw = $GLOBALS['__fb_mail_sw'];
}
if ($sw) {
list($c) = fb_software_colors($sw);
if ($c !== '') { return $c; }
}
$c = fb_color_norm((string)fb_cfg('mail_brand_color', '')); $c = fb_color_norm((string)fb_cfg('mail_brand_color', ''));
if ($c === '') { $c = '#0057B8'; } if ($c === '') { $c = '#0057B8'; }
return $c; return $c;
} }
} }
if (!function_exists('fb_mail_sw_ctx')) {
/** 设置/读取「当前邮件所属软件」,返回之前的上下文(便于嵌套调用后还原) */
function fb_mail_sw_ctx($sw = null, $set = false) {
$prev = isset($GLOBALS['__fb_mail_sw']) ? $GLOBALS['__fb_mail_sw'] : null;
if ($set) { $GLOBALS['__fb_mail_sw'] = $sw; }
return $prev;
}
}
if (!function_exists('fb_mail_sw_header')) {
/**
* 邮件头部的「软件标识」:色块图标 + 软件名。
* 用 table + 内联样式写,兼容 Outlook 等不认 flex 的客户端。
*/
function fb_mail_sw_header($sw) {
if (!is_array($sw) || empty($sw['name'])) { return ''; }
list($c) = fb_software_colors($sw);
if ($c === '') { $c = '#0057B8'; }
$icon = fb_software_icon($sw);
$name = (string)$sw['name'];
return '<table role="presentation" cellpadding="0" cellspacing="0" border="0"'
. ' style="border-collapse:collapse"><tr>'
. '<td width="30" style="width:30px;height:30px;background:' . fb_mail_esc($c) . ';'
. 'border-radius:8px;text-align:center;vertical-align:middle;'
. 'font-size:15px;line-height:30px;color:#ffffff;font-weight:700">'
. '<span style="display:inline-block;line-height:30px">' . fb_mail_esc($icon) . '</span>'
. '</td>'
. '<td style="padding-left:9px;vertical-align:middle;font-size:15px;'
. 'font-weight:700;color:#1b2430;letter-spacing:.2px">'
. fb_mail_esc($name) . '</td>'
. '</tr></table>';
}
}
if (!function_exists('fb_mail_block')) { if (!function_exists('fb_mail_block')) {
/** /**
* 渲染一个内容块。 * 渲染一个内容块。
@@ -242,6 +295,10 @@ if (!function_exists('fb_mail_layout')) {
* @return string 完整 HTML(可直接作为 text/html 正文) * @return string 完整 HTML(可直接作为 text/html 正文)
*/ */
function fb_mail_layout(array $o) { function fb_mail_layout(array $o) {
// 软件上下文:显式传入优先,否则用全局上下文(fb_notify_render 会设好)
$sw = isset($o['software']) && is_array($o['software']) ? $o['software'] : null;
if ($sw) { fb_mail_sw_ctx($sw, true); } // 让本函数内 fb_mail_brand() 取到软件色
$brand = fb_mail_brand(); $brand = fb_mail_brand();
$site = (string)fb_cfg('site_name', '轻反馈'); $site = (string)fb_cfg('site_name', '轻反馈');
$base = fb_base_url(); $base = fb_base_url();
@@ -330,11 +387,18 @@ if (!function_exists('fb_mail_layout')) {
. '<tr><td style="height:4px;background:' . fb_mail_esc($brand) . ';font-size:0;' . '<tr><td style="height:4px;background:' . fb_mail_esc($brand) . ';font-size:0;'
. 'line-height:0">&nbsp;</td></tr>' . 'line-height:0">&nbsp;</td></tr>'
// 站名 // 站名 / 软件标识
// 有软件上下文时:上排是「图标 + 软件名」(这是用户最需要一眼认出的信息),
// 下排再补一行小字站点名。没有软件时退回原来的纯站名写法。
. '<tr><td style="padding:22px 32px 0">' . '<tr><td style="padding:22px 32px 0">'
. '<div style="font-size:13px;font-weight:700;letter-spacing:.6px;' . (isset($o['software']) && is_array($o['software'])
? fb_mail_sw_header($o['software'])
. '<div style="margin-top:7px;font-size:11.5px;letter-spacing:.4px;color:#9aa2ad">'
. fb_mail_esc($site) . '</div>'
: '<div style="font-size:13px;font-weight:700;letter-spacing:.6px;'
. 'color:' . fb_mail_esc($brand) . ';text-transform:uppercase">' . 'color:' . fb_mail_esc($brand) . ';text-transform:uppercase">'
. fb_mail_esc($site) . '</div></td></tr>' . fb_mail_esc($site) . '</div>')
. '</td></tr>'
// 标题 // 标题
. '<tr><td style="padding:12px 32px 4px">' . $badgeHtml . '<tr><td style="padding:12px 32px 4px">' . $badgeHtml
@@ -512,6 +576,7 @@ if (!function_exists('fb_notify_reason_label')) {
/** 事件的中文名,用于日志与模板徽标 */ /** 事件的中文名,用于日志与模板徽标 */
function fb_notify_reason_label($reason) { function fb_notify_reason_label($reason) {
$map = [ $map = [
'receipt' => '已收到反馈',
'reply' => '有新回复', 'reply' => '有新回复',
'status' => '状态更新', 'status' => '状态更新',
'approve' => '已发布', 'approve' => '已发布',
@@ -533,9 +598,15 @@ if (!function_exists('fb_notify_enabled_for')) {
* 它独立于前者 —— 就算关了给用户的信,管理员也可以想收通知 * 它独立于前者 —— 就算关了给用户的信,管理员也可以想收通知
*/ */
function fb_notify_enabled_for($reason) { function fb_notify_enabled_for($reason) {
// 「新反馈」按 admin_new_thread 独立开关;「提交回执」按 receipt_enabled 独立开关
// (回执是发给提问人的,跟「有人回复时通知提交人」是两件不同的事,
// 有人可能只想要回执不想要回复通知,所以不能共用一个开关)
if ($reason === 'new') { if ($reason === 'new') {
return (bool)fb_cfg('notify.admin_new_thread', false); return (bool)fb_cfg('notify.admin_new_thread', false);
} }
if ($reason === 'receipt') {
return (bool)fb_cfg('notify.receipt_enabled', true);
}
return (bool)fb_cfg('notify.enabled', true); return (bool)fb_cfg('notify.enabled', true);
} }
} }
@@ -714,10 +785,10 @@ if (!function_exists('fb_notify_status_meta')) {
'tip' => '感谢你的耐心等待,暂时不需要你做任何操作。', 'tip' => '感谢你的耐心等待,暂时不需要你做任何操作。',
], ],
'resolved' => [ 'resolved' => [
'badge' => '已解决', 'color' => '#1e7b3c', 'tone' => 'ok', 'badge' => '已完成', 'color' => '#1e7b3c', 'tone' => 'ok',
'title' => '你反馈的问题已解决', 'title' => '你反馈的问题已完成并上线',
'intro' => '好消息,你反馈的问题我们已经处理完成。', 'intro' => '好消息:你反馈的内容我们已经处理完成,并已发布上线。',
'tip' => '如果问题仍然存在,直接在本页回复即可,我们会继续跟进。', 'tip' => '建议更新到最新版本后试一下。如果问题仍然存在,直接在本页回复即可,我们会继续跟进。',
], ],
'closed' => [ 'closed' => [
'badge' => '已关闭', 'color' => '#8a6a15', 'tone' => 'warn', 'badge' => '已关闭', 'color' => '#8a6a15', 'tone' => 'warn',
@@ -754,6 +825,24 @@ if (!function_exists('fb_notify_render')) {
$short = fb_excerpt($title, 42); $short = fb_excerpt($title, 42);
$isAdmin = !empty($extra['is_admin']); $isAdmin = !empty($extra['is_admin']);
/* ---- 软件上下文:整封邮件的配色、头部标识、主题前缀都靠它 ----
* 每条反馈都属于某个软件。邮件必须让用户一眼看出「这是哪个软件的来信」,
* 所以这里解析一次,后面所有分支共用:
* $swName 软件名(进主题行前缀)
* $sw 软件行(进邮件头标识与配色)
*
* 🔴 允许 $extra['software'] 显式指定软件行:
* ① 后台「发送测试邮件」可以指定「按某个软件的样子发」,便于预览配色;
* ② 测试脚本能在不往库里插数据的前提下验证配色切换;
* ③ 万一 threads.software_id 指向已被删除的软件,调用方仍能给出正确上下文。
* 没有显式指定时,才按 software_id 回查、再回落默认软件。 */
$sw = (isset($extra['software']) && is_array($extra['software'])) ? $extra['software'] : null;
if (!$sw) { $sw = fb_software_of_thread($thread); }
$swName = $sw ? (string)$sw['name'] : '';
fb_mail_sw_ctx($sw, true);
// 主题统一加软件名前缀,收件箱列表里不点开就能分辨
$pfx = ($swName !== '') ? '【' . $swName . '】' : '';
$subject = ''; $subject = '';
$layout = []; $layout = [];
@@ -764,21 +853,30 @@ if (!function_exists('fb_notify_render')) {
$rbody = (string)(isset($reply['body']) ? $reply['body'] : ''); $rbody = (string)(isset($reply['body']) ? $reply['body'] : '');
$isOff = $isAdmin ? '官方回复' : '新回复'; $isOff = $isAdmin ? '官方回复' : '新回复';
$subject = '【' . $site . '】' . $isOff . ':' . $short; $subject = $pfx . $isOff . ':' . $short;
/* 像博客评论通知那样带上上下文:
* 用户可能同时提过好几条反馈,只给「回复内容」根本想不起来是哪一条。
* 所以固定三段:① 你反馈了什么 ② 谁回复了什么 ③ 去哪里继续。 */
$origBody = (string)(isset($thread['body']) ? $thread['body'] : '');
$blocks = [ $blocks = [
['type' => 'text', 'text' => '你在「' . $site . '」提交的反馈有新的回复。'], ['type' => 'text', 'text' => ($swName !== '' ? '你在「' . $swName . '」提交的反馈' : '你提交的反馈')
. '有新的回复。'],
['type' => 'field', 'rows' => ['反馈标题' => $title]], ['type' => 'field', 'rows' => ['反馈标题' => $title]],
['type' => 'quote', 'who' => $rname . ' 回复:', 'text' => $rbody],
]; ];
if (trim($origBody) !== '') {
$blocks[] = ['type' => 'quote', 'who' => '你当时反馈的内容:', 'text' => fb_excerpt($origBody, 220)];
}
$blocks[] = ['type' => 'quote', 'who' => $rname . ' 回复:', 'text' => $rbody];
if ($isAdmin) { if ($isAdmin) {
$blocks[] = ['type' => 'callout', 'tone' => 'info', $blocks[] = ['type' => 'callout', 'tone' => 'info',
'text' => '这是官方回复。如果还有疑问,直接在本页继续回复即可。']; 'text' => '这是官方回复。如果还有疑问,直接在本页继续回复即可。'];
} }
$layout = [ $layout = [
'software' => $sw,
'preheader' => $rname . ':' . fb_excerpt($rbody, 60), 'preheader' => $rname . ':' . fb_excerpt($rbody, 60),
'badge' => ['text' => $isOff, 'color' => $isAdmin ? '#0057B8' : '#5c6572'], 'badge' => ['text' => $isOff, 'color' => $isAdmin ? fb_mail_brand() : '#5c6572'],
'title' => $isAdmin ? '官方回复了你的反馈' : '有人回复了你的反馈', 'title' => $isAdmin ? '官方回复了你的反馈' : '有人回复了你的反馈',
'intro' => ($name !== '' ? $name . ',你好:' : '你好:'), 'intro' => ($name !== '' ? $name . ',你好:' : '你好:'),
'blocks' => $blocks, 'blocks' => $blocks,
@@ -798,9 +896,10 @@ if (!function_exists('fb_notify_render')) {
$label = fb_status_label($newKey); $label = fb_status_label($newKey);
if ($label === '') { $label = $meta['badge']; } if ($label === '') { $label = $meta['badge']; }
$subject = '【' . $site . '】' . $short . ' —— ' . $label; $subject = $pfx . $short . ' —— ' . $label;
$rows = ['反馈标题' => $title]; $rows = ['反馈标题' => $title];
if ($swName !== '') { $rows['所属软件'] = $swName; }
if ($oldKey !== '' && $oldKey !== $newKey) { if ($oldKey !== '' && $oldKey !== $newKey) {
$oldLabel = fb_status_label($oldKey); $oldLabel = fb_status_label($oldKey);
if ($oldLabel !== '') { $rows['原状态'] = $oldLabel; } if ($oldLabel !== '') { $rows['原状态'] = $oldLabel; }
@@ -818,33 +917,50 @@ if (!function_exists('fb_notify_render')) {
$blocks[] = ['type' => 'callout', 'tone' => $meta['tone'], 'text' => $meta['tip']]; $blocks[] = ['type' => 'callout', 'tone' => $meta['tone'], 'text' => $meta['tip']];
} }
/* 「已解决」要真的推用户一把去验证:
* 软件配了下载地址就给一个下载按钮 —— 只说「修好了」用户不知道去哪拿新版本。 */
$dlUrl = $sw ? trim((string)(isset($sw['download_url']) ? $sw['download_url'] : '')) : '';
$btnText = '查看详情';
$btnUrl = $url;
if ($newKey === 'resolved' && $dlUrl !== '') {
$blocks[] = ['type' => 'callout', 'tone' => 'ok',
'text' => '新版本已经发布,建议下载最新版后验证一下。'];
$btnText = '下载最新版本';
$btnUrl = $dlUrl;
}
$layout = [ $layout = [
'software' => $sw,
'preheader' => '状态更新为「' . $label . '」', 'preheader' => '状态更新为「' . $label . '」',
'badge' => ['text' => $meta['badge'], 'color' => $meta['color']], 'badge' => ['text' => $meta['badge'], 'color' => $meta['color']],
'title' => $meta['title'], 'title' => $meta['title'],
'intro' => ($name !== '' ? $name . ',你好:' : '你好:'), 'intro' => ($name !== '' ? $name . ',你好:' : '你好:'),
'blocks' => $blocks, 'blocks' => $blocks,
'button' => ['text' => '查看详情', 'url' => $url], 'button' => ['text' => $btnText, 'url' => $btnUrl],
'link' => $url, // 下载按钮之外,始终保留「查看这条反馈」的原文链接
'link' => ($btnUrl === $url) ? $url
: ('下载地址:' . $dlUrl . "\n" . '查看反馈:' . $url),
'recipient' => $to, 'recipient' => $to,
]; ];
} }
/* ---------------- 3. 审核通过 ---------------- */ /* ---------------- 3. 审核通过 ---------------- */
elseif ($reason === 'approve') { elseif ($reason === 'approve') {
$subject = '【' . $site . '】你的反馈已发布:' . $short; $subject = $pfx . '你的反馈已发布:' . $short;
$layout = [ $layout = [
'software' => $sw,
'preheader' => '你的反馈已经公开可见', 'preheader' => '你的反馈已经公开可见',
'badge' => ['text' => '已发布', 'color' => '#1e7b3c'], 'badge' => ['text' => '已发布', 'color' => '#1e7b3c'],
'title' => '你的反馈已通过审核并公开', 'title' => '你的反馈已通过审核并公开',
'intro' => ($name !== '' ? $name . ',你好:' : '你好:'), 'intro' => ($name !== '' ? $name . ',你好:' : '你好:'),
'blocks' => [ 'blocks' => [
['type' => 'text', 'text' => '你提交的反馈已通过审核,现在可以在公开列表中看到了。'], ['type' => 'text', 'text' => '你提交的反馈已通过审核,现在可以在'
. ($swName !== '' ? '「' . $swName . '」的' : '') . '公开列表中看到了。'],
['type' => 'field', 'rows' => ['反馈标题' => $title]], ['type' => 'field', 'rows' => ['反馈标题' => $title]],
['type' => 'callout', 'tone' => 'info', ['type' => 'callout', 'tone' => 'info',
'text' => '后续的处理进展与回复,我们会通过邮件通知你。'], 'text' => '后续的处理进展与回复,我们会通过邮件通知你。'],
], ],
'button' => ['text' => '查看这条反馈', 'url' => $url], 'button' => ['text' => '查看并跟踪这条反馈', 'url' => $url],
'link' => $url, 'link' => $url,
'recipient' => $to, 'recipient' => $to,
]; ];
@@ -853,7 +969,7 @@ if (!function_exists('fb_notify_render')) {
/* ---------------- 4. 转为不公开 ---------------- */ /* ---------------- 4. 转为不公开 ---------------- */
elseif ($reason === 'hide') { elseif ($reason === 'hide') {
$note = trim((string)(isset($extra['note']) ? $extra['note'] : '')); $note = trim((string)(isset($extra['note']) ? $extra['note'] : ''));
$subject = '【' . $site . '】你的反馈已转为不公开:' . $short; $subject = $pfx . '你的反馈已转为不公开:' . $short;
$blocks = [ $blocks = [
['type' => 'text', 'text' => '你提交的反馈已从公开列表中撤下,不再对其他人可见。'], ['type' => 'text', 'text' => '你提交的反馈已从公开列表中撤下,不再对其他人可见。'],
@@ -866,6 +982,7 @@ if (!function_exists('fb_notify_render')) {
'text' => '这条反馈本身仍然保留,你依然可以通过原链接访问和处理进展。']; 'text' => '这条反馈本身仍然保留,你依然可以通过原链接访问和处理进展。'];
$layout = [ $layout = [
'software' => $sw,
'preheader' => '这条反馈已不对其他人可见', 'preheader' => '这条反馈已不对其他人可见',
'badge' => ['text' => '不公开', 'color' => '#5c6572'], 'badge' => ['text' => '不公开', 'color' => '#5c6572'],
'title' => '你的反馈已转为不公开', 'title' => '你的反馈已转为不公开',
@@ -883,11 +1000,12 @@ if (!function_exists('fb_notify_render')) {
$body = (string)$thread['body']; $body = (string)$thread['body'];
$mail = trim((string)fb_cfg('admin_email', '')); $mail = trim((string)fb_cfg('admin_email', ''));
$subject = '【' . $site . '】关于你反馈的问题《' . $short . '》'; $subject = $pfx . '关于你反馈的问题《' . $short . '》';
$blocks = [ $blocks = [
['type' => 'text', ['type' => 'text',
'text' => '感谢你的反馈。我们已经核实过,这个情况并不是应用本身的问题,因此这条反馈已关闭(不会公开显示)。'], 'text' => '感谢你的反馈。我们已经核实过,这个情况并不是'
. ($swName !== '' ? '「' . $swName . '」' : '应用') . '本身的问题,因此这条反馈已关闭(不会公开显示)。'],
['type' => 'field', 'rows' => ['反馈标题' => $title]], ['type' => 'field', 'rows' => ['反馈标题' => $title]],
]; ];
if ($note !== '') { if ($note !== '') {
@@ -902,6 +1020,7 @@ if (!function_exists('fb_notify_render')) {
]; ];
$layout = [ $layout = [
'software' => $sw,
'preheader' => '关于你反馈的问题,我们的说明', 'preheader' => '关于你反馈的问题,我们的说明',
'badge' => ['text' => '已关闭', 'color' => '#8a6a15'], 'badge' => ['text' => '已关闭', 'color' => '#8a6a15'],
'title' => '关于你反馈的问题,我们的说明', 'title' => '关于你反馈的问题,我们的说明',
@@ -916,18 +1035,24 @@ if (!function_exists('fb_notify_render')) {
$body = (string)$thread['body']; $body = (string)$thread['body'];
$mail = (string)(isset($thread['author_email']) ? $thread['author_email'] : ''); $mail = (string)(isset($thread['author_email']) ? $thread['author_email'] : '');
$phone = trim((string)(isset($thread['author_phone']) ? $thread['author_phone'] : '')); $phone = trim((string)(isset($thread['author_phone']) ? $thread['author_phone'] : ''));
$swName = (string)(isset($extra['software_name']) ? $extra['software_name'] : ''); // 软件名优先取实际软件行(比 extra 里传进来的更可靠)
$swName = $swName !== '' ? $swName
: (string)(isset($extra['software_name']) ? $extra['software_name'] : '');
$subject = '【' . $site . '】新反馈:' . $short; $subject = $pfx . '新反馈:' . $short;
$rows = ['标题' => $title]; $rows = [];
if ($swName !== '') { $rows['所属软件'] = $swName; } if ($swName !== '') { $rows['所属软件'] = $swName; }
$rows['标题'] = $title;
$rows['提交人'] = $name !== '' ? $name : '(未留名)'; $rows['提交人'] = $name !== '' ? $name : '(未留名)';
if ($mail !== '') { $rows['邮箱'] = $mail; } if ($mail !== '') { $rows['邮箱'] = $mail; }
if ($phone !== '') { $rows['电话'] = $phone; } if ($phone !== '') { $rows['电话'] = $phone; }
$adminUrl = fb_base_url() . '/admin.php?tab=thread&id=' . (int)$thread['id'];
$blocks = [ $blocks = [
['type' => 'text', 'text' => '有新的反馈提交,请及时处理。'], ['type' => 'text', 'text' => ($swName !== '' ? '「' . $swName . '」' : '')
. '有一条新的反馈提交,请到管理后台处理。'],
['type' => 'field', 'rows' => $rows], ['type' => 'field', 'rows' => $rows],
['type' => 'quote', 'who' => '反馈内容:', 'text' => $body], ['type' => 'quote', 'who' => '反馈内容:', 'text' => $body],
['type' => 'callout', 'tone' => 'warn', ['type' => 'callout', 'tone' => 'warn',
@@ -935,22 +1060,54 @@ if (!function_exists('fb_notify_render')) {
]; ];
$layout = [ $layout = [
'software' => $sw,
'preheader' => $name . ':' . fb_excerpt($body, 60), 'preheader' => $name . ':' . fb_excerpt($body, 60),
'badge' => ['text' => '新反馈', 'color' => '#b4553c'], 'badge' => ['text' => '新反馈', 'color' => '#b4553c'],
'title' => '收到一条新反馈', 'title' => ($swName !== '' ? $swName . ' 收到一条新反馈' : '收到一条新反馈'),
'intro' => '你好:', 'intro' => '你好:',
'blocks' => $blocks, 'blocks' => $blocks,
'button' => ['text' => '去后台处理', 'url' => fb_base_url() . '/admin.php?tab=thread&id=' . (int)$thread['id']], 'button' => ['text' => '去后台处理这条反馈', 'url' => $adminUrl],
'link' => fb_base_url() . '/admin.php?tab=thread&id=' . (int)$thread['id'], 'link' => $adminUrl,
'recipient' => $to, 'recipient' => $to,
'footer' => '此邮件由系统自动发送。想调整接收规则,请到后台「邮件通知」页修改。', 'footer' => '此邮件由系统自动发送。想调整接收规则,请到后台「邮件通知」页修改。',
]; ];
} }
/* ---------------- 7. 提交回执(发给提问人) ---------------- */
elseif ($reason === 'receipt') {
$body = (string)$thread['body'];
$subject = $pfx . '已收到你的反馈:' . $short;
$blocks = [
['type' => 'text', 'text' => '我们已收到你在'
. ($swName !== '' ? '「' . $swName . '」' : '本站')
. '提交的反馈,感谢你的反馈!'],
['type' => 'field', 'rows' => ['反馈标题' => $title]],
['type' => 'quote', 'who' => '你提交的内容:', 'text' => fb_excerpt($body, 400)],
['type' => 'callout', 'tone' => 'info',
'text' => '这条反馈正在等待管理员审核,请耐心等待。审核通过后会在列表中公开显示。'],
['type' => 'text', 'text' => '审核结果与后续处理进展,我们都会通过邮件通知你,无需反复回来查看。'],
];
$layout = [
'software' => $sw,
'preheader' => '已收到你的反馈,正在等待审核',
'badge' => ['text' => '已收到', 'color' => fb_mail_brand()],
'title' => '已收到你的反馈',
'intro' => ($name !== '' ? $name . ',你好:' : '你好:'),
'blocks' => $blocks,
'button' => ['text' => '查看这条反馈', 'url' => $url],
'link' => $url,
'recipient' => $to,
];
}
/* ---------------- 兜底 ---------------- */ /* ---------------- 兜底 ---------------- */
else { else {
$subject = '【' . $site . '】' . $short; $subject = $pfx . $short;
$layout = [ $layout = [
'software' => $sw,
'preheader' => '你有一条新的通知', 'preheader' => '你有一条新的通知',
'title' => '你有一条新的通知', 'title' => '你有一条新的通知',
'intro' => ($name !== '' ? $name . ',你好:' : '你好:'), 'intro' => ($name !== '' ? $name . ',你好:' : '你好:'),
+83
View File
@@ -171,6 +171,20 @@ function fb_default_software() {
return $list ? $list[0] : null; return $list ? $list[0] : null;
} }
/**
* 由帖子行取它所属的软件行(邮件/页面要显示「这是对哪个软件提交的」都用它)。
* threads 只存 software_id,这里统一解析,避免各处自己写 SQL 漏掉。
* 取不到时回落到默认软件,保证邮件里永远有软件名可显示。
*/
function fb_software_of_thread(array $thread) {
$id = isset($thread['software_id']) ? (int)$thread['software_id'] : 0;
if ($id > 0) {
$sw = fb_software($id);
if ($sw) { return $sw; }
}
return fb_default_software();
}
/** /**
* 表单回显用:如果当前值等于「出厂默认」,就返回空串。 * 表单回显用:如果当前值等于「出厂默认」,就返回空串。
* *
@@ -263,6 +277,74 @@ function fb_software_colors($software) {
return fb_color_variants($hex); return fb_color_variants($hex);
} }
/**
* 规范化软件图标字符。
* 只留前几个字符,去掉换行与 HTML 尖括号 —— 这个值会直接输出到页面和邮件里,
* 放进 <span> 之间。虽然后面统一走 e() 转义,但源头收窄一层更稳。
*/
function fb_sw_icon_norm($s) {
$s = trim(strip_tags((string)$s));
$s = preg_replace('/[\x00-\x1F\x7F]+/u', '', $s);
if ($s === null || $s === '') { return ''; }
return mb_substr($s, 0, 4, 'UTF-8');
}
/** 规范化软件的下载地址:只接受 http/https,其它一律丢空 */
function fb_sw_url_norm($s) {
$s = trim((string)$s);
if ($s === '') { return ''; }
if (!preg_match('~^https?://~i', $s)) { return ''; }
return mb_substr($s, 0, 300, 'UTF-8');
}
/**
* 某软件的图标字符(单字符:emoji / 汉字 / 字母)。
* 没配就按软件名首字兜底 —— 多软件并存时,任何地方都不该出现「无图标」的空档。
*/
function fb_software_icon($software) {
$ic = '';
if (is_array($software)) {
$ic = trim((string)(isset($software['icon']) ? $software['icon'] : ''));
if ($ic === '') {
// 兜底:取名称首字(中文取第一个字,英文取首字母大写)
$nm = trim((string)(isset($software['name']) ? $software['name'] : ''));
if ($nm !== '') {
if (preg_match('/^[A-Za-z]/', $nm)) { $ic = strtoupper($nm[0]); }
else { $ic = mb_substr($nm, 0, 1, 'UTF-8'); }
}
}
}
if ($ic === '') { $ic = '·'; }
// 只允许极短内容,防止把整段 HTML 塞进图标位
return mb_substr($ic, 0, 4, 'UTF-8');
}
/**
* 图标 + 名字的组合标签(HTML)。
* 前端所有「这是哪个软件」的地方都用它,保证视觉一致。
*
* @param array $sw 软件行
* @param string $size 'sm' | 'md' | 'lg'
*/
function fb_software_badge($software, $size = 'md') {
if (!is_array($software) || empty($software['name'])) { return ''; }
list($c) = fb_software_colors($software);
if ($c === '') { $c = '#0057B8'; }
$icon = fb_software_icon($software);
$name = (string)$software['name'];
$px = ['sm' => 20, 'md' => 26, 'lg' => 34];
$fs = ['sm' => 11, 'md' => 14, 'lg' => 17];
$box = isset($px[$size]) ? $px[$size] : 26;
$fnt = isset($fs[$size]) ? $fs[$size] : 14;
return '<span class="sw-badge sw-badge-' . e($size) . '">'
. '<span class="sw-badge-ic" aria-hidden="true" style="width:' . $box . 'px;height:' . $box
. 'px;background:' . e($c) . ';font-size:' . $fnt . 'px">' . e($icon) . '</span>'
. '<span class="sw-badge-nm">' . e($name) . '</span>'
. '</span>';
}
/** 某软件下的分类;不传软件则返回空数组 */ /** 某软件下的分类;不传软件则返回空数组 */
function fb_categories($softwareId = null, $onlyEnabled = true) { function fb_categories($softwareId = null, $onlyEnabled = true) {
if ($softwareId === null) { return []; } if ($softwareId === null) { return []; }
@@ -490,6 +572,7 @@ function fb_setting_keys() {
'smtp.timeout', 'smtp.verify_ssl', 'smtp.timeout', 'smtp.verify_ssl',
'notify.enabled', 'notify.on_every_reply', 'notify.cooldown_seconds', 'notify.enabled', 'notify.on_every_reply', 'notify.cooldown_seconds',
'notify.admin_new_thread', 'notify.admin_new_thread',
'notify.receipt_enabled',
]; ];
} }
+12 -1
View File
@@ -119,6 +119,13 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$swRow = fb_software((int)$swId); $swRow = fb_software((int)$swId);
if ($swRow) { $swName = (string)$swRow['name']; } if ($swRow) { $swName = (string)$swRow['name']; }
} }
/* ① 先给提交人发「已收到」回执 —— 让他知道东西送达了、正在等审核。
* 这一步是用户最在意的:提交完页面跳走了,没有回执就等于石沉大海。
* 放在管理员通知之前,是因为回执对人的价值更高,且失败互不影响。 */
fb_notify_event($pdo, 'receipt', $newThread, ['software_name' => $swName]);
/* ② 再通知管理员「有新反馈」 */
fb_notify_event($pdo, 'new', $newThread, ['software_name' => $swName]); fb_notify_event($pdo, 'new', $newThread, ['software_name' => $swName]);
} }
} catch (Throwable $e) { } catch (Throwable $e) {
@@ -137,6 +144,10 @@ fb_layout_head('我要反馈', ['robots' => 'noindex,follow', 'software' => $sw]
<section class="narrow"> <section class="narrow">
<h1>我要反馈</h1> <h1>我要反馈</h1>
<?php if ($sw): ?>
<div class="sw-context"><?php echo fb_software_badge($sw, 'md'); ?>
<span class="muted small">你正在为这个软件提交反馈</span></div>
<?php endif; ?>
<p class="muted">请描述你遇到的问题或想要的功能。提交后会先进入审核,确认为有效问题后才会公开显示;<b>若经确认不是应用的问题,我们会把结论与说明通过邮件发送给你</b>(请填写常用邮箱)。</p> <p class="muted">请描述你遇到的问题或想要的功能。提交后会先进入审核,确认为有效问题后才会公开显示;<b>若经确认不是应用的问题,我们会把结论与说明通过邮件发送给你</b>(请填写常用邮箱)。</p>
<?php fb_flash_box($err, 'error'); ?> <?php fb_flash_box($err, 'error'); ?>
@@ -155,7 +166,7 @@ fb_layout_head('我要反馈', ['robots' => 'noindex,follow', 'software' => $sw]
<div class="chips"> <div class="chips">
<?php foreach ($swList as $one): ?> <?php foreach ($swList as $one): ?>
<a class="chip <?php echo ((int)$one['id'] === $swId) ? 'on' : ''; ?>" <a class="chip <?php echo ((int)$one['id'] === $swId) ? 'on' : ''; ?>"
href="new.php?sw=<?php echo e(urlencode((string)$one['slug'])); ?>"><?php echo e((string)$one['name']); ?></a> href="new.php?sw=<?php echo e(urlencode((string)$one['slug'])); ?>"><?php echo fb_software_badge($one, 'sm'); ?></a>
<?php endforeach; ?> <?php endforeach; ?>
</div> </div>
</div> </div>
+1 -1
View File
@@ -161,7 +161,7 @@ fb_layout_head(fb_excerpt($thread['title'], 50), ['software' => $thSwForColor]);
$thSw = !empty($thread['software_id']) ? fb_software((int)$thread['software_id']) : null; $thSw = !empty($thread['software_id']) ? fb_software((int)$thread['software_id']) : null;
$thCat = !empty($thread['category_id']) ? fb_category((int)$thread['category_id']) : null; $thCat = !empty($thread['category_id']) ? fb_category((int)$thread['category_id']) : null;
?> ?>
<?php if ($thSw): ?><span class="badge sw"><?php echo e((string)$thSw['name']); ?></span><?php endif; ?> <?php if ($thSw): ?><span class="badge sw"><?php echo fb_software_badge($thSw, 'sm'); ?></span><?php endif; ?>
<?php if ($thCat): ?><span class="badge cat"><?php echo e((string)$thCat['name']); ?></span><?php endif; ?> <?php if ($thCat): ?><span class="badge cat"><?php echo e((string)$thCat['name']); ?></span><?php endif; ?>
<span class="badge st st-<?php echo e($thread['status']); ?>"><?php echo e(fb_status_label($thread['status'])); ?></span> <span class="badge st st-<?php echo e($thread['status']); ?>"><?php echo e(fb_status_label($thread['status'])); ?></span>
<h1 class="subject-title"><?php echo e($thread['title']); ?></h1> <h1 class="subject-title"><?php echo e($thread['title']); ?></h1>