|
1 |
| -<?php |
2 |
| - |
| 1 | +<?php /* vim: set colorcolumn=: */ |
3 | 2 | namespace BNETDocs\Templates\Comment;
|
4 |
| - |
5 | 3 | use \CarlBennett\MVC\Libraries\Common;
|
6 | 4 | 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; |
30 | 16 | }
|
31 |
| - |
32 | 17 | $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(); |
34 | 22 | $c_id = $c->getId();
|
| 23 | + $c_parent_url = $c->getParentUrl(); |
35 | 24 | $c_user = $c->getUser();
|
36 | 25 | $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); |
38 | 27 | $c_user_url = $c_user->getURI();
|
39 | 28 | $c_user_avatar = $c_user->getAvatarURI(22);
|
40 | 29 | }
|
| 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> |
41 | 65 |
|
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'); ?> |
0 commit comments