size = 1 + (count - Cmin) * A
*
* @param array selected tag, max tag displayed, number of sizes available,
* class prefix for css class, style for selected tag
*/
function tag_cloud($params = '') {
global $NB_SIZE;
global $NB_MAX;
global $CLASS_PREFIX;
global $SELECTED_STYLE;
if (! is_array($params)) $parames = array();
if (! isset($params['selected'])) {
$params['selected'] = '';
}
if (! isset($params['nb_max'])) {
$params['nb_max'] = $NB_MAX;
}
if (! isset($params['nb_size'])) {
$params['nb_size'] = $NB_SIZE;
}
if (! isset($params['class_prefix'])) {
$params['class_prefix'] = $CLASS_PREFIX;
}
if (! isset($params['selected_style'])) {
$params['selected_style'] = $SELECTED_STYLE;
}
$return = '';
$res = db_query_params ('SELECT name,count(*) AS count
FROM project_tags, groups
WHERE project_tags.group_id = groups.group_id
AND status = $1 AND is_public=1 AND type_id=1 AND register_time > 0
GROUP BY name ORDER BY count DESC',
array ('A')) ;
if (db_numrows($res) > 0) {
$count_min = 0;
$count_max = 0;
$nb = 1;
// Search upper and lower tag frequencies; stop when maximum tag number to display is reached
while ($row = db_fetch_array($res)) {
$tag_count[$row['name']] = $row['count'];
if ($count_min == 0 || $row['count'] < $count_min) $count_min = $row['count'];
if ($row['count'] > $count_max) $count_max = $row['count'];
if ($params['nb_max'] && $nb >= $params['nb_max']) break; // no limit if nb_max == 0
$nb++;
}
// Compute 'A' parameter of the function
if ($count_max != $count_min) // else we have a division by zero
{
$a = ($params['nb_size'] - 1) / ($count_max - $count_min);
}
else {
// Set value 0 for 'A' parameter just for initialised variable
// but it's not realy necessary because if $count_max == $count_min
// then $count - $count_min = 0 (see below)
$a = 0;
}
ksort($tag_count, SORT_STRING);
foreach ($tag_count as $name => $count) {
$size = intval(1 + ($count - $count_min) * $a);
$return .= '' . htmlspecialchars($name) . ' ';
}
}
return $return;
}
/**
* list_project_tag() - Returns the list of the tags defined by the project.
* Each tag is a link to display a list of projects
* where the tag is defined.
*
* @param int Group ID
*/
function list_project_tag($group_id) {
$req = 'SELECT name FROM project_tags WHERE group_id = $1';
$res = db_query_params($req, array($group_id));
$nb_tag = db_numrows($res);
$return = '';
$idx = 1;
if ($nb_tag) {
while ($row = db_fetch_array($res)) {
$return .= '' . htmlspecialchars($row['name']) . '' . (($idx < $nb_tag) ? ', ' : '');
$idx++;
}
}
return $return;
}
?>