some cleanup in the usertool handling

do not display unavailable actions
This commit is contained in:
Andreas Gohr 2023-07-10 13:40:06 +02:00
commit 621124b325

View file

@ -1,4 +1,10 @@
<?php
use dokuwiki\Menu\Item\AbstractItem;
use dokuwiki\Menu\Item\Admin;
use dokuwiki\Menu\Item\Login;
use dokuwiki\Menu\Item\Register;
if (!defined('DOKU_INC')) die();
if ($conf['useacl']): ?>
@ -6,39 +12,38 @@
<nav id="dokuwiki__usertools" class="nav-usertools <?php echo $navClass ?>">
<h6 class="sr-only" role="heading" aria-level="2"><?php echo $lang['user_tools']; ?></h6>
<ul>
<li class="log"><?php
<?php
try {
if (empty($_SERVER['REMOTE_USER'])) {
echo (new \dokuwiki\Menu\Item\Login())->asHtmlLink();
} else {
echo (new \dokuwiki\Menu\Item\Login())->asHtmlButton();
}
} catch (\RuntimeException $ignored) {
$item = new Login();
if ($item->visibleInContext(AbstractItem::CTX_DESKTOP))
echo '<li class="log">' . $item->asHtmlButton() . '</li>';
} catch (RuntimeException $ignored) {
// item not available
}
?>
</li>
<?php
if (!empty($_SERVER['REMOTE_USER'])) {
echo '<li class="user"><span class="sr-only">' . $lang['loggedinas'] . ' </span>' . userlink() . '</li>';
}?>
}
<?php /* dokuwiki user tools */
try {
echo '<li class="admin">' . (new \dokuwiki\Menu\Item\Admin())->asHtmlLink() . '</li>';
} catch(\RuntimeException $ignored) {
$item = new Admin();
if ($item->visibleInContext(AbstractItem::CTX_DESKTOP)) {
echo '<li class="admin">' . $item->asHtmlLink() . '</li>';
}
} catch (RuntimeException $ignored) {
// item not available
}
try {
echo '<li class="register">' . (new \dokuwiki\Menu\Item\Register())->asHtmlLink() . '</li>';
} catch(\RuntimeException $ignored) {
$item = new Register();
if ($item->visibleInContext(AbstractItem::CTX_DESKTOP)) {
echo '<li class="register">' . $item->asHtmlLink() . '</li>';
}
} catch (RuntimeException $ignored) {
// item not available
}
?>
<?php /* tasks do Plug-In */
/** @var \helper_plugin_do $doplugin */
/** @var helper_plugin_do $doplugin */
$doplugin = plugin_load('helper', 'do');
if ($doplugin !== null && isset($_SERVER['REMOTE_USER'])) {
$icon = $doplugin->tpl_getUserTasksIconHTML();