Remove language-specific content handling

Refactor to use plugin system for language support

Remove hardcoded language features from core

Move language handling to plugin system

Improve content file discovery

Simplify context creation

Add plugin system documentation

Implement hook system for extensibility

Add template variable hook

Add context storage for plugins

Improve error handling

Refactor rendering logic

Improve list view sorting

Add support for custom list templates

Improve metadata handling

Add plugin system reference documentation
This commit is contained in:
Ruben 2025-11-25 20:19:12 +01:00
parent 24ee209e17
commit a205f2cbd7
8 changed files with 524 additions and 315 deletions

View file

@ -10,9 +10,6 @@ function createContext(): Context {
// Load global plugins
getPluginManager()->loadGlobalPlugins($config);
$defaultLang = $config['languages']['default'] ?? 'no';
$availableLangs = array_map('trim', explode(',', $config['languages']['available'] ?? 'no'));
// Use user content if exists and has content, otherwise fall back to demo content
$userContentDir = $_SERVER['DOCUMENT_ROOT'];
$demoContentDir = __DIR__ . '/default/content';
@ -27,15 +24,6 @@ function createContext(): Context {
$hasTrailingSlash = str_ends_with($requestUri, '/') && $requestUri !== '/';
$requestPath = trim($requestUri, '/');
// Extract language from URL
$currentLang = $defaultLang;
$pathParts = explode('/', $requestPath);
if (!empty($pathParts[0]) && in_array($pathParts[0], $availableLangs) && $pathParts[0] !== $defaultLang) {
$currentLang = $pathParts[0];
array_shift($pathParts);
$requestPath = implode('/', $pathParts);
}
// Resolve templates with custom fallback to defaults
$templates = new Templates(
base: resolveTemplate('base'),
@ -43,13 +31,19 @@ function createContext(): Context {
list: resolveTemplate('list')
);
return new Context(
// Create base context
$ctx = new Context(
contentDir: $contentDir,
currentLang: $currentLang,
defaultLang: $defaultLang,
availableLangs: $availableLangs,
templates: $templates,
requestPath: $requestPath,
hasTrailingSlash: $hasTrailingSlash
);
// Store globally for plugins
$GLOBALS['ctx'] = $ctx;
// Let plugins modify context (e.g., extract language from URL)
$ctx = Hooks::apply(Hook::CONTEXT_READY, $ctx, $config);
return $ctx;
}