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/post-view.phtml
Marcin Kurczewski 91b0432067 Fixed css
CSS for comments wasn't included in post-view.phtml. This manifested when user
posted a comment thruogh it (AJAX requests don't append CSS from AJAXed pages,
so added it in parent view).
2014-02-02 22:45:41 +01:00

351 lines
11 KiB
PHTML

<?php
LayoutHelper::setSubTitle('showing ' . TextHelper::reprPost($this->context->transport->post) . ' &ndash; ' . TextHelper::reprTags($this->context->transport->post->getTags()));
LayoutHelper::addStylesheet('post-view.css');
LayoutHelper::addScript('post-view.js');
LayoutHelper::addStylesheet('../lib/tagit/jquery.tagit.css');
LayoutHelper::addScript('../lib/tagit/jquery.tagit.js');
?>
<div id="sidebar">
<nav id="around">
<div class="left">
<?php if ($this->context->transport->nextPostId): ?>
<a href="<?php echo \Chibi\UrlHelper::route('post', 'view', ['id' => $this->context->transport->nextPostId]) ?>">
<?php else: ?>
<a class="disabled">
<?php endif ?>
<i class="icon-next"></i>
<span>next post</span>
</a>
</div>
<div class="right">
<?php if ($this->context->transport->prevPostId): ?>
<a href="<?php echo \Chibi\UrlHelper::route('post', 'view', ['id' => $this->context->transport->prevPostId]) ?>">
<?php else: ?>
<a class="disabled">
<?php endif ?>
<span>prev post</span>
<i class="icon-prev"></i>
</a>
</div>
<div class="clear"></div>
<?php if (!empty($this->context->transport->lastSearchQuery)): ?>
<div class="text">
Current&nbsp;search:<br/>
<a href="<?php echo \Chibi\UrlHelper::route('post', 'list', ['query' => $this->context->transport->lastSearchQuery]) ?>"><?php echo $this->context->transport->lastSearchQuery ?></a>
</div>
<?php endif ?>
</nav>
<div class="unit tags">
<h1>tags (<?php echo count($this->context->transport->post->getTags()) ?>)</h1>
<ul>
<?php $tags = $this->context->transport->post->getTags() ?>
<?php uasort($tags, function($a, $b) { return strnatcasecmp($a->name, $b->name); }) ?>
<?php foreach ($tags as $tag): ?>
<li title="<?php echo $tag->name ?>">
<a href="<?php echo \Chibi\UrlHelper::route('post', 'list', ['query' => $tag->name]) ?>">
<?php echo $tag->name ?>
</a>
<span class="count">
<?php echo TextHelper::useDecimalUnits($tag->getPostCount()) ?>
</span>
</li>
<?php endforeach ?>
</ul>
</div>
<div class="unit details">
<h1>details</h1>
<div class="key-value uploader">
<span class="key">Uploader:</span>
<?php $uploader = $this->context->transport->post->getUploader() ?>
<?php if ($uploader): ?>
<span class="value" title="<?php echo $val = $uploader->name ?>">
<a href="<?php echo \Chibi\UrlHelper::route('user', 'view', ['name' => $uploader->name]) ?>">
<img src="<?php echo htmlentities($uploader->getAvatarUrl(16)) ?>" alt="<?php echo $uploader->name ?>"/>
<?php echo $val ?>
</a>
</span>
<?php else: ?>
<span class="value" title="<?php echo UserModel::getAnonymousName() ?>">
<img src="<?php echo \Chibi\UrlHelper::absoluteUrl('/media/img/pixel.gif') ?>" alt="<?php echo UserModel::getAnonymousName() ?>"/>
<?php echo UserModel::getAnonymousName() ?>
</span>
<?php endif ?>
</div>
<div class="key-value safety">
<span class="key">Safety:</span>
<span class="value safety-<?php echo $val = TextHelper::camelCaseToHumanCase(PostSafety::toString($this->context->transport->post->safety)) ?>" title="<?php echo $val ?>">
<?php echo $val ?>
</span>
</div>
<div class="key-value score">
<span class="key">Score:</span>
<span class="value">
<?php echo $this->context->transport->post->score ?>
<?php if (PrivilegesHelper::confirm(Privilege::ScorePost)): ?>
&nbsp;[
<?php $scoreLink = function($score) { return \Chibi\UrlHelper::route('post', 'score', ['id' => $this->context->transport->post->id, 'score' => $score]); } ?>
<?php if ($this->context->score === 1): ?>
<a class="simple-action selected" href="<?php echo $scoreLink(0) ?>">
<?php else: ?>
<a class="simple-action" href="<?php echo $scoreLink(1) ?>">
<?php endif ?>
vote up
</a>
,&nbsp;
<?php if ($this->context->score === -1): ?>
<a class="simple-action selected" href="<?php echo $scoreLink(0) ?>">
<?php else: ?>
<a class="simple-action" href="<?php echo $scoreLink(-1) ?>">
<?php endif ?>
down
</a>]
<?php endif ?>
</span>
</div>
<div class="key-value date">
<span class="key">Date:</span>
<span class="value" title="<?php echo $val = date('Y-m-d H:i', $this->context->transport->post->uploadDate) ?>">
<?php echo $val ?>
</span>
</div>
<?php if ($this->context->transport->post->imageWidth > 0): ?>
<div class="key-value dim">
<span class="key">Dimensions:</span>
<span class="value" title="<?php echo $val = sprintf('%dx%d',
$this->context->transport->post->imageWidth,
$this->context->transport->post->imageHeight) ?>">
<?php echo $val ?>
</span>
</div>
<?php endif ?>
<div class="key-value source">
<span class="key">Source:</span>
<span class="value" title="<?php echo $val = htmlspecialchars($this->context->transport->post->source ?: 'unknown') ?>">
<?php if (preg_match('/^((https?|ftp):|)\/\//', $val)): ?>
<a href="<?php echo $val ?>"><?php echo $val ?></a>
<?php else: ?>
<?php echo $val ?>
<?php endif ?>
</span>
</div>
<?php if ($this->context->transport->post->type != PostType::Youtube): ?>
<div class="permalink">
<a href="<?php echo \Chibi\UrlHelper::route('post', 'retrieve', ['name' => $this->context->transport->post->name]) ?>" title="Download">
<i class="icon-dl"></i>
<span class="ext">
<?php $mimes = ['image/jpeg' => 'JPG', 'image/gif' => 'GIF', 'image/png' => 'PNG', 'application/x-shockwave-flash' => 'SWF'] ?>
<?php $mime = $this->context->transport->post->mimeType ?>
<?php echo isset($mimes[$mime]) ? $mimes[$mime] : 'unknown' ?>
</span>
<span class="size">
<?php echo TextHelper::useBytesUnits($this->context->transport->post->fileSize) ?>
</span>
</a>
</div>
<?php endif ?>
</div>
<?php if (count($this->context->transport->post->getFavorites()) > 0): ?>
<div class="unit favorites">
<h1>favorites (<?php echo count($this->context->transport->post->getFavorites()) ?>)</h1>
<ul>
<?php foreach ($this->context->transport->post->getFavorites() as $user): ?>
<li>
<a href="<?php echo \Chibi\UrlHelper::route('user', 'view', ['name' => $user->name]) ?>" title="<?php echo $user->name ?>">
<img src="<?php echo htmlspecialchars($user->getAvatarUrl()) ?>" alt="<?php echo $user->name ?>">
</a>
</li>
<?php endforeach ?>
</ul>
</div>
<?php endif ?>
<?php if (count($this->context->transport->post->getRelations())): ?>
<div class="relations unit">
<h1>related</h1>
<ul>
<?php foreach ($this->context->transport->post->getRelations() as $relatedPost): ?>
<li>
<a href="<?php echo \Chibi\UrlHelper::route('post', 'view', ['id' => $relatedPost->id]) ?>">
@<?php echo $relatedPost->id ?>
</a>
</li>
<?php endforeach ?>
</ul>
</div>
<?php endif ?>
<?php
$editPostPrivileges = [
Privilege::EditPostSafety,
Privilege::EditPostTags,
Privilege::EditPostThumb,
Privilege::EditPostSource,
];
$editPostPrivileges = array_fill_keys($editPostPrivileges, false);
foreach (array_keys($editPostPrivileges) as $privilege)
{
if (PrivilegesHelper::confirm($privilege, PrivilegesHelper::getIdentitySubPrivilege($this->context->transport->post->getUploader())))
$editPostPrivileges[$privilege] = true;
}
$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->getUploader())))
{
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->getUploader())))
{
$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');
?>
</div>
<div id="inner-content">
<div class="post-wrapper post-type-<?php echo strtolower(PostType::toString($this->context->transport->post->type)) ?>">
<?php echo $this->renderFile('post-file-render') ?>
</div>
<?php if ($canEditAnything): ?>
<div class="edit-post unit">
<?php $this->renderFile('post-edit') ?>
</div>
<?php endif ?>
<?php
LayoutHelper::addStylesheet('comment-list.css');
LayoutHelper::addStylesheet('comment-small.css');
?>
<div class="comments-wrapper">
<?php if (!empty($this->context->transport->post->getComments())): ?>
<div class="comments unit">
<h1>comments (<?php echo count($this->context->transport->post->getComments()) ?>)</h1>
<div class="comments">
<?php foreach ($this->context->transport->post->getComments() as $comment): ?>
<?php $this->context->comment = $comment ?>
<?php echo $this->renderFile('comment-small') ?>
<?php endforeach ?>
</div>
</div>
<?php endif ?>
</div>
<?php if (PrivilegesHelper::confirm(Privilege::AddComment)): ?>
<div class="unit">
<?php $this->renderFile('comment-add') ?>
</div>
<?php endif ?>
</div>