From: Andreas Unterkircher Date: Fri, 15 Jun 2007 18:10:30 +0000 (+0000) Subject: issue2, first tag cloud implementation X-Git-Tag: phpfspot-1.2~242 X-Git-Url: https://git.nubati.net/cgi-bin/gitweb.cgi?p=phpfspot.git;a=commitdiff_plain;h=83cde026568fe57a2ccaac2977ef21ae5de7bf38 issue2, first tag cloud implementation git-svn-id: file:///var/lib/svn/phpfspot/trunk@93 fa6a889d-dae6-447d-9e79-4ba9a3039384 --- diff --git a/phpfspot.class.php b/phpfspot.class.php index 0095ca8..af51752 100644 --- a/phpfspot.class.php +++ b/phpfspot.class.php @@ -144,13 +144,52 @@ class PHPFSPOT { public function getAvailableTags() { - foreach($this->avail_tags as $tag) - { - if(isset($_SESSION['selected_tags']) && in_array($tag, $_SESSION['selected_tags'])) + $result = $this->db->db_query(" + SELECT tag_id as id, count(tag_id) as quantity + FROM photo_tags + GROUP BY tag_id + ORDER BY tag_id ASC + "); + + $tags = Array(); + + while($row = $this->db->db_fetch_object($result)) { + $tags[$row['id']] = $row['quantity']; + } + + // change these font sizes if you will + $max_size = 125; // max font size in % + $min_size = 75; // min font size in % + + // get the largest and smallest array values + $max_qty = max(array_values($tags)); + $min_qty = min(array_values($tags)); + + // find the range of values + $spread = $max_qty - $min_qty; + if (0 == $spread) { // we don't want to divide by zero + $spread = 1; + } + + // determine the font-size increment + // this is the increase per tag quantity (times used) + $step = ($max_size - $min_size)/($spread); + + // loop through our tag array + foreach ($tags as $key => $value) { + + if(isset($_SESSION['selected_tags']) && in_array($key, $_SESSION['selected_tags'])) continue; - // return all available (= not selected) tags - print "". $this->tags[$tag] ." "; + // calculate CSS font-size + // find the $value in excess of $min_qty + // multiply by the font-size increment ($size) + // and add the $min_size set above + $size = $min_size + (($value - $min_qty) * $step); + // uncomment if you want sizes in whole %: + // $size = ceil($size); + + print "". $this->tags[$key] ." "; } diff --git a/stylesheet.css b/stylesheet.css index 72955f6..d1f3ae0 100644 --- a/stylesheet.css +++ b/stylesheet.css @@ -21,7 +21,6 @@ table, tr, td { } td.tags { - font-size: 14px; width: 150px; padding: 2px; padding-top: 10px; diff --git a/templates/credits.tpl b/templates/credits.tpl index 2bff9ee..b15127e 100644 --- a/templates/credits.tpl +++ b/templates/credits.tpl @@ -17,6 +17,8 @@ Bubble base JavaScript by WebSnapr
HTML_AJAX +
+ PHP tag-cloud code by Jenny Ferenc.