source: extensions/PWG_Stuffs/trunk/modules/Tags/main.inc.php @ 19067

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

improve display with Typetags

File size: 3.4 KB
Line 
1<?php
2
3if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
4
5global $conf, $template, $pwg_loaded_plugins;
6
7function counter_compare($a, $b)
8{
9  if ($a['counter'] == $b['counter'])
10  {
11    return id_compare($a, $b);
12  }
13
14  return ($a['counter'] < $b['counter']) ? +1 : -1;
15}
16
17function id_compare($a, $b)
18{
19  return ($a['id'] < $b['id']) ? -1 : 1;
20}
21
22$pwgCumulus_installed = get_db_plugins('active','pwgCumulus');
23
24$block['TITLE_URL'] = 'tags.php';
25
26// hack typetags
27if (isset($pwg_loaded_plugins['typetags']))
28{
29  $typetags = true;
30  $template->assign('display_mode', $datas[0]);
31  if ($conf['TypeTags']['show_all'])
32  {
33    remove_event_handler('render_tag_name', 'typetags_render', 0);
34  }
35}
36
37$tags = get_available_tags();
38
39if ((!$pwgCumulus_installed and $datas[0] == 'cumulus') or empty($datas[0]))
40{
41  $datas[0] = 'cloud';
42}
43
44if ($datas[0] == 'letters')
45{
46  // we want tags diplayed in alphabetic order
47  usort($tags, 'tag_alpha_compare');
48
49  $current_letter = null;
50  $nb_tags = count($tags);
51  $current_column = 1;
52  $current_tag_idx = 0;
53
54  $letter = array(
55    'tags' => array()
56    );
57
58  foreach ($tags as $tag)
59  {
60    $tag_letter = strtoupper(substr($tag['url_name'], 0, 1));
61
62    if ($current_tag_idx==0) {
63      $current_letter = $tag_letter;
64      $letter['TITLE'] = $tag_letter;
65    }
66
67    //lettre precedente differente de la lettre suivante
68    if ($tag_letter !== $current_letter)
69    {
70      if ($current_column<$conf['tag_letters_column_number']
71          and $current_tag_idx > $current_column*$nb_tags/$conf['tag_letters_column_number'] )
72      {
73        $letter['CHANGE_COLUMN'] = true;
74        $current_column++;
75      }
76
77      $letter['TITLE'] = $current_letter;
78
79      $template->append(
80        'letters',
81        $letter
82        );
83
84      $current_letter = $tag_letter;
85      $letter = array(
86        'tags' => array()
87        );
88    }
89
90    array_push(
91      $letter['tags'],
92      array_merge(
93        $tag,
94        array(
95          'URL' => make_index_url(
96            array(
97              'tags' => array($tag),
98              )
99            ),
100          )
101        )
102      );
103
104    $current_tag_idx++;
105  }
106
107  // flush last letter
108  if (count($letter['tags']) > 0)
109  {
110    unset($letter['CHANGE_COLUMN']);
111    $letter['TITLE'] = $current_letter;
112    $template->append(
113      'letters',
114      $letter
115      );
116  }
117}
118else
119{
120  usort($tags, 'counter_compare');
121  $tags = array_slice($tags, 0, $conf['full_tag_cloud_items_number']);
122
123  // depending on its counter and the other tags counter, each tag has a level
124  $tags = add_level_to_tags($tags);
125
126  // we want tags diplayed in alphabetic order
127  usort($tags, 'tag_alpha_compare');
128
129  // display sorted tags
130  foreach ($tags as $tag)
131  {
132    $template->append(
133      '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  if ($datas[0] == 'cumulus' and defined('PWG_CUMULUS_PLUGIN_ROOT'))
147  {
148    include_once PWG_CUMULUS_PLUGIN_ROOT . "/include/pwgCumulusContent.class.php";
149    $cumulus = new pwgCumulusContent(get_plugin_data('pwgCumulus'));
150    $cumulus->loc_begin_page_header();
151  }
152}
153
154if (isset($typetags))
155{
156  typetags_tags();
157  if ($conf['TypeTags']['show_all'])
158  {
159    add_event_handler('render_tag_name', 'typetags_render', 0);
160  }
161}
162
163$template->assign('display_mode', $datas[0]);
164
165$block['TEMPLATE'] = 'stuffs_tags.tpl';
166
167?>
Note: See TracBrowser for help on using the repository browser.