diff options
author | ArthurHoaro <arthur@hoa.ro> | 2016-02-05 16:10:26 +0100 |
---|---|---|
committer | ArthurHoaro <arthur@hoa.ro> | 2016-02-05 16:10:34 +0100 |
commit | f1e96a06d8471dd10b730bf89747665eb4595211 (patch) | |
tree | 6fe1eb10f9f10b6e5d793251397144531d328342 | |
parent | 268a2e52659964fb7d033a1bb4d1490bf8cc49bf (diff) | |
download | Shaarli-f1e96a06d8471dd10b730bf89747665eb4595211.tar.gz Shaarli-f1e96a06d8471dd10b730bf89747665eb4595211.tar.zst Shaarli-f1e96a06d8471dd10b730bf89747665eb4595211.zip |
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.
-rw-r--r-- | index.php | 20 |
1 files changed, 17 insertions, 3 deletions
@@ -1203,11 +1203,25 @@ function renderPage() | |||
1203 | 1203 | ||
1204 | // We sort tags alphabetically, then choose a font size according to count. | 1204 | // We sort tags alphabetically, then choose a font size according to count. |
1205 | // First, find max value. | 1205 | // First, find max value. |
1206 | $maxcount=0; foreach($tags as $key=>$value) $maxcount=max($maxcount,$value); | 1206 | $maxcount = 0; |
1207 | ksort($tags); | 1207 | foreach ($tags as $value) { |
1208 | $maxcount = max($maxcount, $value); | ||
1209 | } | ||
1210 | |||
1211 | // Sort tags alphabetically: case insensitive, support locale if avalaible. | ||
1212 | uksort($tags, function($a, $b) { | ||
1213 | // Collator is part of PHP intl. | ||
1214 | if (class_exists('Collator')) { | ||
1215 | $c = new Collator(setlocale(LC_ALL, 0)); | ||
1216 | return $c->compare($a, $b); | ||
1217 | } else { | ||
1218 | return strcasecmp($a, $b); | ||
1219 | } | ||
1220 | }); | ||
1221 | |||
1208 | $tagList=array(); | 1222 | $tagList=array(); |
1209 | foreach($tags as $key=>$value) | 1223 | foreach($tags as $key=>$value) |
1210 | // Tag font size scaling: default 15 and 30 logarithm bases affect scaling, 22 and 6 are arbitrary font sizes for max and min sizes. | 1224 | // Tag font size scaling: default 15 and 30 logarithm bases affect scaling, 22 and 6 are arbitrary font sizes for max and min sizes. |
1211 | { | 1225 | { |
1212 | $tagList[$key] = array('count'=>$value,'size'=>log($value, 15) / log($maxcount, 30) * (22-6) + 6); | 1226 | $tagList[$key] = array('count'=>$value,'size'=>log($value, 15) / log($maxcount, 30) * (22-6) + 6); |
1213 | } | 1227 | } |