From a33de15f0c88bf6f0b97253e644f367d0a73f852 Mon Sep 17 00:00:00 2001 From: marc-go Date: Sat, 10 Oct 2026 13:43:18 +0200 Subject: [PATCH] Refactor API structure: add internal handling, update templates, and remove deprecated files --- api/api.php | 5 +++- api/auth/isauth.php | 5 ++++ api/auth/login.php | 5 ++++ api/entrys/add.php | 5 ++++ api/entrys/get.php | 5 ++++ api/settings/appname.php | 5 ++++ api/setup/save.php | 3 +- public/html_loader.php | 4 +-- public/main.php | 27 ++++++++++++++++++ .../entrys_frontend/entrys_frontend.html | 0 .../templates/{ => standard}/error/error.css | 0 .../templates/{ => standard}/error/error.html | 0 .../templates/{ => standard}/login/login.html | 0 .../templates/{ => standard}/setup/setup.html | 0 public/templates/standard/template.json | 28 +++++++++++++++++++ public/templates/templates.json | 28 ++----------------- 16 files changed, 91 insertions(+), 29 deletions(-) rename public/templates/{ => standard}/entrys_frontend/entrys_frontend.html (100%) rename public/templates/{ => standard}/error/error.css (100%) rename public/templates/{ => standard}/error/error.html (100%) rename public/templates/{ => standard}/login/login.html (100%) rename public/templates/{ => standard}/setup/setup.html (100%) create mode 100755 public/templates/standard/template.json mode change 100755 => 100644 public/templates/templates.json diff --git a/api/api.php b/api/api.php index d9ab707..3656df5 100755 --- a/api/api.php +++ b/api/api.php @@ -12,6 +12,8 @@ class gbAPI { private $db; private $config; + private $internal; + private function b64url_encode($data) { return rtrim(strtr(base64_encode($data), "+/", "-_"), "="); } @@ -20,8 +22,9 @@ class gbAPI { return base64_decode(strtr($data, "-_", "+/")); } - function __construct($authRequired) { + function __construct($authRequired, $internal) { define("APP_PATH", __DIR__ . "/../"); + $this->internal = $internal; if ($authRequired) { if (!$this->checkAuth()) { diff --git a/api/auth/isauth.php b/api/auth/isauth.php index a37a29e..7fee7d1 100755 --- a/api/auth/isauth.php +++ b/api/auth/isauth.php @@ -1,4 +1,9 @@ "Guestbook", "allow_html" => "false", "approve_entrys" => "true", - "allow_new_entrys" => "true" + "allow_new_entrys" => "true", + "template" => "standard" ]; foreach ($settings as $key => $value) { diff --git a/public/html_loader.php b/public/html_loader.php index c7efa3f..03728ce 100755 --- a/public/html_loader.php +++ b/public/html_loader.php @@ -1,6 +1,6 @@ template = $template; + $this->page = $template; } function showError($error) { diff --git a/public/main.php b/public/main.php index 40fe680..bd99aaf 100755 --- a/public/main.php +++ b/public/main.php @@ -12,6 +12,7 @@ class gb { define("APP_DOMAIN", $_SERVER["SERVER_NAME"]); define("APP_PATH", __DIR__ . "/../"); define("FRONTEND_PATH", __DIR__ . "/"); + define("API_PATH", __DIR__ . "/../api/"); define("TEMPLATE_PATH", FRONTEND_PATH . "templates/"); define("TEMPLATE_CONF", TEMPLATE_PATH . "templates.json"); @@ -30,4 +31,30 @@ class gb { $html->setTemplate("setup"); $html->show(); } +} + + +// Internal API Call Library +class APICall { + private $response; + private $error; + + function __construct($path, $data) { + // Set $internal to true so the api return does not go to the browser + $internal = true; + + // Check Path + if (!is_file(API_PATH . $path)) { + $this->error("API Path invalid."); + return false; + } + + // Call API + require API_PATH . $path; + + // Get return from the API Library + $response = $api->getAnswer(); + + $this->response = $response; + } } \ No newline at end of file diff --git a/public/templates/entrys_frontend/entrys_frontend.html b/public/templates/standard/entrys_frontend/entrys_frontend.html similarity index 100% rename from public/templates/entrys_frontend/entrys_frontend.html rename to public/templates/standard/entrys_frontend/entrys_frontend.html diff --git a/public/templates/error/error.css b/public/templates/standard/error/error.css similarity index 100% rename from public/templates/error/error.css rename to public/templates/standard/error/error.css diff --git a/public/templates/error/error.html b/public/templates/standard/error/error.html similarity index 100% rename from public/templates/error/error.html rename to public/templates/standard/error/error.html diff --git a/public/templates/login/login.html b/public/templates/standard/login/login.html similarity index 100% rename from public/templates/login/login.html rename to public/templates/standard/login/login.html diff --git a/public/templates/setup/setup.html b/public/templates/standard/setup/setup.html similarity index 100% rename from public/templates/setup/setup.html rename to public/templates/standard/setup/setup.html diff --git a/public/templates/standard/template.json b/public/templates/standard/template.json new file mode 100755 index 0000000..9498c72 --- /dev/null +++ b/public/templates/standard/template.json @@ -0,0 +1,28 @@ +{ + "error":{ + "name":"error", + "dir_name":"error", + "html_file":"error.html", + "css_files":[ + "error.css" + ] + }, + "setup":{ + "name":"setup", + "dir_name":"setup", + "html_file":"setup.html", + "css_files":[] + }, + "entrys_frontend":{ + "name":"entrys_frontend", + "dir_name":"entrys_frontend", + "html_file":"entrys_frontend.html", + "css_files":[] + }, + "login":{ + "name":"login", + "dir_name":"login", + "html_file":"login.html", + "css_files":[] + } +} \ No newline at end of file diff --git a/public/templates/templates.json b/public/templates/templates.json old mode 100755 new mode 100644 index 9498c72..bcaca69 --- a/public/templates/templates.json +++ b/public/templates/templates.json @@ -1,28 +1,6 @@ { - "error":{ - "name":"error", - "dir_name":"error", - "html_file":"error.html", - "css_files":[ - "error.css" - ] - }, - "setup":{ - "name":"setup", - "dir_name":"setup", - "html_file":"setup.html", - "css_files":[] - }, - "entrys_frontend":{ - "name":"entrys_frontend", - "dir_name":"entrys_frontend", - "html_file":"entrys_frontend.html", - "css_files":[] - }, - "login":{ - "name":"login", - "dir_name":"login", - "html_file":"login.html", - "css_files":[] + "standard":{ + "name":"Standard Template", + "dir_name":"standard" } } \ No newline at end of file