From 91776a3e54be322db6e90a308fc96f4327371e51 Mon Sep 17 00:00:00 2001 From: Marcin Kurczewski Date: Sat, 19 Oct 2013 13:38:20 +0200 Subject: [PATCH] Closed #30 --- config.ini | 2 + public_html/media/css/core.css | 19 +++++-- public_html/media/css/index-index.css | 82 +++++++++++++++++++++++++++ src/Controllers/IndexController.php | 34 +++++++++++ src/Controllers/PostController.php | 15 +++++ src/Models/Model_Property.php | 37 ++++++++++++ src/Models/Privilege.php | 1 + src/Views/index-index.phtml | 54 +++++++++++++++++- src/Views/post-view.phtml | 10 +++- 9 files changed, 247 insertions(+), 7 deletions(-) create mode 100644 public_html/media/css/index-index.css create mode 100644 src/Models/Model_Property.php diff --git a/config.ini b/config.ini index 1e60dafc..a1c5ba91 100644 --- a/config.ini +++ b/config.ini @@ -8,6 +8,7 @@ filesPath=./files/ thumbsPath=./thumbs/ mediaPath=./public_html/media/ title=szurubooru +featuredPostMaxDays=7 debugQueries=0 [browsing] @@ -68,6 +69,7 @@ hidePost.own=moderator hidePost.all=moderator deletePost.own=moderator deletePost.all=moderator +featurePost=moderator listUsers=registered viewUser=registered diff --git a/public_html/media/css/core.css b/public_html/media/css/core.css index 5881c4ca..5a9b0de9 100644 --- a/public_html/media/css/core.css +++ b/public_html/media/css/core.css @@ -38,7 +38,7 @@ body { #top-nav ul.main-nav { - margin: 0 -0.75em; + margin: 0 0 0 -0.75em; padding: 0; list-style-type: none; } @@ -68,17 +68,22 @@ body { #top-nav li.search { float: right; background: white; - margin: 0; - padding: 0 5px; - line-height: 38px; + margin: 5px 0; + padding: 0; + line-height: 20px; } #top-nav li.search input { border: 0; - padding: 5px; + height: 20px; + line-height: 20px; + padding: 4px 10px; + margin: 0; + box-sizing: content-box; } #top-nav li.safety { float: right; + margin-left: 5px; } #top-nav li.safety ul { list-style-type: none; @@ -121,6 +126,10 @@ footer { font-size: small; color: silver; } +footer span:not(:last-child):after { + content: '\022C5'; + margin: 0 0.2em; +} diff --git a/public_html/media/css/index-index.css b/public_html/media/css/index-index.css new file mode 100644 index 00000000..5b633970 --- /dev/null +++ b/public_html/media/css/index-index.css @@ -0,0 +1,82 @@ +#sidebar { + min-width: 100px; + padding: 5em 0; + width: 25%; + margin-right: 5%; + text-align: center; +} +#sidebar p { + font-size: small; +} +#sidebar p span:not(:last-child):after { + content: '\022C5'; + margin: 0 0.5em; +} + +#sidebar h1 { + font-size: 26pt; +} +#sidebar input { + width: 100%; + max-width: 300px; + border: 2px solid #ccc; + padding: 5px; +} + +#featured-post { + float: right; + width: 70%; + position: relative; +} + +#featured-post .header .tags:before { + margin: 0 0.5em; + content: '\2013'; +} +#featured-post .header ul { + list-style-type: none; + display: inline; + margin: 0; + padding: 0; +} +#featured-post .header li { + display: inline; +} +#featured-post .header li:not(:last-child) a:after { + content: ', '; +} + +#featured-post .body { + background: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAYAAAAGCAYAAADgzO9IAAAAJElEQVQImWNgYGBgePfu3X8YZoABFA6SIqwS+HXgtANZF7IEAJnGPJE70lLLAAAAAElFTkSuQmCC'); + margin: 1em 0; + text-align: center; +} +#featured-post .body img { + max-width: 100%; + margin: 0 auto; + display: block; +} +#featured-post .body a { + display: block; +} + +#featured-post .header .favs-comments { + margin-left: 0.5em; + float: right; +} + +#featured-post .footer { + text-align: right; +} + +@media (max-width: 600px) { + #sidebar { + float: none; + width: 100%; + padding: 0 0 1em 0; + } + #featured-post { + float: none; + width: 100%; + } +} diff --git a/src/Controllers/IndexController.php b/src/Controllers/IndexController.php index 7592fdb4..b8d734d8 100644 --- a/src/Controllers/IndexController.php +++ b/src/Controllers/IndexController.php @@ -8,6 +8,40 @@ class IndexController public function indexAction() { $this->context->subTitle = 'home'; + $this->context->stylesheets []= 'index-index.css'; + $this->context->transport->postCount = R::$f->begin()->select('count(1)')->as('count')->from('post')->get('row')['count']; + + $featuredPostRotationTime = $this->config->main->featuredPostMaxDays * 24 * 3600; + + $featuredPostId = Model_Property::get(Model_Property::FeaturedPostId); + $featuredPostUserId = Model_Property::get(Model_Property::FeaturedPostUserId); + $featuredPostDate = Model_Property::get(Model_Property::FeaturedPostDate); + if (!$featuredPostId or $featuredPostDate + $featuredPostRotationTime < time()) + { + $featuredPostId = R::$f->begin() + ->select('id') + ->from('post') + ->where('type = ?')->put(PostType::Image) + ->and('safety = ?')->put(PostSafety::Safe) + ->orderBy('random()') + ->desc() + ->get('row')['id']; + $featuredPostUserId = null; + $featuredPostDate = time(); + Model_Property::set(Model_Property::FeaturedPostId, $featuredPostId); + Model_Property::set(Model_Property::FeaturedPostUserId, $featuredPostUserId); + Model_Property::set(Model_Property::FeaturedPostDate, $featuredPostDate); + } + + if ($featuredPostId !== null) + { + $featuredPost = Model_Post::locate($featuredPostId); + R::preload($featuredPost, ['user', 'comment', 'favoritee']); + $featuredPostUser = R::findOne('user', 'id = ?', [$featuredPostUserId]); + $this->context->featuredPost = $featuredPost; + $this->context->featuredPostUser = $featuredPostUser; + $this->context->featuredPostDate = $featuredPostDate; + } } /** diff --git a/src/Controllers/PostController.php b/src/Controllers/PostController.php index 8a9bac75..a44686e1 100644 --- a/src/Controllers/PostController.php +++ b/src/Controllers/PostController.php @@ -396,6 +396,21 @@ class PostController + /** + * @route /post/{id}/feature + */ + public function featureAction($id) + { + $post = Model_Post::locate($id); + PrivilegesHelper::confirmWithException(Privilege::FeaturePost); + Model_Property::set(Model_Property::FeaturedPostId, $post->id); + Model_Property::set(Model_Property::FeaturedPostUserId, $this->context->user->id); + Model_Property::set(Model_Property::FeaturedPostDate, time()); + $this->context->transport->success = true; + } + + + /** * Action that decorates the page containing the post. * @route /post/{id} diff --git a/src/Models/Model_Property.php b/src/Models/Model_Property.php new file mode 100644 index 00000000..3ee9b97e --- /dev/null +++ b/src/Models/Model_Property.php @@ -0,0 +1,37 @@ +prop_id] = $prop->value; + } + } + return isset(self::$allProperties[$propertyId]) + ? self::$allProperties[$propertyId] + : null; + } + + public static function set($propertyId, $value) + { + $row = R::findOne('property', 'prop_id = ?', [$propertyId]); + if (!$row) + { + $row = R::dispense('property'); + $row->prop_id = $propertyId; + } + $row->value = $value; + self::$allProperties[$propertyId] = $value; + R::store($row); + } +} diff --git a/src/Models/Privilege.php b/src/Models/Privilege.php index 535bf1db..02ab75f9 100644 --- a/src/Models/Privilege.php +++ b/src/Models/Privilege.php @@ -11,6 +11,7 @@ class Privilege extends Enum const EditPostThumb = 8; const HidePost = 9; const DeletePost = 10; + const FeaturePost = 25; const ListUsers = 11; const ViewUser = 12; diff --git a/src/Views/index-index.phtml b/src/Views/index-index.phtml index 90be513a..9cc2b1b4 100644 --- a/src/Views/index-index.phtml +++ b/src/Views/index-index.phtml @@ -1 +1,53 @@ -Todo: index + + +context->featuredPost)): ?> +
+
+ Featured image + +
    + context->featuredPost->sharedTag as $tag): ?> +
  • + + name ?> + +
  • + +
+ + + context->featuredPost->countOwn('favoritee'), $x == 1 ? '' : 's') ?>, + context->featuredPost->countOwn('comment'), $x == 1 ? '' : 's') ?> + +
+
+ +
+ + <?php echo $this->context->featuredPost->name ?> + +
+ + + +
+
+ diff --git a/src/Views/post-view.phtml b/src/Views/post-view.phtml index 96c7aa4f..f04c866a 100644 --- a/src/Views/post-view.phtml +++ b/src/Views/post-view.phtml @@ -174,9 +174,17 @@ + +
  • + + Feature on main page + +
  • + + context->transport->post->uploader))): ?>
  • - + Delete