Fixes #456: Tag cloud does not sort tags (fully) alphabetically

* Use Collator class to sort tags using the locale (in PECL intl, included in most PHP installation).
  * Use strcasecmp if Collator is not found.

Both sorts are case insensitive.
This commit is contained in:
ArthurHoaro 2016-02-05 16:10:26 +01:00
parent 268a2e5265
commit f1e96a06d8

View file

@ -1203,8 +1203,22 @@ function renderPage()
// We sort tags alphabetically, then choose a font size according to count. // We sort tags alphabetically, then choose a font size according to count.
// First, find max value. // First, find max value.
$maxcount=0; foreach($tags as $key=>$value) $maxcount=max($maxcount,$value); $maxcount = 0;
ksort($tags); foreach ($tags as $value) {
$maxcount = max($maxcount, $value);
}
// Sort tags alphabetically: case insensitive, support locale if avalaible.
uksort($tags, function($a, $b) {
// Collator is part of PHP intl.
if (class_exists('Collator')) {
$c = new Collator(setlocale(LC_ALL, 0));
return $c->compare($a, $b);
} else {
return strcasecmp($a, $b);
}
});
$tagList=array(); $tagList=array();
foreach($tags as $key=>$value) foreach($tags as $key=>$value)
// Tag font size scaling: default 15 and 30 logarithm bases affect scaling, 22 and 6 are arbitrary font sizes for max and min sizes. // Tag font size scaling: default 15 and 30 logarithm bases affect scaling, 22 and 6 are arbitrary font sizes for max and min sizes.