Merge branch 'ent-9713-boton-para-mostrar-ruta-real-en-ventana-modal-en-filemanager' into 'develop'

Ent 9713 boton para mostrar ruta real en ventana modal en filemanager

See merge request artica/pandorafms!5298
This commit is contained in:
Diego Muñoz-Reja 2023-02-15 09:36:48 +00:00
commit f56b6435d7

View File

@ -1,4 +1,5 @@
<?php
/**
* Images File Manager functions.
*
@ -96,7 +97,7 @@ function upload_file($upload_file_or_zip, $default_real_directory, $destination_
check_login();
if (! check_acl($config['id_user'], 0, 'AW')) {
if (!check_acl($config['id_user'], 0, 'AW')) {
db_pandora_audit(
AUDIT_LOG_ACL_VIOLATION,
'Trying to access File manager'
@ -139,25 +140,8 @@ function upload_file($upload_file_or_zip, $default_real_directory, $destination_
$nombre_archivo = sprintf('%s/%s', $real_directory, $filename);
try {
$mimeContentType = mime_content_type($_FILES['file']['tmp_name']);
$fileExtension = pathinfo($_FILES['file']['name'], PATHINFO_EXTENSION);
$validFileExtension = true;
if (empty($fileExtension) === false) {
$filtered_types = array_filter(
$filterFilesType,
function ($value) use ($fileExtension) {
$mimeTypeExtensionName = explode('/', $value)[1];
return $mimeTypeExtensionName === $fileExtension;
}
);
if (empty($filtered_types) === true) {
$validFileExtension = false;
}
}
if ($validFileExtension === true && (empty($filterFilesType) === true || in_array($mimeContentType, $filterFilesType) === true)) {
if (empty($filterFilesType) === true || in_array($mimeContentType, $filterFilesType) === true) {
$result = copy($_FILES['file']['tmp_name'], $nombre_archivo);
} else {
$error_message = 'The uploaded file is not allowed. Only gif, png or jpg files can be uploaded.';
@ -240,7 +224,7 @@ function create_text_file($default_real_directory, $destination_directory)
check_login();
if (! check_acl($config['id_user'], 0, 'AW')) {
if (!check_acl($config['id_user'], 0, 'AW')) {
db_pandora_audit(
AUDIT_LOG_ACL_VIOLATION,
'Trying to access File manager'
@ -522,35 +506,36 @@ function filemanager_file_explorer(
check_opened_dialog('create_text_file');
}
<?php endif ?>
function show_upload_file() {
actions_dialog('upload_file');
$("#upload_file").css("display", "block");
check_opened_dialog('upload_file');
}
function check_opened_dialog(check_opened){
if(check_opened !== 'create_folder'){
function check_opened_dialog(check_opened) {
if (check_opened !== 'create_folder') {
if (($("#create_folder").hasClass("ui-dialog-content") && $('#create_folder').dialog('isOpen') === true)) {
$('#create_folder').dialog('close');
}
}
<?php if ($allowCreateText === true) : ?>
if(check_opened !== 'create_text_file'){
if (check_opened !== 'create_text_file') {
if (($("#create_text_file").hasClass("ui-dialog-content") && $('#create_text_file').dialog('isOpen') === true)) {
$('#create_text_file').dialog('close');
}
}
<?php endif ?>
if(check_opened !== 'upload_file'){
if (check_opened !== 'upload_file') {
if (($("#upload_file").hasClass("ui-dialog-content") && $('#upload_file').dialog('isOpen')) === true) {
$('#upload_file').dialog('close');
}
}
}
function actions_dialog(action){
$('.'+action).addClass('file_table_modal_active');
var title_action ='';
function actions_dialog(action) {
$('.' + action).addClass('file_table_modal_active');
var title_action = '';
switch (action) {
case 'create_folder':
title_action = "<?php echo __('Create a Directory'); ?>";
@ -568,7 +553,7 @@ function filemanager_file_explorer(
break;
}
$('#'+action)
$('#' + action)
.dialog({
title: title_action,
resizable: true,
@ -583,11 +568,49 @@ function filemanager_file_explorer(
minHeight: 210,
maxWidth: 800,
maxHeight: 300,
close: function () {
$('.'+action).removeClass('file_table_modal_active');
close: function() {
$('.' + action).removeClass('file_table_modal_active');
}
}).show();
}
function show_modal_real_path(path) {
if (navigator.clipboard && window.isSecureContext) <?php $secure_con = true; ?>;
else <?php $secure_con = false; ?>;
$('#modal_real_path').addClass('file_table_modal_active');
$('#real_path').empty();
$('#real_path').html(path);
title_action = "<?php echo __('Real path'); ?>";
$('#modal_real_path')
.dialog({
title: title_action,
resizable: true,
draggable: true,
modal: true,
overlay: {
opacity: 0.5,
background: "black"
},
width: 448,
minWidth: 448,
minHeight: 213,
maxWidth: 800,
maxHeight: 300,
close: function() {
$('#modal_real_path').removeClass('file_table_modal_active');
}
}).show();
$("#submit-submit").on("click", copyToClipboard);
}
function copyToClipboard() {
if (navigator.clipboard && window.isSecureContext) {
window.navigator.clipboard.writeText($("#real_path").text()).then(function() {
$('#modal_real_path').dialog('close');
});
}
}
</script>
<?php
// List files.
@ -764,6 +787,13 @@ function filemanager_file_explorer(
$data[4] .= '</a>';
}
if (is_writable($fileinfo['realpath']) === true
&& (is_dir($fileinfo['realpath']) === false || count(scandir($fileinfo['realpath'])) < 3)
&& ($readOnly === false)
) {
$data[4] .= '<a href="javascript: show_modal_real_path(`'.$fileinfo['realpath'].'`);">'.html_print_image('images/book_edit.png', true, ['style' => 'margin-top: 2px;', 'title' => __('Real path'), 'class' => 'invert_filter']).'</a>';
}
$data[4] .= '</span>';
array_push($table->data, $data);
@ -859,7 +889,7 @@ function filemanager_file_explorer(
'content' => html_print_input_file(
'file',
true,
[ 'style' => 'border:0; padding:0; width:100%' ]
['style' => 'border:0; padding:0; width:100%']
),
],
true
@ -942,6 +972,22 @@ function filemanager_file_explorer(
);
echo '</a>';
// Show Modal Real Path
$modal_real_path = "<div><b>Real path to plugin execution is:</b></div>
<div id='real_path'></div>";
if (isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == 'on' || $_SERVER['SERVER_NAME'] == 'localhost' || $_SERVER['SERVER_NAME'] == '127.0.0.1') {
$modal_real_path .= "<div style='float:right;margin: 5em 0 0 auto';>".html_print_submit_button(__('Copy'), 'submit', false, 'class="sub next"', true).'</div>';
}
html_print_div(
[
'id' => 'modal_real_path',
'class' => 'invisible',
'content' => $modal_real_path,
]
);
echo '</div>';
} else {
echo "<div style='text-align: right; width: ".$table->width."; color:#AC4444; margin-bottom:10px;'>";