-
Notifications
You must be signed in to change notification settings - Fork 0
/
indxr_summary.php
78 lines (68 loc) · 2.6 KB
/
indxr_summary.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
// Function to check if an item is hidden based on the $hiddenItems configuration
function isHiddenItem($item, $hiddenItems)
{
foreach ($hiddenItems as $pattern) {
if (fnmatch($pattern, $item)) {
return true;
}
}
return false;
}
// Count the number of visible directories and files
$visibleDirectories = array_filter($directories, function ($dir) use (
$hiddenItems
) {
return !isHiddenItem($dir, $hiddenItems);
});
$visibleFiles = array_filter($files, function ($file) use ($hiddenItems) {
return !isHiddenItem($file, $hiddenItems);
});
// Skip the . and .. directories
$visibleDirectories = array_diff($visibleDirectories, [".", ".."]);
$numberOfVisibleDirectories = count($visibleDirectories);
$numberOfVisibleFiles = count($visibleFiles);
$totalVisibleObjects = $numberOfVisibleDirectories + $numberOfVisibleFiles;
if ($totalVisibleObjects === 0) {
echo '<span class="indxr-summary-text">0 objects found</span>';
} else {
echo '<span class="indxr-summary-text">' .
$totalVisibleObjects .
" " .
($totalVisibleObjects === 1 ? "object" : "objects") .
" found";
if ($numberOfVisibleDirectories > 0) {
echo ", " .
$numberOfVisibleDirectories .
" director" .
($numberOfVisibleDirectories === 1 ? "y" : "ies");
}
// Display number of files and total size only if there are visible files
if (!empty($visibleFiles)) {
$totalSizeInKB =
array_sum(array_map("filesize", $visibleFiles)) / 1024;
if ($totalSizeInKB > 100) {
$totalSizeInMB = $totalSizeInKB / 1024;
echo ", " .
$numberOfVisibleFiles .
" file" .
($numberOfVisibleFiles === 1 ? "" : "s") .
", " .
round($totalSizeInMB, 2) .
" MB total";
} else {
echo ", " .
$numberOfVisibleFiles .
" file" .
($numberOfVisibleFiles === 1 ? "" : "s") .
", " .
round($totalSizeInKB, 2) .
" KB total";
}
}
// Display the version string & misc info
$indxrversion = "v. 0.3.2"; // Update this version string as needed
$indxrdesigned = "Designed for navigation and content organization";
echo "</span>";
}
?>