From b941f0a3e439ffb5c0968cd729267e21a4f50cba Mon Sep 17 00:00:00 2001 From: Karson Date: Fri, 6 Apr 2018 21:39:12 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=8F=92=E4=BB=B6=E5=88=86?= =?UTF-8?q?=E7=B1=BB=E3=80=81=E5=85=8D=E8=B4=B9=E6=8F=92=E4=BB=B6=E6=90=9C?= =?UTF-8?q?=E7=B4=A2=20=E6=96=B0=E5=A2=9E=E5=85=A8=E5=B1=80=E7=9A=84Templa?= =?UTF-8?q?te=20=E6=96=B0=E5=A2=9E=E8=87=AA=E5=AE=9A=E4=B9=89=E9=80=9A?= =?UTF-8?q?=E7=94=A8=E6=90=9C=E7=B4=A2=E8=A1=A8=E5=8D=95=E5=86=85=E5=AE=B9?= =?UTF-8?q?=20=E6=96=B0=E5=A2=9E=E9=80=9A=E7=94=A8=E6=90=9C=E7=B4=A2?= =?UTF-8?q?=E6=8C=89=E9=92=AE=E6=98=BE=E7=A4=BA=E9=85=8D=E7=BD=AE=20?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=8D=95=E7=8B=AC=E6=B8=85=E9=99=A4=E6=A8=A1?= =?UTF-8?q?=E6=9D=BF=E3=80=81=E6=8F=92=E4=BB=B6=E7=BC=93=E5=AD=98=20?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=90=8E=E5=8F=B0=E7=99=BB=E5=BD=95=E5=A4=B1?= =?UTF-8?q?=E8=B4=A5=E9=87=8D=E8=AF=95=E9=85=8D=E7=BD=AE=20=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E9=80=9A=E7=94=A8=E6=90=9C=E7=B4=A2,=E6=90=9C?= =?UTF-8?q?=E7=B4=A2=E5=85=83=E7=B4=A0=E6=94=AF=E6=8C=81=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E7=BB=91=E5=AE=9A=E5=85=83=E7=B4=A0=E4=BA=8B=E4=BB=B6=20?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=9C=AC=E5=9C=B0=E6=8F=92=E4=BB=B6=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=20=E4=BC=98=E5=8C=96=E5=89=8D=E5=8F=B0=E9=A6=96?= =?UTF-8?q?=E9=A1=B5=E5=92=8CAPI=E6=96=87=E6=A1=A3=E5=AD=97=E4=BD=93?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=20=E4=BF=AE=E5=A4=8D=E5=85=83=E7=B4=A0?= =?UTF-8?q?=E9=AA=8C=E8=AF=81=E6=8C=87=E5=AE=9Adata-target=E4=B8=8D?= =?UTF-8?q?=E7=94=9F=E6=95=88=E7=9A=84BUG=20=E4=BF=AE=E5=A4=8D=E6=8F=92?= =?UTF-8?q?=E4=BB=B6=E5=91=BD=E4=BB=A4=E8=A1=8C=E6=B7=BB=E5=8A=A0--force?= =?UTF-8?q?=E4=B8=8D=E7=94=9F=E6=95=88=E7=9A=84BUG=20=E4=BF=AE=E5=A4=8DnoN?= =?UTF-8?q?eedLogin=E5=92=8CnoNeedRight=E5=A4=A7=E5=B0=8F=E5=86=99?= =?UTF-8?q?=E7=9A=84BUG=20=E4=BF=AE=E5=A4=8Dfieldlist=E6=97=A0=E6=B3=95?= =?UTF-8?q?=E6=8C=BA=E6=8B=BD=E7=9A=84BUG=20=E4=BF=AE=E5=A4=8D=E4=B8=80?= =?UTF-8?q?=E9=94=AECRUD=E5=90=8E=E6=8C=87=E5=AE=9A=E5=AD=97=E6=AE=B5?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E5=90=8E=E6=97=A0=E6=B3=95=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E5=85=B3=E8=81=94=E6=95=B0=E6=8D=AE=E7=9A=84BUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/admin/command/Addon.php | 208 +- .../admin/command/Api/template/index.html | 10 +- application/admin/command/Crud.php | 12 +- application/admin/controller/Addon.php | 216 +- application/admin/controller/Ajax.php | 100 +- application/admin/lang/zh-cn/addon.php | 2 + application/admin/lang/zh-cn/index.php | 4 + application/admin/library/Auth.php | 7 +- application/admin/view/addon/config.html | 13 +- application/admin/view/addon/index.html | 95 +- application/admin/view/common/header.html | 26 +- application/admin/view/index/login.html | 4 +- application/common/controller/Backend.php | 3 +- application/common/library/Auth.php | 2 + application/common/model/Category.php | 7 + application/config.php | 16 +- public/api.html | 12 +- public/assets/css/backend.css | 4 +- public/assets/css/backend.min.css | 2 +- public/assets/css/index.css | 5 +- public/assets/js/backend.js | 15 +- public/assets/js/backend/addon.js | 52 +- public/assets/js/backend/index.js | 3 +- .../assets/js/bootstrap-table-commonsearch.js | 161 +- public/assets/js/frontend.js | 4 +- public/assets/js/require-backend.min.js | 3849 +++++------------ public/assets/js/require-form.js | 19 +- public/assets/js/require-frontend.min.js | 6 +- public/assets/less/backend.less | 4 + 29 files changed, 1581 insertions(+), 3280 deletions(-) diff --git a/application/admin/command/Addon.php b/application/admin/command/Addon.php index e2cde5fe..302ced6f 100644 --- a/application/admin/command/Addon.php +++ b/application/admin/command/Addon.php @@ -19,14 +19,14 @@ class Addon extends Command protected function configure() { $this - ->setName('addon') - ->addOption('name', 'a', Option::VALUE_REQUIRED, 'addon name', null) - ->addOption('action', 'c', Option::VALUE_REQUIRED, 'action(create/enable/disable/install/uninstall/refresh/upgrade/package)', 'create') - ->addOption('force', 'f', Option::VALUE_OPTIONAL, 'force override', null) - ->addOption('release', 'r', Option::VALUE_OPTIONAL, 'addon release version', null) - ->addOption('uid', 'u', Option::VALUE_OPTIONAL, 'fastadmin uid', null) - ->addOption('token', 't', Option::VALUE_OPTIONAL, 'fastadmin token', null) - ->setDescription('Addon manager'); + ->setName('addon') + ->addOption('name', 'a', Option::VALUE_REQUIRED, 'addon name', null) + ->addOption('action', 'c', Option::VALUE_REQUIRED, 'action(create/enable/disable/install/uninstall/refresh/upgrade/package)', 'create') + ->addOption('force', 'f', Option::VALUE_OPTIONAL, 'force override', null) + ->addOption('release', 'r', Option::VALUE_OPTIONAL, 'addon release version', null) + ->addOption('uid', 'u', Option::VALUE_OPTIONAL, 'fastadmin uid', null) + ->addOption('token', 't', Option::VALUE_OPTIONAL, 'fastadmin token', null) + ->setDescription('Addon manager'); } protected function execute(Input $input, Output $output) @@ -44,12 +44,10 @@ class Addon extends Command include dirname(__DIR__) . DS . 'common.php'; - if (!$name) - { + if (!$name) { throw new Exception('Addon name could not be empty'); } - if (!$action || !in_array($action, ['create', 'disable', 'enable', 'install', 'uninstall', 'refresh', 'upgrade', 'package'])) - { + if (!$action || !in_array($action, ['create', 'disable', 'enable', 'install', 'uninstall', 'refresh', 'upgrade', 'package'])) { throw new Exception('Please input correct action name'); } @@ -57,17 +55,14 @@ class Addon extends Command Db::execute("SELECT 1"); $addonDir = ADDON_PATH . $name . DS; - switch ($action) - { + switch ($action) { case 'create': //非覆盖模式时如果存在则报错 - if (is_dir($addonDir) && !$force) - { + if (is_dir($addonDir) && !$force) { throw new Exception("addon already exists!\nIf you need to create again, use the parameter --force=true "); } //如果存在先移除 - if (is_dir($addonDir)) - { + if (is_dir($addonDir)) { rmdirs($addonDir); } mkdir($addonDir); @@ -76,16 +71,12 @@ class Addon extends Command $createMenu = $this->getCreateMenu($menuList); $prefix = Config::get('database.prefix'); $createTableSql = ''; - try - { + try { $result = Db::query("SHOW CREATE TABLE `" . $prefix . $name . "`;"); - if (isset($result[0]) && isset($result[0]['Create Table'])) - { + if (isset($result[0]) && isset($result[0]['Create Table'])) { $createTableSql = $result[0]['Create Table']; } - } - catch (PDOException $e) - { + } catch (PDOException $e) { } @@ -102,8 +93,7 @@ class Addon extends Command $this->writeToFile("config", $data, $addonDir . 'config.php'); $this->writeToFile("info", $data, $addonDir . 'info.ini'); $this->writeToFile("controller", $data, $addonDir . 'controller' . DS . 'Index.php'); - if ($createTableSql) - { + if ($createTableSql) { $createTableSql = str_replace("`" . $prefix, '`__PREFIX__', $createTableSql); file_put_contents($addonDir . 'install.sql', $createTableSql); } @@ -112,75 +102,61 @@ class Addon extends Command break; case 'disable': case 'enable': - try - { + try { //调用启用、禁用的方法 Service::$action($name, 0); - } - catch (AddonException $e) - { - if ($e->getCode() != -3) - { + } catch (AddonException $e) { + if ($e->getCode() != -3) { throw new Exception($e->getMessage()); } - //如果有冲突文件则提醒 - $data = $e->getData(); - foreach ($data['conflictlist'] as $k => $v) - { - $output->warning($v); - } - $output->info("Are you sure you want to " . ($action == 'enable' ? 'override' : 'delete') . " all those files? Type 'yes' to continue: "); - $line = fgets(STDIN); - if (trim($line) != 'yes') - { - throw new Exception("Operation is aborted!"); + if (!$force) { + //如果有冲突文件则提醒 + $data = $e->getData(); + foreach ($data['conflictlist'] as $k => $v) { + $output->warning($v); + } + $output->info("Are you sure you want to " . ($action == 'enable' ? 'override' : 'delete') . " all those files? Type 'yes' to continue: "); + $line = fgets(STDIN); + if (trim($line) != 'yes') { + throw new Exception("Operation is aborted!"); + } } //调用启用、禁用的方法 Service::$action($name, 1); - } - catch (Exception $e) - { + } catch (Exception $e) { throw new Exception($e->getMessage()); } $output->info(ucfirst($action) . " Successed!"); break; case 'install': //非覆盖模式时如果存在则报错 - if (is_dir($addonDir) && !$force) - { + if (is_dir($addonDir) && !$force) { throw new Exception("addon already exists!\nIf you need to install again, use the parameter --force=true "); } //如果存在先移除 - if (is_dir($addonDir)) - { + if (is_dir($addonDir)) { rmdirs($addonDir); } - try - { + try { Service::install($name, 0, ['version' => $release]); - } - catch (AddonException $e) - { - if ($e->getCode() != -3) - { + } catch (AddonException $e) { + if ($e->getCode() != -3) { throw new Exception($e->getMessage()); } - //如果有冲突文件则提醒 - $data = $e->getData(); - foreach ($data['conflictlist'] as $k => $v) - { - $output->warning($v); - } - $output->info("Are you sure you want to override all those files? Type 'yes' to continue: "); - $line = fgets(STDIN); - if (trim($line) != 'yes') - { - throw new Exception("Operation is aborted!"); + if (!$force) { + //如果有冲突文件则提醒 + $data = $e->getData(); + foreach ($data['conflictlist'] as $k => $v) { + $output->warning($v); + } + $output->info("Are you sure you want to override all those files? Type 'yes' to continue: "); + $line = fgets(STDIN); + if (trim($line) != 'yes') { + throw new Exception("Operation is aborted!"); + } } Service::install($name, 1, ['version' => $release, 'uid' => $uid, 'token' => $token]); - } - catch (Exception $e) - { + } catch (Exception $e) { throw new Exception($e->getMessage()); } @@ -188,36 +164,29 @@ class Addon extends Command break; case 'uninstall': //非覆盖模式时如果存在则报错 - if (!$force) - { + if (!$force) { throw new Exception("If you need to uninstall addon, use the parameter --force=true "); } - try - { + try { Service::uninstall($name, 0); - } - catch (AddonException $e) - { - if ($e->getCode() != -3) - { + } catch (AddonException $e) { + if ($e->getCode() != -3) { throw new Exception($e->getMessage()); } - //如果有冲突文件则提醒 - $data = $e->getData(); - foreach ($data['conflictlist'] as $k => $v) - { - $output->warning($v); - } - $output->info("Are you sure you want to delete all those files? Type 'yes' to continue: "); - $line = fgets(STDIN); - if (trim($line) != 'yes') - { - throw new Exception("Operation is aborted!"); + if (!$force) { + //如果有冲突文件则提醒 + $data = $e->getData(); + foreach ($data['conflictlist'] as $k => $v) { + $output->warning($v); + } + $output->info("Are you sure you want to delete all those files? Type 'yes' to continue: "); + $line = fgets(STDIN); + if (trim($line) != 'yes') { + throw new Exception("Operation is aborted!"); + } } Service::uninstall($name, 1); - } - catch (Exception $e) - { + } catch (Exception $e) { throw new Exception($e->getMessage()); } @@ -233,53 +202,44 @@ class Addon extends Command break; case 'package': $infoFile = $addonDir . 'info.ini'; - if (!is_file($infoFile)) - { + if (!is_file($infoFile)) { throw new Exception(__('Addon info file was not found')); } $info = get_addon_info($name); - if (!$info) - { + if (!$info) { throw new Exception(__('Addon info file data incorrect')); } $infoname = isset($info['name']) ? $info['name'] : ''; - if (!$infoname || !preg_match("/^[a-z]+$/i", $infoname) || $infoname != $name) - { + if (!$infoname || !preg_match("/^[a-z]+$/i", $infoname) || $infoname != $name) { throw new Exception(__('Addon info name incorrect')); } $infoversion = isset($info['version']) ? $info['version'] : ''; - if (!$infoversion || !preg_match("/^\d+\.\d+\.\d+$/i", $infoversion)) - { + if (!$infoversion || !preg_match("/^\d+\.\d+\.\d+$/i", $infoversion)) { throw new Exception(__('Addon info version incorrect')); } $addonTmpDir = RUNTIME_PATH . 'addons' . DS; - if (!is_dir($addonTmpDir)) - { + if (!is_dir($addonTmpDir)) { @mkdir($addonTmpDir, 0755, true); } $addonFile = $addonTmpDir . $infoname . '-' . $infoversion . '.zip'; - if (!class_exists('ZipArchive')) - { + if (!class_exists('ZipArchive')) { throw new Exception(__('ZinArchive not install')); } $zip = new \ZipArchive; $zip->open($addonFile, \ZipArchive::CREATE | \ZipArchive::OVERWRITE); $files = new \RecursiveIteratorIterator( - new \RecursiveDirectoryIterator($addonDir), \RecursiveIteratorIterator::LEAVES_ONLY + new \RecursiveDirectoryIterator($addonDir), \RecursiveIteratorIterator::LEAVES_ONLY ); - foreach ($files as $name => $file) - { - if (!$file->isDir()) - { + foreach ($files as $name => $file) { + if (!$file->isDir()) { $filePath = $file->getRealPath(); $relativePath = substr($filePath, strlen($addonDir)); - if (!in_array($file->getFilename(), ['.git', '.DS_Store', 'Thumbs.db'])) - { + if (!in_array($file->getFilename(), ['.git', '.DS_Store', 'Thumbs.db'])) { $zip->addFile($filePath, $relativePath); } } @@ -301,22 +261,18 @@ class Addon extends Command protected function getCreateMenu($menu) { $result = []; - foreach ($menu as $k => & $v) - { + foreach ($menu as $k => & $v) { $arr = [ 'name' => $v['name'], 'title' => $v['title'], ]; - if ($v['icon'] != 'fa fa-circle-o') - { + if ($v['icon'] != 'fa fa-circle-o') { $arr['icon'] = $v['icon']; } - if ($v['ismenu']) - { + if ($v['ismenu']) { $arr['ismenu'] = $v['ismenu']; } - if (isset($v['childlist']) && $v['childlist']) - { + if (isset($v['childlist']) && $v['childlist']) { $arr['sublist'] = $this->getCreateMenu($v['childlist']); } $result[] = $arr; @@ -334,16 +290,14 @@ class Addon extends Command protected function writeToFile($name, $data, $pathname) { $search = $replace = []; - foreach ($data as $k => $v) - { + foreach ($data as $k => $v) { $search[] = "{%{$k}%}"; $replace[] = $v; } $stub = file_get_contents($this->getStub($name)); $content = str_replace($search, $replace, $stub); - if (!is_dir(dirname($pathname))) - { + if (!is_dir(dirname($pathname))) { mkdir(strtolower(dirname($pathname)), 0755, true); } return file_put_contents($pathname, $content); diff --git a/application/admin/command/Api/template/index.html b/application/admin/command/Api/template/index.html index aaa73b3d..1fc0b185 100755 --- a/application/admin/command/Api/template/index.html +++ b/application/admin/command/Api/template/index.html @@ -9,7 +9,15 @@ {$config.title}
- {:build_heading()} +
+ {:build_heading(null,FALSE)} + + +
@@ -27,10 +52,11 @@ @@ -44,6 +70,55 @@
+