r20150918

Signed-off-by: Flashwave <me@flash.moe>
This commit is contained in:
Pachira 2015-09-18 23:56:54 +02:00
parent 430e8ffa82
commit 062f672026
14 changed files with 254 additions and 161 deletions

View file

@ -2820,6 +2820,22 @@
"user": "Flashwave"
}
],
"20150918": [
"eminence",
{
"type": "UPD",
"change": "Changed report flag to an exclamation thing.",
"user": "Flashwave"
},
{
"type": "UPD",
"change": "Added more comments stuff.",
"user": "Flashwave"
}
]
}

View file

@ -7,9 +7,71 @@ namespace Sakura;
class Comments
{
public $comments = []; // Array containing comments
private $commenters = []; // Array containing User objects
public $category; // Comment category
public $count = 0; // Amount of comments
// Constructor
public function ___construct()
public function __construct($category)
{
//
// Set category
$this->category = $category;
// Get the comments and assign them to $comments
$comments = Database::fetch(
'comments',
true,
[
'comment_category' => [$this->category, '='],
'comment_reply_to' => ['0', '='],
],
['comment_id', true]
);
// Feed them into the sorter
$this->comments = $this->sortComments($comments);
}
// Sorting
public function sortComments($comments)
{
// Create storage array
$layer = [];
// Sort comments
foreach ($comments as $comment) {
// Check if we already have an object for this user
if (!array_key_exists($comment['comment_poster'], $this->commenters)) {
// Create new object
$this->commenters[$comment['comment_poster']] = new User($comment['comment_poster']);
}
// Attach the poster
$comment['comment_poster'] = $this->commenters[$comment['comment_poster']];
// Add post to posts array
$layer[$comment['comment_id']] = $comment;
// Up the comment count
$this->count += 1;
// Attempt to get replies from the database
$replies = Database::fetch('comments', true, [
'comment_category' => [$this->category, '='],
'comment_reply_to' => [$comment['comment_id'], '='],
]);
// Check if this was a reply to something
if ($replies) {
// Save the replies
$layer[$comment['comment_id']]['comment_replies'] = $this->sortComments($replies);
}
}
return $layer;
}
}

View file

@ -11,7 +11,7 @@ class News
private $posters = []; // Posters array (so we don't create a new user object every time)
// Initialise the news object
public function __construct($category, $comments = true)
public function __construct($category)
{
// Get the news posts and assign them to $posts
@ -31,9 +31,13 @@ class News
// Attach the poster
$post['poster'] = $this->posters[$post['uid']];
// Load comments
$post['comments'] = $this->comments = new Comments('news-' . $category . '-' . $post['id']);
// Add post to posts array
$this->posts[$post['id']] = $post;
}
}
// Get the amount of posts

View file

@ -12,7 +12,7 @@ class Session
public $sessionId;
// Initialise new session
public function ___construct()
public function __construct()
{
// Check if a PHP session was already started and if not start one

View file

@ -230,6 +230,24 @@ class Urls
'/manage/%s/%s',
],
// Comments urls
'COMMENT_POST' => [
'/settings.php?comment-action=true',
'/comments',
],
'COMMENT_LIKE' => [
'/settings.php?comment-action=true&id=%u&mode=like&session=%s',
'/comments?id=%u&mode=like&session=%s',
],
'COMMENT_DISLIKE' => [
'/settings.php?comment-action=true&id=%u&mode=dislike&session=%s',
'/comments?id=%u&mode=dislike&session=%s',
],
'COMMENT_DELETE' => [
'/settings.php?comment-action=true&id=%u&mode=delete&session=%s',
'/comments?id=%u&mode=delete&session=%s',
],
];
// Get a formatted url

View file

@ -8,7 +8,7 @@
namespace Sakura;
// Define Sakura version
define('SAKURA_VERSION', '20150916');
define('SAKURA_VERSION', '20150918');
define('SAKURA_VLABEL', 'Eminence');
define('SAKURA_COLOUR', '#6C3082');
define('SAKURA_STABLE', false);

