v2.6.1d (Lyra): Plugin i18n, plugin editor vernieuwd, media invoegen
Plugin internationalisatie: plugins hebben eigen language/ mappen. Systeem plugins volgen admin taal (admin.php), content plugins volgen content taal (site.php). Fallback chain: geselecteerd -> plugin default_language -> CMS default. PluginManager/AdminPluginAPI/CMSAPI uitgebreid met getPluginTranslations()/t(). plugin.json settings ondersteunen label_key/help_key/option_label_key. Plugin uniformiteit: alle 6 plugins hebben uniforme structuur (README.md, assets/.gitkeep, language/nl|en/). plugins/README.md herschreven. guide plugin-development.md (NL+EN) volledig herschreven. Plugin editor vernieuwd: geneste bestandsbrowser zijbalk, nieuw bestand aanmaken, uploaden naar assets/, verwijderen en verplaatsen. Nieuwe routes: plugins-file-upload, plugins-file-delete, plugins-file-move. Path-traversal bescherming + protected plugins geblokkeerd. Media invoegen in editor: nieuw /admin/media-list JSON endpoint + herbruikbare _media-modal.twig include. Plugin-context scant assets/ map. editor-toolbar.js modeMap uitgebreid voor css/scss/js/json. Plugin overzicht knoppen: alleen iconen met title/aria-label. Tests: pentest 30/30, WCAG 2.1 AA 25/25.
This commit is contained in:
@@ -20,24 +20,67 @@ class Statistics
|
||||
|
||||
public function getAdminMenu(): array
|
||||
{
|
||||
$config = $this->getPluginConfig();
|
||||
$requiredRoles = $config['required_roles'] ?? ['bi-manager', 'site-admin', 'admin'];
|
||||
|
||||
return [
|
||||
[
|
||||
'plugin' => 'Statistics',
|
||||
'route' => 'statistics',
|
||||
'label' => 'Statistieken',
|
||||
'label_key' => 'menu_label',
|
||||
'icon' => 'bi-bar-chart',
|
||||
'section' => 'general',
|
||||
'permission' => 'statistics',
|
||||
'required_roles' => $requiredRoles,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get this plugin's runtime config (defaults + overrides).
|
||||
*/
|
||||
private function getPluginConfig(): array
|
||||
{
|
||||
$pluginDir = dirname(__DIR__);
|
||||
$pluginJsonFile = $pluginDir . '/plugin.json';
|
||||
$configJsonFile = $pluginDir . '/config.json';
|
||||
|
||||
$defaults = [];
|
||||
if (file_exists($pluginJsonFile)) {
|
||||
$pluginJson = json_decode(file_get_contents($pluginJsonFile), true) ?? [];
|
||||
foreach ($pluginJson['settings'] ?? [] as $setting) {
|
||||
if (isset($setting['key'])) {
|
||||
$defaults[$setting['key']] = $setting['default'] ?? null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$overrides = [];
|
||||
if (file_exists($configJsonFile)) {
|
||||
$overrides = json_decode(file_get_contents($configJsonFile), true) ?? [];
|
||||
}
|
||||
|
||||
return array_merge($defaults, $overrides);
|
||||
}
|
||||
|
||||
public function handleAdminRoute(string $action): ?string
|
||||
{
|
||||
// System plugin: translations resolve against the admin language.
|
||||
$t = $this->api ? $this->api->getPluginTranslations('Statistics') : [];
|
||||
$tr = function (string $key) use ($t): string {
|
||||
return $t[$key] ?? $key;
|
||||
};
|
||||
|
||||
$analytics = $this->getAnalytics();
|
||||
if ($analytics === null) {
|
||||
return '<div class="alert alert-warning">Analytics is uitgeschakeld.</div>';
|
||||
return '<div class="alert alert-warning">' . htmlspecialchars($tr('analytics_disabled')) . '</div>';
|
||||
}
|
||||
|
||||
$config = $this->getPluginConfig();
|
||||
$showCountries = $config['show_countries'] ?? true;
|
||||
$showTopPages = $config['show_top_pages'] ?? true;
|
||||
|
||||
$stats = $analytics->getStats();
|
||||
$totals = $stats['totals'] ?? ['views' => 0, 'uniques' => 0, 'pages' => []];
|
||||
$countries = $stats['countries'] ?? [];
|
||||
@@ -45,14 +88,14 @@ class Statistics
|
||||
|
||||
ob_start();
|
||||
?>
|
||||
<h2 class="mb-4"><i class="bi bi-bar-chart"></i> Statistieken</h2>
|
||||
<h2 class="mb-4"><i class="bi bi-bar-chart"></i> <?= htmlspecialchars($tr('page_title')) ?></h2>
|
||||
|
||||
<div class="row g-4 mb-4">
|
||||
<div class="col-md-4">
|
||||
<div class="card stat-card shadow-sm">
|
||||
<div class="card-body d-flex justify-content-between align-items-center">
|
||||
<div>
|
||||
<h6 class="text-muted mb-1">Totaal aantal views</h6>
|
||||
<h6 class="text-muted mb-1"><?= htmlspecialchars($tr('total_views')) ?></h6>
|
||||
<h3 class="mb-0"><?= number_format($totals['views'] ?? 0, 0, ',', '.') ?></h3>
|
||||
</div>
|
||||
<i class="bi bi-eye stat-icon text-primary"></i>
|
||||
@@ -63,7 +106,7 @@ class Statistics
|
||||
<div class="card stat-card shadow-sm">
|
||||
<div class="card-body d-flex justify-content-between align-items-center">
|
||||
<div>
|
||||
<h6 class="text-muted mb-1">Unieke bezoekers</h6>
|
||||
<h6 class="text-muted mb-1"><?= htmlspecialchars($tr('unique_visitors')) ?></h6>
|
||||
<h3 class="mb-0"><?= number_format($totals['uniques'] ?? 0, 0, ',', '.') ?></h3>
|
||||
</div>
|
||||
<i class="bi bi-people stat-icon text-success"></i>
|
||||
@@ -74,7 +117,7 @@ class Statistics
|
||||
<div class="card stat-card shadow-sm">
|
||||
<div class="card-body d-flex justify-content-between align-items-center">
|
||||
<div>
|
||||
<h6 class="text-muted mb-1">Pagina views</h6>
|
||||
<h6 class="text-muted mb-1"><?= htmlspecialchars($tr('page_views')) ?></h6>
|
||||
<h3 class="mb-0"><?= number_format($totals['page_views'] ?? ($totals['views'] ?? 0), 0, ',', '.') ?></h3>
|
||||
</div>
|
||||
<i class="bi bi-file-earmark-text stat-icon text-info"></i>
|
||||
@@ -83,16 +126,18 @@ class Statistics
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php if ($showCountries || $showTopPages): ?>
|
||||
<div class="row g-4">
|
||||
<?php if ($showCountries): ?>
|
||||
<div class="col-md-6">
|
||||
<div class="card shadow-sm">
|
||||
<div class="card-header"><i class="bi bi-globe"></i> Landen</div>
|
||||
<div class="card-header"><i class="bi bi-globe"></i> <?= htmlspecialchars($tr('countries')) ?></div>
|
||||
<div class="card-body">
|
||||
<?php if (empty($countries)): ?>
|
||||
<p class="text-muted mb-0">Geen data</p>
|
||||
<p class="text-muted mb-0"><?= htmlspecialchars($tr('no_data')) ?></p>
|
||||
<?php else: ?>
|
||||
<table class="table table-sm mb-0">
|
||||
<thead><tr><th>Land</th><th>Views</th></tr></thead>
|
||||
<thead><tr><th><?= htmlspecialchars($tr('col_country')) ?></th><th><?= htmlspecialchars($tr('col_views')) ?></th></tr></thead>
|
||||
<tbody>
|
||||
<?php foreach ($countries as $country => $count): ?>
|
||||
<tr>
|
||||
@@ -106,15 +151,17 @@ class Statistics
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php if ($showTopPages): ?>
|
||||
<div class="col-md-6">
|
||||
<div class="card shadow-sm">
|
||||
<div class="card-header"><i class="bi bi-file-earmark-bar"></i> Top pagina's</div>
|
||||
<div class="card-header"><i class="bi bi-file-earmark-bar"></i> <?= htmlspecialchars($tr('top_pages')) ?></div>
|
||||
<div class="card-body">
|
||||
<?php if (empty($topPages)): ?>
|
||||
<p class="text-muted mb-0">Geen data</p>
|
||||
<p class="text-muted mb-0"><?= htmlspecialchars($tr('no_data')) ?></p>
|
||||
<?php else: ?>
|
||||
<table class="table table-sm mb-0">
|
||||
<thead><tr><th>Pagina</th><th>Views</th></tr></thead>
|
||||
<thead><tr><th><?= htmlspecialchars($tr('col_page')) ?></th><th><?= htmlspecialchars($tr('col_views')) ?></th></tr></thead>
|
||||
<tbody>
|
||||
<?php foreach ($topPages as $page => $count): ?>
|
||||
<tr>
|
||||
@@ -128,7 +175,9 @@ class Statistics
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user