From e85f6e91e1d21b0dd93e307708b6ab14c6273522 Mon Sep 17 00:00:00 2001 From: Edwin Noorlander Date: Tue, 28 Jul 2026 13:49:33 +0200 Subject: [PATCH] Vervang raw JSON config editor door instellingenformulier met default_page dropdown - Admin config pagina is nu een formulier met secties voor algemeen, taal, SEO, auteur en features - Startpagina instelbaar via dropdown met beschikbare pagina's uit content/ - Handleiding (nl/en) bijgewerkt met nieuwe configuratie-instructies --- admin/templates/pages/config.php | 148 ++++++++++++++++++++++++++++--- guide/en.codepress.md | 32 ++++--- guide/nl.codepress.md | 32 ++++--- public/admin.php | 61 +++++++++---- 4 files changed, 218 insertions(+), 55 deletions(-) diff --git a/admin/templates/pages/config.php b/admin/templates/pages/config.php index 050362e..7947b74 100644 --- a/admin/templates/pages/config.php +++ b/admin/templates/pages/config.php @@ -1,19 +1,139 @@

Configuratie

-
-
- config.json + +
+ +
-
-
- -
- - Bewerk de JSON configuratie. Ongeldige JSON wordt niet opgeslagen. + + + + + +
+
+ Algemene instellingen +
+
+
+
+ + +
+
+ + + Welke pagina wordt getoond als bezoekers de site openen. +
- - +
-
+ +
+
+ Taal +
+
+
+
+ + +
+
+ +
+ +
+ > + +
+
+ > + +
+
+
+
+
+
+ +
+
+ SEO +
+
+
+ + +
+
+ + + Komma-gescheiden trefwoorden. +
+
+
+ +
+
+ Auteur +
+
+
+
+ + +
+
+ + +
+
+
+
+ +
+
+ Features +
+
+
+ > + +
+
+ > + +
+
+ > + +
+
+ > + +
+
+
+ + + diff --git a/guide/en.codepress.md b/guide/en.codepress.md index 6736d1f..4fab02c 100644 --- a/guide/en.codepress.md +++ b/guide/en.codepress.md @@ -31,8 +31,8 @@ CodePress CMS is a lightweight, file-based content management system built with - Search URL: `?search=query` ### Configuration -- **JSON configuration** in `config.json` -- Dynamic homepage setting (`default_page`) +- **Settings form** in admin panel via `/admin/config` +- Dynamic homepage setting via dropdown - SEO settings (description, keywords) - Author information with links - Theme configuration via `themes/` directory @@ -58,7 +58,7 @@ CodePress CMS is a lightweight, file-based content management system built with - **CodeMirror editor** with toolbar (bold, italic, heading, link, image, list, media insert) - **Media browser modal** in the editor for selecting images/files - **Directory management** - Create, rename and delete directories (empty only) -- **Configuration editor** - Edit `config.json` with JSON validation +- **Configuration editor** - Settings form for site configuration (title, homepage, language, SEO, author, features) - **Theme management** - Create, activate, edit (colors, background) and delete themes - **Plugin management** - Overview, create, edit, configure, enable/disable and delete - **Media management** - Upload and delete media files in `content/-assets/` @@ -157,7 +157,19 @@ codepress/ ## Configuration -### Basic Configuration (`config.json`) +### Basic Configuration + +The site configuration is managed via the **admin panel** at `/admin/config`. Here you'll find a settings form with the following sections: + +- **General settings** - Site title and homepage (dropdown with available pages) +- **Language** - Default language and available languages +- **SEO** - Meta description and keywords +- **Author** - Name and website +- **Features** - Auto-link pages, search, breadcrumbs, show version + +The configuration is stored in `config.json`. You can also edit this file manually for advanced options like `active_theme`, `content_dir` and `templates_dir`. + +### Example `config.json` ```json { @@ -186,11 +198,6 @@ codepress/ } ``` -- `active_theme` - Determines which theme from `themes/` is active -- `templates_dir` - Directory with Mustache templates (`cms/templates`) -- `default_page` - Default page (e.g. `index`) -- `content_dir` - Directory with content files (usually not changed) - ### Theme Configuration (`themes//theme.json`) ```json @@ -268,7 +275,7 @@ Media files (images, PDFs, video, audio) can be placed in any `content/` subdire | `content-dir-rename` | Rename directory | | `content-dir-create` | Create directory (POST) | | `content-dir-delete` | Delete directory (empty only) | -| `config` | Configuration editor (`config.json`) | +| `config` | Configuration form (title, homepage, language, SEO, author, features) | | `theme` | Theme management | | `plugins` | Plugin overview | | `plugins-new` | Create new plugin | @@ -499,8 +506,9 @@ The MQTTTracker plugin stores `broker_host`, `broker_port`, `client_id`, `userna ### How do I set the homepage? -1. **Automatic**: Set `"default_page": "index"` in `config.json` (or omit the field) -2. **Manual**: Set `"default_page": "page-name"` in `config.json` +1. Go to **Configuration** in the admin panel (`/admin/config`) +2. Select the desired page in the **Default/homepage** dropdown +3. Click **Save configuration** ### How does navigation work? diff --git a/guide/nl.codepress.md b/guide/nl.codepress.md index 220eb80..199fb55 100644 --- a/guide/nl.codepress.md +++ b/guide/nl.codepress.md @@ -31,8 +31,8 @@ CodePress CMS is een lichtgewicht, file-based content management systeem gebouwd - Search URL: `?search=zoekterm` ### Configuratie -- **JSON configuratie** in `config.json` -- Dynamische homepage instelling (`default_page`) +- **Instellingenformulier** in admin paneel via `/admin/config` +- Dynamische homepage instelling via dropdown - SEO instellingen (description, keywords) - Author informatie met links - Thema configuratie via `themes/` directory @@ -58,7 +58,7 @@ CodePress CMS is een lichtgewicht, file-based content management systeem gebouwd - **CodeMirror editor** met toolbar (vet, cursief, kop, link, afbeelding, lijst, media invoegen) - **Media browser modal** in de editor voor het selecteren van afbeeldingen/bestanden - **Map beheer** - Mappen aanmaken, hernoemen en verwijderen (alleen lege mappen) -- **Configuratie editor** - `config.json` bewerken met JSON-validatie +- **Configuratie editor** - Instellingenformulier voor site configuratie (titel, startpagina, taal, SEO, auteur, features) - **Thema beheer** - Thema's aanmaken, activeren, bewerken (kleuren, achtergrond) en verwijderen - **Plugin beheer** - Overzicht, aanmaken, bewerken, configureren, in-/uitschakelen en verwijderen - **Media beheer** - Uploaden en verwijderen van mediabestanden in `content/-assets/` @@ -157,7 +157,19 @@ codepress/ ## Configuratie -### Basis Configuratie (`config.json`) +### Basis Configuratie + +De site configuratie wordt beheerd via het **admin paneel** op `/admin/config`. Hier vind je een instellingenformulier met de volgende secties: + +- **Algemene instellingen** - Site titel en startpagina (dropdown met beschikbare pagina's) +- **Taal** - Standaard taal en beschikbare talen +- **SEO** - Meta beschrijving en keywords +- **Auteur** - Naam en website +- **Features** - Auto-link pagina's, zoekfunctie, breadcrumbs, versie tonen + +De configuratie wordt opgeslagen in `config.json`. Je kunt dit bestand ook handmatig bewerken voor geavanceerde opties zoals `active_theme`, `content_dir` en `templates_dir`. + +### Voorbeeld `config.json` ```json { @@ -186,11 +198,6 @@ codepress/ } ``` -- `active_theme` - Bepaalt welk thema uit `themes/` actief is -- `templates_dir` - Map met Mustache templates (`cms/templates`) -- `default_page` - Standaard pagina (bijv. `index`) -- `content_dir` - Map met content bestanden (wordt gewoonlijk niet gewijzigd) - ### Thema Configuratie (`themes//theme.json`) ```json @@ -269,7 +276,7 @@ Media bestanden (afbeeldingen, PDFs, video, audio) kunnen in elke `content/` sub | `content-dir-rename` | Map hernoemen | | `content-dir-create` | Map aanmaken (POST) | | `content-dir-delete` | Map verwijderen (alleen leeg) | -| `config` | Configuratie editor (`config.json`) | +| `config` | Configuratieformulier (titel, startpagina, taal, SEO, auteur, features) | | `theme` | Thema beheer | | `plugins` | Plugin overzicht | | `plugins-new` | Nieuwe plugin aanmaken | @@ -500,8 +507,9 @@ De MQTTTracker plugin slaat `broker_host`, `broker_port`, `client_id`, `username ### Hoe stel ik de homepage in? -1. **Automatisch**: Zet `"default_page": "index"` in `config.json` (of verwijder het veld) -2. **Handmatig**: Stel `"default_page": "pagina-naam"` in `config.json` +1. Ga naar **Configuratie** in het admin paneel (`/admin/config`) +2. Selecteer de gewenste pagina in het **Standaard/startpagina** dropdown +3. Klik op **Configuratie opslaan ### Hoe werkt de navigatie? diff --git a/public/admin.php b/public/admin.php index 16a48ef..e3883ec 100644 --- a/public/admin.php +++ b/public/admin.php @@ -658,29 +658,56 @@ function handleConfig(AdminAuth $auth, array $config): void $message = ''; $messageType = ''; + // Load current config + $configData = file_exists($configJson) ? json_decode(file_get_contents($configJson), true) : []; + if (!is_array($configData)) $configData = []; + + // Get available root-level pages + $contentDir = $config['content_dir']; + $availablePages = []; + $availableLangs = $configData['language']['available'] ?? ['nl', 'en']; + if (is_dir($contentDir)) { + $pageMap = []; + foreach (scandir($contentDir) as $file) { + if ($file[0] === '.') continue; + $filePath = $contentDir . '/' . $file; + if (is_file($filePath) && preg_match('/\.(md|php|html)$/', $file)) { + $base = $file; + $langPattern = '/^(' . implode('|', $availableLangs) . ')\.(.+)$/'; + if (preg_match($langPattern, $base, $m)) { + $base = $m[2]; + } + $pageKey = preg_replace('/\.(md|php|html)$/', '', $base); + $pageMap[$pageKey] = true; + } + } + $availablePages = array_keys($pageMap); + sort($availablePages); + } + if ($_SERVER['REQUEST_METHOD'] === 'POST') { if (!$auth->verifyCsrf($_POST['csrf_token'] ?? '')) { $message = 'Ongeldige CSRF token.'; $messageType = 'danger'; } else { - $jsonContent = $_POST['config_content'] ?? ''; - $parsed = json_decode($jsonContent, true); - if ($parsed === null && json_last_error() !== JSON_ERROR_NONE) { - $message = 'Ongeldige JSON: ' . json_last_error_msg(); - $messageType = 'danger'; - } else { - file_put_contents($configJson, json_encode($parsed, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE)); - adminLog($config, 'info', $user['username'] . ' wijzigde site configuratie'); - $message = 'Configuratie opgeslagen.'; - $messageType = 'success'; - $jsonContent = null; // reload from file - } - } - } + $configData['site_title'] = trim($_POST['site_title'] ?? 'CodePress'); + $configData['default_page'] = trim($_POST['default_page'] ?? 'index'); + $configData['language']['default'] = trim($_POST['language_default'] ?? 'nl'); + $configData['language']['available'] = $_POST['language_available'] ?? ['nl', 'en']; + $configData['seo']['description'] = trim($_POST['seo_description'] ?? ''); + $configData['seo']['keywords'] = trim($_POST['seo_keywords'] ?? ''); + $configData['author']['name'] = trim($_POST['author_name'] ?? ''); + $configData['author']['website'] = trim($_POST['author_website'] ?? ''); + $configData['show_version'] = !empty($_POST['show_version']); + $configData['features']['auto_link_pages'] = !empty($_POST['feature_auto_link']); + $configData['features']['search_enabled'] = !empty($_POST['feature_search']); + $configData['features']['breadcrumbs_enabled'] = !empty($_POST['feature_breadcrumbs']); - $siteConfig = file_exists($configJson) ? file_get_contents($configJson) : '{}'; - if (isset($jsonContent)) { - $siteConfig = $jsonContent; + file_put_contents($configJson, json_encode($configData, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE)); + adminLog($config, 'info', $user['username'] . ' wijzigde site configuratie'); + $message = 'Configuratie opgeslagen.'; + $messageType = 'success'; + } } $route = 'config';