Helpful Information
 
 
Category: vBulletin 2.x Full Releases
[ Release v2.0.1 ] Avatar import from filesystem

Me again - another simple integration hack for those moving from something like UBB. In my old hacked up UBB, I had my own avatar hack (not one of the common ones floating around). At any rate, all the avatars were stored in a single directory, and they all were named "username.gif", where "username" was the account name (bob.gif, dumbass.gif, etc.). If you have avatars for folks who have spaces in their username, and you've replaced them with underscores (john_doe.gif), this script will handle that, too.

Backup your customavatar table first. If you hose it with this script, don't cry to me....you've been warned. :p

This is a perl script - to be run from the directory containing your avatars:


!/usr/bin/perl

# Must be run *from* the avatar directory

# Configuration section
$avatardir = ".";

use DBI;

$datasource="DBI:mysql:vbulletin";

$dbh = DBI->connect( $datasource, 'id', 'password');

if ( !defined $dbh ) {
die "Cannot connect to mySQL server: $DBI::errstr\n";
}

my @filearray = glob("$tinydir/*.gif");

foreach $filename (@filearray)
{
$filename =~ s/\.\///g;
$username = $filename;
$username =~ s/_/ /g;
$username =~ s/\.gif//g;

# Okay, grab the user ID from the database that matches this user
$quoted_username = $dbh->quote($username);
$sth = $dbh->prepare("SELECT userid FROM user WHERE username = $quoted_username");
$sth->execute;

@result = $sth->fetchrow_array;

$user_id = $result[0];

if($user_id == "") {
print "Invalid account name: [$user_id] $quoted_username (skipping)\n";
$sth->finish;
next;
}

print "Processing --> [$user_id] $username ($filename)\n";

$sth->finish;

# Prepare file for binary insertion
open(IMG, "<$filename");
read(IMG, $filestuff, 100000);
close(IMG);

$quoted_bindata = $dbh->quote($filestuff);
$quoted_filename = $dbh->quote($filename);

# Grab current time
$currtime = time();

# Insert the user's original avatar into the customavatar table
$q = "INSERT into customavatar (userid,avatardata,dateline,filename) VALUES ($user_id, $quoted_bindata, $currtime, $quoted_filenam
e)";
$sth = $dbh->prepare($q);

$sth->execute || print "ERROR INSERTING ROW!\n";

$sth->finish;
}

exit;


Paste this into a script, chmod 755, and run it from the directory containing your avatars.

You may need to play with a bit to work with your directory of avatars - every hacked-up UBB (or whatever) is different. But it should be a good start at least ...

Voila.

Cheers.

Nice easy hack..

I will try it..










privacy (GDPR)