diff options
Diffstat (limited to 'application/Utils.php')
-rw-r--r-- | application/Utils.php | 32 |
1 files changed, 26 insertions, 6 deletions
diff --git a/application/Utils.php b/application/Utils.php index 3d819716..da521cce 100644 --- a/application/Utils.php +++ b/application/Utils.php | |||
@@ -41,8 +41,14 @@ function smallHash($text) | |||
41 | 41 | ||
42 | /** | 42 | /** |
43 | * Tells if a string start with a substring | 43 | * Tells if a string start with a substring |
44 | * | ||
45 | * @param string $haystack Given string. | ||
46 | * @param string $needle String to search at the beginning of $haystack. | ||
47 | * @param bool $case Case sensitive. | ||
48 | * | ||
49 | * @return bool True if $haystack starts with $needle. | ||
44 | */ | 50 | */ |
45 | function startsWith($haystack, $needle, $case=true) | 51 | function startsWith($haystack, $needle, $case = true) |
46 | { | 52 | { |
47 | if ($case) { | 53 | if ($case) { |
48 | return (strcmp(substr($haystack, 0, strlen($needle)), $needle) === 0); | 54 | return (strcmp(substr($haystack, 0, strlen($needle)), $needle) === 0); |
@@ -52,8 +58,14 @@ function startsWith($haystack, $needle, $case=true) | |||
52 | 58 | ||
53 | /** | 59 | /** |
54 | * Tells if a string ends with a substring | 60 | * Tells if a string ends with a substring |
61 | * | ||
62 | * @param string $haystack Given string. | ||
63 | * @param string $needle String to search at the end of $haystack. | ||
64 | * @param bool $case Case sensitive. | ||
65 | * | ||
66 | * @return bool True if $haystack ends with $needle. | ||
55 | */ | 67 | */ |
56 | function endsWith($haystack, $needle, $case=true) | 68 | function endsWith($haystack, $needle, $case = true) |
57 | { | 69 | { |
58 | if ($case) { | 70 | if ($case) { |
59 | return (strcmp(substr($haystack, strlen($haystack) - strlen($needle)), $needle) === 0); | 71 | return (strcmp(substr($haystack, strlen($haystack) - strlen($needle)), $needle) === 0); |
@@ -63,14 +75,22 @@ function endsWith($haystack, $needle, $case=true) | |||
63 | 75 | ||
64 | /** | 76 | /** |
65 | * Htmlspecialchars wrapper | 77 | * Htmlspecialchars wrapper |
78 | * Support multidimensional array of strings. | ||
66 | * | 79 | * |
67 | * @param string $str the string to escape. | 80 | * @param mixed $input Data to escape: a single string or an array of strings. |
68 | * | 81 | * |
69 | * @return string escaped. | 82 | * @return string escaped. |
70 | */ | 83 | */ |
71 | function escape($str) | 84 | function escape($input) |
72 | { | 85 | { |
73 | return htmlspecialchars($str, ENT_COMPAT, 'UTF-8', false); | 86 | if (is_array($input)) { |
87 | $out = array(); | ||
88 | foreach($input as $key => $value) { | ||
89 | $out[$key] = escape($value); | ||
90 | } | ||
91 | return $out; | ||
92 | } | ||
93 | return htmlspecialchars($input, ENT_COMPAT, 'UTF-8', false); | ||
74 | } | 94 | } |
75 | 95 | ||
76 | /** | 96 | /** |
@@ -226,7 +246,7 @@ function space2nbsp($text) | |||
226 | * | 246 | * |
227 | * @return string formatted description. | 247 | * @return string formatted description. |
228 | */ | 248 | */ |
229 | function format_description($description, $redirector) { | 249 | function format_description($description, $redirector = false) { |
230 | return nl2br(space2nbsp(text2clickable($description, $redirector))); | 250 | return nl2br(space2nbsp(text2clickable($description, $redirector))); |
231 | } | 251 | } |
232 | 252 | ||