Post viewing - sidebar

This commit is contained in:
Marcin Kurczewski 2013-10-12 10:46:15 +02:00
parent b9a6dab7ae
commit b92f925e94
8 changed files with 240 additions and 11 deletions

View file

@ -100,7 +100,6 @@ body {
#sidebar h1 { #sidebar h1 {
margin-top: 0; margin-top: 0;
text-align: center;
font-weight: normal; font-weight: normal;
} }
@ -112,3 +111,26 @@ p:first-child,
h1:first-child { h1:first-child {
margin-top: 0; margin-top: 0;
} }
a {
color: firebrick;
text-decoration: none;
outline: 0;
}
a:focus,
a:hover {
color: red;
}
i[class*='icon-'] {
background-image: url('../img/icons.png');
background-repeat: no-repeat;
display: inline-block;
}
a i[class*='icon-'] {
background-color: firebrick;
}
a:focus i[class*='icon-'],
a:hover i[class*='icon-'] {
background-color: red;
}

View file

@ -1,5 +1,5 @@
.post-wrapper { .post-wrapper {
text-align: center; /*text-align: center;*/
} }
embed { embed {
@ -10,3 +10,67 @@ embed {
img { img {
max-width: 100%; max-width: 100%;
} }
.tags ul {
list-style-type: none;
margin: 0 0 0 1em;
padding: 0;
}
.tags li .count {
padding-left: 0.5em;
color: silver;
}
i.icon-prev {
background-position: -12px -1px;
}
i.icon-next {
background-position: -1px -1px;
}
i.icon-prev,
i.icon-next {
margin: 0 8px;
vertical-align: middle;
width: 8px;
height: 20px;
}
i.icon-dl {
margin: 0;
width: 20px;
height: 20px;
background-position: -22px -1px;
}
nav .left {
float: left;
}
nav .right {
float: right;
}
nav a.inactive {
color: silver;
}
nav a.inactive i[class*='icon-'] {
background-color: silver;
}
#sidebar h1 {
margin-top: 1em;
}
.dl-box {
float: left;
margin: 0 2em 0 1em;
}
.dl-box span {
display: block;
text-align: center;
font-size: small;
}
.details-box {
font-size: small;
line-height: 1.33em;
}
.details-box .key {
margin-right: 0.5em;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 322 B

View file

@ -68,7 +68,7 @@ class PostController
$searchDbQuery = R::$f->begin(); $searchDbQuery = R::$f->begin();
$searchDbQuery->select('*'); $searchDbQuery->select('*');
$buildDbQuery($searchDbQuery); $buildDbQuery($searchDbQuery);
$searchDbQuery->orderBy('upload_date DESC'); $searchDbQuery->orderBy('id DESC');
$searchDbQuery->limit('?')->put($postsPerPage); $searchDbQuery->limit('?')->put($postsPerPage);
$searchDbQuery->offset('?')->put(($page - 1) * $postsPerPage); $searchDbQuery->offset('?')->put(($page - 1) * $postsPerPage);
@ -205,13 +205,34 @@ class PostController
$post = R::findOne('post', 'id = ?', [$id]); $post = R::findOne('post', 'id = ?', [$id]);
if (!$post) if (!$post)
throw new SimpleException('Invalid post ID "' . $id . '"'); throw new SimpleException('Invalid post ID "' . $id . '"');
R::preload($post, ['user', 'tag']);
$prevPost = R::findOne('post', 'id < ? ORDER BY id DESC LIMIT 1', [$id]);
$nextPost = R::findOne('post', 'id > ? ORDER BY id ASC LIMIT 1', [$id]);
PrivilegesHelper::confirmWithException($this->context->user, Privilege::ViewPost); PrivilegesHelper::confirmWithException($this->context->user, Privilege::ViewPost);
PrivilegesHelper::confirmWithException($this->context->user, Privilege::ViewPost, PostSafety::toString($post->safety)); PrivilegesHelper::confirmWithException($this->context->user, Privilege::ViewPost, PostSafety::toString($post->safety));
$dbQuery = R::$f->begin();
$dbQuery->select('tag.name, COUNT(1) AS count');
$dbQuery->from('tag');
$dbQuery->innerJoin('post_tag');
$dbQuery->on('tag.id = post_tag.tag_id');
$dbQuery->where('tag.id IN (' . R::genSlots($post->sharedTag) . ')');
foreach ($post->sharedTag as $tag)
$dbQuery->put($tag->id);
$dbQuery->groupBy('tag.id');
$rows = $dbQuery->get();
$this->context->transport->tagDistribution = [];
foreach ($rows as $row)
$this->context->transport->tagDistribution[$row['name']] = $row['count'];
$this->context->stylesheets []= 'post-view.css'; $this->context->stylesheets []= 'post-view.css';
$this->context->subTitle = 'showing @' . $post->id; $this->context->subTitle = 'showing @' . $post->id;
$this->context->transport->post = $post; $this->context->transport->post = $post;
$this->context->transport->uploader = R::load('user', $post->user_id);
$this->context->transport->prevPostId = $prevPost ? $prevPost->id : null;
$this->context->transport->nextPostId = $nextPost ? $nextPost->id : null;
} }

View file

@ -14,7 +14,7 @@ class UserController
* @route /user/{name} * @route /user/{name}
* @validate name [^\/]+ * @validate name [^\/]+
*/ */
public function showAction($name) public function viewAction($name)
{ {
$this->context->subTitle = $name; $this->context->subTitle = $name;
throw new Exception('Not implemented'); throw new Exception('Not implemented');

View file

@ -50,4 +50,30 @@ class TextHelper
} }
return constant($constantName); return constant($constantName);
} }
private static function useUnits($number, $base, $suffixes)
{
$suffix = array_shift($suffixes);
if ($number < $base)
{
return sprintf('%d%s', $number, $suffix);
}
do
{
$suffix = array_shift($suffixes);
$number /= (float) $base;
}
while ($number >= $base and !empty($suffixes));
return sprintf('%.01f%s', $number, $suffix);
}
public static function useBytesUnits($number)
{
return self::useUnits($number, 1024, ['B', 'K', 'M', 'G']);
}
public static function useDecimalUnits($number)
{
return self::useUnits($number, 1000, ['', 'K', 'M']);
}
} }

