0)){ for($cnt=0; $cnt<$numRows; $cnt++){ $retVal[] = mysql_result($result, $cnt, "tag"); } } } return $retVal; } // end getTags(...) //// // Given the mediaType, id, and array of tags this updates the database to match. // Since only priviledged users would be using this function, errors are displayed (instead of hidden and logged). //// function setTags($mediaType, $id, $tags){ $db = dil_connect(); $queryString = "DELETE FROM tags WHERE id=$id AND mediaType='$mediaType'"; if(false === mysql_query($queryString, $db)){ dispError("$queryString

".mysql_error()); } $tags = array_unique($tags); for($cnt=0; $cnt
".mysql_error()); } } } } // end setTags(...) //// // Displays the tags given an array of tags and optionally the media-type. //// function dispTags($tags, $mediaType=""){ if(count($tags) > 0){ print "
\n"; print "\n"; print "\n"; print "
Tagged with
\n"; for($cnt=0; $cnt"; print "$tag\n"; print ((($cnt+1)

\n"; } } // end dispTags(...) //// // Displays a side-bar of the 'limit' most popular tags. //// function popularTagBar($limit=10){ $db = dil_connect(); $queryString = "SELECT COUNT(tag) AS numTags, tag FROM tags"; $queryString.= " GROUP BY tag ORDER BY numTags DESC LIMIT $limit"; if($result = mysql_query($queryString,$db)){ if(($numRows = mysql_num_rows($result)) && ($numRows > 0)){ print "\n"; print "\n"; print "
Popular Tags
\n"; for($cnt=0; $cnt<$numRows; $cnt++){ $tag = mysql_result($result, $cnt, "tag"); $numTags = mysql_result($result, $cnt, "numTags"); $tagLink = str_replace(' ', '%20', $tag); print "$tag ($numTags)
\n"; } print "

\n"; } } } // end popularTagB ar(...) //// // Displays a tag cloud. If maxResults is -1, all tags will be displayed. //// function tagCloud($maxResults=150){ $PHP_SELF = $_SERVER['PHP_SELF']; $db = dil_connect(); // TODO: Remove these variables and just code in some specific styles for different tag sizes... tag clouds are only going to appear in one or two places and // should probably follow the same style anyway. $numSizes = 5; $normalSize = 16; $queryString = "SELECT COUNT(tag) as num,tag FROM tags"; $queryString.= " GROUP BY tag"; if($maxResults != -1){ $queryString .= " ORDER BY RAND()$limitString"; } if($result = mysql_query($queryString,$db)){ if(($numRows = mysql_num_rows($result)) && ($numRows > 0)){ for($cnt=0; $cnt<$numRows; $cnt++){ $tag = mysql_result($result, $cnt, "tag"); $num = mysql_result($result, $cnt, "num"); $tags[$tag] = $num; } ksort($tags); // Find min, max, and distribution size $tCopy = $tags; asort($tCopy); $tCopy = array_values($tCopy); $minCount = $tCopy[0]; $maxCount = $tCopy[count($tCopy)-1]; $dist = (($maxCount - $minCount) / $numSizes); $mean = (($maxCount - $minCount) / 2); // Display the cloud foreach($tags as $tag=>$freq){ $diff = floor(($freq - $mean) / $dist); $diff = constrainTo($diff, floor(0-($numSize/2)), floor($numSizes/2)); $fontSize = $normalSize + ($diff * 2); if($fontSize < 0){$fontSize = 0;} $fontSize = constrainTo($fontSize, 0, 72); print "
"; print "$tag"; print "
 \n"; } } } } // end tagCloud(...) ?>