Files
MailNotifier/Manage.php

916 lines
50 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
/**
* MailNotifier 后台面板:邮件历史
*
* 菜单挂在「扩展管理 → 邮件历史」下(Helper::addPanel 的第 3 组)。
*
* 这个页面做三件事:
* 1. 列出每一次发信:成功还是失败、发的是哪种邮件、收件人、邮件正文、关联文章
* 2. 邮件正文用弹窗里的 iframe 原样渲染(邮件模板自带内联样式,直接塞进后台会被全局 CSS 搅乱)
* 3. 插件设置的备份 / 恢复放在插件设置页顶部,这个页面只管发送记录
*
* 动作处理全部放在输出之前,做完就 302 回列表页,避免刷新时重复提交。
*
* @package MailNotifier
*/
if (!defined('__TYPECHO_ROOT_DIR__')) {
exit;
}
if (!class_exists('MailNotifier_Plugin')) {
require_once dirname(__FILE__) . '/Plugin.php';
}
if (!class_exists('MailNotifier_MailLog')) {
require_once dirname(__FILE__) . '/MailLog.php';
}
/* 覆盖升级过的站:进这个页面也顺手把记录表和菜单补齐 */
MailNotifier_Plugin::initSupport();
/* ------------------------------------------------------------------
* 取参:只收标量
*
* ?status[]=1 这种写法拿到的是数组,后面塞进 htmlspecialchars()、
* in_array() 会直接抛 TypeError(PHP 8 是硬错误),所以统一在这里挡掉。
* ------------------------------------------------------------------ */
$cnotGet = function ($key, $default = '') {
if (!isset($_GET[$key])) {
return $default;
}
$raw = $_GET[$key];
return is_scalar($raw) ? (string) $raw : $default;
};
$cnotPost = function ($key, $default = '') {
if (!isset($_POST[$key])) {
return $default;
}
$raw = $_POST[$key];
return is_scalar($raw) ? (string) $raw : $default;
};
$cnotEsc = function ($text) {
return htmlspecialchars((string) $text, ENT_QUOTES, 'UTF-8');
};
$cnotToken = MailNotifier_Plugin::mailLogToken();
$cnotBase = MailNotifier_Plugin::manageUrl();
/* 动作名可能来自 GET(预览)也可能来自 POST 表单(备份 / 恢复 / 清空 / 删除),
表单是 POST 到本页的,do 在请求体里,只读 $_GET 会什么都拿不到。 */
$cnotAction = $cnotPost('do');
if ($cnotAction === '') {
$cnotAction = $cnotGet('do');
}
/* ------------------------------------------------------------------
* 权限:只给管理员
* ------------------------------------------------------------------ */
$cnotIsAdmin = false;
try {
if (isset($user) && is_object($user)) {
$cnotIsAdmin = (bool) $user->pass('administrator', true);
}
} catch (Exception $e) {
$cnotIsAdmin = false;
} catch (Throwable $e) {
$cnotIsAdmin = false;
}
if (!$cnotIsAdmin) {
include 'header.php';
include 'menu.php';
echo '<div class="main"><div class="body container"><div class="row typecho-page-main" role="main">'
. '<div class="col-mb-12"><div style="padding:28px;border:1px solid #e6d2b8;border-radius:14px;'
. 'background:#fffaf4;color:#7a5a35;">只有管理员可以查看邮件历史的发送记录。</div></div></div></div></div>';
include 'footer.php';
return;
}
/* ------------------------------------------------------------------
* 动作:预览邮件正文(GET,输出原始 HTML)
* ------------------------------------------------------------------ */
if ($cnotAction === 'preview') {
if (!MailNotifier_Plugin::checkMailLogToken($cnotGet('_'))) {
while (ob_get_level() > 0) {
ob_end_clean();
}
header('Content-Type: text/plain; charset=UTF-8', true, 403);
echo '链接已失效,请回到「邮件历史」页面重新打开。';
return;
}
$cnotRow = MailNotifier_MailLog::find(intval($cnotGet('id')));
while (ob_get_level() > 0) {
ob_end_clean();
}
header('Content-Type: text/html; charset=UTF-8');
if (!$cnotRow) {
echo '<!doctype html><meta charset="utf-8"><div style="font:14px/1.8 -apple-system,sans-serif;padding:24px;">记录不存在或已被删除。</div>';
return;
}
$cnotBody = isset($cnotRow['body_text']) ? $cnotRow['body_text'] : '';
if (trim($cnotBody) === '') {
echo '<!doctype html><meta charset="utf-8"><div style="font:14px/1.8 -apple-system,sans-serif;padding:24px;color:#8a7a68;">这条记录没有保存邮件正文。</div>';
return;
}
echo $cnotBody;
return;
}
/* ------------------------------------------------------------------
* 动作:备份 / 恢复 / 清空 / 删除(POST + 令牌)
* ------------------------------------------------------------------ */
if ($_SERVER['REQUEST_METHOD'] === 'POST' && $cnotAction !== '') {
/*
* 跳转必须走 Typecho 的 Response,不能只 header('Location:'):
* 后台的响应是在 shutdown 阶段由 Response 统一发出的,它会用自己记的状态码
* (默认 200)盖掉我们设的 302,浏览器于是把「跳转」当成一个普通页面,
* 刷新就会重复提交。Response::redirect() 会把状态码记成 302,才是对的。
*/
$cnotResponse = (isset($response) && is_object($response) && method_exists($response, 'redirect')) ? $response : null;
$cnotRedirect = function ($query) use ($cnotBase, $cnotResponse) {
$url = $cnotBase . '&' . $query;
if ($cnotResponse) {
try {
$cnotResponse->redirect($url);
return $url;
} catch (Exception $e) {
} catch (Throwable $e) {
}
}
header('Location: ' . $url, true, 302);
return $url;
};
if (!MailNotifier_Plugin::checkMailLogToken($cnotPost('_'))) {
$cnotRedirect('msg=token');
exit;
}
if ($cnotAction === 'clear') {
$cnotCount = MailNotifier_MailLog::clearAll();
$cnotRedirect('msg=clear_ok&n=' . intval($cnotCount));
exit;
}
if ($cnotAction === 'delete') {
MailNotifier_MailLog::remove(intval($cnotPost('id')));
$cnotRedirect('msg=delete_ok');
exit;
}
/* 多选删除:ids 是逗号分隔的记录 id,由列表页的表单提交 */
if ($cnotAction === 'delete_multi') {
$cnotIds = array();
foreach (explode(',', (string) $cnotPost('ids')) as $cnotId) {
$cnotId = intval(trim($cnotId));
if ($cnotId > 0) {
$cnotIds[] = $cnotId;
}
}
$cnotCount = MailNotifier_MailLog::removeMany($cnotIds);
$cnotRedirect('msg=delete_multi_ok&n=' . intval($cnotCount));
exit;
}
/* 重发:按记录里存的正文、当前的 SMTP 配置再发一次,结果记成新记录 */
if ($cnotAction === 'resend') {
$cnotRow = MailNotifier_MailLog::find(intval($cnotPost('id')));
if (!$cnotRow) {
$cnotRedirect('msg=resend_fail&detail=' . rawurlencode('记录不存在或已被删除'));
exit;
}
$cnotResult = MailNotifier_Plugin::resendFromLog($cnotRow);
if (!empty($cnotResult['ok'])) {
$cnotRedirect('msg=resend_ok');
} else {
$cnotRedirect('msg=resend_fail&detail=' . rawurlencode(MailNotifier_MailLog::cut(
isset($cnotResult['message']) ? $cnotResult['message'] : '未知原因',
180
)));
}
exit;
}
$cnotRedirect('msg=unknown');
exit;
}
/* ------------------------------------------------------------------
* 列表数据
* ------------------------------------------------------------------ */
$cnotFilters = array(
'status' => $cnotGet('status'),
'type' => $cnotGet('type'),
'keyword' => $cnotGet('keyword'),
);
if ($cnotFilters['status'] !== 'ok' && $cnotFilters['status'] !== 'fail') {
$cnotFilters['status'] = '';
}
if (!array_key_exists($cnotFilters['type'], MailNotifier_MailLog::typeLabels())) {
$cnotFilters['type'] = '';
}
/* 每页条数:列表上可以临时切,没传参时用插件设置里存的默认值 */
$cnotPerPage = intval($cnotGet('per', (string) MailNotifier_Plugin::configRaw('mailPer', '20')));
$cnotPerOptions = array(20, 50, 100);
if (!in_array($cnotPerPage, $cnotPerOptions, true)) {
$cnotPerPage = 20;
}
$cnotPage = max(1, intval($cnotGet('page', '1')));
$cnotTableOk = MailNotifier_MailLog::ensureTable();
$cnotList = MailNotifier_MailLog::page($cnotFilters, $cnotPage, $cnotPerPage);
$cnotStats = MailNotifier_MailLog::stats();
/* 分页 / 筛选链接 */
$cnotQuery = function ($overrides = array()) use ($cnotBase, $cnotFilters, $cnotPerPage) {
$query = array(
'status' => $cnotFilters['status'],
'type' => $cnotFilters['type'],
'keyword' => $cnotFilters['keyword'],
'per' => $cnotPerPage,
);
foreach ($overrides as $key => $value) {
$query[$key] = $value;
}
$parts = array();
foreach ($query as $key => $value) {
if ($value === '' || $value === null) {
continue;
}
$parts[] = $key . '=' . rawurlencode((string) $value);
}
return $cnotBase . (empty($parts) ? '' : '&' . implode('&', $parts));
};
/* 顶部提示条 */
$cnotMsg = $cnotGet('msg');
$cnotNoticeCount = intval($cnotGet('n'));
$cnotNotice = null;
if ($cnotMsg === 'clear_ok') {
$cnotNotice = array('ok', '已清空 ' . $cnotNoticeCount . ' 条发送记录。');
} elseif ($cnotMsg === 'delete_ok') {
$cnotNotice = array('ok', '记录已删除。');
} elseif ($cnotMsg === 'delete_multi_ok') {
$cnotNotice = array($cnotNoticeCount > 0 ? 'ok' : 'fail', $cnotNoticeCount > 0 ? '已删除 ' . $cnotNoticeCount . ' 条发送记录。' : '没有删掉任何记录,可能已被删除过。');
} elseif ($cnotMsg === 'resend_ok') {
$cnotNotice = array('ok', '已重新发送,发送结果会作为新记录出现在列表顶部。');
} elseif ($cnotMsg === 'resend_fail') {
$cnotNotice = array('fail', '重发失败:' . ($cnotGet('detail') !== '' ? $cnotGet('detail') : '未知原因'));
} elseif ($cnotMsg === 'token') {
$cnotNotice = array('fail', '安全令牌校验失败,请刷新页面后重试。');
} elseif ($cnotMsg === 'unknown') {
$cnotNotice = array('fail', '无法识别的操作。');
}
include 'header.php';
include 'menu.php';
?>
<style>
.cnot-log{--bg2:#fff;--bd:rgba(126,96,60,.14);--tx:#332b24;--sub:#8d7b6a;--th:#f7efe4;--accent:#8b633b;--okc:#2f8a57;--failc:#b4503f;--chip:#f5ece0;--shadow:0 12px 30px rgba(75,56,35,.05);font-family:-apple-system,BlinkMacSystemFont,"Segoe UI","PingFang SC","Microsoft YaHei",sans-serif;color:var(--tx);}
#newadmin.dark .cnot-log,body.dark .cnot-log{--bg2:#1b2635;--bd:rgba(255,255,255,.10);--tx:#e8eef7;--sub:#9aa8bb;--th:#1f2b3d;--accent:#d0a877;--okc:#4ade80;--failc:#f87171;--chip:#243247;--shadow:0 12px 30px rgba(0,0,0,.25);}
.cnot-log *{box-sizing:border-box;}
.cnot-log .cnot-card{background:var(--bg2);border:1px solid var(--bd);border-radius:16px;box-shadow:var(--shadow);margin-bottom:16px;overflow:hidden;}
.cnot-log .cnot-card-h{display:flex;align-items:center;justify-content:space-between;gap:12px;flex-wrap:wrap;padding:14px 18px;border-bottom:1px solid var(--bd);background:var(--th);}
.cnot-log .cnot-card-h strong{font-size:15px;color:var(--tx);}
.cnot-log .cnot-card-h span{font-size:12px;color:var(--sub);}
.cnot-log .cnot-card-b{padding:16px 18px;}
/* 隐藏后台自带的页面大标题(h2「邮件历史发送记录」),信息统计卡里都有,留着占地方。
选择器收在自己的包裹层里,不要写成全局 .typecho-page-title —— 同一页面上若还有
别的组件用这个类,会被一起藏掉。
注意别只写 display:none:那个 h2 自带 margin:25px 0 10px,是内容与固定头部之间的
那道间距,一起藏掉的话第一排统计卡会顶到 header 底下,所以把 25px 补到 .cnot-log 上 */
.cnot-pagetitle{height:0;margin:0;padding:0;overflow:hidden;}
.cnot-pagetitle .typecho-page-title{display:none!important;}
.cnot-log{margin-top:25px;}
.cnot-log .cnot-grid{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:12px;margin-bottom:16px;}
/* 统计卡:数字和文字上下左右都居中,三张卡等高 */
.cnot-log .cnot-stat{display:flex;flex-direction:column;align-items:center;justify-content:center;text-align:center;min-height:96px;background:var(--bg2);border:1px solid var(--bd);border-radius:16px;box-shadow:var(--shadow);padding:16px 18px;}
.cnot-log .cnot-stat b{display:block;font-size:26px;line-height:1.2;font-weight:800;text-align:center;}
.cnot-log .cnot-stat em{display:block;margin-top:4px;font-size:12px;font-style:normal;line-height:1.6;color:var(--sub);text-align:center;}
.cnot-log .cnot-v-ok{color:var(--okc);}
.cnot-log .cnot-v-fail{color:var(--failc);}
.cnot-log .cnot-btn{display:inline-flex;align-items:center;justify-content:center;height:34px;padding:0 16px;border-radius:999px;border:1px solid var(--bd);background:var(--chip);color:var(--tx);font-size:13px;font-weight:700;cursor:pointer;text-decoration:none;transition:.15s ease;white-space:nowrap;line-height:1;}
.cnot-log .cnot-btn:hover{transform:translateY(-1px);}
.cnot-log .cnot-btn-primary{background:linear-gradient(135deg,#8b633b,#a77b4c);border-color:transparent;color:#fff;}
.cnot-log .cnot-btn-danger{color:var(--failc);border-color:rgba(180,80,63,.35);background:transparent;}
.cnot-log .cnot-btn[disabled]{opacity:.45;cursor:not-allowed;transform:none;}
/* 表格里的小按钮:圆角别用 999px,28px 高的胶囊两端会把「删除」两个字吃掉 */
.cnot-log table.cnot-table .cnot-btn{height:28px;padding:0 12px;font-size:12px;border-radius:9px;}
.cnot-log .cnot-backup{display:flex;align-items:center;justify-content:space-between;gap:16px;flex-wrap:wrap;padding:16px 18px;border:1px solid var(--bd);border-radius:16px;background:var(--bg2);box-shadow:var(--shadow);margin-bottom:16px;}
.cnot-log .cnot-backup-info{min-width:0;}
.cnot-log .cnot-backup-info strong{display:block;font-size:15px;margin-bottom:6px;}
.cnot-log .cnot-backup-info p{margin:0;font-size:12.5px;line-height:1.7;color:var(--sub);}
.cnot-log .cnot-backup-actions{display:flex;gap:10px;flex-wrap:wrap;}
/* 工具行:左边筛选表单,右边批量操作(已选 N 项 + 删除所选),挤不下时批量条自动换行 */
.cnot-log .cnot-toolbar{display:flex;flex-wrap:wrap;align-items:center;border-bottom:1px solid var(--bd);}
.cnot-log .cnot-filter{display:flex;gap:10px;flex-wrap:wrap;align-items:center;padding:14px 0 14px 18px;flex:1 1 320px;min-width:0;}
.cnot-log .cnot-toolbar .cnot-filter{border-bottom:0;}
.cnot-log .cnot-filter select,.cnot-log .cnot-filter input[type=text]{height:36px;min-width:130px;padding:0 10px;border-radius:10px;border:1px solid var(--bd);background:var(--bg2);color:var(--tx);font-size:13px;outline:none;}
.cnot-log .cnot-filter input[type=text]{min-width:200px;}
.cnot-log .cnot-filter select:focus,.cnot-log .cnot-filter input[type=text]:focus{border-color:var(--accent);}
/* 筛选按钮高度和输入框对齐(.cnot-btn 默认 34px,输入框是 36px) */
.cnot-log .cnot-filter .cnot-btn{height:36px;}
/* 表格:固定列宽(table-layout:fixed),列与列之间严格对齐,不再随内容来回伸缩 */
.cnot-log .cnot-table-wrap{width:100%;overflow-x:auto;}
.cnot-log table.cnot-table{width:100%;min-width:1024px;border-collapse:collapse;table-layout:fixed;}
.cnot-log table.cnot-table th{text-align:left;font-size:12px;font-weight:700;color:var(--sub);letter-spacing:.04em;padding:12px 14px;border-bottom:1px solid var(--bd);white-space:nowrap;background:var(--th);}
.cnot-log table.cnot-table td{padding:12px 14px;border-bottom:1px solid var(--bd);font-size:13px;vertical-align:top;line-height:1.6;overflow-wrap:break-word;}
.cnot-log table.cnot-table th.cnot-c,.cnot-log table.cnot-table td.cnot-c{text-align:center;}
/* 多选框、查看、操作按钮在单元格里上下居中(和状态徽标一致) */
.cnot-log table.cnot-table td.cnot-c{vertical-align:middle;}
.cnot-log table.cnot-table tr:last-child td{border-bottom:0;}
.cnot-log table.cnot-table tbody tr:hover td{background:rgba(126,96,60,.04);}
/* 偶数行极浅斑马纹,长表格逐行看不容易串行 */
.cnot-log table.cnot-table tbody tr:nth-child(even) td{background:rgba(126,96,60,.025);}
.cnot-log table.cnot-table tbody tr:hover:nth-child(even) td{background:rgba(126,96,60,.04);}
.cnot-log table.cnot-table td.cnot-time{white-space:nowrap;font-variant-numeric:tabular-nums;}
/* 状态列:成功/失败徽标在单元格里垂直居中(失败原因跟在徽标下方) */
.cnot-log table.cnot-table td.cnot-state{vertical-align:middle;}
#newadmin.dark .cnot-log table.cnot-table tbody tr:hover td,body.dark .cnot-log table.cnot-table tbody tr:hover td{background:rgba(255,255,255,.04);}
#newadmin.dark .cnot-log table.cnot-table tbody tr:nth-child(even) td,body.dark .cnot-log table.cnot-table tbody tr:nth-child(even) td{background:rgba(255,255,255,.02);}
#newadmin.dark .cnot-log table.cnot-table tbody tr:hover:nth-child(even) td,body.dark .cnot-log table.cnot-table tbody tr:hover:nth-child(even) td{background:rgba(255,255,255,.04);}
/* 状态文字:纯文本,不要背景和内边距,和表头一样左对齐 */
.cnot-log .cnot-badge{display:inline-block;font-size:12.5px;font-weight:700;white-space:nowrap;line-height:1.6;}
.cnot-log .cnot-badge-ok{color:var(--okc);}
.cnot-log .cnot-badge-fail{color:var(--failc);}
.cnot-log .cnot-why{margin-top:6px;font-size:11.5px;line-height:1.55;color:var(--failc);width:100%;overflow-wrap:anywhere;word-break:normal;display:-webkit-box;-webkit-line-clamp:3;-webkit-box-orient:vertical;overflow:hidden;}
/* 类型标签(测试邮件 / 评论通知…):纯文本,和邮件标题共用左边缘 */
.cnot-log .cnot-type{display:block;color:var(--sub);font-size:11.5px;font-weight:700;}
.cnot-log .cnot-subject{display:block;color:var(--tx);word-break:break-all;}
/* 收件邮箱单行显示,超长用省略号,鼠标悬停看全文(避免邮箱被拆成两行、末位只剩一个字母) */
.cnot-log .cnot-mail{display:block;max-width:100%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;}
.cnot-log .cnot-small{display:block;margin-top:3px;font-size:11.5px;color:var(--sub);word-break:break-all;}
/* 文章标题链接:覆盖 NewAdmin 等主题给 a 的胶囊底色和内边距,和邮件标题一样是纯文本 */
.cnot-log .cnot-post{display:inline;background:none!important;border:0!important;padding:0!important;margin:0!important;box-shadow:none!important;border-radius:0;color:var(--accent);text-decoration:none;font-weight:600;word-break:break-all;}
.cnot-log .cnot-post:hover{text-decoration:underline;background:none!important;}
.cnot-log .cnot-muted{color:var(--sub);}
.cnot-log .cnot-empty{padding:52px 20px;text-align:center;color:var(--sub);font-size:13.5px;line-height:1.9;}
.cnot-log .cnot-empty strong{display:block;color:var(--tx);font-size:15px;margin-bottom:6px;}
/* 批量操作条:已选计数 + 删除所选 */
/* 批量操作条:贴在筛选行右侧,margin-left:auto 推到最右 */
.cnot-log .cnot-batch{display:flex;align-items:center;gap:14px;flex-wrap:wrap;margin-left:auto;padding:10px 18px;font-size:12.5px;color:var(--sub);}
.cnot-log .cnot-batch b{color:var(--tx);font-variant-numeric:tabular-nums;}
.cnot-log .cnot-batch .cnot-btn{height:30px;padding:0 14px;font-size:12px;}
/* 多选框 */
.cnot-log input[type=checkbox]{box-sizing:border-box;width:15px;height:15px;margin:0;accent-color:#8b633b;cursor:pointer;vertical-align:middle;}
#newadmin.dark .cnot-log input[type=checkbox],body.dark .cnot-log input[type=checkbox]{accent-color:#d0a877;}
/* 操作列:重发 + 删除 并排 */
.cnot-log .cnot-act{display:flex;align-items:center;justify-content:center;gap:4px;flex-wrap:nowrap;}
.cnot-log .cnot-act .cnot-btn{height:28px;padding:0 10px;font-size:12px;border-radius:9px;}
/* 分页:对齐 RssUnion 网址管理的 typecho-pager——居中排布、无边框、当前页色块、首尾+省略号 */
.cnot-log .cnot-pager{display:flex;justify-content:center;align-items:center;flex-wrap:wrap;gap:5px;padding:14px 18px 16px;font-size:13px;color:var(--sub);list-style:none;margin:0;}
.cnot-log .cnot-pager a,.cnot-log .cnot-pager span{display:inline-block;padding:5px 12px;min-width:30px;text-align:center;border-radius:4px;text-decoration:none;color:var(--accent);transition:all .2s;}
.cnot-log .cnot-pager a:hover{background:rgba(126,96,60,.10);color:var(--tx);}
.cnot-log .cnot-pager span.cnot-cur{background:var(--accent);color:#fff;font-weight:700;cursor:default;}
.cnot-log .cnot-pager span.cnot-ellipsis{padding:5px 8px;color:var(--sub);cursor:default;}
.cnot-log .cnot-pager span.cnot-disabled{color:var(--sub);cursor:not-allowed;}
.cnot-log .cnot-pager .cnot-total{min-width:0;font-size:12.5px;color:var(--sub);margin-right:8px;}
#newadmin.dark .cnot-log .cnot-pager a,body.dark .cnot-log .cnot-pager a{color:#4e92e3;}
#newadmin.dark .cnot-log .cnot-pager a:hover,body.dark .cnot-log .cnot-pager a:hover{background:#1c2a3b;color:#e6edf3;}
#newadmin.dark .cnot-log .cnot-pager span.cnot-cur,body.dark .cnot-log .cnot-pager span.cnot-cur{background:var(--accent);color:#fff;}
#newadmin.dark .cnot-log .cnot-pager span.cnot-ellipsis,#newadmin.dark .cnot-log .cnot-pager span.cnot-disabled,#newadmin.dark .cnot-log .cnot-pager .cnot-total,body.dark .cnot-log .cnot-pager span.cnot-ellipsis,body.dark .cnot-log .cnot-pager span.cnot-disabled,body.dark .cnot-log .cnot-pager .cnot-total{color:#9cb0c6;}
.cnot-log .cnot-alert{display:flex;gap:10px;align-items:flex-start;padding:12px 16px;border-radius:14px;margin-bottom:16px;font-size:13px;line-height:1.7;}
.cnot-log .cnot-alert-ok{background:rgba(47,138,87,.10);border:1px solid rgba(47,138,87,.24);color:var(--okc);}
.cnot-log .cnot-alert-fail{background:rgba(180,80,63,.10);border:1px solid rgba(180,80,63,.26);color:var(--failc);}
.cnot-log .cnot-modal{position:fixed;z-index:99999;left:0;right:0;top:0;bottom:0;display:none;align-items:center;justify-content:center;padding:24px;background:rgba(20,16,12,.62);}
.cnot-log .cnot-modal.is-open{display:flex;}
.cnot-log .cnot-modal-box{display:flex;flex-direction:column;width:min(860px,96vw);height:min(760px,90vh);background:var(--bg2);border-radius:16px;overflow:hidden;box-shadow:0 30px 80px rgba(0,0,0,.35);}
.cnot-log .cnot-modal-h{display:flex;align-items:center;justify-content:space-between;gap:12px;padding:12px 16px;border-bottom:1px solid var(--bd);background:var(--th);}
.cnot-log .cnot-modal-h strong{font-size:14px;}
.cnot-log .cnot-modal-h .cnot-modal-links{display:flex;gap:8px;align-items:center;}
.cnot-log .cnot-modal iframe{flex:1 1 auto;width:100%;border:0;background:#fff;}
/* 深色模式下 iframe 底色跟着变暗,邮件正文由 JS 注入反转滤镜适配(浅色邮件直接反白会刺眼) */
#newadmin.dark .cnot-log .cnot-modal iframe,body.dark .cnot-log .cnot-modal iframe{background:#182230;}
/* 元素级反转滤镜:挂在 iframe 本体上,设 src 前就生效——打开弹窗第一帧就是深色,
不会出现「先白一下再变暗」的闪烁。文档内的 img/video/svg 由 JS 再反一次保色。 */
#newadmin.dark .cnot-log .cnot-modal iframe.cnot-dark,body.dark .cnot-log .cnot-modal iframe.cnot-dark{filter:invert(.91) hue-rotate(180deg);}
@media(max-width:900px){.cnot-log .cnot-grid{grid-template-columns:1fr;}}
@media(max-width:680px){
.cnot-log .cnot-backup{align-items:stretch;flex-direction:column;}
.cnot-log .cnot-backup-actions .cnot-btn{flex:1 1 auto;}
.cnot-log .cnot-filter select,.cnot-log .cnot-filter input[type=text]{flex:1 1 100%;min-width:0;}
/* 窄屏:筛选占满一行,批量条换行到筛选下方 */
.cnot-log .cnot-batch{margin-left:0;padding:0 18px 12px;}
/* 邮件内容列(现在是第 6 列,前面多了多选框)窄屏时隐藏 */
.cnot-log table.cnot-table th:nth-child(6),.cnot-log table.cnot-table td:nth-child(6){display:none;}
}
</style>
<div class="main">
<div class="body container">
<?php /* 用自带类名包一层,把隐藏页面大标题的样式限制在这块里 */ ?>
<div class="cnot-pagetitle"><?php include 'page-title.php'; ?></div>
<div class="row typecho-page-main" role="main">
<div class="col-mb-12 typecho-list">
<div class="cnot-log">
<?php if ($cnotNotice): ?>
<div class="cnot-alert cnot-alert-<?php echo $cnotNotice[0] === 'ok' ? 'ok' : 'fail'; ?>">
<span><?php echo $cnotEsc($cnotNotice[1]); ?></span>
</div>
<?php endif; ?>
<?php if (!$cnotTableOk): ?>
<div class="cnot-alert cnot-alert-fail">
<span>发送记录表创建失败,记录暂时无法写入。请检查数据库账号是否有建表权限,或到 error_log 里搜 [MailNotifier] 看具体报错。</span>
</div>
<?php endif; ?>
<div class="cnot-grid">
<div class="cnot-stat">
<b><?php echo intval($cnotStats['total']); ?></b>
<em>发送记录总数(最多保留 <?php echo intval(MailNotifier_MailLog::keepLimit()); ?> 条)</em>
</div>
<div class="cnot-stat">
<b class="cnot-v-ok"><?php echo intval($cnotStats['ok']); ?></b>
<em>发送成功</em>
</div>
<div class="cnot-stat">
<b class="cnot-v-fail"><?php echo intval($cnotStats['fail']); ?></b>
<em>发送失败</em>
</div>
</div>
<!-- 筛选 + 列表 -->
<div class="cnot-card">
<div class="cnot-card-h">
<strong>发送记录</strong>
<span>每封邮件发完就记一条,失败的也会记下来并写明原因</span>
</div>
<!-- 工具行:左筛选右批量 -->
<div class="cnot-toolbar">
<form method="get" action="<?php echo $cnotEsc(rtrim($cnotBase, '&')); ?>" class="cnot-filter">
<input type="hidden" name="panel" value="<?php echo $cnotEsc(MailNotifier_Plugin::PANEL_FILE); ?>">
<select name="status">
<option value="">全部状态</option>
<option value="ok"<?php echo $cnotFilters['status'] === 'ok' ? ' selected' : ''; ?>>发送成功</option>
<option value="fail"<?php echo $cnotFilters['status'] === 'fail' ? ' selected' : ''; ?>>发送失败</option>
</select>
<select name="type">
<option value="">全部类型</option>
<?php foreach (MailNotifier_MailLog::typeLabels() as $cnotKey => $cnotLabel): ?>
<option value="<?php echo $cnotEsc($cnotKey); ?>"<?php echo $cnotFilters['type'] === $cnotKey ? ' selected' : ''; ?>><?php echo $cnotEsc($cnotLabel); ?></option>
<?php endforeach; ?>
</select>
<input type="text" name="keyword" value="<?php echo $cnotEsc($cnotFilters['keyword']); ?>" placeholder="收件人 / 邮件标题 / 文章标题">
<select name="per">
<?php foreach ($cnotPerOptions as $cnotPer): ?>
<option value="<?php echo $cnotPer; ?>"<?php echo $cnotPerPage === $cnotPer ? ' selected' : ''; ?>>每页 <?php echo $cnotPer; ?> 条</option>
<?php endforeach; ?>
</select>
<button type="submit" class="cnot-btn">筛选</button>
<?php if ($cnotFilters['status'] !== '' || $cnotFilters['type'] !== '' || $cnotFilters['keyword'] !== ''): ?>
<a class="cnot-btn" href="<?php echo $cnotEsc($cnotBase); ?>">重置</a>
<?php endif; ?>
</form>
<?php if (!empty($cnotList['rows'])): ?>
<!-- 批量操作:贴在筛选右侧;按钮由 JS 提交下方列表表单 -->
<div class="cnot-batch">
<span class="cnot-batch-info">已选 <b id="cnot-sel-count">0</b> 项</span>
<button type="button" class="cnot-btn cnot-btn-danger" id="cnot-del-sel" disabled>删除所选</button>
</div>
<?php endif; ?>
</div><!-- end .cnot-toolbar -->
<?php if (empty($cnotList['rows'])): ?>
<div class="cnot-empty">
<strong><?php echo ($cnotFilters['status'] !== '' || $cnotFilters['type'] !== '' || $cnotFilters['keyword'] !== '') ? '没有符合条件的记录' : '还没有发送记录'; ?></strong>
<?php if ($cnotFilters['status'] !== '' || $cnotFilters['type'] !== '' || $cnotFilters['keyword'] !== ''): ?>
换个筛选条件试试。
<?php else: ?>
等有人评论、或者点一次插件设置里的「测试发送」,这里就会出现记录。
<?php endif; ?>
</div>
<?php else: ?>
<!-- 列表表单:多选框 + 单条删除 / 重发 / 批量删除都走它提交 -->
<form method="post" action="<?php echo $cnotEsc($cnotBase); ?>" id="cnot-list-form" class="cnot-list-form">
<input type="hidden" name="do" value="">
<input type="hidden" name="id" value="0">
<input type="hidden" name="ids" value="">
<input type="hidden" name="_" value="<?php echo $cnotEsc($cnotToken); ?>">
<div class="cnot-table-wrap">
<table class="cnot-table">
<thead>
<tr>
<th class="cnot-c" style="width:36px;"><input type="checkbox" id="cnot-check-all" aria-label="全选本页"></th>
<th style="width:88px;">状态</th>
<th>邮件</th>
<th style="width:160px;">收件人</th>
<th style="width:150px;">关联文章</th>
<th class="cnot-c" style="width:92px;">邮件内容</th>
<th style="width:132px;">发送时间</th>
<th class="cnot-c" style="width:128px;">操作</th>
</tr>
</thead>
<tbody>
<?php foreach ($cnotList['rows'] as $cnotRow): ?>
<?php
$cnotRowId = intval($cnotRow['id']);
$cnotIsOk = isset($cnotRow['status']) && $cnotRow['status'] === 'ok';
$cnotType = isset($cnotRow['mail_type']) ? (string) $cnotRow['mail_type'] : '';
$cnotPostTitle = isset($cnotRow['post_title']) ? (string) $cnotRow['post_title'] : '';
$cnotPostUrl = isset($cnotRow['post_url']) ? (string) $cnotRow['post_url'] : '';
$cnotCreated = isset($cnotRow['created']) ? intval($cnotRow['created']) : 0;
$cnotPreviewUrl = $cnotBase . '&do=preview&id=' . $cnotRowId . '&_=' . rawurlencode($cnotToken);
?>
<tr>
<td class="cnot-c"><input type="checkbox" class="cnot-check-item" value="<?php echo $cnotRowId; ?>" aria-label="选择这条记录"></td>
<td class="cnot-state">
<?php if ($cnotIsOk): ?>
<span class="cnot-badge cnot-badge-ok">成功</span>
<?php else: ?>
<span class="cnot-badge cnot-badge-fail">失败</span>
<?php if (!empty($cnotRow['message'])): ?>
<span class="cnot-why" title="<?php echo $cnotEsc($cnotRow['message']); ?>"><?php echo $cnotEsc(MailNotifier_MailLog::cut($cnotRow['message'], 60)); ?></span>
<?php endif; ?>
<?php endif; ?>
</td>
<td>
<span class="cnot-type"><?php echo $cnotEsc(MailNotifier_MailLog::typeLabel($cnotType)); ?></span>
<span class="cnot-subject"><?php echo $cnotEsc($cnotRow['subject']); ?></span>
</td>
<td>
<span class="cnot-mail" title="<?php echo $cnotEsc($cnotRow['to_mail']); ?>"><?php echo $cnotEsc($cnotRow['to_mail']); ?></span>
<?php if (!empty($cnotRow['to_name'])): ?>
<span class="cnot-small"><?php echo $cnotEsc($cnotRow['to_name']); ?></span>
<?php endif; ?>
</td>
<td>
<?php if ($cnotPostTitle !== ''): ?>
<?php if ($cnotPostUrl !== ''): ?>
<a class="cnot-post" href="<?php echo $cnotEsc($cnotPostUrl); ?>" target="_blank" rel="noopener noreferrer"><?php echo $cnotEsc($cnotPostTitle); ?></a>
<?php else: ?>
<span class="cnot-subject"><?php echo $cnotEsc($cnotPostTitle); ?></span>
<?php endif; ?>
<?php else: ?>
<span class="cnot-muted">—</span>
<?php endif; ?>
</td>
<td class="cnot-c">
<a href="<?php echo $cnotEsc($cnotPreviewUrl); ?>" target="_blank" rel="noopener noreferrer"
class="cnot-btn cnot-preview" data-url="<?php echo $cnotEsc($cnotPreviewUrl); ?>"
data-title="<?php echo $cnotEsc($cnotRow['subject']); ?>">查看</a>
</td>
<td class="cnot-time">
<?php echo $cnotEsc($cnotCreated > 0 ? date('Y-m-d H:i', $cnotCreated) : '—'); ?>
</td>
<td class="cnot-c">
<div class="cnot-act">
<button type="button" class="cnot-btn cnot-act-resend" data-id="<?php echo $cnotRowId; ?>"
title="按当前 SMTP 配置把这封邮件再发一次">重发</button>
<button type="button" class="cnot-btn cnot-btn-danger cnot-act-del" data-id="<?php echo $cnotRowId; ?>">删除</button>
</div>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</form>
<?php if ($cnotList['pages'] > 1): ?>
<?php
/* 分页结构照抄 RssUnion 网址管理的 typecho-pager:
上一页 / 页码(总页数不多全列,多了只留当前附近 + 首尾省略号) / 下一页;
首末页的上一页、下一页输出禁用态,样式里单独拉灰 */
$cnotPageList = array();
if ($cnotList['pages'] <= 7) {
for ($cnotI = 1; $cnotI <= $cnotList['pages']; $cnotI++) {
$cnotPageList[] = $cnotI;
}
} else {
$cnotStart = max(1, $cnotList['page'] - 2);
$cnotEnd = min($cnotList['pages'], $cnotStart + 4);
$cnotStart = max(1, $cnotEnd - 4);
for ($cnotI = $cnotStart; $cnotI <= $cnotEnd; $cnotI++) {
$cnotPageList[] = $cnotI;
}
if ($cnotStart > 1) {
array_unshift($cnotPageList, 1, 0);
}
if ($cnotEnd < $cnotList['pages']) {
$cnotPageList[] = 0;
$cnotPageList[] = $cnotList['pages'];
}
}
?>
<div class="cnot-pager">
<span class="cnot-total">共 <?php echo intval($cnotList['total']); ?> 条 · 第 <?php echo intval($cnotList['page']); ?> / <?php echo intval($cnotList['pages']); ?> 页</span>
<?php if ($cnotList['page'] > 1): ?>
<a href="<?php echo $cnotEsc($cnotQuery(array('page' => $cnotList['page'] - 1))); ?>">上一页</a>
<?php else: ?>
<span class="cnot-disabled">上一页</span>
<?php endif; ?>
<?php foreach ($cnotPageList as $cnotI): ?>
<?php if ($cnotI === 0): ?>
<span class="cnot-ellipsis">…</span>
<?php elseif ($cnotI === $cnotList['page']): ?>
<span class="cnot-cur"><?php echo $cnotI; ?></span>
<?php else: ?>
<a href="<?php echo $cnotEsc($cnotQuery(array('page' => $cnotI))); ?>"><?php echo $cnotI; ?></a>
<?php endif; ?>
<?php endforeach; ?>
<?php if ($cnotList['page'] < $cnotList['pages']): ?>
<a href="<?php echo $cnotEsc($cnotQuery(array('page' => $cnotList['page'] + 1))); ?>">下一页</a>
<?php else: ?>
<span class="cnot-disabled">下一页</span>
<?php endif; ?>
</div>
<?php endif; ?>
<?php endif; ?>
</div>
<!-- 清空记录:放在最后,不抢眼 -->
<?php if (!empty($cnotList['total'])): ?>
<div class="cnot-backup">
<div class="cnot-backup-info">
<strong>清空发送记录</strong>
<p>只删记录,不影响插件设置和已发出的邮件。要备份设置,请到插件设置页顶部的「插件设置备份」。</p>
</div>
<div class="cnot-backup-actions">
<form method="post" action="<?php echo $cnotEsc($cnotBase); ?>" style="margin:0;"
onsubmit="return confirm('确定清空全部 <?php echo intval($cnotList['total']); ?> 条发送记录?此操作不可撤销。');">
<input type="hidden" name="do" value="clear">
<input type="hidden" name="_" value="<?php echo $cnotEsc($cnotToken); ?>">
<button type="submit" class="cnot-btn cnot-btn-danger">清空全部记录</button>
</form>
</div>
</div>
<?php endif; ?>
<!-- 邮件正文弹窗 -->
<div class="cnot-modal" id="cnot-modal" aria-hidden="true">
<div class="cnot-modal-box">
<div class="cnot-modal-h">
<strong id="cnot-modal-title">邮件内容</strong>
<div class="cnot-modal-links">
<a class="cnot-btn" id="cnot-modal-newtab" href="#" target="_blank" rel="noopener noreferrer" style="height:28px;padding:0 12px;font-size:12px;">新窗口打开</a>
<button type="button" class="cnot-btn" id="cnot-modal-close" style="height:28px;padding:0 12px;font-size:12px;">关闭</button>
</div>
</div>
<iframe id="cnot-modal-frame" src="about:blank" title="邮件内容预览"></iframe>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<script>
(function () {
var modal = document.getElementById('cnot-modal');
var frame = document.getElementById('cnot-modal-frame');
var title = document.getElementById('cnot-modal-title');
var newTab = document.getElementById('cnot-modal-newtab');
var closeBtn = document.getElementById('cnot-modal-close');
if (!modal || !frame) {
return;
}
/* ------------------------------------------------------------------
* 深色模式适配:邮件模板本身是浅色设计的 HTML,直接放进深色弹窗
* 会是一大块白。整体反转滤镜挂在 iframe 元素本体上(.cnot-dark 类,
* 设 src 前就切换好,打开第一帧就是深色,不会先白一下再变暗);
* 文档内只注入 img/video/svg 的反向补偿,让图片颜色保持原样。
* 浅色模式两边都不动。
* ------------------------------------------------------------------ */
function isDarkMode() {
var na = document.getElementById('newadmin');
return document.body.classList.contains('dark') || (na && na.classList.contains('dark'));
}
var DARK_TINT_ID = 'cnot-dark-tint';
/* 文档内只补媒体元素:iframe 元素级滤镜已经把整页反过了,这里再反一次
正好抵消,图片/视频/SVG 恢复原色 */
var DARK_TINT_CSS = 'html{background:#182230!important}'
+ 'img,video,svg{filter:invert(1) hue-rotate(180deg)}';
/* 同步部分:切 iframe 元素上的滤镜类,打开弹窗前调用,保证首帧即深色 */
function applyFrameFilter() {
if (isDarkMode()) {
frame.className += (frame.className ? ' ' : '') + 'cnot-dark';
} else {
frame.className = frame.className.replace(/\s?cnot-dark/g, '');
}
}
/* 文档内部分:iframe 加载完后注入媒体补偿样式(幂等) */
function tintFrameDoc() {
try {
var doc = frame.contentDocument;
if (!doc || !doc.documentElement) {
return;
}
if (isDarkMode()) {
if (!doc.getElementById(DARK_TINT_ID)) {
var st = doc.createElement('style');
st.id = DARK_TINT_ID;
st.textContent = DARK_TINT_CSS;
(doc.head || doc.documentElement).appendChild(st);
}
} else {
var old = doc.getElementById(DARK_TINT_ID);
if (old && old.parentNode) {
old.parentNode.removeChild(old);
}
}
} catch (e) {
/* 跨域或文档没就绪就算了,浅色邮件在深色里也只是白底 */
}
}
frame.addEventListener('load', tintFrameDoc);
/* 主题在弹窗开着的时候被切换(NewAdmin 的深浅色开关),两边都要跟着变 */
function syncTint() {
applyFrameFilter();
tintFrameDoc();
}
if (typeof MutationObserver !== 'undefined') {
new MutationObserver(syncTint).observe(document.body, { attributes: true, attributeFilter: ['class'] });
var na = document.getElementById('newadmin');
if (na) {
new MutationObserver(syncTint).observe(na, { attributes: true, attributeFilter: ['class'] });
}
}
function openModal(url, subject) {
if (title) {
title.textContent = subject ? ('邮件内容 · ' + subject) : '邮件内容';
}
if (newTab) {
newTab.setAttribute('href', url);
}
/* 关键顺序:先切滤镜类再设 src,iframe 第一帧渲染时滤镜已就位 */
applyFrameFilter();
frame.setAttribute('src', url);
modal.className += ' is-open';
modal.setAttribute('aria-hidden', 'false');
}
function closeModal() {
modal.className = modal.className.replace(/\s?is-open/g, '');
modal.setAttribute('aria-hidden', 'true');
frame.setAttribute('src', 'about:blank');
}
var links = document.querySelectorAll('.cnot-log .cnot-preview');
for (var i = 0; i < links.length; i++) {
links[i].addEventListener('click', function (event) {
// 后台里用弹窗看更顺手;按住 Ctrl / Cmd 或中键仍然走浏览器新标签
if (event.metaKey || event.ctrlKey || event.shiftKey || event.button !== 0) {
return;
}
event.preventDefault();
openModal(this.getAttribute('data-url'), this.getAttribute('data-title'));
});
}
if (closeBtn) {
closeBtn.addEventListener('click', closeModal);
}
modal.addEventListener('click', function (event) {
if (event.target === modal) {
closeModal();
}
});
document.addEventListener('keydown', function (event) {
if (event.key === 'Escape' || event.keyCode === 27) {
closeModal();
}
});
})();
</script>
<script>
/* 列表的多选 + 单条删除 / 重发 / 批量删除 */
(function () {
var form = document.getElementById('cnot-list-form');
if (!form) {
return;
}
var all = document.getElementById('cnot-check-all');
var items = form.querySelectorAll('.cnot-check-item');
var countEl = document.getElementById('cnot-sel-count');
var delSel = document.getElementById('cnot-del-sel');
function selectedIds() {
var ids = [];
for (var i = 0; i < items.length; i++) {
if (items[i].checked) {
ids.push(items[i].value);
}
}
return ids;
}
function refresh() {
var n = selectedIds().length;
if (countEl) {
countEl.textContent = n;
}
if (delSel) {
delSel.disabled = (n === 0);
}
if (all) {
all.checked = n > 0 && n === items.length;
all.indeterminate = n > 0 && n < items.length;
}
}
/* 单条 / 批量都把参数写进隐藏域再提交整张表单,
免得每行再塞一个小 form(表格里嵌 form 也合法但不干净) */
function submitList(doName, data) {
form.elements['do'].value = doName;
form.elements['id'].value = data.id || 0;
form.elements['ids'].value = data.ids || '';
form.submit();
}
if (all) {
all.addEventListener('change', function () {
for (var i = 0; i < items.length; i++) {
items[i].checked = all.checked;
}
refresh();
});
}
for (var j = 0; j < items.length; j++) {
items[j].addEventListener('change', refresh);
}
if (delSel) {
delSel.addEventListener('click', function () {
var ids = selectedIds();
if (ids.length === 0) {
return;
}
if (!window.confirm('删除所选的 ' + ids.length + ' 条记录?此操作不可撤销。')) {
return;
}
submitList('delete_multi', {ids: ids.join(',')});
});
}
var resends = form.querySelectorAll('.cnot-act-resend');
for (var k = 0; k < resends.length; k++) {
resends[k].addEventListener('click', function () {
if (!window.confirm('按当前 SMTP 配置把这封邮件再发一次?')) {
return;
}
submitList('resend', {id: this.getAttribute('data-id')});
});
}
var dels = form.querySelectorAll('.cnot-act-del');
for (var m = 0; m < dels.length; m++) {
dels[m].addEventListener('click', function () {
if (!window.confirm('删除这条发送记录?')) {
return;
}
submitList('delete', {id: this.getAttribute('data-id')});
});
}
refresh();
})();
</script>
<?php include 'footer.php'; ?>