config = [
'title' => 'HTML Block Plugin',
'type' => 'content',
];
}
public function setAPI(PluginAPIInterface $api): void
{
$this->api = $api;
}
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 = '
' . htmlspecialchars($tr('current_page')) . ': ' . htmlspecialchars($currentPage) . '
' . htmlspecialchars($tr('language')) . ': ' . strtoupper($currentLang) . '
' . htmlspecialchars($tr('homepage')) . ': ' . htmlspecialchars($isHomepage ? $tr('yes') : $tr('no')) . '
';
// Add page-specific content
if ($this->api) {
$fileInfo = $this->api->getCurrentPageFileInfo();
if ($fileInfo) {
$content .= '
' . htmlspecialchars($tr('file_info')) . ':
' . htmlspecialchars($tr('created')) . ': ' . htmlspecialchars($fileInfo['created']) . '
' . htmlspecialchars($tr('modified')) . ': ' . htmlspecialchars($fileInfo['modified']) . '
';
}
// Add dynamic quick navigation
$menu = $this->api->getMenu();
if (!empty($menu)) {
$content .= '
' . htmlspecialchars($tr('quick_navigation')) . '
';
foreach ($menu as $item) {
if ($item['type'] === 'file') {
$url = '/' . $currentLang . '/' . $item['path'];
$isActive = ($item['path'] === $currentPath) ? ' fw-bold' : '';
$content .= '- ' . htmlspecialchars($item['title'], ENT_QUOTES, 'UTF-8') . '
';
} elseif ($item['type'] === 'folder' && !empty($item['children'])) {
$url = '/' . $currentLang . '/' . $item['path'];
$isActive = strpos($currentPath, $item['path']) === 0 ? ' fw-bold' : '';
$content .= '- ' . htmlspecialchars($item['title'], ENT_QUOTES, 'UTF-8') . '
';
// Show children if current page is in this folder
if (strpos($currentPath, $item['path']) === 0) {
$content .= '';
}
}
}
$content .= '
';
}
}
return $content;
}
public function getConfig(): array
{
return $this->config;
}
public function setConfig(array $config): void
{
$this->config = array_merge($this->config, $config);
}
}