90 lines
No EOL
3 KiB
PHP
90 lines
No EOL
3 KiB
PHP
<?php
|
|
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 = [];
|
|
foreach(scandir($dir) as $filename) {
|
|
if ($filename[0] == '.'){
|
|
continue;
|
|
}
|
|
|
|
if (isset($filesToHide)) {
|
|
if (in_array($filename, $filesToHide)) continue;
|
|
}
|
|
|
|
$filePath = $dir . '/' . $filename;
|
|
|
|
if (is_dir($filePath)) {
|
|
$result[$filePath] = completeScanDir($filePath);
|
|
|
|
} else {
|
|
$result[$filePath] = $filename;
|
|
}
|
|
}
|
|
return $result;
|
|
}
|
|
|
|
function generateCSSCode($directory) {
|
|
foreach ($directory as $path => $filename) {
|
|
if (is_array($filename)) { // $filename is either a filename or an array of filenames, if so, it represents a directory
|
|
$randomColor = "rgba(" . rand(0, 255) . ", " . rand(0, 255) . ", " . rand(0, 255);
|
|
|
|
$useableName = str_replace("/", "_", $path);
|
|
echo " #input_$useableName:checked + .submenu_$useableName,
|
|
.submenu_$useableName:hover {
|
|
display: block;
|
|
background-color: $randomColor, 0.2);
|
|
}
|
|
|
|
.label_$useableName {
|
|
background-color: $randomColor, 0.2);
|
|
}\n\n";
|
|
|
|
generateCSSCode($filename);
|
|
}
|
|
}
|
|
}
|
|
|
|
function generateSubmenusHTML($directory, $indentation) {
|
|
foreach ($directory as $path => $filename) {
|
|
if ($filename !== "README.txt") {
|
|
$useableName = str_replace("/", "_", $path); // CSS classes cant contain slashes
|
|
|
|
if (is_array($filename)) {
|
|
$pathFragments = explode("/", $path); // i wanted to just use end(explode("/", $path)) but PHP doesnt like it.
|
|
$folderName = end($pathFragments);
|
|
echo " $indentation<label for='input_$useableName' class='inout hcb-label label_$useableName'>$folderName</label>
|
|
$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
|
|
echo " $indentation<p class='tiny-text'>Beschreibung:</p>\n";
|
|
|
|
$readmeFile = fopen("$path/README.txt", "r");
|
|
$readmeContent = fread($readmeFile, filesize("$path/README.txt"));
|
|
echo " $indentation<pre class='heading-text fat-text'>
|
|
$readmeContent
|
|
$indentation</pre>
|
|
$indentation<hr>\n";
|
|
fclose($readmeFile);
|
|
}
|
|
|
|
generateSubmenusHTML($filename, "$indentation ");
|
|
echo " $indentation</div>
|
|
$indentation<br>\n";
|
|
|
|
} else {
|
|
if ($filename !== "README.txt") {
|
|
echo " $indentation<a href='$path' class='file-link'>$filename</a>\n";
|
|
}
|
|
}
|
|
echo " $indentation<br>\n";
|
|
}
|
|
}
|
|
}
|
|
?>
|