diff --git a/index.php b/index.php index 4d4751e..41aec08 100644 --- a/index.php +++ b/index.php @@ -187,7 +187,51 @@ if ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on') || (isset($_SERVER[ session_start(); runtime_debug_boot_mark('boot:session_started'); -require_once __DIR__ . '/includes/page_routes.php'; +$route_helpers_path = __DIR__ . '/includes/page_routes.php'; +if (is_file($route_helpers_path)) { + require_once $route_helpers_path; +} else { + if (!function_exists('page_url')) { + function page_url(string $page = 'dashboard', array $params = []): string { + $query = $params; + $page = strtolower(trim($page)); + if ($page !== '' && $page !== 'dashboard') { + $query = ['page' => $page] + $query; + } + $queryString = http_build_query($query); + return 'index.php' . ($queryString !== '' ? '?' . $queryString : ''); + } + } + if (!function_exists('page_normalize_url')) { + function page_normalize_url(string $url): string { + $url = trim($url); + return $url !== '' ? $url : 'index.php'; + } + } + if (!function_exists('page_request_is_ajax')) { + function page_request_is_ajax(): bool { + return strtolower((string)($_SERVER['HTTP_X_REQUESTED_WITH'] ?? '')) === 'xmlhttprequest'; + } + } + if (!function_exists('page_redirect_legacy_url')) { + function page_redirect_legacy_url(): void { + // Route helper file is missing; keep serving the legacy index.php?page=... URLs. + } + } + if (!function_exists('set_route_page_context')) { + function set_route_page_context(string $page): void { + $_GET['page'] = $page; + $_REQUEST['page'] = $page; + } + } + + runtime_debug_boot_mark('boot:route_helpers_fallback'); + @file_put_contents( + __DIR__ . '/runtime_debug.log', + date('Y-m-d H:i:s') . " || [route_fallback] || Missing include={$route_helpers_path} || uri=" . ($_SERVER['REQUEST_URI'] ?? '') . PHP_EOL, + FILE_APPEND + ); +} if (!defined('APP_ROUTE_BOOTSTRAP')) { page_redirect_legacy_url(); } diff --git a/page_bootstrap.php b/page_bootstrap.php index dcf26cc..f946e63 100644 --- a/page_bootstrap.php +++ b/page_bootstrap.php @@ -1,14 +1,24 @@