Skip to content

Commit

Permalink
Merge branch 'master' of github.com:ZoneMinder/zoneminder
Browse files Browse the repository at this point in the history
  • Loading branch information
Isaac Connor committed Nov 12, 2024
2 parents f1cab94 + 1667e97 commit ce862d4
Showing 1 changed file with 99 additions and 48 deletions.
147 changes: 99 additions & 48 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,49 +74,84 @@ 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">
<tr>
<th class="colSelect"><input type="checkbox" name="toggleCheck" value="1" data-checkbox-name="files[]" data-on-click-this="updateFormCheckboxesByName"></th>
<th class="colName"><?php echo translate('Filename') ?></th>
<th class="colMtime"><?php echo translate('Last Modified') ?></th>
<th class="colSize"><?php echo translate('Size') ?></th>
</tr>
</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;
function get_dir_size($dir_path) {
$size = 0;
$entries = is_readable($dir_path) ? scandir($dir_path) : array();
foreach ($entries as $file) {
if ($file == '.' || $file == '..') {
continue;
}
$full_path = $dir_path.'/'.$file;
if (@is_file($full_path)) {
$stat = stat($full_path);
if (!$stat) {
ZM\Error("Fail to stat $full_path");
continue;
}
$size += $stat[7];
} else if (@is_dir($full_path)) {
$size += get_dir_size($full_path);
}
} # end foreach
return $size;
} # end function get_dir_size


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,26 +164,31 @@ function guess_material_icon($file) {
</tr>';
}
foreach ($folders as $folder) {
$url = urlencode($path.'/'.$folder);
$full_path = ($path?$path.'/':'').$folder;
$url = urlencode($full_path);
$stat = stat($full_path);
echo '
<tr>
<td class="colSelect"><input type="checkbox" name="files[]" value="'.validHtmlStr($folder).'"/></td>
<td><span class="material-icons md-18">folder</span><a href="?view=files&amp;path='.$url.'">'.validHtmlStr($folder).'</a></td>
<td class="colMtime">'.$dateTimeFormatter->format($stat[9]).'</td>
<td class="colSize">'.human_filesize(get_dir_size($full_path)).'</td>
</tr>';
}
foreach ($files as $file) {
$url = urlencode($path.'/'.$file);
$full_path = ($path?$path.'/':'').$file;
$url = urlencode($full_path);
$stat = stat($full_path);
echo '<tr><td class="colSelect"><input type="checkbox" name="files[]" value="'.validHtmlStr($file).'"/></td>
<td><span class="material-icons md-18">'.guess_material_icon($file).'</span><a href="?view=files&amp;path='.$url.'">'.validHtmlStr($file).'</a></td>
<td class="colMtime">'.$dateTimeFormatter->format($stat[9]).'</td>
<td class="colSize">'.human_filesize($stat[7]).'</td>
</tr>';
}

?>
</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 ce862d4

Please sign in to comment.