Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exclude multiple items from multiple users #1049

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 24 additions & 5 deletions tinyfilemanager.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@
// e.g. array('myfile.html', 'personal-folder', '*.php', ...)
$exclude_items = array();

// Users excluded from listing excluded files and folders
// e.g. 'username' => array('myfile.html', 'personal-folder', '*.php', ...)
$exclude_items_users = array(
'username' => array(),
);

// Online office Docs Viewer
// Availabe rules are 'google', 'microsoft' or false
// Google => View documents using Google Docs Viewer
Expand Down Expand Up @@ -423,6 +429,7 @@ function getClientIP() {
defined('FM_FILE_EXTENSION') || define('FM_FILE_EXTENSION', $allowed_file_extensions);
defined('FM_UPLOAD_EXTENSION') || define('FM_UPLOAD_EXTENSION', $allowed_upload_extensions);
defined('FM_EXCLUDE_ITEMS') || define('FM_EXCLUDE_ITEMS', (version_compare(PHP_VERSION, '7.0.0', '<') ? serialize($exclude_items) : $exclude_items));
defined('FM_EXCLUDE_ITEMS_USERS') || define('FM_EXCLUDE_ITEMS_USERS', (version_compare(PHP_VERSION, '7.0.0', '<') ? serialize($exclude_items_users) : $exclude_items_users));
defined('FM_DOC_VIEWER') || define('FM_DOC_VIEWER', $online_viewer);
define('FM_READONLY', $global_readonly || ($use_auth && !empty($readonly_users) && isset($_SESSION[FM_SESSION_ID]['logged']) && in_array($_SESSION[FM_SESSION_ID]['logged'], $readonly_users)));
define('FM_IS_WIN', DIRECTORY_SEPARATOR == '\\');
Expand Down Expand Up @@ -1647,7 +1654,10 @@ function getSelected($l) {
$file = $_GET['view'];
$file = fm_clean_path($file, false);
$file = str_replace('/', '', $file);
if ($file == '' || !is_file($path . '/' . $file) || in_array($file, $GLOBALS['exclude_items'])) {
if ($file == '' || !is_file($path . '/' . $file) || in_array($file, $GLOBALS['exclude_items']) || (
isset($exclude_items_users[$_SESSION[FM_SESSION_ID]['logged']]) &&
in_array($file, $exclude_items_users[$_SESSION[FM_SESSION_ID]['logged']]))
){
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 @@ -1846,7 +1856,10 @@ class="edit-file"><i class="fa fa-pencil-square-o"></i> <?php echo lng('Advanced
$file = $_GET['edit'];
$file = fm_clean_path($file, false);
$file = str_replace('/', '', $file);
if ($file == '' || !is_file($path . '/' . $file) || in_array($file, $GLOBALS['exclude_items'])) {
if ($file == '' || !is_file($path . '/' . $file) || in_array($file, $GLOBALS['exclude_items']) || (
isset($exclude_items_users[$_SESSION[FM_SESSION_ID]['logged']]) &&
in_array($file, $exclude_items_users[$_SESSION[FM_SESSION_ID]['logged']]))
){
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 @@ -2569,13 +2582,19 @@ function fm_is_exclude_items($file) {
}

$exclude_items = FM_EXCLUDE_ITEMS;
$exclude_items_users = FM_EXCLUDE_ITEMS_USERS;
if (version_compare(PHP_VERSION, '7.0.0', '<')) {
$exclude_items = unserialize($exclude_items);
$exclude_items_users = unserialize($exclude_items_users);
}
if (!in_array($file, $exclude_items) && !in_array("*.$ext", $exclude_items)) {
return true;
if (in_array($file, $exclude_items) || in_array("*.$ext", $exclude_items) || (
isset($exclude_items_users[$_SESSION[FM_SESSION_ID]['logged']]) && (
in_array($file, $exclude_items_users[$_SESSION[FM_SESSION_ID]['logged']]) ||
in_array("*.$ext", $exclude_items_users[$_SESSION[FM_SESSION_ID]['logged']])))
){
return false;
}
return false;
return true;
}

/**
Expand Down