diff --git a/composer.json b/composer.json index c6a9271..fd872a7 100644 --- a/composer.json +++ b/composer.json @@ -7,6 +7,7 @@ "phpmailer/phpmailer": "*", "paypal/rest-api-sdk-php": "*", "jbbcode/jbbcode": "*", - "corneltek/cliframework": "*" + "corneltek/cliframework": "*", + "phroute/phroute": "^2.1" } } diff --git a/libraries/Controllers/Meta.php b/libraries/Controllers/Meta.php new file mode 100644 index 0000000..e7dea77 --- /dev/null +++ b/libraries/Controllers/Meta.php @@ -0,0 +1,16 @@ +addRoute($name, $path, $args[1], $filter); + } + } + + // Initialisation function + public static function init($basePath = '/') + { + // Set base path + self::setBasePath($basePath); + + // Create router + self::$router = new RouteCollector; + } + + // Set base path + public static function setBasePath($basePath) + { + self::$basePath = $basePath; + } + + // Parse the url + private static function parseUrl($url) + { + return parse_url(str_replace(self::$basePath, '', $url), PHP_URL_PATH); + } + + // Handle requests + public static function handle($method, $url) + { + // Check if the dispatcher is defined + if (self::$dispatcher === null) { + self::$dispatcher = new Dispatcher(self::$router->getData()); + } + + // Parse url + $url = self::parseUrl($url); + + // Handle the request + return self::$dispatcher->dispatch($method, $url); + } } diff --git a/public/content/scripts/dynload.js b/public/content/scripts/dynload.js index 7d35dcf..37826d4 100644 --- a/public/content/scripts/dynload.js +++ b/public/content/scripts/dynload.js @@ -6,6 +6,12 @@ var DynLoad = (function () { } // Add the hooks DynLoad.init = function () { + if (this.active) { + return; + } + else { + this.active = true; + } // Add an event listener to the document document.addEventListener("click", function (e) { // Check if a href attribute is set @@ -21,7 +27,7 @@ var DynLoad = (function () { var doc = (new DOMParser()).parseFromString(loader.response(), "text/html"); history.pushState(null, null, e.target['href']); document.head.innerHTML = doc.head.innerHTML; - document.getElementById("content").innerHTML = doc.getElementById("content").innerHTML; + document.getElementById("contentwrapper").innerHTML = doc.getElementById("contentwrapper").innerHTML; var evt = document.createEvent('Event'); evt.initEvent('load', false, false); window.dispatchEvent(evt); @@ -31,5 +37,7 @@ var DynLoad = (function () { } }); }; + // Is active + DynLoad.active = false; return DynLoad; })(); diff --git a/public/content/scripts/dynload.ts b/public/content/scripts/dynload.ts index 0dbb7c1..8768ef9 100644 --- a/public/content/scripts/dynload.ts +++ b/public/content/scripts/dynload.ts @@ -3,8 +3,17 @@ */ class DynLoad { + // Is active + public static active: boolean = false; + // Add the hooks public static init(): void { + if (this.active) { + return; + } else { + this.active = true; + } + // Add an event listener to the document document.addEventListener("click", (e) => { // Check if a href attribute is set @@ -23,7 +32,7 @@ class DynLoad { var doc = (new DOMParser()).parseFromString(loader.response(), "text/html"); history.pushState(null, null, e.target['href']); document.head.innerHTML = doc.head.innerHTML; - document.getElementById("content").innerHTML = doc.getElementById("content").innerHTML; + document.getElementById("contentwrapper").innerHTML = doc.getElementById("contentwrapper").innerHTML; var evt = document.createEvent('Event'); evt.initEvent('load', false, false); window.dispatchEvent(evt); diff --git a/public/router.php b/public/router.php new file mode 100644 index 0000000..7378a0c --- /dev/null +++ b/public/router.php @@ -0,0 +1,19 @@ +