bug 2502 fixed: better handling of non-latin tags and multilanguage tags on

tags.php with mode letter.

We can't rely on url_name because it always start with "_" when the tag looks
like "[lang...". Instead we compute a str2url on the name, but once it has been
rendered by Extended Description. To avoid useless computations, I have added a
cache on the tag_alpha_compare function. Tested on a 175 tags set, speed is
good.


git-svn-id: http://piwigo.org/svn/branches/2.3@12760 68402e56-0260-453c-a942-63ccdbb3a9ee
This commit is contained in:
plegall
2011-12-17 22:51:20 +00:00
parent 7add07ee9f
commit f2ebe2bb57
2 changed files with 16 additions and 3 deletions

View File

@@ -294,7 +294,17 @@ function name_compare($a, $b)
function tag_alpha_compare($a, $b)
{
return strcmp(strtolower($a['url_name']), strtolower($b['url_name']));
global $page;
foreach (array($a, $b) as $tag)
{
if (!isset($page[__FUNCTION__.'_cache'][ $tag['name'] ]))
{
$page[__FUNCTION__.'_cache'][ $tag['name'] ] = strtolower(str2url($tag['name']));
}
}
return strcmp($page[__FUNCTION__.'_cache'][ $a['name'] ], $page[__FUNCTION__.'_cache'][ $b['name'] ]);
}
/**

View File

@@ -99,7 +99,7 @@ if ($page['display_mode'] == 'letters') {
foreach ($tags as $tag)
{
$tag_letter = strtoupper(substr($tag['url_name'], 0, 1));
$tag_letter = strtoupper(mb_substr(str2url($tag['name']), 0, 1, 'utf-8'));
if ($current_tag_idx==0) {
$current_letter = $tag_letter;
@@ -171,7 +171,10 @@ $tags = array_slice($tags, 0, $conf['full_tag_cloud_items_number']);
$tags = add_level_to_tags($tags);
// we want tags diplayed in alphabetic order
usort($tags, 'tag_alpha_compare');
if ('letters' != $page['display_mode'])
{
usort($tags, 'tag_alpha_compare');
}
// display sorted tags
foreach ($tags as $tag)