* Change the style of the show file page.
This commit is contained in:
@@ -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("<html><head><meta charset='utf-8'></head><body>{$this->lang->file->fileNotFound}</body></html>");
|
||||
$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("<html><head><meta charset='utf-8'></head><body>{$this->lang->file->fileNotFound}</body></html>");
|
||||
$this->view->error = $this->lang->file->fileNotFound;
|
||||
return $this->display();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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;}
|
||||
@@ -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
|
||||
(
|
||||
<<<JAVASCRIPT
|
||||
@@ -71,9 +77,11 @@ window.setCharset = function(obj)
|
||||
let link = $.createLink('file', 'download', 'fileID={$file->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();
|
||||
|
||||
Reference in New Issue
Block a user