Improve code

This commit is contained in:
José González 2022-06-07 13:39:58 +02:00
parent 06d9e0d137
commit 9d071982f5
2 changed files with 13 additions and 22 deletions

View File

@ -476,12 +476,6 @@ function filemanager_file_explorer(
$options=[]
) {
global $config;
// Requirements for message dialog.
ui_require_css_file('dialog');
ui_require_jquery_file('jquery-ui.min');
ui_require_jquery_file('jquery-ui_custom');
// Check for errors.
$errorOutput = (string) get_parameter('errorOutput');
// Windows compatibility.
$real_directory = str_replace('\\', '/', $real_directory);
@ -498,17 +492,7 @@ function filemanager_file_explorer(
$hack_metaconsole = (is_metaconsole() === true) ? '../../' : '';
?>
<div id="modalAlert"></div>
<script type="text/javascript">
<?php if (empty($errorOutput) === false) : ?>
$("#modalAlert").html('<?php echo io_safe_output($errorOutput); ?>');
$("#modalAlert").dialog ({
title: '<?php echo __('Error'); ?>',
resizable: false,
draggable: false,
width: 450
});
<?php endif; ?>
function show_form_create_folder() {
actions_dialog('create_folder');
$("#create_folder").css("display", "block");
@ -966,10 +950,11 @@ function filemanager_get_file_info(string $filepath)
$realpath = realpath($filepath);
$filepath = str_replace('\\', '/', $filepath);
$mimeExtend = mime_content_type($filepath);
// Windows compatibility.
$info = [
'mime' => MIME_UNKNOWN,
'mime_extend' => mime_content_type($filepath),
'mime_extend' => ($mimeExtend === false) ? '' : $mimeExtend,
'link' => 0,
'is_dir' => false,
'name' => basename($realpath),
@ -985,13 +970,13 @@ function filemanager_get_file_info(string $filepath)
'application/x-gzip',
'application/x-bzip2',
];
if (is_dir($filepath)) {
if (is_dir($filepath) === true) {
$info['mime'] = MIME_DIR;
$info['is_dir'] = true;
$info['size'] = 0;
} else if (strpos($info['mime_extend'], 'image') !== false) {
$info['mime'] = MIME_IMAGE;
} else if (in_array($info['mime_extend'], $zip_mimes)) {
} else if (in_array($info['mime_extend'], $zip_mimes) === true) {
$info['mime'] = MIME_ZIP;
} else if (strpos($info['mime_extend'], 'text') !== false) {
$info['mime'] = MIME_TEXT;

View File

@ -84,6 +84,12 @@ if (empty($file) === true || empty($hash) === true || $hash !== md5($file_raw.$c
if (empty($downloadable_file) === true || file_exists($downloadable_file) === false) {
$errorMessage = __('File is missing in disk storage. Please contact the administrator.');
// Avoid possible inifite loop with referer.
if (isset($_SERVER['HTTP_ORIGIN']) === true && $_SERVER['HTTP_REFERER'] === $_SERVER['HTTP_ORIGIN'].$_SERVER['REQUEST_URI']) {
$refererPath = ui_get_full_url('index.php');
} else {
$refererPath = $_SERVER['HTTP_REFERER'];
}
} else {
// Everything went well.
header('Content-type: aplication/octet-stream;');
@ -98,11 +104,11 @@ if (empty($file) === true || empty($hash) === true || $hash !== md5($file_raw.$c
<script type="text/javascript">
document.addEventListener('DOMContentLoaded', function () {
var refererPath = '<?php echo (($_SERVER['HTTP_REFERER']) ?? ui_get_full_url()); ?>';
var errorOutput = '<?php echo $errorMessage; ?>';
var refererPath = '<?php echo $refererPath; ?>';
var errorFileOutput = '<?php echo $errorMessage; ?>';
document.body.innerHTML = `<form action="` + refererPath + `" name="failedReturn" method="post" style="display:none;">
<input type="hidden" name="errorOutput" value="` + errorOutput + `" />
<input type="hidden" name="errorFileOutput" value="` + errorFileOutput + `" />
</form>`;
document.forms['failedReturn'].submit();