source: trunk/tags.php @ 20156

Last change on this file since 20156 was 19703, checked in by plg, 12 years ago

update Piwigo headers to 2013 (the end of the world didn't occur as expected on r12922)

  • Property keywords set to Author Date Id Revision
  • Property svn:eol-style set to LF
File size: 6.5 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based photo gallery                                    |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008-2013 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
28function 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
38function id_compare($a, $b)
39{
40  return ($a['id'] < $b['id']) ? -1 : 1;
41}
42
43// +-----------------------------------------------------------------------+
44// |                           initialization                              |
45// +-----------------------------------------------------------------------+
46
47define('PHPWG_ROOT_PATH','./');
48include_once(PHPWG_ROOT_PATH.'include/common.inc.php');
49
50check_status(ACCESS_GUEST);
51
52trigger_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'];
64if (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
72foreach (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
89if ($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}
162else
163{
164  // +-----------------------------------------------------------------------+
165  // |                        tag cloud construction                         |
166  // +-----------------------------------------------------------------------+
167
168  // we want only the first most represented tags, so we sort them by counter
169  // and take the first tags
170  usort($tags, 'counter_compare');
171  $tags = array_slice($tags, 0, $conf['full_tag_cloud_items_number']);
172
173  // depending on its counter and the other tags counter, each tag has a level
174  $tags = add_level_to_tags($tags);
175
176  // we want tags diplayed in alphabetic order
177  usort($tags, 'tag_alpha_compare');
178
179  // display sorted tags
180  foreach ($tags as $tag)
181  {
182    $template->append(
183      'tags',
184      array_merge(
185        $tag,
186        array(
187          'URL' => make_index_url(
188            array(
189              'tags' => array($tag),
190              )
191            ),
192          )
193        )
194      );
195  }
196}
197// include menubar
198$themeconf = $template->get_template_vars('themeconf');
199if (!isset($themeconf['hide_menu_on']) OR !in_array('theTagsPage', $themeconf['hide_menu_on']))
200{
201  include( PHPWG_ROOT_PATH.'include/menubar.inc.php');
202}
203
204include(PHPWG_ROOT_PATH.'include/page_header.php');
205trigger_action('loc_end_tags');
206include(PHPWG_ROOT_PATH.'include/page_messages.php');
207$template->pparse('tags');
208include(PHPWG_ROOT_PATH.'include/page_tail.php');
209?>
Note: See TracBrowser for help on using the repository browser.