From b92f925e94f3fd4c1ec1f69cae54ad6cf15b8240 Mon Sep 17 00:00:00 2001 From: Marcin Kurczewski Date: Sat, 12 Oct 2013 10:46:15 +0200 Subject: [PATCH] Post viewing - sidebar --- public_html/media/css/core.css | 24 ++++++- public_html/media/css/post-view.css | 66 +++++++++++++++++- public_html/media/img/icons.png | Bin 0 -> 322 bytes src/Controllers/PostController.php | 23 ++++++- src/Controllers/UserController.php | 2 +- src/Helpers/TextHelper.php | 26 +++++++ src/Views/layout-normal.phtml | 7 +- src/Views/post-view.phtml | 103 ++++++++++++++++++++++++++-- 8 files changed, 240 insertions(+), 11 deletions(-) create mode 100644 public_html/media/img/icons.png diff --git a/public_html/media/css/core.css b/public_html/media/css/core.css index df7b8079..55c59c6d 100644 --- a/public_html/media/css/core.css +++ b/public_html/media/css/core.css @@ -100,7 +100,6 @@ body { #sidebar h1 { margin-top: 0; - text-align: center; font-weight: normal; } @@ -112,3 +111,26 @@ p:first-child, h1:first-child { 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; +} diff --git a/public_html/media/css/post-view.css b/public_html/media/css/post-view.css index 1d590f39..fcd05019 100644 --- a/public_html/media/css/post-view.css +++ b/public_html/media/css/post-view.css @@ -1,5 +1,5 @@ .post-wrapper { - text-align: center; + /*text-align: center;*/ } embed { @@ -10,3 +10,67 @@ embed { img { 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; +} diff --git a/public_html/media/img/icons.png b/public_html/media/img/icons.png new file mode 100644 index 0000000000000000000000000000000000000000..3490c265ee11f189c7a42808327eddffaabc0130 GIT binary patch literal 322 zcmV-I0lof-P)tV1XY zU1~X&SVvG4y3}wisSY4JbgAK3QY|MtbSZT#xfYWZx|BMW+$bg1lLjP|{SMd+V4`FF zvmZG?@HiCYsr7_vFnT0|^FSE)(dVVk#UGuRxcK)EP6o8-rNq_&K zu5O_q0EiQaF79aAkRhcEB}P9@n~3ysEL9rc)b1cKkdc9iPOH>*EaOn>FaiV^0Itw4 Ua6dVGx&QzG07*qoM6N<$g8K=45C8xG literal 0 HcmV?d00001 diff --git a/src/Controllers/PostController.php b/src/Controllers/PostController.php index 0ac44dbb..b86c183e 100644 --- a/src/Controllers/PostController.php +++ b/src/Controllers/PostController.php @@ -68,7 +68,7 @@ class PostController $searchDbQuery = R::$f->begin(); $searchDbQuery->select('*'); $buildDbQuery($searchDbQuery); - $searchDbQuery->orderBy('upload_date DESC'); + $searchDbQuery->orderBy('id DESC'); $searchDbQuery->limit('?')->put($postsPerPage); $searchDbQuery->offset('?')->put(($page - 1) * $postsPerPage); @@ -205,13 +205,34 @@ class PostController $post = R::findOne('post', 'id = ?', [$id]); if (!$post) 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, 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->subTitle = 'showing @' . $post->id; $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; } diff --git a/src/Controllers/UserController.php b/src/Controllers/UserController.php index 1d65c0aa..98752a2d 100644 --- a/src/Controllers/UserController.php +++ b/src/Controllers/UserController.php @@ -14,7 +14,7 @@ class UserController * @route /user/{name} * @validate name [^\/]+ */ - public function showAction($name) + public function viewAction($name) { $this->context->subTitle = $name; throw new Exception('Not implemented'); diff --git a/src/Helpers/TextHelper.php b/src/Helpers/TextHelper.php index f8915a8b..c3e61120 100644 --- a/src/Helpers/TextHelper.php +++ b/src/Helpers/TextHelper.php @@ -50,4 +50,30 @@ class TextHelper } 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']); + } } diff --git a/src/Views/layout-normal.phtml b/src/Views/layout-normal.phtml index 4d2c4569..6e99f616 100644 --- a/src/Views/layout-normal.phtml +++ b/src/Views/layout-normal.phtml @@ -48,7 +48,7 @@ } 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')]; } @@ -62,6 +62,11 @@ echo ''; } ?> +
  • +
    + +
    +
    diff --git a/src/Views/post-view.phtml b/src/Views/post-view.phtml index 7e525f56..44339a8b 100644 --- a/src/Views/post-view.phtml +++ b/src/Views/post-view.phtml @@ -1,11 +1,102 @@ context->transport->errorMessage)): ?>

    context->transport->errorMessage ?>

    -
    - context->transport->post->type == PostType::Image): ?> - <?php echo $this->context->transport->post->name ?> - context->transport->post->type == PostType::Flash): ?> - - + + + +
    +
    + context->transport->post->type == PostType::Image): ?> + <?php echo $this->context->transport->post->name ?> + context->transport->post->type == PostType::Flash): ?> + + +
    +
    +