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:
@@ -3,11 +3,21 @@
|
||||
class CMSAPI implements PluginAPIInterface
|
||||
{
|
||||
private CodePressCMS $cms;
|
||||
private ?PluginManager $pluginManager = null;
|
||||
|
||||
public function __construct(CodePressCMS $cms)
|
||||
{
|
||||
$this->cms = $cms;
|
||||
}
|
||||
|
||||
/**
|
||||
* Inject the front-end PluginManager so content plugins can resolve
|
||||
* their own translations through the same fallback chain.
|
||||
*/
|
||||
public function setPluginManager(PluginManager $pm): void
|
||||
{
|
||||
$this->pluginManager = $pm;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current page information
|
||||
@@ -220,4 +230,55 @@ class CMSAPI implements PluginAPIInterface
|
||||
{
|
||||
return $this->cms->getAllPageTitles();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the author metadata for the current page.
|
||||
* Returns author_name, author_email and created from the page frontmatter.
|
||||
*
|
||||
* @return array Author metadata with keys: author_name, author_email, created
|
||||
*/
|
||||
public function getPageAuthor(): array
|
||||
{
|
||||
$page = $this->cms->getPage();
|
||||
$metadata = $page['metadata'] ?? [];
|
||||
return [
|
||||
'author_name' => $metadata['author_name'] ?? '',
|
||||
'author_email' => $metadata['author_email'] ?? '',
|
||||
'created' => $metadata['created'] ?? '',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the translations for a plugin in the front-end context.
|
||||
*
|
||||
* Content plugins follow the current content language. 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 current content language
|
||||
* @return array Translations [key => value]
|
||||
*/
|
||||
public function getPluginTranslations(string $pluginName, ?string $lang = null): array
|
||||
{
|
||||
if ($this->pluginManager === null) {
|
||||
return [];
|
||||
}
|
||||
$lang = $lang ?? $this->cms->currentLanguage;
|
||||
return $this->pluginManager->getPluginTranslations($pluginName, $lang, 'site');
|
||||
}
|
||||
|
||||
/**
|
||||
* Translate a single key for a plugin in the front-end context.
|
||||
*
|
||||
* @param string $key Translation key
|
||||
* @param string $pluginName Plugin directory name
|
||||
* @param string|null $lang Override language; defaults to the current content 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user