Shortened a few lines in views

This commit is contained in:
Marcin Kurczewski 2014-06-10 11:01:24 +02:00
parent c2e3c8dd23
commit 09973ae151
4 changed files with 107 additions and 103 deletions

View file

@ -1,7 +1,11 @@
<?php
$post = $this->context->transport->post;
?>
<form method="post" <form method="post"
action="<?= Core::getRouter()->linkTo( action="<?= Core::getRouter()->linkTo(
['PostController', 'editAction'], ['PostController', 'editAction'],
['identifier' => $this->context->transport->post->getId()]) ?>" ['identifier' => $post->getId()]) ?>"
enctype="multipart/form-data" enctype="multipart/form-data"
class="edit-post"> class="edit-post">
@ -10,12 +14,12 @@
<input type="hidden" <input type="hidden"
name="revision" name="revision"
id="revision" id="revision"
value="<?= htmlspecialchars($this->context->transport->post->getRevision()) ?>"/> value="<?= htmlspecialchars($post->getRevision()) ?>"/>
<?php <?php
if (Access::check(new Privilege( if (Access::check(new Privilege(
Privilege::EditPostSafety, Privilege::EditPostSafety,
Access::getIdentity($this->context->transport->post->getUploader())))) Access::getIdentity($post->getUploader()))))
{ {
$safety = PostSafety::getAll(); $safety = PostSafety::getAll();
@ -24,13 +28,13 @@
$context->name = 'safety'; $context->name = 'safety';
$context->optionValues = array_map(function($s) { return $s->toInteger(); }, $safety); $context->optionValues = array_map(function($s) { return $s->toInteger(); }, $safety);
$context->optionLabels = array_map(function($s) { return ucfirst($s->toDisplayString()); }, $safety); $context->optionLabels = array_map(function($s) { return ucfirst($s->toDisplayString()); }, $safety);
$context->activeOptionValue = $this->context->transport->post->getSafety()->toInteger(); $context->activeOptionValue = $post->getSafety()->toInteger();
$this->renderExternal('input-radioboxes', $context); $this->renderExternal('input-radioboxes', $context);
} }
if (Access::check(new Privilege( if (Access::check(new Privilege(
Privilege::EditPostTags, Privilege::EditPostTags,
Access::getIdentity($this->context->transport->post->getUploader())))) Access::getIdentity($post->getUploader()))))
{ {
$context = new StdClass; $context = new StdClass;
$context->label = 'Tags'; $context->label = 'Tags';
@ -41,24 +45,24 @@
{ {
return htmlspecialchars($tag->getName()); return htmlspecialchars($tag->getName());
}, },
$this->context->transport->post->getTags())); $post->getTags()));
$this->renderExternal('input-text', $context); $this->renderExternal('input-text', $context);
} }
if (Access::check(new Privilege( if (Access::check(new Privilege(
Privilege::EditPostSource, Privilege::EditPostSource,
Access::getIdentity($this->context->transport->post->getUploader())))) Access::getIdentity($post->getUploader()))))
{ {
$context = new StdClass; $context = new StdClass;
$context->label = 'Source'; $context->label = 'Source';
$context->name = 'source'; $context->name = 'source';
$context->value = htmlspecialchars($this->context->transport->post->getSource()); $context->value = htmlspecialchars($post->getSource());
$this->renderExternal('input-text', $context); $this->renderExternal('input-text', $context);
} }
if (Access::check(new Privilege( if (Access::check(new Privilege(
Privilege::EditPostRelations, Privilege::EditPostRelations,
Access::getIdentity($this->context->transport->post->getUploader())))) Access::getIdentity($post->getUploader()))))
{ {
$context = new StdClass; $context = new StdClass;
$context->label = 'Relations'; $context->label = 'Relations';
@ -69,13 +73,13 @@
{ {
return $post->getId(); return $post->getId();
}, },
$this->context->transport->post->getRelations())); $post->getRelations()));
$this->renderExternal('input-text', $context); $this->renderExternal('input-text', $context);
} }
if (Access::check(new Privilege( if (Access::check(new Privilege(
Privilege::EditPostContent, Privilege::EditPostContent,
Access::getIdentity($this->context->transport->post->getUploader())))) Access::getIdentity($post->getUploader()))))
{ {
$context = new StdClass; $context = new StdClass;
$context->label = 'File'; $context->label = 'File';
@ -90,12 +94,12 @@
if (Access::check(new Privilege( if (Access::check(new Privilege(
Privilege::EditPostThumbnail, Privilege::EditPostThumbnail,
Access::getIdentity($this->context->transport->post->getUploader())))) Access::getIdentity($post->getUploader()))))
{ {
$context = new StdClass; $context = new StdClass;
$context->name = 'thumbnail'; $context->name = 'thumbnail';
$context->label = 'Thumb'; $context->label = 'Thumb';
if ($this->context->transport->post->hasCustomThumbnail()) if ($post->hasCustomThumbnail())
$context->additionalInfo = '(Currently using custom thumb)'; $context->additionalInfo = '(Currently using custom thumb)';
$this->renderExternal('input-file', $context); $this->renderExternal('input-file', $context);
} }

View file

@ -1,7 +1,8 @@
<?php <?php
$post = $this->context->transport->post;
$subTitle = sprintf('showing %s&nbsp;&ndash;&nbsp;%s', $subTitle = sprintf('showing %s&nbsp;&ndash;&nbsp;%s',
TextHelper::reprPost($this->context->transport->post), TextHelper::reprPost($post),
TextHelper::reprTags($this->context->transport->post->getTags())); TextHelper::reprTags($post->getTags()));
$this->assets->setSubTitle($subTitle); $this->assets->setSubTitle($subTitle);
$this->assets->addStylesheet('post-view.css'); $this->assets->addStylesheet('post-view.css');
$this->assets->addScript('post-view.js'); $this->assets->addScript('post-view.js');
@ -19,7 +20,7 @@ foreach (array_keys($editPostPrivileges) as $privilege)
{ {
if (Access::check(new Privilege( if (Access::check(new Privilege(
$privilege, $privilege,
Access::getIdentity($this->context->transport->post->getUploader())))) Access::getIdentity($post->getUploader()))))
$editPostPrivileges[$privilege] = true; $editPostPrivileges[$privilege] = true;
} }
@ -69,7 +70,7 @@ $canEditAnything = count(array_filter($editPostPrivileges)) > 0;
</nav> </nav>
<div class="unit tags"> <div class="unit tags">
<?php $tags = $this->context->transport->post->getTags() ?> <?php $tags = $post->getTags() ?>
<h1>tags (<?= count($tags) ?>)</h1> <h1>tags (<?= count($tags) ?>)</h1>
<ul> <ul>
<?php uasort($tags, function($a, $b) { return strnatcasecmp($a->getName(), $b->getName()); }) ?> <?php uasort($tags, function($a, $b) { return strnatcasecmp($a->getName(), $b->getName()); }) ?>
@ -92,7 +93,7 @@ $canEditAnything = count(array_filter($editPostPrivileges)) > 0;
<h1>details</h1> <h1>details</h1>
<div class="uploader"> <div class="uploader">
<?php $uploader = $this->context->transport->post->getUploader() ?> <?php $uploader = $post->getUploader() ?>
<?php if ($uploader): ?> <?php if ($uploader): ?>
<span class="value" title="<?= $val = $uploader->getName() ?>"> <span class="value" title="<?= $val = $uploader->getName() ?>">
<a href="<?= Core::getRouter()->linkTo( <a href="<?= Core::getRouter()->linkTo(
@ -111,14 +112,14 @@ $canEditAnything = count(array_filter($editPostPrivileges)) > 0;
<?php endif ?> <?php endif ?>
<br> <br>
<span class="date" <span class="date"
title="<?= TextHelper::formatDate($this->context->transport->post->getCreationTime(), true) ?>"> title="<?= TextHelper::formatDate($post->getCreationTime(), true) ?>">
<?= TextHelper::formatDate($this->context->transport->post->getCreationTime(), false) ?> <?= TextHelper::formatDate($post->getCreationTime(), false) ?>
</span> </span>
</div> </div>
<div class="key-value safety"> <div class="key-value safety">
<span class="key">Safety:</span> <span class="key">Safety:</span>
<span class="value safety-<?= $val = $this->context->transport->post->getSafety()->toDisplayString() ?>" <span class="value safety-<?= $val = $post->getSafety()->toDisplayString() ?>"
title="<?= $val ?>"> title="<?= $val ?>">
<?= $val ?> <?= $val ?>
</span> </span>
@ -127,8 +128,8 @@ $canEditAnything = count(array_filter($editPostPrivileges)) > 0;
<div class="key-value source"> <div class="key-value source">
<span class="key">Source:</span> <span class="key">Source:</span>
<span class="value" <span class="value"
title="<?= $val = htmlspecialchars($this->context->transport->post->getSource() ?: 'unknown') ?>"> title="<?= $val = htmlspecialchars($post->getSource() ?: 'unknown') ?>">
<?php if (preg_match('/^((https?|ftp):|)\/\//', $this->context->transport->post->getSource())): ?> <?php if (preg_match('/^((https?|ftp):|)\/\//', $post->getSource())): ?>
<a href="<?= $val ?>"><?= $val ?></a> <a href="<?= $val ?>"><?= $val ?></a>
<?php else: ?> <?php else: ?>
<?= $val ?> <?= $val ?>
@ -136,12 +137,12 @@ $canEditAnything = count(array_filter($editPostPrivileges)) > 0;
</span> </span>
</div> </div>
<?php if ($this->context->transport->post->getImageWidth()): ?> <?php if ($post->getImageWidth()): ?>
<div class="key-value dim"> <div class="key-value dim">
<span class="key">Dimensions:</span> <span class="key">Dimensions:</span>
<span class="value" title="<?= $val = sprintf('%dx%d', <span class="value" title="<?= $val = sprintf('%dx%d',
$this->context->transport->post->getImageWidth(), $post->getImageWidth(),
$this->context->transport->post->getImageHeight()) ?>"> $post->getImageHeight()) ?>">
<?= $val ?> <?= $val ?>
</span> </span>
</div> </div>
@ -150,19 +151,19 @@ $canEditAnything = count(array_filter($editPostPrivileges)) > 0;
<div class="key-value score"> <div class="key-value score">
<span class="key">Score:</span> <span class="key">Score:</span>
<span class="value"> <span class="value">
<?= $this->context->transport->post->getScore() ?> <?= $post->getScore() ?>
<?php <?php
$scoreLink = function($score) $scoreLink = function($score) use ($post)
{ {
return Core::getRouter()->linkTo( return Core::getRouter()->linkTo(
['PostController', 'scoreAction'], ['PostController', 'scoreAction'],
['identifier' => $this->context->transport->post->getId(), 'score' => $score]); ['identifier' => $post->getId(), 'score' => $score]);
} }
?> ?>
<?php if (Access::check(new Privilege( <?php if (Access::check(new Privilege(
Privilege::ScorePost, Privilege::ScorePost,
Access::getIdentity($this->context->transport->post->getUploader())))): ?> Access::getIdentity($post->getUploader())))): ?>
<?php if ($this->context->userScore === 1): ?> <?php if ($this->context->userScore === 1): ?>
<a class="simple-action selected" href="<?= $scoreLink(0) ?>"> <a class="simple-action selected" href="<?= $scoreLink(0) ?>">
<?php else: ?> <?php else: ?>
@ -186,19 +187,19 @@ $canEditAnything = count(array_filter($editPostPrivileges)) > 0;
</div> </div>
<div class="unit hl-options"> <div class="unit hl-options">
<?php if ($this->context->transport->post->getType()->toInteger() != PostType::Youtube): ?> <?php if ($post->getType()->toInteger() != PostType::Youtube): ?>
<div class="hl-option"> <div class="hl-option">
<a title="Download" href="<?= Core::getRouter()->linkTo( <a title="Download" href="<?= Core::getRouter()->linkTo(
['PostController', 'fileView'], ['PostController', 'fileView'],
['name' => $this->context->transport->post->getName()]) ?>"> ['name' => $post->getName()]) ?>">
<i class="icon-dl"></i> <i class="icon-dl"></i>
<span> <span>
<?php <?php
printf( printf(
'Download %s (%s)', 'Download %s (%s)',
strtoupper(TextHelper::resolveMimeType($this->context->transport->post->getMimeType())) strtoupper(TextHelper::resolveMimeType($post->getMimeType()))
?: 'Unknown', ?: 'Unknown',
TextHelper::useBytesUnits($this->context->transport->post->getFileSize())); TextHelper::useBytesUnits($post->getFileSize()));
?> ?>
</span> </span>
</a> </a>
@ -207,13 +208,13 @@ $canEditAnything = count(array_filter($editPostPrivileges)) > 0;
<?php if (Access::check(new Privilege( <?php if (Access::check(new Privilege(
Privilege::FavoritePost, Privilege::FavoritePost,
Access::getIdentity($this->context->transport->post->getUploader())))): ?> Access::getIdentity($post->getUploader())))): ?>
<div class="hl-option"> <div class="hl-option">
<?php if (!$this->context->isUserFavorite): ?> <?php if (!$this->context->isUserFavorite): ?>
<a class="add-fav icon simple-action" <a class="add-fav icon simple-action"
href="<?= Core::getRouter()->linkTo( href="<?= Core::getRouter()->linkTo(
['PostController', 'addFavoriteAction'], ['PostController', 'addFavoriteAction'],
['identifier' => $this->context->transport->post->getId()]) ?>"> ['identifier' => $post->getId()]) ?>">
<i class="icon-fav"></i> <i class="icon-fav"></i>
<span>Add to favorites</span> <span>Add to favorites</span>
</a> </a>
@ -221,7 +222,7 @@ $canEditAnything = count(array_filter($editPostPrivileges)) > 0;
<a class="rem-fav icon simple-action" <a class="rem-fav icon simple-action"
href="<?= Core::getRouter()->linkTo( href="<?= Core::getRouter()->linkTo(
['PostController', 'removeFavoriteAction'], ['PostController', 'removeFavoriteAction'],
['identifier' => $this->context->transport->post->getId()]) ?>"> ['identifier' => $post->getId()]) ?>">
<i class="icon-fav"></i> <i class="icon-fav"></i>
<span>Remove from favorites</span> <span>Remove from favorites</span>
</a> </a>
@ -233,7 +234,7 @@ $canEditAnything = count(array_filter($editPostPrivileges)) > 0;
<div class="hl-option"> <div class="hl-option">
<a class="edit-post icon" href="<?= Core::getRouter()->linkTo( <a class="edit-post icon" href="<?= Core::getRouter()->linkTo(
['PostController', 'editView'], ['PostController', 'editView'],
['identifier' => $this->context->transport->post->getId()]) ?>"> ['identifier' => $post->getId()]) ?>">
<i class="icon-edit"></i> <i class="icon-edit"></i>
<span>Edit</span> <span>Edit</span>
</a> </a>
@ -241,11 +242,11 @@ $canEditAnything = count(array_filter($editPostPrivileges)) > 0;
<?php endif ?> <?php endif ?>
</div> </div>
<?php if (count($this->context->transport->post->getFavorites()) > 0): ?> <?php if (count($post->getFavorites()) > 0): ?>
<div class="unit favorites"> <div class="unit favorites">
<h1>favorites (<?= count($this->context->transport->post->getFavorites()) ?>)</h1> <h1>favorites (<?= count($post->getFavorites()) ?>)</h1>
<ul> <ul>
<?php foreach ($this->context->transport->post->getFavorites() as $user): ?> <?php foreach ($post->getFavorites() as $user): ?>
<li> <li>
<a title="<?= $user->getName() ?>" href="<?= Core::getRouter()->linkTo( <a title="<?= $user->getName() ?>" href="<?= Core::getRouter()->linkTo(
['UserController', 'genericView'], ['UserController', 'genericView'],
@ -258,11 +259,11 @@ $canEditAnything = count(array_filter($editPostPrivileges)) > 0;
</div> </div>
<?php endif ?> <?php endif ?>
<?php if (count($this->context->transport->post->getRelations())): ?> <?php if (count($post->getRelations())): ?>
<div class="unit relations"> <div class="unit relations">
<h1>related</h1> <h1>related</h1>
<ul> <ul>
<?php foreach ($this->context->transport->post->getRelations() as $relatedPost): ?> <?php foreach ($post->getRelations() as $relatedPost): ?>
<li> <li>
<a href="<?= Core::getRouter()->linkTo( <a href="<?= Core::getRouter()->linkTo(
['PostController', 'genericView'], ['PostController', 'genericView'],
@ -280,7 +281,7 @@ $canEditAnything = count(array_filter($editPostPrivileges)) > 0;
if (Access::check(new Privilege( if (Access::check(new Privilege(
Privilege::FeaturePost, Privilege::FeaturePost,
Access::getIdentity($this->context->transport->post->getUploader())))) Access::getIdentity($post->getUploader()))))
{ {
$options []= $options []=
[ [
@ -288,7 +289,7 @@ $canEditAnything = count(array_filter($editPostPrivileges)) > 0;
'text' => 'Feature on main page', 'text' => 'Feature on main page',
'simple-action' => Core::getRouter()->linkTo( 'simple-action' => Core::getRouter()->linkTo(
['PostController', 'featureAction'], ['PostController', 'featureAction'],
['identifier' => $this->context->transport->post->getId()]), ['identifier' => $post->getId()]),
'data-confirm-text' => 'Are you sure you want to feature this post on the main page?', 'data-confirm-text' => 'Are you sure you want to feature this post on the main page?',
'data-redirect-url' => Core::getRouter()->linkTo(['StaticPagesController', 'mainPageView']), 'data-redirect-url' => Core::getRouter()->linkTo(['StaticPagesController', 'mainPageView']),
]; ];
@ -296,7 +297,7 @@ $canEditAnything = count(array_filter($editPostPrivileges)) > 0;
if (Access::check(new Privilege( if (Access::check(new Privilege(
Privilege::FlagPost, Privilege::FlagPost,
Access::getIdentity($this->context->transport->post->getUploader())))) Access::getIdentity($post->getUploader()))))
{ {
if ($this->context->flagged) if ($this->context->flagged)
{ {
@ -315,7 +316,7 @@ $canEditAnything = count(array_filter($editPostPrivileges)) > 0;
'text' => 'Flag for moderator attention', 'text' => 'Flag for moderator attention',
'simple-action' => Core::getRouter()->linkTo( 'simple-action' => Core::getRouter()->linkTo(
['PostController', 'flagAction'], ['PostController', 'flagAction'],
['identifier' => $this->context->transport->post->getId()]), ['identifier' => $post->getId()]),
'data-confirm-text' => 'Are you sure you want to flag this post?', 'data-confirm-text' => 'Are you sure you want to flag this post?',
]; ];
} }
@ -323,9 +324,9 @@ $canEditAnything = count(array_filter($editPostPrivileges)) > 0;
if (Access::check(new Privilege( if (Access::check(new Privilege(
Privilege::HidePost, Privilege::HidePost,
Access::getIdentity($this->context->transport->post->getUploader())))) Access::getIdentity($post->getUploader()))))
{ {
if ($this->context->transport->post->isHidden()) if ($post->isHidden())
{ {
$options []= $options []=
[ [
@ -333,7 +334,7 @@ $canEditAnything = count(array_filter($editPostPrivileges)) > 0;
'text' => 'Unhide', 'text' => 'Unhide',
'simple-action' => Core::getRouter()->linkTo( 'simple-action' => Core::getRouter()->linkTo(
['PostController', 'unhideAction'], ['PostController', 'unhideAction'],
['identifier' => $this->context->transport->post->getId()]), ['identifier' => $post->getId()]),
]; ];
} }
else else
@ -344,14 +345,14 @@ $canEditAnything = count(array_filter($editPostPrivileges)) > 0;
'text' => 'Hide', 'text' => 'Hide',
'simple-action' => Core::getRouter()->linkTo( 'simple-action' => Core::getRouter()->linkTo(
['PostController', 'hideAction'], ['PostController', 'hideAction'],
['identifier' => $this->context->transport->post->getId()]), ['identifier' => $post->getId()]),
]; ];
} }
} }
if (Access::check(new Privilege( if (Access::check(new Privilege(
Privilege::DeletePost, Privilege::DeletePost,
Access::getIdentity($this->context->transport->post->getUploader())))) Access::getIdentity($post->getUploader()))))
{ {
$options []= $options []=
[ [
@ -359,7 +360,7 @@ $canEditAnything = count(array_filter($editPostPrivileges)) > 0;
'text' => 'Delete', 'text' => 'Delete',
'simple-action' => Core::getRouter()->linkTo( 'simple-action' => Core::getRouter()->linkTo(
['PostController', 'deleteAction'], ['PostController', 'deleteAction'],
['identifier' => $this->context->transport->post->getId()]), ['identifier' => $post->getId()]),
'data-confirm-text' => 'Are you sure you want to delete this post?', 'data-confirm-text' => 'Are you sure you want to delete this post?',
'data-redirect-url' => Core::getRouter()->linkTo(['PostController', 'listView']), 'data-redirect-url' => Core::getRouter()->linkTo(['PostController', 'listView']),
]; ];
@ -377,7 +378,7 @@ $canEditAnything = count(array_filter($editPostPrivileges)) > 0;
</div> </div>
<?php endif ?> <?php endif ?>
<div class="post-wrapper post-type-<?= $this->context->transport->post->getType()->toString() ?>"> <div class="post-wrapper post-type-<?= $post->getType()->toString() ?>">
<?php $this->renderExternal('post-file-render') ?> <?php $this->renderExternal('post-file-render') ?>
</div> </div>
@ -387,11 +388,11 @@ $canEditAnything = count(array_filter($editPostPrivileges)) > 0;
?> ?>
<div class="comments-wrapper"> <div class="comments-wrapper">
<?php if (!empty($this->context->transport->post->getComments())): ?> <?php if (!empty($post->getComments())): ?>
<div class="unit comments"> <div class="unit comments">
<h1>comments (<?= count($this->context->transport->post->getComments()) ?>)</h1> <h1>comments (<?= count($post->getComments()) ?>)</h1>
<div class="comments"> <div class="comments">
<?php foreach ($this->context->transport->post->getComments() as $comment): ?> <?php foreach ($post->getComments() as $comment): ?>
<?php $this->context->comment = $comment ?> <?php $this->context->comment = $comment ?>
<?php $this->renderExternal('comment-small') ?> <?php $this->renderExternal('comment-small') ?>
<?php endforeach ?> <?php endforeach ?>

View file

@ -1,18 +1,19 @@
<?php <?php
$this->assets->addScript('user-edit.js'); $this->assets->addScript('user-edit.js');
$user = $this->context->transport->user;
?> ?>
<form <form
action="<?= Core::getRouter()->linkTo( action="<?= Core::getRouter()->linkTo(
['UserController', 'editAction'], ['UserController', 'editAction'],
['identifier' => $this->context->transport->user->getName()]) ?>" ['identifier' => $user->getName()]) ?>"
enctype="multipart/form-data" enctype="multipart/form-data"
method="post" method="post"
class="edit-user simple-action" class="edit-user simple-action"
autocomplete="off"> autocomplete="off">
<?php <?php
if (Auth::getCurrentUser()->getId() == $this->context->transport->user->getId()) if (Auth::getCurrentUser()->getId() == $user->getId())
{ {
$context = new StdClass; $context = new StdClass;
$context->label = 'Current password'; $context->label = 'Current password';
@ -24,7 +25,7 @@ $this->assets->addScript('user-edit.js');
if (Access::check(new Privilege( if (Access::check(new Privilege(
Privilege::EditUserAvatar, Privilege::EditUserAvatar,
Access::getIdentity($this->context->transport->user)))) Access::getIdentity($user))))
{ {
$styles = UserAvatarStyle::getAll(); $styles = UserAvatarStyle::getAll();
$context = new StdClass; $context = new StdClass;
@ -32,7 +33,7 @@ $this->assets->addScript('user-edit.js');
$context->label = 'User picture'; $context->label = 'User picture';
$context->optionValues = array_map(function($s) { return $s->toInteger(); }, $styles); $context->optionValues = array_map(function($s) { return $s->toInteger(); }, $styles);
$context->optionLabels = array_map(function($s) { return ucfirst($s->toDisplayString()); }, $styles); $context->optionLabels = array_map(function($s) { return ucfirst($s->toDisplayString()); }, $styles);
$context->activeOptionValue = $this->context->transport->user->getAvatarStyle()->toInteger(); $context->activeOptionValue = $user->getAvatarStyle()->toInteger();
$context->inputClass = 'avatar-style'; $context->inputClass = 'avatar-style';
$this->renderExternal('input-radioboxes', $context); $this->renderExternal('input-radioboxes', $context);
@ -44,7 +45,7 @@ $this->assets->addScript('user-edit.js');
if (Access::check(new Privilege( if (Access::check(new Privilege(
Privilege::EditUserName, Privilege::EditUserName,
Access::getIdentity($this->context->transport->user)))) Access::getIdentity($user))))
{ {
$context = new StdClass; $context = new StdClass;
$context->label = 'Name'; $context->label = 'Name';
@ -56,7 +57,7 @@ $this->assets->addScript('user-edit.js');
if (Access::check(new Privilege( if (Access::check(new Privilege(
Privilege::EditUserEmail, Privilege::EditUserEmail,
Access::getIdentity($this->context->transport->user)))) Access::getIdentity($user))))
{ {
$context = new StdClass; $context = new StdClass;
$context->label = 'E-mail'; $context->label = 'E-mail';
@ -68,7 +69,7 @@ $this->assets->addScript('user-edit.js');
if (Access::check(new Privilege( if (Access::check(new Privilege(
Privilege::EditUserPassword, Privilege::EditUserPassword,
Access::getIdentity($this->context->transport->user)))) Access::getIdentity($user))))
{ {
$context = new StdClass; $context = new StdClass;
$context->label = 'New password'; $context->label = 'New password';
@ -86,14 +87,11 @@ $this->assets->addScript('user-edit.js');
if (Access::check(new Privilege( if (Access::check(new Privilege(
Privilege::EditUserAccessRank, Privilege::EditUserAccessRank,
Access::getIdentity($this->context->transport->user)))) Access::getIdentity($user))))
{ {
$accessRanks = array_filter( $accessRanks = array_filter(
AccessRank::getAll(), AccessRank::getAll(),
function($ar) function($ar) { return $ar->toInteger() != AccessRank::Nobody; });
{
return $ar->toInteger() != AccessRank::Nobody;
});
$context = new StdClass; $context = new StdClass;
$context->name = 'access-rank'; $context->name = 'access-rank';
@ -102,7 +100,7 @@ $this->assets->addScript('user-edit.js');
$context->optionValues = array_map(function($ar) { return $ar->toInteger(); }, $accessRanks); $context->optionValues = array_map(function($ar) { return $ar->toInteger(); }, $accessRanks);
$context->optionLabels = array_map(function($ar) { return $ar->toDisplayString(); }, $accessRanks); $context->optionLabels = array_map(function($ar) { return $ar->toDisplayString(); }, $accessRanks);
$context->activeOptionValue = InputHelper::get('access-rank') $context->activeOptionValue = InputHelper::get('access-rank')
?: $this->context->transport->user->getAccessRank()->toInteger(); ?: $user->getAccessRank()->toInteger();
$this->renderExternal('input-select', $context); $this->renderExternal('input-select', $context);
} }

View file

@ -1,5 +1,6 @@
<?php <?php
$this->assets->setSubTitle($this->context->transport->user->getName()); $user = $this->context->transport->user;
$this->assets->setSubTitle($user->getName());
$this->assets->addStylesheet('user-view.css'); $this->assets->addStylesheet('user-view.css');
?> ?>
@ -7,13 +8,13 @@ $this->assets->addStylesheet('user-view.css');
<div class="avatar-wrapper"> <div class="avatar-wrapper">
<a href="<?= Core::getRouter()->linkTo( <a href="<?= Core::getRouter()->linkTo(
['UserController', 'genericView'], ['UserController', 'genericView'],
['identifier' => $this->context->transport->user->getName()]) ?>"> ['identifier' => $user->getName()]) ?>">
<img <img
src="<?= htmlspecialchars($this->context->transport->user->getAvatarUrl(140)) ?>" src="<?= htmlspecialchars($user->getAvatarUrl(140)) ?>"
alt="<?= $this->context->transport->user->getName() ?>"/> alt="<?= $user->getName() ?>"/>
</a> </a>
<h1><?= $this->context->transport->user->getName() ?></h1> <h1><?= $user->getName() ?></h1>
</div> </div>
<div class="unit details"> <div class="unit details">
@ -23,9 +24,9 @@ $this->assets->addStylesheet('user-view.css');
<span class="key">Joined:</span> <span class="key">Joined:</span>
<span <span
class="value" class="value"
title="<?= TextHelper::formatDate($this->context->transport->user->getJoinTime(), true) ?>"> title="<?= TextHelper::formatDate($user->getJoinTime(), true) ?>">
<?= TextHelper::formatDate($this->context->transport->user->getJoinTime(), false) ?> <?= TextHelper::formatDate($user->getJoinTime(), false) ?>
</span> </span>
</div> </div>
@ -34,9 +35,9 @@ $this->assets->addStylesheet('user-view.css');
<span class="key">Last seen:</span> <span class="key">Last seen:</span>
<span <span
class="value" class="value"
title="<?= TextHelper::formatDate($this->context->transport->user->getLastLoginTime(), true) ?>"> title="<?= TextHelper::formatDate($user->getLastLoginTime(), true) ?>">
<?= TextHelper::formatDate($this->context->transport->user->getLastLoginTime(), false) ?> <?= TextHelper::formatDate($user->getLastLoginTime(), false) ?>
</span> </span>
</div> </div>
@ -45,7 +46,7 @@ $this->assets->addStylesheet('user-view.css');
<span class="key">Access rank:</span> <span class="key">Access rank:</span>
<span <span
class="value" class="value"
title="<?= $val = $this->context->transport->user->getAccessRank()->toDisplayString() ?>"> title="<?= $val = $user->getAccessRank()->toDisplayString() ?>">
<?= $val ?> <?= $val ?>
@ -54,13 +55,13 @@ $this->assets->addStylesheet('user-view.css');
<?php if (Access::check(new Privilege( <?php if (Access::check(new Privilege(
Privilege::ViewUserEmail, Privilege::ViewUserEmail,
Access::getIdentity($this->context->transport->user)))): ?> Access::getIdentity($user)))): ?>
<div class="key-value email"> <div class="key-value email">
<span class="key">E-mail:</span> <span class="key">E-mail:</span>
<span class="value" title="<?= $val = ($this->context->transport->user->getUnconfirmedEmail() <span class="value" title="<?= $val = ($user->getUnconfirmedEmail()
? '(unconfirmed) ' . $this->context->transport->user->getUnconfirmedEmail() ? '(unconfirmed) ' . $user->getUnconfirmedEmail()
: $this->context->transport->user->getConfirmedEmail() ?: 'none specified') ?>"> : $user->getConfirmedEmail() ?: 'none specified') ?>">
<?= $val ?> <?= $val ?>
</span> </span>
<br>(only you and staff can see this) <br>(only you and staff can see this)
@ -81,7 +82,7 @@ $this->assets->addStylesheet('user-view.css');
if (Access::check(new Privilege( if (Access::check(new Privilege(
$privilege, $privilege,
Access::getIdentity($this->context->transport->user)))) Access::getIdentity($user))))
{ {
$userModificationPrivileges[$privilege] = true; $userModificationPrivileges[$privilege] = true;
} }
@ -98,12 +99,12 @@ $this->assets->addStylesheet('user-view.css');
'text' => 'Edit account settings', 'text' => 'Edit account settings',
'link' => Core::getRouter()->linkTo( 'link' => Core::getRouter()->linkTo(
['UserController', 'editAction'], ['UserController', 'editAction'],
['identifier' => $this->context->transport->user->getName(), 'tab' => 'edit']), ['identifier' => $user->getName(), 'tab' => 'edit']),
]; ];
} }
if (Access::check(new Privilege(Privilege::AcceptUserRegistration)) if (Access::check(new Privilege(Privilege::AcceptUserRegistration))
and !$this->context->transport->user->isStaffConfirmed() and !$user->isStaffConfirmed()
and Core::getConfig()->registration->staffActivation) and Core::getConfig()->registration->staffActivation)
{ {
$options []= $options []=
@ -112,13 +113,13 @@ $this->assets->addStylesheet('user-view.css');
'text' => 'Accept registration', 'text' => 'Accept registration',
'simple-action' => Core::getRouter()->linkTo( 'simple-action' => Core::getRouter()->linkTo(
['UserController', 'acceptRegistrationAction'], ['UserController', 'acceptRegistrationAction'],
['identifier' => $this->context->transport->user->getName()]), ['identifier' => $user->getName()]),
]; ];
} }
if (Access::check(new Privilege( if (Access::check(new Privilege(
Privilege::FlagUser, Privilege::FlagUser,
Access::getIdentity($this->context->transport->user)))) Access::getIdentity($user))))
{ {
if ($this->context->flagged) if ($this->context->flagged)
{ {
@ -137,7 +138,7 @@ $this->assets->addStylesheet('user-view.css');
'text' => 'Flag for moderator attention', 'text' => 'Flag for moderator attention',
'simple-action' => Core::getRouter()->linkTo( 'simple-action' => Core::getRouter()->linkTo(
['UserController', 'flagAction'], ['UserController', 'flagAction'],
['identifier' => $this->context->transport->user->getName()]), ['identifier' => $user->getName()]),
'data-confirm-text' => 'Are you sure you want to flag this user?', 'data-confirm-text' => 'Are you sure you want to flag this user?',
]; ];
} }
@ -145,9 +146,9 @@ $this->assets->addStylesheet('user-view.css');
if (Access::check(new Privilege( if (Access::check(new Privilege(
Privilege::BanUser, Privilege::BanUser,
Access::getIdentity($this->context->transport->user)))) Access::getIdentity($user))))
{ {
if (!$this->context->transport->user->isBanned()) if (!$user->isBanned())
{ {
$options []= $options []=
[ [
@ -155,7 +156,7 @@ $this->assets->addStylesheet('user-view.css');
'text' => 'Ban user', 'text' => 'Ban user',
'simple-action' => Core::getRouter()->linkTo( 'simple-action' => Core::getRouter()->linkTo(
['UserController', 'banAction'], ['UserController', 'banAction'],
['identifier' => $this->context->transport->user->getName()]), ['identifier' => $user->getName()]),
'data-confirm-text' => 'Are you sure you want to ban this user?', 'data-confirm-text' => 'Are you sure you want to ban this user?',
]; ];
} }
@ -167,7 +168,7 @@ $this->assets->addStylesheet('user-view.css');
'text' => 'Unban user', 'text' => 'Unban user',
'simple-action' => Core::getRouter()->linkTo( 'simple-action' => Core::getRouter()->linkTo(
['UserController', 'unbanAction'], ['UserController', 'unbanAction'],
['identifier' => $this->context->transport->user->getName()]), ['identifier' => $user->getName()]),
'data-confirm-text' => 'Are you sure you want to unban this user?', 'data-confirm-text' => 'Are you sure you want to unban this user?',
]; ];
} }
@ -175,7 +176,7 @@ $this->assets->addStylesheet('user-view.css');
if (Access::check(new Privilege( if (Access::check(new Privilege(
Privilege::DeleteUser, Privilege::DeleteUser,
Access::getIdentity($this->context->transport->user)))) Access::getIdentity($user))))
{ {
$options []= $options []=
[ [
@ -183,7 +184,7 @@ $this->assets->addStylesheet('user-view.css');
'text' => 'Delete account', 'text' => 'Delete account',
'link' => Core::getRouter()->linkTo( 'link' => Core::getRouter()->linkTo(
['UserController', 'deleteAction'], ['UserController', 'deleteAction'],
['identifier' => $this->context->transport->user->getName(), 'tab' => 'delete']), ['identifier' => $user->getName(), 'tab' => 'delete']),
]; ];
} }
@ -202,7 +203,7 @@ $this->assets->addStylesheet('user-view.css');
<?php endif ?> <?php endif ?>
<a href="<?= Core::getRouter()->linkTo( <a href="<?= Core::getRouter()->linkTo(
['UserController', 'genericView'], ['UserController', 'genericView'],
['identifier' => $this->context->transport->user->getName(), ['identifier' => $user->getName(),
'tab' => 'favs', 'tab' => 'favs',
'page' => 1]) ?>"> 'page' => 1]) ?>">
Favs Favs
@ -216,7 +217,7 @@ $this->assets->addStylesheet('user-view.css');
<?php endif ?> <?php endif ?>
<a href="<?= Core::getRouter()->linkTo( <a href="<?= Core::getRouter()->linkTo(
['UserController', 'genericView'], ['UserController', 'genericView'],
['identifier' => $this->context->transport->user->getName(), ['identifier' => $user->getName(),
'tab' => 'uploads', 'tab' => 'uploads',
'page' => 1]) ?>"> 'page' => 1]) ?>">
Uploads Uploads
@ -225,7 +226,7 @@ $this->assets->addStylesheet('user-view.css');
<?php if (Access::check(new Privilege( <?php if (Access::check(new Privilege(
Privilege::EditUserSettings, Privilege::EditUserSettings,
Access::getIdentity($this->context->transport->user)))): ?> Access::getIdentity($user)))): ?>
<?php if ($this->context->transport->tab == 'settings'): ?> <?php if ($this->context->transport->tab == 'settings'): ?>
<li class="selected settings"> <li class="selected settings">
@ -234,7 +235,7 @@ $this->assets->addStylesheet('user-view.css');
<?php endif ?> <?php endif ?>
<a href="<?= Core::getRouter()->linkTo( <a href="<?= Core::getRouter()->linkTo(
['UserController', 'genericView'], ['UserController', 'genericView'],
['identifier' => $this->context->transport->user->getName(), ['identifier' => $user->getName(),
'tab' => 'settings']) ?>"> 'tab' => 'settings']) ?>">
Browsing settings Browsing settings
</a> </a>
@ -249,7 +250,7 @@ $this->assets->addStylesheet('user-view.css');
<?php endif ?> <?php endif ?>
<a href="<?= Core::getRouter()->linkTo( <a href="<?= Core::getRouter()->linkTo(
['UserController', 'genericView'], ['UserController', 'genericView'],
['identifier' => $this->context->transport->user->getName(), ['identifier' => $user->getName(),
'tab' => 'edit']) ?>"> 'tab' => 'edit']) ?>">
Account settings Account settings
</a> </a>
@ -258,7 +259,7 @@ $this->assets->addStylesheet('user-view.css');
<?php if (Access::check(new Privilege( <?php if (Access::check(new Privilege(
Privilege::DeleteUser, Privilege::DeleteUser,
Access::getIdentity($this->context->transport->user)))): ?> Access::getIdentity($user)))): ?>
<?php if ($this->context->transport->tab == 'delete'): ?> <?php if ($this->context->transport->tab == 'delete'): ?>
<li class="selected delete"> <li class="selected delete">
<?php else: ?> <?php else: ?>
@ -266,7 +267,7 @@ $this->assets->addStylesheet('user-view.css');
<?php endif ?> <?php endif ?>
<a href="<?= Core::getRouter()->linkTo( <a href="<?= Core::getRouter()->linkTo(
['UserController', 'genericView'], ['UserController', 'genericView'],
['identifier' => $this->context->transport->user->getName(), ['identifier' => $user->getName(),
'tab' => 'delete']) ?>"> 'tab' => 'delete']) ?>">
Delete account Delete account
</a> </a>