r20151006

Signed-off-by: Flashwave <me@flash.moe>
This commit is contained in:
flash 2015-10-06 21:51:07 +02:00
parent 3937f188ee
commit e2f42874de
9 changed files with 190 additions and 31 deletions

View file

@ -3005,7 +3005,7 @@
],
"20151003": [
"20151004": [
"eminence",
{
@ -3014,6 +3014,17 @@
"user": "Flashwave"
}
],
"20151006": [
"eminence",
{
"type": "ADD",
"change": "Added comment posting.",
"user": "Flashwave"
}
]
}

View file

@ -74,4 +74,32 @@ class Comments
return $layer;
}
// Sorting
public function makeComment($uid, $reply, $content)
{
// Check if the comment is long enough
if (strlen($content) < Configuration::getConfig('comment_min_length')) {
return [0, 'TOO_SHORT'];
}
// Check if the comment isn't too long
if (strlen($content) > Configuration::getConfig('comment_max_length')) {
return [0, 'TOO_LONG'];
}
// Insert into database
Database::insert('comments', [
'comment_category' => $this->category,
'comment_timestamp' => time(),
'comment_poster' => $uid,
'comment_reply_to' => (int) $reply,
'comment_text' => $content,
]);
// Return success
return [1, 'SUCCESS'];
}
}

View file

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

View file

@ -7,7 +7,7 @@
<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><a href="javascript:void(0);" onclick="commentReply({{ comment.comment_id }}, '{{ php.sessionid }}', '{{ comment.comment_category }}', '{{ urls.format('COMMENT_POST') }}', '{{ urls.format('IMAGE_AVATAR', [user.data.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>
@ -18,11 +18,9 @@
</div>
</div>
</div>
{% if comment.comment_replies %}
<ul>
{% for comment in comment.comment_replies %}
{% include 'elements/comment.tpl' %}
{% endfor %}
</ul>
{% endif %}
</li>

View file

@ -3,13 +3,14 @@
{% if session.checkLogin %}
<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="category" value="{{ commentsCategory }}" />
<input type="hidden" name="replyto" value="0" />
<input type="hidden" name="mode" value="comment" />
<div class="comment">
<div class="comment-avatar" style="background-image: url('{{ urls.format('IMAGE_AVATAR', [user.data.id]) }}');"></div>
<div class="comment-pointer"></div>
<textarea class="comment-content" class="comment" placeholder="Join the conversation..."></textarea>
<input class="comment-submit" name="submit" type="submit" value="&#xf1d8;" />
<textarea class="comment-content" name="comment" placeholder="Join the conversation..."></textarea>
<input class="comment-submit new" name="submit" type="submit" value="&#xf1d8;" />
</div>
</form>
{% else %}
@ -18,8 +19,8 @@
</div>
<div class="comments-discussion">
<ul class="comments-list">
{% if post.comments.comments %}
{% for comment in post.comments.comments %}
{% if comments %}
{% for comment in comments %}
{% include 'elements/comment.tpl' %}
{% endfor %}
{% else %}
@ -30,8 +31,6 @@
</div>
<script type="text/javascript">
window.addEventListener("load", function() {
prepareAjaxForm('commentsForm', 'Posting comment...');
});
</script>

View file

@ -4,6 +4,11 @@
{% set pagination = {'page': currentPage, 'pages': news.getPosts(postsPerPage), 'urlPattern': 'SITE_NEWS_PAGE'} %}
{% if viewPost and postExists %}
{% set commentsCategory = 'news-' ~ newsPosts[0].category ~ '-' ~ newsPosts[0].id %}
{% set comments = newsPosts[0].comments.comments %}
{% endif %}
{% set title %}
{% if not (viewPost ? postExists : newsPosts|length) %}Post does not exist!{% elseif viewPost and postExists %}{{ newsPosts[0].title }}{% else %}News{% endif %}
{% endset %}

View file

