Skip to content

Commit 7b41105

Browse files
committed
Convert news edit page to bootstrap
1 parent e1119f2 commit 7b41105

File tree

3 files changed

+46
-110
lines changed

3 files changed

+46
-110
lines changed

src/controllers/News/Edit.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class Edit extends Controller {
2525
public function &run(Router &$router, View &$view, array &$args) {
2626
$data = $router->getRequestQueryArray();
2727
$model = new NewsEditModel();
28+
$model->active_user = Authentication::$user;
2829
$model->category = null;
2930
$model->content = null;
3031
$model->error = null;
@@ -35,9 +36,8 @@ public function &run(Router &$router, View &$view, array &$args) {
3536
$model->published = null;
3637
$model->rss_exempt = null;
3738
$model->title = null;
38-
$model->user = Authentication::$user;
3939

40-
$model->acl_allowed = ($model->user && $model->user->getAcl(
40+
$model->acl_allowed = ($model->active_user && $model->active_user->getAcl(
4141
User::OPTION_ACL_NEWS_MODIFY
4242
));
4343

@@ -105,7 +105,7 @@ protected function handlePost(Router &$router, NewsEditModel &$model) {
105105
$model->error = 'EMPTY_CONTENT';
106106
}
107107

108-
$user_id = $model->user->getId();
108+
$user_id = $model->active_user->getId();
109109

110110
try {
111111

src/models/News/Edit.php

+3-10
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
1-
<?php
2-
3-
namespace BNETDocs\Models\News;
4-
5-
use \CarlBennett\MVC\Libraries\Model;
6-
7-
class Edit extends Model {
8-
1+
<?php namespace BNETDocs\Models\News;
2+
class Edit extends \BNETDocs\Models\ActiveUser
3+
{
94
public $acl_allowed;
105
public $category;
116
public $content;
@@ -17,6 +12,4 @@ class Edit extends Model {
1712
public $published;
1813
public $rss_exempt;
1914
public $title;
20-
public $user;
21-
2215
}

src/templates/News/Edit.phtml

+40-97
Original file line numberDiff line numberDiff line change
@@ -1,101 +1,44 @@
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 = "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;
3318
}
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

Comments
 (0)