22
33namespace BNETDocs \Templates \Packet ;
44
5+ use \BNETDocs \Libraries \Comment ;
6+ use \BNETDocs \Libraries \User ;
57use \CarlBennett \MVC \Libraries \Common ;
68use \CarlBennett \MVC \Libraries \Pair ;
79
810$ comments = $ this ->getContext ()->comments ;
911$ object_id = $ this ->getContext ()->packet_id ;
1012$ object = $ this ->getContext ()->packet ;
1113
14+ $ logged_in = (
15+ isset ($ _SESSION ['user_id ' ]) ? new User ($ _SESSION ['user_id ' ]) : null
16+ );
17+ $ logged_in_id = ($ logged_in ? $ logged_in ->getId () : null );
18+
1219$ title = "Packet Not Found " ;
1320$ description = "The requested packet does not exist or could not be found. " ;
1421
@@ -21,9 +28,9 @@ if ($object) {
2128 $ url = $ object ->getURI ();
2229 $ packet_id = $ object ->getPacketId (true );
2330
24- $ title = htmlspecialchars ( $ object ->getPacketDirectionTag (), ENT_HTML5 , " UTF-8 " )
25- . " " . $ packet_id . " "
26- . htmlspecialchars ( $ object ->getPacketName (), ENT_HTML5 , " UTF-8 " );
31+ $ title = $ object ->getPacketDirectionTag () . ' '
32+ . $ packet_id . ' '
33+ . $ object ->getPacketName ();
2734
2835 $ description = Common::stripUpTo (trim (filter_var (
2936 $ object ->getPacketRemarks (true ), FILTER_SANITIZE_STRING
@@ -47,31 +54,32 @@ $this->opengraph->attach(new Pair("url", $url));
4754
4855$ this ->additional_css [] = "/a/packet.css " ;
4956$ this ->additional_css [] = "/a/comments.css " ;
57+ if ($ logged_in ) $ this ->additional_css [] = "/a/forms.css " ;
5058require ("./header.inc.phtml " );
5159?>
5260 <article>
5361<?php if ($ object ) { ?>
5462 <a href="https://plus.google.com/share?url=<?php echo urlencode ($ url ); ?> " rel="external" data-popup="1"><img class="header-button float-right" src="<?php echo Common::relativeUrlToAbsolute ("/a/social-gplus-24px.png " ); ?> "/></a>
5563 <a href="https://twitter.com/share?text=<?php echo urlencode ($ packet_id . " " . $ object ->getPacketName ()); ?> &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>
5664 <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>
57- <header><a href="<?php echo $ url ; ?> "><?php echo $ title ; ?> </a></header>
65+ <header><a href="<?php echo $ url ; ?> "><?php echo filter_var ( $ title, FILTER_SANITIZE_STRING ) ; ?> </a></header>
5866 <section>
5967 <table class="info"><tbody>
6068 <tr><th style="width:20%;">Message Id:</th><td><?php echo $ packet_id ; ?> </td></tr>
61- <tr><th>Message Name:</th><td><?php echo htmlspecialchars ($ object ->getPacketName (), ENT_HTML5 , " UTF-8 " ); ?> </td></tr>
62- <tr><th>Direction:</th><td><?php echo htmlspecialchars ($ object ->getPacketDirectionLabel (), ENT_HTML5 , " UTF-8 " ); ?> </td></tr>
69+ <tr><th>Message Name:</th><td><?php echo filter_var ($ object ->getPacketName (), FILTER_SANITIZE_STRING ); ?> </td></tr>
70+ <tr><th>Direction:</th><td><?php echo filter_var ($ object ->getPacketDirectionLabel (), FILTER_SANITIZE_STRING ); ?> </td></tr>
6371 <tr><th>Used By:</th><td><?php
6472 $ products = $ this ->getContext ()->used_by ;
6573 if (count ($ products ) == 1 ) {
66- echo htmlspecialchars ($ products [0 ]->getLabel (), ENT_HTML5 , " UTF-8 " );
74+ echo filter_var ($ products [0 ]->getLabel (), FILTER_SANITIZE_STRING );
6775 } else {
6876 $ j = count ($ this ->getContext ()->used_by );
6977 for ($ i = 0 ; $ i < $ j ; ++$ i ) {
70- echo htmlspecialchars ($ this ->getContext ()->used_by [$ i ]->getLabel (), ENT_HTML5 , " UTF-8 " );
78+ echo filter_var ($ this ->getContext ()->used_by [$ i ]->getLabel (), FILTER_SANITIZE_STRING );
7179 if ($ i + 1 < $ j ) {
7280 ++$ i ;
73- echo " , " ;
74- echo htmlspecialchars ($ this ->getContext ()->used_by [$ i ]->getLabel (), ENT_HTML5 , " UTF-8 " ) . "<br/> " ;
81+ echo ' , ' ;
82+ echo filter_var ($ this ->getContext ()->used_by [$ i ]->getLabel (), FILTER_SANITIZE_STRING ) . "<br/> " ;
7583 } else {
7684 echo "<br/> " ;
7785 }
@@ -92,7 +100,7 @@ require("./header.inc.phtml");
92100 <span class="float-right"><time datetime="<?php echo $ object ->getCreatedDateTime ()->format ('c ' ); ?> "><?php echo $ object ->getCreatedDateTime ()->format ("l, F j, Y " ); ?> </time></span>
93101<?php } ?>
94102<?php if ($ user_id !== null ) { ?>
95- <span class="float-left" ><a href="<?php echo $ user_url ; ?> "><img class="avatar" src="<?php echo $ user_avatar ; ?> "/> <?php echo htmlspecialchars ($ user_name , ENT_HTML5 , " UTF-8 " ); ?> </a></span>
103+ <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>
96104<?php } ?>
97105 </footer>
98106 </article>
@@ -101,23 +109,41 @@ require("./header.inc.phtml");
101109 <section>
102110<?php if (!$ comments ) { ?>
103111 <p class="center"><em>no one has commented yet.</em></p>
104- <?php } else { ?>
112+ <?php } else {
113+ $ c_edit_visible_master = ($ logged_in && ($ logged_in ->getOptionsBitmask () & User::OPTION_ACL_COMMENT_MODIFY ));
114+ $ c_delete_visible_master = ($ logged_in && ($ logged_in ->getOptionsBitmask () & User::OPTION_ACL_COMMENT_DELETE ));
115+ ?>
105116 <table class="comments"><tbody>
106117<?php foreach ($ comments as $ c ) {
107118 $ c_user = $ c ->getUser ();
108119 $ c_user_name = $ c_user ->getName ();
109120 $ c_user_id = $ c ->getUserId ();
110121 $ c_user_url = $ c_user ->getURI ();
111122 $ c_user_avatar = $ c_user ->getAvatarURI (22 );
123+
124+ $ c_edit_visible = ($ c_user_id == $ logged_in_id || $ c_edit_visible_master );
125+ $ c_delete_visible = ($ c_user_id == $ logged_in_id || $ c_delete_visible_master );
112126?>
113- <tr><td><a href="<?php echo $ c_user_url ; ?> "><img class="avatar" src="<?php echo $ c_user_avatar ; ?> "/> <?php echo htmlspecialchars ($ c_user_name , ENT_HTML5 , " UTF-8 " ); ?> </a><br/><time class="comment_timestamp" datetime="<?php echo $ c ->getCreatedDateTime ()->format ("c " ); ?> "><?php echo $ c ->getCreatedDateTime ()->format ("D M j, Y g:ia T " ); ?> </time></td><td><?php echo $ c ->getContent (true ); ?> </td></tr>
127+ <tr><td><a href="<?php echo $ c_user_url ; ?> "><img class="avatar" src="<?php echo $ c_user_avatar ; ?> "/> <?php echo filter_var ($ c_user_name , FILTER_SANITIZE_STRING ); ?> </a><br/><time class="comment_timestamp" datetime="<?php echo $ c ->getCreatedDateTime ()->format ("c " ); ?> "><?php echo $ c ->getCreatedDateTime ()->format ("D M j, Y g:ia T " ); ?> </time> <?php if ( $ c_delete_visible ) { ?> <a class="button comment_button" href=" <?php echo Common:: relativeUrlToAbsolute ( " /comment/delete?id= " . urlencode ( $ c_id )); ?> ">Delete</a> <?php } if ( $ c_edit_visible ) { ?> <a class="button comment_button" href=" <?php echo Common:: relativeUrlToAbsolute ( " /comment/edit?id= " . urlencode ( $ c_id )); ?> ">Edit</a> <?php } ? > </td><td><?php echo $ c ->getContent (true ); ?> </td></tr>
114128<?php } ?>
115129 </tbody></table>
116130<?php } ?>
117131 </section>
132+ <?php if ($ logged_in ) { ?>
133+ <section>
134+ <hr/>
135+ <form method="POST" action="<?php echo Common::relativeUrlToAbsolute ("/comment/create " ); ?> ">
136+ <input type="hidden" name="parent_type" value="<?php echo Comment::PARENT_TYPE_PACKET ; ?> "/>
137+ <input type="hidden" name="parent_id" value="<?php echo $ object_id ; ?> "/>
138+ <p class="center"><label for="comment-content">Comment on this post:</label></p>
139+ <p class="center"><textarea id="comment-content" name="content" cols="80" rows="5"></textarea></p>
140+ <p class="center"><input type="submit" value="Comment"/></p>
141+ </form>
142+ </section>
143+ <?php } ?>
118144<?php } else { ?>
119- <header class="red"><?php echo htmlspecialchars ($ title , ENT_HTML5 , " UTF-8 " ); ?> </header>
120- <section class="red"><?php echo htmlspecialchars ($ description , ENT_HTML5 , " UTF-8 " ); ?> </section>
145+ <header class="red"><?php echo filter_var ($ title , FILTER_SANITIZE_STRING ); ?> </header>
146+ <section class="red"><?php echo filter_var ($ description , FILTER_SANITIZE_STRING ); ?> </section>
121147<?php } ?>
122148 </article>
123149<?php require ("./footer.inc.phtml " ); ?>
0 commit comments