44
55use \BNETDocs \Libraries \Common ;
66use \BNETDocs \Libraries \Controller ;
7- use \BNETDocs \Libraries \Packet ;
87use \BNETDocs \Libraries \Exceptions \UnspecifiedViewException ;
98use \BNETDocs \Libraries \Gravatar ;
9+ use \BNETDocs \Libraries \Packet ;
10+ use \BNETDocs \Libraries \Pair ;
1011use \BNETDocs \Libraries \Router ;
1112use \BNETDocs \Libraries \UserSession ;
1213use \BNETDocs \Models \Packet \Index as PacketIndexModel ;
14+ use \BNETDocs \Views \Packet \IndexCpp as PacketIndexCppView ;
1315use \BNETDocs \Views \Packet \IndexHtml as PacketIndexHtmlView ;
1416use \BNETDocs \Views \Packet \IndexJSON as PacketIndexJSONView ;
17+ use \BNETDocs \Views \Packet \IndexJava as PacketIndexJavaView ;
18+ use \BNETDocs \Views \Packet \IndexPHP as PacketIndexPHPView ;
19+ use \BNETDocs \Views \Packet \IndexVB as PacketIndexVBView ;
1520use \DateTime ;
1621use \DateTimeZone ;
1722
1823class Index extends Controller {
1924
2025 public function run (Router &$ router ) {
2126 switch ($ router ->getRequestPathExtension ()) {
27+ case "cpp " :
28+ $ view = new PacketIndexCppView ();
29+ break ;
2230 case "htm " : case "html " : case "" :
2331 $ view = new PacketIndexHtmlView ();
2432 break ;
33+ case "java " :
34+ $ view = new PacketIndexJavaView ();
35+ break ;
2536 case "json " :
2637 $ view = new PacketIndexJSONView ();
2738 break ;
39+ case "php " :
40+ $ view = new PacketIndexPHPView ();
41+ break ;
42+ case "vb " :
43+ $ view = new PacketIndexVBView ();
44+ break ;
2845 default :
2946 throw new UnspecifiedViewException ();
3047 }
@@ -33,8 +50,8 @@ public function run(Router &$router) {
3350 $ model ->packets = Packet::getAllPackets ();
3451 $ model ->user_session = UserSession::load ($ router );
3552
36- // Alphabetically sort the packets for HTML
37- if ($ view instanceof PacketIndexHtmlView && $ model ->packets ) {
53+ // Alphabetically sort the packets for non-json
54+ if (! $ view instanceof PacketIndexJSONView && $ model ->packets ) {
3855 usort ($ model ->packets , function ($ a , $ b ){
3956 $ a1 = $ a ->getPacketApplicationLayerId ();
4057 $ b1 = $ b ->getPacketApplicationLayerId ();
@@ -65,9 +82,13 @@ public function run(Router &$router) {
6582 }
6683 }
6784
85+ // Include timestamp if non-html
86+ if (!$ view instanceof PacketIndexHtmlView) {
87+ $ model ->timestamp = new DateTime ("now " , new DateTimeZone ("UTC " ));
88+ }
89+
6890 // Objectify for JSON
6991 if ($ view instanceof PacketIndexJSONView) {
70- $ model ->timestamp = new DateTime ("now " , new DateTimeZone ("UTC " ));
7192 $ packets = [];
7293 foreach ($ model ->packets as $ packet ) {
7394 $ user = $ packet ->getUser ();
@@ -106,6 +127,17 @@ public function run(Router &$router) {
106127 $ model ->packets = $ packets ;
107128 }
108129
130+ // Remove duplicates if non-html and non-json
131+ if (!$ view instanceof PacketIndexHtmlView
132+ && !$ view instanceof PacketIndexJSONView) {
133+ $ packets = [];
134+ foreach ($ model ->packets as $ pkt ) {
135+ // This removes duplicates by overwriting keys that already exist.
136+ $ packets [$ pkt ->getPacketId ().$ pkt ->getPacketName ()] = $ pkt ;
137+ }
138+ $ model ->packets = $ packets ;
139+ }
140+
109141 // Post-filter summary of packets
110142 $ model ->sum_packets = count ($ model ->packets );
111143
0 commit comments