From e7cf4849c926c97e96aab4f91accadfe049ee0bf Mon Sep 17 00:00:00 2001 From: tensent Date: Tue, 18 Feb 2020 17:52:26 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common.php | 58 +++++++++++++++++++++++++++++++ app/controller/admin/Database.php | 10 +++--- app/model/Config.php | 33 ++++++++++-------- public/uploads/files/.gitignore | 2 ++ public/uploads/images/.gitignore | 2 ++ public/uploads/media/.gitignore | 2 ++ 6 files changed, 87 insertions(+), 20 deletions(-) create mode 100644 public/uploads/files/.gitignore create mode 100644 public/uploads/images/.gitignore create mode 100644 public/uploads/media/.gitignore diff --git a/app/common.php b/app/common.php index 86fdda6f..d290aabe 100755 --- a/app/common.php +++ b/app/common.php @@ -80,4 +80,62 @@ function parse_config_attr($string) { $value = $array; } return $value; +} + +function mk_dir($dir, $mode = 0755) { + if (is_dir($dir) || @mkdir($dir, $mode, true)) { + return true; + } + + if (!mk_dir(dirname($dir), $mode, true)) { + return false; + } + + return @mkdir($dir, $mode, true); +} + +/** + * 字符串转换为数组,主要用于把分隔符调整到第二个参数 + * @param string $str 要分割的字符串 + * @param string $glue 分割符 + * @return array + * @author 麦当苗儿 + */ +function str2arr($str = '', $glue = ',') { + if ($str) { + return explode($glue, $str); + } else { + return array(); + } +} + +/** + * 数组转换为字符串,主要用于把分隔符调整到第二个参数 + * @param array $arr 要连接的数组 + * @param string $glue 分割符 + * @return string + * @author 麦当苗儿 + */ +function arr2str($arr = array(), $glue = ',') { + if (empty($arr)) { + return ''; + } else { + return implode($glue, $arr); + } +} + +/** + * 格式化字节大小 + * @param number $size 字节数 + * @param string $delimiter 数字和单位分隔符 + * @return string 格式化后的带单位的大小 + * @author 麦当苗儿 + */ +function format_bytes($size, $delimiter = '') { + $units = array('B', 'KB', 'MB', 'GB', 'TB', 'PB'); + for ($i = 0; $size >= 1024 && $i < 5; $i++) { + $size /= 1024; + } + + return round($size, 2) . $delimiter . $units[$i]; } \ No newline at end of file diff --git a/app/controller/admin/Database.php b/app/controller/admin/Database.php index 855962ab..b82c520c 100644 --- a/app/controller/admin/Database.php +++ b/app/controller/admin/Database.php @@ -27,7 +27,7 @@ class Database extends Admin { /* 数据还原 */ case 'import': //列出备份文件列表 - $path = config('data_backup_path'); + $path = \think\facade\Cache::get('system_config_data.data_backup_path'); if (!is_dir($path)) { mkdir($path, 0755, true); } @@ -63,8 +63,7 @@ class Database extends Admin { break; /* 数据备份 */ case 'export': - $Db = \think\Db::connect(); - $list = $Db->query('SHOW TABLE STATUS'); + $list = \think\facade\Db::query('SHOW TABLE STATUS'); $list = array_map('array_change_key_case', $list); $title = '数据备份'; break; @@ -72,8 +71,9 @@ class Database extends Admin { return $this->error('参数错误!'); } //渲染模板 - $this->setMeta($title); - $this->assign('list', $list); + $this->data = [ + 'list' => $list + ]; return $this->fetch($type); } diff --git a/app/model/Config.php b/app/model/Config.php index de755acb..67ebdec4 100644 --- a/app/model/Config.php +++ b/app/model/Config.php @@ -59,23 +59,26 @@ class Config extends Model { private static function parse($type, $value) { $data = []; switch ($type) { - case 'textarea': //解析数组 - $array = preg_split('/[,;\r\n]+/', trim($value, ",;\r\n")); - if (strpos($value, ':')) { - foreach ($array as $val) { - $list = explode(':', $val); - if (isset($list[2])) { - $data[] = ['key' => is_numeric($list[0]) ? (int) $list[0] : $list[0], 'value' => $list[1], 'label' => $list[1], 'other' => $list[2]]; - } else { - $data[] = ['key' => is_numeric($list[0]) ? (int) $list[0] : $list[0], 'value' => $list[1], 'label' => $list[1]]; + case 'textarea': //解析数组 + $array = preg_split('/[,;\r\n]+/', trim($value, ",;\r\n")); + if (strpos($value, ':')) { + foreach ($array as $val) { + $list = explode(':', $val); + if (isset($list[2])) { + $data[] = ['key' => is_numeric($list[0]) ? (int) $list[0] : $list[0], 'value' => $list[1], 'label' => $list[1], 'other' => $list[2]]; + } else { + $data[] = ['key' => is_numeric($list[0]) ? (int) $list[0] : $list[0], 'value' => $list[1], 'label' => $list[1]]; + } + } + } else { + foreach ($array as $key => $val) { + $data[] = ['key' => $key, 'value' => $val, 'label' => $val]; } } - } else { - foreach ($array as $key => $val) { - $data[] = ['key' => $key, 'value' => $val, 'label' => $val]; - } - } - break; + break; + default: + return $value; + break; } return $data; } diff --git a/public/uploads/files/.gitignore b/public/uploads/files/.gitignore new file mode 100644 index 00000000..c96a04f0 --- /dev/null +++ b/public/uploads/files/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore \ No newline at end of file diff --git a/public/uploads/images/.gitignore b/public/uploads/images/.gitignore new file mode 100644 index 00000000..c96a04f0 --- /dev/null +++ b/public/uploads/images/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore \ No newline at end of file diff --git a/public/uploads/media/.gitignore b/public/uploads/media/.gitignore new file mode 100644 index 00000000..c96a04f0 --- /dev/null +++ b/public/uploads/media/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore \ No newline at end of file