source: trunk/tags.php @ 2409

Last change on this file since 2409 was 2409, checked in by rvelices, 16 years ago
  • remember me cookie security improvement (the time when the cookie was generated is saved and checked in range [now-remember_me_length; now]
  • tags improvements
    • pass to templates all fields in table #tags (handy for plugins such as type tags)
    • fix issue with tag letter when first letter is accentuated (utf-8)
    • tags are sorted on url_name instead of name (accentuated first letter chars are the same as without accent)
    • better use of columns in by letter display mode
  • 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, 'tag_alpha_compare');
88
89  $current_letter = null;
90  $nb_tags = count($tags);
91  $current_column = 1;
92  $current_tag_idx = 0;
93
94  $letter = array(
95    'tags' => array()
96    );
97
98  foreach ($tags as $tag)
99  {
100    $tag_letter = strtoupper(substr($tag['url_name'], 0, 1));
101
102    if ($current_tag_idx==0) {
103      $current_letter = $tag_letter;
104      $letter['TITLE'] = $tag_letter;
105    }
106
107    //lettre precedente differente de la lettre suivante
108    if ($tag_letter !== $current_letter)
109    {
110      if ($current_column<$conf['tag_letters_column_number']
111          and $current_tag_idx > $current_column*$nb_tags/$conf['tag_letters_column_number'] )
112      {
113        $letter['CHANGE_COLUMN'] = true;
114        $current_column++;
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_merge(
133        $tag,
134        array(
135          'URL' => make_index_url(
136            array(
137              'tags' => array($tag),
138              )
139            ),
140          )
141        )
142      );
143
144    $current_tag_idx++;
145  }
146
147  // flush last letter
148  if (count($letter['tags']) > 0)
149  {
150    $letter['CHANGE_COLUMN'] = false;
151    $letter['TITLE'] = $current_letter;
152    $template->append(
153      'letters',
154      $letter
155      );
156  }
157}
158
159// +-----------------------------------------------------------------------+
160// |                        tag cloud construction                         |
161// +-----------------------------------------------------------------------+
162
163// we want only the first most represented tags, so we sort them by counter
164// and take the first tags
165usort($tags, 'counter_compare');
166$tags = array_slice($tags, 0, $conf['full_tag_cloud_items_number']);
167
168// depending on its counter and the other tags counter, each tag has a level
169$tags = add_level_to_tags($tags);
170
171// we want tags diplayed in alphabetic order
172usort($tags, 'tag_alpha_compare');
173
174// display sorted tags
175foreach ($tags as $tag)
176{
177  $template->append(
178    'tags',
179    array_merge(
180      $tag,
181      array(
182        'URL' => make_index_url(
183          array(
184            'tags' => array($tag),
185            )
186          ),
187        )
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.