issue2, first tag cloud implementation
authorAndreas Unterkircher <unki@netshadow.at>
Fri, 15 Jun 2007 18:10:30 +0000 (18:10 +0000)
committerAndreas Unterkircher <unki@netshadow.at>
Fri, 15 Jun 2007 18:10:30 +0000 (18:10 +0000)
git-svn-id: file:///var/lib/svn/phpfspot/trunk@93 fa6a889d-dae6-447d-9e79-4ba9a3039384

phpfspot.class.php
stylesheet.css
templates/credits.tpl

index 0095ca819b13157c4e971acaecb907db3a42296b..af51752f8f0b56cabe8b090b7b350de7d789b644 100644 (file)
@@ -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 "<a href=\"javascript:Tags('add', ". $tag .");\" class=\"tag\">". $this->tags[$tag] ."</a>&nbsp;";
+          // 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 "<a href=\"javascript:Tags('add', ". $key .");\" class=\"tag\" style=\"font-size: ". $size ."%;\">". $this->tags[$key] ."</a>&nbsp;";
 
       }
 
index 72955f685daeed0749e60aff42e566468ee88d8c..d1f3ae01bdb9f7bb1c18c18af6fa5b2e45097162 100644 (file)
@@ -21,7 +21,6 @@ table, tr, td {
 }\r
 \r
 td.tags {\r
-   font-size:              14px;\r
    width:                  150px;\r
    padding:                2px;\r
    padding-top:            10px;\r
index 2bff9ee58b30155d083abd88faf907a89201a0b7..b15127ebef3c4186aa2470d300074e40629f6a1f 100644 (file)
@@ -17,6 +17,8 @@
       Bubble base JavaScript by <a href="http://www.websnapr.com/index.php?action=previewbubble">WebSnapr</a>
       <hr />
       <a href="http://wiki.bluga.net/HTML_AJAX/HomePage">HTML_AJAX</a>
+      <hr />
+      PHP tag-cloud code by <a href="http://prism-perfect.net/archive/php-tag-cloud-tutorial/">Jenny Ferenc</a>.
      </td>
     </tr>
    </table>