X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=tags.php;h=ddde120596086c446714a7a6d46968748c289b45;hb=f1ddaa8817df4a82805ec3902c72554c411ad468;hp=740c0aae6b91a755ff3f4caeb5c96bc1e0a752e2;hpb=e5e982801086e26aaacd4e9706b2854972ae264c;p=contagged
diff --git a/tags.php b/tags.php
index 740c0aa..ddde120 100644
--- a/tags.php
+++ b/tags.php
@@ -1,7 +1,11 @@
-
- require_once('init.php');
+assign('tagcloud',tag_cloud());
@@ -12,32 +16,56 @@
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;
+ }
+ }
+ }
+
+