|
1 |
| -<?php |
2 |
| - |
| 1 | +<?php /* vim: set colorcolumn=: */ |
3 | 2 | namespace BNETDocs\Templates\Packet;
|
4 |
| - |
5 | 3 | use \BNETDocs\Libraries\Packet;
|
6 | 4 | use \BNETDocs\Libraries\User;
|
7 | 5 | use \CarlBennett\MVC\Libraries\Common;
|
8 | 6 | use \CarlBennett\MVC\Libraries\Pair;
|
9 |
| - |
10 |
| -$title = 'Packet Index'; |
11 |
| -$description = 'The index for packets on BNETDocs'; |
| 7 | +$title = 'All Packets'; |
| 8 | +$description = 'The index for all of the packets documented on BNETDocs'; |
12 | 9 | $this->opengraph->attach(new Pair('url', '/packet/index'));
|
13 |
| - |
14 | 10 | $order = $this->getContext()->order;
|
| 11 | +$form_order_by = [ |
| 12 | + 'created-datetime-asc' => 'Created Timestamp (Ascending)', |
| 13 | + 'created-datetime-desc' => 'Created Timestamp (Descending)', |
| 14 | + 'id-asc' => 'Database Id (Ascending)', |
| 15 | + 'id-desc' => 'Database Id (Descending)', |
| 16 | + 'packet-id-asc' => 'Packet Id (Ascending)', |
| 17 | + 'packet-id-desc' => 'Packet Id (Descending)', |
| 18 | + 'user-id-asc' => 'User Id (Ascending)', |
| 19 | + 'user-id-desc' => 'User Id (Descending)', |
| 20 | +]; |
| 21 | +require('./header.inc.phtml'); ?> |
| 22 | +<div class="container mb-3"> |
| 23 | + <h2><?=$title?></h2> |
| 24 | + <p><?=$description?></p> |
| 25 | + <form method="GET" class="m-2" id="filter_form"> |
| 26 | + <div class="form-group" id="order_by_form"> |
| 27 | + <label for="order" class="font-weight-bold m-1">Order by:</label> |
| 28 | + <select class="form-control form-control-sm m-1" name="order" id="order" onchange="form.submit();" style="display:inline-block;width:200px;"> |
| 29 | +<? foreach ($form_order_by as $item_value => $item_label) { |
| 30 | + $item_selected = ($order === $item_value ? ' selected="selected"' : ''); |
| 31 | + echo sprintf('<option value="%s"%s>%s</option>' . PHP_EOL, $item_value, $item_selected, $item_label); |
| 32 | + } ?> |
| 33 | + </select> |
| 34 | + </div> |
| 35 | + <div class="form-group"> |
| 36 | + <table class="table d-inline-block"><thead><tr><th colspan="3" class="text-center">Packet Types</th></tr></thead><tbody> |
| 37 | +<? $x = 0; |
| 38 | + foreach ($this->getContext()->application_layers as $layer) |
| 39 | + { |
| 40 | + $id = 'pktapplayer-' . $layer->getId(); |
| 41 | + $chk = in_array($layer->getId(), $this->getContext()->pktapplayer); |
| 42 | + if ( $x % 3 == 0 ) { echo '<tr>'; } |
| 43 | + echo sprintf( |
| 44 | + '<td><div class="custom-control custom-switch"><input class="custom-control-input" type="checkbox" name="pktapplayer[]" id="%s" value="%s"%s><label class="custom-control-label" for="%s">%s</label></div></td>', |
| 45 | + $id, $layer->getId(), ($chk ? ' checked="checked"' : ''), $id, $layer->getTag() |
| 46 | + ); |
| 47 | + if ( $x % 3 == 2 ) { echo '</tr>'; } |
| 48 | + $x++; |
| 49 | + } |
| 50 | + if ( $x % 3 > 0 ) { echo '</tr>'; } ?> |
| 51 | + <tr><td colspan="3" class="text-center"><input class="btn btn-sm btn-secondary" type="submit" value="Set Filter"/></td></tr> |
| 52 | + </tbody></table> |
| 53 | + </div> |
| 54 | + </form> |
| 55 | + <table class="table table-hover table-striped" id="packets_tbl"> |
| 56 | + <thead><tr><th>Packet</th><th>Author</th></tr></thead><tbody> |
| 57 | +<? foreach ($this->getContext()->packets as $packet) |
| 58 | + { |
| 59 | + $user = $packet->getUser(); |
| 60 | + if ($user) |
| 61 | + { |
| 62 | + $avatar_url = $user->getAvatarURI(22); |
| 63 | + $user_url = $user->getURI(); |
| 64 | + } |
| 65 | + $deprecated = $packet->isDeprecated(); |
| 66 | + $packet_id = $packet->getPacketId(true); |
| 67 | + $published = $packet->isPublished(); |
| 68 | + $research = $packet->isInResearch(); |
15 | 69 |
|
16 |
| -require('./header.inc.phtml'); |
17 |
| -?> |
18 |
| - <article> |
19 |
| - <header>Packet Index</header> |
20 |
| - <section> |
21 |
| - <form method="GET"> |
22 |
| - <div style="text-align:center;"> |
23 |
| - <label for="order">Order by:</label> |
24 |
| - <select name="order" id="order" onchange="form.submit();" |
25 |
| - style="display:inline-block;width:200px;"> |
26 |
| - <option value="created-datetime-asc"<?php |
27 |
| - if ($order === 'created-datetime-asc') { echo ' selected="selected"'; |
28 |
| - } ?>>Created Timestamp (Ascending)</option> |
29 |
| - <option value="created-datetime-desc"<?php |
30 |
| - if ($order === 'created-datetime-desc') { echo ' selected="selected"'; |
31 |
| - } ?>>Created Timestamp (Descending)</option> |
32 |
| - <option value="id-asc"<?php |
33 |
| - if ($order === 'id-asc') { echo ' selected="selected"'; |
34 |
| - } ?>>Database Id (Ascending)</option> |
35 |
| - <option value="id-desc"<?php |
36 |
| - if ($order === 'id-desc') { echo ' selected="selected"'; |
37 |
| - } ?>>Database Id (Descending)</option> |
38 |
| - <option value="packet-id-asc"<?php |
39 |
| - if ($order === 'packet-id-asc') { echo ' selected="selected"'; |
40 |
| - } ?>>Packet Id (Ascending)</option> |
41 |
| - <option value="packet-id-desc"<?php |
42 |
| - if ($order === 'packet-id-desc') { echo ' selected="selected"'; |
43 |
| - } ?>>Packet Id (Descending)</option> |
44 |
| - <option value="user-id-asc"<?php |
45 |
| - if ($order === 'user-id-asc') { echo ' selected="selected"'; |
46 |
| - } ?>>User Id (Ascending)</option> |
47 |
| - <option value="user-id-desc"<?php |
48 |
| - if ($order === 'user-id-desc') { echo ' selected="selected"'; |
49 |
| - } ?>>User Id (Descending)</option> |
50 |
| - </select> |
51 |
| - </div> |
52 |
| - <table><thead><tr><th colspan="6">Packet Types</th></tr></thead><tbody> |
53 |
| -<?php $x = 0; foreach ($this->getContext()->application_layers as $layer) { |
54 |
| - $id = 'pktapplayer-' . $layer->getId(); |
55 |
| - $chk = in_array( $layer->getId(), $this->getContext()->pktapplayer ); |
56 |
| - if ( $x % 3 == 0 ) { ?> |
57 |
| - <tr> |
58 |
| -<?php } ?> |
59 |
| - <td style="width:20px;"><input type="checkbox" name="pktapplayer[]" id="<?php echo $id; ?>" value="<?php echo $layer->getId(); ?>"<?php if ($chk) { ?> checked="checked"<?php } ?>></td><td><label style="display:inline-block;" for="<?php echo $id; ?>"><?php echo $layer->getTag(); ?></label></td> |
60 |
| -<?php if ( $x % 3 == 2 ) { ?> |
61 |
| - </tr> |
62 |
| -<?php } ?> |
63 |
| -<?php $x++; } ?> |
64 |
| -<?php if ( $x % 3 > 0 ) { ?> |
65 |
| - </tr> |
66 |
| -<?php } ?> |
67 |
| - </tbody></table> |
68 |
| - <div style="text-align:center;"><input type="submit" value="Submit"/></div> |
69 |
| - </form> |
70 |
| - <hr/> |
71 |
| - <table> |
72 |
| - <thead> |
73 |
| - <tr> |
74 |
| - <th class="left">Packet</th> |
75 |
| - <th class="left">Author</th> |
76 |
| - </tr> |
77 |
| - </thead><tbody> |
78 |
| -<?php foreach ($this->getContext()->packets as $packet) { |
79 |
| - $user = $packet->getUser(); |
80 |
| - if ($user) { |
81 |
| - $user_url = $user->getURI(); |
82 |
| - $avatar_url = $user->getAvatarURI(22); |
83 |
| - } |
84 |
| - $packet_id = $packet->getPacketId(true); |
85 |
| - $deprecated = $packet->isDeprecated(); |
86 |
| - $research = $packet->isInResearch(); |
87 |
| - $published = $packet->isPublished(); |
88 |
| - |
89 |
| - ob_start(); |
90 |
| - if ($deprecated) require('./Deprecated.inc.phtml'); |
91 |
| - if ($research) require('./InResearch.inc.phtml'); |
92 |
| - if (!$published) require('./Draft.inc.phtml'); |
93 |
| - $tpl_packet_flags = ob_get_clean(); |
94 |
| - if (!empty($tpl_packet_flags)) $tpl_packet_flags = ' ' . $tpl_packet_flags; |
95 |
| -?> |
96 |
| - <tr> |
97 |
| - <td><strong><a href="<?php echo $packet->getURI(); ?>"><?php echo filter_var($packet->getPacketDirectionTag() . " " . $packet_id . " " . $packet->getPacketName(), FILTER_SANITIZE_STRING); ?></a></strong><?=$tpl_packet_flags?><br/><span style="color:#aaa;"><?php echo rtrim(Common::stripUpTo(Common::stripUpTo(trim(filter_var($packet->getPacketRemarks(true), FILTER_SANITIZE_STRING)), "\n", 90), ". ", 90), "."); ?></span></td> |
98 |
| - <td><?php if ($user) { ?><a href="<?php echo $user_url; ?>"><img class="avatar" src="<?php echo $avatar_url; ?>"/> <?php echo filter_var($user->getName(), FILTER_SANITIZE_STRING); ?></a><?php } else { ?>Anonymous<?php } ?></td> |
99 |
| - </tr> |
100 |
| -<?php } ?> |
101 |
| - </tbody></table> |
| 70 | + ob_start(); |
| 71 | + if ($deprecated) require('./Deprecated.inc.phtml'); |
| 72 | + if ($research) require('./InResearch.inc.phtml'); |
| 73 | + if (!$published) require('./Draft.inc.phtml'); |
| 74 | + $tpl_packet_flags = ob_get_clean(); |
| 75 | + if (!empty($tpl_packet_flags)) $tpl_packet_flags = ' ' . $tpl_packet_flags; ?> |
| 76 | + <tr> |
| 77 | + <td><strong><a href="<? echo $packet->getURI(); ?>"><? echo filter_var($packet->getPacketDirectionTag() . " " . $packet_id . " " . $packet->getPacketName(), FILTER_SANITIZE_STRING); ?></a></strong><?=$tpl_packet_flags?><br/><span style="color:#aaa;"><? echo rtrim(Common::stripUpTo(Common::stripUpTo(trim(filter_var($packet->getPacketRemarks(true), FILTER_SANITIZE_STRING)), "\n", 90), ". ", 90), "."); ?></span></td> |
| 78 | + <td><? if ($user) { ?><a href="<? echo $user_url; ?>"><img class="avatar" src="<? echo $avatar_url; ?>"/> <? echo filter_var($user->getName(), FILTER_SANITIZE_STRING); ?></a><? } else { ?>Anonymous<? } ?></td> |
| 79 | + </tr> |
| 80 | +<? } ?> |
| 81 | + </tbody></table> |
102 | 82 | </section>
|
103 | 83 | <section>
|
104 | 84 | <p>These packets are also available as constants in
|
105 |
| -<?php $q = getenv('QUERY_STRING'); if (!empty($q)) { $q = '?' . $q; } ?> |
106 |
| - <a href="<?php echo Common::relativeUrlToAbsolute('/packet/index.cpp' . $q); ?>">C++</a>, |
107 |
| - <a href="<?php echo Common::relativeUrlToAbsolute('/packet/index.java' . $q); ?>">Java</a>, |
108 |
| - <a href="<?php echo Common::relativeUrlToAbsolute('/packet/index.json' . $q); ?>">JSON</a>, |
109 |
| - <a href="<?php echo Common::relativeUrlToAbsolute('/packet/index.php' . $q); ?>">PHP</a>, and |
110 |
| - <a href="<?php echo Common::relativeUrlToAbsolute('/packet/index.vb' . $q); ?>">VB6</a>. |
| 85 | +<? $q = getenv('QUERY_STRING'); if (!empty($q)) { $q = '?' . $q; } ?> |
| 86 | + <a href="<? echo Common::relativeUrlToAbsolute('/packet/index.cpp' . $q); ?>">C++</a>, |
| 87 | + <a href="<? echo Common::relativeUrlToAbsolute('/packet/index.java' . $q); ?>">Java</a>, |
| 88 | + <a href="<? echo Common::relativeUrlToAbsolute('/packet/index.json' . $q); ?>">JSON</a>, |
| 89 | + <a href="<? echo Common::relativeUrlToAbsolute('/packet/index.php' . $q); ?>">PHP</a>, and |
| 90 | + <a href="<? echo Common::relativeUrlToAbsolute('/packet/index.vb' . $q); ?>">VB6</a>. |
111 | 91 | </p>
|
112 | 92 | </section>
|
113 | 93 | </article>
|
114 |
| -<?php require("./footer.inc.phtml"); ?> |
| 94 | +<? ob_start(); ?> |
| 95 | + <script type="text/javascript"> |
| 96 | + $(document).ready(function(){ |
| 97 | + $('#order_by_form').hide(); |
| 98 | + $('#packets_tbl').DataTable({ |
| 99 | + "language": {"zeroRecords": "No matching packets found"}, |
| 100 | + "responsive": true, |
| 101 | + }); |
| 102 | + }); |
| 103 | + </script> |
| 104 | +<? $_footer_script = ob_get_clean(); require('./footer.inc.phtml'); ?> |
0 commit comments