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