index chaange

This commit is contained in:
Flatlogic Bot 2026-05-03 09:09:47 +00:00
parent 06c852731f
commit d6a91619f4
2 changed files with 63 additions and 4 deletions

View File

@ -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();
}

View File

@ -1,14 +1,24 @@
<?php
declare(strict_types=1);
require_once __DIR__ . '/includes/page_routes.php';
$routeHelpersPath = __DIR__ . '/includes/page_routes.php';
if (is_file($routeHelpersPath)) {
require_once $routeHelpersPath;
}
if (!defined('APP_PAGE')) {
http_response_code(500);
exit('Route bootstrap is missing APP_PAGE.');
}
if (PHP_SAPI !== 'cli' && strtoupper((string)($_SERVER['REQUEST_METHOD'] ?? 'GET')) === 'GET' && !page_request_is_ajax() && isset($_GET['page'])) {
if (
function_exists('page_request_is_ajax')
&& function_exists('page_normalize_url')
&& PHP_SAPI !== 'cli'
&& strtoupper((string)($_SERVER['REQUEST_METHOD'] ?? 'GET')) === 'GET'
&& !page_request_is_ajax()
&& isset($_GET['page'])
) {
$requestUri = (string)($_SERVER['REQUEST_URI'] ?? '');
$normalized = page_normalize_url($requestUri);
if ($normalized !== '' && $normalized !== $requestUri) {
@ -18,5 +28,10 @@ if (PHP_SAPI !== 'cli' && strtoupper((string)($_SERVER['REQUEST_METHOD'] ?? 'GET
}
define('APP_ROUTE_BOOTSTRAP', true);
set_route_page_context(APP_PAGE);
if (function_exists('set_route_page_context')) {
set_route_page_context(APP_PAGE);
} else {
$_GET['page'] = APP_PAGE;
$_REQUEST['page'] = APP_PAGE;
}
require __DIR__ . '/index.php';