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
Marcin Kurczewski 50e4b40721 Upgraded to newest chibi
- Separate non-static router class
- Moved some setup code to new method, Core::init
- Persistent database connection between tests
2014-05-23 23:34:50 +02:00

173 lines
5 KiB
PHTML

<ul class="main-nav">
<?php
$nav = [];
list ($className, $methodName)
= isset($this->context->route)
? $this->context->route->destination
: [null, null];
$activeController = TextCaseConverter::convert(
str_replace('Controller', '', $className),
TextCaseConverter::CAMEL_CASE,
TextCaseConverter::SPINAL_CASE);
$activeAction = TextCaseConverter::convert(
preg_replace('/Action|View/', '', $methodName),
TextCaseConverter::CAMEL_CASE,
TextCaseConverter::SPINAL_CASE);
$registerNavItem = function ($text, $link, $active = false) use (&$nav)
{
$nav []= [
'text' => $text,
'link' => $link,
'active' => $active];
};
$registerNavItem(
'Home',
Core::getRouter()->linkTo(['StaticPagesController', 'mainPageView']),
$activeController == 'static-pages' and $activeAction == 'main-page');
if (Access::check(new Privilege(Privilege::ListPosts)))
{
$registerNavItem(
'Browse',
Core::getRouter()->linkTo(['PostController', 'listView']),
$activeController == 'post' and $activeAction != 'upload');
}
if (Access::check(new Privilege(Privilege::AddPost)))
{
$registerNavItem(
'Upload',
Core::getRouter()->linkTo(['PostController', 'uploadView']),
$activeController == 'post' and $activeAction == 'upload');
}
if (Access::check(new Privilege(Privilege::ListComments)))
{
$registerNavItem(
'Comments',
Core::getRouter()->linkTo(['CommentController', 'listView']),
$activeController == 'comment');
}
if (Access::check(new Privilege(Privilege::ListTags)))
{
$registerNavItem(
'Tags',
Core::getRouter()->linkTo(['TagController', 'listView']),
$activeController == 'tag');
}
if (Access::check(new Privilege(Privilege::ListUsers)))
{
$registerNavItem(
'Users',
Core::getRouter()->linkTo(['UserController', 'listView']),
$activeController == 'user' and $activeAction != 'registration' and
(!isset($this->context->route->arguments['identifier']) or
$this->context->route->arguments['identifier'] != Auth::getCurrentUser()->getName()));
}
if (!Auth::isLoggedIn())
{
$registerNavItem(
'Log in',
Core::getRouter()->linkTo(['AuthController', 'loginView']),
$activeController == 'auth' and $activeAction == 'login');
$registerNavItem(
'Register',
Core::getRouter()->linkTo(['UserController', 'registrationView']),
$activeController == 'user' and $activeAction == 'registration');
}
else
{
$registerNavItem(
'My account',
Core::getRouter()->linkTo(['UserController', 'genericView'], ['identifier' => Auth::getCurrentUser()->getName()]),
$activeController == 'user' and isset($this->context->route->arguments['identifier']) and
$this->context->route->arguments['identifier'] == Auth::getCurrentUser()->getName());
$registerNavItem(
'Log out',
Core::getRouter()->linkTo(['AuthController', 'logoutAction']));
}
if (!empty(Core::getConfig()->help->title))
{
$registerNavItem(
Core::getConfig()->help->title,
Core::getRouter()->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::EditUserSettings,
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="simple-action <?= Auth::getCurrentUser()->getSettings()->hasEnabledSafety($safety)
? 'enabled'
: 'disabled' ?>"
href="<?= Core::getRouter()->linkTo(
['UserController', 'toggleSafetyAction'],
['safety' => $safety->toInteger()]) ?>"
title="<?= sprintf('Searching %s posts: %s',
$safety->toDisplayString(),
Auth::getCurrentUser()->getSettings()->hasEnabledSafety($safety)
? 'enabled'
: 'disabled') ?>">
<span><?= ucfirst($safety->toDisplayString()) ?></span>
</a>
</li>
<?php endif ?>
<?php endforeach ?>
</ul>
</li>
<?php endif ?>
<li class="search">
<form method="post"
action="<?= Core::getRouter()->linkTo(['PostController', 'listRedirectAction']) ?>"
name="search">
<input
class="autocomplete"
type="search"
name="query"
placeholder="Search&hellip;"
value="<?= isset($this->context->transport->searchQuery)
? htmlspecialchars($this->context->transport->searchQuery)
: '' ?>"/>
</form>
</li>
</ul>