From 2d0c280a0abbe1a3e1100d076add5c3334495d2c Mon Sep 17 00:00:00 2001 From: Yasen Pramatarov Date: Thu, 22 May 2025 14:33:54 +0300 Subject: [PATCH] Adds theme switcher controller and view --- app/pages/theme.php | 57 +++++++++++++++++++++++++++++++++++++++++ app/templates/theme.php | 37 ++++++++++++++++++++++++++ 2 files changed, 94 insertions(+) create mode 100644 app/pages/theme.php create mode 100644 app/templates/theme.php diff --git a/app/pages/theme.php b/app/pages/theme.php new file mode 100644 index 0000000..9abaf41 --- /dev/null +++ b/app/pages/theme.php @@ -0,0 +1,57 @@ +verifyCsrfToken($_GET['csrf_token'] ?? '')) { + Feedback::flash('SECURITY', 'CSRF_INVALID'); + header("Location: $app_root?page=theme"); + exit(); + } + + if (\App\Helpers\Theme::setCurrentTheme($themeName)) { + // Set success message + Feedback::flash('THEME', 'THEME_CHANGED'); + } else { + // Set error message + Feedback::flash('THEME', 'THEME_CHANGE_FAILED'); + } + + // Redirect back to prevent form resubmission + $redirect = $app_root . '?page=theme'; + header("Location: $redirect"); + exit; +} + +// Get available themes and current theme for the view +$themes = \App\Helpers\Theme::getAvailableThemes(); +$currentTheme = \App\Helpers\Theme::getCurrentThemeName(); + +// Generate CSRF token for the form +$csrf_token = $security->generateCsrfToken(); + +// Get any new feedback messages +include '../app/helpers/feedback.php'; + +// Load the template +include '../app/templates/theme.php'; diff --git a/app/templates/theme.php b/app/templates/theme.php new file mode 100644 index 0000000..fc16e33 --- /dev/null +++ b/app/templates/theme.php @@ -0,0 +1,37 @@ + +
+

Theme Switcher

+

Select a theme to change the appearance of the application.

+
+ $themeName): ?> + +
+
+ +
Current Theme
+ +
+
+

Theme ID:

+
+ + Switch to this theme + + + +
+
+
+
+ +
+