From 36dfe45715bec1b982a348563ff6323e1c3522fa Mon Sep 17 00:00:00 2001 From: alias Date: Wed, 20 May 2020 14:18:43 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E7=9B=AE=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/admin/command/Install.php | 8 +- .../admin/controller/general/Config.php | 474 +++++++++--------- 2 files changed, 241 insertions(+), 241 deletions(-) diff --git a/application/admin/command/Install.php b/application/admin/command/Install.php index 835269dea..0e7dd3793 100644 --- a/application/admin/command/Install.php +++ b/application/admin/command/Install.php @@ -197,7 +197,7 @@ class Install extends Command $adminFile = ROOT_PATH . 'public' . DS . 'admin.php'; // 数据库配置文件 - $dbConfigFile = APP_PATH . 'database.php'; + $dbConfigFile = CONF_PATH . 'database.php'; $config = @file_get_contents($dbConfigFile); $callback = function ($matches) use ($mysqlHostname, $mysqlHostport, $mysqlUsername, $mysqlPassword, $mysqlDatabase, $mysqlPrefix) { $field = "mysql" . ucfirst($matches[1]); @@ -232,7 +232,7 @@ class Install extends Command //修改站点名称 if ($siteName != __('My Website')) { $instance->name('config')->where('name', 'name')->update(['value' => $siteName]); - $configFile = APP_PATH . 'extra' . DS . 'site.php'; + $configFile = CONF_PATH . 'extra' . DS . 'site.php'; $config = include $configFile; $configList = $instance->name("config")->select(); foreach ($configList as $k => $value) { @@ -240,7 +240,7 @@ class Install extends Command $value['value'] = explode(',', $value['value']); } if ($value['type'] == 'array') { - $value['value'] = (array)json_decode($value['value'], true); + $value['value'] = (array) json_decode($value['value'], true); } $config[$value['name']] = $value['value']; } @@ -271,7 +271,7 @@ class Install extends Command ]; //数据库配置文件 - $dbConfigFile = APP_PATH . 'database.php'; + $dbConfigFile = CONF_PATH . 'database.php'; if (version_compare(PHP_VERSION, '5.5.0', '<')) { throw new Exception(__("The current version %s is too low, please use PHP 5.5 or higher", PHP_VERSION)); diff --git a/application/admin/controller/general/Config.php b/application/admin/controller/general/Config.php index 24b405a46..84715c17f 100644 --- a/application/admin/controller/general/Config.php +++ b/application/admin/controller/general/Config.php @@ -17,252 +17,252 @@ use think\Validate; class Config extends Backend { - /** - * @var \app\common\model\Config - */ - protected $model = null; - protected $noNeedRight = ['check', 'rulelist']; + /** + * @var \app\common\model\Config + */ + protected $model = null; + protected $noNeedRight = ['check', 'rulelist']; - public function _initialize() - { - parent::_initialize(); - $this->model = model('Config'); - ConfigModel::event('before_write', function ($row) { - if (isset($row['name']) && $row['name'] == 'name' && preg_match("/fast" . "admin/i", $row['value'])) { - throw new Exception(__("Site name incorrect")); - } - }); - } + public function _initialize() + { + parent::_initialize(); + $this->model = model('Config'); + ConfigModel::event('before_write', function ($row) { + if (isset($row['name']) && $row['name'] == 'name' && preg_match("/fast" . "admin/i", $row['value'])) { + throw new Exception(__("Site name incorrect")); + } + }); + } - /** - * 查看 - */ - public function index() - { - $siteList = []; - $groupList = ConfigModel::getGroupList(); - foreach ($groupList as $k => $v) { - $siteList[$k]['name'] = $k; - $siteList[$k]['title'] = $v; - $siteList[$k]['list'] = []; - } + /** + * 查看 + */ + public function index() + { + $siteList = []; + $groupList = ConfigModel::getGroupList(); + foreach ($groupList as $k => $v) { + $siteList[$k]['name'] = $k; + $siteList[$k]['title'] = $v; + $siteList[$k]['list'] = []; + } - foreach ($this->model->all() as $k => $v) { - if (!isset($siteList[$v['group']])) { - continue; - } - $value = $v->toArray(); - $value['title'] = __($value['title']); - if (in_array($value['type'], ['select', 'selects', 'checkbox', 'radio'])) { - $value['value'] = explode(',', $value['value']); - } - $value['content'] = json_decode($value['content'], true); - $value['tip'] = htmlspecialchars($value['tip']); - $siteList[$v['group']]['list'][] = $value; - } - $index = 0; - foreach ($siteList as $k => &$v) { - $v['active'] = !$index ? true : false; - $index++; - } - $this->view->assign('siteList', $siteList); - $this->view->assign('typeList', ConfigModel::getTypeList()); - $this->view->assign('ruleList', ConfigModel::getRegexList()); - $this->view->assign('groupList', ConfigModel::getGroupList()); - return $this->view->fetch(); - } + foreach ($this->model->all() as $k => $v) { + if (!isset($siteList[$v['group']])) { + continue; + } + $value = $v->toArray(); + $value['title'] = __($value['title']); + if (in_array($value['type'], ['select', 'selects', 'checkbox', 'radio'])) { + $value['value'] = explode(',', $value['value']); + } + $value['content'] = json_decode($value['content'], true); + $value['tip'] = htmlspecialchars($value['tip']); + $siteList[$v['group']]['list'][] = $value; + } + $index = 0; + foreach ($siteList as $k => &$v) { + $v['active'] = !$index ? true : false; + $index++; + } + $this->view->assign('siteList', $siteList); + $this->view->assign('typeList', ConfigModel::getTypeList()); + $this->view->assign('ruleList', ConfigModel::getRegexList()); + $this->view->assign('groupList', ConfigModel::getGroupList()); + return $this->view->fetch(); + } - /** - * 添加 - */ - public function add() - { - if ($this->request->isPost()) { - $this->token(); - $params = $this->request->post("row/a", [], 'trim'); - if ($params) { - foreach ($params as $k => &$v) { - $v = is_array($v) ? implode(',', $v) : $v; - } - if (in_array($params['type'], ['select', 'selects', 'checkbox', 'radio', 'array'])) { - $params['content'] = json_encode(ConfigModel::decode($params['content']), JSON_UNESCAPED_UNICODE); - } else { - $params['content'] = ''; - } - try { - $result = $this->model->create($params); - } catch (Exception $e) { - $this->error($e->getMessage()); - } - if ($result !== false) { - try { - $this->refreshFile(); - } catch (Exception $e) { - $this->error($e->getMessage()); - } - $this->success(); - } else { - $this->error($this->model->getError()); - } - } - $this->error(__('Parameter %s can not be empty', '')); - } - return $this->view->fetch(); - } + /** + * 添加 + */ + public function add() + { + if ($this->request->isPost()) { + $this->token(); + $params = $this->request->post("row/a", [], 'trim'); + if ($params) { + foreach ($params as $k => &$v) { + $v = is_array($v) ? implode(',', $v) : $v; + } + if (in_array($params['type'], ['select', 'selects', 'checkbox', 'radio', 'array'])) { + $params['content'] = json_encode(ConfigModel::decode($params['content']), JSON_UNESCAPED_UNICODE); + } else { + $params['content'] = ''; + } + try { + $result = $this->model->create($params); + } catch (Exception $e) { + $this->error($e->getMessage()); + } + if ($result !== false) { + try { + $this->refreshFile(); + } catch (Exception $e) { + $this->error($e->getMessage()); + } + $this->success(); + } else { + $this->error($this->model->getError()); + } + } + $this->error(__('Parameter %s can not be empty', '')); + } + return $this->view->fetch(); + } - /** - * 编辑 - * @param null $ids - */ - public function edit($ids = null) - { - if ($this->request->isPost()) { - $this->token(); - $row = $this->request->post("row/a", [], 'trim'); - if ($row) { - $configList = []; - foreach ($this->model->all() as $v) { - if (isset($row[$v['name']])) { - $value = $row[$v['name']]; - if (is_array($value) && isset($value['field'])) { - $value = json_encode(ConfigModel::getArrayData($value), JSON_UNESCAPED_UNICODE); - } else { - $value = is_array($value) ? implode(',', $value) : $value; - } - $v['value'] = $value; - $configList[] = $v->toArray(); - } - } - try { - $this->model->allowField(true)->saveAll($configList); - } catch (Exception $e) { - $this->error($e->getMessage()); - } - try { - $this->refreshFile(); - } catch (Exception $e) { - $this->error($e->getMessage()); - } - $this->success(); - } - $this->error(__('Parameter %s can not be empty', '')); - } - } + /** + * 编辑 + * @param null $ids + */ + public function edit($ids = null) + { + if ($this->request->isPost()) { + $this->token(); + $row = $this->request->post("row/a", [], 'trim'); + if ($row) { + $configList = []; + foreach ($this->model->all() as $v) { + if (isset($row[$v['name']])) { + $value = $row[$v['name']]; + if (is_array($value) && isset($value['field'])) { + $value = json_encode(ConfigModel::getArrayData($value), JSON_UNESCAPED_UNICODE); + } else { + $value = is_array($value) ? implode(',', $value) : $value; + } + $v['value'] = $value; + $configList[] = $v->toArray(); + } + } + try { + $this->model->allowField(true)->saveAll($configList); + } catch (Exception $e) { + $this->error($e->getMessage()); + } + try { + $this->refreshFile(); + } catch (Exception $e) { + $this->error($e->getMessage()); + } + $this->success(); + } + $this->error(__('Parameter %s can not be empty', '')); + } + } - /** - * 删除 - * @param string $ids - */ - public function del($ids = "") - { - $name = $this->request->post('name'); - $config = ConfigModel::getByName($name); - if ($name && $config) { - try { - $config->delete(); - $this->refreshFile(); - } catch (Exception $e) { - $this->error($e->getMessage()); - } - $this->success(); - } else { - $this->error(__('Invalid parameters')); - } - } + /** + * 删除 + * @param string $ids + */ + public function del($ids = "") + { + $name = $this->request->post('name'); + $config = ConfigModel::getByName($name); + if ($name && $config) { + try { + $config->delete(); + $this->refreshFile(); + } catch (Exception $e) { + $this->error($e->getMessage()); + } + $this->success(); + } else { + $this->error(__('Invalid parameters')); + } + } - /** - * 刷新配置文件 - */ - protected function refreshFile() - { - $config = []; - foreach ($this->model->all() as $k => $v) { - $value = $v->toArray(); - if (in_array($value['type'], ['selects', 'checkbox', 'images', 'files'])) { - $value['value'] = explode(',', $value['value']); - } - if ($value['type'] == 'array') { - $value['value'] = (array)json_decode($value['value'], true); - } - $config[$value['name']] = $value['value']; - } - file_put_contents( - APP_PATH . 'extra' . DS . 'site.php', - 'model->all() as $k => $v) { + $value = $v->toArray(); + if (in_array($value['type'], ['selects', 'checkbox', 'images', 'files'])) { + $value['value'] = explode(',', $value['value']); + } + if ($value['type'] == 'array') { + $value['value'] = (array) json_decode($value['value'], true); + } + $config[$value['name']] = $value['value']; + } + file_put_contents( + CONF_PATH . 'extra' . DS . 'site.php', + 'request->post("row/a"); - if ($params) { - $config = $this->model->get($params); - if (!$config) { - return $this->success(); - } else { - return $this->error(__('Name already exist')); - } - } else { - return $this->error(__('Invalid parameters')); - } - } + /** + * 检测配置项是否存在 + * @internal + */ + public function check() + { + $params = $this->request->post("row/a"); + if ($params) { + $config = $this->model->get($params); + if (!$config) { + return $this->success(); + } else { + return $this->error(__('Name already exist')); + } + } else { + return $this->error(__('Invalid parameters')); + } + } - /** - * 规则列表 - * @internal - */ - public function rulelist() - { - //主键 - $primarykey = $this->request->request("keyField"); - //主键值 - $keyValue = $this->request->request("keyValue", ""); + /** + * 规则列表 + * @internal + */ + public function rulelist() + { + //主键 + $primarykey = $this->request->request("keyField"); + //主键值 + $keyValue = $this->request->request("keyValue", ""); - $keyValueArr = array_filter(explode(',', $keyValue)); - $regexList = \app\common\model\Config::getRegexList(); - $list = []; - foreach ($regexList as $k => $v) { - if ($keyValueArr) { - if (in_array($k, $keyValueArr)) { - $list[] = ['id' => $k, 'name' => $v]; - } - } else { - $list[] = ['id' => $k, 'name' => $v]; - } - } - return json(['list' => $list]); - } + $keyValueArr = array_filter(explode(',', $keyValue)); + $regexList = \app\common\model\Config::getRegexList(); + $list = []; + foreach ($regexList as $k => $v) { + if ($keyValueArr) { + if (in_array($k, $keyValueArr)) { + $list[] = ['id' => $k, 'name' => $v]; + } + } else { + $list[] = ['id' => $k, 'name' => $v]; + } + } + return json(['list' => $list]); + } - /** - * 发送测试邮件 - * @internal - */ - public function emailtest() - { - $row = $this->request->post('row/a'); - $receiver = $this->request->post("receiver"); - if ($receiver) { - if (!Validate::is($receiver, "email")) { - $this->error(__('Please input correct email')); - } - \think\Config::set('site', array_merge(\think\Config::get('site'), $row)); - $email = new Email; - $result = $email - ->to($receiver) - ->subject(__("This is a test mail")) - ->message('
' . __('This is a test mail content') . '
') - ->send(); - if ($result) { - $this->success(); - } else { - $this->error($email->getError()); - } - } else { - return $this->error(__('Invalid parameters')); - } - } + /** + * 发送测试邮件 + * @internal + */ + public function emailtest() + { + $row = $this->request->post('row/a'); + $receiver = $this->request->post("receiver"); + if ($receiver) { + if (!Validate::is($receiver, "email")) { + $this->error(__('Please input correct email')); + } + \think\Config::set('site', array_merge(\think\Config::get('site'), $row)); + $email = new Email; + $result = $email + ->to($receiver) + ->subject(__("This is a test mail")) + ->message('
' . __('This is a test mail content') . '
') + ->send(); + if ($result) { + $this->success(); + } else { + $this->error($email->getError()); + } + } else { + return $this->error(__('Invalid parameters')); + } + } } -- Gitee From 99f6b8c445c60d005d5050057d27b93aca3579a4 Mon Sep 17 00:00:00 2001 From: alias Date: Wed, 20 May 2020 14:55:17 +0800 Subject: [PATCH 2/2] fixbug --- application/admin/controller/general/Config.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/admin/controller/general/Config.php b/application/admin/controller/general/Config.php index 84715c17f..cac7c6958 100644 --- a/application/admin/controller/general/Config.php +++ b/application/admin/controller/general/Config.php @@ -250,7 +250,7 @@ class Config extends Backend $this->error(__('Please input correct email')); } \think\Config::set('site', array_merge(\think\Config::get('site'), $row)); - $email = new Email; + $email = new Email(); $result = $email ->to($receiver) ->subject(__("This is a test mail")) -- Gitee