Skip to content

Commit

Permalink
If no path given, if there is 1 storage area, default to it otherwise…
Browse files Browse the repository at this point in the history
… list available storage areas
  • Loading branch information
Isaac Connor committed Nov 9, 2024
1 parent b6a49be commit 3c6ba77
Showing 1 changed file with 65 additions and 47 deletions.
112 changes: 65 additions & 47 deletions web/skins/classic/views/files.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,34 @@
return;
}

$path = (!empty($_REQUEST['path'])) ? detaintPathAllowAbsolute($_REQUEST['path']) : ZM_DIR_EVENTS;
$storage_areas = ZM\Storage::find();
$is_ok_path = false;
foreach (ZM\Storage::find() as $storage) {
$rc = strstr($path, $storage->Path(), true);
ZM\Debug("rc from strstr ($rc) $path ".$storage->Path());
if ((false !== $rc) and ($rc == '')) {
# Must be at the beginning
$is_ok_path = true;
$path = (!empty($_REQUEST['path'])) ? detaintPathAllowAbsolute($_REQUEST['path']) : '';
if (!$path) {
if (count($storage_areas)==0) {
$path = ZM_DIR_EVENTS;
} else if (count($storage_areas)==0) {
$path = $storage_areas[0]->Path();
}
}
$path_parts = pathinfo($path);

if (@is_file($path)) {
if (output_file($path))
return;
$path = $path_parts['dirname'];
}
if ($path) {
foreach ($storage_areas as $storage) {
$rc = strstr($path, $storage->Path(), true);
if ((false !== $rc) and ($rc == '')) {
# Must be at the beginning
$is_ok_path = true;
}
}
$path_parts = pathinfo($path);

if (@is_file($path)) {
if (output_file($path))
return;
$path = $path_parts['dirname'];
}
} # end if path

$show_hidden = isset($_REQUEST['show_hidden']) ? $_REQUEST['show_hidden'] : 0;

function guess_material_icon($file) {
Expand All @@ -63,24 +74,30 @@ function guess_material_icon($file) {
<div id="content">
<form id="filesForm" name="filesForm" method="post" action="?view=files&path=<?php echo urlencode($path); ?>">
<?php
if (!$is_ok_path) {
echo '<div class="error">Path is not valid. Path must be below a designated Storage area.<br/></div>';
} else {
$exploded = explode('/', $path);
ZM\Debug(print_r($exploded, true));
$array = array();
$files = array();
$folders = array();
$parent = '';
for ($i = 0; $i < count($exploded); $i++) {
if ($exploded[$i])
$parent = $parent . '/' . $exploded[$i];
$parent_enc = urlencode($parent);
$array[] = "<a href='?view=files&amp;path={$parent_enc}'>" . validHtmlStr($exploded[$i]) . '</a>';
}
array_pop($exploded);

$parent = implode('/', $exploded);
$sep = '<i class="bread-crumb"> / </i>';
echo implode($sep, $array).'<br/>';
if ($path) {
if (!$is_ok_path) {
echo '<div class="error">Path is not valid. Path must be below a designated Storage area.<br/></div>';
$path = '';
} else {
$exploded = explode('/', $path);
$array = array();
for ($i = 0; $i < count($exploded); $i++) {
if ($exploded[$i])
$parent = $parent . '/' . $exploded[$i];
$parent_enc = urlencode($parent);
$array[] = "<a href='?view=files&amp;path={$parent_enc}'>" . validHtmlStr($exploded[$i]) . '</a>';
}
array_pop($exploded);

$parent = implode('/', $exploded);
$sep = '<i class="bread-crumb"> / </i>';
echo implode($sep, $array).'<br/>';
}
} # end if path
?>
<table id="contentTable" class="major">
<thead class="thead-highlight">
Expand All @@ -91,21 +108,25 @@ function guess_material_icon($file) {
</thead>
<tbody>
<?php
$files = array();
$folders = array();
$entries = is_readable($path) ? scandir($path) : array();
foreach ($entries as $file) {
if ($file == '.' || $file == '..') {
continue;
}
if (!$show_hidden && substr($file, 0, 1) === '.') {
continue;
if ($path) {
$entries = is_readable($path) ? scandir($path) : array();
foreach ($entries as $file) {
if ($file == '.' || $file == '..') {
continue;
}
if (!$show_hidden && substr($file, 0, 1) === '.') {
continue;
}
$full_path = $path.'/'.$file;
if (@is_file($full_path)) {
$files[] = $file;
} else if (@is_dir($full_path)) {
$folders[] = $file;
}
}
$full_path = $path.'/'.$file;
if (@is_file($full_path)) {
$files[] = $file;
} else if (@is_dir($full_path)) {
$folders[] = $file;
} else { # ! path
foreach ($storage_areas as $storage) {
$folders[] = $storage->Path();
}
}
natcasesort($files);
Expand All @@ -118,7 +139,7 @@ function guess_material_icon($file) {
</tr>';
}
foreach ($folders as $folder) {
$url = urlencode($path.'/'.$folder);
$url = urlencode(($path?$path.'/':'').$folder);
echo '
<tr>
<td class="colSelect"><input type="checkbox" name="files[]" value="'.validHtmlStr($folder).'"/></td>
Expand All @@ -135,9 +156,6 @@ function guess_material_icon($file) {
?>
</tbody>
</table>
<?php
} # end if is_ok_path
?>
<div id="contentButtons">
<button type="submit" name="action" value="delete" disabled="disabled">
<?php echo translate('Delete') ?>
Expand Down

0 comments on commit 3c6ba77

Please sign in to comment.