commit 07379d9d0345324103d9748b040f1624bd80411e Author: Paul Spenke Date: Mon Nov 23 19:28:06 2026 +0100 add Docsify-based documentation site Add a complete documentation site for Plugi with the following pages: - Readme.md: project overview, quick start, and key features - GettingStarted.md: installation guide, requirements, and first steps - Configuration.md: full reference for .env and config.php settings - Themes.md: theme structure, blocks, layouts, and asset compilation - Extensions.md: extension architecture, routes, blocks, and admin pages Also add index.html (Docsify entry point), _sidebar.md (navigation), favicon.ico, and .nojekyll to prevent GitHub Pages from interfering. diff --git a/.nojekyll b/.nojekyll new file mode 100644 index 0000000..e69de29 diff --git a/Configuration.md b/Configuration.md new file mode 100644 index 0000000..cb3491b --- /dev/null +++ b/Configuration.md @@ -0,0 +1,202 @@ +# Configuration + +Plugi is configured through two files: + +- **`.env`** — Environment variables for database connection and application stage. +- **`config.php`** — PHP array that controls all framework behavior, modules, themes, and extensions. + +## The `.env` File + +The `.env` file is loaded by `EnvLoader` at boot time. It must exist in the project root. Typical contents: + +```ini +DB_HOST=mysql +DB_NAME=plugi +DB_USER=plugi +DB_PASSWORD=plugi +STAGE=development +``` + +| Variable | Description | Default | +|----------------|----------------------------------------------|------------------| +| `DB_HOST` | MySQL host (e.g., `localhost` or `mysql`) | `mysql` | +| `DB_NAME` | Database name | `plugi` | +| `DB_USER` | Database user | `plugi` | +| `DB_PASSWORD` | Database password | `plugi` | +| `STAGE` | Application stage (`development` or `production`) | `development` | + +Setting `STAGE=production` disables PHP error display in `index.php`. + +## The `config.php` File + +Copy `config.dist.php` to `config.php` and adjust the settings. The configuration is a PHP array with the following sections: + +### General Settings + +```php +'general' => [ + 'language' => 'en', + 'assets_url' => '/plugi-core/dist', + 'uploads_url' => '/uploads' +], +``` + +| Key | Description | +|----------------|--------------------------------------------------| +| `language` | Default language code (e.g., `en`, `de`, `fr`). Theme and extension translations are loaded for this language. | +| `assets_url` | Public URL path to the Plugi core assets (JS, CSS, images). | +| `uploads_url` | Public URL path to the uploads directory. | + +### Storage Settings + +```php +'storage' => [ + 'use_database' => true, + 'uploads_folder' => __DIR__ . '/uploads' +], +``` + +| Key | Description | +|--------------------|----------------------------------------------------------| +| `use_database` | Set to `true` to use MySQL for storing pages, settings, and uploads metadata. | +| `uploads_folder` | Absolute filesystem path where uploaded files are stored. | + +### Auth Settings + +```php +'auth' => [ + 'use_login' => true, + 'class' => Plugi\Modules\Auth\Auth::class, + 'url' => '/admin/auth', +], +``` + +| Key | Description | +|---------------|-----------------------------------------------------------------------------| +| `use_login` | Enable or disable the built-in authentication module. | +| `class` | Fully qualified class name implementing `AuthContract`. | +| `url` | URL prefix for auth endpoints (login/logout). | + +The default `Auth` class checks credentials stored in the database settings table. Change the admin username and password from the admin panel after first login. + +### Website Manager Settings + +```php +'website_manager' => [ + 'use_website_manager' => true, + 'class' => Plugi\Modules\WebsiteManager\WebsiteManager::class, + 'url' => '/admin' +], +``` + +| Key | Description | +|---------------------------|-----------------------------------------------------------------------| +| `use_website_manager` | Enable or disable the admin dashboard. | +| `class` | Class implementing `WebsiteManagerContract`. | +| `url` | URL prefix for the admin panel. | + +### Page Builder Settings + +```php +'pagebuilder' => [ + 'class' => Plugi\Modules\GrapesJS\PageBuilder::class, + 'url' => '/admin/pagebuilder', + 'actions' => [ + 'back' => '/admin' + ] +], +``` + +| Key | Description | +|-------------|---------------------------------------------------------------| +| `class` | Class implementing `PageBuilderContract` (GrapesJS-based by default). | +| `url` | URL prefix for the page builder. | +| `actions` | Named action URLs, e.g., `back` returns to the admin panel. | + +### Page Settings + +```php +'page' => [ + 'class' => Plugi\Page::class, + 'table' => 'pages', + 'translation' => [ + 'class' => Plugi\PageTranslation::class, + 'table' => 'page_translations', + 'foreign_key' => 'page_id', + ] +], +``` + +| Key | Description | +|-----------------------|---------------------------------------------------------------| +| `class` | Class implementing `PageContract`. | +| `table` | Database table name for pages. | +| `translation.class` | Class implementing `PageTranslationContract`. | +| `translation.table` | Database table name for page translations (multilingual support). | +| `translation.foreign_key` | Foreign key column linking translations to pages. | + +### Cache Settings + +```php +'cache' => [ + 'enabled' => false, + 'folder' => __DIR__ . '/cache', + 'class' => Plugi\Cache::class +], +``` + +| Key | Description | +|-------------|-----------------------------------------------------------------------------| +| `enabled` | Enable page caching. Cached pages skip block parsing on subsequent requests. | +| `folder` | Filesystem path for cache files. | +| `class` | Class implementing `CacheContract`. | + +A page is cached unless it contains a block with caching disabled. The cache is automatically cleared when a page is saved in the page builder. You can also force a cache refresh by appending `?refresh_cache` to the URL. + +### Theme Settings + +```php +'theme' => [ + 'class' => Plugi\Theme::class, + 'folder' => __DIR__ . '/themes', + 'folder_url' => '/themes', + 'active_theme' => 'theme-one' +], +``` + +| Key | Description | +|------------------|---------------------------------------------------------------| +| `class` | Class implementing `ThemeContract`. | +| `folder` | Filesystem path to the themes directory. | +| `folder_url` | Public URL path to the themes directory. | +| `active_theme` | Slug of the active theme (matches a folder name in `themes/`). | + +### Router Settings + +```php +'router' => [ + 'class' => Plugi\Modules\Router\DatabasePageRouter::class +], +``` + +| Key | Description | +|-----------|---------------------------------------------------------------| +| `class` | Class implementing `RouterContract` that resolves URLs to pages. | + +### Class Replacements + +```php +'class_replacements' => [ + // Plugi\UploadedFile::class => Alternative\UploadedFile::class +], +``` + +Map a core class namespace to an alternative implementation. This allows overriding specific classes while extending the originals. Example: + +```php +'class_replacements' => [ + Plugi\UploadedFile::class => My\App\CustomUploadedFile::class, +], +``` + +> **Important:** When overriding a class, always extend the original class. diff --git a/Extensions.md b/Extensions.md new file mode 100644 index 0000000..b6ac477 --- /dev/null +++ b/Extensions.md @@ -0,0 +1,316 @@ +# Extensions + +Extensions (also called plugins) allow you to add functionality to Plugi without modifying the core. They can register routes, blocks, layouts, backend admin pages, assets, settings, and HTML injection points. + +## How Extensions Work + +When Plugi boots, it scans the `extensions/` directory. For each subdirectory that contains both an `extension.php` and a `config.php` file, it loads the extension and registers its features. + +## Extension Structure + +A minimal extension looks like this: + +``` +extensions/ +└── my-extension/ + ├── extension.php # Bootstrap — registers routes, blocks, etc. + ├── config.php # Metadata and configuration + ├── routes/ # Route handler files (optional) + ├── blocks/ # Theme blocks provided by the extension (optional) + ├── admin/ # Admin panel files (optional) + ├── assets/ # CSS, JS, images (optional) + └── lang/ # Translation files (optional) +``` + +## The `config.php` File + +Every extension must have a `config.php` that returns a configuration array: + +```php + 'My Extension', + 'author' => 'Your Name', + 'identifier' => 'my-extension', + 'licence' => 'MIT', + 'version' => '1.0.0', +]; +``` + +### Optional Config Keys + +| Key | Description | +|--------------|---------------------------------------------------------------| +| `settings` | Array of setting definitions for the admin panel (see below). | +| `assets` | Array of CSS/JS assets to inject on public or admin pages. | +| `tables` | Database tables the extension requires (see below). | + +### Extension Settings + +Define settings that appear in the admin panel: + +```php +'settings' => [ + [ + 'name' => 'email', + 'label' => 'Notification Email', + 'default' => 'admin@example.com', + 'type' => 'text', + ], + [ + 'name' => 'enabled', + 'label' => 'Enable Feature', + 'default' => 'true', + 'type' => 'toggle', + ], +], +``` + +Supported types: `text`, `toggle`, and others depending on the admin UI. + +### Extension Assets + +Register CSS and JS files that should be loaded on specific pages: + +```php +'assets' => [ + [ + 'src' => '/assets/dist.css', + 'type' => 'style', + 'location' => 'header', + ], + [ + 'src' => '/assets/app.js', + 'type' => 'script', + 'location' => 'footer', + ], +], +``` + +Valid locations: `header`, `footer`, `admin-header`, `admin-footer`. + +### Extension Database Tables + +Declare tables that the extension needs. Plugi will create them on first run: + +```php +'tables' => [ + 'entries' => [ + 'columns' => [ + 'formId' => 'int NOT NULL', + 'data' => 'longtext NOT NULL', + 'created' => 'timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP', + ], + 'uniqueKeys' => [], + ], + 'definitions' => [ + 'columns' => [ + 'name' => 'varchar(255) NOT NULL', + 'fields' => 'longtext NOT NULL', + 'finishers' => 'longtext NOT NULL', + ], + 'uniqueKeys' => [ + 'name' => ['name'], + ], + ], +], +``` + +## The `extension.php` File + +This file is executed at boot time. Use the `Plugi\Extensions` class to register features: + +```php + dirname(__FILE__) . '/routes/my-route.php', +]); + +// Register blocks +Extensions::addBlocks([ + 'my-block' => __DIR__ . '/blocks/my-block', +]); + +// Register layouts +Extensions::addLayouts([ + 'my-layout' => __DIR__ . '/layouts/my-layout', +]); + +// Register a backend admin page +Extensions::registerBackend('my-extension', [ + 'title' => 'My Extension', + 'include' => __DIR__ . '/admin/index.php', + 'icon' => '', +]); + +// Register assets programmatically +Extensions::registerAsset('/extensions/my-extension/app.js', 'script', 'footer'); + +// Register HTML blocks injected at specific locations +Extensions::registerHtmlBlock('', 'head'); +``` + +## Routes + +Extensions can define custom routes. Each route maps a URL path to a PHP file: + +```php +Extensions::addRoutes([ + '/sitemap.xml' => dirname(__FILE__) . '/routes/sitemap.php', +]); +``` + +The route file is a regular PHP script that has access to all Plugi globals and classes. Return `continue` from the route file to let Plugi continue processing the request: + +```php + 'My Block', + 'category' => 'Custom', + 'icon' => 'fa fa-star', + 'settings' => [ + 'message' => [ + 'label' => 'Message', + 'type' => 'text', + 'value' => 'Hello World', + ], + ], +]; +``` + +In `view.html`, access settings with the `$block` variable: + +```html +
+

