2007-10-11 16:25:56 +00:00
|
|
|
#!/usr/bin/perl
|
2007-10-10 21:48:12 +00:00
|
|
|
require "/var/www/perl/include.pl";
|
|
|
|
|
|
|
|
#get tags from database and fill $page with xml
|
|
|
|
sub fill_tagcloud {
|
|
|
|
#connect to db
|
2007-10-11 10:00:38 +00:00
|
|
|
my $dbh = DBI->connect("DBI:mysql:$database:$dbhost", $dbuser, $dbpass) or die $dbh->errstr;
|
2007-10-10 21:48:12 +00:00
|
|
|
|
|
|
|
#prepare query
|
2007-10-11 10:00:38 +00:00
|
|
|
my $sth = $dbh->prepare(qq{select text, count from tagcloud }) or die $dbh->errstr;
|
2007-10-10 21:48:12 +00:00
|
|
|
|
|
|
|
#execute it
|
2007-10-11 10:00:38 +00:00
|
|
|
$sth->execute() or die $dbh->errstr;
|
2007-10-10 21:48:12 +00:00
|
|
|
|
|
|
|
#get every returned value
|
|
|
|
while (my ($text, $count) = $sth->fetchrow_array())
|
|
|
|
{
|
|
|
|
#push the new value to the $page->tagcloud array
|
|
|
|
push @{ $page->{tagcloud}->{tag} }, { text => [$text], count => [$count] };
|
|
|
|
}
|
|
|
|
|
|
|
|
#finish query
|
2007-10-11 10:00:38 +00:00
|
|
|
$sth->finish() or die $dbh->errstr;
|
2007-10-10 21:48:12 +00:00
|
|
|
|
|
|
|
#close db
|
2007-10-11 10:00:38 +00:00
|
|
|
$dbh->disconnect() or die $dbh->errstr;
|
2007-10-10 21:48:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#return a username from passed session id
|
|
|
|
sub get_username_from_sid {
|
|
|
|
#get parameters
|
|
|
|
my ($sid) = @_;
|
|
|
|
|
|
|
|
#connect to db
|
2007-10-11 10:00:38 +00:00
|
|
|
my $dbh = DBI->connect("DBI:mysql:$database:$dbhost", $dbuser, $dbpass) or die $dbh->errstr;
|
2007-10-10 21:48:12 +00:00
|
|
|
|
|
|
|
#prepare query
|
2007-10-11 10:00:38 +00:00
|
|
|
my $sth = $dbh->prepare(qq{select username from users where sid = '$sid'}) or die $dbh->errstr;
|
2007-10-10 21:48:12 +00:00
|
|
|
|
|
|
|
#execute it
|
2007-10-11 10:00:38 +00:00
|
|
|
$sth->execute() or die $dbh->errstr;
|
2007-10-10 21:48:12 +00:00
|
|
|
|
|
|
|
#save the resulting username
|
2007-10-11 10:00:38 +00:00
|
|
|
my ($username) = $sth->fetchrow_array() or die $dbh->errstr;
|
2007-10-10 21:48:12 +00:00
|
|
|
|
|
|
|
#finish query
|
2007-10-11 10:00:38 +00:00
|
|
|
$sth->finish() or die $dbh->errstr;
|
2007-10-10 21:48:12 +00:00
|
|
|
|
|
|
|
#close db
|
2007-10-11 10:00:38 +00:00
|
|
|
$dbh->disconnect() or die $dbh->errstr;
|
2007-10-10 21:48:12 +00:00
|
|
|
|
2007-10-11 10:00:38 +00:00
|
|
|
#return
|
2007-10-10 21:48:12 +00:00
|
|
|
return $username;
|
|
|
|
}
|
2007-10-11 10:57:52 +00:00
|
|
|
|
|
|
|
#return a username from passed session id
|
|
|
|
sub get_userid_from_sid {
|
|
|
|
#get parameters
|
|
|
|
my ($sid) = @_;
|
|
|
|
|
|
|
|
#connect to db
|
|
|
|
my $dbh = DBI->connect("DBI:mysql:$database:$dbhost", $dbuser, $dbpass) or die $dbh->errstr;
|
|
|
|
|
|
|
|
#prepare query
|
|
|
|
my $sth = $dbh->prepare(qq{select id from users where sid = '$sid'}) or die $dbh->errstr;
|
|
|
|
|
|
|
|
#execute it
|
|
|
|
$sth->execute() or die $dbh->errstr;
|
|
|
|
|
|
|
|
#save the resulting username
|
|
|
|
my ($username) = $sth->fetchrow_array() or die $dbh->errstr;
|
|
|
|
|
|
|
|
#finish query
|
|
|
|
$sth->finish() or die $dbh->errstr;
|
|
|
|
|
|
|
|
#close db
|
|
|
|
$dbh->disconnect() or die $dbh->errstr;
|
|
|
|
|
|
|
|
#return
|
|
|
|
return $username;
|
|
|
|
}
|