View file

@ -0,0 +1,28 @@
<li id="comment-{{ comment.comment_id }}">
<div class="comment">
<a class="comment-avatar clean" href="{{ urls.format('USER_PROFILE', [comment.comment_poster.data.id]) }}" style="background-image: url('{{ urls.format('IMAGE_AVATAR', [comment.comment_poster.data.id]) }}');"><span style="color: {{ comment.comment_poster.colour }};">{{ comment.comment_poster.data.username }}</span></a>
<div class="comment-pointer"></div>
<div class="comment-content">
<div class="comment-controls">
<ul>
<li><a href="{{ urls.format('USER_REPORT', [comment.comment_poster.data.id]) }}" class="underline">Report</a></li>
<li><a href="{{ urls.format('COMMENT_DELETE', [comment.comment_id, php.sessionid])}}" class="underline">Delete</a></li>
<li><a href="javascript:void(0);" onclick="commentReply({{ comment.comment_id }});" class="underline">Reply</a></li>
<li class="shown voting like"><a href="{{ urls.format('COMMENT_LIKE', [comment.comment_id, php.sessionid])}}" class="clean"><span class="fa fa-thumbs-up"></span> {{ comment.comment_likes }}</a></li>
<li class="shown voting dislike"><a href="{{ urls.format('COMMENT_DISLIKE', [comment.comment_id, php.sessionid])}}" class="clean"><span class="fa fa-thumbs-down"></span> {{ comment.comment_dislikes }}</a></li>
</ul>
<div class="clear"></div>
</div>
<div class="comment-text">
{{ comment.comment_text|nl2br }}
</div>
</div>
</div>
{% if comment.comment_replies %}
<ul>
{% for comment in comment.comment_replies %}
{% include 'elements/comment.tpl' %}
{% endfor %}
</ul>
{% endif %}
</li>

View file