setting('message') ?>

+
+``` + +For PHP blocks, use `view.php` instead. The `$block` object provides: +- `$block->setting('key')` — Get a block setting value. +- `$block->get('config_key')` — Get a value from `config.php`. + +## Backend Admin Pages + +Register a backend page that appears in the admin panel sidebar: + +```php +Extensions::registerBackend('my-extension', [ + 'title' => 'My Extension', + 'include' => __DIR__ . '/admin/index.php', + 'icon' => '', +]); +``` + +The `include` file is a PHP view rendered inside the admin panel. It has access to all Plugi classes and helpers. + +## Translations + +Place translation files in the `lang/` directory: + +``` +lang/ +├── en.php +└── de.php +``` + +Each file returns an associative array: + +```php + [ + 'welcome' => 'Welcome!', + 'save' => 'Save', + ], +]; +``` + +Use translations in your code: + +```php +phpb_trans('my-extension.welcome') +``` + +## Helper Functions + +The following global helper functions are available in extension code: + +| Function | Description | +|---------------------------------|--------------------------------------------------| +| `phpb_config('key')` | Get a config value using dot notation. | +| `phpb_trans('key')` | Get a translated string. | +| `phpb_e($string)` | Escape output for HTML. | +| `phpb_current_language()` | Get the current language code. | +| `phpb_current_relative_url()` | Get the current request URL. | +| `phpb_redirect($url)` | Redirect to a URL. | +| `phpb_instance($key, $args=[])` | Create an instance of a configured class. | +| `phpb_asset($path)` | Generate a URL to a Plugi core asset. | +| `phpb_theme_asset($path)` | Generate a URL to a theme asset. | + +## Example: Sitemap Extension + +The `plugi-ext-sitemap` extension demonstrates a minimal extension: + +**config.php:** +```php + 'Sitemap', + 'author' => 'Paul Spenke', + 'identifier' => 'sitemap', + 'licence' => 'MIT', + 'version' => '1.0.0', +]; +``` + +**extension.php:** +```php + dirname(__FILE__) . '/routes/sitemap.php' +]); +``` + +**routes/sitemap.php:** +```php + true`) for better performance. +4. Ensure the `uploads/` directory is writable but not executable. +5. Consider using `.htaccess` (Apache) or Nginx config to serve `/uploads` directly, bypassing PHP for faster file delivery. + +## Next Steps + +- Learn how to [configure](Configuration.md) Plugi in detail. +- Discover how to create custom [themes](Themes.md). +- Build your own [extensions](Extensions.md) to add functionality. diff --git a/Readme.md b/Readme.md new file mode 100644 index 0000000..016fd98 --- /dev/null +++ b/Readme.md @@ -0,0 +1,67 @@ +![Plugi](https://gitea.spenke-nordic.com/deepDiverPaul/plugi/raw/branch/main/plugi-core/dist/images/plugi-banner.png) + +# Plugi + +A lightweight PHP-based website builder with a drag-and-drop page editor, theming system, and extensible plugin architecture. + +> A fork of [PHPagebuilder](https://github.com/HansSchouten/PHPagebuilder) by [Hans Schouten](https://github.com/HansSchouten). + +## Quick Start + +Get up and running in minutes: + +1. **Download** Plugi and upload it to your webroot. +2. **Create** a `.env` file with your database credentials. +3. **Copy** `config.dist.php` to `config.php` and adjust settings. +4. **Navigate** to `/admin` and log in with the default credentials (`admin` / `admin`). + +Or use Docker for a quick local setup: + +```bash +docker-compose up -d +``` + +Then open `http://localhost:63000/admin` in your browser. + +## Key Features + +- **Page Builder** — Visual drag-and-drop editor powered by GrapesJS for designing pages without code. +- **Theming System** — Create custom themes with reusable blocks, layouts, and static pages. +- **Extensions** — Extend functionality with plugins that add routes, admin pages, blocks, and more. +- **Multilingual** — Built-in translation support for pages, themes, and extensions. +- **Caching** — Optional page caching for production performance. +- **Database-Driven** — All content stored in MySQL with automatic schema management. + +## Documentation + +| Section | Description | +|---------|-------------| +| [Getting Started](GettingStarted.md) | Installation, requirements, and first steps. | +| [Configuration](Configuration.md) | Full reference for `.env` and `config.php` settings. | +| [Themes](Themes.md) | How to create and structure custom themes with blocks and layouts. | +| [Extensions](Extensions.md) | How to build extensions that add routes, admin pages, blocks, and more. | + +## Requirements + +- **PHP 8.2** or higher +- **MySQL 8.0** or higher +- **Apache** or **Nginx** web server +- **PDO MySQL** extension enabled + +## Project Structure + +``` +project-root/ +├── index.php # Entry point +├── config.php # Configuration +├── .env # Environment variables +├── plugi-core/ # Core framework +├── extensions/ # Extensions (plugins) +├── themes/ # Themes +├── uploads/ # User-uploaded files +└── docs/ # Documentation +``` + +## License + +Plugi is open-source software under MIT License. diff --git a/Themes.md b/Themes.md new file mode 100644 index 0000000..59d08fe --- /dev/null +++ b/Themes.md @@ -0,0 +1,334 @@ +# Themes + +Themes define the visual appearance and building blocks of your Plugi website. Each theme contains **blocks** (reusable page components), **layouts** (page templates), static pages, and compiled assets. + +## Theme Structure + +A theme lives in the `themes/` directory as a subfolder. The folder name is the theme's slug: + +``` +themes/ +└── theme-one/ + ├── config.php # Theme metadata and settings + ├── preview.jpg # Theme preview image (shown in admin) + ├── blocks/ # Reusable page components + │ ├── paragraph/ + │ │ ├── config.php + │ │ └── view.html + │ ├── quote/ + │ │ ├── config.php + │ │ └── view.php + │ └── ... + ├── layouts/ # Page layout templates + │ └── master/ + │ ├── config.php + │ └── view.php + ├── pages/ # Static pages (e.g., 404.php) + ├── translations/ # Theme-specific translations + │ ├── en.php + │ └── de.php + ├── dist/ # Compiled CSS and JS + │ ├── style.css + │ └── script.js + ├── src/ # Source files (Sass, TypeScript, etc.) + └── package.json # Node.js dependencies for building assets +``` + +## Theme Configuration + +The `config.php` file defines theme metadata and optional settings: + +```php + 'Theme One', + 'author' => 'Your Name', + 'licence' => 'MIT', + 'version' => '1.0.0', + 'settings' => [ + [ + 'name' => 'primaryColor', + 'label' => 'Primary Color', + 'default' => '#3b82f6', + 'type' => 'text', + ], + ], +]; +``` + +| Key | Description | +|-------------|---------------------------------------------------------------| +| `title` | Display name of the theme. | +| `author` | Theme author name. | +| `licence` | License identifier. | +| `version` | Semantic version string. | +| `settings` | Array of setting definitions available in the admin panel. | + +## Blocks + +Blocks are the building blocks of your pages. Each block is a subfolder inside `blocks/` and contains at minimum a `config.php` and a view file. + +### Block Folders + +Blocks can be organized into subfolders: + +| Subfolder | Purpose | +|-----------------|------------------------------------------------------------| +| (root) | Default blocks, always available. | +| `archived/` | Deprecated or archived blocks. | +| `elements/` | Reusable UI elements. | +| `php/` | Blocks that require PHP execution. | + +### Block Files + +A block directory can contain the following files: + +| File | Required | Description | +|-------------------------|----------|------------------------------------------------------------| +| `config.php` | Yes | Block configuration (title, icon, settings, category). | +| `view.html` | One of | HTML template for the block. | +| `view.php` | these | PHP template for the block (enables PHP execution). | +| `controller.php` | No | Custom controller class for the block. | +| `model.php` | No | Custom model class for the block. | +| `script.js` | No | JavaScript executed on the public page. | +| `builder-script.js` | No | JavaScript executed in the page builder preview. | + +### Block Configuration + +```php + 'Quote', + 'category' => 'General', + 'icon' => 'fa fa-quote-left', + 'hidden' => false, // Hide from block library if true + 'cache' => true, // Allow caching (default: true) + 'cache_lifetime' => 3600, // Cache TTL in seconds + 'wrapper' => 'div', // Wrapper element for PHP blocks + 'whitelist' => [], // Domain whitelist (empty = all domains) + 'settings' => [ + 'person' => [ + 'label' => 'Person Name', + 'type' => 'text', + 'placeholder' => 'John Doe', + 'value' => 'Michael Gough', + ], + ], +]; +``` + +### Block Views + +**HTML blocks** (`view.html`) are rendered as-is. Use `{{ setting_name }}` syntax for settings: + +```html +
+

