'******************************************************************* '****** ASP Based tag cloud **************************************** '****** Created by Paul Guise - paulguise@gmail.com - 7-25-06 ****** '******************************************************************* Function tagCloud(theTable,sqlCond) Dim aDigits, tempTagHolder, biggestNum OpenDB() strSql = "SELECT Tags FROM "&theTable&" WHERE Status=1" Set objRs = objConn.Execute (strSql) While Not objRs.EOF 'dump all of the tags into one variable tempTagHolder = tempTagHolder & objRs("Tags") & " " objRs.MoveNext Wend objRs.Close() 'make it pretty tempTagHolder = Trim(Replace(tempTagHolder," "," ")) tempTagHolder = lcase(tempTagHolder) 'split the veriable into an array aDigits = split(tempTagHolder, " ") 'sort the tags alphabetically, will return the variable given SingleSorter aDigits 'testing: display the alphabetized list 'Response.Write(join(aDigits," ") & "

") 'get the tag with the highest mention biggestNum = 0 lastTag = aDigits(0) For i=0 to UBound(aDigits) If lastTag = aDigits(i) Then tagCount = tagCount+1 Else If tagCount >= biggestNum Then biggestNum = tagCount End If tagCount = 1 End If lastTag = aDigits(i) If i = UBound(aDigits) Then If tagCount >= biggestNum Then biggestNum = tagCount End If End If Next 'loop through the array and output the tags Dim lastTag, tagCount, i, newTag, loopHolder, tempNewTag lastTag = aDigits(0) tagCount=0 For i=0 to UBound(aDigits) If lastTag = aDigits(i) Then tagCount = tagCount+1 Else Response.Write (""&renderTag(lastTag,tagCount,biggestNum)&" ") tagCount = 1 End If lastTag = aDigits(i) If i = UBound(aDigits) Then Response.Write (""&renderTag(lastTag,tagCount,biggestNum)&" ") End If Next End Function Function renderTag(tagName,tagCount,biggestNum) Dim tempContent If tagCount < (biggestNum*0.20) Then 'tempContent="
"&tagName&"("&tagCount&")
" tempContent="
"&tagName&"
" End If If tagCount >= (biggestNum*0.20) Then 'tempContent="
"&tagName&"("&tagCount&")
" tempContent="
"&tagName&"
" End If If tagCount >= (biggestNum*0.40) Then 'tempContent="

"&tagName&"("&tagCount&")

" tempContent="

"&tagName&"

" End If If tagCount >= (biggestNum*0.60) Then 'tempContent="

"&tagName&"("&tagCount&")

" tempContent="

"&tagName&"

" End If If tagCount >= (biggestNum*0.80) Then 'tempContent="

"&tagName&"("&tagCount&")

" tempContent="

"&tagName&"

" End If If tagCount >= biggestNum Then 'tempContent="

"&tagName&"("&tagCount&")

" tempContent="

"&tagName&"

" End If renderTag=tempContent End Function '***** Snagged from 4GuyFromRolla - http://www.4guysfromrolla.com/demos/bubblesort.asp **** Sub SingleSorter( byRef arrArray ) Dim row, j Dim StartingKeyValue, NewKeyValue, swap_pos For row = 0 To UBound( arrArray ) - 1 'Take a snapshot of the first element in the array because if there is a 'smaller value elsewhere in the array we'll need to do a swap. StartingKeyValue = arrArray ( row ) NewKeyValue = arrArray ( row ) swap_pos = row For j = row + 1 to UBound( arrArray ) 'Start inner loop. If arrArray ( j ) < NewKeyValue Then 'This is now the lowest number - remember it's position. swap_pos = j NewKeyValue = arrArray ( j ) End If Next If swap_pos <> row Then 'If we get here then we are about to do a swap within the array. arrArray ( swap_pos ) = StartingKeyValue arrArray ( row ) = NewKeyValue End If Next End Sub