Skip to content

Commit

Permalink
修改版本号获取逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
zhheo committed Jan 8, 2025
1 parent 9e62f7c commit f58f764
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ function themeConfig($form)
}
$data = json_decode(file_get_contents('https://plog.zhheo.com/usr/themes/TimePlus/releases.json'), true);
$message = $data['tag_name'];
//当前版本号
$selfmessage = '2.10';

// 从 index.php 中获取版本号
$theme_info = get_theme_info();
$selfmessage = $theme_info['version'];

if ($selfmessage == $message) {
echo 'TimePlus&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp当前版本:' . 'v' . $selfmessage . "&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp" . '最新版本:' . 'v' . $message;
} else if ($selfmessage > $message) {
Expand Down Expand Up @@ -63,3 +66,18 @@ function themeFields($layout)
$location = new Typecho_Widget_Helper_Form_Element_Text('location', NULL, NULL, _t('拍摄地点'), _t('请输入拍摄地点信息'));
$layout->addItem($location);
}

// 添加获取主题信息的函数
function get_theme_info() {
$index_file = __DIR__ . '/index.php';
if (!file_exists($index_file)) {
return ['version' => '0.0'];
}

$content = file_get_contents($index_file);
preg_match('/@version\s+(.*)/', $content, $matches);

return [
'version' => isset($matches[1]) ? trim($matches[1]) : '0.0'
];
}

0 comments on commit f58f764

Please sign in to comment.