This commit is contained in:
Marcin Kurczewski 2013-10-17 23:37:41 +02:00
parent ee050cfd01
commit 379674d027
8 changed files with 59 additions and 5 deletions

View file

@ -85,5 +85,7 @@ deleteUser.all=nobody
listComments=anonymous
addComment=registered
deleteComment.self=registered
deleteComment.all=moderator
listTags=anonymous

View file

@ -1,10 +1,12 @@
.comment {
margin: 0 0 1em 0;
}
.comment .body,
.comment .avatar {
float: left;
}
.comment .body {
margin-left: 60px;
}
.comment .header {
margin-bottom: 0.2em;
}
@ -26,5 +28,21 @@
}
.comment .date {
color: silver;
}
.comment .date,
.comment .delete {
font-size: small;
}
.comment .delete:before {
margin-left: 0.2em;
content: ' [';
color: silver;
}
.comment .delete:after {
content: ']';
color: silver;
}
.comment .delete a {
color: silver;
}

View file

@ -90,8 +90,7 @@ i.icon-dl {
margin: 2px;
}
form.edit-post,
form.edit-comment {
form.edit-post {
display: none;
}
form.edit-post .safety label:not(.left) {

View file

@ -66,7 +66,7 @@ $(function()
$.ajax(ajaxData);
});
$('form.add-comment, form.edit-comment').submit(function(e)
$('form.add-comment').submit(function(e)
{
e.preventDefault();

View file

@ -51,6 +51,8 @@ class CommentController
$this->context->transport->comments = $comments;
}
/**
* @route /post/{postId}/add-comment
* @valdiate postId [0-9]+
@ -78,4 +80,19 @@ class CommentController
$this->context->transport->success = true;
}
}
/**
* @route /comment/{id}/delete
* @validate id [0-9]+
*/
public function deleteAction($id)
{
$comment = Model_Comment::locate($id);
$secondary = $comment->commenter->id == $this->context->user->id ? 'own' : 'all';
PrivilegesHelper::confirmWithException($this->context->user, Privilege::DeleteComment, $secondary);
R::trash($comment);
$this->context->transport->success = true;
}
}

View file

@ -1,6 +1,14 @@
<?php
class Model_Comment extends RedBean_SimpleModel
{
public static function locate($key)
{
$comment = R::findOne('comment', 'id = ?', [$key]);
if (!$comment)
throw new SimpleException('Invalid comment ID "' . $key . '"');
return $comment;
}
public static function validateText($text)
{
$text = trim($text);

View file

@ -25,6 +25,7 @@ class Privilege extends Enum
const ListComments = 20;
const AddComment = 23;
const DeleteComment = 24;
const ListTags = 21;
}

View file

@ -2,7 +2,7 @@
<div class="avatar">
<?php if ($this->context->comment->commenter): ?>
<a href="<?php echo \Chibi\UrlHelper::route('user', 'view', ['name' => $this->context->comment->commenter->name]) ?>">
<img src="<?php echo $this->context->comment->commenter->getAvatarUrl(40) ?>" alt="<?php echo $this->context->comment->commenter->name ?: '[deleted user]' ?>"/>
<img src="<?php echo htmlspecialchars($this->context->comment->commenter->getAvatarUrl(40)) ?>" alt="<?php echo $this->context->comment->commenter->name ?: '[deleted user]' ?>"/>
</a>
<?php else: ?>
<img src="<?php echo \Chibi\UrlHelper::absoluteUrl('/media/img/pixel.gif') ?>" alt="[deleted user]">
@ -24,6 +24,15 @@
<span class="date">
<?php echo date('Y-m-d H:i', $this->context->comment->comment_date) ?>
</span>
<?php $secondary = $this->context->comment->commenter->id == $this->context->user->id ? 'own' : 'all' ?>
<?php if (PrivilegesHelper::confirm($this->context->user, Privilege::DeleteComment, $secondary)): ?>
<span class="delete">
<a class="simple-action" href="<?php echo \Chibi\UrlHelper::route('comment', 'delete', ['id' => $this->context->comment->id]) ?>" data-confirm-text="Are you sure you want to delete this comment?">
delete
</a>
</span>
<?php endif ?>
</div>
<div class="content">