From 5584a6156066ce92892b194a1476f0a5d7b7434d Mon Sep 17 00:00:00 2001 From: bruno Date: Mon, 5 Feb 2024 10:47:46 +0100 Subject: [PATCH 01/12] Me failure --- lib/account.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/account.php b/lib/account.php index 91ce90e..15d7a7c 100644 --- a/lib/account.php +++ b/lib/account.php @@ -174,7 +174,7 @@ function doRegister($firstname, $lastname, $email, $password, $activation_token) $privilege_level = $routerConfig["logged_in_default_permission_level"]; /** @noinspection SpellCheckingInspection */ - $stmt->bind_param("ssssiss", $firstname, $lastname, $email, $passwordHash, $privilege_level, $activation_token, $activation_token); + $stmt->bind_param("ssssis", $firstname, $lastname, $email, $passwordHash, $privilege_level, $activation_token); $stmt->execute(); From 1737c6cc13c172251572c977aef4d2310458f6ad Mon Sep 17 00:00:00 2001 From: AkisYTB3 Date: Mon, 5 Feb 2024 12:37:14 +0100 Subject: [PATCH 02/12] sdf --- assets/style.css | 8 +++++++- templates/login.html | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/assets/style.css b/assets/style.css index 7f638f3..d113389 100644 --- a/assets/style.css +++ b/assets/style.css @@ -239,4 +239,10 @@ table.list-table > tbody, table.list-table > tbody > th, table.list-table > tbod text-align: center; } -/* */ \ No newline at end of file +/* */ + +#loginForm input { + border-radius: 50px; + background: none; + border: 2px solid var(--primary); +} \ No newline at end of file diff --git a/templates/login.html b/templates/login.html index 4f4ab5f..5a06b60 100644 --- a/templates/login.html +++ b/templates/login.html @@ -51,7 +51,7 @@
-
+
From 79a8cc0f0ac030c329c9f54acb65100da3b02862 Mon Sep 17 00:00:00 2001 From: AkisYTB3 Date: Mon, 5 Feb 2024 12:39:03 +0100 Subject: [PATCH 03/12] aasdgfg --- assets/style.css | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/assets/style.css b/assets/style.css index d113389..e5684d3 100644 --- a/assets/style.css +++ b/assets/style.css @@ -245,4 +245,12 @@ table.list-table > tbody, table.list-table > tbody > th, table.list-table > tbod border-radius: 50px; background: none; border: 2px solid var(--primary); + width: 175px; +} + +#register_Form input { + border-radius: 50px; + background: none; + border: 2px solid var(--primary); + width: 175px; } \ No newline at end of file From 2b29d0df16f6f2cde5d0c0b0270a47b016b0bc7c Mon Sep 17 00:00:00 2001 From: bruno Date: Mon, 5 Feb 2024 21:21:04 +0100 Subject: [PATCH 04/12] ajax test --- assets/script.js | 69 ++++++++++++++++++++++++++++++++++++++- endpoints/global/page.php | 13 ++++++++ index.php | 2 +- lib/dynamic_style.php | 14 ++++++++ lib/navigation.php | 7 +++- lib/page.php | 38 ++++++++++++++++----- lib/script_data.php | 9 +++++ templates/skeleton.html | 9 +++-- 8 files changed, 147 insertions(+), 14 deletions(-) create mode 100644 endpoints/global/page.php create mode 100644 lib/dynamic_style.php create mode 100644 lib/script_data.php diff --git a/assets/script.js b/assets/script.js index 92a2871..823fd8d 100644 --- a/assets/script.js +++ b/assets/script.js @@ -20,6 +20,39 @@ function doAccountAction(requestData, successMessage, failureMessage, silent=fal }); } + + +function handlePageResponse(data){ + if(data.Navigation){ + document.getElementById("navbar").innerHTML = data.Navigation; + } + if(data.Page){ + document.getElementById("pagearea").innerHTML = data.Page; + if(data.PageLocation){ + history.pushState({}, "", data.PageLocation); + } + } +} + +function doPageAction(requestData){ + return fetch('/page', { + method: 'POST', + body: requestData, + }) + .then(response => { + if (!response.ok) { + throw new Error(`HTTP error! Status: ${response.status}`); + } + return response.json(); + }) + .then(data => { + handlePageResponse(data); + }) + .catch((error) => { + console.error('Error:', error); + }); +} + function displayList(data, element_id, delete_function=null) { const tableContainer = document.getElementById(element_id); tableContainer.innerHTML = ""; // Clear previous content @@ -86,13 +119,47 @@ function handleResponse(data, SuccessMessage, failureMessage) { }, 3000); } +function navigateTo(site, page){ + const data = new URLSearchParams(); + data.append("action", "getPage"); + data.append("site", site); + data.append("page", page); + doPageAction(data); +} + +function refreshNavbar(){ + const data = new URLSearchParams(); + data.append("action", "getNavigation"); + doPageAction(data); +} + function logout() { const data = new URLSearchParams(); data.append("action", "logout"); doAccountAction(data, "Logout Successful!", "Logout failed.").then(() => { - location.reload(); + refreshNavbar(); + navigateTo("", pageData.defaultPage); // Expected output: "Success!" }); } +let links = document.querySelectorAll('.navsite_link, .navpage_link'); + +// Add click event listener to each link +links.forEach(function(link) { + link.addEventListener('click', function(e) { + e.preventDefault(); + + // Get page and site information + let page = this.closest('.navpage_item').dataset.page; + let site = this.closest('.navsite_item').dataset.site; + + if(site && page){ + navigateTo(site, page); + } + + // You can use this information to update the URL or perform other actions + }); +}); + diff --git a/endpoints/global/page.php b/endpoints/global/page.php new file mode 100644 index 0000000..f59be43 --- /dev/null +++ b/endpoints/global/page.php @@ -0,0 +1,13 @@ + getNavigationEndpoint(), + "getPage" => getPageEndpoint($endpoint_data["page"], $endpoint_data["site"]), + default => ["Status" => "Fail", "message" => "Invalid action"], + }; +} \ No newline at end of file diff --git a/index.php b/index.php index da8f996..bed7315 100644 --- a/index.php +++ b/index.php @@ -16,7 +16,7 @@ $canRender = initRouter(); if ($canRender) { /** @noinspection PhpArrayIsAlwaysEmptyInspection */ /** @noinspection PhpArrayIsAlwaysEmptyInspection */ - session_set_cookie_params(0, '/', "." . $routerRequest["domain"] . "." . $routerRequest["tld"], true, true); +; session_set_cookie_params(0, '/', "." . $routerRequest["domain"] . "." . $routerRequest["tld"], true, true); session_start(); if (!isLoggedIn()) { diff --git a/lib/dynamic_style.php b/lib/dynamic_style.php new file mode 100644 index 0000000..5fcd604 --- /dev/null +++ b/lib/dynamic_style.php @@ -0,0 +1,14 @@ +"; + $color = dechex($_SESSION["favorite_color"]); + $dynamic_style .= "--root{ --favorite-color: #$color;"; + $dynamic_style .= ""; + } + return $dynamic_style; + +} \ No newline at end of file diff --git a/lib/navigation.php b/lib/navigation.php index d6f9f20..e2d9274 100644 --- a/lib/navigation.php +++ b/lib/navigation.php @@ -94,4 +94,9 @@ function generateNavigation(): string return $nav_out; } - +function getNavigationEndpoint() :array{ + return [ + "Status" => "Success", + "Navigation" => generateNavigation(), + ]; +} \ No newline at end of file diff --git a/lib/page.php b/lib/page.php index aa363c6..21255d9 100644 --- a/lib/page.php +++ b/lib/page.php @@ -1,5 +1,7 @@ [], 'output' => $input]; } -function getPage($page_name = null): array|false|string +function getPage($page_name = null, $site_name = null): string { global $routerConfig; global $routerRequest; + if(!$site_name) { + $site_name = $routerRequest["subdomain"]; + } + if(!$page_name){ $page_name = $routerRequest["page_name"]; } - $dynamic_page_file = $routerConfig["page_dir"] . $routerRequest["subdomain"] . "/" . $page_name . ".php"; - $page_file = $routerConfig["page_dir"] . $routerRequest["subdomain"] . "/" . $page_name . ".html"; + $dynamic_page_file = $routerConfig["page_dir"] . $site_name . "/" . $page_name . ".php"; + $page_file = $routerConfig["page_dir"] . $site_name . "/" . $page_name . ".html"; $skeleton = file_get_contents($routerConfig["template_dir"] . "skeleton.html"); $nav = file_get_contents($routerConfig["template_dir"] . "nav.html"); @@ -113,13 +119,15 @@ function getPage($page_name = null): array|false|string $page_title = $page_name; } - $dynamic_style = ""; + + $dynamic_style = doDynamicStyling(); + $dynamic_script = generateScriptData([ + "currentPage" => $page_name, + "currentSite" => $site_name, + "currentTitle" => $page_title, + "defaultPage" => $routerConfig["default_page"], + ]); $navpages = generateNavigation(); $nav = str_replace("__NAV_PAGES__", $navpages, $nav); @@ -127,8 +135,20 @@ function getPage($page_name = null): array|false|string $out = $skeleton; $out = str_replace("__TEMPLATE__NAV__", $nav, $out); $out = str_replace("__TEMPLATE__PAGE__", $page, $out); + $out = str_replace("__TEMPLATE__DYNASCRIPT__", $dynamic_script, $out); $out = str_replace("__TEMPLATE__DYNASTYLE__", $dynamic_style, $out); $out = inlineLocalStylesFromHref($out); $out = inlineScriptFromSrc($out); return str_replace("__TEMPLATE_PAGE_TITLE__", $page_title, $out); +} + +function getPageEndpoint($page_name, $site_name) :array +{ + global $routerRequest, $routerConfig; + $page_location = $routerConfig["protocol"] . $site_name . $routerRequest["domain"] . "." . $routerRequest["tld"] . "/" . $page_name; + return [ + "Status" => "Success", + "Page" => getPage($page_name, $site_name), + "PageLocation" => $page_location, + ]; } \ No newline at end of file diff --git a/lib/script_data.php b/lib/script_data.php new file mode 100644 index 0000000..41d6cc0 --- /dev/null +++ b/lib/script_data.php @@ -0,0 +1,9 @@ +let pageData = JSON.parse('$jsonString');"; +} \ No newline at end of file diff --git a/templates/skeleton.html b/templates/skeleton.html index 70b637c..fdc262b 100644 --- a/templates/skeleton.html +++ b/templates/skeleton.html @@ -9,9 +9,14 @@ Adlerka __TEMPLATE_PAGE_TITLE__ __TEMPLATE__DYNASTYLE__ + __TEMPLATE__DYNASCRIPT__ - __TEMPLATE__NAV__ - __TEMPLATE__PAGE__ + +
+ __TEMPLATE__PAGE__ +
\ No newline at end of file From 46a981cbbfd5b4ee85a047af6828f98859bc6cfe Mon Sep 17 00:00:00 2001 From: YeahAkis_ Date: Mon, 5 Feb 2024 21:22:16 +0100 Subject: [PATCH 05/12] tet --- assets/style.css | 1 + templates/login.html | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/assets/style.css b/assets/style.css index e5684d3..949feda 100644 --- a/assets/style.css +++ b/assets/style.css @@ -1,4 +1,5 @@ @import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700;800&display=swap'); +@import url('https://fonts.googleapis.com/css2?family=Montserrat:ital,wght@0,100..900;1,100..900&display=swap'); :root { --primary-bg: rgb(27, 21, 41); diff --git a/templates/login.html b/templates/login.html index 5a06b60..c8f8f03 100644 --- a/templates/login.html +++ b/templates/login.html @@ -41,7 +41,7 @@

