Raiju/includes/page.php
2026-10-25 06:05:42 +03:00

92 lines
2.9 KiB
PHP

<?php
/**
* Standard page template (Front Controller).
*
* Renders any page that has a JSON content file but no custom PHP template.
* Expects the following variables to be set by the router:
* $lang — language code (e.g. 'en')
* $slug — page slug (e.g. 'example')
* $basePath — '' for root URLs, '../' for language-prefixed URLs
*/
if (!isset($lang) || !isset($slug)) {
http_response_code(500);
echo 'Missing $lang or $slug';
return;
}
$_includeBase = dirname(__DIR__) . '/';
require_once $_includeBase . 'includes/page-path.php';
$contentPage = raijuPageContentKey($lang, $slug);
if ($contentPage === '') {
http_response_code(404);
include $_includeBase . '404.php';
return;
}
// Load config if not already loaded
if (!defined('SITE_LANG_DEFAULT')) {
require_once $_includeBase . 'admin/config.php';
}
if (isset($_GET['rj_agent_preview']) && is_file($_includeBase . 'includes/ai/agent/preview.php')) {
require_once $_includeBase . 'includes/ai/agent/preview.php'; // owner-only preview of an AI change set
raijuAgentPreviewBoot();
}
$_previewData = function_exists('raijuContentOverlayFor') ? raijuContentOverlayFor($contentPage) : null;
$jsonPath = raijuPageJsonPath(dirname(__DIR__), $lang, $slug);
if (!file_exists($jsonPath) && $_previewData === null) {
http_response_code(404);
include $_includeBase . '404.php';
return;
}
$data = $_previewData ?? json_decode(file_get_contents($jsonPath), true);
if (!$data) {
http_response_code(500);
echo 'Failed to parse content file';
return;
}
require_once $_includeBase . 'includes/access-guard.php';
raijuAccessEnforceMaintenance();
raijuAccessEnforcePage($contentPage, $data);
// Set template variables from JSON
$pageTitle = $data['title'] ?? ucfirst(str_replace('-', ' ', $slug));
$pageDescription = $data['description'] ?? '';
$currentLang = $lang;
$currentPage = $slug;
if (!isset($basePath)) {
$basePath = '../';
}
// Site-specific page customizations (survives core updates).
// Use this to set $pageExternalStyles, $pageExternalScripts, $pageClass, etc.
$_sitePageHook = $_includeBase . 'includes/site-page-hook.php';
if (file_exists($_sitePageHook)) {
include $_sitePageHook;
}
// Render page
include $_includeBase . 'includes/header.php';
include $_includeBase . 'includes/content-loader.php';
?>
<!-- Main Content -->
<main class="main-content" id="main-content">
<div class="content-inner">
<?php echo renderBreadcrumb($contentPage, $basePath); ?>
<?php echo renderAllSections($contentPage); ?>
<?php if (!empty($data['contactForm']) || $slug === 'contact' || $slug === 'kontakt' || $slug === 'contacto'): ?>
<?php include $_includeBase . 'includes/contact-form.php'; ?>
<?php endif; ?>
</div>
</main>
<?php
include $_includeBase . 'includes/sidebar.php';
include $_includeBase . 'includes/footer.php';