From 4f9a9e063a7920869d82c2481d26d50ad4211749 Mon Sep 17 00:00:00 2001 From: Roman Hergenreder Date: Wed, 15 Jul 2020 15:05:54 +0200 Subject: [PATCH] Add Regex to extra field --- core/core.php | 12 +++++++++++- index.php | 6 ++++-- js/script.js | 2 +- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/core/core.php b/core/core.php index e08d3c4..d8b3679 100644 --- a/core/core.php +++ b/core/core.php @@ -1,6 +1,6 @@ getCode(); } else { $target = trim(explode("\n", $route["target"])[0]); + $extra = $route["extra"] ?? ""; $pattern = str_replace("/","\\/", $route["request"]); - $pattern = "/$pattern/"; + $pattern = "/$pattern/i"; if (!startsWith($requestedUri, '/')) { $requestedUri = "/$requestedUri"; } @@ -122,6 +123,7 @@ if(isset($_GET["api"]) && is_string($_GET["api"])) { if (is_array($match) && !empty($match)) { foreach($match as $index => $value) { $target = str_replace("$$index", $value, $target); + $extra = str_replace("$$index", $value, $extra); } } @@ -139,7 +141,7 @@ if(isset($_GET["api"]) && is_string($_GET["api"])) { $response = serveStatic($currentDir, $target); break; case "dynamic": - $view = $route["extra"] ?? ""; + $view = parseClass($extra); $file = getClassPath($target); if(!file_exists($file) || !is_subclass_of($target, Document::class)) { $document = new Document404($user, $view); diff --git a/js/script.js b/js/script.js index 9fb48a0..02f00c9 100644 --- a/js/script.js +++ b/js/script.js @@ -9,7 +9,7 @@ let Core = function () { params = typeof params !== 'undefined' ? params : {}; callback = typeof callback !== 'undefined' ? callback : function (data) {}; - const path = '/api/' + (func.startsWith('/') ? '' : '/') + func; + const path = '/api' + (func.startsWith('/') ? '' : '/') + func; $.post(path, params, function (data) { console.log(func + "(): success=" + data.success + " msg=" + data.msg); callback.call(this, data);