This repository has been archived on 2025-02-26. You can view files and clone it, but cannot push or open issues or pull requests.
szurubooru/src/Views/top-navigation.phtml
2014-05-05 17:47:30 +02:00

157 lines
4.5 KiB
PHTML

<ul class="main-nav">
<?php
$nav = [];
$activeController = $this->context->simpleControllerName;
$activeAction = $this->context->simpleActionName;
$registerNavItem = function ($text, $link, $active = false) use (&$nav)
{
$nav []= [
'text' => $text,
'link' => $link,
'active' => $active];
};
$registerNavItem(
'Home',
\Chibi\Router::linkTo(['StaticPagesController', 'mainPageView']),
$activeController == 'static-pages' and $activeAction == 'main-page');
if (Access::check(new Privilege(Privilege::ListPosts)))
{
$registerNavItem(
'Browse',
\Chibi\Router::linkTo(['PostController', 'listView']),
$activeController == 'post' and $activeAction != 'upload');
}
if (Access::check(new Privilege(Privilege::UploadPost)))
{
$registerNavItem(
'Upload',
\Chibi\Router::linkTo(['PostController', 'uploadView']),
$activeController == 'post' and $activeAction == 'upload');
}
if (Access::check(new Privilege(Privilege::ListComments)))
{
$registerNavItem(
'Comments',
\Chibi\Router::linkTo(['CommentController', 'listView']),
$activeController == 'comment');
}
if (Access::check(new Privilege(Privilege::ListTags)))
{
$registerNavItem(
'Tags',
\Chibi\Router::linkTo(['TagController', 'listView']),
$activeController == 'tag');
}
if (Access::check(new Privilege(Privilege::ListUsers)))
{
$registerNavItem(
'Users',
\Chibi\Router::linkTo(['UserController', 'listView']),
$activeController == 'user' and $activeAction != 'registration' and
(!isset($this->context->route->arguments['name']) or
$this->context->route->arguments['name'] != Auth::getCurrentUser()->getName()));
}
if (!Auth::isLoggedIn())
{
$registerNavItem(
'Log in',
\Chibi\Router::linkTo(['AuthController', 'loginView']),
$activeController == 'auth' and $activeAction == 'login');
$registerNavItem(
'Register',
\Chibi\Router::linkTo(['UserController', 'registrationView']),
$activeController == 'user' and $activeAction == 'registration');
}
else
{
$registerNavItem(
'My account',
\Chibi\Router::linkTo(['UserController', 'genericView'], ['name' => Auth::getCurrentUser()->getName()]),
$activeController == 'user' and isset($this->context->route->arguments['name']) and
$this->context->route->arguments['name'] == Auth::getCurrentUser()->getName());
$registerNavItem(
'Log out',
\Chibi\Router::linkTo(['AuthController', 'logoutAction']));
}
if (!empty(getConfig()->help->title))
{
$registerNavItem(
getConfig()->help->title,
\Chibi\Router::linkTo(['StaticPagesController', 'helpView']),
$activeController == 'static-pages' and $activeAction == 'help');
}
foreach ($nav as $navItem)
{
extract($navItem);
echo TextHelper::htmlTag('li', TextHelper::HTML_OPEN, ['class' => rtrim('main-nav-item ' . ($active ? 'active' : ''))]);
echo TextHelper::htmlTag('a', TextHelper::HTML_OPEN, ['href' => $link]);
echo $text;
echo TextHelper::htmlTag('a', textHelper::HTML_CLOSE);
echo TextHelper::htmlTag('li', textHelper::HTML_CLOSE);
}
?>
<?php if (Access::check(new Privilege(
Privilege::ChangeUserSettings,
Access::getIdentity(Auth::getCurrentUser())))): ?>
<li class="safety">
<ul>
<?php foreach (PostSafety::getAll() as $safety): ?>
<?php if (Access::check(new Privilege(
Privilege::ListPosts,
$safety->toString()))): ?>
<li class="safety-<?= TextCaseConverter::convert(
$safety->toString(),
TextCaseConverter::CAMEL_CASE,
TextCaseConverter::SPINAL_CASE) ?>">
<a class="<?= Auth::getCurrentUser()->hasEnabledSafety($safety) ? 'enabled' : 'disabled' ?>"
href="<?= \Chibi\Router::linkTo(
['UserController', 'toggleSafetyAction'],
['safety' => $safety->toInteger()]) ?>"
title="<?= sprintf('Searching %s posts: %s',
$safety->toDisplayString(),
Auth::getCurrentUser()->hasEnabledSafety($safety)
? 'enabled'
: 'disabled') ?>">
<span><?= ucfirst($safety->toDisplayString()) ?></span>
</a>
</li>
<?php endif ?>
<?php endforeach ?>
</ul>
</li>
<?php endif ?>
<li class="search">
<form name="search" action="<?= \Chibi\Router::linkTo(['PostController', 'listView']) ?>" method="get">
<input
class="autocomplete"
type="search"
name="query"
placeholder="Search&hellip;"
value="<?= isset($this->context->transport->searchQuery)
? htmlspecialchars($this->context->transport->searchQuery)
: '' ?>"/>
</form>
</li>
</ul>