From 290fe74069d30979d9983585f64ece21c0664845 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E6=99=AF=E7=AB=8B?= Date: Wed, 22 Mar 2017 11:09:04 +0800 Subject: [PATCH] =?UTF-8?q?[=E4=BC=98=E5=8C=96]=E4=BB=A3=E7=A0=81=E6=95=B4?= =?UTF-8?q?=E5=90=88=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/admin/controller/Index.php | 2 +- application/admin/controller/Plugs.php | 2 + application/admin/controller/User.php | 4 +- application/admin/model/Node.php | 47 +++++++++---------- application/admin/view/user.form.html | 2 +- application/admin/view/user.pass.html | 2 +- application/common.php | 3 +- application/extra/view/admin.main.top.html | 9 ++++ extend/controller/BasicAdmin.php | 13 ++--- extend/controller/BasicApi.php | 12 ++--- extend/service/FileService.php | 1 + extend/service/PayService.php | 5 ++ public/static/theme/default/img/login_bg.jpg | Bin 58424 -> 0 bytes vendor/autoload.php | 2 +- vendor/composer/autoload_real.php | 14 +++--- vendor/composer/autoload_static.php | 8 ++-- 16 files changed, 67 insertions(+), 59 deletions(-) delete mode 100644 public/static/theme/default/img/login_bg.jpg diff --git a/application/admin/controller/Index.php b/application/admin/controller/Index.php index e23e4b1fe..06203ff9a 100644 --- a/application/admin/controller/Index.php +++ b/application/admin/controller/Index.php @@ -19,7 +19,7 @@ use controller\BasicAdmin; use library\Data; use library\Tools; use think\Db; -use think\response\View; +use think\View; /** * 后台入口 diff --git a/application/admin/controller/Plugs.php b/application/admin/controller/Plugs.php index d31223923..23ec04295 100644 --- a/application/admin/controller/Plugs.php +++ b/application/admin/controller/Plugs.php @@ -40,6 +40,8 @@ class Plugs extends BasicAdmin { /** * 文件上传 + * @param string $mode + * @return \think\response\View */ public function upfile($mode = 'one') { $types = $this->request->get('type', 'jpg,png'); diff --git a/application/admin/controller/User.php b/application/admin/controller/User.php index 0036b4ad6..6621d7499 100644 --- a/application/admin/controller/User.php +++ b/application/admin/controller/User.php @@ -44,7 +44,7 @@ class User extends BasicAdmin { /** * 授权管理 - * @return type + * @return array|string */ public function auth() { return $this->_form($this->table, 'auth'); @@ -88,7 +88,7 @@ class User extends BasicAdmin { /** * 表单数据默认处理 - * @param type $data + * @param array $data */ public function _form_filter(&$data) { if ($this->request->isPost()) { diff --git a/application/admin/model/Node.php b/application/admin/model/Node.php index d0b83b9a7..ab089d334 100644 --- a/application/admin/model/Node.php +++ b/application/admin/model/Node.php @@ -27,13 +27,12 @@ class Node { /** * 应用用户权限节点 - * @param type $authid * @return bool */ public static function applyAuthNode() { cache('need_access_node', null); if (($authorize = session('user.authorize'))) { - $nodes = (array) Db::name('SystemAuthNode')->where('auth', 'in', explode(',', $authorize))->column('node'); + $nodes = (array)Db::name('SystemAuthNode')->where('auth', 'in', explode(',', $authorize))->column('node'); return session('user.nodes', $nodes); } return false; @@ -58,7 +57,7 @@ class Node { /** * 检查用户节点权限 - * @param string $node + * @param string $node 节点 * @return bool */ public static function checkAuthNode($node) { @@ -69,7 +68,7 @@ class Node { if (!in_array($auth_node, self::getAuthNode())) { return true; } - return in_array($auth_node, (array) session('user.nodes')); + return in_array($auth_node, (array)session('user.nodes')); } /** @@ -77,15 +76,16 @@ class Node { * @return array */ static public function get() { - $data = Db::name('SystemNode')->select(); - $nodes = []; $alias = []; - foreach ($data as $vo) { + foreach (Db::name('SystemNode')->select() as $vo) { $alias["{$vo['node']}"] = $vo; } + $nodes = []; foreach (self::getNodeTree(APP_PATH) as $thr) { - if (stripos($thr, 'admin/plugs') === 0 || stripos($thr, 'admin/login') === 0 || stripos($thr, 'admin/index') === 0 || stripos($thr, 'index') === 0 || stripos($thr, 'store/api') === 0) { - continue; + foreach (['admin/plugs', 'admin/login', 'admin/index', 'store/api', 'index'] as $str) { + if (stripos($thr, $str) === 0) { + continue 2; + } } $tmp = explode('/', $thr); $one = $tmp[0]; @@ -99,26 +99,22 @@ class Node { /** * 获取节点列表 - * @param string $path - * @param array $nodes + * @param string $path 路径 + * @param array $nodes 额外数据 * @return array */ static public function getNodeTree($path, $nodes = []) { - foreach (self::getFilePaths($path) as $vo) { - if (stripos($vo, DS . 'controller' . DS) === false) { + foreach (self::_getFilePaths($path) as $vo) { + if (!preg_match('|/(\w+)/controller/(\w+)|', str_replace(DS, '/', $vo), $matches) || count($matches) !== 3) { continue; } - $_tmp = explode(DS, $vo); - $controllerName = preg_replace('|\.php$|', '', array_pop($_tmp)); - array_pop($_tmp); - $moduleName = array_pop($_tmp); - $className = config('app_namespace') . "\\{$moduleName}\\controller\\{$controllerName}"; + $className = config('app_namespace') . str_replace('/', '\\', $matches[0]); if (!class_exists($className)) { continue; } foreach (get_class_methods($className) as $actionName) { if ($actionName[0] !== '_') { - $nodes[] = strtolower("{$moduleName}/{$controllerName}/{$actionName}"); + $nodes[] = strtolower("{$matches[1]}/{$matches[2]}/{$actionName}"); } } } @@ -127,19 +123,18 @@ class Node { /** * 获取所有PHP文件 - * @param string $path - * @param array $data - * @param string $ext + * @param string $path 目录 + * @param array $data 额外数据 + * @param string $ext 文件后缀 * @return array */ - static private function getFilePaths($path, $data = [], $ext = 'php') { + static private function _getFilePaths($path, $data = [], $ext = 'php') { foreach (scandir($path) as $dir) { if ($dir[0] === '.') { continue; } - $tmp = realpath($path . DS . $dir); - if ($tmp && (is_dir($tmp) || pathinfo($tmp, PATHINFO_EXTENSION) === $ext)) { - is_dir($tmp) ? $data = array_merge($data, self::getFilePaths($tmp)) : $data[] = $tmp; + if (($tmp = realpath($path . DS . $dir)) && (is_dir($tmp) || pathinfo($tmp, PATHINFO_EXTENSION) === $ext)) { + is_dir($tmp) ? $data = array_merge($data, self::_getFilePaths($tmp)) : $data[] = $tmp; } } return $data; diff --git a/application/admin/view/user.form.html b/application/admin/view/user.form.html index 58074f9f1..b7a581233 100644 --- a/application/admin/view/user.form.html +++ b/application/admin/view/user.form.html @@ -14,7 +14,7 @@
- +
diff --git a/application/admin/view/user.pass.html b/application/admin/view/user.pass.html index 9dff0cb73..f2d0be21a 100644 --- a/application/admin/view/user.pass.html +++ b/application/admin/view/user.pass.html @@ -15,7 +15,7 @@
- +
{/if} diff --git a/application/common.php b/application/common.php index 00d518f70..a343aa6dd 100644 --- a/application/common.php +++ b/application/common.php @@ -85,8 +85,7 @@ function auth($node) { function sysconf($name) { static $config = []; if (empty($config)) { - $list = Db::name('SystemConfig')->select(); - foreach ($list as $vo) { + foreach (Db::name('SystemConfig')->select() as $vo) { $config[$vo['name']] = $vo['value']; } } diff --git a/application/extra/view/admin.main.top.html b/application/extra/view/admin.main.top.html index ae104b7bf..b4d4adf1f 100644 --- a/application/extra/view/admin.main.top.html +++ b/application/extra/view/admin.main.top.html @@ -25,6 +25,15 @@ style='width:50px;'> +