trim((string) ($_POST['new_bg'] ?? '')), 'text' => trim((string) ($_POST['new_text'] ?? '')), 'accent' => trim((string) ($_POST['new_accent'] ?? '')), 'border' => trim((string) ($_POST['new_border'] ?? '')), 'accent_bg' => trim((string) ($_POST['new_accent_bg'] ?? '')), ]; $darkRaw = [ 'bg' => trim((string) ($_POST['new_bg_dark'] ?? '')), 'text' => trim((string) ($_POST['new_text_dark'] ?? '')), 'accent' => trim((string) ($_POST['new_accent_dark'] ?? '')), 'border' => trim((string) ($_POST['new_border_dark'] ?? '')), 'accent_bg' => trim((string) ($_POST['new_accent_bg_dark'] ?? '')), ]; $lightFilled = count(array_filter($lightRaw, fn($v) => $v !== '')); $darkFilled = count(array_filter($darkRaw, fn($v) => $v !== '')); if ($lightFilled === 0 && $darkFilled === 0) { $errors[] = t('admin.settings.theme.error_theme_empty'); } elseif ($lightFilled > 0 && $lightFilled < 5) { $errors[] = t('admin.settings.theme.error_theme_light_incomplete'); } elseif ($darkFilled > 0 && $darkFilled < 5) { $errors[] = t('admin.settings.theme.error_theme_dark_incomplete'); } else { $light = $lightFilled === 5 ? $lightRaw : null; $dark = $darkFilled === 5 ? $darkRaw : null; $res = save_theme_json($themeName, $light, $dark); if (!empty($res['ok'])) { $notice = t('admin.settings.theme.notice_theme_created'); } else { $errors[] = $res['error'] ?? t('admin.settings.theme.error_theme_save'); } } } } elseif ($action === 'import_theme') { if (!empty($_FILES['theme_file'])) { $res = save_uploaded_theme($_FILES['theme_file']); if (!empty($res['ok'])) { $notice = t('admin.settings.theme.notice_theme_imported'); } else { $errors[] = $res['error'] ?? t('admin.settings.theme.error_theme_invalid'); } } else { $errors[] = t('admin.settings.theme.error_theme_upload'); } } else { // Standard typography & layout settings form submit $fontChoice = $_POST['font_stack'] ?? 'sans'; $adminFontChoice = $_POST['admin_font_stack'] ?? 'sans'; $adminColorMode = $_POST['admin_color_mode'] ?? 'auto'; $colorMode = $_POST['color_mode'] ?? 'light'; $postListLayout = $_POST['post_list_layout'] ?? 'excerpt'; if (!in_array($fontChoice, ['sans', 'serif', 'mono'], true)) { $errors[] = t('admin.settings.theme.error_font'); } if (!in_array($adminFontChoice, ['sans', 'serif', 'mono'], true)) { $errors[] = t('admin.settings.theme.error_admin_font'); } if (!in_array($adminColorMode, ['light', 'dark', 'auto'], true)) { $errors[] = t('admin.settings.theme.error_admin_color'); } if (!in_array($colorMode, ['light', 'dark', 'auto'], true)) { $errors[] = t('admin.settings.theme.error_color_mode'); } if (!in_array($postListLayout, ['excerpt', 'full', 'archive'], true)) { $errors[] = t('admin.settings.theme.error_post_layout'); } if (!$errors) { $config['theme']['font_stack'] = $fontChoice; $config['theme']['admin_font_stack'] = $adminFontChoice; $config['theme']['admin_color_mode'] = $adminColorMode; $config['theme']['color_mode'] = $colorMode; $config['theme']['post_list_layout'] = $postListLayout; if (save_config($config)) { $notice = t('admin.settings.theme.notice_updated'); } else { $errors[] = t('admin.settings.theme.error_save'); } } } } function is_theme_active(array $theme, array $activeThemeConfig): bool { if (!empty($activeThemeConfig['active_theme_name']) && $activeThemeConfig['active_theme_name'] === $theme['name']) { return true; } $hasLight = !empty($theme['has_light']); $hasDark = !empty($theme['has_dark']); if (!$hasLight && !$hasDark) { $hasLight = true; $hasDark = true; } $lightMatch = true; if ($hasLight) { $lightMatch = strcasecmp($theme['light']['bg'], $activeThemeConfig['background_color'] ?? '') === 0 && strcasecmp($theme['light']['text'], $activeThemeConfig['text_color'] ?? '') === 0 && strcasecmp($theme['light']['accent'], $activeThemeConfig['accent_color'] ?? '') === 0; } $darkMatch = true; if ($hasDark) { $darkMatch = strcasecmp($theme['dark']['bg'], $activeThemeConfig['background_color_dark'] ?? '') === 0 && strcasecmp($theme['dark']['text'], $activeThemeConfig['text_color_dark'] ?? '') === 0 && strcasecmp($theme['dark']['accent'], $activeThemeConfig['accent_color_dark'] ?? '') === 0; } return $lightMatch && $darkMatch; } $availableThemes = get_available_themes(); $adminTitle = t('admin.settings.theme.page_title'); require __DIR__ . '/../includes/admin-head.php'; ?>

' . e(t('admin.settings.theme.docs_link')) . ''; ?>