source: trunk/tags.php @ 26010

Last change on this file since 26010 was 25018, checked in by mistic100, 11 years ago

remove all array_push (50% slower than []) + some changes missing for feature:2978

  • Property keywords set to Author Date Id Revision
  • Property svn:eol-style set to LF
File size: 6.3 KB
RevLine 
[1119]1<?php
2// +-----------------------------------------------------------------------+
[8728]3// | Piwigo - a PHP based photo gallery                                    |
[2297]4// +-----------------------------------------------------------------------+
[19703]5// | Copyright(C) 2008-2013 Piwigo Team                  http://piwigo.org |
[2297]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// +-----------------------------------------------------------------------+
[1119]23
24// +-----------------------------------------------------------------------+
25// |                             functions                                 |
26// +-----------------------------------------------------------------------+
27
28function counter_compare($a, $b)
29{
30  if ($a['counter'] == $b['counter'])
31  {
[1815]32    return id_compare($a, $b);
[1119]33  }
34
[1120]35  return ($a['counter'] < $b['counter']) ? +1 : -1;
[1119]36}
37
[1815]38function id_compare($a, $b)
[1119]39{
[1815]40  return ($a['id'] < $b['id']) ? -1 : 1;
[1119]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
[18063]52trigger_action('loc_begin_tags');
53
[1119]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
[2362]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
[2478]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}
[2362]79
[2478]80$template->assign( 'display_mode', $page['display_mode'] );
81
[2362]82// find all tags available for the current user
83$tags = get_available_tags();
84
[1119]85// +-----------------------------------------------------------------------+
[2362]86// |                       letter groups construction                      |
87// +-----------------------------------------------------------------------+
88
89if ($page['display_mode'] == 'letters') {
90  // we want tags diplayed in alphabetic order
[2409]91  usort($tags, 'tag_alpha_compare');
[2362]92
93  $current_letter = null;
94  $nb_tags = count($tags);
[2409]95  $current_column = 1;
96  $current_tag_idx = 0;
[2362]97
98  $letter = array(
99    'tags' => array()
100    );
101
102  foreach ($tags as $tag)
103  {
[17748]104    $tag_letter = mb_strtoupper(mb_substr(transliterate($tag['name']), 0, 1, PWG_CHARSET), PWG_CHARSET);
[2362]105
[2409]106    if ($current_tag_idx==0) {
[2362]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    {
[2409]114      if ($current_column<$conf['tag_letters_column_number']
115          and $current_tag_idx > $current_column*$nb_tags/$conf['tag_letters_column_number'] )
[2362]116      {
117        $letter['CHANGE_COLUMN'] = true;
[2409]118        $current_column++;
[2362]119      }
120
121      $letter['TITLE'] = $current_letter;
122
123      $template->append(
124        'letters',
125        $letter
126        );
[2409]127
[2362]128      $current_letter = $tag_letter;
129      $letter = array(
130        'tags' => array()
131        );
132    }
133
[25018]134    $letter['tags'][] = array_merge(
135      $tag,
136      array(
137        'URL' => make_index_url(array('tags' => array($tag))),
[2362]138        )
139      );
[2409]140
141    $current_tag_idx++;
[2362]142  }
143
144  // flush last letter
145  if (count($letter['tags']) > 0)
146  {
[3145]147    unset($letter['CHANGE_COLUMN']);
[2362]148    $letter['TITLE'] = $current_letter;
149    $template->append(
150      'letters',
151      $letter
152      );
153  }
154}
[18455]155else
156{
157  // +-----------------------------------------------------------------------+
158  // |                        tag cloud construction                         |
159  // +-----------------------------------------------------------------------+
[2362]160
[18455]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']);
[1119]165
[18455]166  // depending on its counter and the other tags counter, each tag has a level
167  $tags = add_level_to_tags($tags);
[1119]168
[18455]169  // we want tags diplayed in alphabetic order
[12761]170  usort($tags, 'tag_alpha_compare');
[1119]171
[18455]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          )
[2409]186        )
[18455]187      );
188  }
[1119]189}
[10812]190// include menubar
191$themeconf = $template->get_template_vars('themeconf');
[10824]192if (!isset($themeconf['hide_menu_on']) OR !in_array('theTagsPage', $themeconf['hide_menu_on']))
[10812]193{
194  include( PHPWG_ROOT_PATH.'include/menubar.inc.php');
195}
196
[2107]197include(PHPWG_ROOT_PATH.'include/page_header.php');
[18063]198trigger_action('loc_end_tags');
[20609]199flush_page_messages();
[2223]200$template->pparse('tags');
[1119]201include(PHPWG_ROOT_PATH.'include/page_tail.php');
202?>
Note: See TracBrowser for help on using the repository browser.