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(); // Prepare theme data with screenshot URLs and metadata for the view $themeData = []; foreach ($themes as $id => $name) { $meta = \App\Helpers\Theme::getThemeMetadata($id); $themeData[$id] = [ 'name' => $meta['name'] ?? $name, 'description' => $meta['description'] ?? '', 'version' => $meta['version'] ?? '', 'author' => $meta['author'] ?? '', 'tags' => $meta['tags'] ?? [], 'type' => $meta['type'] ?? '', 'path' => $meta['path'] ?? '', 'last_modified' => $meta['last_modified'] ?? null, 'file_count' => $meta['file_count'] ?? null, 'screenshotUrl' => \App\Helpers\Theme::getAssetUrl($id, 'screenshot.png'), 'isActive' => $id === $currentTheme ]; } // Make theme data available to the view $themes = $themeData; // Generate CSRF token for the form $csrf_token = $security->generateCsrfToken(); // Load the template include '../app/templates/theme.php';