1 | <?php |
||
10 | trait Strings |
||
11 | { |
||
12 | /** |
||
13 | * Obfuscate string (url-safe and somewhat hard to guess). |
||
14 | * |
||
15 | * @param string $input The text that should be obfuscated |
||
16 | * @return string Obfuscated string |
||
17 | */ |
||
18 | public static function obfuscateString($input) |
||
22 | |||
23 | /** |
||
24 | * Deobfuscate string |
||
25 | * |
||
26 | * @param string $input Obfuscated string |
||
27 | * @return string Deobfuscated string |
||
28 | */ |
||
29 | public static function deobfuscateString($input) |
||
33 | |||
34 | /** |
||
35 | * Convert <textarea> to [textarea]. |
||
36 | * |
||
37 | * @param string $html |
||
38 | * @return string |
||
39 | */ |
||
40 | public static function textareaEncode($html) |
||
44 | |||
45 | /** |
||
46 | * Convert [textarea] to <textarea>. |
||
47 | * |
||
48 | * @param string $html |
||
49 | * @return string |
||
50 | */ |
||
51 | public static function textareaDecode($html) |
||
55 | |||
56 | /** |
||
57 | * To replace "Hallo [@var] world" with $value. |
||
58 | * |
||
59 | * Example: |
||
60 | * ```php |
||
61 | * replace_string($string, array("val1" => "foo", "val2" => "bar")) |
||
62 | * ``` |
||
63 | * |
||
64 | * @param string $langString String containing placeholder. |
||
65 | * @param array $dynamicContent key->value array. |
||
66 | * @return string String with placeholder replaced. |
||
67 | */ |
||
68 | public static function replaceString($langString, $dynamicContent = array()) |
||
75 | |||
76 | /** |
||
77 | * Creates rainbow-colored text. |
||
78 | * |
||
79 | * @uses Holt45::colorBlend() |
||
80 | * @uses Holt45::rgbhex() |
||
81 | * |
||
82 | * @param string $text Text wanted coloured. |
||
83 | * @return string String with span-tags with color. |
||
84 | */ |
||
85 | public static function rainbowText($text) |
||
134 | |||
135 | /** |
||
136 | * Get the symbol from a list of keyboard-keys... |
||
137 | * |
||
138 | * @used-by Holt45::kbdShortcut() |
||
139 | * |
||
140 | * @param string $inputKey Text |
||
141 | * @param string $inputOperatingSystem default|auto|win|mac|linux |
||
142 | * @return null|string HTML Entity (decimal) |
||
143 | */ |
||
144 | public static function kbdSymbol($inputKey, $inputOperatingSystem = "default") |
||
145 | { |
||
146 | $inputKey = mb_strtolower($inputKey); |
||
147 | |||
148 | if ($inputOperatingSystem == "auto") { |
||
149 | |||
150 | $inputOperatingSystem = "default"; |
||
151 | |||
152 | $getClientOperatingSystem = self::getClientOperatingSystem(); |
||
|
|||
153 | |||
154 | if ($getClientOperatingSystem == "linux" || |
||
155 | $getClientOperatingSystem == "mac" || |
||
156 | $getClientOperatingSystem == "windows") { |
||
157 | $inputOperatingSystem = $getClientOperatingSystem; |
||
158 | } |
||
159 | } |
||
160 | |||
161 | $arrayConvert = array( |
||
162 | "return" => "enter", |
||
163 | "control" => "ctrl", |
||
164 | "escape" => "esc", |
||
165 | "caps lock" => "caps-lock", |
||
166 | "page up" => "page-up", |
||
167 | "page down" => "page-down", |
||
168 | "arrow left" => "arrow-left", |
||
169 | "left" => "arrow-left", |
||
170 | "arrow up" => "arrow-up", |
||
171 | "up" => "arrow-up", |
||
172 | "arrow right" => "arrow-right", |
||
173 | "right" => "arrow-right", |
||
174 | "arrow down" => "arrow-down", |
||
175 | "down" => "arrow-down" |
||
176 | ); |
||
177 | |||
178 | /* Convert input */ |
||
179 | if (array_key_exists($inputKey, $arrayConvert)) { |
||
180 | $inputKey = $arrayConvert[$inputKey]; |
||
181 | } |
||
182 | |||
183 | $arrayKeySymbols = array( |
||
184 | "shift" => array("default" => "⇧"), |
||
185 | "opt" => array("default" => "⌥"), |
||
186 | "enter" => array("default" => "⏎", "mac" => "⌤"), |
||
187 | "alt" => array("default" => "⎇", "mac" => "⌥"), |
||
188 | "delete" => array("default" => "⌫"), |
||
189 | "ctrl" => array("default" => "✲", "windows" => "✲", "linux" => "⎈", "mac" => "^"), |
||
190 | "esc" => array("default" => "⎋"), |
||
191 | "command" => array("default" => "⌘"), |
||
192 | "tab" => array("default" => "↹", "mac" => "⇥"), |
||
193 | "caps-lock" => array("default" => "A", "mac" => "⇪"), |
||
194 | "page-up" => array("default" => "▲", "mac" => "⇞"), |
||
195 | "page-down" => array("default" => "▼", "mac" => "⇟"), |
||
196 | "arrow-left" => array("default" => "←"), |
||
197 | "arrow-up" => array("default" => "↑"), |
||
198 | "arrow-right" => array("default" => "→"), |
||
199 | "arrow-down" => array("default" => "↓"), |
||
200 | // Sun |
||
201 | "compose" => array("default" => "⎄"), |
||
202 | "meta" => array("default" => "◆") |
||
203 | ); |
||
204 | |||
205 | if (array_key_exists($inputKey, $arrayKeySymbols)) { |
||
206 | |||
207 | return ((array_key_exists($inputOperatingSystem, $arrayKeySymbols[$inputKey])) ? |
||
208 | $arrayKeySymbols[$inputKey][$inputOperatingSystem] : |
||
209 | $arrayKeySymbols[$inputKey]["default"]); |
||
210 | } |
||
211 | |||
212 | return null; |
||
213 | } |
||
214 | |||
215 | /** |
||
216 | * Show fancy buttons for keyboard-shortcuts. |
||
217 | * |
||
218 | * @uses Holt45::kbdSymbol() |
||
219 | * |
||
220 | * @param array $inputArrayKeys |
||
221 | * @param string $inputOperatingSystem |
||
222 | * @param string $inputKbdClass |
||
223 | * @param string $inputKbdSymbolClass |
||
224 | * @param string $inputJoinGlue Glue |
||
225 | * @return string String of html |
||
226 | */ |
||
227 | public static function kbdShortcut( |
||
252 | |||
253 | /** |
||
254 | * Attempting to keep CSS on one line with scoped style. |
||
255 | * |
||
256 | * NOTICE: This is a rough estimate, font type, design, etc affects the results. |
||
257 | * |
||
258 | * @param string $text |
||
259 | * @param string $cssSelector |
||
260 | * @param int $fontSizePx |
||
261 | * @param int $minPageWidthPx |
||
262 | * @return null|string Scoped style |
||
263 | */ |
||
264 | public static function cssOneLineText($text, $cssSelector = "h1", $fontSizePx = 36, $minPageWidthPx = 320) |
||
284 | } |
||
285 |
Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.