v2.0.40-20230916

This commit is contained in:
MI15\Win
2023-09-16 23:26:09 +08:00
parent cdeea3ff36
commit 06eb605e9a
37 changed files with 162 additions and 2783 deletions

View File

@@ -88,102 +88,6 @@ if($page == 'config_home'){
exit;
}
//主题设置页面
if( $page == 'theme_home' || $page == 'theme_login' || $page == 'theme_transit' || $page == 'theme_register' || $page == 'theme_guide' || $page == 'theme_article') {
if(!check_purview('theme_in',1)){
require(DIR.'/templates/admin/page/404.php');
exit;
}
$fn = str_replace('theme_','',$page);
$dirs = get_dir_list(DIR.'/templates/'.$fn);
foreach ($dirs as $dir) {
$path = DIR.'/templates/'.$fn.'/'.$dir; //目录完整路径
//没有信息文件则跳过
if(!is_file($path.'/info.json') ) {continue;}
//读取主题信息
$themes[$dir]['info'] = json_decode(@file_get_contents($path.'/info.json'),true);
//是否支持配置
$themes[$dir]['info']['config'] = is_file($path.'/config.php') ? '1':'0';
//预览图优先顺序:png>jpg>info>default
if(is_file($path.'/screenshot.jpg')){
$themes[$dir]['info']['screenshot'] = "./templates/$fn/$dir/screenshot.jpg";
}elseif(is_file($path.'/screenshot.png')){
$themes[$dir]['info']['screenshot'] = "./templates/$fn/$dir/screenshot.png";
}elseif(empty($themes[$dir]['info']['screenshot'])){
$themes[$dir]['info']['screenshot'] = "./templates/admin/static/42ed3ef2c4a50f6d.png";
}
}
//获取当前主题
require "./system/templates.php";
//在线主题处理
if ( !$global_config['offline'] && $USER_DB['UserGroup'] === 'root'){
if(preg_match('/^v.+-(\d{8})$/i',SysVer,$matches)){
$sysver = intval( $matches[1] );//取版本中的日期
}else{
exit("获取程序版本异常");
}
//读取缓存
$template = get_db('global_config','v',['k'=>$page.'_cache']);
if(!empty($template)){
$data = json_decode($template, true);
}
//没有缓存 或 禁止缓存 或 缓存过时
if(empty($template) || $_GET['cache'] === 'no' || time() - $data["time"] > 1800 ){
$urls = [
"lm21" => "https://update.lm21.top/TwoNav/{$fn}_template.json",
"gitee" => "https://gitee.com/tznb/twonav_updata/raw/master/{$fn}_template.json"
];
$Source = $global_config['Update_Source'] ?? '';
if (!empty($Source) && isset($urls[$Source])) {
$urls = [$Source => $urls[$Source]];
}
}else{
$cache = true;
}
//读取超时参数
$overtime = !isset($global_config['Update_Overtime']) ? 3 : ($global_config['Update_Overtime'] < 3 || $global_config['Update_Overtime'] > 60 ? 3 : $global_config['Update_Overtime']);
//远程获取
foreach($urls as $key => $url){
$Res = ccurl($url,$overtime);
$data = json_decode($Res["content"], true);
if($data["code"] == 200 ){ //如果获取成功
$data["time"] = time(); //记录当前时间
write_global_config($page.'_cache',json_encode($data),$fn.'_模板缓存');
break; //跳出循环.
}
}
//解析
foreach($data["data"] as $key){
$path = DIR.'/templates/'.$fn.'/'.$key["dir"];
if( is_dir($path) ) { //本地存在
$value = $key["dir"];
//检查是否可以更新
$update = str_replace('/','',$themes[$value]['info']['update']); //本地主题版本
$update_new = str_replace('/','',$key["update"]); //远程主题版本
if( $sysver >= intval($key["low"]) && $sysver <= intval($key["high"]) && $update < $update_new ){
$themes[$value]['info']['up'] = '1';
}
}else{
//判断是否适配当前系统版本
if( $sysver >= intval($key["low"]) && $sysver <= intval($key["high"]) ){
$value = $key["dir"];
$themes[$value]['info'] = json_decode(json_encode($key),true);
}
}
}
//来源策略 (用于Gitee作为图床反防盗链)
if(!empty($data['referrer'])){
define('referrer',$data['referrer']);
}
}
}
//不带参数是载入框架
if(empty($page)){
$site = unserialize(get_db('user_config','v',['uid'=>UID,'k'=>'s_site']));