Fix guide template variable replacement and enhance documentation
- Fix template variable replacement in guide pages by removing {{}} brackets
- Escape code blocks in guide markdown to prevent template processing
- Completely rewrite guide documentation with comprehensive CMS features
- Add bilingual guide support (English/Dutch) with detailed examples
- Enhance CodePressCMS core with improved guide page handling
- Update template system with better layout and footer components
- Improve language files with additional translations
- Update configuration with enhanced theme and language settings
Resolves issue where guide pages were showing replaced template variables
instead of displaying them as documentation examples.
This commit is contained in:
216
engine/core/plugin/CMSAPI.php
Normal file
216
engine/core/plugin/CMSAPI.php
Normal file
@@ -0,0 +1,216 @@
|
||||
<?php
|
||||
|
||||
class CMSAPI
|
||||
{
|
||||
private CodePressCMS $cms;
|
||||
|
||||
public function __construct(CodePressCMS $cms)
|
||||
{
|
||||
$this->cms = $cms;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current page information
|
||||
*/
|
||||
public function getCurrentPage(): array
|
||||
{
|
||||
return $this->cms->getPage();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current page title
|
||||
*/
|
||||
public function getCurrentPageTitle(): string
|
||||
{
|
||||
$page = $this->cms->getPage();
|
||||
return $page['title'] ?? '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current page content
|
||||
*/
|
||||
public function getCurrentPageContent(): string
|
||||
{
|
||||
$page = $this->cms->getPage();
|
||||
return $page['content'] ?? '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current page URL
|
||||
*/
|
||||
public function getCurrentPageUrl(): string
|
||||
{
|
||||
$page = $_GET['page'] ?? $this->cms->config['default_page'];
|
||||
$lang = $_GET['lang'] ?? $this->cms->config['language']['default'] ?? 'nl';
|
||||
return "?page={$page}&lang={$lang}";
|
||||
}
|
||||
|
||||
/**
|
||||
* Get menu structure
|
||||
*/
|
||||
public function getMenu(): array
|
||||
{
|
||||
return $this->cms->getMenu();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get configuration value
|
||||
*/
|
||||
public function getConfig(string $key, $default = null)
|
||||
{
|
||||
$keys = explode('.', $key);
|
||||
$value = $this->cms->config;
|
||||
|
||||
foreach ($keys as $k) {
|
||||
if (!isset($value[$k])) {
|
||||
return $default;
|
||||
}
|
||||
$value = $value[$k];
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get translation
|
||||
*/
|
||||
public function translate(string $key): string
|
||||
{
|
||||
return $this->cms->t($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current language
|
||||
*/
|
||||
public function getCurrentLanguage(): string
|
||||
{
|
||||
return $this->cms->currentLanguage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if user is on homepage
|
||||
*/
|
||||
public function isHomepage(): bool
|
||||
{
|
||||
$defaultPage = $this->cms->config['default_page'] ?? 'index';
|
||||
$currentPage = $_GET['page'] ?? $defaultPage;
|
||||
return $currentPage === $defaultPage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get file info for current page
|
||||
*/
|
||||
public function getCurrentPageFileInfo(): ?array
|
||||
{
|
||||
$page = $this->cms->getPage();
|
||||
return $page['file_info'] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get breadcrumb data
|
||||
*/
|
||||
public function getBreadcrumb(): string
|
||||
{
|
||||
return $this->cms->generateBreadcrumb();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if content directory has content
|
||||
*/
|
||||
public function hasContent(): bool
|
||||
{
|
||||
return !$this->cms->isContentDirEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get search results if searching
|
||||
*/
|
||||
public function getSearchResults(): array
|
||||
{
|
||||
if (isset($_GET['search'])) {
|
||||
return $this->cms->searchResults;
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if currently searching
|
||||
*/
|
||||
public function isSearching(): bool
|
||||
{
|
||||
return isset($_GET['search']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get available languages
|
||||
*/
|
||||
public function getAvailableLanguages(): array
|
||||
{
|
||||
return $this->cms->getAvailableLanguages();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create URL for page
|
||||
*/
|
||||
public function createUrl(string $page, ?string $lang = null): string
|
||||
{
|
||||
$lang = $lang ?? $this->getCurrentLanguage();
|
||||
return "?page={$page}&lang={$lang}";
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute PHP file and capture output
|
||||
*/
|
||||
public function executePhpFile(string $filePath): string
|
||||
{
|
||||
if (!file_exists($filePath)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
ob_start();
|
||||
include $filePath;
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get content from PHP/HTML/Markdown file
|
||||
*/
|
||||
public function getFileContent(string $filePath): string
|
||||
{
|
||||
if (!file_exists($filePath)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$extension = pathinfo($filePath, PATHINFO_EXTENSION);
|
||||
|
||||
switch ($extension) {
|
||||
case 'php':
|
||||
return $this->executePhpFile($filePath);
|
||||
case 'md':
|
||||
$content = file_get_contents($filePath);
|
||||
$result = $this->cms->parseMarkdown($content, $filePath);
|
||||
return $result['content'] ?? '';
|
||||
case 'html':
|
||||
return file_get_contents($filePath);
|
||||
default:
|
||||
return file_get_contents($filePath);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if file exists in content directory
|
||||
*/
|
||||
public function contentFileExists(string $filename): bool
|
||||
{
|
||||
$contentDir = $this->cms->config['content_dir'];
|
||||
return file_exists($contentDir . '/' . $filename);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all pages with their metadata
|
||||
*/
|
||||
public function getAllPages(): array
|
||||
{
|
||||
return $this->cms->getAllPageTitles();
|
||||
}
|
||||
}
|
||||
77
engine/core/plugin/PluginManager.php
Normal file
77
engine/core/plugin/PluginManager.php
Normal file
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
class PluginManager
|
||||
{
|
||||
private array $plugins = [];
|
||||
private string $pluginsPath;
|
||||
private ?CMSAPI $api = null;
|
||||
|
||||
public function __construct(string $pluginsPath)
|
||||
{
|
||||
$this->pluginsPath = $pluginsPath;
|
||||
$this->loadPlugins();
|
||||
}
|
||||
|
||||
public function setAPI(CMSAPI $api): void
|
||||
{
|
||||
$this->api = $api;
|
||||
|
||||
// Inject API into all plugins that have setAPI method
|
||||
foreach ($this->plugins as $plugin) {
|
||||
if (method_exists($plugin, 'setAPI')) {
|
||||
$plugin->setAPI($api);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function loadPlugins(): void
|
||||
{
|
||||
if (!is_dir($this->pluginsPath)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$pluginDirs = glob($this->pluginsPath . '/*', GLOB_ONLYDIR);
|
||||
|
||||
foreach ($pluginDirs as $pluginDir) {
|
||||
$pluginName = basename($pluginDir);
|
||||
$pluginFile = $pluginDir . '/' . $pluginName . '.php';
|
||||
|
||||
if (file_exists($pluginFile)) {
|
||||
require_once $pluginFile;
|
||||
|
||||
$className = $pluginName;
|
||||
if (class_exists($className)) {
|
||||
$this->plugins[$pluginName] = new $className();
|
||||
|
||||
// Inject API if already available
|
||||
if ($this->api && method_exists($this->plugins[$pluginName], 'setAPI')) {
|
||||
$this->plugins[$pluginName]->setAPI($this->api);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function getPlugin(string $name): ?object
|
||||
{
|
||||
return $this->plugins[$name] ?? null;
|
||||
}
|
||||
|
||||
public function getAllPlugins(): array
|
||||
{
|
||||
return $this->plugins;
|
||||
}
|
||||
|
||||
public function getSidebarContent(): string
|
||||
{
|
||||
$sidebarContent = '';
|
||||
|
||||
foreach ($this->plugins as $plugin) {
|
||||
if (method_exists($plugin, 'getSidebarContent')) {
|
||||
$sidebarContent .= $plugin->getSidebarContent();
|
||||
}
|
||||
}
|
||||
|
||||
return $sidebarContent;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user