From 577f59708b1c8a993622db99d45516b28fd8c841 Mon Sep 17 00:00:00 2001 From: KasuganoSoras Date: Sun, 16 Sep 2018 21:51:17 +0800 Subject: [PATCH] =?UTF-8?q?v7.3.3199=20=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修改插件加载时搜索目录的方式,同时搜索子目录插件 --- include/core/PHPMC/Main.php | 2 +- include/core/PHPMC/Plugin.php | 38 ++++++++++++++++++++++++++--------- 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/include/core/PHPMC/Main.php b/include/core/PHPMC/Main.php index d6f321c..7ba649d 100644 --- a/include/core/PHPMC/Main.php +++ b/include/core/PHPMC/Main.php @@ -1,7 +1,7 @@ pluginReader("{$realpath}/{$target}"); - $info = json_decode($data, true); - if(!$info) { - PHPMC::Error()->Println("Error when load plugin: " . $file . ": No such plugin info file: " . $target . "
" . $data); + if($file !== "." && $file !== "..") { + if(is_dir("{$realpath}/{$file}/")) { + if(file_exists("{$realpath}/{$file}/{$file}.php") && file_exists("{$realpath}/{$file}/{$file}.json")) { + $files = "{$file}.php"; + $target = pathinfo($files)['filename'] . ".json"; + $data = file_get_contents("{$realpath}/{$file}/{$target}"); + $info = json_decode($data, true); + if(!$info) { + PHPMC::Error()->Println("Error when load plugin: " . $files . ": No such plugin info file: " . $target . "
" . $data); + } + include("{$realpath}/{$file}/{$files}"); + eval('$' . $info['main'] . ' = new ' . $info['main'] . '();'); + eval('$' . $info['main'] . '->onload();'); + } else { + echo "Error: {$realpath}/{$file}/{$file}.php"; + exit; + } + } else { + if(pathinfo($file)['extension'] == "php") { + $target = pathinfo($file)['filename'] . ".json"; + $data = file_get_contents("{$realpath}/{$target}"); + $info = json_decode($data, true); + if(!$info) { + PHPMC::Error()->Println("Error when load plugin: " . $file . ": No such plugin info file: " . $target . "
" . $data); + } + include("{$realpath}/{$file}"); + eval('$' . $info['main'] . ' = new ' . $info['main'] . '();'); + eval('$' . $info['main'] . '->onload();'); + } } - include("{$realpath}/{$file}"); - eval('$' . $info['main'] . ' = new ' . $info['main'] . '();'); - eval('$' . $info['main'] . '->onload();'); } } closedir($handle);