3 * Copyright (C) 2008-2009 Alcatel-Lucent
5 * This file is part of FusionForge.
7 * FusionForge is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published
9 * by the Free Software Foundation; either version 2 of the License,
10 * or (at your option) any later version.
12 * FusionForge is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with FusionForge; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
24 * Standard Alcatel-Lucent disclaimer for contributing to open source
26 * "The Tag Cloud ("Contribution") has not been tested and/or
27 * validated for release as or in products, combinations with products or
28 * other commercial use. Any use of the Contribution is entirely made at
29 * the user's own responsibility and the user can not rely on any features,
30 * functionalities or performances Alcatel-Lucent has attributed to the
33 * THE CONTRIBUTION BY ALCATEL-LUCENT IS PROVIDED AS IS, WITHOUT WARRANTY
34 * OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
35 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, COMPLIANCE,
36 * NON-INTERFERENCE AND/OR INTERWORKING WITH THE SOFTWARE TO WHICH THE
37 * CONTRIBUTION HAS BEEN MADE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL
38 * ALCATEL-LUCENT BE LIABLE FOR ANY DAMAGES OR OTHER LIABLITY, WHETHER IN
39 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
40 * CONTRIBUTION OR THE USE OR OTHER DEALINGS IN THE CONTRIBUTION, WHETHER
41 * TOGETHER WITH THE SOFTWARE TO WHICH THE CONTRIBUTION RELATES OR ON A STAND
47 $CLASS_PREFIX = 'tag';
48 $SELECTED_STYLE = 'style="text-decoration:overline underline;"';
51 * tag_cloud() - This function displays a tag cloug with the tags defined by projects.
52 * The size of each tag depends of its frequency.
53 * Each tag is a link to display a list of projects where the tag is defined.
54 * Delta between two font sizes is constant :
55 * function is F(count) = size = A * count + B
64 * A = (Smax - Smin) / (Cmax - Cmin)
66 * If Smin = 1 then Smax = number of size = N
68 * A = (N - 1) / (Cmax - Cmin)
70 * F(count) = size = A * count + 1 - A * Cmin
71 * => size = 1 + (count - Cmin) * A
73 * @param array selected tag, max tag displayed, number of sizes available,
74 * class prefix for css class, style for selected tag
76 function tag_cloud($params = '') {
80 global $SELECTED_STYLE;
82 if (! is_array($params)) $parames = array();
83 if (! isset($params['selected'])) {
84 $params['selected'] = '';
86 if (! isset($params['nb_max'])) {
87 $params['nb_max'] = $NB_MAX;
89 if (! isset($params['nb_size'])) {
90 $params['nb_size'] = $NB_SIZE;
92 if (! isset($params['class_prefix'])) {
93 $params['class_prefix'] = $CLASS_PREFIX;
95 if (! isset($params['selected_style'])) {
96 $params['selected_style'] = $SELECTED_STYLE;
101 $res = db_query_params ('SELECT project_tags.name,project_tags.group_id
102 FROM project_tags, groups
103 WHERE project_tags.group_id = groups.group_id
104 AND groups.status = $1 AND groups.type_id=1 AND groups.register_time > 0',
106 $tag_count = array();
107 while ($row = db_fetch_array($res)) {
108 if (forge_check_perm ('project_read', $row['group_id'])) {
109 if (!isset ($tag_count[$row['name']])) {
110 $tag_count[$row['name']] = 0;
112 $tag_count[$row['name']]++;
115 if (count($tag_count) > 0) {
119 // Search upper and lower tag frequencies; stop when maximum tag number to display is reached
120 foreach ($tag_count as $name => $count) {
121 if ($count_min == 0 || $count < $count_min) $count_min = $count;
122 if ($count > $count_max) $count_max = $count;
123 if ($params['nb_max'] && $nb >= $params['nb_max']) break; // no limit if nb_max == 0
127 // Compute 'A' parameter of the function
128 if ($count_max != $count_min) // else we have a division by zero
130 $a = ($params['nb_size'] - 1) / ($count_max - $count_min);
133 // Set value 0 for 'A' parameter just for initialised variable
134 // but it's not realy necessary because if $count_max == $count_min
135 // then $count - $count_min = 0 (see below)
139 ksort($tag_count, SORT_STRING);
140 foreach ($tag_count as $name => $count) {
141 $size = intval(1 + ($count - $count_min) * $a);
142 $return .= '<a href="/softwaremap/tag_cloud.php?tag='
144 . '" class="' . $params['class_prefix'] . $size . '" '
145 . (($name == $params['selected']) ? $params['selected_style'] : '' )
146 . '>' . htmlspecialchars($name) . '</a> ';
154 * list_project_tag() - Returns the list of the tags defined by the project.
155 * Each tag is a link to display a list of projects
156 * where the tag is defined.
158 * @param int Group ID
160 function list_project_tag($group_id) {
161 $req = 'SELECT name FROM project_tags WHERE group_id = $1';
162 $res = db_query_params($req, array($group_id));
163 $nb_tag = db_numrows($res);
167 while ($row = db_fetch_array($res)) {
168 $return .= '<a href="/softwaremap/tag_cloud.php?tag='
169 . urlencode($row['name'])
170 . '">' . htmlspecialchars($row['name']) . '</a>' . (($idx < $nb_tag) ? ', ' : '');
180 // c-file-style: "bsd"