Letzte Version

This commit is contained in:
Thomas Spohr
2025-08-13 08:35:35 +02:00
parent 266fd69afb
commit 33fa9c8f94
10 changed files with 149 additions and 84 deletions

View File

@@ -9,7 +9,6 @@ class ModEisAnzeigeHelper
/**
* Holt alle PDF-Elemente aus der Datenbank
*/
public static function getItems(): array
{
/** @var DatabaseDriver $db */
@@ -35,7 +34,6 @@ class ModEisAnzeigeHelper
/**
* Hauptfunktion zum Rendern des Baums
*/
public static function renderTree(array $items, int $parentId = null): string
{
if (!isset($items[$parentId])) {
@@ -47,19 +45,21 @@ class ModEisAnzeigeHelper
foreach ($items[$parentId] as $item) {
$isFolder = (bool) $item['is_folder'];
$title = htmlspecialchars($item['title'] ?: $item['name']);
// $path = htmlspecialchars($item['path'] ?? '');
$path = htmlspecialchars(self::convertToRelativeUrl($item['path'] ?? ''));
$path = self::convertToRelativeUrl($item['path'] ?? '');
// Erweiterung .pdf im Titel entfernen (nur Anzeige, nicht Link)
$displayTitle = preg_replace('/\.pdf$/i', '', $title);
if ($isFolder) {
$fileCount = self::countFilesRecursive($items, $item['id']);
$html .= '<li class="folder">';
$html .= '<span class="toggle">▶</span>';
$html .= '<span class="folder-icon"></span>' . $title . ' <small>(' . $fileCount . ')</small>';
$html .= '<span class="folder-icon">📁</span> ' . $displayTitle . ' <small>(' . $fileCount . ')</small>';
$html .= self::renderTree($items, $item['id']);
$html .= '</li>';
} else {
$html .= '<li class="file">';
$html .= '<span class="file-icon"></span><a class="file-link" href="' . $path . '">' . $title . '</a>';
$html .= '<span class="file-icon">📄</span><a class="file-link" href="' . htmlspecialchars($path) . '" title="' . $title . '">' . $displayTitle . '</a>';
$html .= '</li>';
}
}
@@ -68,22 +68,25 @@ class ModEisAnzeigeHelper
return $html;
}
/**
* Konvertiert absoluten Serverpfad in URL
*/
private static function convertToRelativeUrl(string $fullPath): string
{
// <== HIER den absoluten Pfad zu deinem Webroot anpassen
$webRoot = '/var/www/vhosts/ts-it24.net/stbv.ts-it24.net';
$webBase = ''; // ggf. '/subdir' falls Joomla in Unterordner
// Absoluter Serverpfad zum Joomla-Root
$webRoot = '/var/www/joomla';
$webBase = ''; // ggf. '/unterordner', wenn Joomla in Subdir
if (str_starts_with($fullPath, $webRoot)) {
return $webBase . str_replace($webRoot, '', $fullPath);
$relativePath = str_replace($webRoot, '', $fullPath);
// Leerzeichen und Sonderzeichen escapen
$relativePath = implode('/', array_map('rawurlencode', explode('/', $relativePath)));
return rtrim(\JUri::root(), '/') . $webBase . $relativePath;
}
return $fullPath; // Fallback: Original verwenden
return $fullPath; // Fallback
}
/**
* Zählt alle PDF-Dateien unterhalb eines Ordners rekursiv
*/
@@ -96,7 +99,7 @@ class ModEisAnzeigeHelper
}
foreach ($items[$parentId] as $item) {
if ((bool)$item['is_folder']) {
if ((bool) $item['is_folder']) {
$count += self::countFilesRecursive($items, $item['id']);
} else {
$count++;