- Reorganize admin into admin/theme/default/ (views + assets) - Rename GuideNav to Navigation plugin (essential, protected) - Plugin assets support (SCSS/CSS) loaded after theme CSS - User roles: Admin, Content Manager, BI Manager, Site Admin - Role-based access control (RBAC) for admin routes and sidebar - Guide restructure: sub-topics in separate folders with sidebar nav - Dynamic breadcrumb for homepage and subdirectories - Fix theme path traversal (../../ -> ../) in admin.php - Fix CodeMirror mode load order (xml -> css -> js -> htmlmixed -> php) - Fix editor-toolbar.js null checks for plugin edit pages - Layout select from theme.json with live frontmatter update - Footer sticky at bottom of viewport (min-height: 100vh) - Breadcrumb color fix (var(--nav-font) -> var(--header-bg)) - Remove language switcher from guide pages - Update README.md and README.en.md - Bump version to 2.5.1
120 lines
3.9 KiB
PHP
120 lines
3.9 KiB
PHP
<?php
|
|
// Router file for PHP development server - clean URL support + static file serving
|
|
|
|
$requestUri = $_SERVER['REQUEST_URI'];
|
|
$parsedUrl = parse_url($requestUri);
|
|
$path = $parsedUrl['path'] ?? '/';
|
|
$path = rtrim($path, '/') ?: '/';
|
|
$publicDir = __DIR__ . '/../public';
|
|
|
|
$mimeTypes = [
|
|
'css' => 'text/css',
|
|
'js' => 'application/javascript',
|
|
'svg' => 'image/svg+xml',
|
|
'png' => 'image/png',
|
|
'jpg' => 'image/jpeg',
|
|
'ico' => 'image/x-icon',
|
|
'woff' => 'font/woff',
|
|
'woff2' => 'font/woff2',
|
|
'json' => 'application/json',
|
|
];
|
|
|
|
// Serve static files from public/
|
|
$filePath = $publicDir . $path;
|
|
if (is_file($filePath)) {
|
|
$ext = strtolower(pathinfo($filePath, PATHINFO_EXTENSION));
|
|
if (isset($mimeTypes[$ext])) {
|
|
header('Content-Type: ' . $mimeTypes[$ext]);
|
|
}
|
|
readfile($filePath);
|
|
return true;
|
|
}
|
|
|
|
// Serve theme assets from the themes/ directory (e.g. /themes/default/js/theme.js)
|
|
if (preg_match('#^/themes/([^/]+)/(.+)$#', $path, $m)) {
|
|
$themeName = $m[1];
|
|
$themeRel = $m[2];
|
|
$themesDir = __DIR__ . '/../themes';
|
|
$themeFile = $themesDir . '/' . $themeName . '/' . $themeRel;
|
|
$realThemes = realpath($themesDir);
|
|
$realFile = realpath($themeFile);
|
|
if ($realFile && $realThemes && strpos($realFile, $realThemes) === 0 && is_file($realFile)) {
|
|
$ext = strtolower(pathinfo($realFile, PATHINFO_EXTENSION));
|
|
if (isset($mimeTypes[$ext])) {
|
|
header('Content-Type: ' . $mimeTypes[$ext]);
|
|
}
|
|
readfile($realFile);
|
|
return true;
|
|
}
|
|
http_response_code(404);
|
|
return true;
|
|
}
|
|
|
|
// Serve admin theme assets (e.g. /admin/assets/css/bootstrap.min.js)
|
|
// Served from admin/theme/default/assets/
|
|
if (preg_match('#^/admin/assets/(.+)$#', $path, $m)) {
|
|
$assetPath = $m[1];
|
|
$adminThemeDir = __DIR__ . '/../admin/theme/default/assets';
|
|
$assetFile = $adminThemeDir . '/' . $assetPath;
|
|
$realAdminTheme = realpath($adminThemeDir);
|
|
$realFile = realpath($assetFile);
|
|
if ($realFile && $realAdminTheme && strpos($realFile, $realAdminTheme) === 0 && is_file($realFile)) {
|
|
$ext = strtolower(pathinfo($realFile, PATHINFO_EXTENSION));
|
|
if (isset($mimeTypes[$ext])) {
|
|
header('Content-Type: ' . $mimeTypes[$ext]);
|
|
}
|
|
readfile($realFile);
|
|
return true;
|
|
}
|
|
http_response_code(404);
|
|
return true;
|
|
}
|
|
|
|
// Serve plugin assets (e.g. /plugins/Navigation/assets/css/navigation.css)
|
|
if (preg_match('#^/plugins/([^/]+)/assets/(.+)$#', $path, $m)) {
|
|
$pluginName = $m[1];
|
|
$assetPath = $m[2];
|
|
$pluginAssetDir = __DIR__ . '/../plugins/' . $pluginName . '/assets';
|
|
$assetFile = $pluginAssetDir . '/' . $assetPath;
|
|
$realPluginDir = realpath($pluginAssetDir);
|
|
$realFile = realpath($assetFile);
|
|
if ($realFile && $realPluginDir && strpos($realFile, $realPluginDir) === 0 && is_file($realFile)) {
|
|
$ext = strtolower(pathinfo($realFile, PATHINFO_EXTENSION));
|
|
if (isset($mimeTypes[$ext])) {
|
|
header('Content-Type: ' . $mimeTypes[$ext]);
|
|
}
|
|
readfile($realFile);
|
|
return true;
|
|
}
|
|
http_response_code(404);
|
|
return true;
|
|
}
|
|
|
|
// Admin routes: /admin/login → admin.php?route=login
|
|
if (preg_match('#^/admin(?:/(.+))?$#', $path, $m)) {
|
|
$_GET['route'] = $m[1] ?? 'dashboard';
|
|
require $publicDir . '/admin.php';
|
|
return true;
|
|
}
|
|
|
|
// Language-prefixed routes: /nl/page/path → index.php?lang=nl&page=page/path
|
|
if (preg_match('#^/(nl|en)(?:/(.+))?$#', $path, $m)) {
|
|
$_GET['lang'] = $m[1];
|
|
if (isset($m[2]) && $m[2] !== '') {
|
|
if ($m[2] === 'guide') {
|
|
// /nl/guide → set guide flag, keep existing ?page= from query string
|
|
$_GET['guide'] = '1';
|
|
if (!isset($_GET['page'])) {
|
|
$_GET['page'] = '';
|
|
}
|
|
} else {
|
|
$_GET['page'] = $m[2];
|
|
}
|
|
}
|
|
require $publicDir . '/index.php';
|
|
return true;
|
|
}
|
|
|
|
// Root or unknown → index.php
|
|
require $publicDir . '/index.php';
|
|
return true; |