diff --git a/src/Helpers/TextHelper.php b/src/Helpers/TextHelper.php
index 1f063f94..83e8e760 100644
--- a/src/Helpers/TextHelper.php
+++ b/src/Helpers/TextHelper.php
@@ -233,4 +233,20 @@ class TextHelper
$path = self::cleanPath($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 . '>';
+ }
}
diff --git a/src/Views/post-view.phtml b/src/Views/post-view.phtml
index d128d5ff..1681e1ca 100644
--- a/src/Views/post-view.phtml
+++ b/src/Views/post-view.phtml
@@ -183,102 +183,126 @@
-
-
options
+ context->transport->post->uploader)))
+ $editPostPrivileges[$privilege] = true;
+ }
+ $canEditAnything = count(array_filter($editPostPrivileges)) > 0;
-
-
- context->favorite): ?>
- -
-
- Add to favorites
-
-
-
- -
-
- Remove from favorites
-
-
-
-
+ $options = [];
- context->favorite)
+ {
+ $options []=
+ [
+ 'class' => 'add-fav',
+ 'text' => 'Add to favorites',
+ 'simple-action' => \Chibi\UrlHelper::route('post', 'add-favorite', ['id' => $this->context->transport->post->id]),
];
- $editPostPrivileges = array_fill_keys($editPostPrivileges, false);
- foreach (array_keys($editPostPrivileges) as $privilege)
- {
- if (PrivilegesHelper::confirm($privilege, PrivilegesHelper::getIdentitySubPrivilege($this->context->transport->post->uploader)))
- $editPostPrivileges[$privilege] = true;
- }
- $canEditAnything = count(array_filter($editPostPrivileges)) > 0;
- ?>
+ }
+ else
+ {
+ $options []=
+ [
+ 'class' => 'rem-fav',
+ 'text' => 'Remove from favorites',
+ 'simple-action' => \Chibi\UrlHelper::route('post', 'rem-favorite', ['id' => $this->context->transport->post->id]),
+ ];
+ }
+ }
-
- -
-
- Edit
-
-
-
+ if ($canEditAnything)
+ {
+ $options []=
+ [
+ 'class' => 'edit',
+ 'text' => 'Edit',
+ ];
+ }
- context->transport->post->uploader))): ?>
- context->transport->post->hidden): ?>
- -
-
- Unhide
-
-
-
- -
-
- Hide
-
-
-
-
+ 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]),
+ ];
+ }
+ }
-
- -
-
- Feature on main page
-
-
-
+ 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'),
+ ];
+ }
-
- -
- context->flagged): ?>
-
- Flagged
-
-
-
- Flag for moderator attention
-
-
-
-
+ 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?',
+ ];
+ }
+ }
- context->transport->post->uploader))): ?>
- -
-
- Delete
-
-
-
-
+ 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');
+ ?>
diff --git a/src/Views/sidebar-options.phtml b/src/Views/sidebar-options.phtml
new file mode 100644
index 00000000..c3b251c7
--- /dev/null
+++ b/src/Views/sidebar-options.phtml
@@ -0,0 +1,35 @@
+context->options)): ?>
+
+
options
+
+
+ context->options as $option): ?>
+ -
+ $val)
+ if (strpos($key, 'data-') === 0)
+ $attrs[$key] = $val;
+
+ TextHelper::openHtmlTag('a', $attrs);
+ echo $option['text'];
+ TextHelper::closeHtmlTag('a');
+ ?>
+
+
+
+
+
+
diff --git a/src/Views/user-view.phtml b/src/Views/user-view.phtml
index 34c1815f..49caefaf 100644
--- a/src/Views/user-view.phtml
+++ b/src/Views/user-view.phtml
@@ -28,87 +28,104 @@
-
-
options
+
- context->transport->user)))
+ $userModificationPrivileges[$privilege] = true;
+ }
+ $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,
];
- $userModificationPrivileges = array_fill_keys($userModificationPrivileges, false);
- foreach (array_keys($userModificationPrivileges) as $privilege)
- {
+ }
+ 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, PrivilegesHelper::getIdentitySubPrivilege($this->context->transport->user)))
- $userModificationPrivileges[$privilege] = true;
- }
- $canModifyAnything = count(array_filter($userModificationPrivileges)) > 0;
- ?>
+ 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?',
+ ];
+ }
+ }
-
-
-
- Edit account settings
-
-
-
+ 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]),
+ ];
+ }
- context->transport->user))): ?>
-
-
- Delete account
-
-
-
-
-
-
- context->flagged): ?>
-
- Flagged
-
-
-
- Flag for moderator attention
-
-
-
-
-
- context->transport->user))): ?>
- context->transport->user->banned): ?>
-
-
- Ban user
-
-
-
-
-
- Unban user
-
-
-
-
-
- context->transport->user->staff_confirmed and $this->config->registration->staffActivation): ?>
-
-
- Accept registration
-
-
-
-
-
-
-
+ $this->context->options = $options;
+ $this->renderFile('sidebar-options');
+ ?>