Closed #30
This commit is contained in:
parent
315c5d074e
commit
91776a3e54
9 changed files with 247 additions and 7 deletions
|
@ -8,6 +8,7 @@ filesPath=./files/
|
||||||
thumbsPath=./thumbs/
|
thumbsPath=./thumbs/
|
||||||
mediaPath=./public_html/media/
|
mediaPath=./public_html/media/
|
||||||
title=szurubooru
|
title=szurubooru
|
||||||
|
featuredPostMaxDays=7
|
||||||
debugQueries=0
|
debugQueries=0
|
||||||
|
|
||||||
[browsing]
|
[browsing]
|
||||||
|
@ -68,6 +69,7 @@ hidePost.own=moderator
|
||||||
hidePost.all=moderator
|
hidePost.all=moderator
|
||||||
deletePost.own=moderator
|
deletePost.own=moderator
|
||||||
deletePost.all=moderator
|
deletePost.all=moderator
|
||||||
|
featurePost=moderator
|
||||||
|
|
||||||
listUsers=registered
|
listUsers=registered
|
||||||
viewUser=registered
|
viewUser=registered
|
||||||
|
|
|
@ -38,7 +38,7 @@ body {
|
||||||
|
|
||||||
|
|
||||||
#top-nav ul.main-nav {
|
#top-nav ul.main-nav {
|
||||||
margin: 0 -0.75em;
|
margin: 0 0 0 -0.75em;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
list-style-type: none;
|
list-style-type: none;
|
||||||
}
|
}
|
||||||
|
@ -68,17 +68,22 @@ body {
|
||||||
#top-nav li.search {
|
#top-nav li.search {
|
||||||
float: right;
|
float: right;
|
||||||
background: white;
|
background: white;
|
||||||
margin: 0;
|
margin: 5px 0;
|
||||||
padding: 0 5px;
|
padding: 0;
|
||||||
line-height: 38px;
|
line-height: 20px;
|
||||||
}
|
}
|
||||||
#top-nav li.search input {
|
#top-nav li.search input {
|
||||||
border: 0;
|
border: 0;
|
||||||
padding: 5px;
|
height: 20px;
|
||||||
|
line-height: 20px;
|
||||||
|
padding: 4px 10px;
|
||||||
|
margin: 0;
|
||||||
|
box-sizing: content-box;
|
||||||
}
|
}
|
||||||
|
|
||||||
#top-nav li.safety {
|
#top-nav li.safety {
|
||||||
float: right;
|
float: right;
|
||||||
|
margin-left: 5px;
|
||||||
}
|
}
|
||||||
#top-nav li.safety ul {
|
#top-nav li.safety ul {
|
||||||
list-style-type: none;
|
list-style-type: none;
|
||||||
|
@ -121,6 +126,10 @@ footer {
|
||||||
font-size: small;
|
font-size: small;
|
||||||
color: silver;
|
color: silver;
|
||||||
}
|
}
|
||||||
|
footer span:not(:last-child):after {
|
||||||
|
content: '\022C5';
|
||||||
|
margin: 0 0.2em;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
82
public_html/media/css/index-index.css
Normal file
82
public_html/media/css/index-index.css
Normal file
|
@ -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%;
|
||||||
|
}
|
||||||
|
}
|
|
@ -8,6 +8,40 @@ class IndexController
|
||||||
public function indexAction()
|
public function indexAction()
|
||||||
{
|
{
|
||||||
$this->context->subTitle = 'home';
|
$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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -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.
|
* Action that decorates the page containing the post.
|
||||||
* @route /post/{id}
|
* @route /post/{id}
|
||||||
|
|
37
src/Models/Model_Property.php
Normal file
37
src/Models/Model_Property.php
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
<?php
|
||||||
|
class Model_Property extends RedBean_SimpleModel
|
||||||
|
{
|
||||||
|
const FeaturedPostId = 0;
|
||||||
|
const FeaturedPostUserId = 1;
|
||||||
|
const FeaturedPostDate = 2;
|
||||||
|
|
||||||
|
static $allProperties = null;
|
||||||
|
|
||||||
|
public static function get($propertyId)
|
||||||
|
{
|
||||||
|
if (self::$allProperties === null)
|
||||||
|
{
|
||||||
|
self::$allProperties = [];
|
||||||
|
foreach (R::find('property') as $prop)
|
||||||
|
{
|
||||||
|
self::$allProperties[$prop->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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -11,6 +11,7 @@ class Privilege extends Enum
|
||||||
const EditPostThumb = 8;
|
const EditPostThumb = 8;
|
||||||
const HidePost = 9;
|
const HidePost = 9;
|
||||||
const DeletePost = 10;
|
const DeletePost = 10;
|
||||||
|
const FeaturePost = 25;
|
||||||
|
|
||||||
const ListUsers = 11;
|
const ListUsers = 11;
|
||||||
const ViewUser = 12;
|
const ViewUser = 12;
|
||||||
|
|
|
@ -1 +1,53 @@
|
||||||
Todo: index
|
<div id="sidebar">
|
||||||
|
<h1><?php echo $this->config->main->title ?></h1>
|
||||||
|
|
||||||
|
<form name="search" action="<?php echo \Chibi\UrlHelper::route('post', 'list') ?>" method="get">
|
||||||
|
<input type="search" name="query" placeholder="Search…" value="<?php echo isset($this->context->transport->searchQuery) ? htmlspecialchars($this->context->transport->searchQuery) : '' ?>">
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<span>serving <?php echo $this->context->transport->postCount ?> posts</span>
|
||||||
|
<span>powered by <a href="http://github.com/rr-/booru">szurubooru</a></span>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<?php if (!empty($this->context->featuredPost)): ?>
|
||||||
|
<div id="featured-post">
|
||||||
|
<div class="header">
|
||||||
|
Featured image
|
||||||
|
|
||||||
|
<ul class="tags">
|
||||||
|
<?php foreach ($this->context->featuredPost->sharedTag as $tag): ?>
|
||||||
|
<li>
|
||||||
|
<a href="<?php echo \Chibi\UrlHelper::route('post', 'list', ['query' => $tag->name]) ?>">
|
||||||
|
<?php echo $tag->name ?>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<?php endforeach ?>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<span class="favs-comments">
|
||||||
|
<?php printf('%d fav%s', $x = $this->context->featuredPost->countOwn('favoritee'), $x == 1 ? '' : 's') ?>, 
|
||||||
|
<?php printf('%d comment%s', $x = $this->context->featuredPost->countOwn('comment'), $x == 1 ? '' : 's') ?>
|
||||||
|
</span>
|
||||||
|
<div class="clear"></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="body">
|
||||||
|
<a href="<?php echo \Chibi\UrlHelper::route('post', 'view', ['id' => $this->context->featuredPost->id]) ?>">
|
||||||
|
<img src="<?php echo \Chibi\UrlHelper::route('post', 'retrieve', ['name' => $this->context->featuredPost->name]) ?>" alt="<?php echo $this->context->featuredPost->name ?>"/>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="footer">
|
||||||
|
Featured 
|
||||||
|
<?php if ($this->context->featuredPostUser): ?>
|
||||||
|
by <a href="<?php echo \Chibi\UrlHelper::route('user', 'view', ['name' => $this->context->featuredPostUser->name]) ?>"><?php echo $this->context->featuredPostUser->name ?></a>, 
|
||||||
|
<?php endif ?>
|
||||||
|
<?php printf('%d day%s', $x = round((time() - $this->context->featuredPostDate) / (24 * 3600.)), $x == 1 ? '' : 's') ?> ago
|
||||||
|
<div class="clear"></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="clear"></div>
|
||||||
|
</div>
|
||||||
|
<?php endif ?>
|
||||||
|
|
|
@ -174,9 +174,17 @@
|
||||||
<?php endif ?>
|
<?php endif ?>
|
||||||
<?php endif ?>
|
<?php endif ?>
|
||||||
|
|
||||||
|
<?php if (PrivilegesHelper::confirm(Privilege::FeaturePost)): ?>
|
||||||
|
<li class="feature">
|
||||||
|
<a class="simple-action" href="<?php echo \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="<?php echo \Chibi\UrlHelper::route('index', 'index') ?>">
|
||||||
|
Feature on main page
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<?php endif ?>
|
||||||
|
|
||||||
<?php if (PrivilegesHelper::confirm(Privilege::DeletePost, PrivilegesHelper::getIdentitySubPrivilege($this->context->transport->post->uploader))): ?>
|
<?php if (PrivilegesHelper::confirm(Privilege::DeletePost, PrivilegesHelper::getIdentitySubPrivilege($this->context->transport->post->uploader))): ?>
|
||||||
<li class="delete">
|
<li class="delete">
|
||||||
<a class="simple-action" href="<?php echo \Chibi\UrlHelper::route('post', 'delete', ['id' => $this->context->transport->post->id]) ?>" data-confirm-text="Are you sure?" data-redirect-url="<?php echo \Chibi\UrlHelper::route('post', 'list') ?>">
|
<a class="simple-action" href="<?php echo \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="<?php echo \Chibi\UrlHelper::route('post', 'list') ?>">
|
||||||
Delete
|
Delete
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
|
|
Loading…
Reference in a new issue