1
|
|
|
<?php |
2
|
|
|
namespace w3l\Holt45; |
3
|
|
|
trait Strings { |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Obfuscate string (url-safe and somewhat hard to guess). |
7
|
|
|
* |
8
|
|
|
* @param string $input The text that should be obfuscated |
9
|
|
|
* @return string Obfuscated string |
10
|
|
|
*/ |
11
|
|
|
public static function obfuscateString($input) { |
12
|
|
|
return bin2hex(base64_encode(strrev($input))); |
13
|
|
|
} |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Deobfuscate string |
17
|
|
|
* |
18
|
|
|
* @param string $input Obfuscated string |
19
|
|
|
* @return string Deobfuscated string |
20
|
|
|
*/ |
21
|
|
|
public static function deobfuscateString($input) { |
22
|
|
|
return strrev(base64_decode(hex2bin($input))); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Convert <textarea> to [textarea]. |
27
|
|
|
* |
28
|
|
|
* @param string $html |
29
|
|
|
* @return string |
30
|
|
|
*/ |
31
|
|
|
public static function textareaEncode($html) { |
32
|
|
|
return preg_replace("/<textarea(.*?)>(.*?)<\/textarea>/is", "[textarea$1]$2[/textarea]", $html); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Convert [textarea] to <textarea>. |
37
|
|
|
* |
38
|
|
|
* @param string $html |
39
|
|
|
* @return string |
40
|
|
|
*/ |
41
|
|
|
public static function textareaDecode($html) { |
42
|
|
|
return preg_replace("/\[textarea(.*?)\](.*?)\[\/textarea\]/is", "<textarea$1>$2</textarea>", $html); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* To replace "Hallo [@var] world" with $value. |
47
|
|
|
* |
48
|
|
|
* @example replace_string($string, array("val1" => "foo", "val2" => "bar")) |
49
|
|
|
* |
50
|
|
|
* @param string $langString String containing placeholder. |
51
|
|
|
* @param array $dynamicContent key->value array. |
52
|
|
|
* @return string String with placeholder replaced. |
53
|
|
|
*/ |
54
|
|
|
public static function replaceString($langString, $dynamicContent = array()) { |
55
|
|
|
|
56
|
|
|
foreach ($dynamicContent as $k => $v) { |
57
|
|
|
$langString = str_replace("[@".$k."]", $v, $langString); |
58
|
|
|
} |
59
|
|
|
return $langString; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
} |
63
|
|
|
|