New features: - ContentBackup class with ZIP backup/restore and git versioning - Admin backup & restore page (content-backup.twig) with git init/commit/log/restore - Plugin type system: system (blue) vs content (green) with visual badges - PluginAPIInterface + AdminPluginAPI for plugin architecture - Essential plugin flag (cannot edit/deactivate/delete) Improvements: - Consolidated enabled_plugins config (removed plugins.enabled) - Removed Analytics/Logging toggles from admin config page - Fixed Dashboard plugin Twig comments rendered as text - Updated 20 guide files (NL+EN): configuratie, plugins, plugin-development, core-classes, theme-json, layouts, scss-styling, admin-beheerder, nieuw-thema, architectuur - Improved accessibility test script (grep -E, min/max checks) Cleanup: - Removed unused classes: ARIAComponents, AccessibilityManager, ContentSecurityPolicy, etc. - Removed vendor packages: mustache/mustache, php-mqtt/client - Removed old templates: logs.twig, statistics.twig (now plugins) - Moved language files to language/ directory Tests: - Pentest: 30/30 passed, 0 vulnerabilities - WCAG 2.1 AA: 25/25 passed, 100% compliance
146 lines
3.5 KiB
Markdown
146 lines
3.5 KiB
Markdown
# Plugin Development
|
|
|
|
## Plugin structuur
|
|
|
|
```
|
|
plugins/MijnPlugin/
|
|
├── MijnPlugin.php # Hoofd plugin class (naam = mapnaam)
|
|
├── plugin.json # Plugin metadata
|
|
├── config.json # Optionele configuratie
|
|
└── assets/ # Optionele CSS/JS
|
|
├── css/
|
|
└── scss/
|
|
```
|
|
|
|
## plugin.json
|
|
|
|
```json
|
|
{
|
|
"name": "Mijn Plugin",
|
|
"version": "1.0.0",
|
|
"author": "Jouw Naam",
|
|
"description": "Beschrijving",
|
|
"type": "content",
|
|
"essential": false,
|
|
"hasConfig": false
|
|
}
|
|
```
|
|
|
|
### Velden
|
|
|
|
| Veld | Waarde | Beschrijving |
|
|
|------|--------|--------------|
|
|
| `name` | string | Weergavenaam in admin |
|
|
| `version` | string | Versienummer |
|
|
| `author` | string | Auteur |
|
|
| `description` | string | Korte beschrijving |
|
|
| `type` | `"system"` of `"content"` | Systeem (blauwe badge) of content (groene badge) |
|
|
| `essential` | boolean | Essentiële plugins kunnen niet worden bewerkt/verwijderd |
|
|
| `hasConfig` | boolean | Toont een Config-knop in de admin |
|
|
|
|
## Plugin class voorbeeld
|
|
|
|
```php
|
|
<?php
|
|
|
|
class MijnPlugin
|
|
{
|
|
private ?PluginAPIInterface $api = null;
|
|
|
|
public function setAPI(PluginAPIInterface $api): void
|
|
{
|
|
$this->api = $api;
|
|
}
|
|
|
|
public function getConfig(): array
|
|
{
|
|
return [
|
|
'title' => 'Mijn Plugin',
|
|
'type' => 'content',
|
|
'viewable' => true,
|
|
];
|
|
}
|
|
|
|
public function getSidebarContent(): string
|
|
{
|
|
$title = $this->api ? $this->api->getCurrentPageTitle() : '';
|
|
return '<p>Huidige pagina: ' . htmlspecialchars($title) . '</p>';
|
|
}
|
|
}
|
|
```
|
|
|
|
De plugin class wordt automatisch geladen door `PluginManager` als de plugin in `enabled_plugins` staat in `config.json`.
|
|
|
|
## CMSAPI gebruiken
|
|
|
|
De API wordt geïnjecteerd via `setAPI()`, niet via een statische methode. In de front-end context is dit een `CMSAPI` instance, in de admin context een `AdminPluginAPI` instance. Beide implementeren `PluginAPIInterface`.
|
|
|
|
```php
|
|
// Front-end API (CMSAPI)
|
|
$this->api->getCurrentPageTitle();
|
|
$this->api->getMenu();
|
|
$this->api->getConfig('site_title');
|
|
$this->api->getCurrentLanguage();
|
|
$this->api->isHomepage();
|
|
$this->api->createUrl('over-ons');
|
|
|
|
// Admin API (AdminPluginAPI)
|
|
$this->api->getConfig('analytics.enabled');
|
|
$this->api->getContentDir();
|
|
$this->api->getEnabledPlugins();
|
|
```
|
|
|
|
## Hooks
|
|
|
|
Plugins kunnen de volgende methodes implementeren voor automatiche hook-registratie:
|
|
|
|
**Actions** (geen return waarde):
|
|
|
|
- `onPageLoad` - Bij laden van een pagina
|
|
- `onBeforeRender` - Voor het renderen
|
|
- `onAfterRender` - Na het renderen
|
|
- `onSearch` - Bij zoeken
|
|
- `onMenuBuild` - Bij opbouwen menu
|
|
|
|
**Filters** (return aangepaste waarde):
|
|
|
|
- `onContentFilter` - Content filteren
|
|
- `onTitleFilter` - Titel filteren
|
|
- `onMenuFilter` - Menu filteren
|
|
|
|
## Admin integratie
|
|
|
|
Plugins kunnen eigen admin-pagina's toevoegen via `getAdminMenu()` en `handleAdminRoute()`:
|
|
|
|
```php
|
|
public function getAdminMenu(): array
|
|
{
|
|
return [
|
|
[
|
|
'plugin' => 'MijnPlugin',
|
|
'route' => 'mijn-plugin',
|
|
'label' => 'Mijn Plugin',
|
|
'icon' => 'bi-puzzle',
|
|
'section' => 'general', // of 'system'
|
|
],
|
|
];
|
|
}
|
|
|
|
public function handleAdminRoute(string $action): ?string
|
|
{
|
|
return '<h2>Mijn Plugin admin pagina</h2>';
|
|
}
|
|
```
|
|
|
|
Alleen plugins die in `enabled_plugins` staan worden in de admin sidebar getoond.
|
|
|
|
## CSS toevoegen
|
|
|
|
Plugins kunnen een CSS-URL leveren via `getCssUrl()`:
|
|
|
|
```php
|
|
public function getCssUrl(): string
|
|
{
|
|
return '/plugins/MijnPlugin/assets/css/style.css';
|
|
}
|
|
``` |