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.
137 lines
3.8 KiB
PHP
137 lines
3.8 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Lightweight API wrapper for plugins in the admin context.
|
|
* Provides read-only access to the site config (no CMS instance needed).
|
|
*/
|
|
class AdminPluginAPI implements PluginAPIInterface
|
|
{
|
|
private array $config;
|
|
private string $projectRoot;
|
|
private string $adminLanguage;
|
|
private ?PluginManager $pluginManager = null;
|
|
|
|
public function __construct(array $siteConfig, string $projectRoot = '')
|
|
{
|
|
$this->config = $siteConfig;
|
|
$this->projectRoot = $projectRoot !== '' ? $projectRoot : dirname(__DIR__, 3);
|
|
$this->adminLanguage = $siteConfig['admin_language']
|
|
?? ($siteConfig['language']['default'] ?? 'nl');
|
|
}
|
|
|
|
/**
|
|
* Inject the admin PluginManager so plugins can resolve their own
|
|
* translations through the same fallback chain.
|
|
*/
|
|
public function setPluginManager(PluginManager $pm): void
|
|
{
|
|
$this->pluginManager = $pm;
|
|
}
|
|
|
|
/**
|
|
* Get configuration value using dot notation.
|
|
*/
|
|
public function getConfig(string $key, $default = null)
|
|
{
|
|
$keys = explode('.', $key);
|
|
$value = $this->config;
|
|
|
|
foreach ($keys as $k) {
|
|
if (!is_array($value) || !isset($value[$k])) {
|
|
return $default;
|
|
}
|
|
$value = $value[$k];
|
|
}
|
|
|
|
return $value;
|
|
}
|
|
|
|
/**
|
|
* Get the project root directory.
|
|
*/
|
|
public function getProjectRoot(): string
|
|
{
|
|
return $this->projectRoot;
|
|
}
|
|
|
|
/**
|
|
* Get the content directory path.
|
|
*/
|
|
public function getContentDir(): string
|
|
{
|
|
return $this->config['content_dir'] ?? ($this->projectRoot . '/content');
|
|
}
|
|
|
|
/**
|
|
* Get the plugins directory path.
|
|
*/
|
|
public function getPluginsDir(): string
|
|
{
|
|
return $this->projectRoot . '/plugins';
|
|
}
|
|
|
|
/**
|
|
* Get the list of enabled plugins.
|
|
*/
|
|
public function getEnabledPlugins(): array
|
|
{
|
|
return $this->config['enabled_plugins'] ?? [];
|
|
}
|
|
|
|
/**
|
|
* Get the version info from version.php.
|
|
*/
|
|
public function getVersionInfo(): array
|
|
{
|
|
$versionFile = $this->projectRoot . '/version.php';
|
|
if (file_exists($versionFile)) {
|
|
$data = include $versionFile;
|
|
if (is_array($data)) {
|
|
return $data;
|
|
}
|
|
}
|
|
return ['version' => '0.0.0'];
|
|
}
|
|
|
|
/**
|
|
* Get the active admin language code (e.g. 'nl', 'en').
|
|
* System plugins should use this to resolve their translations.
|
|
*/
|
|
public function getAdminLanguage(): string
|
|
{
|
|
return $this->adminLanguage;
|
|
}
|
|
|
|
/**
|
|
* Get the translations for a plugin in the admin context.
|
|
*
|
|
* Fallback chain (handled by PluginManager):
|
|
* requested language -> plugin default_language -> empty array.
|
|
*
|
|
* @param string $pluginName Plugin directory name
|
|
* @param string|null $lang Override language; defaults to the active admin language
|
|
* @return array Translations [key => value]
|
|
*/
|
|
public function getPluginTranslations(string $pluginName, ?string $lang = null): array
|
|
{
|
|
if ($this->pluginManager === null) {
|
|
return [];
|
|
}
|
|
$lang = $lang ?? $this->adminLanguage;
|
|
return $this->pluginManager->getPluginTranslations($pluginName, $lang, 'admin');
|
|
}
|
|
|
|
/**
|
|
* Translate a single key for a plugin in the admin context.
|
|
*
|
|
* @param string $key Translation key
|
|
* @param string $pluginName Plugin directory name
|
|
* @param string|null $lang Override language; defaults to the active admin language
|
|
* @return string Translated string, or $key if not found
|
|
*/
|
|
public function t(string $key, string $pluginName, ?string $lang = null): string
|
|
{
|
|
$t = $this->getPluginTranslations($pluginName, $lang);
|
|
return $t[$key] ?? $key;
|
|
}
|
|
} |