Optimalization: sidebar options structure
- options rendering moved to separate file - simplified template code - removed redundant JS
This commit is contained in:
parent
5e58488f3e
commit
d570bc1790
4 changed files with 255 additions and 163 deletions
|
@ -233,4 +233,20 @@ class TextHelper
|
||||||
$path = self::cleanPath($path);
|
$path = self::cleanPath($path);
|
||||||
return $path;
|
return $path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function openHtmlTag($tagName, array $attributes)
|
||||||
|
{
|
||||||
|
$html = '<' . $tagName;
|
||||||
|
|
||||||
|
foreach ($attributes as $key => $value)
|
||||||
|
$html .= ' ' . $key . '="' . $value . '"';
|
||||||
|
|
||||||
|
$html .= '>';
|
||||||
|
echo $html;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function closeHtmlTag($tagName)
|
||||||
|
{
|
||||||
|
echo '</' . $tagName . '>';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -183,26 +183,6 @@
|
||||||
</div>
|
</div>
|
||||||
<?php endif ?>
|
<?php endif ?>
|
||||||
|
|
||||||
<div class="unit options">
|
|
||||||
<h1>options</h1>
|
|
||||||
|
|
||||||
<ul>
|
|
||||||
<?php if (PrivilegesHelper::confirm(Privilege::FavoritePost)): ?>
|
|
||||||
<?php if (!$this->context->favorite): ?>
|
|
||||||
<li class="add-fav">
|
|
||||||
<a class="simple-action" href="<?php echo \Chibi\UrlHelper::route('post', 'add-favorite', ['id' => $this->context->transport->post->id]) ?>">
|
|
||||||
Add to favorites
|
|
||||||
</a>
|
|
||||||
</li>
|
|
||||||
<?php else: ?>
|
|
||||||
<li class="rem-fav">
|
|
||||||
<a class="simple-action" href="<?php echo \Chibi\UrlHelper::route('post', 'rem-favorite', ['id' => $this->context->transport->post->id]) ?>">
|
|
||||||
Remove from favorites
|
|
||||||
</a>
|
|
||||||
</li>
|
|
||||||
<?php endif ?>
|
|
||||||
<?php endif ?>
|
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
$editPostPrivileges = [
|
$editPostPrivileges = [
|
||||||
Privilege::EditPostSafety,
|
Privilege::EditPostSafety,
|
||||||
|
@ -217,68 +197,112 @@
|
||||||
$editPostPrivileges[$privilege] = true;
|
$editPostPrivileges[$privilege] = true;
|
||||||
}
|
}
|
||||||
$canEditAnything = count(array_filter($editPostPrivileges)) > 0;
|
$canEditAnything = count(array_filter($editPostPrivileges)) > 0;
|
||||||
|
|
||||||
|
$options = [];
|
||||||
|
|
||||||
|
if (PrivilegesHelper::confirm(Privilege::FavoritePost))
|
||||||
|
{
|
||||||
|
if (!$this->context->favorite)
|
||||||
|
{
|
||||||
|
$options []=
|
||||||
|
[
|
||||||
|
'class' => 'add-fav',
|
||||||
|
'text' => 'Add to favorites',
|
||||||
|
'simple-action' => \Chibi\UrlHelper::route('post', 'add-favorite', ['id' => $this->context->transport->post->id]),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$options []=
|
||||||
|
[
|
||||||
|
'class' => 'rem-fav',
|
||||||
|
'text' => 'Remove from favorites',
|
||||||
|
'simple-action' => \Chibi\UrlHelper::route('post', 'rem-favorite', ['id' => $this->context->transport->post->id]),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($canEditAnything)
|
||||||
|
{
|
||||||
|
$options []=
|
||||||
|
[
|
||||||
|
'class' => 'edit',
|
||||||
|
'text' => 'Edit',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (PrivilegesHelper::confirm(Privilege::HidePost, PrivilegesHelper::getIdentitySubPrivilege($this->context->transport->post->uploader)))
|
||||||
|
{
|
||||||
|
if ($this->context->transport->post->hidden)
|
||||||
|
{
|
||||||
|
$options []=
|
||||||
|
[
|
||||||
|
'class' => 'unhide',
|
||||||
|
'text' => 'Unhide',
|
||||||
|
'simple-action' => \Chibi\UrlHelper::route('post', 'unhide', ['id' => $this->context->transport->post->id]),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$options []=
|
||||||
|
[
|
||||||
|
'class' => 'hide',
|
||||||
|
'text' => 'Hide',
|
||||||
|
'simple-action' => \Chibi\UrlHelper::route('post', 'hide', ['id' => $this->context->transport->post->id]),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (PrivilegesHelper::confirm(Privilege::FeaturePost))
|
||||||
|
{
|
||||||
|
$options []=
|
||||||
|
[
|
||||||
|
'class' => 'feature',
|
||||||
|
'text' => 'Feature on main page',
|
||||||
|
'simple-action' => \Chibi\UrlHelper::route('post', 'feature', ['id' => $this->context->transport->post->id]),
|
||||||
|
'data-confirm-text' => 'Are you sure you want to feature this post on the main page?',
|
||||||
|
'data-redirect-url' => \Chibi\UrlHelper::route('index', 'index'),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (PrivilegesHelper::confirm(Privilege::FlagPost))
|
||||||
|
{
|
||||||
|
if ($this->context->flagged)
|
||||||
|
{
|
||||||
|
$options []=
|
||||||
|
[
|
||||||
|
'class' => 'flag',
|
||||||
|
'text' => 'Flagged',
|
||||||
|
'inactive' => true,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$options []=
|
||||||
|
[
|
||||||
|
'class' => 'flag',
|
||||||
|
'text' => 'Flag for moderator attention',
|
||||||
|
'simple-action' => \Chibi\UrlHelper::route('post', 'flag', ['id' => $this->context->transport->post->id]),
|
||||||
|
'data-confirm-text' => 'Are you sure you want to flag this post?',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (PrivilegesHelper::confirm(Privilege::DeletePost, PrivilegesHelper::getIdentitySubPrivilege($this->context->transport->post->uploader)))
|
||||||
|
{
|
||||||
|
$options []=
|
||||||
|
[
|
||||||
|
'class' => 'delete',
|
||||||
|
'text' => 'Delete',
|
||||||
|
'simple-action' => \Chibi\UrlHelper::route('post', 'delete', ['id' => $this->context->transport->post->id]),
|
||||||
|
'data-confirm-text' => 'Are you sure you want to delete this post?',
|
||||||
|
'data-redirect-url' => \Chibi\UrlHelper::route('post', 'list'),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->context->options = $options;
|
||||||
|
$this->renderFile('sidebar-options');
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<?php if ($canEditAnything): ?>
|
|
||||||
<li class="edit">
|
|
||||||
<a href="#">
|
|
||||||
Edit
|
|
||||||
</a>
|
|
||||||
</li>
|
|
||||||
<?php endif ?>
|
|
||||||
|
|
||||||
<?php if (PrivilegesHelper::confirm(Privilege::HidePost, PrivilegesHelper::getIdentitySubPrivilege($this->context->transport->post->uploader))): ?>
|
|
||||||
<?php if ($this->context->transport->post->hidden): ?>
|
|
||||||
<li class="unhide">
|
|
||||||
<a class="simple-action" href="<?php echo \Chibi\UrlHelper::route('post', 'unhide', ['id' => $this->context->transport->post->id]) ?>">
|
|
||||||
Unhide
|
|
||||||
</a>
|
|
||||||
</li>
|
|
||||||
<?php else: ?>
|
|
||||||
<li class="hide">
|
|
||||||
<a class="simple-action" href="<?php echo \Chibi\UrlHelper::route('post', 'hide', ['id' => $this->context->transport->post->id]) ?>">
|
|
||||||
Hide
|
|
||||||
</a>
|
|
||||||
</li>
|
|
||||||
<?php endif ?>
|
|
||||||
<?php endif ?>
|
|
||||||
|
|
||||||
<?php if (PrivilegesHelper::confirm(Privilege::FeaturePost)): ?>
|
|
||||||
<li class="feature">
|
|
||||||
<a class="simple-action" href="<?php echo \Chibi\UrlHelper::route('post', 'feature', ['id' => $this->context->transport->post->id]) ?>" data-confirm-text="Are you sure you want to feature this post on the main page?" data-redirect-url="<?php echo \Chibi\UrlHelper::route('index', 'index') ?>">
|
|
||||||
Feature on main page
|
|
||||||
</a>
|
|
||||||
</li>
|
|
||||||
<?php endif ?>
|
|
||||||
|
|
||||||
<?php if (PrivilegesHelper::confirm(Privilege::FlagPost)): ?>
|
|
||||||
<li class="flag">
|
|
||||||
<?php if ($this->context->flagged): ?>
|
|
||||||
<a class="simple-action inactive" href="#">
|
|
||||||
Flagged
|
|
||||||
</a>
|
|
||||||
<?php else: ?>
|
|
||||||
<a class="simple-action" href="<?php echo \Chibi\UrlHelper::route('post', 'flag', ['id' => $this->context->transport->post->id]) ?>" data-confirm-text="Are you sure you want to flag this post?">
|
|
||||||
Flag for moderator attention
|
|
||||||
</a>
|
|
||||||
<?php endif ?>
|
|
||||||
</li>
|
|
||||||
<?php endif ?>
|
|
||||||
|
|
||||||
<?php if (PrivilegesHelper::confirm(Privilege::DeletePost, PrivilegesHelper::getIdentitySubPrivilege($this->context->transport->post->uploader))): ?>
|
|
||||||
<li class="delete">
|
|
||||||
<a class="simple-action" href="<?php echo \Chibi\UrlHelper::route('post', 'delete', ['id' => $this->context->transport->post->id]) ?>" data-confirm-text="Are you sure you want to delete this post?" data-redirect-url="<?php echo \Chibi\UrlHelper::route('post', 'list') ?>">
|
|
||||||
Delete
|
|
||||||
</a>
|
|
||||||
</li>
|
|
||||||
<?php endif ?>
|
|
||||||
</ul>
|
|
||||||
|
|
||||||
<script type="text/javascript">
|
|
||||||
if (!$('.options ul li').length)
|
|
||||||
$('.options').hide();
|
|
||||||
</script>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="inner-content">
|
<div id="inner-content">
|
||||||
|
|
35
src/Views/sidebar-options.phtml
Normal file
35
src/Views/sidebar-options.phtml
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
<?php if (!empty($this->context->options)): ?>
|
||||||
|
<div class="unit options">
|
||||||
|
<h1>options</h1>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<?php foreach ($this->context->options as $option): ?>
|
||||||
|
<li class="<?php echo $option['class']; if (isset($option['inactive'])) echo ' inactive' ?>">
|
||||||
|
<?php
|
||||||
|
$attrs = [];
|
||||||
|
if (!empty($option['link']))
|
||||||
|
{
|
||||||
|
$attrs['href'] = $option['link'];
|
||||||
|
}
|
||||||
|
elseif (!empty($option['simple-action']))
|
||||||
|
{
|
||||||
|
$attrs['href'] = $option['simple-action'];
|
||||||
|
$attrs['class'] = 'simple-action';
|
||||||
|
}
|
||||||
|
else
|
||||||
|
$attrs['href'] = '#';
|
||||||
|
|
||||||
|
foreach ($option as $key => $val)
|
||||||
|
if (strpos($key, 'data-') === 0)
|
||||||
|
$attrs[$key] = $val;
|
||||||
|
|
||||||
|
TextHelper::openHtmlTag('a', $attrs);
|
||||||
|
echo $option['text'];
|
||||||
|
TextHelper::closeHtmlTag('a');
|
||||||
|
?>
|
||||||
|
</li>
|
||||||
|
<?php endforeach ?>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
<?php endif ?>
|
||||||
|
|
|
@ -28,10 +28,6 @@
|
||||||
<?php endif ?>
|
<?php endif ?>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="unit options">
|
|
||||||
<h1>options</h1>
|
|
||||||
|
|
||||||
<ul>
|
|
||||||
<?php
|
<?php
|
||||||
$userModificationPrivileges = [
|
$userModificationPrivileges = [
|
||||||
Privilege::ChangeUserName,
|
Privilege::ChangeUserName,
|
||||||
|
@ -47,68 +43,89 @@
|
||||||
$userModificationPrivileges[$privilege] = true;
|
$userModificationPrivileges[$privilege] = true;
|
||||||
}
|
}
|
||||||
$canModifyAnything = count(array_filter($userModificationPrivileges)) > 0;
|
$canModifyAnything = count(array_filter($userModificationPrivileges)) > 0;
|
||||||
|
|
||||||
|
$options = [];
|
||||||
|
|
||||||
|
if ($canModifyAnything)
|
||||||
|
{
|
||||||
|
$options []=
|
||||||
|
[
|
||||||
|
'class' => 'edit',
|
||||||
|
'text' => 'Edit account settings',
|
||||||
|
'link' => \Chibi\UrlHelper::route('user', 'edit', ['name' => $this->context->transport->user->name, 'tab' => 'edit']),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (PrivilegesHelper::confirm(Privilege::DeleteUser, PrivilegesHelper::getIdentitySubPrivilege($this->context->transport->user)))
|
||||||
|
{
|
||||||
|
$options []=
|
||||||
|
[
|
||||||
|
'class' => 'delete',
|
||||||
|
'text' => 'Delete account',
|
||||||
|
'link' => \Chibi\UrlHelper::route('user', 'delete', ['name' => $this->context->transport->user->name, 'tab' => 'delete']),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (PrivilegesHelper::confirm(Privilege::FlagUser))
|
||||||
|
{
|
||||||
|
if ($this->context->flagged)
|
||||||
|
{
|
||||||
|
$options []=
|
||||||
|
[
|
||||||
|
'class' => 'flag',
|
||||||
|
'text' => 'Flagged',
|
||||||
|
'inactive' => true,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$options []=
|
||||||
|
[
|
||||||
|
'class' => 'flag',
|
||||||
|
'text' => 'Flag for moderator attention',
|
||||||
|
'simple-action' => \Chibi\UrlHelper::route('user', 'flag', ['name' => $this->context->transport->user->name]),
|
||||||
|
'data-confirm-text' => 'Are you sure you want to flag this user?',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (PrivilegesHelper::confirm(Privilege::BanUser, PrivilegesHelper::getIdentitySubPrivilege($this->context->transport->user)))
|
||||||
|
{
|
||||||
|
if (!$this->context->transport->user->banned)
|
||||||
|
{
|
||||||
|
$options []=
|
||||||
|
[
|
||||||
|
'class' => 'ban',
|
||||||
|
'text' => 'Ban user',
|
||||||
|
'simple-action' => \Chibi\UrlHelper::route('user', 'ban', ['name' => $this->context->transport->user->name]),
|
||||||
|
'data-confirm-text' => 'Are you sure?',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$options []=
|
||||||
|
[
|
||||||
|
'class' => 'unban',
|
||||||
|
'text' => 'Unban user',
|
||||||
|
'simple-action' => \Chibi\UrlHelper::route('user', 'unban', ['name' => $this->context->transport->user->name]),
|
||||||
|
'data-confirm-text' => 'Are you sure?',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (PrivilegesHelper::confirm(Privilege::AcceptUserRegistration) and !$this->context->transport->user->staff_confirmed and $this->config->registration->staffActivation)
|
||||||
|
{
|
||||||
|
$options []=
|
||||||
|
[
|
||||||
|
'class' => 'accept-registration',
|
||||||
|
'text' => 'Accept registration',
|
||||||
|
'simple-action' => \Chibi\UrlHelper::route('user', 'accept-registration', ['name' => $this->context->transport->user->name]),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->context->options = $options;
|
||||||
|
$this->renderFile('sidebar-options');
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<?php if ($canModifyAnything): ?>
|
|
||||||
<li class="edit">
|
|
||||||
<a href="<?php echo \Chibi\UrlHelper::route('user', 'edit', ['name' => $this->context->transport->user->name, 'tab' => 'edit']) ?>">
|
|
||||||
Edit account settings
|
|
||||||
</a>
|
|
||||||
</li>
|
|
||||||
<?php endif ?>
|
|
||||||
|
|
||||||
<?php if (PrivilegesHelper::confirm(Privilege::DeleteUser, PrivilegesHelper::getIdentitySubPrivilege($this->context->transport->user))): ?>
|
|
||||||
<li class="edit">
|
|
||||||
<a href="<?php echo \Chibi\UrlHelper::route('user', 'delete', ['name' => $this->context->transport->user->name, 'tab' => 'delete']) ?>">
|
|
||||||
Delete account
|
|
||||||
</a>
|
|
||||||
</li>
|
|
||||||
<?php endif ?>
|
|
||||||
|
|
||||||
<?php if (PrivilegesHelper::confirm(Privilege::FlagUser)): ?>
|
|
||||||
<li class="flag">
|
|
||||||
<?php if ($this->context->flagged): ?>
|
|
||||||
<a class="simple-action inactive" href="#">
|
|
||||||
Flagged
|
|
||||||
</a>
|
|
||||||
<?php else: ?>
|
|
||||||
<a class="simple-action" href="<?php echo \Chibi\UrlHelper::route('user', 'flag', ['name' => $this->context->transport->user->name]) ?>" data-confirm-text="Are you sure you want to flag this user?">
|
|
||||||
Flag for moderator attention
|
|
||||||
</a>
|
|
||||||
<?php endif ?>
|
|
||||||
</li>
|
|
||||||
<?php endif ?>
|
|
||||||
|
|
||||||
<?php if (PrivilegesHelper::confirm(Privilege::BanUser, PrivilegesHelper::getIdentitySubPrivilege($this->context->transport->user))): ?>
|
|
||||||
<?php if (!$this->context->transport->user->banned): ?>
|
|
||||||
<li class="ban">
|
|
||||||
<a class="simple-action" href="<?php echo \Chibi\UrlHelper::route('user', 'ban', ['name' => $this->context->transport->user->name]) ?>" data-confirm-text="Are you sure?">
|
|
||||||
Ban user
|
|
||||||
</a>
|
|
||||||
</li>
|
|
||||||
<?php else: ?>
|
|
||||||
<li class="unban">
|
|
||||||
<a class="simple-action" href="<?php echo \Chibi\UrlHelper::route('user', 'unban', ['name' => $this->context->transport->user->name]) ?>" data-confirm-text="Are you sure?">
|
|
||||||
Unban user
|
|
||||||
</a>
|
|
||||||
</li>
|
|
||||||
<?php endif ?>
|
|
||||||
<?php endif ?>
|
|
||||||
|
|
||||||
<?php if (PrivilegesHelper::confirm(Privilege::AcceptUserRegistration) and !$this->context->transport->user->staff_confirmed and $this->config->registration->staffActivation): ?>
|
|
||||||
<li class="accept-registration">
|
|
||||||
<a class="simple-action" href="<?php echo \Chibi\UrlHelper::route('user', 'accept-registration', ['name' => $this->context->transport->user->name]) ?>">
|
|
||||||
Accept registration
|
|
||||||
</a>
|
|
||||||
</li>
|
|
||||||
<?php endif ?>
|
|
||||||
</ul>
|
|
||||||
|
|
||||||
<script type="text/javascript">
|
|
||||||
if (!$('.options ul li').length)
|
|
||||||
$('.options').hide();
|
|
||||||
</script>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="inner-content">
|
<div id="inner-content">
|
||||||
|
|
Loading…
Reference in a new issue