Description:
Deployed as it's own op, takes a cgi argument and sets it as the user's avatar URL for display with "show_avatar"
Box Code:
## START set_avatar ##
# set_avatar scoop box by Jason Eaton
# http://www.on2raj.org
# This box sets an avatar to display next to the
# user's posts and stories.
# The other side of it is show_avatar and
# choose_avatar
# In order to use this box, you must addd a
# table to your SQL
# database named "avatar"
# with the following SQL command:
#
# CREATE TABLE avatar (
# avatar varchar(255),
# user varchar(255),
# uid int(10) DEFAULT 0,
# INDEX (uid)
# );
# Deploy the box as it's own op on a template with
# a navigation menu, and give it /avatar/ as a URL
# template.
#
# Structure stolen nearly completely from janra's
# "referer_catch" box. Thanks for that.
my $raw_user = $S->{NICK};
my $uid = $S->{UID};
my $raw_avatar = $S->cgi->param('avatar');
my $user = $S->{DBH}->quote($raw_user);
my $avatar = $S->{DBH}->quote($raw_avatar);
# check if that URL is already in the db
my ($rv, $sth) = $S->db_select({
WHAT => 'count(uid) AS num',
FROM => 'avatar',
WHERE => "uid = $uid"
});
my $dbresponse = $sth->fetchrow_hashref();
my $uid_exists = $dbresponse->{num};
# count the URL
if ( $uid_exists ) {
($rv, $sth) = $S->db_update({
WHAT => 'avatar',
SET => "avatar = $avatar",
WHERE => "uid = $uid"
});
} else {
$S->db_insert({ INTO => 'avatar',
COLS => 'uid, user, avatar',
VALUES => "$uid, $user, $avatar"
});
}
my $content = qq{ <table><tr><th>Setting Avatar</th>
</tr><tr><td>Sucessfully set avatar $avatar for user $user, uid $uid<br>|BOX,show_avatar,$user|</td></tr></table>};
return $content;
## END set_avatar ##
|