@ -1,10 +1,10 @@
<div class="comments">
<div id="comments">
<div class="comment-input-section">
{% if session.checkLogin %}
<form action="" method="post" id="commentsForm">
<input type="hidden" name="sessid" value="{{ php.sessionid }}" />
<input type="hidden" name="timestamp" value="{{ php.time }}" />
<input type="hidden" name="mode" value="comment" />
<form action="{{ urls.format('COMMENT_POST') }}" method="post" id="commentsForm">
<input type="hidden" name="session" value="{{ php.sessionid }}" />
<input type="hidden" name="category" value="" />
<input type="hidden" name="replyto" value="0" />
<div class="comment">
<div class="comment-avatar" style="background-image: url('{{ urls.format('IMAGE_AVATAR', [user.data.id]) }}');"></div>
<div class="comment-pointer"></div>
@ -18,133 +18,13 @@
</div>
<div class="comments-discussion">
<ul class="comments-list">
<li>
<div class="comment">
<div class="comment-avatar" style="background-image: url('{{ urls.format('IMAGE_AVATAR', [user.data.id]) }}');"></div>
<div class="comment-pointer"></div>
<div class="comment-content">
<div class="comment-controls">
<ul>
<li>Report</li>
<li>Delete</li>
<li>Reply</li>
<li class="shown"><span class="fa fa-plus-circle"></span> 1</li>
<li class="shown"><span class="fa fa-minus-circle"></span> 1</li>
</ul>
<div class="clear"></div>
</div>
<div class="comment-text">
aaaaaaaaaa
</div>
</div>
</div>
<ul>
<li>
<div class="comment">
<div class="comment-avatar" style="background-image: url('{{ urls.format('IMAGE_AVATAR', [1]) }}');"></div>
<div class="comment-pointer"></div>
<div class="comment-content">
<div class="comment-controls">
<ul>
<li>Report</li>
<li>Delete</li>
<li>Reply</li>
<li class="shown"><span class="fa fa-plus-circle"></span> 1</li>
<li class="shown"><span class="fa fa-minus-circle"></span> 1</li>
</ul>
</div>
<div class="comment-text">
aaaaaaaaaa
</div>
</div>
</div>
<ul>
<li>
<div class="comment">
<div class="comment-avatar" style="background-image: url('{{ urls.format('IMAGE_AVATAR', [user.data.id]) }}');"></div>
<div class="comment-pointer"></div>
<div class="comment-content">
<div class="comment-controls">
<ul>
<li>Report</li>
<li>Delete</li>
<li>Reply</li>
<li class="shown"><span class="fa fa-plus-circle"></span> 1</li>
<li class="shown"><span class="fa fa-minus-circle"></span> 1</li>
</ul>
</div>
<div class="comment-text">
aaaaaaaaaa
</div>
</div>
</div>
<ul>
<li>
<div class="comment">
<div class="comment-avatar" style="background-image: url('{{ urls.format('IMAGE_AVATAR', [3]) }}');"></div>
<div class="comment-pointer"></div>
<div class="comment-content">
<div class="comment-controls">
<ul>
<li>Report</li>
<li>Delete</li>
<li>Reply</li>
<li class="shown"><span class="fa fa-plus-circle"></span> 1</li>
<li class="shown"><span class="fa fa-minus-circle"></span> 1</li>
</ul>
</div>
<div class="comment-text">
aaaaaaaaaa
</div>
</div>
</div>
</li>
</ul>
</li>
<li>
<div class="comment">
<div class="comment-avatar" style="background-image: url('{{ urls.format('IMAGE_AVATAR', [1]) }}');"></div>
<div class="comment-pointer"></div>
<div class="comment-content">
<div class="comment-controls">
<ul>
<li>Report</li>
<li>Delete</li>
<li>Reply</li>
<li class="shown"><span class="fa fa-plus-circle"></span> 1</li>
<li class="shown"><span class="fa fa-minus-circle"></span> 1</li>
</ul>
</div>
<div class="comment-text">
aaaaaaaaaa
</div>
</div>
</div>
</li>
</ul>
</li>
<li>
<div class="comment">
<div class="comment-avatar" style="background-image: url('{{ urls.format('IMAGE_AVATAR', [2]) }}');"></div>
<div class="comment-pointer"></div>
<div class="comment-content">
<div class="comment-controls">
<ul>
<li>Report</li>
<li>Delete</li>
<li>Reply</li>
<li class="shown"><span class="fa fa-plus-circle"></span> 1</li>
<li class="shown"><span class="fa fa-minus-circle"></span> 1</li>
</ul>
</div>
<div class="comment-text">
aaaaaaaaaa
</div>
</div>
</div>
</li>
</ul>
</li>
{% if post.comments.comments %}
{% for comment in post.comments.comments %}
{% include 'elements/comment.tpl' %}
{% endfor %}
{% else %}
<h1 class="stylised" style="text-align: center; padding: 10px 0">There are no comments yet!</h1>
{% endif %}
</ul>
</div>
</div>

View file

@ -12,5 +12,5 @@
</div>
<div class="clear"></div>
<div class="news-post-time">
Posted on {{ post.date|date(sakura.dateFormat) }}{% if not (viewPost and postExists) %} <a class="default" href="{{ urls.format('SITE_NEWS_POST', [post.id]) }}">X comments</a>{% endif %}
Posted on {{ post.date|date(sakura.dateFormat) }}{% if not (viewPost and postExists) %} <a class="default" href="{{ urls.format('SITE_NEWS_POST', [post.id]) }}#comments">{{ post.comments.count }} comment{% if post.comments.count != 1 %}s{% endif %}</a>{% endif %}
</div>

View file

