Files
wordpress-kratos-yang/inc/theme-options.php
T
laoyang 37c52948c4 版本号 3.2.5 -> 3.2.6(统一邮件出口 + 邮件模板 + 纪念日自动哀悼 + 去掉广告位)
评论邮件重复的根因是发信源不止一个,分两层处理:一层管「谁发」,一层管「发几封」。
只做前者的话邮件照样重复,只是都从同一个 SMTP 出去。

邮件治理(新增 inc/theme-mail.php)
- phpmailer_init 优先级 9999 接管通道,保证主题配置优先于其它 SMTP 插件;
  接管前先重置可能被别的插件设过的字段,避免残留半套配置。
- From 强制等于 SMTP 登录账号。QQ / 163 会以「发件人不符」拒收。
- wp_mail 优先级 99 统一 From 与 Content-Type;调用方自带的 From 与
  Content-Type 被剥离后重建,自定义 header 保留。
- wp_mail 优先级 100 做短期去重:同一收件人 + 同主题 + 同正文,90 秒内只发一次。
  用 transient 是因为评论通知跨请求(wpDiscuz 走 AJAX、审核通知走后台请求),
  静态变量跨不过去。90 秒足够宽(一次提交引发的通知都在同一秒)也足够窄
  (手动重发通常隔几分钟,不该被吞)。
- 被去重的那次把 to 置空并由 pre_wp_mail 返回 true,而不是 return null:
  返回 null 会改变 wp_mail 返回值语义,有的插件据此判定失败并重试,反而更多封。
- 用 filter 关掉核心的 notify_postauthor / notify_moderator,不改进数据库里的
  comments_notify / moderation_notify。改用户设置属于越权,而且用户下次进后台
  一勾又回来了;filter 是可逆的。只拦通知,不影响评论审核流程。
- 线上站点 m_smtp=1 但 m_host 为空时判定为「未就绪」并完全放手。只勾开关不填
  主机时若强行接管,所有邮件会静默失败,比回退到 mail() 更糟。

邮件模板(新增 inc/theme-mail-template.php)
- 表格布局 + 全内联样式:Outlook 2007-2019 用 Word 引擎,不认 flex / grid;
  Gmail 会剥掉 <head> 里的 style 块(含 media query)。
- 不用外部图片、不用 CSS 变量、不用 ::before。按钮的 padding 放在 td 上,
  因为 Outlook 忽略 a 的 padding。
- 宽度用混合写法:HTML 属性 width=600 给 Outlook,CSS 的
  width:100% + max-width:600px 让手机窄屏自动收窄。只写死 600px 会让手机横向滚动。
- badge 背景用预算的实色而非 rgba。Outlook 不支持 rgba,会当成非法值丢掉,
  半透明背景变成全透明,badge 直接消失。
- 主色下沿那条 3px 深色带必须 height 同时写成 HTML 属性和 CSS,
  否则 Outlook 把它撑成一行文字高,比例就毁了。
- 用 WCAG 相对亮度判断主色深浅来决定叠在上面的文字用白还是深色。
  简单取平均会把 #00ff00 判成中等亮度(人眼对绿最敏感、蓝最不敏感)。
- 次要文字统一调到 #5f6b78。原来的浅灰在白底上只有 1.84:1,看着"高级"但读不出来;
  现在最低 4.62:1,全部过 AA。

theme-smtp.php
- 删掉 comment_notify / comment_approved 两个钩子及其硬编码模板。这两个钩子与
  wpDiscuz 的 notifyCommentSubscribers 完全重复,是重复收信的直接来源。

纪念日自动哀悼(新增 inc/theme-mourning.php)
- 法定纪念日三个默认勾选:09-03 抗战胜利纪念日、09-30 烈士纪念日、
  12-13 南京大屠杀死难者国家公祭日。依据是 2014 年全国人大常委会两次决定,
  已在代码注释里记下来源。
- 民间通行做法(05-12、09-18 等)默认不勾,由用户自己决定。替用户做价值判断不合适。
- 一次性全国哀悼日(2020-04-04 等)支持 YYYY-MM-DD 写法,只在当年生效。
  不能当周年循环,否则明年 4 月 4 日又自动变黑白。
- 按站点时区判断(current_time),不按服务器时区。服务器在 UTC 时会晚 8 小时生效。
- 只挂 wp_head 而不限定 is_home():老代码限定首页,详情页不黑白,那是 bug。
- 打印时取消灰度,否则打印出来是灰的。
- 保留旧的 g_rip 手动常开开关。不能因为升级把原本黑白中的站点变回彩色。

