v2.6.0: Content backup/git versioning, plugin type system, docs update
New features: - ContentBackup class with ZIP backup/restore and git versioning - Admin backup & restore page (content-backup.twig) with git init/commit/log/restore - Plugin type system: system (blue) vs content (green) with visual badges - PluginAPIInterface + AdminPluginAPI for plugin architecture - Essential plugin flag (cannot edit/deactivate/delete) Improvements: - Consolidated enabled_plugins config (removed plugins.enabled) - Removed Analytics/Logging toggles from admin config page - Fixed Dashboard plugin Twig comments rendered as text - Updated 20 guide files (NL+EN): configuratie, plugins, plugin-development, core-classes, theme-json, layouts, scss-styling, admin-beheerder, nieuw-thema, architectuur - Improved accessibility test script (grep -E, min/max checks) Cleanup: - Removed unused classes: ARIAComponents, AccessibilityManager, ContentSecurityPolicy, etc. - Removed vendor packages: mustache/mustache, php-mqtt/client - Removed old templates: logs.twig, statistics.twig (now plugins) - Moved language files to language/ directory Tests: - Pentest: 30/30 passed, 0 vulnerabilities - WCAG 2.1 AA: 25/25 passed, 100% compliance
This commit is contained in:
@@ -11,5 +11,7 @@ The admin manager guide contains the following topics:
|
||||
- **Users** - Adding and removing users
|
||||
- **Statistics** - Viewing visitor statistics
|
||||
- **Logs** - Viewing and filtering log files
|
||||
- **Media** - Managing media files
|
||||
- **Update** - Check for updates
|
||||
|
||||
Select a topic from the navigation on the left.
|
||||
@@ -3,7 +3,13 @@
|
||||
## General settings
|
||||
|
||||
- **Site title** - Website name
|
||||
- **Default language** - nl/en/de/fr
|
||||
- **Author** - Name and email
|
||||
- **Analytics** - Visitor tracking on/off
|
||||
- **Logging** - Log files on/off
|
||||
- **Admin language** - Admin panel language (nl/en/de)
|
||||
- **Content language** - Default website content language (nl/en/de/fr)
|
||||
|
||||
## Homepage
|
||||
|
||||
Choose which page is shown on the homepage:
|
||||
|
||||
- **Automatic** - First available page
|
||||
- **Most recent** - Last modified page
|
||||
- **Specific page** - Select a specific page from the content directory
|
||||
@@ -1,15 +1,30 @@
|
||||
# Plugins
|
||||
|
||||
## Plugin types
|
||||
|
||||
There are two types of plugins:
|
||||
|
||||
- **System plugins** (blue badge) - Manage CMS functionality such as Dashboard, Logs and Statistics
|
||||
- **Content plugins** (green badge) - Display content on the front-end such as HTMLBlock and Navigation
|
||||
|
||||
## Essential plugins
|
||||
|
||||
Essential plugins (with a shield icon) cannot be edited, deactivated, or deleted. This applies to the Navigation plugin for example.
|
||||
|
||||
## Managing plugins
|
||||
|
||||
- **Enable/Disable** - Turn plugins on/off
|
||||
- **Edit** - Modify plugin code
|
||||
- **Configuration** - Plugin settings
|
||||
- **Configuration** - Plugin settings (only for plugins with a Config button)
|
||||
- **Delete** - Remove plugin
|
||||
|
||||
Only active plugins are shown in the admin sidebar.
|
||||
|
||||
## New plugin
|
||||
|
||||
1. Go to **Plugins** → **New plugin**
|
||||
2. Enter a name (e.g. `MyPlugin`)
|
||||
3. Edit `plugin.php`
|
||||
4. Enable the plugin
|
||||
3. Edit the PHP file
|
||||
4. Enable the plugin
|
||||
|
||||
New plugins are content-plugins by default. To create a system plugin, add `"type": "system"` to `plugin.json`.
|
||||
@@ -2,10 +2,23 @@
|
||||
|
||||
```
|
||||
codepress/
|
||||
├── cms/core/ # Core engine
|
||||
├── admin/ # Admin console
|
||||
├── themes/ # Themes
|
||||
├── plugins/ # Plugins
|
||||
├── content/ # Content
|
||||
└── public/ # Web root
|
||||
├── cms/core/ # Core engine
|
||||
│ ├── class/ # CodePressCMS, ThemeManager, Logger, Analytics
|
||||
│ ├── plugin/ # PluginManager, CMSAPI, AdminPluginAPI
|
||||
│ ├── config.php # Config loader
|
||||
│ └── index.php # Bootstrap
|
||||
├── admin/ # Admin console
|
||||
│ ├── config/ # app.php, admin.json
|
||||
│ ├── src/ # AdminAuth
|
||||
│ └── theme/default/views/ # Twig templates
|
||||
├── themes/ # Themes (default, demo, ...)
|
||||
├── plugins/ # Plugins (Dashboard, HTMLBlock, Navigation, ...)
|
||||
├── content/ # Content files (.md, .php, .html)
|
||||
├── language/ # Language files (nl/, en/, de/)
|
||||
├── guide/ # Guides (nl/, en/)
|
||||
├── public/ # Web root
|
||||
│ ├── index.php # Website entry point
|
||||
│ └── admin.php # Admin entry point + router
|
||||
├── config.json # Site configuration
|
||||
└── version.php # Version info
|
||||
```
|
||||
@@ -5,28 +5,62 @@
|
||||
Main CMS class in `cms/core/class/CodePressCMS.php`:
|
||||
|
||||
```php
|
||||
$cms = new CodePressCMS();
|
||||
$cms->init();
|
||||
$cms = new CodePressCMS($config);
|
||||
$cms->renderPage($pagePath);
|
||||
```
|
||||
|
||||
Key methods: `renderPage()`, `getMenu()`, `getPage()`, `parseMarkdown()`, `generateBreadcrumb()`, `getAvailableLanguages()`.
|
||||
|
||||
## ThemeManager.php
|
||||
|
||||
Theme management in `cms/core/class/ThemeManager.php`:
|
||||
|
||||
```php
|
||||
$themeManager = new ThemeManager($config);
|
||||
$themeManager->getActiveTheme();
|
||||
$themeManager->renderTwig($template, $data);
|
||||
$themeManager->compileCss($force);
|
||||
```
|
||||
|
||||
Compiles `assets/scss/theme.scss` at runtime to CSS and renders Twig templates.
|
||||
|
||||
## PluginManager.php
|
||||
|
||||
Plugin system in `cms/core/class/PluginManager.php`:
|
||||
Plugin system in `cms/core/plugin/PluginManager.php`:
|
||||
|
||||
```php
|
||||
$pluginManager = new PluginManager();
|
||||
$pluginManager->loadPlugins($enabledPlugins);
|
||||
$pluginManager->executeHook($name, $params);
|
||||
```
|
||||
$pluginManager = new PluginManager($pluginsPath, $enabledPlugins);
|
||||
$pluginManager->setAPI($api);
|
||||
$pluginManager->doAction('onPageLoad', $args);
|
||||
$result = $pluginManager->applyFilters('onContentFilter', $content);
|
||||
$pluginManager->getAdminMenuItems();
|
||||
```
|
||||
|
||||
Key methods: `setAPI()`, `doAction()`, `applyFilters()`, `getPlugin()`, `getAllPlugins()`, `getEnabledPlugins()`, `isEnabled()`, `getSidebarContent()`, `getPluginCssUrls()`, `getAdminMenuItems()`, `dispatchAdminRoute()`, `resolveAdminRoute()`.
|
||||
|
||||
## CMSAPI.php
|
||||
|
||||
Front-end plugin API in `cms/core/plugin/CMSAPI.php`. Implements `PluginAPIInterface`. Provides access to the CMS instance for plugins in the front-end context.
|
||||
|
||||
```php
|
||||
$api->getCurrentPageTitle();
|
||||
$api->getMenu();
|
||||
$api->getConfig('site_title');
|
||||
$api->createUrl('about-us');
|
||||
```
|
||||
|
||||
## AdminPluginAPI.php
|
||||
|
||||
Admin plugin API in `cms/core/plugin/AdminPluginAPI.php`. Implements `PluginAPIInterface`. Lightweight wrapper with config-only access (no CMS instance needed).
|
||||
|
||||
```php
|
||||
$api->getConfig('analytics.enabled');
|
||||
$api->getContentDir();
|
||||
$api->getEnabledPlugins();
|
||||
```
|
||||
|
||||
## AdminAuth.php
|
||||
|
||||
Authentication in `admin/src/AdminAuth.php`. Manages sessions, bcrypt passwords, CSRF tokens, brute-force lockout, and role-based permissions.
|
||||
|
||||
## LogManager.php
|
||||
|
||||
Logging system in `cms/core/class/LogManager.php`. Supports SQLite, syslog, and file-based logging. Events: admin, requests, errors, security, content, system.
|
||||
@@ -4,9 +4,12 @@
|
||||
|
||||
```
|
||||
plugins/MyPlugin/
|
||||
├── plugin.json # Plugin metadata
|
||||
├── plugin.php # Plugin code
|
||||
└── config.json # Optional configuration
|
||||
├── MyPlugin.php # Main plugin class (name = folder name)
|
||||
├── plugin.json # Plugin metadata
|
||||
├── config.json # Optional configuration
|
||||
└── assets/ # Optional CSS/JS
|
||||
├── css/
|
||||
└── scss/
|
||||
```
|
||||
|
||||
## plugin.json
|
||||
@@ -16,28 +19,128 @@ plugins/MyPlugin/
|
||||
"name": "My Plugin",
|
||||
"version": "1.0.0",
|
||||
"author": "Your Name",
|
||||
"description": "Description"
|
||||
"description": "Description",
|
||||
"type": "content",
|
||||
"essential": false,
|
||||
"hasConfig": false
|
||||
}
|
||||
```
|
||||
|
||||
## plugin.php example
|
||||
### Fields
|
||||
|
||||
| Field | Value | Description |
|
||||
|-------|-------|-------------|
|
||||
| `name` | string | Display name in admin |
|
||||
| `version` | string | Version number |
|
||||
| `author` | string | Author |
|
||||
| `description` | string | Short description |
|
||||
| `type` | `"system"` or `"content"` | System (blue badge) or content (green badge) |
|
||||
| `essential` | boolean | Essential plugins cannot be edited/deleted |
|
||||
| `hasConfig` | boolean | Shows a Config button in admin |
|
||||
|
||||
## Plugin class example
|
||||
|
||||
```php
|
||||
<?php
|
||||
/**
|
||||
* Plugin: MyPlugin
|
||||
*/
|
||||
|
||||
echo '<div class="my-plugin">Hello World</div>';
|
||||
class MyPlugin
|
||||
{
|
||||
private ?PluginAPIInterface $api = null;
|
||||
|
||||
public function setAPI(PluginAPIInterface $api): void
|
||||
{
|
||||
$this->api = $api;
|
||||
}
|
||||
|
||||
public function getConfig(): array
|
||||
{
|
||||
return [
|
||||
'title' => 'My Plugin',
|
||||
'type' => 'content',
|
||||
'viewable' => true,
|
||||
];
|
||||
}
|
||||
|
||||
public function getSidebarContent(): string
|
||||
{
|
||||
$title = $this->api ? $this->api->getCurrentPageTitle() : '';
|
||||
return '<p>Current page: ' . htmlspecialchars($title) . '</p>';
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Using CMSAPI
|
||||
The plugin class is automatically loaded by `PluginManager` when the plugin is listed in `enabled_plugins` in `config.json`.
|
||||
|
||||
## Using the API
|
||||
|
||||
The API is injected via `setAPI()`, not via a static method. In the front-end context this is a `CMSAPI` instance, in the admin context an `AdminPluginAPI` instance. Both implement `PluginAPIInterface`.
|
||||
|
||||
```php
|
||||
<?php
|
||||
require_once '../../cms/core/class/PluginManager.php';
|
||||
// Front-end API (CMSAPI)
|
||||
$this->api->getCurrentPageTitle();
|
||||
$this->api->getMenu();
|
||||
$this->api->getConfig('site_title');
|
||||
$this->api->getCurrentLanguage();
|
||||
$this->api->isHomepage();
|
||||
$this->api->createUrl('about-us');
|
||||
|
||||
$api = PluginManager::getAPI();
|
||||
$config = $api->getConfig();
|
||||
$content = $api->getContent();
|
||||
// Admin API (AdminPluginAPI)
|
||||
$this->api->getConfig('analytics.enabled');
|
||||
$this->api->getContentDir();
|
||||
$this->api->getEnabledPlugins();
|
||||
```
|
||||
|
||||
## Hooks
|
||||
|
||||
Plugins can implement the following methods for automatic hook registration:
|
||||
|
||||
**Actions** (no return value):
|
||||
|
||||
- `onPageLoad` - On page load
|
||||
- `onBeforeRender` - Before rendering
|
||||
- `onAfterRender` - After rendering
|
||||
- `onSearch` - On search
|
||||
- `onMenuBuild` - On menu build
|
||||
|
||||
**Filters** (return modified value):
|
||||
|
||||
- `onContentFilter` - Filter content
|
||||
- `onTitleFilter` - Filter title
|
||||
- `onMenuFilter` - Filter menu
|
||||
|
||||
## Admin integration
|
||||
|
||||
Plugins can add custom admin pages via `getAdminMenu()` and `handleAdminRoute()`:
|
||||
|
||||
```php
|
||||
public function getAdminMenu(): array
|
||||
{
|
||||
return [
|
||||
[
|
||||
'plugin' => 'MyPlugin',
|
||||
'route' => 'my-plugin',
|
||||
'label' => 'My Plugin',
|
||||
'icon' => 'bi-puzzle',
|
||||
'section' => 'general', // or 'system'
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function handleAdminRoute(string $action): ?string
|
||||
{
|
||||
return '<h2>My Plugin admin page</h2>';
|
||||
}
|
||||
```
|
||||
|
||||
Only plugins listed in `enabled_plugins` are shown in the admin sidebar.
|
||||
|
||||
## Adding CSS
|
||||
|
||||
Plugins can provide a CSS URL via `getCssUrl()`:
|
||||
|
||||
```php
|
||||
public function getCssUrl(): string
|
||||
{
|
||||
return '/plugins/MyPlugin/assets/css/style.css';
|
||||
}
|
||||
```
|
||||
@@ -16,12 +16,17 @@ Content...
|
||||
|
||||
```json
|
||||
{
|
||||
"default_layout": "full_content",
|
||||
"layouts": {
|
||||
"config": {
|
||||
"default_template": "full_content"
|
||||
},
|
||||
"template": {
|
||||
"full_content": "full_content.twig",
|
||||
"left_sidebar": "left_sidebar.twig",
|
||||
"right_sidebar": "right_sidebar.twig",
|
||||
"custom1": "custom1.twig"
|
||||
"custom1": "custom1.twig",
|
||||
"guide": "guide.twig"
|
||||
}
|
||||
}
|
||||
```
|
||||
```
|
||||
|
||||
Unknown layouts in frontmatter fall back to `config.default_template`.
|
||||
@@ -22,4 +22,5 @@ Create basic files:
|
||||
- `full_content.twig`
|
||||
- `partials/header.twig`
|
||||
- `partials/footer.twig`
|
||||
- `scss/theme.scss`
|
||||
- `scss/theme.scss`
|
||||
- `guide.twig` (if guide support is needed)
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
1. Go to **Admin** → **Theme**
|
||||
2. Click **Compile SCSS** for your theme
|
||||
3. CSS is generated in `assets/css/theme.css`
|
||||
3. CSS is generated in `assets/css_compiled/theme.css`
|
||||
|
||||
## SCSS example
|
||||
|
||||
|
||||
@@ -3,19 +3,23 @@
|
||||
```json
|
||||
{
|
||||
"title": "My Theme",
|
||||
"default_layout": "full_content",
|
||||
"header_color": "#0a369d",
|
||||
"layouts": {
|
||||
"config": {
|
||||
"default_template": "full_content"
|
||||
},
|
||||
"template": {
|
||||
"full_content": "full_content.twig",
|
||||
"left_sidebar": "left_sidebar.twig",
|
||||
"right_sidebar": "right_sidebar.twig"
|
||||
}
|
||||
"right_sidebar": "right_sidebar.twig",
|
||||
"custom1": "custom1.twig",
|
||||
"guide": "guide.twig"
|
||||
},
|
||||
"header_color": "#0a369d"
|
||||
}
|
||||
```
|
||||
|
||||
## Fields
|
||||
|
||||
- `title` - Display name in admin
|
||||
- `default_layout` - Default layout for new pages
|
||||
- `header_color` - Admin sidebar color
|
||||
- `layouts` - Mapping of layout names to .twig files
|
||||
- `config.default_template` - Default layout for new pages
|
||||
- `template` - Mapping of layout names to .twig files
|
||||
- `header_color` - (optional) Admin sidebar color, defaults to `#0a369d`
|
||||
Reference in New Issue
Block a user