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,54 +1,59 @@
<?php
if (!defined('DOKU_INC')) die();
if ($conf['useacl']): ?>
use dokuwiki\Menu\Item\AbstractItem;
use dokuwiki\Menu\Item\Admin;
use dokuwiki\Menu\Item\Login;
use dokuwiki\Menu\Item\Register;
<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
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 not available
}
?>
</li>
if (!defined('DOKU_INC')) die();
<?php
if (!empty($_SERVER['REMOTE_USER'])) {
echo '<li class="user"><span class="sr-only">'.$lang['loggedinas'].' </span>'.userlink().'</li>';
}?>
if ($conf['useacl']): ?>
<?php /* dokuwiki user tools */
try{
echo '<li class="admin">' . (new \dokuwiki\Menu\Item\Admin())->asHtmlLink() . '</li>';
} catch(\RuntimeException $ignored) {
// item not available
<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>
<?php
try {
$item = new Login();
if ($item->visibleInContext(AbstractItem::CTX_DESKTOP))
echo '<li class="log">' . $item->asHtmlButton() . '</li>';
} catch (RuntimeException $ignored) {
// item not available
}
if (!empty($_SERVER['REMOTE_USER'])) {
echo '<li class="user"><span class="sr-only">' . $lang['loggedinas'] . ' </span>' . userlink() . '</li>';
}
try {
$item = new Admin();
if ($item->visibleInContext(AbstractItem::CTX_DESKTOP)) {
echo '<li class="admin">' . $item->asHtmlLink() . '</li>';
}
try{
echo '<li class="register">' . (new \dokuwiki\Menu\Item\Register())->asHtmlLink() . '</li>';
} catch(\RuntimeException $ignored) {
// item not available
} catch (RuntimeException $ignored) {
// item not available
}
try {
$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 */
$doplugin = plugin_load('helper','do');
if ($doplugin !== null && isset($_SERVER['REMOTE_USER'])) {
$icon = $doplugin->tpl_getUserTasksIconHTML();
if ($icon) {
echo '<li class="user-task">' . $icon . '</li>';
}
/** @var helper_plugin_do $doplugin */
$doplugin = plugin_load('helper', 'do');
if ($doplugin !== null && isset($_SERVER['REMOTE_USER'])) {
$icon = $doplugin->tpl_getUserTasksIconHTML();
if ($icon) {
echo '<li class="user-task">' . $icon . '</li>';
}
?>
}
?>
</ul>
</nav><!-- #dokuwiki__usertools -->
<?php endif ?>
</ul>
</nav><!-- #dokuwiki__usertools -->
<?php endif ?>