Version mit sicherem Download

This commit is contained in:
Thomas Spohr
2025-08-18 11:34:09 +02:00
parent 33fa9c8f94
commit bd7e720c47
13 changed files with 43 additions and 35 deletions

BIN
mod_pdf_tree/.DS_Store vendored

Binary file not shown.

BIN
mod_pdf_tree/Archiv.zip Normal file

Binary file not shown.

View File

@@ -2,6 +2,7 @@
defined('_JEXEC') or die;
use Joomla\CMS\Factory;
use Joomla\CMS\Router\Route;
use Joomla\Database\DatabaseDriver;
class ModEisAnzeigeHelper
@@ -21,13 +22,18 @@ class ModEisAnzeigeHelper
$rows = $db->setQuery($query)->loadAssocList();
// Nach parent_id gruppieren
// Nach parent_id gruppieren und alphabetisch sortieren
$grouped = [];
foreach ($rows as $row) {
$pid = $row['parent_id'] === null ? null : (int) $row['parent_id'];
$grouped[$pid][] = $row;
}
// Sortieren nach name (case-insensitive)
foreach ($grouped as &$group) {
usort($group, fn($a, $b) => strcasecmp($a['name'], $b['name']));
}
return $grouped;
}
@@ -44,22 +50,31 @@ class ModEisAnzeigeHelper
foreach ($items[$parentId] as $item) {
$isFolder = (bool) $item['is_folder'];
$title = htmlspecialchars($item['title'] ?: $item['name']);
$path = self::convertToRelativeUrl($item['path'] ?? '');
$rawName = $item['title'] ?: $item['name'];
$fileId = (int) $item['id'];
// Erweiterung .pdf im Titel entfernen (nur Anzeige, nicht Link)
$displayTitle = preg_replace('/\.pdf$/i', '', $title);
// Dateiendung .pdf entfernen
$displayName = preg_replace('/\.pdf$/i', '', $rawName);
$displayName = htmlspecialchars($displayName);
if ($isFolder) {
$fileCount = self::countFilesRecursive($items, $item['id']);
$html .= '<li class="folder">';
$html .= '<span class="toggle">▶</span>';
$html .= '<span class="folder-icon">📁</span> ' . $displayTitle . ' <small>(' . $fileCount . ')</small>';
$html .= '📁 ' . $displayName . ' <small>(' . $fileCount . ')</small>';
$html .= self::renderTree($items, $item['id']);
$html .= '</li>';
} else {
$link = Route::_('index.php?option=com_eis&task=download.download&id=' . $fileId);
// Tooltip mit Dateigröße
$tooltip = '';
if (!empty($item['path']) && file_exists($item['path'])) {
$size = filesize($item['path']);
$tooltip = ' title="Größe: ' . self::formatFileSize($size) . '"';
}
$html .= '<li class="file">';
$html .= '<span class="file-icon">📄</span><a class="file-link" href="' . htmlspecialchars($path) . '" title="' . $title . '">' . $displayTitle . '</a>';
$html .= '📄 <a class="file-link" href="' . $link . '"' . $tooltip . '>' . $displayName . '</a>';
$html .= '</li>';
}
}
@@ -68,25 +83,6 @@ class ModEisAnzeigeHelper
return $html;
}
/**
* Konvertiert absoluten Serverpfad in URL
*/
private static function convertToRelativeUrl(string $fullPath): string
{
// Absoluter Serverpfad zum Joomla-Root
$webRoot = '/var/www/joomla';
$webBase = ''; // ggf. '/unterordner', wenn Joomla in Subdir
if (str_starts_with($fullPath, $webRoot)) {
$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
}
/**
* Zählt alle PDF-Dateien unterhalb eines Ordners rekursiv
*/
@@ -108,4 +104,20 @@ class ModEisAnzeigeHelper
return $count;
}
/**
* Formatierte Dateigröße für Tooltip
*/
private static function formatFileSize(int $bytes): string
{
if ($bytes >= 1073741824) {
return number_format($bytes / 1073741824, 2) . ' GB';
} elseif ($bytes >= 1048576) {
return number_format($bytes / 1048576, 1) . ' MB';
} elseif ($bytes >= 1024) {
return number_format($bytes / 1024, 0) . ' KB';
} else {
return $bytes . ' B';
}
}
}

View File

@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<extension type="module" version="5.0" client="site" method="upgrade">
<name>EIS-Anzeige</name>
<author>Ich</author>
<author>Thomas Spohr</author>
<version>1.0.1</version>
<description>Anzeige des PDF-Baums mit Dokumentenzählung und Expand/Collapse-All</description>
<files>

Binary file not shown.

View File

@@ -10,8 +10,6 @@
border: 1px solid #ddd;
border-radius: 6px;
box-shadow: 0 4px 10px rgba(0,0,0,0.05);
width: 100%;
max-width: 100%; /* Oder: max-width: 1400px; */
}
.pdf-tree-container {
@@ -35,7 +33,6 @@
border: none;
display: block;
}
.pdf-tree {
list-style: none;
margin: 0;
@@ -48,7 +45,6 @@
display: none;
}
.pdf-tree li {
margin: 0.3em 0;
}