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:
2026-08-18 13:49:52 +00:00
parent 10c72de859
commit 5edc929c13
64 changed files with 3503 additions and 366 deletions
+51
View File
@@ -0,0 +1,51 @@
# Statistics Plugin
Toont bezoekersstatistieken: totaal aantal views, unieke bezoekers, landen en top pagina's op een admin-pagina.
## Plugin type
**Systeem** plugin. De plugin-output volgt de geselecteerde **admin taal** (via `AdminPluginAPI::getPluginTranslations()` met `admin.php`).
## Bestandsstructuur
```
Statistics/
├── Statistics.php # Hoofd plugin class
├── plugin.json # Plugin metadata + instellingen
├── README.md # Dit bestand
├── assets/ # Optionele CSS/JS (leeg)
└── language/ # Vertalingen
├── nl/admin.php # Nederlandse admin labels
└── en/admin.php # Engelse admin labels
```
## Functies
- **Totaal aantal views**: Totaal aantal paginaweergaven
- **Unieke bezoekers**: Aantal unieke bezoekers
- **Pagina views**: Totaal aantal pagina views
- **Landen**: Overzicht van bezoekers per land (met vlag-emoji)
- **Top pagina's**: Meest bezochte pagina's
Statistieken worden alleen getoond als Analytics is ingeschakeld in de site configuratie; anders wordt een waarschuwing getoond.
## Instellingen
Deze plugin heeft instelbare configuratie (`hasConfig: true`). Instellingen worden gedefinieerd in `plugin.json` onder `settings` en overschreven via `config.json`.
| Sleutel | Type | Standaard | Beschrijving |
|---------|------|-----------|--------------|
| `required_roles` | multi-select | `bi-manager, site-admin, admin` | Rollen die deze plugin mogen zien |
| `show_countries` | checkbox | `true` | Schakel het landen-overzicht in of uit |
| `show_top_pages` | checkbox | `true` | Schakel het top pagina's overzicht in of uit |
De label- en help-teksten voor instellingen worden vertaald via `label_key`/`help_key` (verwijst naar sleutels in `language/<lang>/admin.php`).
## Taal support
De plugin gebruikt `AdminPluginAPI::getPluginTranslations('Statistics')` om labels op te halen. Fallback chain:
1. Geselecteerde admin taal
2. Plugin `default_language` (`nl`)
3. Lege array (sleutel wordt ongewijzigd getoond)
Beschikbare sleutels staan in `language/<lang>/admin.php`. Het admin-menu label wordt vertaald via `label_key: 'menu_label'` in `getAdminMenu()`.
+60 -11
View File
@@ -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();
}
View File
+32
View File
@@ -0,0 +1,32 @@
<?php
return [
// Menu
'menu_label' => 'Statistics',
// Page
'page_title' => 'Statistics',
'total_views' => 'Total views',
'unique_visitors' => 'Unique visitors',
'page_views' => 'Page views',
'countries' => 'Countries',
'top_pages' => 'Top pages',
'no_data' => 'No data',
'col_country' => 'Country',
'col_views' => 'Views',
'col_page' => 'Page',
'analytics_disabled' => 'Analytics is disabled.',
// Settings (plugin.json label_key/help_key)
'setting_required_roles' => 'Roles allowed to view this plugin',
'setting_required_roles_help' => 'Determines which roles can access the statistics page in the admin panel. Admin always has access.',
'role_options' => [
'admin' => 'Admin',
'content-manager' => 'Content Manager',
'bi-manager' => 'BI Manager',
'site-admin' => 'Site Admin',
],
'setting_show_countries' => 'Show countries overview',
'setting_show_countries_help' => 'Enable or disable the countries overview on the statistics page.',
'setting_show_top_pages' => 'Show top pages',
'setting_show_top_pages_help' => 'Enable or disable the top pages overview.',
];
+32
View File
@@ -0,0 +1,32 @@
<?php
return [
// Menu
'menu_label' => 'Statistieken',
// Page
'page_title' => 'Statistieken',
'total_views' => 'Totaal aantal views',
'unique_visitors' => 'Unieke bezoekers',
'page_views' => 'Pagina views',
'countries' => 'Landen',
'top_pages' => "Top pagina's",
'no_data' => 'Geen data',
'col_country' => 'Land',
'col_views' => 'Views',
'col_page' => 'Pagina',
'analytics_disabled' => 'Analytics is uitgeschakeld.',
// Settings (plugin.json label_key/help_key)
'setting_required_roles' => 'Rollen die deze plugin mogen zien',
'setting_required_roles_help' => 'Bepaalt welke rollen toegang hebben tot de statistieken-pagina in het admin-paneel. Admin heeft altijd toegang.',
'role_options' => [
'admin' => 'Admin',
'content-manager' => 'Content Beheerder',
'bi-manager' => 'BI Beheerder',
'site-admin' => 'Site Admin',
],
'setting_show_countries' => 'Toon landen-overzicht',
'setting_show_countries_help' => 'Schakel het landen-overzicht in of uit op de statistieken-pagina.',
'setting_show_top_pages' => "Toon top pagina's",
'setting_show_top_pages_help' => "Schakel het top pagina's overzicht in of uit.",
];
+32 -1
View File
@@ -5,5 +5,36 @@
"description": "Bezoekersstatistieken: totaal aantal views, unieke bezoekers, landen en top pagina's.",
"type": "system",
"essential": false,
"hasConfig": true
"hasConfig": true,
"default_language": "nl",
"settings": [
{
"key": "required_roles",
"label_key": "setting_required_roles",
"help_key": "setting_required_roles_help",
"option_label_key": "role_options",
"type": "multi-select",
"default": ["bi-manager", "site-admin", "admin"],
"options": {
"admin": "Admin",
"content-manager": "Content Beheerder",
"bi-manager": "BI Beheerder",
"site-admin": "Site Admin"
}
},
{
"key": "show_countries",
"label_key": "setting_show_countries",
"help_key": "setting_show_countries_help",
"type": "checkbox",
"default": true
},
{
"key": "show_top_pages",
"label_key": "setting_show_top_pages",
"help_key": "setting_show_top_pages_help",
"type": "checkbox",
"default": true
}
]
}