Security: verwijder hardcoded wachtwoord, voeg random-wachtwoord-generator toe bij eerste installatie
This commit is contained in:
@@ -1,10 +1,36 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Navigation plugin: bouwt zijbalk-navigatie voor content en guide.
|
||||
*
|
||||
* Content-plugin die de navigatie opbouwt op basis van de mappenstructuur,
|
||||
* met ondersteuning voor guide-pagina's en reguliere content-pagina's.
|
||||
*
|
||||
* @since 2.6.4
|
||||
*/
|
||||
class Navigation
|
||||
{
|
||||
/**
|
||||
* Plugin-configuratie.
|
||||
*
|
||||
* @since 2.6.4
|
||||
* @var array<string, mixed>
|
||||
*/
|
||||
private array $config;
|
||||
|
||||
/**
|
||||
* Plugin-API instantie voor communicatie met de CMS-core.
|
||||
*
|
||||
* @since 2.6.4
|
||||
* @var PluginAPIInterface|null
|
||||
*/
|
||||
private ?PluginAPIInterface $api = null;
|
||||
|
||||
/**
|
||||
* Initialiseert de plugin met standaardconfiguratie.
|
||||
*
|
||||
* @since 2.6.4
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->config = [
|
||||
@@ -14,23 +40,46 @@ class Navigation
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Stelt de Plugin-API instantie in.
|
||||
*
|
||||
* @since 2.6.4
|
||||
* @param PluginAPIInterface $api De Plugin-API instantie.
|
||||
* @return void
|
||||
*/
|
||||
public function setAPI(PluginAPIInterface $api): void
|
||||
{
|
||||
$this->api = $api;
|
||||
}
|
||||
|
||||
/**
|
||||
* Geeft de plugin-configuratie terug.
|
||||
*
|
||||
* @since 2.6.4
|
||||
* @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.4
|
||||
* @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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the path to this plugin's CSS file (relative to web root).
|
||||
* Geeft het pad naar het CSS-bestand van deze plugin (relatief ten opzichte van de webroot).
|
||||
*
|
||||
* @since 2.6.4
|
||||
* @return string Het CSS-URL-pad.
|
||||
*/
|
||||
public function getCssUrl(): string
|
||||
{
|
||||
@@ -38,8 +87,13 @@ class Navigation
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate sidebar navigation.
|
||||
* Detects whether we're on a guide page or content page and builds nav accordingly.
|
||||
* Genereert de zijbalk-navigatie.
|
||||
*
|
||||
* Detecteert of het om een guide-pagina of een content-pagina gaat en
|
||||
* bouwt de navigatie dienovereenkomstig op.
|
||||
*
|
||||
* @since 2.6.4
|
||||
* @return string De HTML-navigatie, of een lege string in admin-context.
|
||||
*/
|
||||
public function getSidebarContent(): string
|
||||
{
|
||||
@@ -61,11 +115,17 @@ class Navigation
|
||||
}
|
||||
|
||||
/**
|
||||
* Build navigation for the guide section.
|
||||
* Bouwt de navigatie voor de guide-sectie.
|
||||
*
|
||||
* @since 2.6.4
|
||||
* @param string $lang De huidige taalcode.
|
||||
* @param string $currentPage De huidige pagina-pad.
|
||||
* @param bool $isAdmin Of dit in admin-context is.
|
||||
* @return string De opgebouwde HTML-navigatie, of een lege string.
|
||||
*/
|
||||
private function buildGuideNav(string $lang, string $currentPage, bool $isAdmin): string
|
||||
{
|
||||
$guideRoot = dirname(__DIR__, 2) . '/guide/' . $lang;
|
||||
$guideRoot = ($this->api ? $this->api->getProjectRoot() : dirname(__DIR__, 2)) . '/guide/' . $lang;
|
||||
if (!is_dir($guideRoot)) {
|
||||
return '';
|
||||
}
|
||||
@@ -79,11 +139,16 @@ class Navigation
|
||||
}
|
||||
|
||||
/**
|
||||
* Build navigation for the content section.
|
||||
* Bouwt de navigatie voor de content-sectie.
|
||||
*
|
||||
* @since 2.6.4
|
||||
* @param string $lang De huidige taalcode.
|
||||
* @param string $currentPage De huidige pagina-pad.
|
||||
* @return string De opgebouwde HTML-navigatie, of een lege string.
|
||||
*/
|
||||
private function buildContentNav(string $lang, string $currentPage): string
|
||||
{
|
||||
$contentRoot = dirname(__DIR__, 2) . '/content';
|
||||
$contentRoot = $this->api ? $this->api->getContentDir() : dirname(__DIR__, 2) . '/content';
|
||||
if (!is_dir($contentRoot)) {
|
||||
return '';
|
||||
}
|
||||
@@ -95,15 +160,17 @@ class Navigation
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursively build navigation from a directory structure.
|
||||
* Bouwt recursief navigatie op vanuit een mapstructuur.
|
||||
*
|
||||
* @param string $dir Current directory
|
||||
* @param string $relPath Relative path from root
|
||||
* @param string $currentPage Current page path
|
||||
* @param bool $isAdmin Whether this is admin context
|
||||
* @param string $mode 'guide' or 'content'
|
||||
* @param string $lang Current language
|
||||
* @param int $depth Nesting depth (0 = top level)
|
||||
* @since 2.6.4
|
||||
* @param string $dir Huidige map.
|
||||
* @param string $relPath Relatief pad vanaf de root.
|
||||
* @param string $currentPage Huidige pagina-pad.
|
||||
* @param bool $isAdmin Of dit in admin-context is.
|
||||
* @param string $mode Modus: 'guide' of 'content'.
|
||||
* @param string $lang Huidige taalcode.
|
||||
* @param int $depth Nesting-diepte (0 = topniveau). Standaard 0.
|
||||
* @return string De opgebouwde HTML-navigatie.
|
||||
*/
|
||||
private function buildNav(string $dir, string $relPath, string $currentPage, bool $isAdmin, string $mode, string $lang, int $depth = 0): string
|
||||
{
|
||||
@@ -188,7 +255,14 @@ class Navigation
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the URL for a page.
|
||||
* Bouwt de URL voor een pagina-referentie.
|
||||
*
|
||||
* @since 2.6.4
|
||||
* @param string $pageRef De pagina-referentie.
|
||||
* @param string $lang De huidige taalcode.
|
||||
* @param bool $isAdmin Of dit in admin-context is.
|
||||
* @param string $mode Modus: 'guide' of 'content'.
|
||||
* @return string De opgebouwde URL.
|
||||
*/
|
||||
private function buildUrl(string $pageRef, string $lang, bool $isAdmin, string $mode): string
|
||||
{
|
||||
@@ -203,7 +277,13 @@ class Navigation
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a nav item is the current page.
|
||||
* Controleert of een navigatie-item de huidige pagina is.
|
||||
*
|
||||
* @since 2.6.4
|
||||
* @param string $pageRef De pagina-referentie van het item.
|
||||
* @param string $currentPage Het huidige pagina-pad.
|
||||
* @param string $mode Modus: 'guide' of 'content'.
|
||||
* @return bool True als het item actief is, anders false.
|
||||
*/
|
||||
private function isActive(string $pageRef, string $currentPage, string $mode): bool
|
||||
{
|
||||
@@ -215,7 +295,10 @@ class Navigation
|
||||
}
|
||||
|
||||
/**
|
||||
* Get available language codes.
|
||||
* Geeft de beschikbare taalcodes terug.
|
||||
*
|
||||
* @since 2.6.4
|
||||
* @return array<int, string> Lijst met taalcodes.
|
||||
*/
|
||||
private function getLanguageCodes(): array
|
||||
{
|
||||
@@ -223,7 +306,11 @@ class Navigation
|
||||
}
|
||||
|
||||
/**
|
||||
* Format a slug into a readable title.
|
||||
* Formateert een slug naar een leesbare titel.
|
||||
*
|
||||
* @since 2.6.4
|
||||
* @param string $slug De te formatteren slug.
|
||||
* @return string De geformatteerde titel.
|
||||
*/
|
||||
private function formatTitle(string $slug): string
|
||||
{
|
||||
@@ -233,8 +320,13 @@ class Navigation
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract the H1 title from a markdown/PHP/HTML file.
|
||||
* Falls back to formatTitle() if no H1 is found.
|
||||
* Haalt de H1-titel uit een markdown-, PHP- of HTML-bestand.
|
||||
*
|
||||
* Valt terug op formatTitle() wanneer geen H1 gevonden is.
|
||||
*
|
||||
* @since 2.6.4
|
||||
* @param string $filePath Pad naar het bestand.
|
||||
* @return string De gevonden titel, of een lege string.
|
||||
*/
|
||||
private function getTitleFromFile(string $filePath): string
|
||||
{
|
||||
@@ -253,10 +345,12 @@ class Navigation
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the navigation items as HTML.
|
||||
* Rendert de navigatie-items als HTML.
|
||||
*
|
||||
* @param array $items Navigation items
|
||||
* @param int $depth Nesting depth (0 = top level)
|
||||
* @since 2.6.4
|
||||
* @param array $items Navigatie-items.
|
||||
* @param int $depth Nesting-diepte (0 = topniveau). Standaard 0.
|
||||
* @return string De gegenereerde HTML.
|
||||
*/
|
||||
private function renderNav(array $items, int $depth = 0): string
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user