';
foreach ($items as $node) {
$name = htmlspecialchars($node['name'], ENT_QUOTES, 'UTF-8');
// Ordner: hat Kinder
if (isset($node['children']) && is_array($node['children'])) {
$count = self::countFiles($node['children']);
$html .= '
'
. '▶'
. ''
. ''
. $name . ' (' . $count . ')'
. '';
// Rekursiver Aufruf
$html .= self::renderTree($node['children']);
$html .= '';
} else {
// Datei
$path = $node['path'] ?? '';
$relative = str_replace(JPATH_ROOT, '', $path);
$url = Uri::root(true) . '/' . ltrim(str_replace(DIRECTORY_SEPARATOR, '/', $relative), '/');
$html .= ''
. ''
. ''
. $name . ''
. '';
}
}
$html .= '';
return $html;
}
/**
* Dateien im aktuellen Knotenbaum zählen
* @param array $items Unterknoten
* @return int Anzahl Dateien
*/
private static function countFiles(array $items): int
{
$count = 0;
foreach ($items as $node) {
if (isset($node['children']) && is_array($node['children'])) {
$count += self::countFiles($node['children']);
} else {
$count++;
}
}
return $count;
}
}