#!/usr/bin/perl
# showreviews.pl by Sid Sowder (sid@vicious.com)
# version 1.0 1999-JUL-22 by ME
# Run this to go through the database and create an HTML file
# of reviews. Quick and dirty.
$database = 'sid';
$hostname = 'localhost';
$user = 'sid';
$password = 'password';
chomp($IP = `cat /home/ssowder/.IP`); # where is my webserver today?
use DBI;
&getInput; # did we get any parameters?
&setSQL; # figure out which select to use
&connectDB; # connect to the database and run the sql
&headers; # HTML headers
# Fetch the rows back from the SELECT statement dropping each in a hash
while ( $ref = $sth->fetchrow_hashref() ) {
$song = "";
while ( $ref2 = $sth2->fetchrow_hashref() ) {
$song.= "\t$ref2->{'title'} ".
"[{'playkey'}')\">".
"mp3]
\n";
}
$ref->{'artist_nm'} =~ s/(.*), The$/The $1/;
$ART=0; #assume the worst
if (length($ref->{'art_url'}) > 0) {
$ART = 1;
unless ($ref->{'art_url'} =~ /http/) {
$ref->{'art_url'} = 'http://'. $IP .'/albumart/'. $ref->{'art_url'};
}
}
$ref->{'album_nm'} = 's/t' unless ($ref->{'album_nm'});
# the dB is not consistent
if ($ref->{'length_tm'} =~ /:00$/) {
if ($ref->{'length_tm'} =~ /00:00:00/) {
$ref->{'length_tm'} = "";
} else {
($min, $sec, $msec) = split(':', $ref->{'length_tm'});
$min=~ s/^0+//; # remove any leading 0s
$ref->{'length_tm'} = "$min:$sec";
}
} else {
($hour, $min, $sec) = split(':', $ref->{'length_tm'});
$hour =~ s/^0+//; # remove any leading 0s
if ($hour) {
$ref->{'length_tm'} = "$hour:$min:$sec";
} else {
$ref->{'length_tm'} = "$min:$sec";
}
}
$ref->{'review_tx'} =~ s/\r//g; # no silly returns
$ref->{'review_tx'} = &wrap($ref->{'review_tx'}); # wrap as nesc.
$ref->{'review_tx'} =~ s/
<\/P>//g; # avoid blanks print "
\n".
"\t$ref->{'artist_nm'}
\n".
"\t$ref->{'album_nm'}
\n".
"\t$ref->{'release_nb'}
\n".
"\t$ref->{'label_nm'}
\n".
"\t$ref->{'tracks_nb'} tracks
\n".
"\t$ref->{'length_tm'}
\n";
if ($song) {
print "\t
\n$song";
}
if ($FORM{'owner'}) {
print "\t
'.$_); } return($finalline); } sub cutIt { $cwa = 50; #wrap at 50th char (49th position) $line = $_[0]; $leftover = ''; print "FULL: $line\n" if ($DEBUG); if (length($line) <= $cwa) { $doneline .= "\t$line
\n"; print "FINAL BIT: $line\n" if ($DEBUG); } else { for ($count=$cwa-1;$count>0;$count--) { $check = substr($line, $count, 1); if ($check =~ /[\s-]/) { $break = $count; last; # $break now contains the position of #the last space or dash } } # For really long lines with no spaces $break = $cwa-1 unless ($count); $break++ if ($check eq '-'); #keep the dash $outline = substr($line,0,$break); $doneline .= "\t$outline\n"; $leftover = substr($line,$break,length($line)-$break); chomp($leftover); $leftover =~ s/^\s+//; &cutIt($leftover) if ($leftover); } return($doneline); } sub getInput { if ($ENV{'QUERY_STRING'}) { @pairs = split(/&/, $ENV{'QUERY_STRING'}); } else { read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); @pairs = split(/&/, $buffer); } foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $value =~ s/~!/ ~!/g; $FORM{$name} = $value; } } sub headers { print <