File tree Expand file tree Collapse file tree 2 files changed +19
-3
lines changed
Expand file tree Collapse file tree 2 files changed +19
-3
lines changed Original file line number Diff line number Diff line change @@ -95,3 +95,18 @@ function str2int(string $x, ...$args): int
9595 throw new ValueError ("not digits: $ x " );
9696 }
9797}
98+
99+ /* example with 3 leading chars and 3 trailing chars: "foobarbaz" -> "foo...baz" */
100+ function shortenString (
101+ string $ x ,
102+ int $ leading_chars ,
103+ int $ trailing_chars ,
104+ string $ ellipsis = "... " ,
105+ ): string {
106+ if ($ leading_chars + strlen ($ ellipsis ) + $ trailing_chars > strlen ($ x )) {
107+ return $ x ;
108+ }
109+ return substr ($ x , 0 , $ leading_chars ) .
110+ $ ellipsis .
111+ substr ($ x , -1 * $ trailing_chars , $ trailing_chars );
112+ }
Original file line number Diff line number Diff line change 4242 }
4343 $ keys = array_map ("trim " , $ keys );
4444 foreach ($ keys as $ key ) {
45+ $ keyShort = shortenString ($ key , 10 , 10 );
4546 try {
4647 $ keyWasAdded = $ USER ->addSSHKey ($ key , $ OPERATOR );
4748 } catch (NoKeyLoadedException ) {
48- UnityHTTPD::messageError ("SSH Key Not Added: Invalid " , $ key );
49+ UnityHTTPD::messageError ("SSH Key Not Added: Invalid " , $ keyShort );
4950 UnityHTTPD::redirect ();
5051 }
5152 if ($ keyWasAdded ) {
52- UnityHTTPD::messageSuccess ("SSH Key Added " , $ key );
53+ UnityHTTPD::messageSuccess ("SSH Key Added " , $ keyShort );
5354 UnityHTTPD::redirect ();
5455 } else {
55- UnityHTTPD::messageInfo ("SSH Key Not Added: Already Exists " , $ key );
56+ UnityHTTPD::messageInfo ("SSH Key Not Added: Already Exists " , $ keyShort );
5657 UnityHTTPD::redirect ();
5758 }
5859 }
You can’t perform that action at this time.
0 commit comments