From 3f24f961b1cdeff5c60387e837ae454448bc5e1b Mon Sep 17 00:00:00 2001 From: slawkens Date: Tue, 9 Sep 2025 15:17:06 +0200 Subject: [PATCH] Possibility to override routes with plugins pages, like characters.php No need to define routes in plugin.json anymore --- system/router.php | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/system/router.php b/system/router.php index a6da5f4b..9c9ce4ad 100644 --- a/system/router.php +++ b/system/router.php @@ -94,19 +94,30 @@ $dispatcher = FastRoute\cachedDispatcher(function (FastRoute\RouteCollector $r) $routesFinal[] = ['*', $page, '__database__/' . $page, 100]; } + $routes = require SYSTEM . 'routes.php'; Plugins::clearWarnings(); - foreach (Plugins::getRoutes() as $route) { - $routesFinal[] = [$route[0], $route[1], $route[2], $route[3] ?? 1000]; + + foreach (Plugins::getRoutes() as $pluginRoute) { + + $routesFinal[] = [$pluginRoute[0], $pluginRoute[1], $pluginRoute[2], $pluginRoute[3] ?? 1000]; + + // Possibility to override routes with plugins pages, like characters.php + foreach ($routes as &$route) { + if (str_contains($pluginRoute[2], 'pages/' . $route[2])) { + $route[2] = $pluginRoute[2]; + } + } /* echo '
';
-		var_dump($route[1], $route[3], $route[2]);
+		var_dump($pluginRoute[1], $pluginRoute[3], $pluginRoute[2]);
 		echo '/
';
 */
 	}
 
-	$routes = require SYSTEM . 'routes.php';
 	foreach ($routes as $route) {
-		if (!str_contains($route[2], '__redirect__') && !str_contains($route[2], '__database__')) {
+		if (!str_contains($route[2], '__redirect__') && !str_contains($route[2], '__database__')
+			&& !str_contains($route[2], 'plugins/')
+		) {
 			if (!is_file(BASE . 'system/pages/' . $route[2])) {
 				continue;
 			}