@ -25,6 +25,9 @@
{% if (viewPost ? postExists : newsPosts|length) %}
{% for post in newsPosts %}
{% include 'elements/newsPost.tpl' %}
{% if viewPost and postExists %}
{% include 'elements/comments.tpl' %}
{% endif %}
{% endfor %}
{% if not (viewPost and postExists) and news.getPosts(postsPerPage)|length > 1 %}
<div>
@ -32,9 +35,6 @@
<div class="clear"></div>
</div>
{% endif %}
{% if viewPost and postExists %}
{% include 'elements/comments.tpl' %}
{% endif %}
{% else %}
<div style="padding: 20px;">
<h1>The requested news post does not exist!</h1>

View file

@ -32,7 +32,7 @@
{% else %}
{% if profile.checkFriends(user.data.id) != 0 %}<a class="fa fa-{% if profile.checkFriends(user.data.id) == 2 %}heart{% else %}star{% endif %}" title="You are friends"></a>{% endif %}
<a class="fa fa-user-{% if profile.checkFriends(user.data.id) == 0 %}plus{% else %}times{% endif %}" title="{% if profile.checkFriends(user.data.id) == 0 %}Add {{ legacyprofile.data.username }} as a friend{% else %}Remove friend{% endif %}" href="{% if profile.checkFriends(user.data.id) == 0 %}{{ urls.format('FRIEND_ADD', [profile.data.id, php.sessionid, php.time, sakura.currentPage]) }}{% else %}{{ urls.format('FRIEND_REMOVE', [profile.data.id, php.sessionid, php.time, sakura.currentPage]) }}{% endif %}" id="profileFriendToggle"></a>
<a class="fa fa-flag" title="Report {{ profile.data.username }}" href="{{ urls.format('USER_REPORT', [profile.data.id]) }}"></a>
<a class="fa fa-exclamation-circle" title="Report {{ profile.data.username }}" href="{{ urls.format('USER_REPORT', [profile.data.id]) }}"></a>
{% endif %}
</div>
{% endif %}

View file

@ -42,6 +42,7 @@ RewriteRule ^settings/([a-z]+)/([a-z]+)/?$ settings.php?cat=$1&mode=$2 [L,QSA]
RewriteRule ^settings/([a-z]+)/([a-z]+)/p([0-9]+)/?$ settings.php?cat=$1&mode=$2&page=$3 [L,QSA]
RewriteRule ^friends/?$ settings.php?friend-action=true [L,QSA]
RewriteRule ^notifications/?$ settings.php?request-notifications=true [L,QSA]
RewriteRule ^comments/?$ settings.php?comment-action=true [L,QSA]
# Members
RewriteRule ^members/?$ members.php [L,QSA]

View file