-
+ +
+
+ +
+
\ No newline at end of file From 460f38a74d71f266f71e53abd1bb8e2d31a66f22 Mon Sep 17 00:00:00 2001 From: YeahAkis_ Date: Mon, 5 Feb 2024 21:22:50 +0100 Subject: [PATCH 06/12] test --- templates/login.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/login.html b/templates/login.html index c8f8f03..0aebedf 100644 --- a/templates/login.html +++ b/templates/login.html @@ -83,7 +83,7 @@ - + Password">
From 38c0269665153d60b66e0300b858cef22b4b539f Mon Sep 17 00:00:00 2001 From: bruno Date: Mon, 5 Feb 2024 21:23:21 +0100 Subject: [PATCH 07/12] run ajax after loaded --- assets/script.js | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/assets/script.js b/assets/script.js index 823fd8d..2f0e1fd 100644 --- a/assets/script.js +++ b/assets/script.js @@ -144,22 +144,24 @@ function logout() { }); } -let links = document.querySelectorAll('.navsite_link, .navpage_link'); +function initAjax() { + let links = document.querySelectorAll('.navsite_link, .navpage_link'); // Add click event listener to each link -links.forEach(function(link) { - link.addEventListener('click', function(e) { - e.preventDefault(); + links.forEach(function (link) { + link.addEventListener('click', function (e) { + e.preventDefault(); - // Get page and site information - let page = this.closest('.navpage_item').dataset.page; - let site = this.closest('.navsite_item').dataset.site; + // Get page and site information + let page = this.closest('.navpage_item').dataset.page; + let site = this.closest('.navsite_item').dataset.site; - if(site && page){ - navigateTo(site, page); - } + if (site && page) { + navigateTo(site, page); + } - // You can use this information to update the URL or perform other actions + // You can use this information to update the URL or perform other actions + }); }); -}); - +} +document.addEventListener('DOMContentLoaded', initAjax); From 3608aa655fbab5f06c73ffeaac11c0d44c3462fb Mon Sep 17 00:00:00 2001 From: YeahAkis_ Date: Mon, 5 Feb 2024 21:24:08 +0100 Subject: [PATCH 08/12] asd --- templates/login.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/login.html b/templates/login.html index 0aebedf..5b9e98e 100644 --- a/templates/login.html +++ b/templates/login.html @@ -83,7 +83,7 @@ - Password"> +
From 45fe0e11442617367568d88cd02b6559caefcba1 Mon Sep 17 00:00:00 2001 From: bruno Date: Mon, 5 Feb 2024 21:25:41 +0100 Subject: [PATCH 09/12] run ajax after loaded --- assets/script.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/assets/script.js b/assets/script.js index 2f0e1fd..a48353d 100644 --- a/assets/script.js +++ b/assets/script.js @@ -145,7 +145,7 @@ function logout() { } function initAjax() { - let links = document.querySelectorAll('.navsite_link, .navpage_link'); + let links = document.querySelectorAll('.navsite_item, .navpage_item'); // Add click event listener to each link links.forEach(function (link) { @@ -153,8 +153,8 @@ function initAjax() { e.preventDefault(); // Get page and site information - let page = this.closest('.navpage_item').dataset.page; - let site = this.closest('.navsite_item').dataset.site; + let site = this.dataset.site; + let page = this.dataset.page; if (site && page) { navigateTo(site, page); From d88cbb4759f866f12d3deddb87b4e8ceb299c82c Mon Sep 17 00:00:00 2001 From: YeahAkis_ Date: Mon, 5 Feb 2024 21:29:29 +0100 Subject: [PATCH 10/12] aers --- templates/login.html | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/templates/login.html b/templates/login.html index 5b9e98e..4c434d1 100644 --- a/templates/login.html +++ b/templates/login.html @@ -84,8 +84,26 @@ - + + + + \ No newline at end of file From 01fd8389ac73fa8125a993e8e52e1bf021497353 Mon Sep 17 00:00:00 2001 From: bruno Date: Mon, 5 Feb 2024 21:29:29 +0100 Subject: [PATCH 11/12] run ajax after loaded --- lib/navigation.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/navigation.php b/lib/navigation.php index e2d9274..4f1609d 100644 --- a/lib/navigation.php +++ b/lib/navigation.php @@ -83,11 +83,12 @@ function generateNavigation(): string } if($page_required_permission <= $_SESSION["privilege_level"]) { - $navpages .= ""; + $navpages .= ""; } } if(!empty($navpages)){ - $nav_out .= ""; + $default_page = $routerConfig["default_page"]; + $nav_out .= ""; } } From 914057680d054d9fb9ec371725eb4425f3a99826 Mon Sep 17 00:00:00 2001 From: bruno Date: Mon, 5 Feb 2024 21:37:42 +0100 Subject: [PATCH 12/12] Change the page endpoint --- lib/page.php | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/lib/page.php b/lib/page.php index 21255d9..0a4eb54 100644 --- a/lib/page.php +++ b/lib/page.php @@ -32,7 +32,7 @@ function parsePageTag($input): array return ['parameters' => [], 'output' => $input]; } -function getPage($page_name = null, $site_name = null): string +function renderPage($page_name = null, $site_name = null): array { global $routerConfig; global $routerRequest; @@ -48,9 +48,6 @@ function getPage($page_name = null, $site_name = null): string $dynamic_page_file = $routerConfig["page_dir"] . $site_name . "/" . $page_name . ".php"; $page_file = $routerConfig["page_dir"] . $site_name . "/" . $page_name . ".html"; - $skeleton = file_get_contents($routerConfig["template_dir"] . "skeleton.html"); - $nav = file_get_contents($routerConfig["template_dir"] . "nav.html"); - if (file_exists($dynamic_page_file)){ $pageMetadata = renderDynamicPage($dynamic_page_file); @@ -112,15 +109,31 @@ function getPage($page_name = null, $site_name = null): string $page = ""; } + return [ + "PageContent" => $page, + "PageName" => $page_name, + "SiteName" => $site_name, + ]; + +} + +function getPage($page_name_in = null, $site_name_in = null): string +{ + $page_tmp = renderPage($page_name_in, $site_name_in); + + $page = $page_tmp["PageContent"]; + $page_name = $page_tmp["PageName"]; + $site_name = $page_tmp["SiteName"]; + global $routerConfig; + + $skeleton = file_get_contents($routerConfig["template_dir"] . "skeleton.html"); + $nav = file_get_contents($routerConfig["template_dir"] . "nav.html"); if(!empty($pageMetadata["parameters"]["page_title"])){ $page_title = $pageMetadata["parameters"]["page_title"]; } else{ $page_title = $page_name; } - - - $dynamic_style = doDynamicStyling(); $dynamic_script = generateScriptData([ "currentPage" => $page_name, @@ -146,9 +159,10 @@ function getPageEndpoint($page_name, $site_name) :array { global $routerRequest, $routerConfig; $page_location = $routerConfig["protocol"] . $site_name . $routerRequest["domain"] . "." . $routerRequest["tld"] . "/" . $page_name; + $page_tmp = renderPage($page_name, $site_name); return [ "Status" => "Success", - "Page" => getPage($page_name, $site_name), + "Page" => $page_tmp["PageContent"], "PageLocation" => $page_location, ]; } \ No newline at end of file