WebOrbiton
v3.0.0.2

FlatlyPage

218 lines · 10.7 KB
  1. <?php
  2. require_once __DIR__ . '/../config.php';
  3. require_once __DIR__ . '/sidebar.php';
  4. ​
  5. require_login();
  6. ​
  7. $message = '';
  8. $message_type = '';
  9. ​
  10. $providers = [];
  11. $xmlPath = __DIR__ . '/../data/translate-api.xml';
  12. if (is_file($xmlPath)) {
  13. $xml = @simplexml_load_file($xmlPath);
  14. if ($xml && isset($xml->apis->api)) {
  15. foreach ($xml->apis->api as $api) {
  16. $providers[(string) $api->id] = [
  17. 'name' => (string) $api->name,
  18. 'requiresKey' => (string) $api->requiresKey === 'true',
  19. ];
  20. }
  21. }
  22. }
  23. ​
  24. $system_settings = get_system_settings();
  25. ​
  26. if ($_SERVER['REQUEST_METHOD'] === 'POST') {
  27. if (!verify_csrf_token($_POST['csrf_token'] ?? '')) {
  28. $message = 'Your session timed out while the page was open. Please try again.';
  29. $message_type = 'error';
  30. } else {
  31. $provider = (string) ($_POST['translator_provider'] ?? '');
  32. if (!isset($providers[$provider])) {
  33. $provider = $system_settings['translator_provider'];
  34. }
  35. ​
  36. $api_key = trim((string) ($_POST['translator_api_key'] ?? ''));
  37. if (!empty($_POST['translator_api_key_clear'])) {
  38. $api_key = '';
  39. } elseif ($api_key === '') {
  40. $api_key = (string) $system_settings['translator_api_key'];
  41. }
  42. ​
  43. $new_settings = [
  44. 'translator_enabled' => ($_POST['translator_enabled'] ?? '') === 'true',
  45. 'translator_provider' => $provider,
  46. 'translator_api_key' => $api_key,
  47. 'dashboard_font' => resolve_font($_POST['dashboard_font'] ?? null, 'Space Grotesk'),
  48. ];
  49. ​
  50. if (save_page('system', array_merge($system_settings, $new_settings))) {
  51. $_SESSION['admin_msg'] = 'Settings saved.';
  52. $_SESSION['admin_msg_type'] = 'success';
  53. } else {
  54. $_SESSION['admin_msg'] = "Couldn't save the settings. Please try again.";
  55. $_SESSION['admin_msg_type'] = 'error';
  56. }
  57. header('Location: ' . BASE_URL . '/admin/system');
  58. exit;
  59. }
  60. }
  61. ​
  62. $message = $_SESSION['admin_msg'] ?? $message;
  63. $message_type = $_SESSION['admin_msg_type'] ?? $message_type;
  64. unset($_SESSION['admin_msg'], $_SESSION['admin_msg_type']);
  65. ​
  66. $csrf_token = generate_csrf_token();
  67. $fonts = array_keys(get_available_fonts());
  68. $current_font = get_dashboard_font();
  69. $has_key = $system_settings['translator_api_key'] !== '';
  70. ?>
  71. <!DOCTYPE html>
  72. <html lang="en">
  73. ​
  74. <head>
  75. <meta charset="UTF-8">
  76. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  77. <title>System - FlatlyPage CMS</title>
  78. <link rel="icon" href="admin.ico?v=<?= filemtime(__DIR__ . '/../css/admin.css') ?>" type="image/x-icon">
  79. <?= admin_font_head() ?>
  80. <link rel="stylesheet" href="/css/admin.css?v=<?= filemtime(__DIR__ . '/../css/admin.css') ?>">
  81. <script src="/assets/js/admin-theme.js?v=5"></script>
  82. </head>
  83. ​
  84. <body>
  85. <div class="app">
  86. <?php admin_sidebar('system'); ?>
  87. ​
  88. <main class="main">
  89. <header class="main-header">
  90. <button class="mobile-nav-toggle" onclick="document.querySelector('.sidebar').classList.add('open')">
  91. <svg fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24">
  92. <line x1="3" y1="6" x2="21" y2="6" />
  93. <line x1="3" y1="12" x2="21" y2="12" />
  94. <line x1="3" y1="18" x2="21" y2="18" />
  95. </svg>
  96. </button>
  97. ​
  98. <div class="main-header-inner">
  99. <h1>System</h1>
  100. <div class="header-actions">
  101. <a class="btn btn-secondary btn-sm" href="javascript:void(0)" onclick="toggleTheme()" id="theme-toggle-btn">
  102. <svg fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" width="16" height="16">
  103. <path d="M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z" />
  104. </svg>
  105. <span>Theme</span>
  106. </a>
  107. </div>
  108. </div>
  109. </header>
  110. ​
  111. <div class="main-content">
  112. <?php if ($message): ?>
  113. <div class="message <?= e($message_type) ?>">
  114. <svg fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" width="20" height="20">
  115. <?php if ($message_type === 'success'): ?>
  116. <path d="M22 11.08V12a10 10 0 1 1-5.93-9.14" />
  117. <polyline points="22 4 12 14.01 9 11.01" />
  118. <?php else: ?>
  119. <circle cx="12" cy="12" r="10" />
  120. <line x1="12" y1="8" x2="12" y2="12" />
  121. <line x1="12" y1="16" x2="12.01" y2="16" />
  122. <?php endif; ?>
  123. </svg>
  124. <?= e($message) ?>
  125. </div>
  126. <?php endif; ?>
  127. ​
  128. <form method="POST" action="">
  129. <input type="hidden" name="csrf_token" value="<?= e($csrf_token) ?>">
  130. ​
  131. <div class="card" style="margin-bottom: 24px;">
  132. <div class="card-header">
  133. <h3 class="card-title">Dashboard</h3>
  134. </div>
  135. <div class="card-body">
  136. <div class="form-group">
  137. <label class="form-label">Glass Effect</label>
  138. <div class="form-switch">
  139. <input type="checkbox" id="glass_effect" checked>
  140. <label for="glass_effect"></label>
  141. </div>
  142. <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>
  143. </div>
  144. <div class="form-group">
  145. <label class="form-label">Minimalism</label>
  146. <div class="form-switch">
  147. <input type="checkbox" id="minimalism">
  148. <label for="minimalism"></label>
  149. </div>
  150. <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>
  151. </div>
  152. <script>
  153. (function() {
  154. var glass = document.getElementById('glass_effect');
  155. glass.checked = isGlassOn();
  156. glass.addEventListener('change', function() { setGlass(glass.checked); });
  157. ​
  158. var minimal = document.getElementById('minimalism');
  159. minimal.checked = isMinimalOn();
  160. minimal.addEventListener('change', function() { setMinimal(minimal.checked); });
  161. })();
  162. </script>
  163. ​
  164. <div class="form-group">
  165. <label class="form-label">Dashboard Font</label>
  166. <select name="dashboard_font" class="form-input">
  167. <?php foreach ($fonts as $font_name): ?>
  168. <option value="<?= e($font_name) ?>" <?= $current_font === $font_name ? 'selected' : '' ?>><?= e($font_name) ?></option>
  169. <?php endforeach; ?>
  170. </select>
  171. <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>
  172. </div>
  173. </div>
  174. </div>
  175. ​
  176. <div class="card" style="margin-bottom: 24px;">
  177. <div class="card-header">
  178. <h3 class="card-title">Translator</h3>
  179. </div>
  180. <div class="card-body">
  181. <div class="form-group">
  182. <label class="form-label">Translator Button</label>
  183. <div class="form-switch">
  184. <input type="checkbox" name="translator_enabled" id="translator_enabled" value="true" <?= $system_settings['translator_enabled'] ? 'checked' : '' ?>>
  185. <label for="translator_enabled"></label>
  186. </div>
  187. <p class="form-hint">Show a translate button next to text fields in the editor</p>
  188. </div>
  189. ​
  190. <div class="form-row">
  191. <div class="form-group">
  192. <label class="form-label">Translation service</label>
  193. <select name="translator_provider" class="form-input">
  194. <?php foreach ($providers as $id => $provider): ?>
  195. <option value="<?= e($id) ?>" <?= $system_settings['translator_provider'] === $id ? 'selected' : '' ?>><?= e($provider['name']) ?><?= $provider['requiresKey'] ? '' : ' (no key needed)' ?></option>
  196. <?php endforeach; ?>
  197. </select>
  198. </div>
  199. <div class="form-group">
  200. <label class="form-label">Translator API Key</label>
  201. <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' ?>">
  202. <?php if ($has_key): ?>
  203. <p class="form-hint"><label><input type="checkbox" name="translator_api_key_clear" value="1"> Delete the saved key</label></p>
  204. <?php endif; ?>
  205. </div>
  206. </div>
  207. </div>
  208. </div>
  209. ​
  210. <button type="submit" class="btn btn-primary">Save System Settings</button>
  211. </form>
  212. </div>
  213. </main>
  214. </div>
  215. </body>
  216. ​
  217. </html>
  218. ​