@@ -14,23 +14,36 @@ $this->opengraph->attach(new Pair("url", "/news"));
1414$ this ->additional_css [] = "/a/news.css " ;
1515require ("./header.inc.phtml " );
1616
17- $ avatars = [];
18- $ getAvatar = function (&$ avatars , $ user_id ) {
19- if (isset ($ avatars [$ user_id ])) {
20- return $ avatars [$ user_id ];
21- }
22- $ avatars [$ user_id ] = new Gravatar ((new User ($ user_id ))->getEmail ());
23- return $ avatars [$ user_id ];
24- };
17+ $ news_posts = $ this ->getContext ()->news_posts ;
18+ $ pagination = $ this ->getContext ()->pagination ;
2519
26- $ users = [];
27- foreach ($ this ->context ->news_posts as $ news_post ) {
28- $ url = Common::relativeUrlToAbsolute ("/news/ " . urlencode ($ news_post ->getId ()));
29- $ url .= "/ " . Common::sanitizeForUrl ($ news_post ->getTitle (), true );
30- $ user_id = $ news_post ->getUserId ();
31- $ avatar = "https: " . $ getAvatar ($ avatars , $ user_id )->getUrl (22 , "identicon " );
32- if (!isset ($ users [$ user_id ])) $ users [$ user_id ] = new User ($ user_id );
20+ if (is_null ($ news_posts ) || empty ($ news_posts )) {
3321?>
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 {
30+
31+ $ avatars = [];
32+ $ getAvatar = function (&$ avatars , $ user_id ) {
33+ if (isset ($ avatars [$ user_id ])) {
34+ return $ avatars [$ user_id ];
35+ }
36+ $ avatars [$ user_id ] = new Gravatar ((new User ($ user_id ))->getEmail ());
37+ return $ avatars [$ user_id ];
38+ };
39+
40+ $ users = [];
41+ foreach ($ this ->getContext ()->news_posts as $ news_post ) {
42+ $ url = Common::relativeUrlToAbsolute ("/news/ " . urlencode ($ news_post ->getId ()));
43+ $ url .= "/ " . Common::sanitizeForUrl ($ news_post ->getTitle (), true );
44+ $ user_id = $ news_post ->getUserId ();
45+ $ avatar = "https: " . $ getAvatar ($ avatars , $ user_id )->getUrl (22 , "identicon " );
46+ if (!isset ($ users [$ user_id ])) $ users [$ user_id ] = new User ($ user_id ); ?>
3447 <article>
3548 <a href="https://plus.google.com/share?url=<?php echo urlencode ($ url ); ?> " rel="external" data-popup="1"><img class="social-btn float-right" src="<?php echo Common::relativeUrlToAbsolute ("/a/social-gplus-24px.png " ); ?> "/></a>
3649 <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="social-btn float-right" src="<?php echo Common::relativeUrlToAbsolute ("/a/social-twitter-24px.png " ); ?> "/></a>
@@ -46,4 +59,33 @@ foreach ($this->context->news_posts as $news_post) {
4659 </footer>
4760 </article>
4861<?php }
62+ }
63+ if ($ pagination ) {
64+ $ page_current = $ pagination ->currentPage ();
65+ $ page_count = $ pagination ->pageCount ();
66+ $ page_prev = ($ page_current > 0 ? $ page_current + 0 : false );
67+ $ page_next = ($ page_current + 1 < $ page_count ? $ page_current + 2 : false );
68+ ?>
69+ <p class="pagination">
70+ <?php
71+ if ($ page_prev ) { ?>
72+ <a href="<?php echo Common::relativeUrlToAbsolute (
73+ "/news?page= " . urlencode ($ page_prev )
74+ ); ?> "><</a>
75+ <?php
76+ }
77+ for ($ i = 1 ; $ i <= $ page_count ; ++$ i ) {
78+ ?>
79+ <a<?php if ($ i - 1 == $ page_current ) { ?> class="active"<?php }
80+ ?> href="<?php echo Common::relativeUrlToAbsolute (
81+ "/news?page= " . urlencode ($ i )
82+ ); ?> "><?php echo $ i ; ?> </a>
83+ <?php }
84+ if ($ page_next ) { ?>
85+ <a href="<?php echo Common::relativeUrlToAbsolute (
86+ "/news?page= " . urlencode ($ page_next )
87+ ); ?> ">></a>
88+ <?php } ?>
89+ </p>
90+ <?php }
4991require ("./footer.inc.phtml " ); ?>
0 commit comments