diff options
author | Arthur <arthur@hoa.ro> | 2016-02-15 21:26:33 +0100 |
---|---|---|
committer | Arthur <arthur@hoa.ro> | 2016-02-15 21:26:33 +0100 |
commit | 07c2f73543b358d39b3751c8542966794f28db03 (patch) | |
tree | efb806d69881a00ed2345d95322f840b07ab9433 /index.php | |
parent | 3a38c95d4232aed4a40f70eb11d26cafc9188bac (diff) | |
parent | f1e96a06d8471dd10b730bf89747665eb4595211 (diff) | |
download | Shaarli-07c2f73543b358d39b3751c8542966794f28db03.tar.gz Shaarli-07c2f73543b358d39b3751c8542966794f28db03.tar.zst Shaarli-07c2f73543b358d39b3751c8542966794f28db03.zip |
Merge pull request #461 from ArthurHoaro/tagcloud-sort
Fixes #456: Tag cloud does not sort tags (fully) alphabetically
Diffstat (limited to 'index.php')
-rw-r--r-- | index.php | 20 |
1 files changed, 17 insertions, 3 deletions
@@ -1229,11 +1229,25 @@ function renderPage() | |||
1229 | 1229 | ||
1230 | // We sort tags alphabetically, then choose a font size according to count. | 1230 | // We sort tags alphabetically, then choose a font size according to count. |
1231 | // First, find max value. | 1231 | // First, find max value. |
1232 | $maxcount=0; foreach($tags as $key=>$value) $maxcount=max($maxcount,$value); | 1232 | $maxcount = 0; |
1233 | ksort($tags); | 1233 | foreach ($tags as $value) { |
1234 | $maxcount = max($maxcount, $value); | ||
1235 | } | ||
1236 | |||
1237 | // Sort tags alphabetically: case insensitive, support locale if avalaible. | ||
1238 | uksort($tags, function($a, $b) { | ||
1239 | // Collator is part of PHP intl. | ||
1240 | if (class_exists('Collator')) { | ||
1241 | $c = new Collator(setlocale(LC_ALL, 0)); | ||
1242 | return $c->compare($a, $b); | ||
1243 | } else { | ||
1244 | return strcasecmp($a, $b); | ||
1245 | } | ||
1246 | }); | ||
1247 | |||
1234 | $tagList=array(); | 1248 | $tagList=array(); |
1235 | foreach($tags as $key=>$value) | 1249 | foreach($tags as $key=>$value) |
1236 | // Tag font size scaling: default 15 and 30 logarithm bases affect scaling, 22 and 6 are arbitrary font sizes for max and min sizes. | 1250 | // Tag font size scaling: default 15 and 30 logarithm bases affect scaling, 22 and 6 are arbitrary font sizes for max and min sizes. |
1237 | { | 1251 | { |
1238 | $tagList[$key] = array('count'=>$value,'size'=>log($value, 15) / log($maxcount, 30) * (22-6) + 6); | 1252 | $tagList[$key] = array('count'=>$value,'size'=>log($value, 15) / log($maxcount, 30) * (22-6) + 6); |
1239 | } | 1253 | } |