|
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 \BNETDocs\Libraries\Comment;
|
6 | 4 | use \BNETDocs\Libraries\NewsPost;
|
7 | 5 | use \BNETDocs\Libraries\User;
|
8 | 6 | use \CarlBennett\MVC\Libraries\Common;
|
9 | 7 | 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; |
15 | 12 | $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)); |
16 | 17 |
|
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 | +{ |
29 | 20 | $url = $object->getURI();
|
30 | 21 |
|
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'))); |
33 | 24 | 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'))); |
35 | 26 | }
|
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())); |
38 | 29 |
|
39 | 30 | }
|
40 | 31 |
|
41 |
| -$this->opengraph->attach(new Pair("url", $url)); |
| 32 | +$this->opengraph->attach(new Pair('url', $url)); |
42 | 33 |
|
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)); |
45 | 36 | $edit_visible = ($logged_in && ($logged_in->getOptionsBitmask()
|
46 | 37 | & User::OPTION_ACL_NEWS_MODIFY));
|
47 | 38 | $delete_visible = ($logged_in && ($logged_in->getOptionsBitmask()
|
48 | 39 | & User::OPTION_ACL_NEWS_DELETE));
|
49 | 40 |
|
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); |
56 | 49 | }
|
57 | 50 |
|
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()); ?>&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; ?>"/> <?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)?>&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; ?>"/> <? echo filter_var($user_name, FILTER_SANITIZE_STRING); ?></a></span> |
| 79 | + </footer> |
| 80 | +</div> |
| 81 | +<div class="container mb-3"> |
| 82 | +<? |
86 | 83 |
|
87 | 84 | $comment_parent_type = Comment::PARENT_TYPE_NEWS_POST;
|
88 | 85 | require("./Comment/Section.inc.phtml");
|
89 | 86 |
|
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"); ?> |
0 commit comments