source: trunk/tags.php @ 2362

Last change on this file since 2362 was 2362, checked in by plg, 16 years ago

feature 828 added: display tags by letters. Users can switch from "cloud" to
"letters" with a button in the top bar.

  • Property keywords set to Author Date Id Revision
  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 6.0 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based picture gallery                                  |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008      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
70$template->assign(
71  array(
72    'U_CLOUD' => get_root_url().'tags.php?display_mode=cloud',
73    'U_LETTERS' => get_root_url().'tags.php?display_mode=letters',
74    'display_mode' => $page['display_mode'],
75    )
76  );
77
78// find all tags available for the current user
79$tags = get_available_tags();
80
81// +-----------------------------------------------------------------------+
82// |                       letter groups construction                      |
83// +-----------------------------------------------------------------------+
84
85if ($page['display_mode'] == 'letters') {
86  // we want tags diplayed in alphabetic order
87  usort($tags, 'name_compare');
88
89  $current_letter = null;
90  $is_first_tag = true;
91  $nb_tags = count($tags);
92  $current_column_tags = 0;
93
94  $letter = array(
95    'tags' => array()
96    );
97
98  foreach ($tags as $tag)
99  {
100    $tag_letter = strtoupper(substr($tag['name'], 0, 1));
101
102    if ($is_first_tag) {
103      $current_letter = $tag_letter;
104      $letter['TITLE'] = $tag_letter;
105      $is_first_tag = false;
106    }
107
108    //lettre precedente differente de la lettre suivante
109    if ($tag_letter !== $current_letter)
110    {
111      if ($current_column_tags > $nb_tags/$conf['tag_letters_column_number'])
112      {
113        $letter['CHANGE_COLUMN'] = true;
114        $current_column_tags = 0;
115      }
116
117      $letter['TITLE'] = $current_letter;
118
119      $template->append(
120        'letters',
121        $letter
122        );
123     
124      $current_letter = $tag_letter;
125      $letter = array(
126        'tags' => array()
127        );
128    }
129
130    array_push(
131      $letter['tags'],
132      array(
133        'URL' => make_index_url(
134          array(
135            'tags' => array($tag),
136            )
137          ),
138        'NAME' => $tag['name'],
139        'COUNTER' => $tag['counter'],
140        )
141      );
142   
143    $current_column_tags++;
144  }
145
146  // flush last letter
147  if (count($letter['tags']) > 0)
148  {
149    $letter['CHANGE_COLUMN'] = false;
150    $letter['TITLE'] = $current_letter;
151    $template->append(
152      'letters',
153      $letter
154      );
155  }
156}
157
158// +-----------------------------------------------------------------------+
159// |                        tag cloud construction                         |
160// +-----------------------------------------------------------------------+
161
162// we want only the first most represented tags, so we sort them by counter
163// and take the first tags
164usort($tags, 'counter_compare');
165$tags = array_slice($tags, 0, $conf['full_tag_cloud_items_number']);
166
167// depending on its counter and the other tags counter, each tag has a level
168$tags = add_level_to_tags($tags);
169
170// we want tags diplayed in alphabetic order
171usort($tags, 'name_compare');
172
173// display sorted tags
174foreach ($tags as $tag)
175{
176  $template->append(
177    'tags',
178    array(
179      'URL' => make_index_url(
180        array(
181          'tags' => array($tag),
182          )
183        ),
184
185      'NAME' => $tag['name'],
186      'TITLE' => $tag['counter'],
187      'CLASS' => 'tagLevel'.$tag['level'],
188      )
189    );
190}
191
192include(PHPWG_ROOT_PATH.'include/page_header.php');
193$template->pparse('tags');
194include(PHPWG_ROOT_PATH.'include/page_tail.php');
195?>
Note: See TracBrowser for help on using the repository browser.