💾 Downloads
Download-Ordner können einfach über TVs integriert werden.
<?php
# V 2025-11-21 (mit absolut URLs)
# Parameter
$strSORT = $modx->getOption('SORT', $scriptProperties, 'asc'); # asc oder desc
$dir = trim($modx->getOption('dir', $scriptProperties, ""), '/');
$style = $modx->getOption('style', $scriptProperties, 'legacy'); # legacy oder bs5
# Pfade vorbereiten
$fsDir = MODX_BASE_PATH . $dir; # Dateisystem-Pfad
$urlDir = rtrim(MODX_BASE_URL, '/') . '/' . $dir; # URL-Pfad (immer mit führendem /)
if (is_dir($fsDir)) {
$open_dir = opendir($fsDir);
$output = array(); // legacy
$files = array(); // bs5
while ($file = readdir($open_dir)) {
if ($file != "." && $file != "..") {
if (
strstr($file, ".pdf") ||
strstr($file, ".ics") ||
strstr($file, ".deb") ||
strstr($file, ".zip") ||
strstr($file, ".gif") ||
strstr($file, ".png") ||
strstr($file, ".jpg") ||
strstr($file, ".xz") ||
strstr($file, ".zst") ||
strstr($file, ".gz")
) {
# Dateigröße aus dem Dateisystem
$size = ceil(filesize($fsDir . "/" . $file) / 1024);
if ($style === 'bs5') {
# Bootstrap-Variante
$files[$file] = array(
'file' => $file,
'size' => $size,
);
} else {
# Legacy-Ausgabe
$o = "<ul style=\"list-style-type:square;\">";
$o .= "<li><a href=\"{$urlDir}/{$file}\" target=\"_blank\"> $file</a>";
$o .= " [" . $size . " KB]</li>";
$o .= "</ul>";
$output[$file] = $o;
}
}
}
}
closedir($open_dir);
# Bootstrap-Ausgabe
if ($style === 'bs5') {
if ($strSORT == "asc") {
ksort($files);
} else {
krsort($files);
}
$html = array();
$html[] = '<div class="download card file-list-card my-4">';
$html[] = ' <div class="card-header py-2">Downloads</div>';
$html[] = ' <ul class="list-group list-group-flush small mb-0">';
foreach ($files as $fileName => $data) {
$file = $data['file'];
$size = $data['size'];
$html[] = ' <li class="list-group-item d-flex justify-content-between align-items-center">';
$html[] = ' <a href="' . $urlDir . '/' . $file . '" target="_blank" class="file-link text-decoration-none">';
$html[] = ' <i class="bi bi-file-earmark-pdf me-2"></i> ' . $file;
$html[] = ' </a>';
$html[] = ' <span class="badge bg-secondary">' . $size . ' KB</span>';
$html[] = ' </li>';
}
$html[] = ' </ul>';
$html[] = '</div>';
return implode("\n", $html);
} else {
if ($strSORT == "asc") {
ksort($output);
} else {
krsort($output);
}
return implode('', $output);
}
}
return "Das Verzeichnis \"" . $dir . "\" existiert nicht!";
<style>
.download.card.file-list-card {
max-width: 520px;
margin: 2rem 0;
box-shadow: 0 4px 12px rgba(0,0,0,0.10);
}
.file-list-card .card-header {
background-color: #f8f9fa;
font-weight: 600;
font-size: 0.95rem;
}
.file-list-card .list-group-item {
padding: 0.35rem 0.75rem;
}
.file-list-card .file-link {
display: inline-flex;
align-items: center;
}
.file-list-card .file-link:hover {
text-decoration: underline;
}
.file-list-card .badge {
font-size: 0.75rem;
font-weight: 400;
}
</style>
