Skip to content

Commit a4a44e9

Browse files
committed
Add edit/delete comment buttons
1 parent 59a0dae commit a4a44e9

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/static/a/comments.css

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,15 @@ table.comments time.comment_timestamp {
3030
font-size: smaller;
3131
}
3232

33+
table.comments a.comment_button {
34+
float: right;
35+
font-size: smaller;
36+
margin-left: 2px;
37+
min-height: 0px;
38+
min-width: 0px;
39+
padding: 0px 4px;
40+
}
41+
3342
table.comments blockquote {
3443
margin: 10px 0px;
3544
}

src/templates/News/View.phtml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ $object = $this->getContext()->news_post;
1212
$object_id = $this->getContext()->news_post_id;
1313
$user_session = $this->getContext()->user_session;
1414
$logged_in = ($user_session ? new User($user_session->user_id) : null);
15+
$logged_in_id = ($logged_in ? $logged_in->getId() : null);
1516

1617
$title = ($object ? $object->getTitle() : "News Post Not Found");
1718
$description = Common::stripUpTo(trim(filter_var(
@@ -92,13 +93,17 @@ require("./header.inc.phtml");
9293
<?php } else { ?>
9394
<table class="comments"><tbody>
9495
<?php foreach ($comments as $c) {
96+
$c_id = $c->getId();
9597
$c_user = $c->getUser();
9698
$c_user_name = $c_user->getName();
9799
$c_user_id = $c->getUserId();
98100
$c_user_url = $c_user->getURI();
99101
$c_user_avatar = $c_user->getAvatarURI(22);
102+
103+
$c_edit_visible = ($c_user_id == $logged_in_id);
104+
$c_delete_visible = ($c_user_id == $logged_in_id);
100105
?>
101-
<tr><td><a href="<?php echo $c_user_url; ?>"><img class="avatar" src="<?php echo $c_user_avatar; ?>"/> <?php echo filter_var($c_user_name, FILTER_SANITIZE_STRING); ?></a><br/><time class="comment_timestamp" datetime="<?php echo $c->getCreatedDateTime()->format("c"); ?>"><?php echo $c->getCreatedDateTime()->format("D M j, Y g:ia T"); ?></time></td><td><?php echo $c->getContent(true); ?></td></tr>
106+
<tr><td><a href="<?php echo $c_user_url; ?>"><img class="avatar" src="<?php echo $c_user_avatar; ?>"/> <?php echo filter_var($c_user_name, FILTER_SANITIZE_STRING); ?></a><br/><time class="comment_timestamp" datetime="<?php echo $c->getCreatedDateTime()->format("c"); ?>"><?php echo $c->getCreatedDateTime()->format("D M j, Y g:ia T"); ?></time><?php if ($c_delete_visible) { ?><a class="button comment_button" href="<?php echo Common::relativeUrlToAbsolute("/comment/delete?id=" . urlencode($c_id)); ?>">Delete</a><?php } if ($c_edit_visible) { ?><a class="button comment_button" href="<?php echo Common::relativeUrlToAbsolute("/comment/edit?id=" . urlencode($c_id)); ?>">Edit</a><?php } ?></td><td><?php echo $c->getContent(true); ?></td></tr>
102107
<?php } ?>
103108
</tbody></table>
104109
<?php } ?>

0 commit comments

Comments
 (0)