diff options
author | ArthurHoaro <arthur@hoa.ro> | 2020-11-10 10:46:04 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-10 10:46:04 +0100 |
commit | 302662797cb5e8ac6579a99297ceae301f7927a6 (patch) | |
tree | 67f493a1cc6d3691742946f1d7e512bffe41e02f /application/Utils.php | |
parent | c94c32d1a3e86a479cb2582eadc668a5bb476fc6 (diff) | |
parent | 2f4df753041088d788d1923692a7d530167a6840 (diff) | |
download | Shaarli-302662797cb5e8ac6579a99297ceae301f7927a6.tar.gz Shaarli-302662797cb5e8ac6579a99297ceae301f7927a6.tar.zst Shaarli-302662797cb5e8ac6579a99297ceae301f7927a6.zip |
Merge pull request #1635 from ArthurHoaro/feature/phpcs
Diffstat (limited to 'application/Utils.php')
-rw-r--r-- | application/Utils.php | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/application/Utils.php b/application/Utils.php index db046893..952378ab 100644 --- a/application/Utils.php +++ b/application/Utils.php | |||
@@ -1,4 +1,5 @@ | |||
1 | <?php | 1 | <?php |
2 | |||
2 | /** | 3 | /** |
3 | * Shaarli utilities | 4 | * Shaarli utilities |
4 | */ | 5 | */ |
@@ -102,7 +103,7 @@ function escape($input) | |||
102 | } | 103 | } |
103 | 104 | ||
104 | if (is_array($input)) { | 105 | if (is_array($input)) { |
105 | $out = array(); | 106 | $out = []; |
106 | foreach ($input as $key => $value) { | 107 | foreach ($input as $key => $value) { |
107 | $out[escape($key)] = escape($value); | 108 | $out[escape($key)] = escape($value); |
108 | } | 109 | } |
@@ -163,7 +164,7 @@ function checkDateFormat($format, $string) | |||
163 | * | 164 | * |
164 | * @return string $referer - final referer. | 165 | * @return string $referer - final referer. |
165 | */ | 166 | */ |
166 | function generateLocation($referer, $host, $loopTerms = array()) | 167 | function generateLocation($referer, $host, $loopTerms = []) |
167 | { | 168 | { |
168 | $finalReferer = './?'; | 169 | $finalReferer = './?'; |
169 | 170 | ||
@@ -196,7 +197,7 @@ function generateLocation($referer, $host, $loopTerms = array()) | |||
196 | function autoLocale($headerLocale) | 197 | function autoLocale($headerLocale) |
197 | { | 198 | { |
198 | // Default if browser does not send HTTP_ACCEPT_LANGUAGE | 199 | // Default if browser does not send HTTP_ACCEPT_LANGUAGE |
199 | $locales = array('en_US', 'en_US.utf8', 'en_US.UTF-8'); | 200 | $locales = ['en_US', 'en_US.utf8', 'en_US.UTF-8']; |
200 | if (! empty($headerLocale)) { | 201 | if (! empty($headerLocale)) { |
201 | if (preg_match_all('/([a-z]{2,3})[-_]?([a-z]{2})?,?/i', $headerLocale, $matches, PREG_SET_ORDER)) { | 202 | if (preg_match_all('/([a-z]{2,3})[-_]?([a-z]{2})?,?/i', $headerLocale, $matches, PREG_SET_ORDER)) { |
202 | $attempts = []; | 203 | $attempts = []; |
@@ -376,13 +377,15 @@ function return_bytes($val) | |||
376 | return $val; | 377 | return $val; |
377 | } | 378 | } |
378 | $val = trim($val); | 379 | $val = trim($val); |
379 | $last = strtolower($val[strlen($val)-1]); | 380 | $last = strtolower($val[strlen($val) - 1]); |
380 | $val = intval(substr($val, 0, -1)); | 381 | $val = intval(substr($val, 0, -1)); |
381 | switch ($last) { | 382 | switch ($last) { |
382 | case 'g': | 383 | case 'g': |
383 | $val *= 1024; | 384 | $val *= 1024; |
385 | // do no break in order 1024^2 for each unit | ||
384 | case 'm': | 386 | case 'm': |
385 | $val *= 1024; | 387 | $val *= 1024; |
388 | // do no break in order 1024^2 for each unit | ||
386 | case 'k': | 389 | case 'k': |
387 | $val *= 1024; | 390 | $val *= 1024; |
388 | } | 391 | } |
@@ -482,7 +485,9 @@ function alphabetical_sort(&$data, $reverse = false, $byKeys = false) | |||
482 | */ | 485 | */ |
483 | function t($text, $nText = '', $nb = 1, $domain = 'shaarli', $variables = [], $fixCase = false) | 486 | function t($text, $nText = '', $nb = 1, $domain = 'shaarli', $variables = [], $fixCase = false) |
484 | { | 487 | { |
485 | $postFunction = $fixCase ? 'ucfirst' : function ($input) { return $input; }; | 488 | $postFunction = $fixCase ? 'ucfirst' : function ($input) { |
489 | return $input; | ||
490 | }; | ||
486 | 491 | ||
487 | return $postFunction(dn__($domain, $text, $nText, $nb, $variables)); | 492 | return $postFunction(dn__($domain, $text, $nText, $nb, $variables)); |
488 | } | 493 | } |
@@ -494,4 +499,3 @@ function exception2text(Throwable $e): string | |||
494 | { | 499 | { |
495 | return $e->getMessage() . PHP_EOL . $e->getFile() . $e->getLine() . PHP_EOL . $e->getTraceAsString(); | 500 | return $e->getMessage() . PHP_EOL . $e->getFile() . $e->getLine() . PHP_EOL . $e->getTraceAsString(); |
496 | } | 501 | } |
497 | |||