source: trunk/tags.php @ 29729

Last change on this file since 29729 was 28587, checked in by mistic100, 10 years ago

feature 3010 : replace trigger_action/event by trigger_notify/change

  • Property keywords set to Author Date Id Revision
  • Property svn:eol-style set to LF
File size: 6.3 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based photo gallery                                    |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008-2014 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_notify('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    $letter['tags'][] = array_merge(
135      $tag,
136      array(
137        'URL' => make_index_url(array('tags' => array($tag))),
138        )
139      );
140
141    $current_tag_idx++;
142  }
143
144  // flush last letter
145  if (count($letter['tags']) > 0)
146  {
147    unset($letter['CHANGE_COLUMN']);
148    $letter['TITLE'] = $current_letter;
149    $template->append(
150      'letters',
151      $letter
152      );
153  }
154}
155else
156{
157  // +-----------------------------------------------------------------------+
158  // |                        tag cloud construction                         |
159  // +-----------------------------------------------------------------------+
160
161  // we want only the first most represented tags, so we sort them by counter
162  // and take the first tags
163  usort($tags, 'counter_compare');
164  $tags = array_slice($tags, 0, $conf['full_tag_cloud_items_number']);
165
166  // depending on its counter and the other tags counter, each tag has a level
167  $tags = add_level_to_tags($tags);
168
169  // we want tags diplayed in alphabetic order
170  usort($tags, 'tag_alpha_compare');
171
172  // display sorted tags
173  foreach ($tags as $tag)
174  {
175    $template->append(
176      'tags',
177      array_merge(
178        $tag,
179        array(
180          'URL' => make_index_url(
181            array(
182              'tags' => array($tag),
183              )
184            ),
185          )
186        )
187      );
188  }
189}
190// include menubar
191$themeconf = $template->get_template_vars('themeconf');
192if (!isset($themeconf['hide_menu_on']) OR !in_array('theTagsPage', $themeconf['hide_menu_on']))
193{
194  include( PHPWG_ROOT_PATH.'include/menubar.inc.php');
195}
196
197include(PHPWG_ROOT_PATH.'include/page_header.php');
198trigger_notify('loc_end_tags');
199flush_page_messages();
200$template->pparse('tags');
201include(PHPWG_ROOT_PATH.'include/page_tail.php');
202?>
Note: See TracBrowser for help on using the repository browser.