Files
wordpress-kratos-yang/functions.php
T
laoyang 7125fdd3ce feat(lightbox): 正文图片点击在当前页放大、多图轮播、键盘切换
新增主题自带的图片灯箱,替代「点图片跳新标签页」的旧行为,
不再依赖第三方灯箱插件。

主要能力
· 正文里的图片链接改写成「在当前页覆盖展示原图」,不跳转
· 原图优先按附件 ID 取 full size(wp_get_attachment_image_src),
  取不到才退回 href 自己 —— 不在前端从缩略图文件名反推原图地址
· 原图地址写在 href 里而不是 data-full:主题的 CDN 是整页输出缓冲
  改写,只认 src= / href= 与 CSS url(),写 data-* 会绕回源站
· 多图左右箭头轮播(到头循环),键盘 ←↑ / →↓ 切换、Esc 关闭、
  Home / End 跳首尾,点空白关闭,打开时锁滚动并在关闭后归还焦点
· 两套遮罩配色(白色默认 / 深色)与九档不透明度(默认 80%)
· 图片本身始终保持不透明:透明度只作用在遮罩底色上

兼容性处理
· 剥掉第三方灯箱插件留下的触发属性(data-rel / data-imagelightbox /
  data-rl_title 等)。线上实测 100 篇文章 112 张图**全部**带这些属性,
  若只「让给插件」则主题灯箱永不生效;同时关掉开关时一律不动,
  插件可照常工作
· 移除 imgnofollow() 给图片链接加的 target="_blank" 与 rel,
  链接不再承担跳转职责
· 无 JS 时 href 仍在,右键「在新标签页打开图片」照常可用

可读性
· 半透明遮罩下底部说明条自带更实的底(≥0.9),并按「遮罩底下是
  纯黑」的最坏情况验证文字对比度 ≥ 4.5:1
· 行内不透明度样式用 [data-theme] 选择器,避免被样式表默认值压掉
  (裸类名优先级不足,会让深色配色下透明度静默失效)

验证
· 服务端正文改写探针 51 通过 / 0 失败(PHP 8.4 与 8.5)
· 浏览器真实交互探针 200 通过 / 0 失败(两配色 × 80%,含 50%/100%)
· 上述两者的反向验证 21 项注入全部按预期捕获
· 三个改动文件 php -l 通过

Refs #10
2026-10-25 22:05:24 +08:00

86 lines
3.5 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
/**
* 模板函数
* @author Yongquan Yang <yangyq.net>
* @license MIT License
* @version 2020.03.17
*/
define('THEME_VERSION', wp_get_theme()->get('Version'));
// 主题配置
require get_template_directory() . '/inc/options-framework/autoload.php';
// 自定义代码(CSS / JS,存选项表而非主题目录)
require get_template_directory() . '/inc/theme-custom-code.php';
// 更新配置
require get_template_directory() . '/inc/update-checker/autoload.php';
// 核心配置
require get_template_directory() . '/inc/theme-core.php';
// 图片类选项的默认值(Logo/favicon/404/分享图… 空值时落到包内默认图)。
// 必须排在 theme-core.php 之后:它要用 ASSET_PATH 与 kratos_option。
require get_template_directory() . '/inc/theme-option-defaults.php';
// 站点配置
require get_template_directory() . '/inc/theme-setting.php';
// 纪念日自动哀悼(按日期判断,需在 theme-setting 之后,
// 因为它用到 kratos_option)
require get_template_directory() . '/inc/theme-mourning.php';
// 哀悼说明页(固定路径 /memory,由主题判定路由,不写数据库)
require get_template_directory() . '/inc/theme-mourning-page.php';
// 文章配置
require get_template_directory() . '/inc/theme-article.php';
// 评论区(统一渲染 + AJAX + 评论通知)。
// 必须在 theme-article.php 之后:后者不再定义评论函数,
// 但评论模板 comments.php 里引用的 comment_callbacks 由本文件提供。
// 也必须早于 theme-mail.php(评论通知要调 yang_mail_render)。
require get_template_directory() . '/inc/theme-comments.php';
// 小工具配置
require get_template_directory() . '/inc/theme-widgets.php';
// 文章增强
require get_template_directory() . '/inc/theme-shortcode.php';
// 文章目录([TOC] 短代码)
require get_template_directory() . '/inc/theme-toc.php';
// 添加导航目录
require get_template_directory() . '/inc/theme-navwalker.php';
// 对象存储配置
require get_template_directory() . '/inc/theme-dogecloud.php';
// CDN 加速(地址改写:CDN 地址 + 白名单 + 黑名单)。
// 必须排在 theme-core.php 之后:它要用 kratos_option 与 wp_parse_url。
// 挂在 template_redirect 上开输出缓冲,所以本文件晚加载不影响生效。
require get_template_directory() . '/inc/theme-cdn.php';
// 自动头像:为没有头像的访客按邮箱生成一张(纯 PHP,零外网请求)。
// 必须排在 theme-core.php 之后:它要用 kratos_option。
// 它挂在 get_avatar 过滤器上(优先级 20,晚于 theme-core.php 里
// 那个改 Gravatar 域名的过滤器),所以要保证 theme-core.php 先加载。
require get_template_directory() . '/inc/theme-avatar.php';
// 图片灯箱:正文图片点击在当前页放大、多图轮播、键盘切换。
// 必须排在 theme-core.php 之后:它要用 ASSET_PATH 与 THEME_VERSION。
// 必须排在 theme-article.php 之后:它挂在 the_content 优先级 20,
// 要去掉 imgnofollow()(优先级 10)给图片链接加的 target="_blank"。
require get_template_directory() . '/inc/theme-lightbox.php';
// 邮件模板:必须先于 theme-mail.php 加载,
// 因为后者在发信时会调用 yang_mail_render()
require get_template_directory() . '/inc/theme-mail-template.php';
// 邮件治理:统一接管发信通道、去重、关掉重复通知
require get_template_directory() . '/inc/theme-mail.php';
// SMTP 配置(连通性相关,实际接管在 theme-mail.php)
require get_template_directory() . '/inc/theme-smtp.php';