Skip to content

Commit

Permalink
Add configurable path display modes for better privacy and clarity (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
DannyDaemonic committed Apr 26, 2023
1 parent 8194249 commit 8486c7a
Showing 1 changed file with 34 additions and 2 deletions.
36 changes: 34 additions & 2 deletions tinyfilemanager.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@
// Doc - https://www.php.net/manual/en/function.date.php
$datetime_format = 'm/d/Y g:i A';

// Path display mode when viewing file information
// 'full' => show full path
// 'relative' => show path relative to root_path
// 'host' => show path on the host
$path_display_mode = 'full';

// Allowed file extensions for create and rename files
// e.g. 'txt,html,css,js'
$allowed_file_extensions = '';
Expand Down Expand Up @@ -1684,7 +1690,8 @@ function getSelected($l) {
<div class="col-12">
<p class="break-word"><b><?php echo lng($view_title) ?> "<?php echo fm_enc(fm_convert_win($file)) ?>"</b></p>
<p class="break-word">
<strong>Full path:</strong> <?php echo fm_enc(fm_convert_win($file_path)) ?><br>
<?php $display_path = fm_get_display_path($file_path); ?>
<strong><?php echo $display_path['label']; ?>:</strong> <?php echo $display_path['path']; ?><br>
<strong>File size:</strong> <?php echo ($filesize_raw <= 1000) ? "$filesize_raw bytes" : $filesize; ?><br>
<strong>MIME-type:</strong> <?php echo $mime_type ?><br>
<?php
Expand Down Expand Up @@ -1943,7 +1950,8 @@ class="edit-file"><i class="fa fa-pencil-square-o"></i> <?php echo lng('Advanced
</h6>
<div class="card-body">
<p class="card-text">
Full path: <?php echo $file_path ?><br>
<?php $display_path = fm_get_display_path($file_path); ?>
<?php echo $display_path['label']; ?>: <?php echo $display_path['path']; ?><br>
</p>
<form action="" method="post">
<input type="hidden" name="p" value="<?php echo fm_enc(FM_PATH) ?>">
Expand Down Expand Up @@ -2514,6 +2522,30 @@ function fm_get_parent_path($path)
return false;
}

function fm_get_display_path($file_path)
{
global $path_display_mode, $root_path, $root_url;
switch ($path_display_mode) {
case 'relative':
return array(
'label' => 'Path',
'path' => fm_enc(fm_convert_win(str_replace($root_path, '', $file_path)))
);
case 'host':
$relative_path = str_replace($root_path, '', $file_path);
return array(
'label' => 'Host Path',
'path' => fm_enc(fm_convert_win('/' . $root_url . '/' . ltrim(str_replace('\\', '/', $relative_path), '/')))
);
case 'full':
default:
return array(
'label' => 'Full Path',
'path' => fm_enc(fm_convert_win($file_path))
);
}
}

/**
* Check file is in exclude list
* @param string $file
Expand Down

0 comments on commit 8486c7a

Please sign in to comment.