X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=tags.php;h=999bffbdd838918f3bd4b32340331f256967224d;hb=af6040dce7b6dd4c903148c5e7d7825b3899febf;hp=13b07b2b86cf2efee4f01ac2d528a0a6a3acac0c;hpb=98725dae90d4a672db841c35d8b51e54fafddddd;p=contagged diff --git a/tags.php b/tags.php index 13b07b2..999bffb 100644 --- a/tags.php +++ b/tags.php @@ -1,46 +1,71 @@ -assign('tagcloud',tag_cloud()); //display templates header('Content-Type: text/html; charset=utf-8'); - $smarty->display('header.tpl'); - $smarty->display('list_filter.tpl'); $smarty->display('tags.tpl'); - $smarty->display('footer.tpl'); function tag_cloud(){ global $conf; global $LDAP_CON; - if(!$conf[extended]) return; - - $result = ldap_queryabooks('(objectClass=contactPerson)','marker'); + global $FIELDS; + if(!$FIELDS['_marker']) return; + $result = ldap_queryabooks('(objectClass=inetOrgPerson)',$FIELDS['_marker']); $max = 0; + $min = 999999999; $tags = array(); foreach ($result as $entry){ - if(count($entry['marker'])){ - foreach($entry['marker'] as $marker){ + if(!empty($entry[$FIELDS['_marker']]) && count($entry[$FIELDS['_marker']])){ + foreach($entry[$FIELDS['_marker']] as $marker){ $marker = strtolower($marker); + if (empty($tags[$marker])) { $tags[$marker]=0; } $tags[$marker] += 1; if($tags[$marker] > $max) $max = $tags[$marker]; + if($tags[$marker] < $min) $min = $tags[$marker]; } } } ksort($tags); + tag_cloud_weight(&$tags,$min,$max,6); $out = ''; foreach($tags as $tag => $cnt){ - $pct = round($cnt * 20 / $max); // percents from 0 to 20 - - $out .= ''; + $out .= ''; $out .= htmlspecialchars($tag).' '; } return $out; } -?> + /** + * Calculate weights for a nicer tagcloud distribution + */ + function tag_cloud_weight(&$tags,$min,$max,$levels){ + // calculate tresholds + $tresholds = array(); + for($i=0; $i<=$levels; $i++){ + $tresholds[$i] = pow($max - $min + 1, $i/$levels); + } + + // assign weights + foreach($tags as $tag => $cnt){ + foreach($tresholds as $tresh => $val){ + if($cnt <= $val){ + $tags[$tag] = $tresh; + break; + } + $tags[$tag] = $levels; + } + } + } + +