source: trunk/tags.php @ 6467

Last change on this file since 6467 was 6363, checked in by plg, 15 years ago

remove all svn:mergeinfo properties

  • Property keywords set to Author Date Id Revision
  • Property svn:eol-style set to LF
File size: 6.0 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based picture gallery                                  |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008-2010 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
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
61$page['display_mode'] = $conf['tags_default_display_mode'];
62if (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
70foreach (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}
77
78$template->assign( 'display_mode', $page['display_mode'] );
79
80// find all tags available for the current user
81$tags = get_available_tags();
82
83// +-----------------------------------------------------------------------+
84// |                       letter groups construction                      |
85// +-----------------------------------------------------------------------+
86
87if ($page['display_mode'] == 'letters') {
88  // we want tags diplayed in alphabetic order
89  usort($tags, 'tag_alpha_compare');
90
91  $current_letter = null;
92  $nb_tags = count($tags);
93  $current_column = 1;
94  $current_tag_idx = 0;
95
96  $letter = array(
97    'tags' => array()
98    );
99
100  foreach ($tags as $tag)
101  {
102    $tag_letter = strtoupper(substr($tag['url_name'], 0, 1));
103
104    if ($current_tag_idx==0) {
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    {
112      if ($current_column<$conf['tag_letters_column_number']
113          and $current_tag_idx > $current_column*$nb_tags/$conf['tag_letters_column_number'] )
114      {
115        $letter['CHANGE_COLUMN'] = true;
116        $current_column++;
117      }
118
119      $letter['TITLE'] = $current_letter;
120
121      $template->append(
122        'letters',
123        $letter
124        );
125
126      $current_letter = $tag_letter;
127      $letter = array(
128        'tags' => array()
129        );
130    }
131
132    array_push(
133      $letter['tags'],
134      array_merge(
135        $tag,
136        array(
137          'URL' => make_index_url(
138            array(
139              'tags' => array($tag),
140              )
141            ),
142          )
143        )
144      );
145
146    $current_tag_idx++;
147  }
148
149  // flush last letter
150  if (count($letter['tags']) > 0)
151  {
152    unset($letter['CHANGE_COLUMN']);
153    $letter['TITLE'] = $current_letter;
154    $template->append(
155      'letters',
156      $letter
157      );
158  }
159}
160
161// +-----------------------------------------------------------------------+
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
167usort($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
174usort($tags, 'tag_alpha_compare');
175
176// display sorted tags
177foreach ($tags as $tag)
178{
179  $template->append(
180    'tags',
181    array_merge(
182      $tag,
183      array(
184        'URL' => make_index_url(
185          array(
186            'tags' => array($tag),
187            )
188          ),
189        )
190      )
191    );
192}
193
194include(PHPWG_ROOT_PATH.'include/page_header.php');
195$template->pparse('tags');
196include(PHPWG_ROOT_PATH.'include/page_tail.php');
197?>
Note: See TracBrowser for help on using the repository browser.