Skip to content

Commit 2a8325e

Browse files
committed
Convert news post create page to bootstrap
1 parent bfb3bd7 commit 2a8325e

File tree

2 files changed

+74
-91
lines changed

2 files changed

+74
-91
lines changed

src/templates/News/Create.phtml

Lines changed: 37 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -1,95 +1,41 @@
1-
<?php
2-
1+
<?php /* vim: set colorcolumn= expandtab shiftwidth=2 softtabstop=2 tabstop=4 smarttab: */
32
namespace BNETDocs\Templates\News;
4-
53
use \CarlBennett\MVC\Libraries\Common;
64
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;
3017
}
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'); ?>

src/templates/News/Form.inc.phtml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php /* vim: set colorcolumn= expandtab shiftwidth=2 softtabstop=2 tabstop=4 smarttab: */
2+
namespace BNETDocs\Templates\Document; ?>
3+
<form method="POST" action="?<?=($news_post_id ? 'id=' . filter_var($news_post_id, FILTER_SANITIZE_FULL_SPECIAL_CHARS) : '')?>">
4+
<div class="form-group">
5+
<label class="font-weight-bold" for="category">Category:</label><br/>
6+
<select class="border border-primary custom-select bg-dark text-light" name="category" id="category" tabindex="1" required autofocus="autofocus" size="1">
7+
<?php $category = $this->getContext()->category;
8+
foreach ($this->getContext()->news_categories as $item) { ?>
9+
<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>
10+
<?php } ?>
11+
</select>
12+
</div>
13+
<div class="form-group">
14+
<label class="font-weight-bold" class="form-label" for="title">Title:</label><br/>
15+
<input class="border border-primary form-control bg-dark text-light" type="text" name="title" id="title" tabindex="1" required placeholder="Enter the news post title here" value="<?=$form_title?>"/>
16+
</div>
17+
<div class="form-group">
18+
<label class="font-weight-bold" for="content">Content:</label>
19+
<textarea class="border border-primary form-control bg-dark text-light" name="content" id="content" tabindex="2" required placeholder="Enter the news post content here" style="height:200px;"><?=$form_content?></textarea>
20+
</div>
21+
<div class="form-group">
22+
<div class="custom-control custom-switch m-2">
23+
<input class="custom-control-input" type="checkbox" name="markdown" id="markdown" tabindex="3" title="Use markdown or use raw HTML" value="1"<?=($form_markdown ? ' checked="checked"' : '')?>/>
24+
<label class="custom-control-label" for="markdown" title="Use markdown or use raw HTML">Markdown <span class="text-muted small">(enables Markdown-formatted parsing of the content, which renders into native html &ndash; uses <a title="https://github.com/erusev/parsedown" href="https://github.com/erusev/parsedown" rel="external">Parsedown</a> and <a title="https://highlightjs.readthedocs.io/" href="https://highlightjs.readthedocs.io/" rel="external">Highlight.js</a>)</span></label>
25+
</div>
26+
<div class="custom-control custom-switch m-2">
27+
<input class="custom-control-input" type="checkbox" name="rss_exempt" id="rss_exempt" tabindex="4" title="Exempt from RSS feed" value="1"<?=($form_rss_exempt ? ' checked="checked"' : '')?>/>
28+
<label class="custom-control-label" for="rss_exempt" title="Exempt from RSS feed">RSS Exempt <span class="text-muted small">(excludes this post from RSS/Atom feeds, which typically ignore future edits to posts &ndash; use this to control when to publish to those feeds)</span></label>
29+
</div>
30+
</div>
31+
<div class="form-group text-center">
32+
<a class="btn btn-primary" href="<?=($news_post_url ?? 'javascript:history.go(-1);')?>" tabindex="5">Back</a>
33+
<span class="m-1"></span>
34+
<input class="btn btn-secondary" type="submit" name="save" value="Save Draft" tabindex="6"/>
35+
<input class="btn btn-success" type="submit" name="publish" value="Publish" tabindex="7"/>
36+
</div>
37+
</form>

0 commit comments

Comments
 (0)