From 30bc167c9e15f7ca90151e1a00e9f8beb0856d43 Mon Sep 17 00:00:00 2001 From: plegall Date: Wed, 28 May 2008 22:39:06 +0000 Subject: feature 828 added: display tags by letters. Users can switch from "cloud" to "letters" with a button in the top bar. git-svn-id: http://piwigo.org/svn/trunk@2362 68402e56-0260-453c-a942-63ccdbb3a9ee --- tags.php | 100 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 97 insertions(+), 3 deletions(-) (limited to 'tags.php') diff --git a/tags.php b/tags.php index 60c575121..28ce3177c 100644 --- a/tags.php +++ b/tags.php @@ -58,13 +58,107 @@ $page['body_id'] = 'theTagsPage'; $template->set_filenames(array('tags'=>'tags.tpl')); -// +-----------------------------------------------------------------------+ -// | tag cloud construction | -// +-----------------------------------------------------------------------+ +$page['display_mode'] = $conf['tags_default_display_mode']; +if (isset($_GET['display_mode'])) +{ + if (in_array($_GET['display_mode'], array('cloud', 'letters'))) + { + $page['display_mode'] = $_GET['display_mode']; + } +} + +$template->assign( + array( + 'U_CLOUD' => get_root_url().'tags.php?display_mode=cloud', + 'U_LETTERS' => get_root_url().'tags.php?display_mode=letters', + 'display_mode' => $page['display_mode'], + ) + ); // find all tags available for the current user $tags = get_available_tags(); +// +-----------------------------------------------------------------------+ +// | letter groups construction | +// +-----------------------------------------------------------------------+ + +if ($page['display_mode'] == 'letters') { + // we want tags diplayed in alphabetic order + usort($tags, 'name_compare'); + + $current_letter = null; + $is_first_tag = true; + $nb_tags = count($tags); + $current_column_tags = 0; + + $letter = array( + 'tags' => array() + ); + + foreach ($tags as $tag) + { + $tag_letter = strtoupper(substr($tag['name'], 0, 1)); + + if ($is_first_tag) { + $current_letter = $tag_letter; + $letter['TITLE'] = $tag_letter; + $is_first_tag = false; + } + + //lettre precedente differente de la lettre suivante + if ($tag_letter !== $current_letter) + { + if ($current_column_tags > $nb_tags/$conf['tag_letters_column_number']) + { + $letter['CHANGE_COLUMN'] = true; + $current_column_tags = 0; + } + + $letter['TITLE'] = $current_letter; + + $template->append( + 'letters', + $letter + ); + + $current_letter = $tag_letter; + $letter = array( + 'tags' => array() + ); + } + + array_push( + $letter['tags'], + array( + 'URL' => make_index_url( + array( + 'tags' => array($tag), + ) + ), + 'NAME' => $tag['name'], + 'COUNTER' => $tag['counter'], + ) + ); + + $current_column_tags++; + } + + // flush last letter + if (count($letter['tags']) > 0) + { + $letter['CHANGE_COLUMN'] = false; + $letter['TITLE'] = $current_letter; + $template->append( + 'letters', + $letter + ); + } +} + +// +-----------------------------------------------------------------------+ +// | tag cloud construction | +// +-----------------------------------------------------------------------+ + // we want only the first most represented tags, so we sort them by counter // and take the first tags usort($tags, 'counter_compare'); -- cgit v1.2.3