diff --git a/application/admin/behavior/AdminLog.php b/application/admin/behavior/AdminLog.php index f5bcd3c9..2a7afc72 100644 --- a/application/admin/behavior/AdminLog.php +++ b/application/admin/behavior/AdminLog.php @@ -4,7 +4,7 @@ namespace app\admin\behavior; class AdminLog { - public function run(&$params) + public function run(&$response) { //只记录POST请求的日志 if (request()->isPost() && config('fastadmin.auto_record_log')) { diff --git a/application/admin/command/Addon.php b/application/admin/command/Addon.php index fb7c437c..7bca186e 100644 --- a/application/admin/command/Addon.php +++ b/application/admin/command/Addon.php @@ -15,7 +15,6 @@ use think\exception\PDOException; class Addon extends Command { - protected function configure() { $this @@ -33,6 +32,7 @@ class Addon extends Command protected function execute(Input $input, Output $output) { + \think\Config::load(dirname(dirname(__FILE__)) . DS . 'config.php'); $name = $input->getOption('name') ?: ''; $action = $input->getOption('action') ?: ''; if (stripos($name, 'addons' . DS) !== false) { @@ -82,7 +82,6 @@ class Addon extends Command $createTableSql = $result[0]['Create Table']; } } catch (PDOException $e) { - } $data = [ @@ -177,12 +176,12 @@ class Addon extends Command if (!$info) { throw new Exception(__('Addon info file data incorrect')); } - $infoname = isset($info['name']) ? $info['name'] : ''; + $infoname = $info['name'] ?? ''; if (!$infoname || !preg_match("/^[a-z]+$/i", $infoname) || $infoname != $name) { throw new Exception(__('Addon info name incorrect')); } - $infoversion = isset($info['version']) ? $info['version'] : ''; + $infoversion = $info['version'] ?? ''; if (!$infoversion || !preg_match("/^\d+\.\d+\.\d+$/i", $infoversion)) { throw new Exception(__('Addon info version incorrect')); } @@ -340,5 +339,4 @@ class Addon extends Command { return __DIR__ . '/Addon/stubs/' . $name . '.stub'; } - } diff --git a/application/admin/command/Crud.php b/application/admin/command/Crud.php index 3845fa4c..ced92450 100755 --- a/application/admin/command/Crud.php +++ b/application/admin/command/Crud.php @@ -152,7 +152,7 @@ class Crud extends Command /** * JSON后缀 */ - protected $jsonSuffix = ['json']; + protected $jsonSuffix = ['json', 'array']; /** * 标签后缀 @@ -466,7 +466,7 @@ class Crud extends Command } } $relationTableInfo = $relationTableInfo[0]; - $relationModel = isset($relationModels[$index]) ? $relationModels[$index] : ''; + $relationModel = $relationModels[$index] ?? ''; list($relationNamespace, $relationName, $relationFile) = $this->getModelData($modelModuleName, $relationModel, $relationName); @@ -666,8 +666,8 @@ class Crud extends Command //如果是关联模型 foreach ($relations as $index => &$relation) { if ($relation['relationMode'] == 'hasone') { - $relationForeignKey = $relation['relationForeignKey'] ? $relation['relationForeignKey'] : $table . "_id"; - $relationPrimaryKey = $relation['relationPrimaryKey'] ? $relation['relationPrimaryKey'] : $priKey; + $relationForeignKey = $relation['relationForeignKey'] ?: $table . "_id"; + $relationPrimaryKey = $relation['relationPrimaryKey'] ?: $priKey; if (!in_array($relationForeignKey, $relation['relationFieldList'])) { throw new Exception('relation table [' . $relation['relationTableName'] . '] must be contain field [' . $relationForeignKey . ']'); @@ -676,8 +676,8 @@ class Crud extends Command throw new Exception('table [' . $modelTableName . '] must be contain field [' . $relationPrimaryKey . ']'); } } elseif ($relation['relationMode'] == 'belongsto') { - $relationForeignKey = $relation['relationForeignKey'] ? $relation['relationForeignKey'] : Loader::parseName($relation['relationName']) . "_id"; - $relationPrimaryKey = $relation['relationPrimaryKey'] ? $relation['relationPrimaryKey'] : $relation['relationPriKey']; + $relationForeignKey = $relation['relationForeignKey'] ?: Loader::parseName($relation['relationName']) . "_id"; + $relationPrimaryKey = $relation['relationPrimaryKey'] ?: $relation['relationPriKey']; if (!in_array($relationForeignKey, $fieldArr)) { throw new Exception('table [' . $modelTableName . '] must be contain field [' . $relationForeignKey . ']'); } @@ -685,8 +685,8 @@ class Crud extends Command throw new Exception('relation table [' . $relation['relationTableName'] . '] must be contain field [' . $relationPrimaryKey . ']'); } } elseif ($relation['relationMode'] == 'hasmany') { - $relationForeignKey = $relation['relationForeignKey'] ? $relation['relationForeignKey'] : $table . "_id"; - $relationPrimaryKey = $relation['relationPrimaryKey'] ? $relation['relationPrimaryKey'] : $priKey; + $relationForeignKey = $relation['relationForeignKey'] ?: $table . "_id"; + $relationPrimaryKey = $relation['relationPrimaryKey'] ?: $priKey; if (!in_array($relationForeignKey, $relation['relationFieldList'])) { throw new Exception('relation table [' . $relation['relationTableName'] . '] must be contain field [' . $relationForeignKey . ']'); } @@ -879,7 +879,7 @@ class Crud extends Command $formEditElement = Form::input('text', $fieldName, $editValue, $attrArr); } elseif ($inputType == 'fieldlist') { $itemArr = $this->getItemArray($itemArr, $field, $v['COLUMN_COMMENT']); - $templateName = !isset($itemArr['key']) && !isset($itemArr['value']) && count($itemArr) > 0 ? 'fieldlist-template' : 'fieldlist'; + $templateName = !isset($itemArr['key']) && count($itemArr) > 0 ? (isset($itemArr['value']) && count($itemArr) === 1 ? 'fieldlist-array' : 'fieldlist-template') : 'fieldlist'; $itemKey = isset($itemArr['key']) ? ucfirst($itemArr['key']) : 'Key'; $itemValue = isset($itemArr['value']) ? ucfirst($itemArr['value']) : 'Value'; $theadListArr = $tbodyListArr = []; @@ -901,6 +901,12 @@ class Crud extends Command $cssClassArr[] = 'selectpage'; $selectpageTable = substr($field, 0, strripos($field, '_')); $selectpageField = ''; + foreach ($relations as $index => $relation) { + if ($relation['relationForeignKey'] === $field) { + $selectpageTable = substr($relation['relationTableName'], strlen($prefix)); + break; + } + } $selectpageController = str_replace('_', '/', $selectpageTable); $attrArr['data-source'] = $selectpageController . "/index"; //如果是类型表需要特殊处理下 @@ -931,7 +937,6 @@ class Crud extends Command } } } catch (\Exception $e) { - } if (!$selectpageField) { foreach ($this->fieldSelectpageMap as $m => $n) { @@ -993,7 +998,7 @@ class Crud extends Command } if (!$fields || in_array($field, explode(',', $fields))) { //构造JS列信息 - $javascriptList[] = $this->getJsColumn($field, $v['DATA_TYPE'], $inputType && in_array($inputType, ['select', 'checkbox', 'radio']) ? '_text' : '', $itemArr); + $javascriptList[] = $this->getJsColumn($field, $v['DATA_TYPE'], $inputType && in_array($inputType, ['select', 'checkbox', 'radio']) ? '_text' : '', $itemArr, $v); } if ($this->headingFilterField && $this->headingFilterField == $field && $itemArr) { $headingHtml = $this->getReplacedStub('html/heading-html', ['field' => $field, 'fieldName' => Loader::parseName($field, 1, false)]); @@ -1048,7 +1053,7 @@ class Crud extends Command //过滤text类型字段 if ($v['DATA_TYPE'] != 'text') { //构造JS列信息 - $javascriptList[] = $this->getJsColumn($relationField, $v['DATA_TYPE']); + $javascriptList[] = $this->getJsColumn($relationField, $v['DATA_TYPE'], '', [], $v); } } } @@ -1537,7 +1542,7 @@ EOD; { $itemArr = []; $comment = str_replace(',', ',', $comment); - if (stripos($comment, ':') !== false && stripos($comment, ',') && stripos($comment, '=') !== false) { + if (stripos($comment, ':') !== false && stripos($comment, '=') !== false) { list($fieldLang, $item) = explode(':', $comment); $itemArr = []; foreach (explode(',', $item) as $k => $v) { @@ -1699,9 +1704,10 @@ EOD; * @param string $datatype * @param string $extend * @param array $itemArr + * @param array $fieldConfig * @return string */ - protected function getJsColumn($field, $datatype = '', $extend = '', $itemArr = []) + protected function getJsColumn($field, $datatype = '', $extend = '', $itemArr = [], $fieldConfig = []) { $lang = mb_ucfirst($field); $formatter = ''; @@ -1739,7 +1745,7 @@ EOD; $noSearchFiles = ['file$', 'files$', 'image$', 'images$', '^weigh$']; if (preg_match("/" . implode('|', $noSearchFiles) . "/i", $field)) { $html .= ", operate: false"; - } else if (in_array($datatype, ['varchar'])) { + } elseif (in_array($datatype, ['varchar'])) { $html .= ", operate: 'LIKE'"; } @@ -1751,6 +1757,10 @@ EOD; if (in_array($datatype, ['set'])) { $html .= ", operate:'FIND_IN_SET'"; } + if (isset($fieldConfig['CHARACTER_MAXIMUM_LENGTH']) && $fieldConfig['CHARACTER_MAXIMUM_LENGTH'] >= 255 && in_array($datatype, ['varchar']) && !$formatter) { + $formatter = 'content'; + $html .= ", table: table, class: 'autocontent'"; + } if (in_array($formatter, ['image', 'images'])) { $html .= ", events: Table.api.events.image"; } diff --git a/application/admin/command/Crud/stubs/add.stub b/application/admin/command/Crud/stubs/add.stub index e51cf203..1a6563f3 100644 --- a/application/admin/command/Crud/stubs/add.stub +++ b/application/admin/command/Crud/stubs/add.stub @@ -5,7 +5,6 @@
我是测试内容
', '/assets/img/avatar.png', '/assets/img/avatar.png,/assets/img/qrcode.png', '/assets/img/avatar.png', '关键字', '我是一篇测试文章描述,内容过多时将自动隐藏', '广西壮族自治区/百色市/平果县', '{\"a\":\"1\",\"b\":\"2\"}', '[{\"title\":\"标题一\",\"intro\":\"介绍一\",\"author\":\"小明\",\"age\":\"21\"}]', 0.00, 0, '2020-10-01 00:00:00 - 2021-10-31 23:59:59', '2017-07-10', '2017-07-10 18:24:45', 2017, '18:24:45', 1491635035, 1491635035, 1491635035, NULL, 0, 1, 'normal', '1'); +INSERT INTO `fa_test` VALUES (1, 1, 1, 12, '12,13', '互联网,计算机', 'monday', 'hot,index', 'male', 'music,reading', '我是一篇测试文章', '我是测试内容
', '/assets/img/avatar.png', '/assets/img/avatar.png,/assets/img/qrcode.png', '/assets/img/avatar.png', '关键字', '我是一篇测试文章描述,内容过多时将自动隐藏', '广西壮族自治区/百色市/平果县', '[\"a\",\"b\"]', '{\"a\":\"1\",\"b\":\"2\"}', '[{\"title\":\"标题一\",\"intro\":\"介绍一\",\"author\":\"小明\",\"age\":\"21\"}]', 0.00, 0, '2020-10-01 00:00:00 - 2021-10-31 23:59:59', '2017-07-10', '2017-07-10 18:24:45', 2017, '18:24:45', 1491635035, 1491635035, 1491635035, NULL, 0, 1, 'normal', '1'); COMMIT; -- ---------------------------- @@ -468,7 +469,7 @@ CREATE TABLE `fa_user` ( -- Records of fa_user -- ---------------------------- BEGIN; -INSERT INTO `fa_user` VALUES (1, 1, 'admin', 'admin', '', '', 'admin@163.com', '13888888888', '', 0, 0, '2017-04-08', '', 0, 0, 1, 1, 1491635035, 1491635035, '127.0.0.1', 0, '127.0.0.1', 1491635035, 0, 1491635035, '', 'normal',''); +INSERT INTO `fa_user` VALUES (1, 1, 'admin', 'admin', '', '', 'admin@163.com', '13000000000', '', 0, 0, '2017-04-08', '', 0, 0, 1, 1, 1491635035, 1491635035, '127.0.0.1', 0, '127.0.0.1', 1491635035, 0, 1491635035, '', 'normal',''); COMMIT; -- ---------------------------- diff --git a/application/admin/controller/Addon.php b/application/admin/controller/Addon.php index 355ddab6..8fc7a886 100644 --- a/application/admin/controller/Addon.php +++ b/application/admin/controller/Addon.php @@ -95,19 +95,24 @@ class Addon extends Backend } $tips = []; $groupList = []; + $ungroupList = []; foreach ($config as $index => &$item) { //如果有设置分组 if (isset($item['group']) && $item['group']) { if (!in_array($item['group'], $groupList)) { $groupList["custom" . (count($groupList) + 1)] = $item['group']; } + } elseif ($item['name'] != '__tips__') { + $ungroupList[] = $item['name']; } if ($item['name'] == '__tips__') { $tips = $item; unset($config[$index]); } } - $groupList['other'] = '其它'; + if ($ungroupList) { + $groupList['other'] = '其它'; + } $this->view->assign("groupList", $groupList); $this->view->assign("addon", ['info' => $info, 'config' => $config, 'tips' => $tips]); $configFile = ADDON_PATH . $name . DS . 'config.html'; @@ -230,6 +235,7 @@ class Addon extends Backend $uid = $this->request->post("uid"); $token = $this->request->post("token"); $faversion = $this->request->post("faversion"); + $force = $this->request->post("force"); if (!$uid || !$token) { throw new Exception(__('Please login and try to install')); } @@ -238,7 +244,7 @@ class Addon extends Backend 'token' => $token, 'faversion' => $faversion ]; - $info = Service::local($file, $extend); + $info = Service::local($file, $extend, $force); } catch (AddonException $e) { $this->result($e->getData(), $e->getCode(), __($e->getMessage())); } catch (Exception $e) { @@ -441,8 +447,11 @@ class Addon extends Backend } catch (\Exception $e) { } - $rows = isset($json['rows']) ? $json['rows'] : []; + $rows = $json['rows'] ?? []; foreach ($rows as $index => $row) { + if (!isset($row['name'])) { + continue; + } $onlineaddons[$row['name']] = $row; } Cache::set("onlineaddons", $onlineaddons, 600); diff --git a/application/admin/controller/Index.php b/application/admin/controller/Index.php index 63c2ba92..fe560fb3 100644 --- a/application/admin/controller/Index.php +++ b/application/admin/controller/Index.php @@ -44,7 +44,6 @@ class Index extends Backend 'dashboard' => 'hot', 'addon' => ['new', 'red', 'badge'], 'auth/rule' => __('Menu'), - 'general' => ['new', 'purple'], ], $this->view->site['fixedpage']); $action = $this->request->request('action'); if ($this->request->isPost()) { @@ -66,7 +65,8 @@ class Index extends Backend */ public function login() { - $url = $this->request->get('url', 'index/index', 'url_clean'); + $url = $this->request->get('url', '', 'url_clean'); + $url = $url ?: 'index/index'; if ($this->auth->isLogin()) { $this->success(__("You've logged in, do not login again"), $url); } @@ -74,7 +74,7 @@ class Index extends Backend $keeyloginhours = 24; if ($this->request->isPost()) { $username = $this->request->post('username'); - $password = $this->request->post('password'); + $password = $this->request->post('password', '', null); $keeplogin = $this->request->post('keeplogin'); $token = $this->request->post('__token__'); $rule = [ diff --git a/application/admin/controller/auth/Adminlog.php b/application/admin/controller/auth/Adminlog.php index 9ed148ce..1d8cc810 100644 --- a/application/admin/controller/auth/Adminlog.php +++ b/application/admin/controller/auth/Adminlog.php @@ -53,6 +53,7 @@ class Adminlog extends Backend $query->where('admin_id', 'in', $childrenAdminIds); } }) + ->field('content,useragent', true) ->order($sort, $order) ->paginate($limit); diff --git a/application/admin/controller/general/Profile.php b/application/admin/controller/general/Profile.php index feffa995..63b765c9 100644 --- a/application/admin/controller/general/Profile.php +++ b/application/admin/controller/general/Profile.php @@ -74,6 +74,7 @@ class Profile extends Backend $admin->save($params); //因为个人资料面板读取的Session显示,修改自己资料后同时更新Session Session::set("admin", $admin->toArray()); + Session::set("admin.safecode", $this->auth->getEncryptSafecode($admin)); $this->success(); } $this->error(); diff --git a/application/admin/controller/user/User.php b/application/admin/controller/user/User.php index ba373e56..6908ad67 100644 --- a/application/admin/controller/user/User.php +++ b/application/admin/controller/user/User.php @@ -24,7 +24,7 @@ class User extends Backend public function _initialize() { parent::_initialize(); - $this->model = model('User'); + $this->model = new \app\admin\model\User; } /** diff --git a/application/admin/lang/zh-cn.php b/application/admin/lang/zh-cn.php index f2a7efd9..f0e1bc49 100755 --- a/application/admin/lang/zh-cn.php +++ b/application/admin/lang/zh-cn.php @@ -4,6 +4,8 @@ return [ 'User id' => '会员ID', 'Username' => '用户名', 'Nickname' => '昵称', + 'Mobile' => '手机', + 'Email' => '邮箱', 'Password' => '密码', 'Mobile' => '手机号', 'Sign up' => '注 册', diff --git a/application/admin/lang/zh-cn/addon.php b/application/admin/lang/zh-cn/addon.php index 6c999d2a..abbcb254 100755 --- a/application/admin/lang/zh-cn/addon.php +++ b/application/admin/lang/zh-cn/addon.php @@ -14,11 +14,8 @@ return [ 'Refresh addon cache' => '刷新插件缓存', 'Userinfo' => '会员信息', 'Reload authorization' => '刷新授权', - 'Online store' => '在线商店', 'Local addon' => '本地插件', 'Conflict tips' => '此插件中发现和现有系统中部分文件发现冲突!以下文件将会被影响,请备份好相关文件后再继续操作', - 'Login tips' => '此处登录账号为FastAdmin官网账号', - 'Logined tips' => '你好!%s1、请务必做好代码和数据库备份!备份!备份!
2、升级后如出现冗余数据,请根据需要移除即可!
3、不建议在生产环境升级,请在本地完成升级测试
{:__('Delete all the addon file and cannot be recovered!')}
- {if config('app_debug')} + {if config('app_debug')}{:__('Delete all the addon database and cannot be recovered!')}
- {/if} + {/if}{:__('Please backup important data manually before uninstall!')}