Merge development v2.6.0 into main

Resolved conflicts by taking development (v2.6.0) version for all files.
Removed statistics.twig (replaced by Statistics plugin).
This commit is contained in:
2026-08-15 19:32:47 +02:00
207 changed files with 3736 additions and 23879 deletions
+234
View File
@@ -0,0 +1,234 @@
<?php
class Dashboard
{
private ?PluginAPIInterface $api = null;
public function setAPI(PluginAPIInterface $api): void
{
$this->api = $api;
}
public function getConfig(): array
{
return [
'title' => 'Dashboard',
'viewable' => false,
'type' => 'system',
];
}
public function getAdminMenu(): array
{
return [
[
'plugin' => 'Dashboard',
'route' => 'dashboard',
'label' => 'Dashboard',
'icon' => 'bi-speedometer2',
'section' => 'general',
],
];
}
public function handleAdminRoute(string $action): ?string
{
$siteConfig = $this->getSiteConfig();
$contentDir = $this->api ? $this->api->getContentDir() : '';
$pluginsDir = $this->api ? $this->api->getPluginsDir() : '';
$enabledPlugins = $this->api ? $this->api->getEnabledPlugins() : [];
$versionInfo = $this->api ? $this->api->getVersionInfo() : ['version' => '0.0.0'];
$stats = [
'pages' => $this->countFiles($contentDir, ['md', 'php', 'html']),
'directories' => $this->countDirs($contentDir),
'content_size' => $this->formatSize($this->dirSize($contentDir)),
'config_exists' => !empty($siteConfig),
'php_version' => PHP_VERSION,
'cms_version' => $versionInfo['version'] ?? '0.0.0',
'os' => PHP_OS_FAMILY . ' (' . php_uname('r') . ')',
];
// Build plugin overview
$pluginOverview = [];
if (is_dir($pluginsDir)) {
foreach (glob($pluginsDir . '/*', GLOB_ONLYDIR) as $pluginDir) {
$pluginName = basename($pluginDir);
$pluginType = $this->getPluginType($pluginDir, $pluginName);
$pluginOverview[$pluginName] = [
'enabled' => in_array($pluginName, $enabledPlugins, true),
'type' => $pluginType,
];
}
}
ksort($pluginOverview);
$siteTitle = $siteConfig['site_title'] ?? 'CodePress';
$defaultLang = $siteConfig['language']['default'] ?? 'nl';
ob_start();
?>
<h2 class="mb-4"><i class="bi bi-speedometer2"></i> Dashboard</h2>
<div class="row g-4">
<div class="col-md-6">
<div class="card shadow-sm">
<div class="card-header"><i class="bi bi-info-circle"></i> Site informatie</div>
<div class="card-body">
<table class="table table-sm mb-0">
<tr><td class="text-muted">Site titel</td><td><?= htmlspecialchars($siteTitle) ?></td></tr>
<tr><td class="text-muted">Standaard taal</td><td><?= htmlspecialchars($defaultLang) ?></td></tr>
<tr><td class="text-muted">CodePress versie</td><td><?= htmlspecialchars($stats['cms_version']) ?></td></tr>
<tr><td class="text-muted">PHP versie</td><td><?= htmlspecialchars($stats['php_version']) ?></td></tr>
<tr><td class="text-muted">Besturingssysteem</td><td><?= htmlspecialchars($stats['os']) ?></td></tr>
<tr><td class="text-muted">Config geladen</td><td><?php if ($stats['config_exists']): ?><span class="badge bg-success">Ja</span><?php else: ?><span class="badge bg-danger">Nee</span><?php endif; ?></td></tr>
</table>
</div>
</div>
</div>
<div class="col-md-6">
<div class="card shadow-sm">
<div class="card-header"><i class="bi bi-folder2-open"></i> Content informatie</div>
<div class="card-body">
<table class="table table-sm mb-0">
<tr><td class="text-muted">Pagina's</td><td><span class="badge bg-primary"><?= $stats['pages'] ?></span></td></tr>
<tr><td class="text-muted">Mappen</td><td><span class="badge bg-warning text-dark"><?= $stats['directories'] ?></span></td></tr>
<tr><td class="text-muted">Content grootte</td><td><?= htmlspecialchars($stats['content_size']) ?></td></tr>
</table>
</div>
</div>
</div>
<div class="col-md-6">
<div class="card shadow-sm">
<div class="card-header d-flex justify-content-between align-items-center">
<span><i class="bi bi-plug"></i> Plugins</span>
<a href="/admin/plugins" class="btn btn-sm btn-outline-secondary">Beheren</a>
</div>
<div class="card-body">
<table class="table table-sm mb-0">
<?php foreach ($pluginOverview as $pluginName => $info): ?>
<tr>
<td>
<i class="bi bi-plug-fill"></i> <?= htmlspecialchars($pluginName) ?>
<?php if ($info['type'] === 'system'): ?>
<span class="badge bg-secondary fs-7">systeem</span>
<?php else: ?>
<span class="badge bg-info fs-7">content</span>
<?php endif; ?>
</td>
<td>
<?php if ($info['enabled']): ?>
<span class="badge bg-success">Actief</span>
<?php else: ?>
<span class="badge bg-secondary">Inactief</span>
<?php endif; ?>
</td>
</tr>
<?php endforeach; ?>
<?php if (empty($pluginOverview)): ?>
<tr><td colspan="2" class="text-muted text-center">Geen plugins gevonden.</td></tr>
<?php endif; ?>
</table>
</div>
</div>
</div>
</div>
<?php
return ob_get_clean();
}
private function getSiteConfig(): array
{
if ($this->api === null) {
return [];
}
// AdminPluginAPI holds the full site config
if ($this->api instanceof AdminPluginAPI) {
return $this->api->getConfig('', []) ?? [];
}
return [];
}
private function getPluginType(string $pluginDir, string $pluginName): string
{
$pluginFile = $pluginDir . '/' . $pluginName . '.php';
if (!file_exists($pluginFile)) {
return 'content';
}
// Read the file to find 'type' in the config array
$source = file_get_contents($pluginFile);
if (preg_match("/'type'\s*=>\s*'([^']+)'/", $source, $m)) {
return $m[1];
}
return 'content';
}
private function countFiles(string $dir, array $extensions = []): int
{
if (!is_dir($dir)) return 0;
$count = 0;
$iterator = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($dir, RecursiveDirectoryIterator::SKIP_DOTS)
);
foreach ($iterator as $file) {
if (!$file->isFile()) continue;
// Skip hidden/dash-prefixed
$relative = substr($file->getRealPath(), strlen(realpath($dir)) + 1);
$skip = false;
foreach (explode('/', str_replace('\\', '/', $relative)) as $seg) {
if ($seg !== '' && ($seg[0] === '.' || $seg[0] === '-')) { $skip = true; break; }
}
if ($skip) continue;
$ext = strtolower($file->getExtension());
if (empty($extensions) || in_array($ext, $extensions, true)) {
$count++;
}
}
return $count;
}
private function countDirs(string $dir): int
{
if (!is_dir($dir)) return 0;
$count = 0;
$iterator = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($dir, RecursiveDirectoryIterator::SKIP_DOTS),
RecursiveIteratorIterator::SELF_FIRST
);
foreach ($iterator as $file) {
if ($file->isDir()) {
$name = $file->getFilename();
if ($name[0] === '.' || $name[0] === '-') continue;
$count++;
}
}
return $count;
}
private function dirSize(string $dir): int
{
if (!is_dir($dir)) return 0;
$size = 0;
$iterator = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($dir, RecursiveDirectoryIterator::SKIP_DOTS)
);
foreach ($iterator as $file) {
if ($file->isFile()) {
$size += $file->getSize();
}
}
return $size;
}
private function formatSize(int $bytes): string
{
if ($bytes <= 0) return '0 B';
$units = ['B', 'KB', 'MB', 'GB'];
$pow = floor(($bytes ? log($bytes) : 0) / log(1024));
$pow = min($pow, count($units) - 1);
$bytes /= pow(1024, $pow);
return round($bytes, 2) . ' ' . $units[$pow];
}
}
+9
View File
@@ -0,0 +1,9 @@
{
"name": "Dashboard",
"version": "1.0.0",
"author": "CodePress",
"description": "Toont site informatie, content statistieken en plugin overzicht op het dashboard.",
"type": "system",
"essential": true,
"hasConfig": false
}
+4 -3
View File
@@ -3,16 +3,17 @@
class HTMLBlock
{
private array $config;
private ?CMSAPI $api = null;
private ?PluginAPIInterface $api = null;
public function __construct()
{
$this->config = [
'title' => 'HTML Block Plugin'
'title' => 'HTML Block Plugin',
'type' => 'content',
];
}
public function setAPI(CMSAPI $api): void
public function setAPI(PluginAPIInterface $api): void
{
$this->api = $api;
}
+5 -3
View File
@@ -1,7 +1,9 @@
{
"name": "HTMLBlock",
"name": "HTML Block",
"version": "1.0.0",
"author": "CodePress",
"description": "Voorbeeld sidebar plugin met pagina info en quick navigation",
"type": "content"
"description": "Toont aangepaste HTML-blokken in de sidebar van content-pagina's.",
"type": "content",
"essential": false,
"hasConfig": false
}
+101
View File
@@ -0,0 +1,101 @@
<?php
class Logs
{
private ?PluginAPIInterface $api = null;
public function setAPI(PluginAPIInterface $api): void
{
$this->api = $api;
}
public function getConfig(): array
{
return [
'title' => 'Logs',
'viewable' => false,
'type' => 'system',
];
}
public function getAdminMenu(): array
{
return [
[
'plugin' => 'Logs',
'route' => 'logs',
'label' => 'Logs',
'icon' => 'bi-journal-text',
'section' => 'general',
],
];
}
public function handleAdminRoute(string $action): ?string
{
$tab = $_GET['tab'] ?? 'admin';
$logDir = dirname(__DIR__, 2) . '/admin/storage/logs';
$logFile = $tab === 'requests' ? $logDir . '/requests.log' : $logDir . '/admin.log';
$logs = [];
if (file_exists($logFile)) {
$lines = file($logFile) ?: [];
$lines = array_slice($lines, -100);
foreach ($lines as $line) {
if (preg_match('/^\[([^\]]+)\] \[([^\]]+)\] \[([^\]]+)\] (.+)$/', trim($line), $m)) {
$logs[] = [
'time' => $m[1],
'level' => strtolower($m[2]),
'ip' => $m[3],
'message' => $m[4],
];
}
}
$logs = array_reverse($logs);
}
ob_start();
?>
<h2 class="mb-4"><i class="bi bi-journal-text"></i> Logs</h2>
<ul class="nav nav-tabs mb-3">
<li class="nav-item">
<a class="nav-link <?= $tab === 'admin' ? 'active' : '' ?>" href="/admin/logs?tab=admin">Admin</a>
</li>
<li class="nav-item">
<a class="nav-link <?= $tab === 'requests' ? 'active' : '' ?>" href="/admin/logs?tab=requests">Requests</a>
</li>
</ul>
<div class="card shadow-sm">
<div class="card-body p-0">
<table class="table table-hover mb-0">
<thead>
<tr>
<th>Tijd</th>
<th>Level</th>
<th>IP</th>
<th>Bericht</th>
</tr>
</thead>
<tbody>
<?php if (empty($logs)): ?>
<tr><td colspan="4" class="text-muted text-center py-4">Geen logs gevonden.</td></tr>
<?php else: ?>
<?php foreach ($logs as $log): ?>
<tr>
<td class="text-muted small"><?= htmlspecialchars($log['time']) ?></td>
<td><span class="badge bg-<?= $log['level'] === 'warning' ? 'warning text-dark' : ($log['level'] === 'error' ? 'danger' : 'info') ?>"><?= htmlspecialchars($log['level']) ?></span></td>
<td><code class="text-muted"><?= htmlspecialchars($log['ip']) ?></code></td>
<td><?= htmlspecialchars($log['message']) ?></td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
</tbody>
</table>
</div>
</div>
<?php
return ob_get_clean();
}
}
+9
View File
@@ -0,0 +1,9 @@
{
"name": "Logs",
"version": "1.0.0",
"author": "CodePress",
"description": "Toont admin activiteitlogs en front-end request logs met filter tabs.",
"type": "system",
"essential": false,
"hasConfig": true
}
+2 -2
View File
@@ -3,7 +3,7 @@
class Navigation
{
private array $config;
private ?CMSAPI $api = null;
private ?PluginAPIInterface $api = null;
public function __construct()
{
@@ -14,7 +14,7 @@ class Navigation
];
}
public function setAPI(CMSAPI $api): void
public function setAPI(PluginAPIInterface $api): void
{
$this->api = $api;
}
+3 -1
View File
@@ -3,5 +3,7 @@
"version": "1.0.0",
"author": "CodePress",
"description": "Essentiële navigatie plugin voor handleidingen en content",
"type": "content"
"type": "content",
"essential": true,
"hasConfig": false
}
+147
View File
@@ -0,0 +1,147 @@
<?php
class Statistics
{
private ?PluginAPIInterface $api = null;
public function setAPI(PluginAPIInterface $api): void
{
$this->api = $api;
}
public function getConfig(): array
{
return [
'title' => 'Statistics',
'viewable' => false,
'type' => 'system',
];
}
public function getAdminMenu(): array
{
return [
[
'plugin' => 'Statistics',
'route' => 'statistics',
'label' => 'Statistieken',
'icon' => 'bi-bar-chart',
'section' => 'general',
],
];
}
public function handleAdminRoute(string $action): ?string
{
$analytics = $this->getAnalytics();
if ($analytics === null) {
return '<div class="alert alert-warning">Analytics is uitgeschakeld.</div>';
}
$stats = $analytics->getStats();
$totals = $stats['totals'] ?? ['views' => 0, 'uniques' => 0, 'pages' => []];
$countries = $stats['countries'] ?? [];
$topPages = $stats['top_pages'] ?? $totals['pages'] ?? [];
ob_start();
?>
<h2 class="mb-4"><i class="bi bi-bar-chart"></i> Statistieken</h2>
<div class="row g-4 mb-4">
<div class="col-md-4">
<div class="card stat-card shadow-sm">
<div class="card-body d-flex justify-content-between align-items-center">
<div>
<h6 class="text-muted mb-1">Totaal aantal views</h6>
<h3 class="mb-0"><?= number_format($totals['views'] ?? 0, 0, ',', '.') ?></h3>
</div>
<i class="bi bi-eye stat-icon text-primary"></i>
</div>
</div>
</div>
<div class="col-md-4">
<div class="card stat-card shadow-sm">
<div class="card-body d-flex justify-content-between align-items-center">
<div>
<h6 class="text-muted mb-1">Unieke bezoekers</h6>
<h3 class="mb-0"><?= number_format($totals['uniques'] ?? 0, 0, ',', '.') ?></h3>
</div>
<i class="bi bi-people stat-icon text-success"></i>
</div>
</div>
</div>
<div class="col-md-4">
<div class="card stat-card shadow-sm">
<div class="card-body d-flex justify-content-between align-items-center">
<div>
<h6 class="text-muted mb-1">Pagina views</h6>
<h3 class="mb-0"><?= number_format($totals['page_views'] ?? ($totals['views'] ?? 0), 0, ',', '.') ?></h3>
</div>
<i class="bi bi-file-earmark-text stat-icon text-info"></i>
</div>
</div>
</div>
</div>
<div class="row g-4">
<div class="col-md-6">
<div class="card shadow-sm">
<div class="card-header"><i class="bi bi-globe"></i> Landen</div>
<div class="card-body">
<?php if (empty($countries)): ?>
<p class="text-muted mb-0">Geen data</p>
<?php else: ?>
<table class="table table-sm mb-0">
<thead><tr><th>Land</th><th>Views</th></tr></thead>
<tbody>
<?php foreach ($countries as $country => $count): ?>
<tr>
<td><?= GeoIP::getCountryFlagEmoji($country) ?> <?= htmlspecialchars(GeoIP::getCountryName($country)) ?></td>
<td><?= number_format($count, 0, ',', '.') ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php endif; ?>
</div>
</div>
</div>
<div class="col-md-6">
<div class="card shadow-sm">
<div class="card-header"><i class="bi bi-file-earmark-bar"></i> Top pagina's</div>
<div class="card-body">
<?php if (empty($topPages)): ?>
<p class="text-muted mb-0">Geen data</p>
<?php else: ?>
<table class="table table-sm mb-0">
<thead><tr><th>Pagina</th><th>Views</th></tr></thead>
<tbody>
<?php foreach ($topPages as $page => $count): ?>
<tr>
<td><?= htmlspecialchars($page) ?></td>
<td><?= number_format($count, 0, ',', '.') ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php endif; ?>
</div>
</div>
</div>
</div>
<?php
return ob_get_clean();
}
private function getAnalytics(): ?Analytics
{
if ($this->api === null) {
return null;
}
$analyticsConfig = $this->api->getConfig('analytics', []);
if (!is_array($analyticsConfig) || empty($analyticsConfig['enabled'])) {
return null;
}
return new Analytics($analyticsConfig);
}
}
+9
View File
@@ -0,0 +1,9 @@
{
"name": "Statistics",
"version": "1.0.0",
"author": "CodePress",
"description": "Bezoekersstatistieken: totaal aantal views, unieke bezoekers, landen en top pagina's.",
"type": "system",
"essential": false,
"hasConfig": true
}