1 | <?php |
---|
2 | // +-----------------------------------------------------------------------+ |
---|
3 | // | Piwigo - a PHP based photo gallery | |
---|
4 | // +-----------------------------------------------------------------------+ |
---|
5 | // | Copyright(C) 2008-2012 Piwigo Team http://piwigo.org | |
---|
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 | // +-----------------------------------------------------------------------+ |
---|
23 | |
---|
24 | // +-----------------------------------------------------------------------+ |
---|
25 | // | functions | |
---|
26 | // +-----------------------------------------------------------------------+ |
---|
27 | |
---|
28 | function counter_compare($a, $b) |
---|
29 | { |
---|
30 | if ($a['counter'] == $b['counter']) |
---|
31 | { |
---|
32 | return id_compare($a, $b); |
---|
33 | } |
---|
34 | |
---|
35 | return ($a['counter'] < $b['counter']) ? +1 : -1; |
---|
36 | } |
---|
37 | |
---|
38 | function id_compare($a, $b) |
---|
39 | { |
---|
40 | return ($a['id'] < $b['id']) ? -1 : 1; |
---|
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 | trigger_action('loc_begin_tags'); |
---|
53 | |
---|
54 | // +-----------------------------------------------------------------------+ |
---|
55 | // | page header and options | |
---|
56 | // +-----------------------------------------------------------------------+ |
---|
57 | |
---|
58 | $title= l10n('Tags'); |
---|
59 | $page['body_id'] = 'theTagsPage'; |
---|
60 | |
---|
61 | $template->set_filenames(array('tags'=>'tags.tpl')); |
---|
62 | |
---|
63 | $page['display_mode'] = $conf['tags_default_display_mode']; |
---|
64 | if (isset($_GET['display_mode'])) |
---|
65 | { |
---|
66 | if (in_array($_GET['display_mode'], array('cloud', 'letters'))) |
---|
67 | { |
---|
68 | $page['display_mode'] = $_GET['display_mode']; |
---|
69 | } |
---|
70 | } |
---|
71 | |
---|
72 | foreach (array('cloud', 'letters') as $mode) |
---|
73 | { |
---|
74 | $template->assign( |
---|
75 | 'U_'.strtoupper($mode), |
---|
76 | get_root_url().'tags.php'. ($conf['tags_default_display_mode']==$mode ? '' : '?display_mode='.$mode) |
---|
77 | ); |
---|
78 | } |
---|
79 | |
---|
80 | $template->assign( 'display_mode', $page['display_mode'] ); |
---|
81 | |
---|
82 | // find all tags available for the current user |
---|
83 | $tags = get_available_tags(); |
---|
84 | |
---|
85 | // +-----------------------------------------------------------------------+ |
---|
86 | // | letter groups construction | |
---|
87 | // +-----------------------------------------------------------------------+ |
---|
88 | |
---|
89 | if ($page['display_mode'] == 'letters') { |
---|
90 | // we want tags diplayed in alphabetic order |
---|
91 | usort($tags, 'tag_alpha_compare'); |
---|
92 | |
---|
93 | $current_letter = null; |
---|
94 | $nb_tags = count($tags); |
---|
95 | $current_column = 1; |
---|
96 | $current_tag_idx = 0; |
---|
97 | |
---|
98 | $letter = array( |
---|
99 | 'tags' => array() |
---|
100 | ); |
---|
101 | |
---|
102 | foreach ($tags as $tag) |
---|
103 | { |
---|
104 | $tag_letter = mb_strtoupper(mb_substr(transliterate($tag['name']), 0, 1, PWG_CHARSET), PWG_CHARSET); |
---|
105 | |
---|
106 | if ($current_tag_idx==0) { |
---|
107 | $current_letter = $tag_letter; |
---|
108 | $letter['TITLE'] = $tag_letter; |
---|
109 | } |
---|
110 | |
---|
111 | //lettre precedente differente de la lettre suivante |
---|
112 | if ($tag_letter !== $current_letter) |
---|
113 | { |
---|
114 | if ($current_column<$conf['tag_letters_column_number'] |
---|
115 | and $current_tag_idx > $current_column*$nb_tags/$conf['tag_letters_column_number'] ) |
---|
116 | { |
---|
117 | $letter['CHANGE_COLUMN'] = true; |
---|
118 | $current_column++; |
---|
119 | } |
---|
120 | |
---|
121 | $letter['TITLE'] = $current_letter; |
---|
122 | |
---|
123 | $template->append( |
---|
124 | 'letters', |
---|
125 | $letter |
---|
126 | ); |
---|
127 | |
---|
128 | $current_letter = $tag_letter; |
---|
129 | $letter = array( |
---|
130 | 'tags' => array() |
---|
131 | ); |
---|
132 | } |
---|
133 | |
---|
134 | array_push( |
---|
135 | $letter['tags'], |
---|
136 | array_merge( |
---|
137 | $tag, |
---|
138 | array( |
---|
139 | 'URL' => make_index_url( |
---|
140 | array( |
---|
141 | 'tags' => array($tag), |
---|
142 | ) |
---|
143 | ), |
---|
144 | ) |
---|
145 | ) |
---|
146 | ); |
---|
147 | |
---|
148 | $current_tag_idx++; |
---|
149 | } |
---|
150 | |
---|
151 | // flush last letter |
---|
152 | if (count($letter['tags']) > 0) |
---|
153 | { |
---|
154 | unset($letter['CHANGE_COLUMN']); |
---|
155 | $letter['TITLE'] = $current_letter; |
---|
156 | $template->append( |
---|
157 | 'letters', |
---|
158 | $letter |
---|
159 | ); |
---|
160 | } |
---|
161 | } |
---|
162 | |
---|
163 | // +-----------------------------------------------------------------------+ |
---|
164 | // | tag cloud construction | |
---|
165 | // +-----------------------------------------------------------------------+ |
---|
166 | |
---|
167 | // we want only the first most represented tags, so we sort them by counter |
---|
168 | // and take the first tags |
---|
169 | usort($tags, 'counter_compare'); |
---|
170 | $tags = array_slice($tags, 0, $conf['full_tag_cloud_items_number']); |
---|
171 | |
---|
172 | // depending on its counter and the other tags counter, each tag has a level |
---|
173 | $tags = add_level_to_tags($tags); |
---|
174 | |
---|
175 | // we want tags diplayed in alphabetic order |
---|
176 | if ('letters' != $page['display_mode']) |
---|
177 | { |
---|
178 | usort($tags, 'tag_alpha_compare'); |
---|
179 | } |
---|
180 | |
---|
181 | // display sorted tags |
---|
182 | foreach ($tags as $tag) |
---|
183 | { |
---|
184 | $template->append( |
---|
185 | 'tags', |
---|
186 | array_merge( |
---|
187 | $tag, |
---|
188 | array( |
---|
189 | 'URL' => make_index_url( |
---|
190 | array( |
---|
191 | 'tags' => array($tag), |
---|
192 | ) |
---|
193 | ), |
---|
194 | ) |
---|
195 | ) |
---|
196 | ); |
---|
197 | } |
---|
198 | |
---|
199 | // include menubar |
---|
200 | $themeconf = $template->get_template_vars('themeconf'); |
---|
201 | if (!isset($themeconf['hide_menu_on']) OR !in_array('theTagsPage', $themeconf['hide_menu_on'])) |
---|
202 | { |
---|
203 | include( PHPWG_ROOT_PATH.'include/menubar.inc.php'); |
---|
204 | } |
---|
205 | |
---|
206 | include(PHPWG_ROOT_PATH.'include/page_header.php'); |
---|
207 | trigger_action('loc_end_tags'); |
---|
208 | include(PHPWG_ROOT_PATH.'include/page_messages.php'); |
---|
209 | $template->pparse('tags'); |
---|
210 | include(PHPWG_ROOT_PATH.'include/page_tail.php'); |
---|
211 | ?> |
---|