{{ content }}

+
+``` + +**PHP blocks** (`view.php`) have full PHP access. The `$block` variable provides: + +```php +
+
+

"setting('quote_text') ?>"

+
+ — setting('person') ?> +
+``` + +Available methods on `$block`: +- `$block->setting('key')` — Get a setting value. +- `$block->get('config_key')` — Get a value from `config.php`. +- `$block->get('config.nested.key')` — Dot notation for nested config. + +### Block Controllers and Models + +For complex blocks, you can add a controller and/or model: + +**controller.php:** +```php +view['extra_data'] = 'hello'; + } +} +``` + +**model.php:** +```php + 'MyCustom\Namespace', +``` + +## Layouts + +Layouts define the overall page structure (header, navigation, footer). Each layout is a subfolder inside `layouts/`. + +### Layout Files + +| File | Required | Description | +|----------------|----------|------------------------------------------------------------| +| `config.php` | No | Layout configuration. | +| `view.php` | Yes | PHP template for the layout. | + +### Layout View + +The layout view receives two variables: +- `$body` — The rendered page content (blocks). +- `$page` — The current page object. + +Example `view.php`: + +```php + + + + + <?= phpb_e($page->getTranslation('meta_title')) ?> + + + + +
+ +
+ +
+ +
+ + + + + + + +``` + +### Available Variables in Layouts + +| Variable | Description | +|-------------|------------------------------------------------| +| `$body` | Rendered page content (all blocks combined). | +| `$page` | Current `Page` object with translation methods.| + +### Page Methods + +- `$page->getTranslation('field')` — Get a translated field value. +- `$page->get('field')` — Get a page field value. +- `$page->get('type')` — Get page type (e.g., `redirect`). + +## Static Pages + +Place static PHP pages in the `pages/` directory. Plugi looks for special pages here: + +- `404.php` — Custom 404 error page. + +## Translations + +Theme translations go in the `translations/` directory: + +```php + [ + 'welcome' => 'Welcome to our site', + 'footer' => 'All rights reserved', + ], +]; +``` + +Translations are merged with core translations and can be overridden per language. + +## Assets + +Themes typically use a build pipeline (Webpack, Vite, etc.) to compile source files into the `dist/` directory: + +``` +theme-one/ +├── src/ +│ ├── styles/ +│ │ └── main.scss +│ └── scripts/ +│ └── main.ts +├── dist/ +│ ├── style.css # Compiled CSS +│ └── script.js # Compiled JS +└── package.json # Build dependencies +``` + +Reference compiled assets in your views: + +```php + + +``` + +## Creating a New Theme + +1. **Create a folder** inside `themes/` with your theme's slug: + + ```bash + mkdir themes/my-theme + ``` + +2. **Add `config.php`**: + + ```php + 'My Theme', + 'author' => 'Your Name', + 'licence' => 'MIT', + 'version' => '1.0.0', + ]; + ``` + +3. **Create a layout** in `layouts/master/view.php` with your HTML structure. + +4. **Add blocks** in `blocks/` with `config.php` and view files. + +5. **Set as active** in `config.php`: + + ```php + 'theme' => [ + 'active_theme' => 'my-theme', + ], + ``` + +6. **Add a preview image** (`preview.jpg`) so the theme appears in the admin panel's theme selector. + +## Switching Themes + +You can switch themes from the admin panel (Settings → Theme) or by changing `theme.active_theme` in `config.php`. The value must match a folder name inside `themes/`. + +## Extension Blocks and Layouts + +Extensions can also provide blocks and layouts that are merged with the active theme's blocks and layouts. See the [Extensions](Extensions.md) documentation for details. diff --git a/_sidebar.md b/_sidebar.md new file mode 100644 index 0000000..0405e6b --- /dev/null +++ b/_sidebar.md @@ -0,0 +1,10 @@ +- Plugi Core + + - [Home](Readme.md) + - [Getting Started](GettingStarted.md) + - [Configuration](Configuration.md) + +- Customization + + - [Themes](Themes.md) + - [Extensions](Extensions.md) diff --git a/favicon.ico b/favicon.ico new file mode 100644 index 0000000..187b66b Binary files /dev/null and b/favicon.ico differ diff --git a/index.html b/index.html new file mode 100644 index 0000000..3f88f69 --- /dev/null +++ b/index.html @@ -0,0 +1,23 @@ + + + + + Document + + + + + + +
+ + + + +