folderweb/app/config.php
Ruben a205f2cbd7 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
2025-11-25 20:19:12 +01:00

49 lines
1.6 KiB
PHP

<?php
function createContext(): Context {
// Load configuration
$configFile = file_exists(__DIR__ . '/../custom/config.ini')
? __DIR__ . '/../custom/config.ini'
: __DIR__ . '/config.ini';
$config = parse_ini_file($configFile, true);
// Load global plugins
getPluginManager()->loadGlobalPlugins($config);
// Use user content if exists and has content, otherwise fall back to demo content
$userContentDir = $_SERVER['DOCUMENT_ROOT'];
$demoContentDir = __DIR__ . '/default/content';
// Check if user content directory has actual content (more than just . and ..)
$hasUserContent = is_dir($userContentDir) && count(scandir($userContentDir) ?: []) > 2;
$contentDir = $hasUserContent ? realpath($userContentDir) : realpath($demoContentDir);
// Extract request information
$requestUri = parse_url($_SERVER['REQUEST_URI'] ?? '', PHP_URL_PATH) ?: '/';
$hasTrailingSlash = str_ends_with($requestUri, '/') && $requestUri !== '/';
$requestPath = trim($requestUri, '/');
// Resolve templates with custom fallback to defaults
$templates = new Templates(
base: resolveTemplate('base'),
page: resolveTemplate('page'),
list: resolveTemplate('list')
);
// Create base context
$ctx = new Context(
contentDir: $contentDir,
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;
}