source: trunk/tags.php @ 17748

Last change on this file since 17748 was 17748, checked in by rvelices, 12 years ago

bug 2735: fix/improve non latin language tags

  1. non latin tags (greek/cyrillic...) are not sorted case-insesitive and group by letter view in tag list is not case insesitive
  2. quick searching tag names does not perform correctly accent folding (e.g. Köln and Koln do not match) and case insesitivity for non latin letters
  3. missing from remove_accents characters in romanian language (Latin Extended-B) ? c8 98 = LATIN CAPITAL LETTER S WITH COMMA BELOW ? c8 99 = LATIN SMALL LETTER S WITH COMMA BELOW ? c8 9a = LATIN CAPITAL LETTER T WITH COMMA BELOW ? c8 9b = LATIN SMALL LETTER T WITH COMMA BELOW
  4. str2url allow non latin letters in output only if the input does not contain any valid lating letter/digit. we should always allow non latin letters in output
  • Property keywords set to Author Date Id Revision
  • Property svn:eol-style set to LF
File size: 6.4 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based photo gallery                                    |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008-2012 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 = mb_strtoupper(mb_substr(transliterate($tag['name']), 0, 1, PWG_CHARSET), PWG_CHARSET);
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
174if ('letters' != $page['display_mode'])
175{
176  usort($tags, 'tag_alpha_compare');
177}
178
179// display sorted tags
180foreach ($tags as $tag)
181{
182  $template->append(
183    'tags',
184    array_merge(
185      $tag,
186      array(
187        'URL' => make_index_url(
188          array(
189            'tags' => array($tag),
190            )
191          ),
192        )
193      )
194    );
195}
196
197// include menubar
198$themeconf = $template->get_template_vars('themeconf');
199if (!isset($themeconf['hide_menu_on']) OR !in_array('theTagsPage', $themeconf['hide_menu_on']))
200{
201  include( PHPWG_ROOT_PATH.'include/menubar.inc.php');
202}
203
204include(PHPWG_ROOT_PATH.'include/page_header.php');
205include(PHPWG_ROOT_PATH.'include/page_messages.php');
206$template->pparse('tags');
207include(PHPWG_ROOT_PATH.'include/page_tail.php');
208?>
Note: See TracBrowser for help on using the repository browser.