Skip to content

Commit

Permalink
Allow hiding files/folders by full path (#1092)
Browse files Browse the repository at this point in the history
  • Loading branch information
mlocati authored Jan 23, 2025
1 parent 8a17a5b commit 8c78bc7
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions tinyfilemanager.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
$favicon_path = '';

// Files and folders to excluded from listing
// e.g. array('myfile.html', 'personal-folder', '*.php', ...)
// e.g. array('myfile.html', 'personal-folder', '*.php', '/path/to/folder', ...)
$exclude_items = array();

// Online office Docs Viewer
Expand Down Expand Up @@ -1334,7 +1334,7 @@ function get_file_path()
$folders = array();
$files = array();
$current_path = array_slice(explode("/", $path), -1)[0];
if (is_array($objects) && fm_is_exclude_items($current_path)) {
if (is_array($objects) && fm_is_exclude_items($current_path, $path)) {
foreach ($objects as $file) {
if ($file == '.' || $file == '..') {
continue;
Expand All @@ -1343,9 +1343,9 @@ function get_file_path()
continue;
}
$new_path = $path . '/' . $file;
if (@is_file($new_path) && fm_is_exclude_items($file)) {
if (@is_file($new_path) && fm_is_exclude_items($file, $new_path)) {
$files[] = $file;
} elseif (@is_dir($new_path) && $file != '.' && $file != '..' && fm_is_exclude_items($file)) {
} elseif (@is_dir($new_path) && $file != '.' && $file != '..' && fm_is_exclude_items($file, $new_path)) {
$folders[] = $file;
}
}
Expand Down Expand Up @@ -1712,7 +1712,7 @@ function getSelected($l)
$file = $_GET['view'];
$file = fm_clean_path($file, false);
$file = str_replace('/', '', $file);
if ($file == '' || !is_file($path . '/' . $file) || !fm_is_exclude_items($file)) {
if ($file == '' || !is_file($path . '/' . $file) || !fm_is_exclude_items($file, $path . '/' . $file)) {
fm_set_msg(lng('File not found'), 'error');
$FM_PATH = FM_PATH;
fm_redirect(FM_SELF_URL . '?p=' . urlencode($FM_PATH));
Expand Down Expand Up @@ -1917,7 +1917,7 @@ class="edit-file"><i class="fa fa-pencil-square"></i> <?php echo lng('AdvancedEd
$file = $_GET['edit'];
$file = fm_clean_path($file, false);
$file = str_replace('/', '', $file);
if ($file == '' || !is_file($path . '/' . $file) || !fm_is_exclude_items($file)) {
if ($file == '' || !is_file($path . '/' . $file) || !fm_is_exclude_items($file, $path . '/' . $file)) {
fm_set_msg(lng('File not found'), 'error');
$FM_PATH = FM_PATH;
fm_redirect(FM_SELF_URL . '?p=' . urlencode($FM_PATH));
Expand Down Expand Up @@ -2664,12 +2664,13 @@ function fm_get_display_path($file_path)

/**
* Check file is in exclude list
* @param string $file
* @param string $name The name of the file/folder
* @param string $path The full path of the file/folder
* @return bool
*/
function fm_is_exclude_items($file)
function fm_is_exclude_items($name, $path)
{
$ext = strtolower(pathinfo($file, PATHINFO_EXTENSION));
$ext = strtolower(pathinfo($name, PATHINFO_EXTENSION));
if (isset($exclude_items) and sizeof($exclude_items)) {
unset($exclude_items);
}
Expand All @@ -2678,7 +2679,7 @@ function fm_is_exclude_items($file)
if (version_compare(PHP_VERSION, '7.0.0', '<')) {
$exclude_items = unserialize($exclude_items);
}
if (!in_array($file, $exclude_items) && !in_array("*.$ext", $exclude_items)) {
if (!in_array($name, $exclude_items) && !in_array("*.$ext", $exclude_items) && !in_array($path, $exclude_items)) {
return true;
}
return false;
Expand Down

0 comments on commit 8c78bc7

Please sign in to comment.