@ -2064,6 +2064,7 @@ textarea.inputStyling {
border: 0;
min-height: 50px;
height: 50px;
min-width: 300px;
flex-grow: 2;
padding: 5px;
font: 12px/20px "SegoeUI", "Segoe UI", sans-serif;
@ -2101,8 +2102,7 @@ textarea.inputStyling {
#comments .comment > .comment-submit {
flex-shrink: 0;
font-family: FontAwesome;
height: 60px;
width: 60px;
width: 50px;
border-radius: 4px;
margin-left: 2px;
font-size: 2em;
@ -2112,6 +2112,10 @@ textarea.inputStyling {
cursor: pointer;
}
#comments .comment > .comment-submit.new {
width: 60px;
}
#comments .comment > .comment-submit:hover {
background: linear-gradient(0deg, #9475B2 30%, #C2AFFE 70%);
}
@ -2120,6 +2124,10 @@ textarea.inputStyling {
background: linear-gradient(180deg, #9475B2 30%, #C2AFFE 70%);
}
#comments .comments-discussion {
overflow: auto;
}
#comments ul {
list-style: none;
}

View file

@ -853,8 +853,99 @@ function safeTagsReplace(str) {
return str.replace(/[&<>]/g, replaceTag);
}
function commentReply(id, session, category, action, avatar) {
// Find subject post
var replyingTo = document.getElementById('comment-' + id);
// Check if it actually exists
if(typeof replyingTo === 'undefined') {
return false;
}
// Container
var replyContainer = document.createElement('li');
// Form
var replyForm = document.createElement('form');
replyForm.id = 'comment-reply-' + id;
replyForm.action = action;
replyForm.method = 'post';
// Session
var replyInput = document.createElement('input');
replyInput.type = 'hidden';
replyInput.name = 'session';
replyInput.value = session;
replyForm.appendChild(replyInput);
// Category
var replyInput = document.createElement('input');
replyInput.type = 'hidden';
replyInput.name = 'category';
replyInput.value = category;
replyForm.appendChild(replyInput);
// Reply ID
var replyInput = document.createElement('input');
replyInput.type = 'hidden';
replyInput.name = 'replyto';
replyInput.value = id;
replyForm.appendChild(replyInput);
// Mode
var replyInput = document.createElement('input');
replyInput.type = 'hidden';
replyInput.name = 'mode';
replyInput.value = 'comment';
replyForm.appendChild(replyInput);
// Comment container
var replyDiv = document.createElement('div');
replyDiv.className = 'comment';
// Avatar
var replyAvatar = document.createElement('div');
replyAvatar.className = 'comment-avatar';
replyAvatar.style = 'background-image: url(' + avatar + ')';
replyDiv.appendChild(replyAvatar);
// Pointer
var replyPoint = document.createElement('div');
replyPoint.className = 'comment-pointer';
replyDiv.appendChild(replyPoint);
// Textarea
var replyText = document.createElement('textarea');
replyText.className = 'comment-content';
replyText.name = 'comment';
replyDiv.appendChild(replyText);
// Submit
var replySubmit = document.createElement('input');
replySubmit.className = 'comment-submit';
replySubmit.type = 'submit';
replySubmit.name = 'submit';
replySubmit.value = "\uf1d8";
replyDiv.appendChild(replySubmit);
// Append to form
replyForm.appendChild(replyDiv);
// Append form to container
replyContainer.appendChild(replyForm);
// Insert the HTML
replyingTo.children[1].appendChild(replyContainer);
// Prepare AJAX submission
prepareAjaxForm(replyForm.id, 'Replying...');
}
// Formatting money
Number.prototype.formatMoney = function(c, d, t) {
var n = this,
c = isNaN(c = Math.abs(c)) ? 2 : c,
d = d == undefined ? "." : d,
@ -862,5 +953,7 @@ var n = this,
s = n < 0 ? "-" : "",
i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "",
j = (j = i.length) > 3 ? j % 3 : 0;
return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : "");
};

View file

@ -72,22 +72,39 @@ if (isset($_REQUEST['request-notifications']) && $_REQUEST['request-notification
if ($continue) {
switch (isset($_REQUEST['mode']) ? $_REQUEST['mode'] : false) {
case 'like':
break;
case 'dislike':
break;
case 'delete':
break;
case 'comment':
// Attempt to make a new comment
$comment = (new Comments($_POST['category']))->makeComment($currentUser->data['id'], $_POST['replyto'], $_POST['comment']);
// Messages
$messages = [
'TOO_SHORT' => 'The comment you\'re trying to make is too short!',
'TOO_LONG' => 'The comment you\'re trying to make is too long!',
'SUCCESS' => 'Posted!',
];
$renderData['page'] = [
'redirect' => $redirect,
'message' => $messages[$comment[1]],
'success' => $comment[0],
];
break;
default:
$renderData['page'] = [
'redirect' => $redirect,
'message' => 'Did nothing.',
'message' => 'Unknown action.',
'success' => 0,
];