Browse Source

优化服务端cdnurl函数计算

优化代码
Karson 1 year ago
parent
commit
7f28eaa570
2 changed files with 12 additions and 11 deletions
  1. 1 1
      application/admin/command/Install/fastadmin.sql
  2. 11 10
      application/common.php

+ 1 - 1
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\"]', '', '', '');

+ 11 - 10
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);
         }