Skip to content

Commit ad117d9

Browse files
committed
Next pass at bootstrap conversion
1 parent 8235ef8 commit ad117d9

File tree

5 files changed

+73
-83
lines changed

5 files changed

+73
-83
lines changed

src/controllers/News/View.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717
class View extends Controller {
1818
public function &run(Router &$router, ViewLib &$view, array &$args) {
1919
$model = new NewsViewModel();
20+
$model->active_user = Authentication::$user;
2021
$model->news_post_id = array_shift($args);
21-
$model->user = Authentication::$user;
2222

23-
$model->acl_allowed = ($model->user && $model->user->getAcl(
23+
$model->acl_allowed = ($model->active_user && $model->active_user->getAcl(
2424
User::OPTION_ACL_NEWS_CREATE |
2525
User::OPTION_ACL_NEWS_MODIFY |
2626
User::OPTION_ACL_NEWS_DELETE

src/models/News/View.php

+3-10
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,8 @@
1-
<?php
2-
3-
namespace BNETDocs\Models\News;
4-
5-
use \CarlBennett\MVC\Libraries\Model;
6-
7-
class View extends Model {
8-
1+
<?php namespace BNETDocs\Models\News;
2+
class View extends \BNETDocs\Models\ActiveUser
3+
{
94
public $acl_allowed;
105
public $comments;
116
public $news_post;
127
public $news_post_id;
13-
public $user;
14-
158
}

src/templates/News/View.phtml

+65-68
Original file line numberDiff line numberDiff line change
@@ -1,95 +1,92 @@
1-
<?php
2-
1+
<?php /* vim: set colorcolumn= expandtab shiftwidth=2 softtabstop=2 tabstop=4 smarttab: */
32
namespace BNETDocs\Templates\News;
4-
53
use \BNETDocs\Libraries\Comment;
64
use \BNETDocs\Libraries\NewsPost;
75
use \BNETDocs\Libraries\User;
86
use \CarlBennett\MVC\Libraries\Common;
97
use \CarlBennett\MVC\Libraries\Pair;
10-
11-
$comments = $this->getContext()->comments;
12-
$object = $this->getContext()->news_post;
13-
$object_id = $this->getContext()->news_post_id;
14-
$logged_in = $this->getContext()->user;
8+
$comments = $this->getContext()->comments;
9+
$object = $this->getContext()->news_post;
10+
$object_id = $this->getContext()->news_post_id;
11+
$logged_in = $this->getContext()->active_user;
1512
$logged_in_id = ($logged_in ? $logged_in->getId() : null);
13+
$title = ($object ? $object->getTitle() : 'News Post Not Found');
14+
$description = filter_var(($object ? $object->getContent(true) : 'The requested news post does not exist or could not be found.'), FILTER_SANITIZE_STRING);
15+
$this->opengraph->attach(new Pair('type', 'article'));
16+
$url = Common::relativeUrlToAbsolute('/news/' . urlencode($object_id));
1617

17-
$title = ($object ? $object->getTitle() : "News Post Not Found");
18-
$description = Common::stripUpTo(trim(filter_var(
19-
($object ? $object->getContent(true) : "The requested news post does not exist or could not be found."),
20-
FILTER_SANITIZE_STRING
21-
)), "\n", 300);
22-
23-
$this->opengraph->attach(new Pair("type", "article"));
24-
25-
$url = Common::relativeUrlToAbsolute("/news/" . urlencode($object_id));
26-
27-
if ($object) {
28-
18+
if ($object)
19+
{
2920
$url = $object->getURI();
3021

31-
$this->opengraph->attach(new Pair("image", "/a/news_categories/" . $object->getCategory()->getFilename()));
32-
$this->opengraph->attach(new Pair("article:published_time", $object->getCreatedDateTime()->format("c")));
22+
$this->opengraph->attach(new Pair('image', '/a/news_categories/' . $object->getCategory()->getFilename()));
23+
$this->opengraph->attach(new Pair('article:published_time', $object->getCreatedDateTime()->format('c')));
3324
if (!is_null($object->getEditedDateTime())) {
34-
$this->opengraph->attach(new Pair("article:modified_time", $object->getEditedDateTime()->format("c")));
25+
$this->opengraph->attach(new Pair('article:modified_time', $object->getEditedDateTime()->format('c')));
3526
}
36-
$this->opengraph->attach(new Pair("article:author:username", $object->getUser()->getName()));
37-
$this->opengraph->attach(new Pair("article:section", $object->getCategory()->getLabel()));
27+
$this->opengraph->attach(new Pair('article:author:username', $object->getUser()->getName()));
28+
$this->opengraph->attach(new Pair('article:section', $object->getCategory()->getLabel()));
3829

3930
}
4031

41-
$this->opengraph->attach(new Pair("url", $url));
32+
$this->opengraph->attach(new Pair('url', $url));
4233

43-
$edit_url = Common::relativeUrlToAbsolute("/news/edit?id=" . urlencode($object_id));
44-
$delete_url = Common::relativeUrlToAbsolute("/news/delete?id=" . urlencode($object_id));
34+
$edit_url = Common::relativeUrlToAbsolute('/news/edit?id=' . urlencode($object_id));
35+
$delete_url = Common::relativeUrlToAbsolute('/news/delete?id=' . urlencode($object_id));
4536
$edit_visible = ($logged_in && ($logged_in->getOptionsBitmask()
4637
& User::OPTION_ACL_NEWS_MODIFY));
4738
$delete_visible = ($logged_in && ($logged_in->getOptionsBitmask()
4839
& User::OPTION_ACL_NEWS_DELETE));
4940

50-
if ($object) {
51-
$user = $object->getUser();
52-
$user_id = $object->getUserId();
53-
$user_name = $user->getName();
54-
$user_url = $user->getURI();
55-
$user_avatar = $user->getAvatarURI(22);
41+
if ($object)
42+
{
43+
$draft = !$object->isPublished();
44+
$user = $object->getUser();
45+
$user_id = $object->getUserId();
46+
$user_name = $user->getName();
47+
$user_url = $user->getURI();
48+
$user_avatar = $user->getAvatarURI(40);
5649
}
5750

58-
require("./header.inc.phtml");
59-
?>
60-
<article class="container mb-3">
61-
<?php if ($object) { ?>
62-
<a href="https://twitter.com/share?text=<?php echo urlencode($object->getTitle()); ?>&amp;url=<?php echo urlencode($url); ?>" rel="external" data-popup="1"><img class="header-button float-right" src="<?php echo Common::relativeUrlToAbsolute("/a/social-twitter-24px.png"); ?>"/></a>
63-
<a href="https://facebook.com/sharer/sharer.php?u=<?php echo urlencode($url); ?>" rel="external" data-popup="1"><img class="header-button float-right" src="<?php echo Common::relativeUrlToAbsolute("/a/social-facebook-24px.png"); ?>"/></a>
64-
<?php if ($edit_visible) { ?>
65-
<a href="<?php echo $edit_url; ?>" class="header-button float-right">Edit</a>
66-
<?php } ?>
67-
<?php if ($delete_visible) { ?>
68-
<a href="<?php echo $delete_url; ?>" class="header-button float-right">Delete</a>
69-
<?php } ?>
70-
<header><a href="<?php echo $url; ?>"><?php echo filter_var($title, FILTER_SANITIZE_STRING); ?></a></header>
71-
<?php if (!($object->getOptionsBitmask() & NewsPost::OPTION_PUBLISHED)) { ?>
72-
<section class="red"><p><strong>Warning:</strong> This news post is not yet published. You can view this because you are allowed to create, modify, or delete news posts.</p></section>
73-
<?php } ?>
74-
<section class="news"><img class="category" alt="<?php echo $object->getCategory()->getLabel(); ?>" title="<?php echo $object->getCategory()->getLabel(); ?>" src="<?php echo Common::relativeUrlToAbsolute("/a/news_categories/" . $object->getCategory()->getFilename()); ?>"/><?php echo $object->getContent(true); ?></section>
75-
<footer>
76-
<?php if ($object->getEditedDateTime() !== null) { ?>
77-
<span class="float-right"><time datetime="<?php echo $object->getCreatedDateTime()->format('c'); ?>"><?php echo $object->getCreatedDateTime()->format("l, F j, Y"); ?></time> | Edited: <time datetime="<?php echo $object->getEditedDateTime()->format('c'); ?>"><?php echo $object->getEditedDateTime()->format("l, F j, Y"); ?></time></span>
78-
<?php } else { ?>
79-
<span class="float-right"><time datetime="<?php echo $object->getCreatedDateTime()->format('c'); ?>"><?php echo $object->getCreatedDateTime()->format("l, F j, Y"); ?></time></span>
80-
<?php } ?>
81-
<span><a href="<?php echo $user_url; ?>"><img class="avatar" src="<?php echo $user_avatar; ?>"/>&nbsp;<?php echo filter_var($user_name, FILTER_SANITIZE_STRING); ?></a></span>
82-
</footer>
83-
</article>
84-
<article class="container mb-3">
85-
<?php
51+
require_once('./MarkdownBootstrapFix.inc.php');
52+
require('./header.inc.phtml'); ?>
53+
<div class="container mb-3">
54+
<? if ($object) { ?>
55+
<? if ($draft) { ?>
56+
<div class="alert alert-warning">This news post is marked as <strong>draft</strong>. Edit the news post to <strong>publish</strong> it.</div>
57+
<? } ?>
58+
<span class="float-right">
59+
<? if ($edit_visible) { ?>
60+
<a class="btn btn-sm btn-secondary" href="<?=$edit_url?>" title="Edit">📝</a>
61+
<? } if ($delete_visible) { ?>
62+
<a class="btn btn-sm btn-danger" href="<?=$delete_url?>" title="Delete">❌</a>
63+
<? } ?>
64+
<a class="btn btn-sm btn-primary" href="https://facebook.com/sharer/sharer.php?u=<?=urlencode($url)?>" rel="external" data-popup="1"><img class="img-fluid" src="<?=Common::relativeUrlToAbsolute('/a/social-facebook-24px.png')?>"/></a>
65+
<a class="btn btn-sm btn-primary" href="https://twitter.com/share?text=<?=urlencode($title)?>&amp;url=<?=urlencode($url)?>" rel="external" data-popup="1"><img class="img-fluid" src="<?=Common::relativeUrlToAbsolute('/a/social-twitter-24px.png')?>"/></a>
66+
</span>
67+
<h1 class="display-4"><a href="<? echo $url; ?>"><? echo filter_var($title, FILTER_SANITIZE_STRING); ?></a></h1>
68+
<? if (!($object->getOptionsBitmask() & NewsPost::OPTION_PUBLISHED)) { ?>
69+
<section class="red"><p><strong>Warning:</strong> This news post is not yet published. You can view this because you are allowed to create, modify, or delete news posts.</p></section>
70+
<? } ?>
71+
<section class="news"><img class="category" alt="<? echo $object->getCategory()->getLabel(); ?>" title="<? echo $object->getCategory()->getLabel(); ?>" src="<? echo Common::relativeUrlToAbsolute("/a/news_categories/" . $object->getCategory()->getFilename()); ?>"/><? echo $object->getContent(true); ?></section>
72+
<footer>
73+
<? if ($object->getEditedDateTime() !== null) { ?>
74+
<span class="float-right"><time datetime="<? echo $object->getCreatedDateTime()->format('c'); ?>"><? echo $object->getCreatedDateTime()->format("l, F j, Y"); ?></time> | Edited: <time datetime="<? echo $object->getEditedDateTime()->format('c'); ?>"><? echo $object->getEditedDateTime()->format("l, F j, Y"); ?></time></span>
75+
<? } else { ?>
76+
<span class="float-right"><time datetime="<? echo $object->getCreatedDateTime()->format('c'); ?>"><? echo $object->getCreatedDateTime()->format("l, F j, Y"); ?></time></span>
77+
<? } ?>
78+
<span><a href="<? echo $user_url; ?>"><img class="avatar" src="<? echo $user_avatar; ?>"/>&nbsp;<? echo filter_var($user_name, FILTER_SANITIZE_STRING); ?></a></span>
79+
</footer>
80+
</div>
81+
<div class="container mb-3">
82+
<?
8683

8784
$comment_parent_type = Comment::PARENT_TYPE_NEWS_POST;
8885
require("./Comment/Section.inc.phtml");
8986

90-
} else { ?>
91-
<header class="red"><?php echo filter_var($title, FILTER_SANITIZE_STRING); ?></header>
92-
<section class="red"><?php echo filter_var($description, FILTER_SANITIZE_STRING); ?></section>
93-
<?php } ?>
94-
</article>
95-
<?php require("./footer.inc.phtml"); ?>
87+
} else { ?>
88+
<header class="red"><? echo filter_var($title, FILTER_SANITIZE_STRING); ?></header>
89+
<section class="red"><? echo filter_var($description, FILTER_SANITIZE_STRING); ?></section>
90+
<? } ?>
91+
</div>
92+
<? require("./footer.inc.phtml"); ?>

src/templates/Packet/View.phtml

+2-2
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@ require('./header.inc.phtml'); ?>
103103
</tbody></table>
104104

105105
<h2>Remarks</h2>
106-
<? echo $object->getPacketRemarks(true); ?>
106+
<div class="container"><? echo $object->getPacketRemarks(true); ?></div>
107107

108-
<div class="card"><div class="card-body">
108+
<div class="card mt-3"><div class="card-body">
109109
<span class="float-right text-muted">
110110
<time datetime="<?=$created_dt->format('c')?>"><?=$created_dt->format('l, F j, Y')?></time>
111111
<? if ($edited_dt) { ?>

src/templates/header.inc.phtml

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ function _header_nav_html($nav)
138138
$acl_news_modify = (Authentication::$user && (Authentication::$user->getOptionsBitmask() & User::OPTION_ACL_NEWS_MODIFY));
139139
foreach ($recent_news as $news)
140140
{
141-
if (!$news->isPublished() && !$acl_neews_modify) continue;
141+
if (!$news->isPublished() && !$acl_news_modify) continue;
142142
$news_class = ($news->isPublished() ? '' : ' text-warning');
143143
_line('<a class="dropdown-item%s" href="%s">%s</a>', $news_class, $news->getURI(), filter_var($news->getTitle(), FILTER_SANITIZE_FULL_SPECIAL_CHARS));
144144
}

0 commit comments

Comments
 (0)