[✌️progress value=75]
(去掉Emoji)
<?php
// 解析进度条短代码
function parseProgressBarShortcode($content) {
return preg_replace_callback('/\[progress\s+value=(\d+)\]/', function ($matches) {
$currentProgress = intval($matches[1]);
$currentProgress = max(0, min(100, $currentProgress)); // 限制范围为 0-100%
// 计算已填充的宽度
$filledWidth = $currentProgress . '%';
// 生成带有文本的进度条
return "
<div style='position: relative; width: 100%; height: 30px; background: #f3f3f3; border-radius: 10px; overflow: hidden; border: 1px solid #ddd;'>
<div style='width: $filledWidth; height: 100%; background: #4caf50; display: flex; align-items: center; justify-content: center;'>
<span style='color: white; font-weight: bold;'>进度: {$currentProgress}%</span>
</div>
</div>
";
}, $content);
}
// 注册短代码解析钩子
Typecho_Plugin::factory('Widget_Abstract_Contents')->contentEx = 'parseProgressBarShortcode';
Typecho_Plugin::factory('Widget_Abstract_Contents')->excerptEx = 'parseProgressBarShortcode';
?>