Files
CodePress/plugins/HTMLBlock/HTMLBlock.php
T
E.Noorlander d9ea2eee47 v2.6.5 (Lyra): Dynamische pad-resolutie, WordPress-stijl docblocks, security-fix wachtwoord, git-historie schoon
- Bug: dashboard toonde 0 content (AdminPluginAPI::getContentDir() gaf relatief pad terug zonder normalisatie)
- Dynamische pad-resolutie: PluginAPIInterface uitgebreid met getProjectRoot/getContentDir/getPluginsDir/getVersionInfo; CMSAPI en AdminPluginAPI implementeren deze universeel
- public/index.php media-serving gebruikt $config['content_dir'] i.p.v. hardcoded /content
- Navigation en Logs plugins halen paden via de API i.p.v. hardcoded dirname(__DIR__)
- WordPress-stijl docblocks toegevoegd voor alle classes, methods, properties en functies (~450 docblocks, @since 2.6.5)
- Security: hardcoded plaintext-wachtwoord 'admin' verwijderd uit AdminAuth.php; bij eerste installatie wordt een cryptografisch veilig wachtwoord gegenereerd (random_bytes, 16 tekens) en eenmalig op het inlogscherm getoond
- Security: git-geschiedenis schoongemaakt (admin.json, admin.json.example, admin-console/config/admin.json verwijderd uit alle commits; filter-branch over alle branches + tags, gc --prune --aggressive)
- README.md, README.en.md, AGENTS.md bijgewerkt
- Test-scripts bijgewerkt naar clean-URL structuur + actuele ARIA-waarden
- Versie verhoogd naar 2.6.5
- Tests: pentest 29/29, WCAG 25/25, functioneel 16/16, enhanced 25/25
2026-08-27 09:05:51 +00:00

156 lines
6.2 KiB
PHP

<?php
/**
* HTMLBlock plugin: toont context-afhankelijke HTML-blokken in de zijbalk.
*
* Content-plugin die informatie over de huidige pagina toont,
* inclusief taal, homepage-status, bestandsinformatie en snelle navigatie.
*
* @since 2.6.5
*/
class HTMLBlock
{
/**
* Plugin-configuratie.
*
* @since 2.6.5
* @var array<string, mixed>
*/
private array $config;
/**
* Plugin-API instantie voor communicatie met de CMS-core.
*
* @since 2.6.5
* @var PluginAPIInterface|null
*/
private ?PluginAPIInterface $api = null;
/**
* Initialiseert de plugin met standaardconfiguratie.
*
* @since 2.6.5
*/
public function __construct()
{
$this->config = [
'title' => 'HTML Block Plugin',
'type' => 'content',
];
}
/**
* Stelt de Plugin-API instantie in.
*
* @since 2.6.5
* @param PluginAPIInterface $api De Plugin-API instantie.
* @return void
*/
public function setAPI(PluginAPIInterface $api): void
{
$this->api = $api;
}
/**
* Genereert de HTML-inhoud voor de zijbalk.
*
* Toont informatie over de huidige pagina, taal, homepage-status,
* bestandsinformatie en een snelle navigatielijst.
*
* @since 2.6.5
* @return string De opgebouwde HTML voor de zijbalk.
*/
public function getSidebarContent(): string
{
// Content plugin: translations follow the current content language.
$t = $this->api ? $this->api->getPluginTranslations('HTMLBlock') : [];
$tr = function (string $key) use ($t): string {
return $t[$key] ?? $key;
};
$currentPage = $this->api ? $this->api->getCurrentPageTitle() : $tr('unknown');
$isHomepage = $this->api ? $this->api->isHomepage() : false;
$currentLang = $this->api ? $this->api->getCurrentLanguage() : 'nl';
$currentPath = $_GET['page'] ?? '';
$currentPath = preg_replace('/\.(md|php|html)$/', '', $currentPath);
$content = '
<p class="mb-2"><strong>' . htmlspecialchars($tr('current_page')) . ':</strong> ' . htmlspecialchars($currentPage) . '</p>
<p class="mb-2"><strong>' . htmlspecialchars($tr('language')) . ':</strong> ' . strtoupper($currentLang) . '</p>
<p class="mb-3"><strong>' . htmlspecialchars($tr('homepage')) . ':</strong> ' . htmlspecialchars($isHomepage ? $tr('yes') : $tr('no')) . '</p>';
// Add page-specific content
if ($this->api) {
$fileInfo = $this->api->getCurrentPageFileInfo();
if ($fileInfo) {
$content .= '
<div class="alert alert-info mb-3">
<small>
<strong>' . htmlspecialchars($tr('file_info')) . ':</strong><br>
' . htmlspecialchars($tr('created')) . ': ' . htmlspecialchars($fileInfo['created']) . '<br>
' . htmlspecialchars($tr('modified')) . ': ' . htmlspecialchars($fileInfo['modified']) . '
</small>
</div>';
}
// Add dynamic quick navigation
$menu = $this->api->getMenu();
if (!empty($menu)) {
$content .= '
<h6>' . htmlspecialchars($tr('quick_navigation')) . '</h6>
<ul class="list-unstyled mb-3">';
foreach ($menu as $item) {
if ($item['type'] === 'file') {
$url = '/' . $currentLang . '/' . $item['path'];
$isActive = ($item['path'] === $currentPath) ? ' fw-bold' : '';
$content .= '<li><a href="' . htmlspecialchars($url, ENT_QUOTES, 'UTF-8') . '" class="text-decoration-none' . $isActive . '"><i class="bi bi-file-earmark"></i> ' . htmlspecialchars($item['title'], ENT_QUOTES, 'UTF-8') . '</a></li>';
} elseif ($item['type'] === 'folder' && !empty($item['children'])) {
$url = '/' . $currentLang . '/' . $item['path'];
$isActive = strpos($currentPath, $item['path']) === 0 ? ' fw-bold' : '';
$content .= '<li><a href="' . htmlspecialchars($url, ENT_QUOTES, 'UTF-8') . '" class="text-decoration-none' . $isActive . '"><i class="bi bi-folder"></i> ' . htmlspecialchars($item['title'], ENT_QUOTES, 'UTF-8') . '</a></li>';
// Show children if current page is in this folder
if (strpos($currentPath, $item['path']) === 0) {
$content .= '<ul class="list-unstyled ms-3 mb-1">';
foreach ($item['children'] as $child) {
if ($child['type'] === 'file') {
$childUrl = '/' . $currentLang . '/' . $child['path'];
$childActive = ($child['path'] === $currentPath) ? ' fw-bold' : '';
$content .= '<li><a href="' . htmlspecialchars($childUrl, ENT_QUOTES, 'UTF-8') . '" class="text-decoration-none' . $childActive . '"><i class="bi bi-file-earmark"></i> ' . htmlspecialchars($child['title'], ENT_QUOTES, 'UTF-8') . '</a></li>';
}
}
$content .= '</ul>';
}
}
}
$content .= '</ul>';
}
}
return $content;
}
/**
* Geeft de plugin-configuratie terug.
*
* @since 2.6.5
* @return array<string, mixed> Plugin-configuratie.
*/
public function getConfig(): array
{
return $this->config;
}
/**
* Stelt de plugin-configuratie in door deze te mergen met standaardwaarden.
*
* @since 2.6.5
* @param array<string, mixed> $config De configuratie die samengevoegd moet worden.
* @return void
*/
public function setConfig(array $config): void
{
$this->config = array_merge($this->config, $config);
}
}