Add plugin system and improve language handling
Add global and page-level plugin support Implement language-aware content filtering Add month translations to language files Refactor date formatting to use translations Move translation loading to plugin system Improve content availability checks
This commit is contained in:
parent
875408a27c
commit
24ee209e17
9 changed files with 196 additions and 30 deletions
83
app/plugins.php
Normal file
83
app/plugins.php
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
<?php
|
||||
|
||||
// Plugin System - manages global and page-level plugins
|
||||
|
||||
class PluginManager {
|
||||
private array $loadedPlugins = [];
|
||||
private array $globalPlugins = [];
|
||||
|
||||
public function loadGlobalPlugins(array $config): void {
|
||||
if (!isset($config['plugins']['enabled'])) return;
|
||||
|
||||
$plugins = array_map('trim', explode(',', $config['plugins']['enabled']));
|
||||
foreach ($plugins as $pluginName) {
|
||||
if (!empty($pluginName)) {
|
||||
$this->loadPlugin($pluginName, 'global');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function loadPagePlugins(?array $metadata): void {
|
||||
if (!$metadata || !isset($metadata['plugins'])) return;
|
||||
|
||||
$plugins = array_map('trim', explode(',', $metadata['plugins']));
|
||||
foreach ($plugins as $pluginName) {
|
||||
if (!empty($pluginName)) {
|
||||
$this->loadPlugin($pluginName, 'page');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function loadPlugin(string $pluginName, string $scope): bool {
|
||||
if (isset($this->loadedPlugins[$pluginName])) return true;
|
||||
|
||||
$pluginName = basename($pluginName);
|
||||
|
||||
$customPluginPath = __DIR__ . "/../custom/plugins/{$scope}/{$pluginName}.php";
|
||||
$appPluginPath = __DIR__ . "/plugins/{$scope}/{$pluginName}.php";
|
||||
|
||||
$pluginPath = file_exists($customPluginPath) ? $customPluginPath
|
||||
: (file_exists($appPluginPath) ? $appPluginPath : null);
|
||||
|
||||
if (!$pluginPath) {
|
||||
error_log("Plugin not found: {$pluginName} (scope: {$scope})");
|
||||
return false;
|
||||
}
|
||||
|
||||
require_once $pluginPath;
|
||||
|
||||
$this->loadedPlugins[$pluginName] = [
|
||||
'path' => $pluginPath,
|
||||
'scope' => $scope,
|
||||
'loaded_at' => microtime(true)
|
||||
];
|
||||
|
||||
if ($scope === 'global') {
|
||||
$this->globalPlugins[] = $pluginName;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getLoadedPlugins(): array {
|
||||
return array_keys($this->loadedPlugins);
|
||||
}
|
||||
|
||||
public function getGlobalPlugins(): array {
|
||||
return $this->globalPlugins;
|
||||
}
|
||||
|
||||
public function isLoaded(string $pluginName): bool {
|
||||
return isset($this->loadedPlugins[$pluginName]);
|
||||
}
|
||||
|
||||
public function getPluginInfo(string $pluginName): ?array {
|
||||
return $this->loadedPlugins[$pluginName] ?? null;
|
||||
}
|
||||
}
|
||||
|
||||
$GLOBALS['pluginManager'] = new PluginManager();
|
||||
|
||||
function getPluginManager(): PluginManager {
|
||||
return $GLOBALS['pluginManager'];
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue