CMS 2.0 - Theme engine, logging, admin improvements

Major changes:
- New ThemeManager with Twig templating and SCSS compilation
- Dynamic themes system (themes/default, themes/demo)
- LogManager with SQLite storage and syslog forwarding
- RequestLogger with static helper methods
- Admin UI overhaul (Bootstrap 5, dark mode)
- Admin config page with logging and theme settings
- Admin logs page with filters and search
- Removed legacy Mustache templates
- Removed test plugin and theme
- Composer dependencies: Twig, scssphp, CommonMark, MaxMind GeoIP
This commit is contained in:
2026-08-08 18:02:14 +02:00
parent d453b8073f
commit 6333bc410f
833 changed files with 108974 additions and 1386 deletions
+103 -39
View File
@@ -58,8 +58,8 @@ codepress/
│ ├── core/
│ │ ├── class/
│ │ │ ├── CodePressCMS.php # Main CMS class (content, navigation, search)
│ │ │ ├── ThemeManager.php # Theme resolver + Twig render + SCSS compile
│ │ │ ├── Logger.php # Structured logging system
│ │ │ ├── SimpleTemplate.php # Mustache-style template engine
│ │ │ ├── Analytics.php # Visitor statistics
│ │ │ ├── BotGuard.php # Bot/AI/scraper detection
│ │ │ ├── GeoIP.php # Country lookup by IP
@@ -73,13 +73,21 @@ codepress/
│ ├── lang/ # Language files
│ │ ├── nl.php # Dutch translations
│ │ └── en.php # English translations
── templates/ # Mustache templates
├── layout.mustache # Main layout (CSS, structure)
│ ├── assets/ # Header, navigation, footer partials
│ │ ├── markdown_content.mustache
│ │ ├── php_content.mustache
│ │ ── html_content.mustache
└── router.php # PHP dev server router
── router.php # PHP dev server router (also serves /themes/)
├── themes/ # Dynamic themes (fully self-contained)
│ ├── default/ # Default theme
│ │ ├── theme.json # { title, config.default_template, template→.twig mapping }
│ │ ├── base.twig # Main layout (head, header, nav, footer)
│ │ ── full_content.twig # Layout: full width
│ ├── left_sidebar.twig # Layout: sidebar left
│ │ ├── right_sidebar.twig # Layout: sidebar right
│ │ ├── custom1.twig # Layout: custom
│ │ ├── partials/ # header.twig, navigation.twig, footer.twig
│ │ ├── css/theme.scss # Colors, heights, background (compiled at runtime)
│ │ ├── js/theme.js # Theme JavaScript
│ │ └── theme.png # Preview image
│ ├── demo/ # Demo theme (same structure, different look)
│ └── test/ # Test theme
├── admin/ # Admin panel
│ ├── config/
│ │ ├── app.php # Admin app configuration (paths, timezone)
@@ -124,12 +132,19 @@ codepress/
│ ├── assets/ # CSS, JS, favicons
│ │ ├── codemirror/ # CodeMirror editor (minified JS/CSS)
│ │ └── css/js/ # Bootstrap, icons, app CSS/JS
│ ├── themes/ # Uploaded theme backgrounds
│ ├── themes/ # Runtime compiled theme CSS (public/themes)
│ └── manifest.json / sw.js # PWA support
├── themes/ # Theme definitions
├── themes/ # Dynamic themes (fully self-contained)
│ ├── default/ # Default theme
│ │ ── theme.json # Colors, heights, background
└── ... # Other themes
│ │ ── theme.json # Title, default template, template mapping
│ ├── base.twig # Main layout
│ │ ├── *.twig # Layout templates (full_content, left_sidebar, ...)
│ │ ├── partials/ # header, navigation, footer
│ │ ├── css/theme.scss # Colors, heights, background
│ │ ├── js/theme.js # Theme JavaScript
│ │ └── theme.png # Preview image
│ ├── demo/ # Demo theme
│ └── test/ # Test theme
├── config.json # Site configuration
├── version.php # Version information
└── vendor/ # Composer dependencies
@@ -301,7 +316,6 @@ This is useful for your own IP address or internal monitoring tools.
{
"site_title": "CodePress",
"content_dir": "content",
"templates_dir": "cms\/templates",
"default_page": "index",
"active_theme": "default",
"language": {
@@ -336,32 +350,64 @@ This is useful for your own IP address or internal monitoring tools.
### Themes
Themes are managed via the admin panel at `/admin/theme`. You can create, activate, adjust colors, upload background images, and delete themes.
Themes are managed via the admin panel at `/admin/theme`. This is a selection page: pick the active theme and click "Activate theme". Each theme is a fully self-contained folder in `themes/` with its own Twig templates, SCSS and JavaScript.
#### Theme structure (`themes/<name>/`)
```
themes/<name>/
├── theme.json # Title, default template, template mapping
├── base.twig # Main layout (head, header, nav, footer)
├── full_content.twig # Layout: full width
├── left_sidebar.twig # Layout: sidebar left
├── right_sidebar.twig # Layout: sidebar right
├── custom1.twig # Layout: custom
├── partials/ # header.twig, navigation.twig, footer.twig
├── css/theme.scss # Colors, heights, background (compiled at runtime)
├── js/theme.js # Theme JavaScript
└── theme.png # Preview image (shown in admin)
```
#### Theme Configuration (`themes/<name>/theme.json`)
```json
{
"name": "Default",
"header_color": "#0a369d",
"header_font_color": "#ffffff",
"header_height": "56",
"navigation_color": "#2754b4",
"navigation_font_color": "#ffffff",
"nav_height": "42",
"sidebar_background": "#f8f9fa",
"sidebar_border": "#dee2e6",
"background_image": "",
"background_image_opacity": "100"
"title": "default",
"config": {
"default_template": "full_content"
},
"template": {
"full_content": "full_content.twig",
"left_sidebar": "left_sidebar.twig",
"right_sidebar": "right_sidebar.twig",
"custom1": "custom1.twig"
}
}
```
- **`config.default_template`**: the default template used when a page requests an unknown layout.
- **`template`**: the layout-key → `.twig` file mapping. A theme can have multiple template pages.
Colors, heights and background are **not** set in `theme.json` but in `css/theme.scss`:
```scss
$header-bg: #0a369d;
$header-font: #ffffff;
$header-height: 56px;
$nav-bg: #2754b4;
$nav-font: #ffffff;
$nav-height: 42px;
$sidebar-bg: #f8f9fa;
$sidebar-border: #dee2e6;
$header-bg-image: none; // optional header background
$header-bg-opacity: 1;
```
The SCSS is compiled at runtime into `public/themes/<name>/theme.css`.
#### How to create a new theme
1. Go to `/admin/theme`
2. Enter a name and click "Create"
3. Adjust colors, heights and background
4. Activate the theme
Themes are created manually: copy the `themes/default/` folder to `themes/<name>/`, adjust the SCSS colors and templates, and add a `theme.png` preview. The theme is then available on `/admin/theme` to activate.
### Security
@@ -418,10 +464,23 @@ Country detection via three sources:
### Logging
The admin console maintains two logs, viewable at `/admin/logs`:
The admin console maintains logs, viewable at `/admin/logs`:
- **Activity log** (`admin/storage/logs/admin.log`) — admin actions like creating, editing, deleting pages, enabling/disabling plugins, changing configuration.
- **Request log** (`admin/storage/logs/requests.log`) — every page view on the website, including IP, page, domain, language, user agent, and referrer.
- **Dynamic log** — structured log entries via `LogManager`, with event type, level, IP, and message.
#### Configuring dynamic logging
Via `/admin/config`**Logging** you can configure how and what is recorded:
- **Storage**: `SQLite` (default) or `Syslog`.
- **Syslog server**: if a host is provided, log entries are sent to that server over UDP. Leave empty to use SQLite.
- **Facility**: the category of the log source in syslog. `local0``local7` are for your own applications; `daemon`, `user`, and `auth` are standard system categories.
- **Syslog ident**: the name that appears in the log message (e.g. `codepress`).
- **Events**: choose which types are recorded — `admin`, `requests`, `errors`, `security`, `content`, `system`.
If no syslog server is configured, SQLite is always used (with a file fallback if SQLite is unavailable).
The dashboard shows the last 20 entries of each log. Click "View all →" for the full list, where you can also download or clear.
@@ -523,6 +582,8 @@ This guide is also built into the admin panel via `/admin/guide`, with support f
### Templates
Templates are Twig files per theme in `themes/<name>/`. `ThemeManager` renders them and compiles `css/theme.scss` at runtime into `public/themes/<name>/theme.css`.
#### Template Variables
**Site Info** - `site_title`, `author_name`, `author_website`, `author_git`
@@ -531,36 +592,39 @@ This guide is also built into the admin panel via `/admin/guide`, with support f
**Navigation** - `menu`, `breadcrumb`, `homepage`
**Theme (from theme.json)** - `header_color`, `header_font_color`, `header_height`, `navigation_color`, `navigation_font_color`, `nav_height`, `sidebar_background`, `sidebar_border`, `background_image_css`, `background_image_opacity`
**Theme** - `theme_title`, `theme_css_url`, `theme_js_url`, `theme_config` (config from theme.json)
**Language** - `current_lang`, `current_lang_upper`, `t_*` (translated strings)
#### Layout Options
Use YAML frontmatter to select layout:
Use YAML frontmatter to select the template. The layout key references a template in the active theme:
```yaml
---
title: My Page
layout: sidebar-content
layout: left_sidebar
plugins: HTMLBlock
---
```
#### Available Layouts
- `sidebar-content` - Sidebar left, content right (default)
- `content` - Content only (full width)
- `sidebar` - Sidebar only
- `content-sidebar` - Content left, sidebar right
- `content-sidebar-reverse` - Content right, sidebar left
The available layouts are defined by the `template` section of the active theme (`themes/<name>/theme.json`). The default theme includes:
- `full_content` - Content only (full width)
- `left_sidebar` - Sidebar left, content right
- `right_sidebar` - Content left, sidebar right
- `custom1` - Custom layout
If a page requests an unknown layout, the `default_template` from the theme's `config` is used.
#### Meta Data
```yaml
---
title: Page Title
layout: content-sidebar
layout: left_sidebar
description: Page description
author: Author Name
date: 2025-11-26