Browse Source

Support undefined messages

master
Skylar Ittner 8 months ago
parent
commit
cb3c8aaf2d
1 changed files with 28 additions and 22 deletions
  1. 28
    22
      app.php

+ 28
- 22
app.php View File

@@ -1,5 +1,4 @@
1 1
 <?php
2
-
3 2
 /* This Source Code Form is subject to the terms of the Mozilla Public
4 3
  * License, v. 2.0. If a copy of the MPL was not distributed with this
5 4
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
@@ -66,28 +65,35 @@ header("Link: <static/js/bootstrap.bundle.min.js>; rel=preload; as=script", fals
66 65
 
67 66
         <?php
68 67
 // Alert messages
69
-        if (isset($_GET['msg']) && !is_empty($_GET['msg']) && array_key_exists($_GET['msg'], MESSAGES)) {
70
-            // optional string generation argument
71
-            if (!isset($_GET['arg']) || is_empty($_GET['arg'])) {
72
-                $alertmsg = $Strings->get(MESSAGES[$_GET['msg']]['string'], false);
68
+        if (!empty($_GET['msg'])) {
69
+            if (array_key_exists($_GET['msg'], MESSAGES)) {
70
+                // optional string generation argument
71
+                if (!isset($_GET['arg']) || is_empty($_GET['arg'])) {
72
+                    $alertmsg = $Strings->get(MESSAGES[$_GET['msg']]['string'], false);
73
+                } else {
74
+                    $alertmsg = $Strings->build(MESSAGES[$_GET['msg']]['string'], ["arg" => strip_tags($_GET['arg'])], false);
75
+                }
76
+                $alerttype = MESSAGES[$_GET['msg']]['type'];
77
+                $alerticon = "square-o";
78
+                switch (MESSAGES[$_GET['msg']]['type']) {
79
+                    case "danger":
80
+                        $alerticon = "times";
81
+                        break;
82
+                    case "warning":
83
+                        $alerticon = "exclamation-triangle";
84
+                        break;
85
+                    case "info":
86
+                        $alerticon = "info-circle";
87
+                        break;
88
+                    case "success":
89
+                        $alerticon = "check";
90
+                        break;
91
+                }
73 92
             } else {
74
-                $alertmsg = $Strings->build(MESSAGES[$_GET['msg']]['string'], ["arg" => strip_tags($_GET['arg'])], false);
75
-            }
76
-            $alerttype = MESSAGES[$_GET['msg']]['type'];
77
-            $alerticon = "square-o";
78
-            switch (MESSAGES[$_GET['msg']]['type']) {
79
-                case "danger":
80
-                    $alerticon = "times";
81
-                    break;
82
-                case "warning":
83
-                    $alerticon = "exclamation-triangle";
84
-                    break;
85
-                case "info":
86
-                    $alerticon = "info-circle";
87
-                    break;
88
-                case "success":
89
-                    $alerticon = "check";
90
-                    break;
93
+                // We don't have a message for this, so just assume an error and escape stuff.
94
+                $alertmsg = htmlentities($Strings->get($_GET['msg'], false));
95
+                $alerticon = "times";
96
+                $alerttype = "danger";
91 97
             }
92 98
             echo <<<END
93 99
             <div class="row justify-content-center" id="msg-alert-box">

Loading…
Cancel
Save