Added feature to hide files and cleaned the PHP a little.

This commit is contained in:
The Wobbler 2024-10-27 14:51:58 +01:00
parent a8053841a4
commit 77de8e47f2
3 changed files with 46 additions and 25 deletions

View file

@ -1,8 +1,22 @@
<?php <?php
function completeScanDir($dir) { function completeScanDir($dir) {
if (file_exists("$dir/.hide.txt")) {
$hideFile = fopen("$dir/.hide.txt", "r");
$filesToHide = fread($hideFile, filesize("$dir/.hide.txt"));
fclose($hideFile);
$filesToHide = explode("\n", $filesToHide);
}
$result = []; $result = [];
foreach(scandir($dir) as $filename) { foreach(scandir($dir) as $filename) {
if ($filename[0] === '.') continue; if ($filename[0] == '.'){
continue;
}
if (isset($filesToHide)) {
if (in_array($filename, $filesToHide)) continue;
}
$filePath = $dir . '/' . $filename; $filePath = $dir . '/' . $filename;
if (is_dir($filePath)) { if (is_dir($filePath)) {
@ -25,6 +39,10 @@
.submenu_$useableName:hover { .submenu_$useableName:hover {
display: block; display: block;
background-color: $randomColor, 0.2); background-color: $randomColor, 0.2);
}
.label_$useableName {
background-color: $randomColor, 0.2);
}\n\n"; }\n\n";
generateCSSCode($filename); generateCSSCode($filename);
@ -34,36 +52,39 @@
function generateSubmenusHTML($directory, $indentation) { function generateSubmenusHTML($directory, $indentation) {
foreach ($directory as $path => $filename) { foreach ($directory as $path => $filename) {
$useableName = str_replace("/", "_", $path); // CSS classes cant contain slashes if ($filename !== "README.txt") {
$useableName = str_replace("/", "_", $path); // CSS classes cant contain slashes
if (is_array($filename)) { if (is_array($filename)) {
$folderName = end(explode("/", $path)); $pathFragments = explode("/", $path); // i wanted to just use end(explode("/", $path)) but PHP doesnt like it.
echo " $indentation<label for='input_$useableName' class='inout hcb-label label_$useableName'>$folderName</label> $folderName = end($pathFragments);
$indentation<input type='checkbox' id='input_$useableName' class='hacked-checkbox'> echo " $indentation<label for='input_$useableName' class='inout hcb-label label_$useableName'>$folderName</label>
$indentation<div class='glass inset submenu submenu_$useableName' id='submenu_$useableName'>\n"; $indentation<input type='checkbox' id='input_$useableName' class='hacked-checkbox'>
$indentation<div class='glass inset submenu submenu_$useableName' id='submenu_$useableName'>\n";
if (file_exists("$path/README.txt")) { // show description text if there is a README.txt if (file_exists("$path/README.txt")) { // show description text if there is a README.txt
echo " $indentation<p class='tiny-text'>Beschreibung:</p>\n"; echo " $indentation<p class='tiny-text'>Beschreibung:</p>\n";
$readmeFile = fopen("$path/README.txt", "r"); $readmeFile = fopen("$path/README.txt", "r");
$readmeContent = fread($readmeFile, filesize("$path/README.txt")); $readmeContent = fread($readmeFile, filesize("$path/README.txt"));
echo " $indentation<pre class='heading-text fat-text'> echo " $indentation<pre class='heading-text fat-text'>
$readmeContent $readmeContent
$indentation</pre> $indentation</pre>
$indentation<hr>\n"; $indentation<hr>\n";
fclose($readmeFile); fclose($readmeFile);
} }
generateSubmenusHTML($filename, "$indentation "); generateSubmenusHTML($filename, "$indentation ");
echo " $indentation</div> echo " $indentation</div>
$indentation<br>\n"; $indentation<br>\n";
} else { } else {
if ($filename !== "README.txt") { if ($filename !== "README.txt") {
echo " $indentation<a href='$path' class='file-link'>$filename</a>\n"; echo " $indentation<a href='$path' class='file-link'>$filename</a>\n";
}
} }
echo " $indentation<br>\n";
} }
echo " $indentation<br>\n";
} }
} }
?> ?>

View file

@ -131,7 +131,7 @@ echo " </style>";
Evtl. könnt ihr hier etwas brauchbares finden. Evtl. könnt ihr hier etwas brauchbares finden.
</p> </p>
<div class="glass inset"> <div class="glass inset">
<br> <br>
<?= generateSubmenusHTML(completeScanDir("files"), " ") ?> <?= generateSubmenusHTML(completeScanDir("files"), " ") ?>

View file

@ -41,7 +41,7 @@ label {
} }
hr { hr {
margin: 0px 16px 0px 0px; margin: 0px 16px 16px 0px;
border: 1px solid rgba(255, 255, 255, 0.5); border: 1px solid rgba(255, 255, 255, 0.5);
} }