|
1 |
| -<?php |
2 |
| - |
| 1 | +<?php /* vim: set colorcolumn= expandtab shiftwidth=2 softtabstop=2 tabstop=4 smarttab: */ |
3 | 2 | namespace BNETDocs\Templates\News;
|
4 |
| - |
5 | 3 | use \CarlBennett\MVC\Libraries\Common;
|
6 | 4 | use \CarlBennett\MVC\Libraries\Pair;
|
7 |
| - |
8 |
| -$title = "Edit News Post"; |
9 |
| -$description = "This form allows an individual to edit a news post."; |
10 |
| - |
11 |
| -$this->opengraph->attach(new Pair("url", "/news/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 news posts."; |
17 |
| - break; |
18 |
| - case "NOT_FOUND": |
19 |
| - $message = "Cannot find news post by that id."; |
20 |
| - break; |
21 |
| - case "EMPTY_TITLE": |
22 |
| - $message = "The title of the news post is required."; |
23 |
| - break; |
24 |
| - case "EMPTY_CONTENT": |
25 |
| - $message = "The content of the news post is required."; |
26 |
| - break; |
27 |
| - case "INTERNAL_ERROR": |
28 |
| - $message = "An internal error occurred while processing your request. " |
29 |
| - . "Our staff have been notified of the issue. Try again later."; |
30 |
| - break; |
31 |
| - default: |
32 |
| - $message = $this->getContext()->error; |
| 5 | +$title = 'Edit News Post'; |
| 6 | +$description = 'This page enables a user to edit a news post on the site.'; |
| 7 | +$this->opengraph->attach(new Pair('url', '/news/edit')); |
| 8 | +$this->opengraph->attach(new Pair('type', 'article')); |
| 9 | +$error = $this->getContext()->error; |
| 10 | +switch ($error) |
| 11 | +{ |
| 12 | + case 'ACL_NOT_SET': $message = 'You do not have the privilege to edit news posts.'; break; |
| 13 | + case 'NOT_FOUND': $message = 'Cannot find news post by that id.'; break; |
| 14 | + case 'EMPTY_TITLE': $message = 'The title of the news post is required.'; break; |
| 15 | + case 'EMPTY_CONTENT': $message = 'The content of the news post is required.'; break; |
| 16 | + case 'INTERNAL_ERROR': $message = 'An internal error occurred while processing your request. Our staff have been notified of the issue. Try again later.'; break; |
| 17 | + default: $message = $error; |
33 | 18 | }
|
34 |
| - |
35 |
| -require("./header.inc.phtml"); |
36 |
| -?> |
37 |
| - <article> |
38 |
| -<?php if ($this->getContext()->error !== false) { ?> |
39 |
| - <header>Edit News Post</header> |
40 |
| -<?php if (!empty($message)) { ?> |
41 |
| - <section class="red"><p><?php echo $message; ?></p></section> |
42 |
| -<?php } ?> |
43 |
| -<?php if ($this->getContext()->error != "NOT_FOUND") { ?> |
44 |
| - <form method="POST" action="?id=<?php echo |
45 |
| - htmlspecialchars($this->getContext()->news_post_id, ENT_HTML5, "UTF-8"); ?>"> |
46 |
| - <section> |
47 |
| - <label for="category">Category:</label><br/> |
48 |
| - <select name="category" id="category" tabindex="1" required |
49 |
| - autofocus="autofocus" size="<?php echo min(count($this->getContext()->news_categories), 10); ?>"> |
50 |
| -<?php $category = $this->getContext()->category; |
51 |
| - foreach ($this->getContext()->news_categories as $item) { ?> |
52 |
| - <option value="<?php echo htmlspecialchars($item->getId(), ENT_HTML5, "UTF-8"); ?>"<?php if ($category === $item->getId()) { ?> selected="selected"<?php } ?>><?php echo htmlspecialchars($item->getLabel(), ENT_HTML5, "UTF-8"); ?></option> |
53 |
| -<?php } ?> |
54 |
| - </select> |
55 |
| - </section> |
56 |
| - <section> |
57 |
| - <label for="title">Title:</label><br/> |
58 |
| - <input type="text" name="title" id="title" tabindex="2" required |
59 |
| - value="<?php echo |
60 |
| - filter_var($this->getContext()->title, FILTER_SANITIZE_STRING); |
61 |
| - ?>"/> |
62 |
| - </section> |
63 |
| - <section> |
64 |
| - <label for="content">Content:</label> |
65 |
| - <span style="float:right;"> |
66 |
| - <label for="markdown" title="Use markdown or use raw HTML">Markdown</label> |
67 |
| - <input type="checkbox" name="markdown" id="markdown" tabindex="4" |
68 |
| - title="Use markdown or use raw HTML" value="1"<?php |
69 |
| - if ($this->getContext()->markdown) |
70 |
| - echo " checked=\"checked\""; |
71 |
| - ?>/> |
72 |
| - </span> |
73 |
| - <textarea name="content" id="content" tabindex="3" required |
74 |
| - style="height:200px;"><?php echo |
75 |
| - htmlspecialchars($this->getContext()->content, ENT_HTML5, "UTF-8"); |
76 |
| - ?></textarea> |
77 |
| - </section> |
78 |
| - <section> |
79 |
| - <input type="checkbox" name="rss_exempt" id="rss_exempt" |
80 |
| - tabindex="5" value="1"<?php |
81 |
| - if ($this->getContext()->rss_exempt) |
82 |
| - echo " checked=\"checked\""; |
83 |
| - ?>/> |
84 |
| - <label for="rss_exempt">Hide this news post from RSS feeds*</label> |
85 |
| - <p style="font-size:small;padding-left:4px;">* Some RSS feed readers such as Feedly do not automatically update, your updated content may not be reflected everywhere.</p> |
86 |
| - </section> |
87 |
| - <section> |
88 |
| - <input type="submit" name="publish" value="Publish" tabindex="6"/> |
89 |
| - <input type="submit" name="save" value="Unpublish" tabindex="7"/> |
90 |
| - </section> |
91 |
| - </form> |
92 |
| -<?php } ?> |
93 |
| -<?php } else { ?> |
94 |
| - <header class="green">Edit News Post</header> |
95 |
| - <section class="green"> |
96 |
| - <p>Your news post has been edited.</p> |
97 |
| - <p>Use the navigation to the left to move to another page.</p> |
98 |
| - </section> |
99 |
| -<?php } ?> |
100 |
| - </article> |
101 |
| -<?php require("./footer.inc.phtml"); ?> |
| 19 | +$form_category = $this->getContext()->category; |
| 20 | +$form_content = filter_var($this->getContext()->content, FILTER_SANITIZE_FULL_SPECIAL_CHARS); |
| 21 | +$form_markdown = $this->getContext()->markdown; |
| 22 | +$form_rss_exempt = $this->getContext()->rss_exempt; |
| 23 | +$form_title = filter_var($this->getContext()->title, FILTER_SANITIZE_FULL_SPECIAL_CHARS); |
| 24 | +$news_categories = $this->getContext()->news_categories; |
| 25 | +$news_post = $this->getContext()->news_post; |
| 26 | +$news_post_id = filter_var($this->getContext()->news_post_id, FILTER_SANITIZE_FULL_SPECIAL_CHARS); |
| 27 | +require('./header.inc.phtml'); ?> |
| 28 | +<div class="container"> |
| 29 | + <h1><?=$title?></h1> |
| 30 | + <p><?=$description?></p> |
| 31 | +<? if ($error !== false) { |
| 32 | + if (!empty($message)) { ?> |
| 33 | + <div class="alert alert-danger"> |
| 34 | + <p class="mb-0"><?=$message?></p> |
| 35 | + </div> |
| 36 | +<? } |
| 37 | + require('./News/Form.inc.phtml'); |
| 38 | + } else { ?> |
| 39 | + <div class="alert alert-success"> |
| 40 | + <p class="mb-0">Your news post has been edited successfully!</p> |
| 41 | + </div> |
| 42 | +<? } ?> |
| 43 | +</div> |
| 44 | +<? require('./footer.inc.phtml'); ?> |
0 commit comments