89 lines
2.5 KiB
PHP
89 lines
2.5 KiB
PHP
<?php
|
|
/*
|
|
Crispage CMS
|
|
crispycat <the@crispy.cat>
|
|
https://crispy.cat/software/crispage
|
|
|
|
Crispage is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
(at your option) any later version.
|
|
*/
|
|
|
|
namespace Crispage\Components;
|
|
|
|
defined("ROOT") or die();
|
|
|
|
use \Crispage\Backend\Field;
|
|
|
|
class UserMenuComponent extends \Crispage\Framework\ModuleComponent {
|
|
public static function getExtensionInfo(): array {
|
|
return [
|
|
"id" => "crispage.components.usermenu",
|
|
"version" => VERSION,
|
|
"name" => "User Menu Module",
|
|
"author" => "crispycat",
|
|
"description" => "Displays a menu with login/logout, register and user settings links",
|
|
"cache_policy" => \Crispage\Caching\CacheEngine::POL_USER,
|
|
"cache_ttl" => 3600,
|
|
"cache_comdata" => true
|
|
];
|
|
}
|
|
|
|
public static function getModuleFields(): array {
|
|
return [
|
|
new Field(
|
|
"show_title", 0,
|
|
"\\Crispage\\Components\\Fields\\BooleanFieldComponent", [
|
|
"label" => "{%SHOW_TITLE}:"
|
|
]
|
|
),
|
|
new Field(
|
|
"show_login", 0,
|
|
"\\Crispage\\Components\\Fields\\BooleanFieldComponent", [
|
|
"label" => "{%SHOW_LOGIN__LINK}:"
|
|
]
|
|
),
|
|
new Field(
|
|
"show_register", 0,
|
|
"\\Crispage\\Components\\Fields\\BooleanFieldComponent", [
|
|
"label" => "{%SHOW_REGISTER_LINK}:"
|
|
]
|
|
),
|
|
new Field(
|
|
"show_settings", 0,
|
|
"\\Crispage\\Components\\Fields\\BooleanFieldComponent", [
|
|
"label" => "{%SHOW_USER_SETTINGS_LINK}:"
|
|
]
|
|
)
|
|
];
|
|
}
|
|
|
|
public function render(): void {
|
|
echo "<div class=\"menu\">";
|
|
if ($this->getModuleConfig("show_title", true)) {
|
|
echo "<span class=\"menu-label\">";
|
|
($this->app->i18n)("{%USER_MENU}");
|
|
echo "</span>";
|
|
}
|
|
echo "<ul class=\"menu-list\">";
|
|
|
|
if ($this->app->auth->sessionActive()) {
|
|
if ($this->getModuleConfig("show_login", true))
|
|
($this->app->i18n)("<li><a href=\"" . WROOT . "/logout\">{%LOG_OUT}</a></li>");
|
|
|
|
if ($this->getModuleConfig("show_settings", true))
|
|
($this->app->i18n)("<li><a href=\"" . WROOT . "/user_settings\">{%USER_SETTINGS}</a></li>");
|
|
} else {
|
|
if ($this->getModuleConfig("show_login", true))
|
|
($this->app->i18n)("<li><a href=\"" . WROOT . "/login\">{%LOG_IN}</a></li>");
|
|
|
|
if ($this->getModuleConfig("show_register", true))
|
|
($this->app->i18n)("<li><a href=\"" . WROOT . "/register\">{%REGISTER}</a></li>");
|
|
}
|
|
|
|
echo "</ul></div>";
|
|
}
|
|
}
|
|
?>
|