Update PHP version to 8.4 and add property hooks
This commit is contained in:
parent
32449d2edd
commit
673c02d237
14 changed files with 939 additions and 606 deletions
|
|
@ -2,13 +2,17 @@
|
|||
|
||||
// Load modular components
|
||||
require_once __DIR__ . '/constants.php';
|
||||
require_once __DIR__ . '/context.php';
|
||||
require_once __DIR__ . '/helpers.php';
|
||||
require_once __DIR__ . '/config.php';
|
||||
require_once __DIR__ . '/content.php';
|
||||
require_once __DIR__ . '/rendering.php';
|
||||
|
||||
// Create context - no more globals!
|
||||
$ctx = createContext();
|
||||
|
||||
// Check for assets in /custom/assets/ served at root level
|
||||
$assetPath = dirname(__DIR__) . '/custom/assets/' . $requestPath;
|
||||
$assetPath = dirname(__DIR__) . '/custom/assets/' . $ctx->requestPath;
|
||||
if (file_exists($assetPath) && is_file($assetPath)) {
|
||||
header('Content-Type: ' . (mime_content_type($assetPath) ?: 'application/octet-stream'));
|
||||
readfile($assetPath);
|
||||
|
|
@ -16,15 +20,15 @@ if (file_exists($assetPath) && is_file($assetPath)) {
|
|||
}
|
||||
|
||||
// Handle frontpage
|
||||
if (empty($requestPath)) {
|
||||
$contentFiles = findAllContentFiles($contentDir, $currentLang, $defaultLang);
|
||||
if (empty($ctx->requestPath)) {
|
||||
$contentFiles = findAllContentFiles($ctx->contentDir, $ctx->currentLang, $ctx->defaultLang, $ctx->availableLangs);
|
||||
if (!empty($contentFiles)) {
|
||||
renderMultipleFiles($contentFiles, $contentDir);
|
||||
renderMultipleFiles($ctx, $contentFiles, $ctx->contentDir);
|
||||
}
|
||||
}
|
||||
|
||||
// Parse and handle request
|
||||
$parsedPath = parseRequestPath($requestPath, $contentDir, $hasTrailingSlash, $currentLang, $defaultLang);
|
||||
$parsedPath = parseRequestPath($ctx);
|
||||
|
||||
switch ($parsedPath['type']) {
|
||||
case 'page':
|
||||
|
|
@ -34,7 +38,7 @@ switch ($parsedPath['type']) {
|
|||
header('Location: ' . rtrim($_SERVER['REQUEST_URI'], '/') . '/', true, 301);
|
||||
exit;
|
||||
}
|
||||
renderMultipleFiles($parsedPath['files'], $parsedPath['path']);
|
||||
renderMultipleFiles($ctx, $parsedPath['files'], $parsedPath['path']);
|
||||
|
||||
case 'file':
|
||||
// Direct file access or legacy single file
|
||||
|
|
@ -43,25 +47,26 @@ switch ($parsedPath['type']) {
|
|||
header('Location: ' . rtrim($_SERVER['REQUEST_URI'], '/') . '/', true, 301);
|
||||
exit;
|
||||
}
|
||||
renderFile($parsedPath['path']);
|
||||
renderFile($ctx, $parsedPath['path']);
|
||||
|
||||
case 'directory':
|
||||
$dir = $parsedPath['path'];
|
||||
if (file_exists("$dir/index.php")) {
|
||||
renderFile("$dir/index.php");
|
||||
renderFile($ctx, "$dir/index.php");
|
||||
}
|
||||
|
||||
// Check for page content files in this directory
|
||||
$pageContent = null;
|
||||
$contentFiles = findAllContentFiles($dir, $currentLang, $defaultLang);
|
||||
$contentFiles = findAllContentFiles($dir, $ctx->currentLang, $ctx->defaultLang, $ctx->availableLangs);
|
||||
if (!empty($contentFiles)) {
|
||||
$pageContent = implode('', array_map('renderContentFile', $contentFiles));
|
||||
}
|
||||
|
||||
// Load metadata for this directory
|
||||
$metadata = loadMetadata($dir, $currentLang, $defaultLang);
|
||||
$metadata = loadMetadata($dir, $ctx->currentLang, $ctx->defaultLang);
|
||||
|
||||
// Select list template based on metadata page_template
|
||||
$listTemplate = $ctx->templates->list;
|
||||
if (isset($metadata['page_template']) && !empty($metadata['page_template'])) {
|
||||
$templateName = $metadata['page_template'];
|
||||
// Add .php extension if not present
|
||||
|
|
@ -76,27 +81,25 @@ switch ($parsedPath['type']) {
|
|||
} elseif (file_exists($defaultTemplate)) {
|
||||
$listTemplate = $defaultTemplate;
|
||||
}
|
||||
// If template doesn't exist, fall back to default $listTemplate
|
||||
}
|
||||
|
||||
// Build list items
|
||||
$subdirs = getSubdirectories($dir);
|
||||
$langPrefix = getLangPrefix($currentLang, $defaultLang);
|
||||
|
||||
$items = array_filter(array_map(function($item) use ($dir, $requestPath, $currentLang, $defaultLang, $langPrefix) {
|
||||
$items = array_filter(array_map(function($item) use ($dir, $ctx) {
|
||||
$itemPath = "$dir/$item";
|
||||
|
||||
// Check if content exists for current language
|
||||
if ($currentLang !== $defaultLang) {
|
||||
$contentFiles = findAllContentFiles($itemPath, $currentLang, $defaultLang);
|
||||
if ($ctx->currentLang !== $ctx->defaultLang) {
|
||||
$contentFiles = findAllContentFiles($itemPath, $ctx->currentLang, $ctx->defaultLang, $ctx->availableLangs);
|
||||
if (empty($contentFiles)) return null;
|
||||
}
|
||||
|
||||
$metadata = loadMetadata($itemPath, $currentLang, $defaultLang);
|
||||
$metadata = loadMetadata($itemPath, $ctx->currentLang, $ctx->defaultLang);
|
||||
$coverImage = findCoverImage($itemPath);
|
||||
$pdfFile = findPdfFile($itemPath);
|
||||
|
||||
$title = $metadata['title'] ?? extractTitle($itemPath, $currentLang, $defaultLang) ?? $item;
|
||||
$title = $metadata['title'] ?? extractTitle($itemPath, $ctx->currentLang, $ctx->defaultLang) ?? $item;
|
||||
$date = null;
|
||||
if (isset($metadata['date'])) {
|
||||
$date = formatNorwegianDate($metadata['date']);
|
||||
|
|
@ -105,11 +108,11 @@ switch ($parsedPath['type']) {
|
|||
}
|
||||
|
||||
// Use translated slug if available, otherwise use folder name
|
||||
$urlSlug = ($currentLang !== $defaultLang && $metadata && isset($metadata['slug']))
|
||||
$urlSlug = ($ctx->currentLang !== $ctx->defaultLang && $metadata && isset($metadata['slug']))
|
||||
? $metadata['slug']
|
||||
: $item;
|
||||
|
||||
$baseUrl = $langPrefix . '/' . trim($requestPath, '/') . '/' . urlencode($urlSlug);
|
||||
$baseUrl = $ctx->langPrefix . '/' . trim($ctx->requestPath, '/') . '/' . urlencode($urlSlug);
|
||||
|
||||
return [
|
||||
'title' => $title,
|
||||
|
|
@ -126,12 +129,16 @@ switch ($parsedPath['type']) {
|
|||
include $listTemplate;
|
||||
$content = ob_get_clean();
|
||||
|
||||
// Build navigation for base template
|
||||
$navigation = buildNavigation($contentDir, $currentLang, $defaultLang);
|
||||
// Prepare all variables for base template
|
||||
$currentLang = $ctx->currentLang;
|
||||
$navigation = $ctx->navigation;
|
||||
$homeLabel = $ctx->homeLabel;
|
||||
$translations = $ctx->translations;
|
||||
$pageTitle = $metadata['title'] ?? null;
|
||||
|
||||
include $baseTemplate;
|
||||
include $ctx->templates->base;
|
||||
exit;
|
||||
|
||||
case 'not_found':
|
||||
renderTemplate("<h1>404 Not Found</h1><p>The requested resource was not found.</p>", 404);
|
||||
renderTemplate($ctx, "<h1>404 Not Found</h1><p>The requested resource was not found.</p>", 404);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue