1 package Sesse::pr0n::Image;
5 use Sesse::pr0n::Common qw(error dberror);
10 my $dbh = Sesse::pr0n::Common::get_dbh();
12 # if ($r->connection->remote_ip() eq '80.212.251.227') {
13 # die "Har du lest FAQen?";
16 # Find the event and file name
17 my ($event,$filename,$xres,$yres);
19 if ($r->uri =~ m#^/([a-zA-Z0-9-]+)/([a-zA-Z0-9._-]+)$#) {
22 } elsif ($r->uri =~ m#^/([a-zA-Z0-9-]+)/(\d+)x(\d+)/(nobox/)?([a-zA-Z0-9._-]+)$#) {
27 $infobox = 0 if (defined($4));
30 my ($id, $dbwidth, $dbheight);
31 if ($event eq 'single' && $filename =~ /^(\d+)\.jpeg$/) {
34 # Alas, we obviously need to do this :-)
35 # my $evq = $dbh->prepare('SELECT count(*) AS numev FROM events WHERE id=? AND vhost=?')
36 # or die "prepare(): $!";
37 # my $ref = $dbh->selectrow_hashref($evq, undef, $event, $r->get_server_name)
38 # or dberror($r, "Could not look up $event");
39 # $ref->{'numev'} == 1
40 # or error($r, "Could not find $event", 404, "File not found");
42 # Look it up in the database
43 my $ref = $dbh->selectrow_hashref('SELECT id,width,height FROM images WHERE event=? AND filename=?',
44 undef, $event, $filename);
45 error($r, "Could not find $event/$filename", 404, "File not found") unless (defined($ref));
48 $dbwidth = $ref->{'width'};
49 $dbheight = $ref->{'height'};
52 $dbwidth = -1 unless defined($dbwidth);
53 $dbheight = -1 unless defined($dbheight);
55 # Scale if we need to do so
56 my ($fname,$thumbnail) = Sesse::pr0n::Common::ensure_cached($r, $filename, $id, $dbwidth, $dbheight, $infobox, $xres, $yres);
58 # Output the image to the user
61 $mime_type = "image/jpeg";
63 $mime_type = Sesse::pr0n::Common::get_mimetype_from_filename($filename);
65 $r->content_type($mime_type);
67 my (undef, undef, undef, undef, undef, undef, undef, $size, undef, $mtime) = stat($fname)
68 or error($r, "stat of $fname: $!");
70 $r->set_content_length($size);
71 $r->set_last_modified($mtime);
73 # If the client can use cache, by all means do so
74 if ((my $rc = $r->meets_conditions) != Apache2::Const::OK) {
80 return Apache2::Const::OK;