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