]> git.sur5r.net Git - contagged/blob - tags.php
correct URL encoding on search redirects
[contagged] / tags.php
1 <?php
2   require_once('inc/init.php');
3   ldap_login();
4
5   //prepare templates
6   tpl_std();
7   $smarty->assign('tagcloud',tag_cloud());
8   //display templates
9   header('Content-Type: text/html; charset=utf-8');
10   $smarty->display('tags.tpl');
11
12   function tag_cloud(){
13     global $conf;
14     global $LDAP_CON;
15     global $FIELDS;
16     if(!$conf['extended']) return;
17
18     $result = ldap_queryabooks('(objectClass=inetOrgPerson)',$FIELDS['_marker']);
19
20     $max = 0;
21     $min = 999999999;
22     $tags = array();
23     foreach ($result as $entry){
24       if(!empty($entry[$FIELDS['_marker']]) && count($entry[$FIELDS['_marker']])){
25         foreach($entry[$FIELDS['_marker']] as $marker){
26           $marker = strtolower($marker);
27           if (empty($tags[$marker])) { $tags[$marker]=0; }
28           $tags[$marker] += 1;
29           if($tags[$marker] > $max) $max = $tags[$marker];
30           if($tags[$marker] < $min) $min = $tags[$marker];
31         }
32       }
33     }
34     ksort($tags);
35     tag_cloud_weight(&$tags,$min,$max,6);
36
37     $out = '';
38     foreach($tags as $tag => $cnt){
39       $out .= '<a href="index.php?marker='.rawurlencode($tag).'" class="cloud_'.$cnt.'">';
40       $out .= htmlspecialchars($tag).'</a> ';
41     }
42
43     return $out;
44   }
45
46   /**
47    * Calculate weights for a nicer tagcloud distribution
48    */
49   function tag_cloud_weight(&$tags,$min,$max,$levels){
50     // calculate tresholds
51     $tresholds = array();
52     for($i=0; $i<=$levels; $i++){
53         $tresholds[$i] = pow($max - $min + 1, $i/$levels);
54     }
55
56     // assign weights
57     foreach($tags as $tag => $cnt){
58         foreach($tresholds as $tresh => $val){
59             if($cnt <= $val){
60                 $tags[$tag] = $tresh;
61                 break;
62             }
63             $tags[$tag] = $levels;
64         }
65     }
66   }
67
68