View file

@ -48,7 +48,7 @@
} }
else else
{ {
$nav []= ['My account', \Chibi\UrlHelper::route('user', 'show', ['name' => $this->context->user->name])]; $nav []= ['My account', \Chibi\UrlHelper::route('user', 'view', ['name' => $this->context->user->name])];
$nav []= ['Log out', \Chibi\UrlHelper::route('auth', 'logout')]; $nav []= ['Log out', \Chibi\UrlHelper::route('auth', 'logout')];
} }
@ -62,6 +62,11 @@
echo '</li>'; echo '</li>';
} }
?> ?>
<li>
<form name="search" action="<?php echo \Chibi\UrlHelper::route('post', 'list') ?>" method="get">
<input type="search" name="query" placeholder="Search&hellip;" value="<?php echo isset($this->context->transport->searchQuery) ? $this->context->transport->searchQuery : '' ?>">
</form>
</i>
</ul> </ul>
<div class="clear"></div> <div class="clear"></div>
</div> </div>

View file

@ -1,6 +1,95 @@
<?php if (!empty($this->context->transport->errorMessage)): ?> <?php if (!empty($this->context->transport->errorMessage)): ?>
<p class="alert alert-error"><?php echo $this->context->transport->errorMessage ?></p> <p class="alert alert-error"><?php echo $this->context->transport->errorMessage ?></p>
<?php else: ?> <?php else: ?>
<div id="sidebar">
<nav>
<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="inactive">
<?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="inactive">
<?php endif ?>
<span>prev post</span>
<i class="icon-prev"></i>
</a>
</div>
<div class="clear"></div>
</nav>
<div class="details">
<h1>details</h1>
<div class="dl-box">
<a href="<?php echo \Chibi\UrlHelper::route('post', 'retrieve', ['name' => $this->context->transport->post->name]) ?>" alt="<?php echo $this->context->transport->post->name ?>">
<span class="permalink">
<i class="icon-dl"></i>
</span>
<span class="ext">
<?php echo substr($this->context->transport->post->orig_name, strrpos($this->context->transport->post->orig_name, '.') + 1) ?>
</span>
<span class="size">
<?php echo TextHelper::useBytesUnits($this->context->transport->post->size) ?>
</span>
</a>
</div>
<div class="details-box">
<div class="uploader">
<span class="key">Uploader:</span>
<span class="value">
<a href="<?php echo \Chibi\UrlHelper::route('user', 'view', ['id' => $this->context->transport->post->user->id]) ?>">
<?php echo $this->context->transport->post->user->name ?>
</a>
</span>
</div>
<div class="date">
<span class="key">Date:</span>
<span class="value"><?php echo date('Y-m-d H:i', $this->context->transport->post->upload_date) ?></span>
</div>
<div class="safety">
<span class="key">Safety:</span>
<span class="value"><?php echo PostSafety::toString($this->context->transport->post->safety) ?></span>
</div>
</div>
</div>
<div class="tags">
<h1>tags</h1>
<!-- todo: edit tags -->
<ul>
<?php foreach ($this->context->transport->post->sharedTag as $tag): ?>
<li>
<a href="<?php echo \Chibi\UrlHelper::route('post', 'list', ['query' => $tag->name]) ?>">
<?php echo $tag->name ?>
</a>
<span class="count">
<?php echo TextHelper::useDecimalUnits($this->context->transport->tagDistribution[$tag->name]) ?>
</span>
</li>
<?php endforeach ?>
</ul>
</div>
<!-- todo: favorites -->
<!-- todo: control -->
</div>
<div id="inner-content">
<div class="post-wrapper"> <div class="post-wrapper">
<?php if ($this->context->transport->post->type == PostType::Image): ?> <?php if ($this->context->transport->post->type == PostType::Image): ?>
<img src="<?php echo \Chibi\UrlHelper::route('post', 'retrieve', ['name' => $this->context->transport->post->name]) ?>" alt="<?php echo $this->context->transport->post->name ?>"/> <img src="<?php echo \Chibi\UrlHelper::route('post', 'retrieve', ['name' => $this->context->transport->post->name]) ?>" alt="<?php echo $this->context->transport->post->name ?>"/>
@ -8,4 +97,6 @@
<embed type="application/x-shockwave-flash" src="<?php echo \Chibi\UrlHelper::route('post', 'retrieve', ['name' => $this->context->transport->post->name]) ?>"/> <embed type="application/x-shockwave-flash" src="<?php echo \Chibi\UrlHelper::route('post', 'retrieve', ['name' => $this->context->transport->post->name]) ?>"/>
<?php endif ?> <?php endif ?>
</div> </div>
</div>
<?php endif ?> <?php endif ?>