v3.0.0.2
FlatlyPage
- <?php
- require_once __DIR__ . '/../config.php';
- require_once __DIR__ . '/sidebar.php';
-
- require_login();
-
- $message = '';
- $message_type = '';
-
- $providers = [];
- $xmlPath = __DIR__ . '/../data/translate-api.xml';
- if (is_file($xmlPath)) {
- $xml = @simplexml_load_file($xmlPath);
- if ($xml && isset($xml->apis->api)) {
- foreach ($xml->apis->api as $api) {
- $providers[(string) $api->id] = [
- 'name' => (string) $api->name,
- 'requiresKey' => (string) $api->requiresKey === 'true',
- ];
- }
- }
- }
-
- $system_settings = get_system_settings();
-
- if ($_SERVER['REQUEST_METHOD'] === 'POST') {
- if (!verify_csrf_token($_POST['csrf_token'] ?? '')) {
- $message = 'Your session timed out while the page was open. Please try again.';
- $message_type = 'error';
- } else {
- $provider = (string) ($_POST['translator_provider'] ?? '');
- if (!isset($providers[$provider])) {
- $provider = $system_settings['translator_provider'];
- }
-
- $api_key = trim((string) ($_POST['translator_api_key'] ?? ''));
- if (!empty($_POST['translator_api_key_clear'])) {
- $api_key = '';
- } elseif ($api_key === '') {
- $api_key = (string) $system_settings['translator_api_key'];
- }
-
- $new_settings = [
- 'translator_enabled' => ($_POST['translator_enabled'] ?? '') === 'true',
- 'translator_provider' => $provider,
- 'translator_api_key' => $api_key,
- 'dashboard_font' => resolve_font($_POST['dashboard_font'] ?? null, 'Space Grotesk'),
- ];
-
- if (save_page('system', array_merge($system_settings, $new_settings))) {
- $_SESSION['admin_msg'] = 'Settings saved.';
- $_SESSION['admin_msg_type'] = 'success';
- } else {
- $_SESSION['admin_msg'] = "Couldn't save the settings. Please try again.";
- $_SESSION['admin_msg_type'] = 'error';
- }
- header('Location: ' . BASE_URL . '/admin/system');
- exit;
- }
- }
-
- $message = $_SESSION['admin_msg'] ?? $message;
- $message_type = $_SESSION['admin_msg_type'] ?? $message_type;
- unset($_SESSION['admin_msg'], $_SESSION['admin_msg_type']);
-
- $csrf_token = generate_csrf_token();
- $fonts = array_keys(get_available_fonts());
- $current_font = get_dashboard_font();
- $has_key = $system_settings['translator_api_key'] !== '';
- ?>
- <!DOCTYPE html>
- <html lang="en">
-
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>System - FlatlyPage CMS</title>
- <link rel="icon" href="admin.ico?v=<?= filemtime(__DIR__ . '/../css/admin.css') ?>" type="image/x-icon">
- <?= admin_font_head() ?>
- <link rel="stylesheet" href="/css/admin.css?v=<?= filemtime(__DIR__ . '/../css/admin.css') ?>">
- <script src="/assets/js/admin-theme.js?v=5"></script>
- </head>
-
- <body>
- <div class="app">
- <?php admin_sidebar('system'); ?>
-
- <main class="main">
- <header class="main-header">
- <button class="mobile-nav-toggle" onclick="document.querySelector('.sidebar').classList.add('open')">
- <svg fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24">
- <line x1="3" y1="6" x2="21" y2="6" />
- <line x1="3" y1="12" x2="21" y2="12" />
- <line x1="3" y1="18" x2="21" y2="18" />
- </svg>
- </button>
-
- <div class="main-header-inner">
- <h1>System</h1>
- <div class="header-actions">
- <a class="btn btn-secondary btn-sm" href="javascript:void(0)" onclick="toggleTheme()" id="theme-toggle-btn">
- <svg fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" width="16" height="16">
- <path d="M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z" />
- </svg>
- <span>Theme</span>
- </a>
- </div>
- </div>
- </header>
-
- <div class="main-content">
- <?php if ($message): ?>
- <div class="message <?= e($message_type) ?>">
- <svg fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" width="20" height="20">
- <?php if ($message_type === 'success'): ?>
- <path d="M22 11.08V12a10 10 0 1 1-5.93-9.14" />
- <polyline points="22 4 12 14.01 9 11.01" />
- <?php else: ?>
- <circle cx="12" cy="12" r="10" />
- <line x1="12" y1="8" x2="12" y2="12" />
- <line x1="12" y1="16" x2="12.01" y2="16" />
- <?php endif; ?>
- </svg>
- <?= e($message) ?>
- </div>
- <?php endif; ?>
-
- <form method="POST" action="">
- <input type="hidden" name="csrf_token" value="<?= e($csrf_token) ?>">
-
- <div class="card" style="margin-bottom: 24px;">
- <div class="card-header">
- <h3 class="card-title">Dashboard</h3>
- </div>
- <div class="card-body">
- <div class="form-group">
- <label class="form-label">Glass Effect</label>
- <div class="form-switch">
- <input type="checkbox" id="glass_effect" checked>
- <label for="glass_effect"></label>
- </div>
- <p class="form-hint">Frosted, see-through backgrounds for the top bar, dialogs and AI button. Turn it off for a flatter look or if the dashboard feels slow. Only applies to this browser.</p>
- </div>
- <div class="form-group">
- <label class="form-label">Minimalism</label>
- <div class="form-switch">
- <input type="checkbox" id="minimalism">
- <label for="minimalism"></label>
- </div>
- <p class="form-hint">Turns off animations, shadows and gradients for a simple, flat look. Helps on older or slower computers. Only applies to this browser.</p>
- </div>
- <script>
- (function() {
- var glass = document.getElementById('glass_effect');
- glass.checked = isGlassOn();
- glass.addEventListener('change', function() { setGlass(glass.checked); });
-
- var minimal = document.getElementById('minimalism');
- minimal.checked = isMinimalOn();
- minimal.addEventListener('change', function() { setMinimal(minimal.checked); });
- })();
- </script>
-
- <div class="form-group">
- <label class="form-label">Dashboard Font</label>
- <select name="dashboard_font" class="form-input">
- <?php foreach ($fonts as $font_name): ?>
- <option value="<?= e($font_name) ?>" <?= $current_font === $font_name ? 'selected' : '' ?>><?= e($font_name) ?></option>
- <?php endforeach; ?>
- </select>
- <p class="form-hint">The font used in this dashboard. To add your own, put a .ttf file in the fonts folder, and Font_Name.ttf shows up here as "Font Name".</p>
- </div>
- </div>
- </div>
-
- <div class="card" style="margin-bottom: 24px;">
- <div class="card-header">
- <h3 class="card-title">Translator</h3>
- </div>
- <div class="card-body">
- <div class="form-group">
- <label class="form-label">Translator Button</label>
- <div class="form-switch">
- <input type="checkbox" name="translator_enabled" id="translator_enabled" value="true" <?= $system_settings['translator_enabled'] ? 'checked' : '' ?>>
- <label for="translator_enabled"></label>
- </div>
- <p class="form-hint">Show a translate button next to text fields in the editor</p>
- </div>
-
- <div class="form-row">
- <div class="form-group">
- <label class="form-label">Translation service</label>
- <select name="translator_provider" class="form-input">
- <?php foreach ($providers as $id => $provider): ?>
- <option value="<?= e($id) ?>" <?= $system_settings['translator_provider'] === $id ? 'selected' : '' ?>><?= e($provider['name']) ?><?= $provider['requiresKey'] ? '' : ' (no key needed)' ?></option>
- <?php endforeach; ?>
- </select>
- </div>
- <div class="form-group">
- <label class="form-label">Translator API Key</label>
- <input type="password" name="translator_api_key" class="form-input" autocomplete="new-password" placeholder="<?= $has_key ? 'Saved, leave empty to keep it' : 'Paste your API key' ?>">
- <?php if ($has_key): ?>
- <p class="form-hint"><label><input type="checkbox" name="translator_api_key_clear" value="1"> Delete the saved key</label></p>
- <?php endif; ?>
- </div>
- </div>
- </div>
- </div>
-
- <button type="submit" class="btn btn-primary">Save System Settings</button>
- </form>
- </div>
- </main>
- </div>
- </body>
-
- </html>
-