From ab7032c7b08f62396f5c1f117efa65bd1ae95bbb Mon Sep 17 00:00:00 2001 From: tianshujie Date: Fri, 28 Jul 2023 09:58:13 +0800 Subject: [PATCH] * Change the style of the show file page. --- module/file/control.php | 6 ++- module/file/css/download.ui.css | 5 ++ module/file/ui/download.html.php | 82 ++++++++++++++++++-------------- 3 files changed, 54 insertions(+), 39 deletions(-) create mode 100644 module/file/css/download.ui.css diff --git a/module/file/control.php b/module/file/control.php index 0ca9af6fc9..1f9cd20bac 100755 --- a/module/file/control.php +++ b/module/file/control.php @@ -124,7 +124,8 @@ class file extends control if(empty($file)) { if(defined('RUN_MODE') && RUN_MODE == 'api') return $this->send(array('status' => 'fail', 'code' => 404, 'message' => $this->lang->file->fileNotFound)); - return print("{$this->lang->file->fileNotFound}"); + $this->view->error = $this->lang->file->fileNotFound; + return $this->display(); } if(!$this->file->checkPriv($file)) @@ -174,7 +175,8 @@ class file extends control else { if(defined('RUN_MODE') && RUN_MODE == 'api') return $this->send(array('status' => 'fail', 'code' => 404, 'message' => $this->lang->file->fileNotFound)); - return print("{$this->lang->file->fileNotFound}"); + $this->view->error = $this->lang->file->fileNotFound; + return $this->display(); } } diff --git a/module/file/css/download.ui.css b/module/file/css/download.ui.css new file mode 100644 index 0000000000..ef130797ec --- /dev/null +++ b/module/file/css/download.ui.css @@ -0,0 +1,5 @@ +#imageFile > img {margin: 0 auto;} +.modal-body #errorMessage {padding: 80px 20px; text-align: center;} +.m-file-download #header, .m-file-download #mainNavbar {display: none;} +.m-file-download #mainContent .modal-header {margin-left: 0;} +#txtFile > pre {display: block; padding: 10px; border: 1px solid rgb(var(--color-gray-300-rgb)); border-radius: 4px;} diff --git a/module/file/ui/download.html.php b/module/file/ui/download.html.php index 5a2bc692bd..e00a20c6eb 100644 --- a/module/file/ui/download.html.php +++ b/module/file/ui/download.html.php @@ -12,56 +12,62 @@ declare(strict_types=1); namespace zin; -$fileContent = trim(file_get_contents($file->realPath)); -if($charset != $config->charset) +if(!empty($error)) { - $fileContent = helper::convertEncoding($fileContent, $charset . "//IGNORE", $config->charset); + div + ( + setID('errorMessage'), + $error + ); } else { - if(extension_loaded('mbstring')) + $fileContent = trim(file_get_contents($file->realPath)); + if($charset != $config->charset) { - $encoding = mb_detect_encoding($fileContent, array('ASCII', 'UTF-8', 'GB2312', 'GBK', 'BIG5')); - if($encoding != 'UTF-8') $fileContent = helper::convertEncoding($fileContent, $encoding, $config->charset); + $fileContent = helper::convertEncoding($fileContent, $charset . "//IGNORE", $config->charset); } else { - $encoding = 'UTF-8'; - if($config->default->lang == 'zh-cn') $encoding = 'GBK'; - if($config->default->lang == 'zh-tw') $encoding = 'BIG5'; - $fileContent = helper::convertEncoding($fileContent, $encoding, $config->charset); + if(extension_loaded('mbstring')) + { + $encoding = mb_detect_encoding($fileContent, array('ASCII', 'UTF-8', 'GB2312', 'GBK', 'BIG5')); + if($encoding != 'UTF-8') $fileContent = helper::convertEncoding($fileContent, $encoding, $config->charset); + } + else + { + $encoding = 'UTF-8'; + if($config->default->lang == 'zh-cn') $encoding = 'GBK'; + if($config->default->lang == 'zh-tw') $encoding = 'BIG5'; + $fileContent = helper::convertEncoding($fileContent, $encoding, $config->charset); + } } -} -modalHeader -( - set::title($lang->file->preview), - $fileType == 'txt' ? to::suffix + panel ( - div + modalHeader ( - select(setID('charset'), set::items($config->file->charset), set::value($charset), set('onchange', 'setCharset(this)')), - ) - ) : null, -); - -if($fileType == 'image') -{ - div - ( - setID('imageFile'), - h::img(set::src($this->createLink('file', 'read', "fileID={$file->id}"))) + set::title($lang->file->preview), + $fileType == 'txt' ? to::suffix + ( + div + ( + select(setID('charset'), set::name('charset'), set::items($config->file->charset), set::required(true), set::value($charset), set('onchange', 'setCharset(this)'), setClass('ml-2')), + ) + ) : null, + ), + $fileType == 'image' ? div + ( + setID('imageFile'), + h::img(set::src($this->createLink('file', 'read', "fileID={$file->id}"))) + ) : div + ( + setID('txtFile'), + h::pre(set::style(array('background-color' => 'rgb(var(--color-gray-200-rgb))')), $fileContent), + ), ); -} -else -{ - div - ( - setID('txtFile'), - h::pre(set::style(array('background-color' => 'rgba(var(--color-gray-200-rgb), 1)')), $fileContent), - ); -} +$isInModal = isInModal(); h::js ( <<id}&mouse=left'); link += link.indexOf('?') >= 0 ? '&' : '?'; link += 'charset=' + charset; - loadModal(link, $(obj).closest('.modal.show').attr('id')); + if("{$isInModal}") loadModal(link, $(obj).closest('.modal.show').attr('id')); + else loadPage(link); }; JAVASCRIPT ); +} render();