1
- <?php
2
-
1
+ <?php /* vim: set colorcolumn= expandtab shiftwidth=2 softtabstop=2 tabstop=4 smarttab: */
3
2
namespace BNETDocs \Templates ;
4
-
5
3
use \BNETDocs \Libraries \NewsPost ;
6
4
use \BNETDocs \Libraries \User ;
7
-
8
5
use \CarlBennett \MVC \Libraries \Common ;
9
6
use \CarlBennett \MVC \Libraries \Pair ;
10
-
11
- $ title = "News " ;
12
- $ description = "BNETDocs News " ;
13
- $ this ->opengraph ->attach (new Pair ("url " , "/news " ));
14
-
15
- require ("./header.inc.phtml " );
7
+ $ title = 'News ' ;
8
+ $ description = 'BNETDocs News ' ;
9
+ $ this ->opengraph ->attach (new Pair ('url ' , '/news ' ));
10
+ require ('./header.inc.phtml ' );
16
11
17
12
$ news_posts = $ this ->getContext ()->news_posts ;
18
13
$ pagination = $ this ->getContext ()->pagination ;
19
14
20
- if (is_null ($ news_posts ) || empty ($ news_posts )) {
21
- ?>
22
- <article>
23
- <header class="red">No News Found</header>
24
- <section class="red">
25
- <p>There are no news posts to view at this time.</p>
26
- </section>
27
- </article>
28
- <?php
29
- } else {
15
+ if (is_null ($ news_posts ) || empty ($ news_posts )) { ?>
16
+ <div class="container mb-3">
17
+ <div class="alert alert-danger">
18
+ <h1>No News Found</h1>
19
+ <p class="mb-0">There are no news posts to view at this time.</p>
20
+ </div>
21
+ </div>
22
+ <? } else {
30
23
31
24
$ active_user = $ this ->getContext ()->active_user ;
32
25
$ edit_visible = ($ active_user && ($ active_user ->getOptionsBitmask ()
@@ -35,64 +28,65 @@ if (is_null($news_posts) || empty($news_posts)) {
35
28
& User::OPTION_ACL_NEWS_DELETE ));
36
29
37
30
$ users = [];
38
- foreach ($ this ->getContext ()->news_posts as $ news_post ) {
31
+ foreach ($ this ->getContext ()->news_posts as $ news_post )
32
+ {
33
+ $ news_post_title = $ news_post ->getTitle ();
34
+ $ created_dt = $ news_post ->getCreatedDateTime ();
35
+ $ edited_dt = $ news_post ->getEditedDateTime ();
39
36
$ url = $ news_post ->getURI ();
40
- $ edit_url = Common::relativeUrlToAbsolute (" /news/edit?id= " . urlencode ($ news_post ->getId ()));
41
- $ delete_url = Common::relativeUrlToAbsolute (" /news/delete?id= " . urlencode ($ news_post ->getId ()));
37
+ $ edit_url = Common::relativeUrlToAbsolute (' /news/edit?id= ' . urlencode ($ news_post ->getId ()));
38
+ $ delete_url = Common::relativeUrlToAbsolute (' /news/delete?id= ' . urlencode ($ news_post ->getId ()));
42
39
$ user_id = $ news_post ->getUserId ();
43
40
if (!isset ($ users [$ user_id ])) $ users [$ user_id ] = new User ($ user_id );
44
41
$ avatar = $ users [$ user_id ]->getAvatarURI (22 ); ?>
45
- <article>
46
- <a href="https://twitter.com/share?text=<?php echo urlencode ($ news_post ->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>
47
- <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>
48
- <?php if ($ edit_visible ) { ?>
49
- <a href="<?php echo $ edit_url ; ?> " class="header-button float-right">Edit</a>
50
- <?php } ?>
51
- <?php if ($ delete_visible ) { ?>
52
- <a href="<?php echo $ delete_url ; ?> " class="header-button float-right">Delete</a>
53
- <?php } ?>
54
- <header><a href="<?php echo $ url ; ?> "><?php echo $ news_post ->getTitle (); ?> </a></header>
55
- <?php if (!($ news_post ->getOptionsBitmask () & NewsPost::OPTION_PUBLISHED )) { ?>
56
- <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>
57
- <?php } ?>
58
- <section class="news"><img class="category" alt="<?php echo $ news_post ->getCategory ()->getLabel (); ?> " title="<?php echo $ news_post ->getCategory ()->getLabel (); ?> " src="<?php echo Common::relativeUrlToAbsolute ("/a/news_categories/ " . $ news_post ->getCategory ()->getFilename ()); ?> "/><?php echo $ news_post ->getContent (true ); ?> </section>
59
- <footer>
60
- <?php if ($ news_post ->getEditedDateTime () !== null ) { ?>
61
- <span class="float-right"><time datetime="<?php echo $ news_post ->getCreatedDateTime ()->format ('c ' ); ?> "><?php echo $ news_post ->getCreatedDateTime ()->format ("l, F j, Y " ); ?> </time> | Edited: <time datetime="<?php echo $ news_post ->getEditedDateTime ()->format ('c ' ); ?> "><?php echo $ news_post ->getEditedDateTime ()->format ("l, F j, Y " ); ?> </time></span>
62
- <?php } else { ?>
63
- <span class="float-right"><time datetime="<?php echo $ news_post ->getCreatedDateTime ()->format ('c ' ); ?> "><?php echo $ news_post ->getCreatedDateTime ()->format ("l, F j, Y " ); ?> </time></span>
64
- <?php } ?>
65
- <span><a href="<?php echo $ users [$ user_id ]->getURI (); ?> "><img class="avatar" src="<?php echo $ avatar ; ?> "/> <?php echo htmlspecialchars ($ users [$ user_id ]->getName (), ENT_HTML5 , "UTF-8 " ); ?> </a></span>
66
- </footer>
67
- </article>
68
- <?php }
42
+ <div class="container mb-3">
43
+ <span class="float-right">
44
+ <? if ($ edit_visible ) { ?>
45
+ <a class="btn btn-sm btn-secondary" href="<?= $ edit_url?> " title="Edit">📝</a>
46
+ <? } if ($ delete_visible ) { ?>
47
+ <a class="btn btn-sm btn-danger" href="<?= $ delete_url?> " title="Delete">❌</a>
48
+ <? } ?>
49
+ <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>
50
+ <a class="btn btn-sm btn-primary" href="https://twitter.com/share?text=<?= urlencode ($ news_post_title )?> &url=<?= urlencode ($ url )?> " rel="external" data-popup="1"><img class="img-fluid" src="<?= Common::relativeUrlToAbsolute ('/a/social-twitter-24px.png ' )?> "/></a>
51
+ </span>
52
+ <h1><a href="<?= $ url?> "><?= filter_var ($ news_post_title , FILTER_SANITIZE_FULL_SPECIAL_CHARS )?> </a></h1>
53
+ <? if (!($ news_post ->getOptionsBitmask () & NewsPost::OPTION_PUBLISHED )) { ?>
54
+ <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>
55
+ <? } ?>
56
+ <section class="news"><img class="category" alt="<? echo $ news_post ->getCategory ()->getLabel (); ?> " title="<? echo $ news_post ->getCategory ()->getLabel (); ?> " src="<? echo Common::relativeUrlToAbsolute ("/a/news_categories/ " . $ news_post ->getCategory ()->getFilename ()); ?> "/><? echo $ news_post ->getContent (true ); ?> </section>
57
+ <div class="card"><div class="card-body">
58
+ <span class="float-right text-muted">
59
+ <time datetime="<?= $ created_dt ->format ('c ' )?> "><?= $ created_dt ->format ('l, F j, Y ' )?> </time>
60
+ <? if ($ edited_dt ) { ?>
61
+ | <strong>Edited:</strong> <time datetime="<?= $ edited_dt ->format ('c ' )?> "><?= $ edited_dt ->format ('l, F j, Y ' ); ?> </time>
62
+ <? } ?>
63
+ </span>
64
+ <? echo ($ users [$ user_id ] ?
65
+ sprintf ('<a href="%s"><img class="img-fluid rounded mr-2" src="%s"/>%s</a> ' ,
66
+ $ users [$ user_id ]->getURI (), $ users [$ user_id ]->getAvatarURI (40 ), filter_var ($ users [$ user_id ]->getName (), FILTER_SANITIZE_FULL_SPECIAL_CHARS )
67
+ ) : 'Anonymous '
68
+ ); ?>
69
+ </div></div>
70
+ </div>
71
+ <? }
69
72
}
70
73
if ($ pagination ) {
71
74
$ page_current = $ pagination ->currentPage ();
72
75
$ page_count = $ pagination ->pageCount ();
73
76
$ page_prev = ($ page_current > 0 ? $ page_current + 0 : false );
74
77
$ page_next = ($ page_current + 1 < $ page_count ? $ page_current + 2 : false );
75
78
?>
76
- <p class="pagination">
77
- <?php
78
- if ($ page_prev ) { ?>
79
- <a href="<?php echo Common::relativeUrlToAbsolute (
80
- "/news?page= " . urlencode ($ page_prev )
81
- ); ?> "><</a>
82
- <?php
83
- }
84
- for ($ i = 1 ; $ i <= $ page_count ; ++$ i ) {
85
- ?>
86
- <a<?php if ($ i - 1 == $ page_current ) { ?> class="active"<?php }
87
- ?> href="<?php echo Common::relativeUrlToAbsolute (
88
- "/news?page= " . urlencode ($ i )
89
- ); ?> "><?php echo $ i ; ?> </a>
90
- <?php }
91
- if ($ page_next ) { ?>
92
- <a href="<?php echo Common::relativeUrlToAbsolute (
93
- "/news?page= " . urlencode ($ page_next )
94
- ); ?> ">></a>
95
- <?php } ?>
96
- </p>
97
- <?php }
98
- require ("./footer.inc.phtml " ); ?>
79
+ <div class="container mb-3">
80
+ <nav aria-label="User list navigation" class="d-flex justify-content-center">
81
+ <ul class="pagination">
82
+ <? if ($ page_prev ) { ?>
83
+ <li class="page-item"><a class="page-link" href="<?= Common::relativeUrlToAbsolute ('/news?page= ' . urlencode ($ page_prev ))?> "><</a></li>
84
+ <? } for ($ i = 1 ; $ i <= $ page_count ; ++$ i ) { ?>
85
+ <li class="page-item disabled"><a class="page-link<?= ($ i - 1 == $ page_current ? ' active ' : '' )?> " href="<? echo Common::relativeUrlToAbsolute ('/news?page= ' . urlencode ($ i ))?> "><?= $ i?> </a></li>
86
+ <? } if ($ page_next ) { ?>
87
+ <li class="page-item"><a class="page-link" href="<?= Common::relativeUrlToAbsolute ('/news?page= ' . urlencode ($ page_next ))?> ">></a></li>
88
+ <? } ?>
89
+ </ul>
90
+ </nav>
91
+ </div>
92
+ <? } require ('./footer.inc.phtml ' ); ?>
0 commit comments