diff options
Diffstat (limited to 'application/Utils.php')
-rw-r--r-- | application/Utils.php | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/application/Utils.php b/application/Utils.php index 925e1a22..bcfda65c 100644 --- a/application/Utils.php +++ b/application/Utils.php | |||
@@ -87,18 +87,22 @@ function endsWith($haystack, $needle, $case = true) | |||
87 | * | 87 | * |
88 | * @param mixed $input Data to escape: a single string or an array of strings. | 88 | * @param mixed $input Data to escape: a single string or an array of strings. |
89 | * | 89 | * |
90 | * @return string escaped. | 90 | * @return string|array escaped. |
91 | */ | 91 | */ |
92 | function escape($input) | 92 | function escape($input) |
93 | { | 93 | { |
94 | if (is_bool($input)) { | 94 | if (null === $input) { |
95 | return null; | ||
96 | } | ||
97 | |||
98 | if (is_bool($input) || is_int($input) || is_float($input) || $input instanceof DateTimeInterface) { | ||
95 | return $input; | 99 | return $input; |
96 | } | 100 | } |
97 | 101 | ||
98 | if (is_array($input)) { | 102 | if (is_array($input)) { |
99 | $out = array(); | 103 | $out = array(); |
100 | foreach ($input as $key => $value) { | 104 | foreach ($input as $key => $value) { |
101 | $out[$key] = escape($value); | 105 | $out[escape($key)] = escape($value); |
102 | } | 106 | } |
103 | return $out; | 107 | return $out; |
104 | } | 108 | } |
@@ -159,10 +163,10 @@ function checkDateFormat($format, $string) | |||
159 | */ | 163 | */ |
160 | function generateLocation($referer, $host, $loopTerms = array()) | 164 | function generateLocation($referer, $host, $loopTerms = array()) |
161 | { | 165 | { |
162 | $finalReferer = '?'; | 166 | $finalReferer = './?'; |
163 | 167 | ||
164 | // No referer if it contains any value in $loopCriteria. | 168 | // No referer if it contains any value in $loopCriteria. |
165 | foreach ($loopTerms as $value) { | 169 | foreach (array_filter($loopTerms) as $value) { |
166 | if (strpos($referer, $value) !== false) { | 170 | if (strpos($referer, $value) !== false) { |
167 | return $finalReferer; | 171 | return $finalReferer; |
168 | } | 172 | } |
@@ -294,15 +298,15 @@ function normalize_spaces($string) | |||
294 | * Requires php-intl to display international datetimes, | 298 | * Requires php-intl to display international datetimes, |
295 | * otherwise default format '%c' will be returned. | 299 | * otherwise default format '%c' will be returned. |
296 | * | 300 | * |
297 | * @param DateTime $date to format. | 301 | * @param DateTimeInterface $date to format. |
298 | * @param bool $time Displays time if true. | 302 | * @param bool $time Displays time if true. |
299 | * @param bool $intl Use international format if true. | 303 | * @param bool $intl Use international format if true. |
300 | * | 304 | * |
301 | * @return bool|string Formatted date, or false if the input is invalid. | 305 | * @return bool|string Formatted date, or false if the input is invalid. |
302 | */ | 306 | */ |
303 | function format_date($date, $time = true, $intl = true) | 307 | function format_date($date, $time = true, $intl = true) |
304 | { | 308 | { |
305 | if (! $date instanceof DateTime) { | 309 | if (! $date instanceof DateTimeInterface) { |
306 | return false; | 310 | return false; |
307 | } | 311 | } |
308 | 312 | ||