aboutsummaryrefslogtreecommitdiffhomepage
path: root/application/Utils.php
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2017-05-25 15:28:26 +0200
committerGitHub <noreply@github.com>2017-05-25 15:28:26 +0200
commit81a91579ba8eb7b5a203722baf927a3653b5cb94 (patch)
tree228456f9b4d95d03e97fc9bc1b5004aa599f95ee /application/Utils.php
parent8b27824338eb445d69730c9b05f05b131ccea52f (diff)
parent82e3bb5f06dc531ee1080a0313833791a1c1f3c7 (diff)
downloadShaarli-81a91579ba8eb7b5a203722baf927a3653b5cb94.tar.gz
Shaarli-81a91579ba8eb7b5a203722baf927a3653b5cb94.tar.zst
Shaarli-81a91579ba8eb7b5a203722baf927a3653b5cb94.zip
Merge pull request #835 from ArthurHoaro/feature/tag-cloud
Adds a taglist view with edit/delete buttons
Diffstat (limited to 'application/Utils.php')
-rw-r--r--application/Utils.php31
1 files changed, 31 insertions, 0 deletions
diff --git a/application/Utils.php b/application/Utils.php
index ab463af9..9d0ebc5e 100644
--- a/application/Utils.php
+++ b/application/Utils.php
@@ -435,3 +435,34 @@ function get_max_upload_size($limitPost, $limitUpload, $format = true)
435 $maxsize = min($size1, $size2); 435 $maxsize = min($size1, $size2);
436 return $format ? human_bytes($maxsize) : $maxsize; 436 return $format ? human_bytes($maxsize) : $maxsize;
437} 437}
438
439/**
440 * Sort the given array alphabetically using php-intl if available.
441 * Case sensitive.
442 *
443 * Note: doesn't support multidimensional arrays
444 *
445 * @param array $data Input array, passed by reference
446 * @param bool $reverse Reverse sort if set to true
447 * @param bool $byKeys Sort the array by keys if set to true, by value otherwise.
448 */
449function alphabetical_sort(&$data, $reverse = false, $byKeys = false)
450{
451 $callback = function($a, $b) use ($reverse) {
452 // Collator is part of PHP intl.
453 if (class_exists('Collator')) {
454 $collator = new Collator(setlocale(LC_COLLATE, 0));
455 if (!intl_is_failure(intl_get_error_code())) {
456 return $collator->compare($a, $b) * ($reverse ? -1 : 1);
457 }
458 }
459
460 return strcasecmp($a, $b) * ($reverse ? -1 : 1);
461 };
462
463 if ($byKeys) {
464 uksort($data, $callback);
465 } else {
466 usort($data, $callback);
467 }
468}