From: Andreas Gohr Date: Mon, 11 Sep 2006 12:01:15 +0000 (+0200) Subject: weighted tagcloud X-Git-Tag: 0.7.1~76 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=824eac0454ad341f6b285c9159c69317772986ca;p=contagged weighted tagcloud darcs-hash:20060911120115-6e07b-de95c8d8d3abb9e2334ee4971aab4c26b94ab4f1.gz --- diff --git a/README b/README index 4d3cee7..d37c796 100644 --- a/README +++ b/README @@ -11,8 +11,8 @@ You need to have a running LDAP Server with some users (objectClass=posixUser) in it. It is important that you already have these users because LDAPab uses them to authenticate. -You need a webserver (peferable Apache) with PHP4. PHP4 needs to be compiled -with LDAP support (compiled in or as extension) +You need a webserver (peferable Apache) with PHP (4.3 or higher). PHP needs to +be compiled with LDAP support (compiled in or as extension) === SETUP LDAPab === diff --git a/VERSION b/VERSION index be58634..bd73f47 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.3 +0.4 diff --git a/tags.php b/tags.php index bd26632..443ed67 100644 --- a/tags.php +++ b/tags.php @@ -13,10 +13,11 @@ global $conf; global $LDAP_CON; if(!$conf['extended']) return; - + $result = ldap_queryabooks('(objectClass=contactPerson)','marker'); $max = 0; + $min = 999999999; $tags = array(); foreach ($result as $entry){ if(!empty($entry['marker']) && count($entry['marker'])){ @@ -25,20 +26,42 @@ 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; + } + } + } + + diff --git a/templates/style.css b/templates/style.css index b0f4a58..6034799 100644 --- a/templates/style.css +++ b/templates/style.css @@ -54,7 +54,7 @@ td {background-color:#66CCFF:margin:3px} margin:2px; font-family:Lucida,Helvetica,Verdana,Arial,Sans-Serif; font-size: 12px;} - + .photo { margin-top: 1em; border-width:1px; @@ -140,27 +140,13 @@ h1 img { } /* TagCloud */ -a.tc0 { font-size: 80%; } -a.tc1 { font-size: 100%; } -a.tc2 { font-size: 120%; } -a.tc3 { font-size: 130%; } -a.tc4 { font-size: 140%; } -a.tc5 { font-size: 150%; } -a.tc6 { font-size: 160%; } -a.tc7 { font-size: 170%; } -a.tc8 { font-size: 180%; } -a.tc9 { font-size: 190%; } -a.tc10 { font-size: 200%; } -a.tc11 { font-size: 210%; } -a.tc12 { font-size: 220%; } -a.tc13 { font-size: 230%; } -a.tc14 { font-size: 240%; } -a.tc15 { font-size: 250%; } -a.tc16 { font-size: 260%; } -a.tc17 { font-size: 270%; } -a.tc18 { font-size: 280%; } -a.tc19 { font-size: 290%; } -a.tc20 { font-size: 300%; } +a.cloud_0 {font-size: 90%; } +a.cloud_1 {font-size: 110%; } +a.cloud_2 {font-size: 140%; } +a.cloud_3 {font-size: 150%; } +a.cloud_4 {font-size: 160%; } +a.cloud_5 {font-size: 180%; } +a.cloud_6 {font-size: 200%; } a.tag { background: url(../pix/tag_blue.png) left center no-repeat;