1 | <?php |
||
10 | trait Strings |
||
11 | { |
||
12 | /** |
||
13 | * Encrypt string |
||
14 | * |
||
15 | * NOTICE: the code in general, this method in particular, comes with absolutely no warranty. If security is |
||
16 | * important for you, then use a purpose built package. https://github.com/defuse/php-encryption seems like |
||
17 | * a good candidate. |
||
18 | * @deprecated Do not trust a two-line encryption-method. |
||
19 | * |
||
20 | * @throws Exception if extension mcrypt is not loaded. |
||
21 | * |
||
22 | * @param string $string String to encrypt |
||
23 | * @param string $key Key to encrypt/decrypt. |
||
24 | * @return string Encrypted string |
||
25 | */ |
||
26 | public static function encrypt($string, $key) |
||
44 | |||
45 | /** |
||
46 | * Decrypt string |
||
47 | * |
||
48 | * NOTICE: the code in general, this method in particular, comes with absolutely no warranty. If security is |
||
49 | * important for you, then use a purpose built package. https://github.com/defuse/php-encryption seems like |
||
50 | * a good candidate. |
||
51 | * @deprecated Do not trust a two-line decryption-method. |
||
52 | * |
||
53 | * @param string $string String to decrypt |
||
54 | * @param string $key Key to encrypt/decrypt. |
||
55 | * @return string Decrypted string |
||
56 | */ |
||
57 | public static function decrypt($string, $key) |
||
76 | |||
77 | /** |
||
78 | * Obfuscate string (url-safe and somewhat hard to guess). |
||
79 | * |
||
80 | * @param string $input The text that should be obfuscated |
||
81 | * @return string Obfuscated string |
||
82 | */ |
||
83 | public static function obfuscateString($input) |
||
87 | |||
88 | /** |
||
89 | * Deobfuscate string |
||
90 | * |
||
91 | * @param string $input Obfuscated string |
||
92 | * @return string Deobfuscated string |
||
93 | */ |
||
94 | public static function deobfuscateString($input) |
||
98 | |||
99 | /** |
||
100 | * Convert <textarea> to [textarea]. |
||
101 | * |
||
102 | * @param string $html |
||
103 | * @return string |
||
104 | */ |
||
105 | public static function textareaEncode($html) |
||
109 | |||
110 | /** |
||
111 | * Convert [textarea] to <textarea>. |
||
112 | * |
||
113 | * @param string $html |
||
114 | * @return string |
||
115 | */ |
||
116 | public static function textareaDecode($html) |
||
120 | |||
121 | /** |
||
122 | * To replace "Hallo [@var] world" with $value. |
||
123 | * |
||
124 | * Example: |
||
125 | * ```php |
||
126 | * replace_string($string, array("val1" => "foo", "val2" => "bar")) |
||
127 | * ``` |
||
128 | * |
||
129 | * @param string $langString String containing placeholder. |
||
130 | * @param array $dynamicContent key->value array. |
||
131 | * @return string String with placeholder replaced. |
||
132 | */ |
||
133 | public static function replaceString($langString, $dynamicContent = array()) |
||
140 | |||
141 | /** |
||
142 | * Creates rainbow-colored text. |
||
143 | * |
||
144 | * @uses Holt45::colorBlend() |
||
145 | * @uses Holt45::rgbhex() |
||
146 | * |
||
147 | * @param string $text Text wanted coloured. |
||
148 | * @return string String with span-tags with color. |
||
149 | */ |
||
150 | public static function rainbowText($text) |
||
199 | |||
200 | /** |
||
201 | * Get the symbol from a list of keyboard-keys... |
||
202 | * |
||
203 | * @used-by Holt45::kbdShortcut() |
||
204 | * |
||
205 | * @param string $inputKey Text |
||
206 | * @param string $inputOperatingSystem default|auto|win|mac|linux |
||
207 | * @return null|string HTML Entity (decimal) |
||
208 | */ |
||
209 | public static function kbdSymbol($inputKey, $inputOperatingSystem = "default") |
||
279 | |||
280 | /** |
||
281 | * Show fancy buttons for keyboard-shortcuts. |
||
282 | * |
||
283 | * @uses Holt45::kbdSymbol() |
||
284 | * |
||
285 | * @param array $inputArrayKeys |
||
286 | * @param string $inputOperatingSystem |
||
287 | * @param string $inputKbdClass |
||
288 | * @param string $inputKbdSymbolClass |
||
289 | * @param string $inputJoinGlue Glue |
||
290 | * @return string String of html |
||
291 | */ |
||
292 | public static function kbdShortcut( |
||
317 | |||
318 | /** |
||
319 | * Attempting to keep CSS on one line with scoped style. |
||
320 | * |
||
321 | * NOTICE: This is a rough estimate, font type, design, etc affects the results. |
||
322 | * |
||
323 | * @param string $text |
||
324 | * @param string $cssSelector |
||
325 | * @param int $fontSizePx |
||
326 | * @param int $minPageWidthPx |
||
327 | * @return null|string Scoped style |
||
328 | */ |
||
329 | public static function cssOneLineText($text, $cssSelector = "h1", $fontSizePx = 36, $minPageWidthPx = 320) |
||
349 | } |
||
350 |
Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.