Skip to content

Commit a990983

Browse files
committed
First pass at bootstrap convert, work in progress
1 parent 674f76b commit a990983

36 files changed

+649
-666
lines changed

etc/config.sample.json

-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
false,
1919
"BNETDocs has to take a brief moment to do some system maintenance. We'll be back shortly."
2020
],
21-
"mobile_site_enabled": true,
2221
"navigation": {
2322
"front_page": "/welcome",
2423
"hide_search_documents": false,

src/libraries/Comment.php

+15
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,21 @@ public function getParentType() {
194194
return $this->parent_type;
195195
}
196196

197+
public function getParentUrl() {
198+
if (!is_int($this->parent_type)) return false;
199+
switch ($this->parent_type) {
200+
case self::PARENT_TYPE_DOCUMENT: $page = 'document'; break;
201+
case self::PARENT_TYPE_COMMENT: $page = 'comment'; break;
202+
case self::PARENT_TYPE_NEWS_POST: $page = 'news'; break;
203+
case self::PARENT_TYPE_PACKET: $page = 'packet'; break;
204+
case self::PARENT_TYPE_SERVER: $page = 'server'; break;
205+
case self::PARENT_TYPE_USER: $page = 'user'; break;
206+
default: return false;
207+
}
208+
$page = '/' . $page . '/' . rawurlencode($this->parent_id);
209+
return Common::relativeUrlToAbsolute($page);
210+
}
211+
197212
public function getUser() {
198213
return User::findUserById($this->user_id);
199214
}

src/templates/Comment/Delete.phtml

+47-58
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,61 @@
1-
<?php
2-
1+
<?php /* vim: set colorcolumn=: */
32
namespace BNETDocs\Templates\Comment;
4-
53
use \CarlBennett\MVC\Libraries\Pair;
6-
7-
$title = "Delete Comment";
8-
$description = "This form allows an individual to delete a comment.";
9-
10-
$this->opengraph->attach(new Pair("url", "/comment/delete"));
11-
$this->opengraph->attach(new Pair("type", "article"));
12-
13-
switch ($this->getContext()->error) {
14-
case "ACL_NOT_SET":
15-
$message = "You do not have the privilege to delete comments.";
16-
break;
17-
case "NOT_FOUND":
18-
$message = "Cannot find comment by that id.";
19-
break;
20-
case "NOT_LOGGED_IN":
21-
$message = "You must be logged in to delete comments.";
22-
break;
23-
case "INTERNAL_ERROR":
24-
$message = "An internal error occurred while processing your request. "
25-
. "Our staff have been notified of the issue. Try again later.";
26-
break;
27-
default:
28-
$message = $this->getContext()->error;
4+
$title = 'Delete Comment';
5+
$description = 'This page confirms if the user wishes to delete a comment.';
6+
$this->opengraph->attach(new Pair('url', '/comment/delete'));
7+
$this->opengraph->attach(new Pair('type', 'article'));
8+
switch ($this->getContext()->error)
9+
{
10+
case 'ACL_NOT_SET': $message = 'You do not have the privilege to delete comments.'; break;
11+
case 'NOT_FOUND': $message = 'Cannot find comment by that id.'; break;
12+
case 'NOT_LOGGED_IN': $message = 'You must be logged in to delete comments.'; break;
13+
case 'INTERNAL_ERROR': $message = 'An internal error occurred while processing your request. Our staff have been notified of the issue. Try again later.'; break;
14+
default: $message = $this->getContext()->error;
2915
}
30-
3116
$c = $this->getContext()->comment;
32-
if ($c) {
17+
if ($c)
18+
{
3319
$c_id = $c->getId();
20+
$c_parent_url = $c->getParentUrl();
3421
$c_user = $c->getUser();
22+
$c_user_avatar = $c_user->getAvatarURI(22);
3523
$c_user_id = $c->getUserId();
3624
$c_user_name = $c_user->getName();
3725
$c_user_url = $c_user->getURI();
38-
$c_user_avatar = $c_user->getAvatarURI(22);
3926
}
40-
41-
$this->additional_css[] = "/a/comments.css";
42-
$this->additional_css[] = "/a/forms.css";
43-
require("./header.inc.phtml");
44-
?>
45-
<article>
27+
$id = $this->getContext()->id;
28+
require('./header.inc.phtml'); ?>
29+
<div class="container mb-3">
4630
<?php if (is_null($this->getContext()->error)) { ?>
47-
<header>Delete Comment</header>
48-
<form method="POST" action="?id=<?php echo $this->getContext()->id; ?>">
49-
<section>
50-
<p>Are you sure you wish to delete this comment?</p>
51-
<hr/><table class="comments"><tbody>
52-
<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>
53-
</tbody></table><hr/>
54-
<p><input type="submit" value="Delete Comment" tabindex="1" autofocus="autofocus"/></p>
55-
</section>
56-
</form>
31+
32+
<h2 class="text-danger">Delete Comment</h2>
33+
<p class="text-danger">Are you sure you wish to delete this comment?</p>
34+
<form method="POST" action="?id=<?=rawurlencode($id)?>">
35+
<table class="table table-striped"><tbody>
36+
<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>
37+
</tbody></table>
38+
<a class="btn btn-primary" href="javascript:history.go(-1);">Back</a>
39+
<input class="btn btn-danger" type="submit" value="Delete" tabindex="1" autofocus="autofocus"/>
40+
</form>
41+
5742
<?php } else if ($this->getContext()->error === false) { ?>
58-
<header class="green">Comment Deleted</header>
59-
<section class="green">
60-
<p>You have successfully deleted the comment!</p>
61-
<p>Use the navigation to the left to move to another page.</p>
62-
</section>
43+
44+
<h2 class="text-success">Delete Comment</h2>
45+
<div class="alert alert-success">
46+
<p class="mb-0"><strong>The comment was successfully deleted!</strong></p>
47+
</div>
48+
<a class="btn btn-primary" href="<?=$c_parent_url?>">Back</a>
49+
6350
<?php } else { ?>
64-
<header class="red">Delete Comment</header>
65-
<section class="red">
66-
<p>An error occurred while attempting to delete the comment.</p>
67-
<p><?php echo $message; ?></p>
68-
<p>Use the navigation to the left to move to another page.</p>
69-
</section>
51+
52+
<h2 class="text-danger">Delete Comment</h2>
53+
<div class="alert alert-danger">
54+
<p class="mb-0"><strong>An error occurred while attempting to delete the comment:</strong></p>
55+
<p class="mb-0"><?=$message?></p>
56+
</div>
57+
<a class="btn btn-primary" href="<?=$c_parent_url?>">Back</a>
58+
7059
<?php } ?>
71-
</article>
72-
<?php require("./footer.inc.phtml"); ?>
60+
</div>
61+
<?php require('./footer.inc.phtml'); ?>

src/templates/Comment/Edit.phtml

+56-63
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,68 @@
1-
<?php
2-
1+
<?php /* vim: set colorcolumn=: */
32
namespace BNETDocs\Templates\Comment;
4-
53
use \CarlBennett\MVC\Libraries\Common;
64
use \CarlBennett\MVC\Libraries\Pair;
7-
8-
$title = "Edit Comment";
9-
$description = "This form allows an individual to edit a comment.";
10-
11-
$this->opengraph->attach(new Pair("url", "/comment/edit"));
12-
$this->opengraph->attach(new Pair("type", "article"));
13-
14-
switch ($this->getContext()->error) {
15-
case "ACL_NOT_SET":
16-
$message = "You do not have the privilege to edit this comment.";
17-
break;
18-
case "NOT_FOUND":
19-
$message = "Cannot find comment by that id.";
20-
break;
21-
case "NOT_LOGGED_IN":
22-
$message = "You must be logged in to edit comments.";
23-
break;
24-
case "INTERNAL_ERROR":
25-
$message = "An internal error occurred while processing your request. "
26-
. "Our staff have been notified of the issue. Try again later.";
27-
break;
28-
default:
29-
$message = $this->getContext()->error;
5+
$title = 'Edit Comment';
6+
$description = 'This page enables a user to alter a comment.';
7+
$this->opengraph->attach(new Pair('url', '/comment/edit'));
8+
$this->opengraph->attach(new Pair('type', 'article'));
9+
switch ($this->getContext()->error)
10+
{
11+
case 'ACL_NOT_SET': $message = 'You do not have the privilege to edit this comment.'; break;
12+
case 'NOT_FOUND': $message = 'Cannot find comment by that id.'; break;
13+
case 'NOT_LOGGED_IN': $message = 'You must be logged in to edit comments.'; break;
14+
case 'INTERNAL_ERROR': $message = 'An internal error occurred while processing your request. Our staff have been notified of the issue. Try again later.'; break;
15+
default: $message = $this->getContext()->error;
3016
}
31-
3217
$c = $this->getContext()->comment;
33-
if ($c) {
18+
if ($c)
19+
{
20+
$c_content = filter_var($c->getContent(false), FILTER_SANITIZE_FULL_SPECIAL_CHARS);
21+
$c_created_dt = $c->getCreatedDateTime();
3422
$c_id = $c->getId();
23+
$c_parent_url = $c->getParentUrl();
3524
$c_user = $c->getUser();
3625
$c_user_id = $c->getUserId();
37-
$c_user_name = $c_user->getName();
26+
$c_user_name = filter_var($c_user->getName(), FILTER_SANITIZE_FULL_SPECIAL_CHARS);
3827
$c_user_url = $c_user->getURI();
3928
$c_user_avatar = $c_user->getAvatarURI(22);
4029
}
30+
require('./header.inc.phtml'); ?>
31+
<div class="container mb-3">
32+
<? if (is_null($this->getContext()->error) && !is_null($c)) { ?>
33+
34+
<h2>Edit Comment</h2>
35+
<p>Use the form below to edit the comment, when you are finished you must save.</p>
36+
<form method="POST" action="<?=Common::relativeUrlToAbsolute('/comment/edit?id=' . $c_id)?>">
37+
<table class="table table-striped"><tbody>
38+
<tr><td>
39+
<a href="<?=$c_user_url?>"><img class="avatar" src="<?=$c_user_avatar?>"/> <?=$c_user_name?></a><br/>
40+
<time datetime="<?=$c_created_dt->format('c')?>"><?=$c_created_dt->format('D M j, Y g:ia T')?></time>
41+
</td><td>
42+
<textarea class="form-control bg-dark text-light" name="content" cols="80" rows="5" tabindex="1" autofocus="autofocus"><?=$c_content?></textarea>
43+
</td></tr>
44+
</tbody></table>
45+
<a class="btn btn-primary" href="javascript:history.go(-1);">Back</a>
46+
<input class="btn btn-success" type="submit" value="Save" tabindex="2"/>
47+
</form>
48+
49+
<? } else if ($this->getContext()->error === false) { ?>
50+
51+
<h2 class="text-success">Edit Comment</h2>
52+
<div class="alert alert-success">
53+
<p class="mb-0"><strong>The comment was successfully edited!</strong></p>
54+
</div>
55+
<a class="btn btn-primary" href="<?=$c_parent_url?>">Back</a>
56+
57+
<? } else { ?>
58+
59+
<h2 class="text-danger">Edit Comment</h2>
60+
<div class="alert alert-danger">
61+
<p class="mb-0"><strong>An error occurred while attempting to edit the comment:</strong></p>
62+
<p class="mb-0"><?=$message?></p>
63+
</div>
64+
<a class="btn btn-primary" href="<?=$c_parent_url?>">Back</a>
4165

42-
$this->additional_css[] = "/a/comments.css";
43-
$this->additional_css[] = "/a/forms.css";
44-
require("./header.inc.phtml");
45-
?>
46-
<article>
47-
<?php if (is_null($this->getContext()->error) && !is_null($c)) { ?>
48-
<header>Edit Comment</header>
49-
<form method="POST" action="<?php echo Common::relativeUrlToAbsolute( '/comment/edit?id=' . $c_id ); ?>">
50-
<section>
51-
<table class="comments"><tbody>
52-
<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><textarea id="comment-content" name="content" cols="80" rows="5" tabindex="1" autofocus="autofocus"><?php echo filter_var( $c->getContent( false ), FILTER_SANITIZE_FULL_SPECIAL_CHARS ); ?></textarea></td></tr>
53-
</tbody></table><hr/>
54-
<p>
55-
<input class="float-right bg-green" type="submit" value="Edit Comment" tabindex="2"/>
56-
<a class="button button-bg-red" href="<?php echo $this->getContext()->return_url; ?>" id="cancel-btn">Cancel</a>
57-
</p>
58-
</section>
59-
</form>
60-
<?php } else if ($this->getContext()->error === false) { ?>
61-
<header class="green">Comment Edited</header>
62-
<section class="green">
63-
<p>You have successfully edited the comment!</p>
64-
<p><a href="<?php echo $this->getContext()->return_url; ?>#comments">Return to previous page</a></p>
65-
</section>
66-
<?php } else { ?>
67-
<header class="red">Edit Comment</header>
68-
<section class="red">
69-
<p>An error occurred while attempting to delete the comment.</p>
70-
<p><?php echo $message; ?></p>
71-
<p>Use the navigation to the left to move to another page.</p>
72-
</section>
73-
<?php } ?>
74-
</article>
75-
<?php require("./footer.inc.phtml"); ?>
66+
<? } ?>
67+
</div>
68+
<? require('./footer.inc.phtml'); ?>
+54-36
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,62 @@
1-
<?php
2-
1+
<?php /* vim: set colorcolumn=: */
32
namespace BNETDocs\Templates\Comment;
4-
53
use \BNETDocs\Libraries\Comment;
64
use \BNETDocs\Libraries\User;
7-
85
use \CarlBennett\MVC\Libraries\Common;
9-
6+
$c_edit_visible_admin = ($logged_in && ($logged_in->getOptionsBitmask() & User::OPTION_ACL_COMMENT_MODIFY));
7+
$c_delete_visible_admin = ($logged_in && ($logged_in->getOptionsBitmask() & User::OPTION_ACL_COMMENT_DELETE));
108
?>
11-
<header><a name="comments">Comments</a></header>
12-
<section>
13-
<?php if (!$comments) { ?>
14-
<p class="center"><em>no one has commented yet.</em></p>
15-
<?php } else {
16-
$c_edit_visible_master = ($logged_in && ($logged_in->getOptionsBitmask() & User::OPTION_ACL_COMMENT_MODIFY));
17-
$c_delete_visible_master = ($logged_in && ($logged_in->getOptionsBitmask() & User::OPTION_ACL_COMMENT_DELETE));
18-
?>
19-
<table class="comments"><tbody>
20-
<?php foreach ($comments as $c) {
21-
$c_id = $c->getId();
9+
<div class="row mt-3">
10+
<div class="col">
11+
<h2><a name="comments">Comments</a></h2>
12+
<? if (!$comments) { ?>
13+
<div class="border border-secondary rounded-pill p-2"><p class="text-center mb-0"><em>no one has commented yet.</em></p></div>
14+
<? } else { ?>
15+
<table class="table table-striped"><tbody>
16+
<? foreach ($comments as $c) {
17+
$c_created_dt = $c->getCreatedDateTime();
18+
$c_id = rawurlencode($c->getId());
19+
$c_parent_url = $c->getParentUrl();
2220
$c_user = $c->getUser();
2321
$c_user_id = $c->getUserId();
22+
$c_user_url = ($c_user ? $c_user->getURI() : '');
23+
$c_user_avatar = ($c_user ? $c_user->getAvatarURI(22) : '');
24+
$c_user_name = ($c_user ? filter_var($c_user->getName(), FILTER_SANITIZE_FULL_SPECIAL_CHARS) : 'Anonymous');
2425

25-
$c_edit_visible = ($c_user_id == $logged_in_id || $c_edit_visible_master);
26-
$c_delete_visible = ($c_user_id == $logged_in_id || $c_delete_visible_master);
27-
?>
28-
<tr><td><?php if ($c_user) { ?><a href="<?php echo $c_user->getURI(); ?>"><img class="avatar" src="<?php echo $c_user->getAvatarURI(22); ?>"/> <?php echo filter_var($c_user->getName(), FILTER_SANITIZE_STRING); ?></a><?php } else { ?>Anonymous<?php } ?><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>
29-
<?php } ?>
30-
</tbody></table>
31-
<?php } ?>
32-
</section>
33-
<?php if ($logged_in) { ?>
34-
<section>
35-
<hr/>
36-
<form method="POST" action="<?php echo Common::relativeUrlToAbsolute("/comment/create"); ?>">
37-
<input type="hidden" name="parent_type" value="<?php echo $comment_parent_type; ?>"/>
38-
<input type="hidden" name="parent_id" value="<?php echo $object_id; ?>"/>
39-
<p class="center"><label for="comment-content">Comment on this post:</label></p>
40-
<p class="center"><textarea id="comment-content" name="content" cols="80" rows="5"></textarea></p>
41-
<p class="center"><input type="submit" value="Comment"/></p>
42-
</form>
43-
</section>
44-
<?php } ?>
26+
$c_user_string = ($c_user ? sprintf('<a href="%s"><img src="%s"/> %s</a>', $c_user_url, $c_user_avatar, $c_user_name) : $c_user_name);
27+
28+
$c_edit_visible = ($c_user_id == $logged_in_id || $c_edit_visible_admin);
29+
$c_delete_visible = ($c_user_id == $logged_in_id || $c_delete_visible_admin); ?>
30+
<tr><td>
31+
<?=$c_user_string?><br/>
32+
<time datetime="<?=$c_created_dt->format('c')?>"><?=$c_created_dt->format('D M j, Y g:ia T')?></time>
33+
</td><td>
34+
<? if ($c_delete_visible) { ?>
35+
<a class="btn btn-sm btn-danger float-right m-1" href="<?=Common::relativeUrlToAbsolute('/comment/delete?id=' . $c_id)?>" title="Delete">❌</a>
36+
<? } if ($c_edit_visible) { ?>
37+
<a class="btn btn-sm btn-secondary float-right m-1" href="<?=Common::relativeUrlToAbsolute('/comment/edit?id=' . $c_id)?>" title="Edit">📝</a>
38+
<? } ?>
39+
<?=$c->getContent(true)?>
40+
</td></tr>
41+
<? } ?>
42+
</tbody></table>
43+
<? } ?>
44+
</div>
45+
</div>
46+
<? if ($logged_in) { ?>
47+
<div class="row mt-3">
48+
<div class="col-2"></div>
49+
<div class="col-8">
50+
<form method="POST" action="<?=Common::relativeUrlToAbsolute('/comment/create')?>">
51+
<input type="hidden" name="parent_type" value="<?=$comment_parent_type?>"/>
52+
<input type="hidden" name="parent_id" value="<?=$object_id?>"/>
53+
<div class="form-group">
54+
<label for="comment-content" class="font-weight-bold">Make a Comment:</label>
55+
<textarea id="comment-content" class="border border-secondary form-control bg-dark text-light" name="content"></textarea>
56+
</div>
57+
<input class="btn btn-sm btn-secondary" type="submit" value="Comment"/>
58+
</form>
59+
</div>
60+
<div class="col-2"></div>
61+
</div>
62+
<? } ?>

0 commit comments

Comments
 (0)