From 7f28eaa5702daa2192079ec57427797b2a1256be Mon Sep 17 00:00:00 2001 From: Karson Date: Wed, 5 Jul 2023 15:03:30 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=9C=8D=E5=8A=A1=E7=AB=AFcd?= =?UTF-8?q?nurl=E5=87=BD=E6=95=B0=E8=AE=A1=E7=AE=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 优化代码 --- .../admin/command/Install/fastadmin.sql | 2 +- application/common.php | 21 ++++++++++--------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/application/admin/command/Install/fastadmin.sql b/application/admin/command/Install/fastadmin.sql index 85780dfc..d721ec81 100755 --- a/application/admin/command/Install/fastadmin.sql +++ b/application/admin/command/Install/fastadmin.sql @@ -336,7 +336,7 @@ INSERT INTO `fa_config` VALUES (4, 'version', 'basic', 'Version', '如果静态 INSERT INTO `fa_config` VALUES (5, 'timezone', 'basic', 'Timezone', '', 'string', '', 'Asia/Shanghai', '', 'required', '', ''); INSERT INTO `fa_config` VALUES (6, 'forbiddenip', 'basic', 'Forbidden ip', '一行一条记录', 'text', '', '', '', '', '', ''); INSERT INTO `fa_config` VALUES (7, 'languages', 'basic', 'Languages', '', 'array', '', '{\"backend\":\"zh-cn\",\"frontend\":\"zh-cn\"}', '', 'required', '', ''); -INSERT INTO `fa_config` VALUES (8, 'fixedpage', 'basic', 'Fixed page', '请尽量输入左侧菜单栏存在的链接', 'string', '', 'dashboard', '', 'required', '', ''); +INSERT INTO `fa_config` VALUES (8, 'fixedpage', 'basic', 'Fixed page', '请输入左侧菜单栏存在的链接', 'string', '', 'dashboard', '', 'required', '', ''); INSERT INTO `fa_config` VALUES (9, 'categorytype', 'dictionary', 'Category type', '', 'array', '', '{\"default\":\"Default\",\"page\":\"Page\",\"article\":\"Article\",\"test\":\"Test\"}', '', '', '', ''); INSERT INTO `fa_config` VALUES (10, 'configgroup', 'dictionary', 'Config group', '', 'array', '', '{\"basic\":\"Basic\",\"email\":\"Email\",\"dictionary\":\"Dictionary\",\"user\":\"User\",\"example\":\"Example\"}', '', '', '', ''); INSERT INTO `fa_config` VALUES (11, 'mail_type', 'email', 'Mail type', '选择邮件发送方式', 'select', '', '1', '[\"请选择\",\"SMTP\"]', '', '', ''); diff --git a/application/common.php b/application/common.php index 6123f316..3203418a 100755 --- a/application/common.php +++ b/application/common.php @@ -2,7 +2,6 @@ // 公共助手函数 -use Symfony\Component\VarExporter\VarExporter; use think\exception\HttpResponseException; use think\Response; @@ -89,7 +88,9 @@ if (!function_exists('cdnurl')) { { $regex = "/^((?:[a-z]+:)?\/\/|data:image\/)(.*)/i"; $cdnurl = \think\Config::get('upload.cdnurl'); - $url = preg_match($regex, $url) || ($cdnurl && stripos($url, $cdnurl) === 0) ? $url : $cdnurl . $url; + if (is_bool($domain) || stripos($cdnurl, '/') === 0) { + $url = preg_match($regex, $url) || ($cdnurl && stripos($url, $cdnurl) === 0) ? $url : $cdnurl . $url; + } if ($domain && !preg_match($regex, $url)) { $domain = is_bool($domain) ? request()->domain() : $domain; $url = $domain . $url; @@ -216,7 +217,7 @@ if (!function_exists('addtion')) { } else { foreach ($fields as $k => $v) { if (is_array($v)) { - $v['field'] = isset($v['field']) ? $v['field'] : $k; + $v['field'] = $v['field'] ?? $k; } else { $v = ['field' => $v]; } @@ -225,12 +226,12 @@ if (!function_exists('addtion')) { } foreach ($fieldsArr as $k => &$v) { $v = is_array($v) ? $v : ['field' => $v]; - $v['display'] = isset($v['display']) ? $v['display'] : str_replace(['_ids', '_id'], ['_names', '_name'], $v['field']); - $v['primary'] = isset($v['primary']) ? $v['primary'] : ''; - $v['column'] = isset($v['column']) ? $v['column'] : 'name'; - $v['model'] = isset($v['model']) ? $v['model'] : ''; - $v['table'] = isset($v['table']) ? $v['table'] : ''; - $v['name'] = isset($v['name']) ? $v['name'] : str_replace(['_ids', '_id'], '', $v['field']); + $v['display'] = $v['display'] ?? str_replace(['_ids', '_id'], ['_names', '_name'], $v['field']); + $v['primary'] = $v['primary'] ?? ''; + $v['column'] = $v['column'] ?? 'name'; + $v['model'] = $v['model'] ?? ''; + $v['table'] = $v['table'] ?? ''; + $v['name'] = $v['name'] ?? str_replace(['_ids', '_id'], '', $v['field']); } unset($v); $ids = []; @@ -323,7 +324,7 @@ if (!function_exists('var_export_short')) { if ($replaced) { $dump = preg_replace_callback("/'##<(\d+)>##'/", function ($matches) use ($replaced) { - return isset($replaced[$matches[1]]) ? $replaced[$matches[1]] : "''"; + return $replaced[$matches[1]] ?? "''"; }, $dump); }