keyword cloud of gallery2 keywords as drupal page

kylehase
kylehase's picture

Joined: 2005-09-15
Posts: 38
Posted: Mon, 2007-01-29 03:59

I'm trying to make a keyword cloud of gallery2 keywords as a drupal page. The cloud works great but this code seems to break everything else besides the cloud on that page. Any advice would be greatly appreciated. I hear that gallery 2.2 supports clouds with the use of dynamic galleries but I'll probably stay on 2.1 for a while.
Drupal 4.7.5
Gallery 2.1.2

<?php
function getCloud($minFont=10, $maxFont=35) {
    $keyword  = array();
    $cloud = array();
    $my_link = mysql_connect('localhost', 'user', 'pass')
   or die('Could not connect: ' . mysql_error());
    mysql_select_db('gallery2') or die('Could not select database');

    // Grab the tags from the database
    $keyword_query = mysql_query("SELECT g_keywords FROM g2_Item where g_keywords!=\"\" or g_keywords!=NULL  ORDER BY RAND()");
   
    while($t = mysql_fetch_array($keyword_query)) {
        $key_db = explode('; ', $t[0]);
        while(list($key, $value) = each($key_db)){
               $keyword[$value] += 1;
               }
    }
   
    // Get totals to use for font size
    $min = min(array_values($keyword));
    $max = max(array_values($keyword));
    $fix = ($max - $min == 0) ? 1 : $max - $min;

    // Display the tags
    foreach ($keyword as $tag => $count) {
        $size = $minFont + ($count - $min) * ($maxFont - $minFont) / $fix;
        $cloud[] = '<a style="font-size: '. floor($size) .'px" class="cloud" href="/search/gallery/'.$tag.'" title="'.ucfirst($tag).'">'.htmlspecialchars(stripslashes(ucfirst($tag))).'</a>';
    }
// tried with and without the close line below.
    //mysql_close();
    $shown = join("\n", $cloud) . "\n";
    return $shown;
}
?>

<style type="text/css">
#cloud { padding: 0px 15px; }
.cloud { padding: 3px; text-decoration: none; line-height: 60%; }
.cloud:link { color: #94B3C5; }
.cloud:visited { color: #B5B4A0; }
.cloud:hover { color: #ffffff; background: #333366; }
.cloud:focus { color: #ffffff; background: #000066; }
</style>

<?php echo getCloud(10, 35); ?>

There is a long list of sql errors all starting with:

User warning: Table 'gallery2.--sometable--' doesn't exist