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

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

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
+187 -30
View File
@@ -144,14 +144,67 @@ if (!function_exists('fb_mail_esc')) {
}
if (!function_exists('fb_mail_brand')) {
/** 取站点主色,用于邮件头与按钮。跟随「软件主题色」体系,但邮件里只用主色与浅底 */
/**
* 邮件主色。
*
* 🔴 多软件站点的核心要求:邮件颜色必须跟「这条反馈属于哪个软件」一致,
* 否则用户在收件箱里根本分不清是哪个软件的来信。
* 取值顺序:
* ① 调用方显式传入的软件行(fb_mail_layout(['software' => ...]))
* ② 当前全局软件($GLOBALS['__fb_mail_sw'],由 fb_notify_render 设置)
* ③ 配置里的 mail_brand_color(单软件站点的老配置,保持兼容)
* ④ 兜底蓝
*/
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', ''));
if ($c === '') { $c = '#0057B8'; }
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')) {
/**
* 渲染一个内容块。
@@ -242,6 +295,10 @@ if (!function_exists('fb_mail_layout')) {
* @return string 完整 HTML(可直接作为 text/html 正文)
*/
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();
$site = (string)fb_cfg('site_name', '轻反馈');
$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;'
. 'line-height:0">&nbsp;</td></tr>'
// 站名
// 站名 / 软件标识
// 有软件上下文时:上排是「图标 + 软件名」(这是用户最需要一眼认出的信息),
// 下排再补一行小字站点名。没有软件时退回原来的纯站名写法。
. '<tr><td style="padding:22px 32px 0">'
. '<div style="font-size:13px;font-weight:700;letter-spacing:.6px;'
. 'color:' . fb_mail_esc($brand) . ';text-transform:uppercase">'
. fb_mail_esc($site) . '</div></td></tr>'
. (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">'
. fb_mail_esc($site) . '</div>')
. '</td></tr>'
// 标题
. '<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) {
$map = [
'receipt' => '已收到反馈',
'reply' => '有新回复',
'status' => '状态更新',
'approve' => '已发布',
@@ -533,9 +598,15 @@ if (!function_exists('fb_notify_enabled_for')) {
* 它独立于前者 —— 就算关了给用户的信,管理员也可以想收通知
*/
function fb_notify_enabled_for($reason) {
// 「新反馈」按 admin_new_thread 独立开关;「提交回执」按 receipt_enabled 独立开关
// (回执是发给提问人的,跟「有人回复时通知提交人」是两件不同的事,
// 有人可能只想要回执不想要回复通知,所以不能共用一个开关)
if ($reason === 'new') {
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);
}
}
@@ -714,10 +785,10 @@ if (!function_exists('fb_notify_status_meta')) {
'tip' => '感谢你的耐心等待,暂时不需要你做任何操作。',
],
'resolved' => [
'badge' => '已解决', 'color' => '#1e7b3c', 'tone' => 'ok',
'title' => '你反馈的问题已解决',
'intro' => '好消息,你反馈的问题我们已经处理完成。',
'tip' => '如果问题仍然存在,直接在本页回复即可,我们会继续跟进。',
'badge' => '已完成', 'color' => '#1e7b3c', 'tone' => 'ok',
'title' => '你反馈的问题已完成并上线',
'intro' => '好消息:你反馈的内容我们已经处理完成,并已发布上线。',
'tip' => '建议更新到最新版本后试一下。如果问题仍然存在,直接在本页回复即可,我们会继续跟进。',
],
'closed' => [
'badge' => '已关闭', 'color' => '#8a6a15', 'tone' => 'warn',
@@ -754,6 +825,24 @@ if (!function_exists('fb_notify_render')) {
$short = fb_excerpt($title, 42);
$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 = '';
$layout = [];
@@ -764,21 +853,30 @@ if (!function_exists('fb_notify_render')) {
$rbody = (string)(isset($reply['body']) ? $reply['body'] : '');
$isOff = $isAdmin ? '官方回复' : '新回复';
$subject = '【' . $site . '】' . $isOff . ':' . $short;
$subject = $pfx . $isOff . ':' . $short;
/* 像博客评论通知那样带上上下文:
* 用户可能同时提过好几条反馈,只给「回复内容」根本想不起来是哪一条。
* 所以固定三段:① 你反馈了什么 ② 谁回复了什么 ③ 去哪里继续。 */
$origBody = (string)(isset($thread['body']) ? $thread['body'] : '');
$blocks = [
['type' => 'text', 'text' => '你在「' . $site . '」提交的反馈有新的回复。'],
['type' => 'text', 'text' => ($swName !== '' ? '你在「' . $swName . '」提交的反馈' : '你提交的反馈')
. '有新的回复。'],
['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) {
$blocks[] = ['type' => 'callout', 'tone' => 'info',
'text' => '这是官方回复。如果还有疑问,直接在本页继续回复即可。'];
}
$layout = [
'software' => $sw,
'preheader' => $rname . ':' . fb_excerpt($rbody, 60),
'badge' => ['text' => $isOff, 'color' => $isAdmin ? '#0057B8' : '#5c6572'],
'badge' => ['text' => $isOff, 'color' => $isAdmin ? fb_mail_brand() : '#5c6572'],
'title' => $isAdmin ? '官方回复了你的反馈' : '有人回复了你的反馈',
'intro' => ($name !== '' ? $name . ',你好:' : '你好:'),
'blocks' => $blocks,
@@ -798,9 +896,10 @@ if (!function_exists('fb_notify_render')) {
$label = fb_status_label($newKey);
if ($label === '') { $label = $meta['badge']; }
$subject = '【' . $site . '】' . $short . ' —— ' . $label;
$subject = $pfx . $short . ' —— ' . $label;
$rows = ['反馈标题' => $title];
if ($swName !== '') { $rows['所属软件'] = $swName; }
if ($oldKey !== '' && $oldKey !== $newKey) {
$oldLabel = fb_status_label($oldKey);
if ($oldLabel !== '') { $rows['原状态'] = $oldLabel; }
@@ -818,33 +917,50 @@ if (!function_exists('fb_notify_render')) {
$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 = [
'software' => $sw,
'preheader' => '状态更新为「' . $label . '」',
'badge' => ['text' => $meta['badge'], 'color' => $meta['color']],
'title' => $meta['title'],
'intro' => ($name !== '' ? $name . ',你好:' : '你好:'),
'blocks' => $blocks,
'button' => ['text' => '查看详情', 'url' => $url],
'link' => $url,
'button' => ['text' => $btnText, 'url' => $btnUrl],
// 下载按钮之外,始终保留「查看这条反馈」的原文链接
'link' => ($btnUrl === $url) ? $url
: ('下载地址:' . $dlUrl . "\n" . '查看反馈:' . $url),
'recipient' => $to,
];
}
/* ---------------- 3. 审核通过 ---------------- */
elseif ($reason === 'approve') {
$subject = '【' . $site . '】你的反馈已发布:' . $short;
$subject = $pfx . '你的反馈已发布:' . $short;
$layout = [
'software' => $sw,
'preheader' => '你的反馈已经公开可见',
'badge' => ['text' => '已发布', 'color' => '#1e7b3c'],
'title' => '你的反馈已通过审核并公开',
'intro' => ($name !== '' ? $name . ',你好:' : '你好:'),
'blocks' => [
['type' => 'text', 'text' => '你提交的反馈已通过审核,现在可以在公开列表中看到了。'],
['type' => 'text', 'text' => '你提交的反馈已通过审核,现在可以在'
. ($swName !== '' ? '「' . $swName . '」的' : '') . '公开列表中看到了。'],
['type' => 'field', 'rows' => ['反馈标题' => $title]],
['type' => 'callout', 'tone' => 'info',
'text' => '后续的处理进展与回复,我们会通过邮件通知你。'],
],
'button' => ['text' => '查看这条反馈', 'url' => $url],
'button' => ['text' => '查看并跟踪这条反馈', 'url' => $url],
'link' => $url,
'recipient' => $to,
];
@@ -853,7 +969,7 @@ if (!function_exists('fb_notify_render')) {
/* ---------------- 4. 转为不公开 ---------------- */
elseif ($reason === 'hide') {
$note = trim((string)(isset($extra['note']) ? $extra['note'] : ''));
$subject = '【' . $site . '】你的反馈已转为不公开:' . $short;
$subject = $pfx . '你的反馈已转为不公开:' . $short;
$blocks = [
['type' => 'text', 'text' => '你提交的反馈已从公开列表中撤下,不再对其他人可见。'],
@@ -866,6 +982,7 @@ if (!function_exists('fb_notify_render')) {
'text' => '这条反馈本身仍然保留,你依然可以通过原链接访问和处理进展。'];
$layout = [
'software' => $sw,
'preheader' => '这条反馈已不对其他人可见',
'badge' => ['text' => '不公开', 'color' => '#5c6572'],
'title' => '你的反馈已转为不公开',
@@ -883,11 +1000,12 @@ if (!function_exists('fb_notify_render')) {
$body = (string)$thread['body'];
$mail = trim((string)fb_cfg('admin_email', ''));
$subject = '【' . $site . '】关于你反馈的问题《' . $short . '》';
$subject = $pfx . '关于你反馈的问题《' . $short . '》';
$blocks = [
['type' => 'text',
'text' => '感谢你的反馈。我们已经核实过,这个情况并不是应用本身的问题,因此这条反馈已关闭(不会公开显示)。'],
'text' => '感谢你的反馈。我们已经核实过,这个情况并不是'
. ($swName !== '' ? '「' . $swName . '」' : '应用') . '本身的问题,因此这条反馈已关闭(不会公开显示)。'],
['type' => 'field', 'rows' => ['反馈标题' => $title]],
];
if ($note !== '') {
@@ -902,6 +1020,7 @@ if (!function_exists('fb_notify_render')) {
];
$layout = [
'software' => $sw,
'preheader' => '关于你反馈的问题,我们的说明',
'badge' => ['text' => '已关闭', 'color' => '#8a6a15'],
'title' => '关于你反馈的问题,我们的说明',
@@ -916,18 +1035,24 @@ if (!function_exists('fb_notify_render')) {
$body = (string)$thread['body'];
$mail = (string)(isset($thread['author_email']) ? $thread['author_email'] : '');
$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; }
$rows['标题'] = $title;
$rows['提交人'] = $name !== '' ? $name : '(未留名)';
if ($mail !== '') { $rows['邮箱'] = $mail; }
if ($phone !== '') { $rows['电话'] = $phone; }
$adminUrl = fb_base_url() . '/admin.php?tab=thread&id=' . (int)$thread['id'];
$blocks = [
['type' => 'text', 'text' => '有新的反馈提交,请及时处理。'],
['type' => 'text', 'text' => ($swName !== '' ? '「' . $swName . '」' : '')
. '有一条新的反馈提交,请到管理后台处理。'],
['type' => 'field', 'rows' => $rows],
['type' => 'quote', 'who' => '反馈内容:', 'text' => $body],
['type' => 'callout', 'tone' => 'warn',
@@ -935,22 +1060,54 @@ if (!function_exists('fb_notify_render')) {
];
$layout = [
'software' => $sw,
'preheader' => $name . ':' . fb_excerpt($body, 60),
'badge' => ['text' => '新反馈', 'color' => '#b4553c'],
'title' => '收到一条新反馈',
'title' => ($swName !== '' ? $swName . ' 收到一条新反馈' : '收到一条新反馈'),
'intro' => '你好:',
'blocks' => $blocks,
'button' => ['text' => '去后台处理', 'url' => fb_base_url() . '/admin.php?tab=thread&id=' . (int)$thread['id']],
'link' => fb_base_url() . '/admin.php?tab=thread&id=' . (int)$thread['id'],
'button' => ['text' => '去后台处理这条反馈', 'url' => $adminUrl],
'link' => $adminUrl,
'recipient' => $to,
'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 {
$subject = '【' . $site . '】' . $short;
$subject = $pfx . $short;
$layout = [
'software' => $sw,
'preheader' => '你有一条新的通知',
'title' => '你有一条新的通知',
'intro' => ($name !== '' ? $name . ',你好:' : '你好:'),