From 76a0568ee288f40db1ec7a297c32654505edb548 Mon Sep 17 00:00:00 2001 From: bruno Date: Thu, 1 Feb 2024 09:46:52 +0100 Subject: [PATCH] add per page scripts and styles --- assets/login-script.js | 29 ---------------------------- assets/scripts/global/account.js | 29 ++++++++++++++++++++++++++++ lib/page.php | 33 ++++++++++++++++++++++++++++++++ templates/login.html | 4 +--- templates/skeleton.html | 2 ++ 5 files changed, 65 insertions(+), 32 deletions(-) delete mode 100644 assets/login-script.js create mode 100644 assets/scripts/global/account.js diff --git a/assets/login-script.js b/assets/login-script.js deleted file mode 100644 index e6438ac..0000000 --- a/assets/login-script.js +++ /dev/null @@ -1,29 +0,0 @@ -function login() { - const email = document.getElementById("email").value; - const password = document.getElementById("password").value; - - // Assuming you use fetch API to send data to the server - fetch('https://home.adlerka.top/account', { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: JSON.stringify({ - action: 'login', - email: email, - password: password - }), - }) - .then(response => response.json()) - .then(data => { - if (data.status === 'success') { - document.getElementById("statusMessage").innerText = "Login successful!"; - // Redirect or perform other actions after successful login - } else { - document.getElementById("statusMessage").innerText = "Login failed. Please check your credentials."; - } - }) - .catch((error) => { - console.error('Error:', error); - }); -} diff --git a/assets/scripts/global/account.js b/assets/scripts/global/account.js new file mode 100644 index 0000000..5dddf7c --- /dev/null +++ b/assets/scripts/global/account.js @@ -0,0 +1,29 @@ +function login() { + const email = document.getElementById("email").value; + const password = document.getElementById("password").value; + + // Assuming you use fetch API to send data to the server + fetch('https://home.adlerka.top/account', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ + action: 'login', + email: email, + password: password + }), + }) + .then(response => response.json()) + .then(data => { + if (data.status === 'success') { + document.getElementById("statusMessage").innerText = "Login successful!"; + // Redirect or perform other actions after successful login + } else { + document.getElementById("statusMessage").innerText = "Login failed. Please check your credentials."; + } + }) + .catch((error) => { + console.error('Error:', error); + }); +} diff --git a/lib/page.php b/lib/page.php index 9bbc62b..e22711a 100644 --- a/lib/page.php +++ b/lib/page.php @@ -119,12 +119,45 @@ function getPage($page_name = null): array|false|string $page_title = $page_name; } + $site_name = $routerRequest["subdomain"]; + + if(!empty($pageMetadata["parameters"]["page_style"])){ + $style_location = $pageMetadata["parameters"]["page_style"]; + } + else{ + $style_location = "assets/styles/$site_name/$page_name.css"; + } + + if(file_exists($style_location)) { + $style_tag = $style_location; + } + else{ + $style_tag = ""; + } + + if(!empty($pageMetadata["parameters"]["page_script"])){ + $script_location = $pageMetadata["parameters"]["page_script"]; + } + else{ + $script_location = "assets/scripts/$site_name/$page_name.js"; + } + + if(file_exists($style_location)) { + $script_tag = $script_location; + } + else{ + $script_tag = ""; + } + + $navpages = generateNavigation(); $nav = str_replace("__NAV_PAGES__", $navpages, $nav); $out = $skeleton; $out = str_replace("__TEMPLATE__NAV__", $nav, $out); + $out = str_replace("__TEMPLATE_PAGE_STYLE_TAG__", $style_tag, $out); + $out = str_replace("__TEMPLATE_PAGE_SCRIPT_TAG__", $script_tag, $out); $out = str_replace("__TEMPLATE__PAGE__", $page, $out); return str_replace("__TEMPLATE_PAGE_TITLE__", $page_title, $out); } \ No newline at end of file diff --git a/templates/login.html b/templates/login.html index 45361bb..71b4ae8 100644 --- a/templates/login.html +++ b/templates/login.html @@ -10,6 +10,4 @@

- - - \ No newline at end of file + \ No newline at end of file diff --git a/templates/skeleton.html b/templates/skeleton.html index d3cd4f2..a918e53 100644 --- a/templates/skeleton.html +++ b/templates/skeleton.html @@ -6,6 +6,8 @@ + __TEMPLATE_PAGE_STYLE_TAG__ + __TEMPLATE_PAGE_SCRIPT_TAG__ Adlerka __TEMPLATE_PAGE_TITLE__