Browse Source

Merge pull request #248 from helloxz/dev

修复主题无法删除
main 1.3.1
xiaoz 2 days ago committed by GitHub
parent
commit
4a79e44b96
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 1
      .gitignore
  2. 54
      class/Api.php
  3. 2
      version.txt

1
.gitignore vendored

@ -1,3 +1,4 @@
class/cache class/cache
data/config.php data/config.php
data/onenav.db3 data/onenav.db3
templates/BookNest

54
class/Api.php

@ -1871,14 +1871,25 @@ class Api {
} }
//查询当前使用中的主题 //查询当前使用中的主题
$current_theme = $this->db->get('on_options','value',[ 'key' => "theme" ]); $current_theme = $this->db->get('on_options','value',[ 'key' => "theme" ]);
//前台实际使用 s_themes 区分 PC/手机主题,这里一并检查
$themes_json = $this->db->get('on_options','value',[ 'key' => "s_themes" ]);
$themes = is_string($themes_json) ? json_decode($themes_json, true) : [];
$in_use = ( $current_theme == $name )
|| ( is_array($themes) && (
(($themes['pc_theme'] ?? '') === $name) ||
(($themes['mobile_theme'] ?? '') === $name)
) );
//如果是当前使用中的主题也不允许删除 //如果是当前使用中的主题也不允许删除
if ( $current_theme == $name ) { if ( $in_use ) {
$this->return_json(-2000,'',"使用中的主题不允许删除!"); $this->return_json(-2000,'',"使用中的主题不允许删除!");
} }
//删除主题 //删除主题,只处理实际存在的目录,避免对不存在的目录调用 opendir/readdir
$this->deldir("templates/".$name); if ( is_dir("templates/".$name) ) {
$this->deldir("templates/".$name);
$this->deldir("data/templates/".$name); }
if ( is_dir("data/templates/".$name) ) {
$this->deldir("data/templates/".$name);
}
//判断主题文件夹是否还存在 //判断主题文件夹是否还存在
if( is_dir("templates/".$name) || is_dir("data/templates/".$name) ) { if( is_dir("templates/".$name) || is_dir("data/templates/".$name) ) {
$this->return_json(-2000,'',"删除失败,可能是权限不足!"); $this->return_json(-2000,'',"删除失败,可能是权限不足!");
@ -1891,26 +1902,33 @@ class Api {
* 删除一个目录 * 删除一个目录
*/ */
protected function deldir($dir) { protected function deldir($dir) {
//目录不存在时直接返回,避免 PHP 8 下 readdir(false) 抛 TypeError
if ( !is_dir($dir) ) {
return false;
}
$dh = opendir($dir);
if ( !$dh ) {
return false;
}
//先删除目录下的文件: //先删除目录下的文件:
$dh=opendir($dir); while ( ($file = readdir($dh)) !== false ) {
while ($file=readdir($dh)) { if ( $file === '.' || $file === '..' ) {
if($file!="." && $file!="..") { continue;
$fullpath=$dir."/".$file; }
if(!is_dir($fullpath)) { $fullpath = $dir.'/'.$file;
unlink($fullpath); if ( is_dir($fullpath) ) {
} else {
$this->deldir($fullpath); $this->deldir($fullpath);
} }
} else {
@unlink($fullpath);
}
} }
closedir($dh); closedir($dh);
//删除当前文件夹: //删除当前文件夹:
if(rmdir($dir)) { return rmdir($dir);
return true;
} else {
return false;
}
} }
/** /**
* 获取主题参数 * 获取主题参数

2
version.txt

@ -1 +1 @@
v1.3.0-20261023 v1.3.1-20261023
Loading…
Cancel
Save