@ -2098,21 +2098,18 @@ textarea.inputStyling {
/*
* Comments
*/
.comments {
}
.comments .comment-input-section {
#comments .comment-input-section {
border-top: 1px solid #9475B2;
border-bottom: 1px solid #9475B2;
}
.comments .comment {
#comments .comment {
display: flex;
align-items: stretch;
margin: 3px 0;
}
.comments .comment > .comment-avatar {
#comments .comment > .comment-avatar {
height: 60px;
width: 60px;
background: rgba(0, 0, 0, .2) url("/content/pixel.png") no-repeat scroll left center / contain;
@ -2120,9 +2117,26 @@ textarea.inputStyling {
margin-right: 2px;
border-radius: 4px;
border: 0;
display: block;
text-align: center;
word-wrap: break-word;
transition: .2s;
}
.comments .comment > .comment-pointer {
#comments .comment > .comment-avatar:hover {
background-color: transparent;
}
#comments .comment > .comment-avatar > span {
opacity: 0;
transition: .2s;
}
#comments .comment > .comment-avatar:hover > span {
opacity: 1;
}
#comments .comment > .comment-pointer {
width: 0px;
height: 0px;
border-style: solid;
@ -2131,7 +2145,7 @@ textarea.inputStyling {
margin-top: 10px;
}
.comments .comment > .comment-content {
#comments .comment > .comment-content {
border-radius: 5px;
border: 0;
min-height: 50px;
@ -2142,23 +2156,35 @@ textarea.inputStyling {
background: #F6F6F6;
}
.comments .comment > .comment-content > .comment-controls {
#comments .comment > .comment-content > .comment-controls {
float: right;
}
.comments .comment > .comment-content > .comment-controls > ul > li {
#comments .comment > .comment-content > .comment-controls > ul > li {
float: left;
margin: 0 5px;
opacity: 0;
transition: .5s;
}
.comments .comment > .comment-content:hover > .comment-controls > ul > li,
.comments .comment > .comment-content > .comment-controls > ul > li.shown {
#comments .comment > .comment-content:hover > .comment-controls > ul > li,
#comments .comment > .comment-content > .comment-controls > ul > li.shown {
opacity: 1;
}
.comments .comment > .comment-submit {
#comments .comment > .comment-content > .comment-controls > ul > li.voting {
font-size: 1.5em;
}
#comments .comment > .comment-content > .comment-controls > ul > li.like {
color: #0A0;
}
#comments .comment > .comment-content > .comment-controls > ul > li.dislike {
color: #C00;
}
#comments .comment > .comment-submit {
flex-shrink: 0;
font-family: FontAwesome;
height: 60px;
@ -2172,28 +2198,30 @@ textarea.inputStyling {
cursor: pointer;
}
.comments .comment > .comment-submit:hover {
#comments .comment > .comment-submit:hover {
background: linear-gradient(0deg, #9475B2 30%, #C2AFFE 70%);
}
.comments .comment > .comment-submit:active {
#comments .comment > .comment-submit:active {
background: linear-gradient(180deg, #9475B2 30%, #C2AFFE 70%);
}
.comments ul {
#comments ul {
list-style: none;
}
.comments ul > li > ul {
#comments ul > li > ul {
margin-left: 40px;
}
.comments ul > li > ul .comment > .comment-avatar {
#comments ul > li > ul .comment > .comment-avatar {
height: 50px;
width: 50px;
font-size: .9em;
line-height: 1.1em;
}
.comments ul > li > ul .comment > .comment-content {
#comments ul > li > ul .comment > .comment-content {
min-height: 40px;
height: 40px;
}

View file

@ -47,6 +47,62 @@ if (isset($_REQUEST['request-notifications']) && $_REQUEST['request-notification
// Set header, convert the array to json, print it and exit
print json_encode($notifications);
exit;
} elseif (isset($_REQUEST['comment-action']) && $_REQUEST['comment-action'] && Users::checkLogin()) {
// Referrer
$redirect = (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : $urls->format('SITE_INDEX'));
// Continue
$continue = true;
// Match session ids for the same reason
if (!isset($_REQUEST['session']) || $_REQUEST['session'] != session_id()) {
$renderData['page'] = [
'redirect' => $redirect,
'message' => 'Invalid session, please try again.',
'success' => 0,
];
// Prevent
$continue = false;
}
// Select the right action
if ($continue) {
switch (isset($_REQUEST['mode']) ? $_REQUEST['mode'] : false) {
case 'like':
break;
case 'dislike':
break;
case 'delete':
break;
default:
$renderData['page'] = [
'redirect' => $redirect,
'message' => 'Did nothing.',
'success' => 0,
];
}
}
// Print page contents or if the AJAX request is set only display the render data
print isset($_REQUEST['ajax']) ?
(
$renderData['page']['message'] . '|' .
$renderData['page']['success'] . '|' .
$renderData['page']['redirect']
) :
Templates::render('global/information.tpl', $renderData);
exit;
} elseif (isset($_REQUEST['friend-action']) && $_REQUEST['friend-action'] && Users::checkLogin()) {
// Friends
// Continue