options-framework
- 补 multicheck 的渲染分支与 of_sanitize_multicheck。框架原来只在保存侧处理了
  这个类型,没有渲染分支,所以这个类型此前根本不可用。
- 值存成 array(键 => 1|0) 而不是「勾选了的键组成的列表」:列表无法区分
  「用户明确全部取消」和「从未配置」,会导致取消勾选后静默回退到默认值。
- 读取侧用 array_key_exists 判断是否保存过,而不是判断值是否为空。
- 配套补上 of-multicheck 样式,没有样式时 9 个选项会挤成一行流水文字。

去掉广告配置
- 删除主题选项里的广告配置段,以及 single.php 里上下两处广告位输出。

验证
- 全主题 68 个 PHP 文件语法检查通过。
- 行为测试 82 条、multicheck 闭环 25 条、邮件几何 15 条、设计审计 23 条。
- 反向验证 16 个注入 bug 全部被断言抓住(去重失效、不写标记、to 未清空、
  From 未剥离、亮度算法退化、时区改用 date()、全不勾回退默认等)。
- 邮件最低文字对比度 4.62:1;320px 视口下卡片自动收窄到 296px 不溢出。
2026-10-23 13:55:23 +08:00

546 lines
17 KiB
PHP
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
/**
* 主题选项
* @author Yongquan Yang <yangyq.net>
* @license MIT License
* @version 2020.09.21
*/
function getrobots()
{
$site_url = parse_url(site_url());
$path = (!empty($site_url['path'])) ? $site_url['path'] : '';
$robots = "User-agent: *\n\n";
$robots .= "Disallow: $path/wp-admin/\n";
$robots .= "Disallow: $path/wp-includes/\n";
$robots .= "Disallow: $path/wp-content/plugins/\n";
$robots .= "Disallow: $path/wp-content/themes/\n";
return $robots;
}
function kratos_options()
{
$sitename = get_bloginfo('name');
$imagepath = ASSET_PATH . '/assets/img/options/';
$seorobots = '<a href="' . home_url() . '/robots.txt" target="_blank">robots.txt</a>';
$seoreading = '<a href="' . admin_url('options-reading.php') . '" target="_blank">' . __('设置-阅读-对搜索引擎的可见性', 'kratos') . '</a>';
$cc_array = array(
'one' => __('知识共享署名 4.0 国际许可协议', 'kratos'),
'two' => __('知识共享署名-非商业性使用 4.0 国际许可协议', 'kratos'),
'three' => __('知识共享署名-禁止演绎 4.0 国际许可协议', 'kratos'),
'four' => __('知识共享署名-非商业性使用-禁止演绎 4.0 国际许可协议', 'kratos'),
'five' => __('知识共享署名-相同方式共享 4.0 国际许可协议', 'kratos'),
'six' => __('知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议', 'kratos'),
);
$top_array = array(
'banner' => __( '图片导航', 'kratos' ),
'color' => __( '颜色导航', 'kratos' ),
);
$options = array();
$options[] = array(
'name' => __('全站配置', 'kratos'),
'type' => 'heading',
);
$options[] = array(
'name' => __('图片 Logo', 'kratos'),
'desc' => __('不选择图片则显示文字标题', 'kratos'),
'id' => 'g_logo',
'type' => 'upload',
);
$options[] = array(
'name' => __('Favicon 图片', 'kratos'),
'desc' => __('浏览器收藏夹和地址栏中显示的图标', 'kratos'),
'id' => 'g_icon',
'type' => 'upload',
);
$options[] = array(
'name' => __('是否添加国旗', 'kratos'),
'desc' => __('在页脚添加国旗', 'kratos'),
'std' => '0',
'id' => 'g_flag',
'type' => 'checkbox',
);
$options[] = array(
'name' => __('国旗地址', 'kratos'),
'desc' => __('选择国旗图片地址', 'kratos'),
'id' => 'g_flag_url',
'type' => 'upload',
);
$options[] = array(
'name' => __('背景颜色', 'kratos'),
'desc' => __('全站页面的背景颜色,需填写十六进制颜色码', 'kratos'),
'id' => 'g_background',
'std' => '#f5f5f5',
'type' => 'color',
);
$options[] = array(
'name' => __('前台管理员导航', 'kratos'),
'desc' => __('开启前台管理员导航', 'kratos'),
'std' => '1',
'id' => 'g_adminbar',
'type' => 'checkbox',
);
$options[] = array(
'name' => __('多人模式', 'kratos'),
'desc' => __('在文章列表显示当前文章作者,在文章页面页脚显示当前作者介绍', 'kratos'),
'id' => 'multiusers',
'type' => 'checkbox',
);
$options[] = array(
'name' => __('CSS 动画库', 'kratos'),
'desc' => __('开启 animate.css 效果', 'kratos'),
'std' => '0',
'id' => 'g_animate',
'type' => 'checkbox',
);
$options[] = array(
'name' => __('Font Awesome', 'kratos'),
'desc' => __('开启 Font Awesome 字体', 'kratos'),
'std' => '0',
'id' => 'g_fontawesome',
'type' => 'checkbox',
);
$options[] = array(
'name' => __('禁止生成缩略图', 'kratos'),
'desc' => __('是否禁止生成多种尺寸图片资源', 'kratos'),
'id' => 'g_removeimgsize',
'std' => '0',
'type' => 'checkbox',
);
$options[] = array(
'name' => __('Gutenberg 编辑器', 'kratos'),
'desc' => __('开启 Gutenberg 编辑器', 'kratos'),
'std' => '0',
'id' => 'g_gutenberg',
'type' => 'checkbox',
);
$options[] = array(
'name' => __('Gravatar 加速', 'kratos'),
'desc' => __('开启 Gravatar 头像加速', 'kratos'),
'std' => '0',
'id' => 'g_gravatar',
'type' => 'checkbox',
);
$options[] = array(
'name' => __('Chrome 导航栏颜色', 'kratos'),
'desc' => __('Chrome 移动端浏览器导航栏的颜色', 'kratos'),
'id' => 'g_chrome',
'std' => '#282a2c',
'type' => 'color',
);
$options[] = array(
'name' => __('微信二维码', 'kratos'),
'desc' => __('开启页面右下角浮动微信二维码', 'kratos'),
'id' => 's_wechat',
'type' => 'checkbox',
);
$options[] = array(
'id' => 's_wechat_url',
'std' => ASSET_PATH . '/assets/img/wechat.png',
'type' => 'upload',
'class' => 'hidden',
'type' => 'upload',
);
$options[] = array(
'name' => __('404 页面图片', 'kratos'),
'id' => 'g_404',
'std' => ASSET_PATH . '/assets/img/404.jpg',
'type' => 'upload',
);
$options[] = array(
'name' => __('收录配置', 'kratos'),
'type' => 'heading',
);
$options[] = array(
'name' => __('分享图片', 'kratos'),
'desc' => __('搜索引擎或者社交工具分享首页时抓取的图片', 'kratos'),
'id' => 'seo_shareimg',
'std' => ASSET_PATH . '/assets/img/default.jpg',
'type' => 'upload',
);
$options[] = array(
'name' => __('关键词', 'kratos'),
'desc' => __('每个关键词之间需要用「英文逗号」分割', 'kratos'),
'id' => 'seo_keywords',
'type' => 'text',
);
$options[] = array(
'name' => __('站点描述', 'kratos'),
'id' => 'seo_description',
'type' => 'textarea',
);
$options[] = array(
'name' => __('统计代码', 'kratos'),
'desc' => __('注意:输入 HTML/JS 代码时请注意辨别代码安全!', 'kratos'),
'id' => 'seo_statistical',
'type' => 'textarea',
);
$options[] = array(
'name' => __('robots.txt 配置', 'kratos'),
'desc' => __('- 需要 ', 'kratos') . $seoreading . __(' 是开启的状态,下面的配置才会生效', 'kratos'),
'type' => 'info',
);
$options[] = array(
'desc' => __('- 如果网站根目录下已经有 robots.txt 文件,下面的配置不会生效', 'kratos'),
'type' => 'info',
);
$options[] = array(
'desc' => __('- 点击 ', 'kratos') . $seorobots . __(' 查看配置是否生效,如果网站开启了 CDN,可能需要刷新缓存才会生效', 'kratos'),
'type' => 'info',
);
$options[] = array(
'id' => 'seo_robots',
'std' => getrobots(),
'type' => 'textarea',
);
$options[] = array(
'name' => __('首页配置', 'kratos'),
'type' => 'heading',
);
$options[] = array(
'name' => __('哀悼功能', 'kratos'),
'desc' => __('开启后站点首页与文章页转为黑白。这是老的手动开关,开了就一直黑白,与日期无关。日常建议用下面的「按纪念日自动哀悼」。', 'kratos'),
'id' => 'g_rip',
'type' => 'checkbox',
);
$options[] = array(
'name' => __('按纪念日自动哀悼', 'kratos'),
'desc' => __('勾选后,只有在下表勾选的那些日期才会自动黑白,其余日子正常显示。日期按站点时区判断,只比对月和日,每年循环。', 'kratos'),
'id' => 'g_rip_auto',
'type' => 'checkbox',
);
// 把内置清单转成 multicheck 需要的格式
$rip_options = array();
$rip_legal = array();
$rip_custom = array();
foreach (yang_mourning_presets() as $md => $info) {
$entry = array(
'name' => $md . ' ' . $info['name'],
'note' => $info['note'],
);
if (isset($info['group']) && $info['group'] === 'legal') {
$rip_legal[$md] = $entry;
} else {
$rip_custom[$md] = $entry;
}
}
$rip_default = array();
foreach (yang_mourning_presets() as $md => $info) {
$rip_default[$md] = !empty($info['default']) ? 1 : 0;
}
$options[] = array(
'name' => __('纪念日清单', 'kratos'),
'desc' => __('勾选需要自动黑白的日期。前三个是法定纪念日(默认已勾),后面几个是民间通行做法,按自己意愿决定。日期按站点时区判断,只比对月和日,每年循环。', 'kratos'),
'id' => 'g_rip_days',
'std' => $rip_default,
'type' => 'multicheck',
'options' => array_merge($rip_legal, $rip_custom),
);
$options[] = array(
'name' => __('附加日期', 'kratos'),
'desc' => __('可选。填 MM-DD 表示每年循环(如 05-12);填 YYYY-MM-DD 表示只在当年生效(如 2020-04-04,用于历次全国哀悼日这类一次性事件)。多个日期用空格或逗号分隔。', 'kratos'),
'id' => 'g_rip_extra',
'type' => 'text',
);
$options[] = array(
'desc' => yang_mourning_status_text(),
'type' => 'info',
);
$options[] = array(
'name' => __('特色图片', 'kratos'),
'desc' => __('开启站点首页特色图片功能', 'kratos'),
'std' => '1',
'id' => 'g_thumbnail',
'type' => 'checkbox',
);
$options[] = array(
'name' => __('默认特色图', 'kratos'),
'desc' => __('当文章中没有图片并且没有设置特色图时在首页显示', 'kratos'),
'id' => 'g_postthumbnail',
'class' => 'hidden',
'std' => ASSET_PATH . '/assets/img/default.jpg',
'type' => 'upload',
);
$options[] = array(
'name' => __('无内容图片', 'kratos'),
'desc' => __('当搜索不到文章或文章分类中没有文章时显示', 'kratos'),
'id' => 'g_nothing',
'std' => ASSET_PATH . '/assets/img/nothing.svg',
'type' => 'upload',
);
$options[] = array(
'name' => __('文章配置', 'kratos'),
'type' => 'heading',
);
$options[] = array(
'name' => __('文章打赏', 'kratos'),
'desc' => __('开启文章页面打赏功能', 'kratos'),
'id' => 'g_donate',
'type' => 'checkbox',
);
$options[] = array(
'name' => __('支付宝二维码', 'kratos'),
'id' => 'g_donate_alipay',
'std' => ASSET_PATH . '/assets/img/donate.png',
'type' => 'upload',
'class' => 'hidden',
'type' => 'upload',
);
$options[] = array(
'name' => __('微信二维码', 'kratos'),
'id' => 'g_donate_wechat',
'std' => ASSET_PATH . '/assets/img/donate.png',
'type' => 'upload',
'class' => 'hidden',
'type' => 'upload',
);
$options[] = array(
'name' => __('页面布局', 'kratos'),
'desc' => __('是否显示侧边栏小工具(默认显示侧边栏),仅在文章页面生效', 'kratos'),
'id' => "g_article_widgets",
'std' => "two_side",
'type' => "images",
'options' => array(
'one_side' => $imagepath . 'col-12.png',
'two_side' => $imagepath . 'col-8.png')
);
$options[] = array(
'name' => __('站长配置', 'kratos'),
'type' => 'heading',
);
$options[] = array(
'name' => __('个人头像', 'kratos'),
'id' => 'a_gravatar',
'std' => ASSET_PATH . '/assets/img/gravatar.png',
'type' => 'upload',
);
$options[] = array(
'name' => __('个人昵称', 'kratos'),
'id' => 'a_nickname',
'std' => 'Kratos',
'type' => 'text',
);
$options[] = array(
'name' => __('个人简介', 'kratos'),
'std' => __('保持饥渴的专注,追求最佳的品质', 'kratos'),
'id' => 'a_about',
'type' => 'textarea',
);
$options[] = array(
'name' => __('邮件配置', 'kratos'),
'type' => 'heading',
);
$options[] = array(
'name' => __('SMTP 服务', 'kratos'),
'desc' => __('开启 SMTP 服务功能', 'kratos'),
'id' => 'm_smtp',
'type' => 'checkbox',
);
$options[] = array(
'name' => __('邮件服务器', 'kratos'),
'desc' => __('填写发件服务器地址', 'kratos'),
'id' => 'm_host',
'class' => 'hidden',
'type' => 'text',
);
$options[] = array(
'name' => __('服务器端口', 'kratos'),
'desc' => __('填写发件服务器端口', 'kratos'),
'id' => 'm_port',
'class' => 'hidden',
'type' => 'text',
);
$options[] = array(
'name' => __('授权方式', 'kratos'),
'desc' => __('填写登录鉴权的方式,ssl 或 tls', 'kratos'),
'id' => 'm_sec',
'class' => 'hidden',
'type' => 'text',
);
$options[] = array(
'name' => __('邮箱帐号', 'kratos'),
'desc' => __('填写邮箱账号', 'kratos'),
'id' => 'm_username',
'class' => 'hidden',
'type' => 'text',
);
$options[] = array(
'name' => __('邮箱密码', 'kratos'),
'desc' => __('填写邮箱密码', 'kratos'),
'id' => 'm_passwd',
'class' => 'hidden',
'type' => 'password',
);
$options[] = array(
'id' => 'm_sendmail',
'class' => 'hidden',
'type' => 'sendmail',
);
$options[] = array(
'name' => __('顶部配置', 'kratos'),
'type' => 'heading',
);
$options[] = array(
'name' => __( '顶部样式', 'kratos' ),
'desc' => __('请选择顶部样式(颜色导航或图片导航)', 'kratos'),
'id' => 'top_select',
'std' => 'banner',
'type' => 'select',
'options' => $top_array
);
$options[] = array(
'name' => __('颜色导航', 'kratos'),
'id' => 'top_color',
'std' => '#24292e',
'class' => 'hidden',
'type' => 'color',
);
$options[] = array(
'name' => __('图片导航', 'kratos'),
'id' => 'top_img',
'std' => ASSET_PATH . '/assets/img/background.png',
'class' => 'hidden',
'type' => 'upload',
);
$options[] = array(
'name' => __('副标题', 'kratos'),
'id' => 'top_title',
'std' => 'Kratos',
'class' => 'hidden',
'type' => 'text',
);
$options[] = array(
'name' => __('标题描述', 'kratos'),
'std' => __('一款专注于用户阅读体验的响应式博客主题', 'kratos'),
'id' => 'top_describe',
'class' => 'hidden',
'type' => 'text',
);
$options[] = array(
'name' => __('页脚配置', 'kratos'),
'type' => 'heading',
);
$options[] = array(
'name' => __('工信部备案信息', 'kratos'),
'id' => 's_icp',
'placeholder' => __('例如:京ICP证xxxxxx号', 'kratos'),
'type' => 'text',
);
$options[] = array(
'name' => __('公安网备案信息', 'kratos'),
'id' => 's_gov',
'placeholder' => __('例如:京公网安备 xxxxxxxxxxxx号', 'kratos'),
'type' => 'text',
);
$options[] = array(
'name' => __('公安网备案连接', 'kratos'),
'id' => 's_gov_link',
'placeholder' => __('例如:http://www.beian.gov.cn/portal/registerSystemInfo?recordcode=xxxxx', 'kratos'),
'type' => 'text',
);
$options[] = array(
'name' => __('版权信息', 'kratos'),
'id' => 's_copyright',
'std' => 'COPYRIGHT © 2020 ' . $sitename . '. ALL RIGHTS RESERVED.',
'type' => 'textarea',
);
$options[] = array(
'name' => __('自定义代码', 'kratos'),
'type' => 'heading',
);
$options[] = array(
'name' => __('自定义 CSS', 'kratos'),
'desc' => __('附加样式,在所有主题样式之后加载。保存后立即生效,随主题升级保留。', 'kratos'),
'id' => 'g_custom_css',
'std' => yang_default_custom_css(),
'type' => 'code',
'settings' => array('rows' => 14),
);
$options[] = array(
'name' => __('自定义 JS', 'kratos'),
'desc' => __('附加脚本,在页面底部加载,不需要写 &lt;script&gt; 标签。', 'kratos'),
'id' => 'g_custom_js',
'std' => '',
'type' => 'code',
'settings' => array('rows' => 14),
);
return $options;
}