[1119] | 1 | <?php |
---|
| 2 | // +-----------------------------------------------------------------------+ |
---|
[8728] | 3 | // | Piwigo - a PHP based photo gallery | |
---|
[2297] | 4 | // +-----------------------------------------------------------------------+ |
---|
[12922] | 5 | // | Copyright(C) 2008-2012 Piwigo Team http://piwigo.org | |
---|
[2297] | 6 | // | Copyright(C) 2003-2008 PhpWebGallery Team http://phpwebgallery.net | |
---|
| 7 | // | Copyright(C) 2002-2003 Pierrick LE GALL http://le-gall.net/pierrick | |
---|
| 8 | // +-----------------------------------------------------------------------+ |
---|
| 9 | // | This program is free software; you can redistribute it and/or modify | |
---|
| 10 | // | it under the terms of the GNU General Public License as published by | |
---|
| 11 | // | the Free Software Foundation | |
---|
| 12 | // | | |
---|
| 13 | // | This program is distributed in the hope that it will be useful, but | |
---|
| 14 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
| 15 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
| 16 | // | General Public License for more details. | |
---|
| 17 | // | | |
---|
| 18 | // | You should have received a copy of the GNU General Public License | |
---|
| 19 | // | along with this program; if not, write to the Free Software | |
---|
| 20 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
| 21 | // | USA. | |
---|
| 22 | // +-----------------------------------------------------------------------+ |
---|
[1119] | 23 | |
---|
| 24 | // +-----------------------------------------------------------------------+ |
---|
| 25 | // | functions | |
---|
| 26 | // +-----------------------------------------------------------------------+ |
---|
| 27 | |
---|
| 28 | function counter_compare($a, $b) |
---|
| 29 | { |
---|
| 30 | if ($a['counter'] == $b['counter']) |
---|
| 31 | { |
---|
[1815] | 32 | return id_compare($a, $b); |
---|
[1119] | 33 | } |
---|
| 34 | |
---|
[1120] | 35 | return ($a['counter'] < $b['counter']) ? +1 : -1; |
---|
[1119] | 36 | } |
---|
| 37 | |
---|
[1815] | 38 | function id_compare($a, $b) |
---|
[1119] | 39 | { |
---|
[1815] | 40 | return ($a['id'] < $b['id']) ? -1 : 1; |
---|
[1119] | 41 | } |
---|
| 42 | |
---|
| 43 | // +-----------------------------------------------------------------------+ |
---|
| 44 | // | initialization | |
---|
| 45 | // +-----------------------------------------------------------------------+ |
---|
| 46 | |
---|
| 47 | define('PHPWG_ROOT_PATH','./'); |
---|
| 48 | include_once(PHPWG_ROOT_PATH.'include/common.inc.php'); |
---|
| 49 | |
---|
| 50 | check_status(ACCESS_GUEST); |
---|
| 51 | |
---|
| 52 | // +-----------------------------------------------------------------------+ |
---|
| 53 | // | page header and options | |
---|
| 54 | // +-----------------------------------------------------------------------+ |
---|
| 55 | |
---|
| 56 | $title= l10n('Tags'); |
---|
| 57 | $page['body_id'] = 'theTagsPage'; |
---|
| 58 | |
---|
| 59 | $template->set_filenames(array('tags'=>'tags.tpl')); |
---|
| 60 | |
---|
[2362] | 61 | $page['display_mode'] = $conf['tags_default_display_mode']; |
---|
| 62 | if (isset($_GET['display_mode'])) |
---|
| 63 | { |
---|
| 64 | if (in_array($_GET['display_mode'], array('cloud', 'letters'))) |
---|
| 65 | { |
---|
| 66 | $page['display_mode'] = $_GET['display_mode']; |
---|
| 67 | } |
---|
| 68 | } |
---|
| 69 | |
---|
[2478] | 70 | foreach (array('cloud', 'letters') as $mode) |
---|
| 71 | { |
---|
| 72 | $template->assign( |
---|
| 73 | 'U_'.strtoupper($mode), |
---|
| 74 | get_root_url().'tags.php'. ($conf['tags_default_display_mode']==$mode ? '' : '?display_mode='.$mode) |
---|
| 75 | ); |
---|
| 76 | } |
---|
[2362] | 77 | |
---|
[2478] | 78 | $template->assign( 'display_mode', $page['display_mode'] ); |
---|
| 79 | |
---|
[2362] | 80 | // find all tags available for the current user |
---|
| 81 | $tags = get_available_tags(); |
---|
| 82 | |
---|
[1119] | 83 | // +-----------------------------------------------------------------------+ |
---|
[2362] | 84 | // | letter groups construction | |
---|
| 85 | // +-----------------------------------------------------------------------+ |
---|
| 86 | |
---|
| 87 | if ($page['display_mode'] == 'letters') { |
---|
| 88 | // we want tags diplayed in alphabetic order |
---|
[2409] | 89 | usort($tags, 'tag_alpha_compare'); |
---|
[2362] | 90 | |
---|
| 91 | $current_letter = null; |
---|
| 92 | $nb_tags = count($tags); |
---|
[2409] | 93 | $current_column = 1; |
---|
| 94 | $current_tag_idx = 0; |
---|
[2362] | 95 | |
---|
| 96 | $letter = array( |
---|
| 97 | 'tags' => array() |
---|
| 98 | ); |
---|
| 99 | |
---|
| 100 | foreach ($tags as $tag) |
---|
| 101 | { |
---|
[17749] | 102 | $tag_letter = mb_strtoupper(mb_substr(transliterate($tag['name']), 0, 1, PWG_CHARSET), PWG_CHARSET); |
---|
[2362] | 103 | |
---|
[2409] | 104 | if ($current_tag_idx==0) { |
---|
[2362] | 105 | $current_letter = $tag_letter; |
---|
| 106 | $letter['TITLE'] = $tag_letter; |
---|
| 107 | } |
---|
| 108 | |
---|
| 109 | //lettre precedente differente de la lettre suivante |
---|
| 110 | if ($tag_letter !== $current_letter) |
---|
| 111 | { |
---|
[2409] | 112 | if ($current_column<$conf['tag_letters_column_number'] |
---|
| 113 | and $current_tag_idx > $current_column*$nb_tags/$conf['tag_letters_column_number'] ) |
---|
[2362] | 114 | { |
---|
| 115 | $letter['CHANGE_COLUMN'] = true; |
---|
[2409] | 116 | $current_column++; |
---|
[2362] | 117 | } |
---|
| 118 | |
---|
| 119 | $letter['TITLE'] = $current_letter; |
---|
| 120 | |
---|
| 121 | $template->append( |
---|
| 122 | 'letters', |
---|
| 123 | $letter |
---|
| 124 | ); |
---|
[2409] | 125 | |
---|
[2362] | 126 | $current_letter = $tag_letter; |
---|
| 127 | $letter = array( |
---|
| 128 | 'tags' => array() |
---|
| 129 | ); |
---|
| 130 | } |
---|
| 131 | |
---|
| 132 | array_push( |
---|
| 133 | $letter['tags'], |
---|
[2409] | 134 | array_merge( |
---|
| 135 | $tag, |
---|
| 136 | array( |
---|
| 137 | 'URL' => make_index_url( |
---|
| 138 | array( |
---|
| 139 | 'tags' => array($tag), |
---|
| 140 | ) |
---|
| 141 | ), |
---|
| 142 | ) |
---|
[2362] | 143 | ) |
---|
| 144 | ); |
---|
[2409] | 145 | |
---|
| 146 | $current_tag_idx++; |
---|
[2362] | 147 | } |
---|
| 148 | |
---|
| 149 | // flush last letter |
---|
| 150 | if (count($letter['tags']) > 0) |
---|
| 151 | { |
---|
[3145] | 152 | unset($letter['CHANGE_COLUMN']); |
---|
[2362] | 153 | $letter['TITLE'] = $current_letter; |
---|
| 154 | $template->append( |
---|
| 155 | 'letters', |
---|
| 156 | $letter |
---|
| 157 | ); |
---|
| 158 | } |
---|
| 159 | } |
---|
| 160 | |
---|
| 161 | // +-----------------------------------------------------------------------+ |
---|
[1119] | 162 | // | tag cloud construction | |
---|
| 163 | // +-----------------------------------------------------------------------+ |
---|
| 164 | |
---|
| 165 | // we want only the first most represented tags, so we sort them by counter |
---|
| 166 | // and take the first tags |
---|
| 167 | usort($tags, 'counter_compare'); |
---|
| 168 | $tags = array_slice($tags, 0, $conf['full_tag_cloud_items_number']); |
---|
| 169 | |
---|
| 170 | // depending on its counter and the other tags counter, each tag has a level |
---|
| 171 | $tags = add_level_to_tags($tags); |
---|
| 172 | |
---|
| 173 | // we want tags diplayed in alphabetic order |
---|
[12761] | 174 | if ('letters' != $page['display_mode']) |
---|
| 175 | { |
---|
| 176 | usort($tags, 'tag_alpha_compare'); |
---|
| 177 | } |
---|
[1119] | 178 | |
---|
| 179 | // display sorted tags |
---|
| 180 | foreach ($tags as $tag) |
---|
| 181 | { |
---|
[2223] | 182 | $template->append( |
---|
| 183 | 'tags', |
---|
[2409] | 184 | array_merge( |
---|
| 185 | $tag, |
---|
| 186 | array( |
---|
| 187 | 'URL' => make_index_url( |
---|
| 188 | array( |
---|
| 189 | 'tags' => array($tag), |
---|
| 190 | ) |
---|
| 191 | ), |
---|
| 192 | ) |
---|
[1119] | 193 | ) |
---|
| 194 | ); |
---|
| 195 | } |
---|
| 196 | |
---|
[10812] | 197 | // include menubar |
---|
| 198 | $themeconf = $template->get_template_vars('themeconf'); |
---|
[10824] | 199 | if (!isset($themeconf['hide_menu_on']) OR !in_array('theTagsPage', $themeconf['hide_menu_on'])) |
---|
[10812] | 200 | { |
---|
| 201 | include( PHPWG_ROOT_PATH.'include/menubar.inc.php'); |
---|
| 202 | } |
---|
| 203 | |
---|
[2107] | 204 | include(PHPWG_ROOT_PATH.'include/page_header.php'); |
---|
[15578] | 205 | include(PHPWG_ROOT_PATH.'include/page_messages.php'); |
---|
[2223] | 206 | $template->pparse('tags'); |
---|
[1119] | 207 | include(PHPWG_ROOT_PATH.'include/page_tail.php'); |
---|
| 208 | ?> |
---|