Files
wordpress-kratos-yang/footer.php
T
laoyang da0d9ae4a1 代码高亮整套自研:10 浅 + 10 深配色、语言标签、评论区贴代码 (#11)
不再依赖第三方高亮插件,全部由主题自己实现。

主题配色(20 套)
- 浅色 10:github / vs / atom-one-light / idea / xcode /
  stackoverflow-light / intellij-light / googlecode / magula / color-brewer
- 深色 10:github-dark / atom-one-dark / monokai / github-dark-dimmed /
  a11y-dark / stackoverflow-dark / night-owl / srcery /
  panda-syntax-dark / tomorrow-night-blue
- 深色卡片带 data-kind="dark",顶栏跟着换深色底
- 只加载当前选中的一套(20 套全加载会让后出现的规则压前面的,
  切换配色容易"看起来没变")

代码语言标签(用户要求:防止复制错语言)
- 作者标了 language-xxx → 实线边框、正体
- 自动识别猜出来的 → 虚线边框、斜体
- 认不出来 → 显示 "—",仍保持虚线斜体(不冒充作者标注)

行号
- 默认关;行号槽在 <pre> 外面,复制天然不带行号
- 改掉原主题的 word-break:break-all(任意字符断行,代码像乱码)
- 归零 hljs 主题自带的 pre code.hljs{padding:1em},
  否则代码被压低 1em、与行号槽错位 15.5px

复制
- 默认开;安全上下文判断 + execCommand 退路(HTTP 下 clipboard 是 undefined)
- 取 textContent 而非 innerHTML
- 默认 opacity:0、hover 显示、触屏覆盖回 1
  (旧写法只在 @media(hover:none) 里写 1,等于空操作)

自动识别
- 做成选项,默认开
- 只对没标语言的块生效;站内实测长块准确率 22%,不能覆盖作者标注

评论区贴代码
- 评论工具条加"代码"按钮 + 29 种语言面板
- kses 放行 pre 并给 pre/code 放开 class
  (WP 默认 pre 整条剥掉、code 属性全清,此前根本贴不了代码)
- 放行 pre 之后 wpautop/wptexturize/make_clickable 自动让路,
  代码里的连续空行、引号、URL 都不会被改写
- comments.js 用占位符保护代码块,避免 walk() 的 /\n{3,}/ 压缩

其它
- 资源版本号改为读主题头,不再写死(写死会导致以后升级后
  浏览器一直用旧缓存,改了 CSS/JS 完全不生效)
- 删除 footer.php 里旧的 Prism 兜底(两套高亮器同页会互相打架)

验收
- 用线上 284 个真实代码块跑产品代码:284/284 全部变卡片,内容丢字 0、双转义 0
- 47 个 text 标记全部映射到 plaintext(hljs 无 text 语言,不映射会静默不上色)
- 80 个裸 <pre>(无 code 子元素)全部覆盖
- 核心纯函数 65/65;核心反向 10/10 变红
- 浏览器端到端 32/32;行号几何逐行对齐偏差 0.00px,几何反向 4/4 变红
- 端到端反向 7/7 变红;语言标签反向 2/2 变红
- 全量 PHP 语法 95 文件 0 错误

发布:走 theme-update 通道(zip + readme + update.json),
未覆盖服务器主题目录;线上主题目录仍是 3.2.41,待后台升级。
2026-10-26 09:00:17 +08:00

90 lines
4.7 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.04.12
*/
?>
<div class="k-footer">
<div class="f-toolbox">
<div class="gotop">
<div class="gotop-btn">
<span class="kicon i-up"></span>
</div>
</div>
<div class="search">
<span class="kicon i-find"></span>
<form class="search-form" role="search" method="get" action="<?php echo home_url('/'); ?>">
<input type="text" name="s" id="search" placeholder="<?php _e('搜点什么呢?', 'kratos'); ?>" style="display:none"/>
</form>
</div>
</div>
<div class="container">
<div class="row">
<div class="col-12 text-center">
<p class="social">
<?php
$social = array('s_sina', 's_bilibili', 's_coding', 's_gitee', 's_twitter', 's_telegram', 's_linkedin', 's_youtube', 's_github', 's_stackflow', 's_email');
foreach ($social as $social) {
if (kratos_option($social)) {
echo '<a target="_blank" rel="nofollow" href="' . kratos_option($social . '_url') . '"><i class="kicon i-' . str_replace("s_", "", $social) . '"></i></a>';
}
}
?>
</p>
<?php
$sitename = get_bloginfo('name');
/* 版权行:优先用后台「页脚配置 - 版权信息」里填的内容。
早先这里是无条件硬编码,后台那个输入框填了也不生效 ——
用户在后台改了、前台毫无变化,是很容易被当成 bug 的
那种"功能失灵"。空值才回退到自动拼的默认文案。 */
$copy = kratos_option('s_copyright', '');
if (!is_string($copy) || trim($copy) === '') {
$copy = 'COPYRIGHT © ' . date('Y') . ' ' . $sitename . ' 版权所有';
}
/* 输出必须转义。这个值是后台管理员填的,但后台账号被盗
或者多人站点里有人权限被降,都会让这里变成注入点;
而且版权行里出现 <b> 之类也只会显示成怪异的样子。
换行保留:用户可能分行写。 */
echo '<p>' . nl2br(esc_html($copy)) . '</p>';
echo '<p>THEME <a href="https://git.yangyq.net/laoyang/wordpress-kratos-yang" target="_blank" rel="nofollow">KRATOS YANG</a> Modified BY <a href="https://yangyq.net" target="_blank" rel="nofollow">老杨</a></p>';
if (kratos_option('s_icp')) {
echo '<p><a href="https://beian.miit.gov.cn/" target="_blank" rel="nofollow">' . kratos_option('s_icp') . '</a></p>';
}
if (kratos_option('s_gov')) {
echo '<p><a href="' . kratos_option('s_gov_link', '#') . '" target="_blank" rel="nofollow" ><i class="police-ico"></i>' . kratos_option('s_gov') . '</a></p>';
}
if (kratos_option('seo_statistical')) {echo '<p>' . kratos_option('seo_statistical') . '</p>';}
/* 国旗:勾了「是否添加国旗」才显示。以前 src 直接取选项,
用户没上传地址就得到 <img src="">,页面上是一个破图图标。
逻辑抽到 yang_flag_block() 里,测试能直接测同一个函数,
不必"照着抄一遍"(抄件永远是对的,模板改坏了也发现不了)。 */
echo yang_flag_block();
?>
</div>
</div>
</div>
</div>
<?php wp_footer(); ?>
<?php
/**
* 这里原来有一段「Prism 代码高亮兜底」。
*
* 3.2.42 起已删除。原因:
* 代码高亮改由主题自研接管(inc/theme-highlight.php + highlight.js 自托管),
* 服务端就把每个 <pre> 规范成了卡片结构,前端 hljs 一次性上色完成。
* Prism 那段留着有两个害处:
* ① 它会对同一批 `<pre><code>` 再扫一遍,把 hljs 已经写好的
* `<span class="hljs-*">` 当文本重新包一层,产出嵌套 span,
* 首尾行高算错、行号对不齐;
* ② Prism 的 autoloader 会去拉 wp-editormd 的语言包,
* 而 wp-editormd 已被关停/可能被删,地址 404 时控制台报错。
*
* ⚠️ 如果将来要恢复 Prism,必须同时关掉 yang_hl_enabled(),
* 两套高亮器不能同时在一页里跑。
*/
?>
</body>
</html>