- my $map_file_date;
- my $doc = $html_document;
-
- my $w2 = int ($img_width * $scale);
- my $h2 = int ($img_height * $scale);
- $doc =~ s/%%WIDTH%%/$w2/g;
- $doc =~ s/%%HEIGHT%%/$h2/g;
-
- local *MAP;
- open (MAP, "<$map_file") || die "couldn't open $map_file: $!";
- if ($DEBUG > 2) { print STDERR "html: opened $map_file\n"; }
-
- flock (MAP, LOCK_SH) || die "couldn't lock $map_file: $!";
- seek (MAP, 0, 0) || die "couldn't rewind $map_file: $!";
- if ($DEBUG > 2) { print STDERR "html: locked $map_file\n"; }
-
- $map_file_date = (stat(MAP))[9];
-
- my $map = "<MAP NAME=\"collage\">\n";
- while (<MAP>) {
- my ($x, $y, $w, $h, $url) =
- m/^([0-9]+) ([0-9]+) ([0-9]+) ([0-9]+) (.*)$/;
- if ($w && $h) {
- $x = int($x * $scale);
- $y = int($y * $scale);
- $w = int($w * $scale);
- $h = int($h * $scale);
-
- # protect against URLs that contain <, >, or ".
- $url =~ s/([<>\"])/uc sprintf("%%%02X",ord($1))/eg;
-
- my $x2 = $x + $w;
- my $y2 = $y + $h;
- $map .=
- "<AREA SHAPE=RECT COORDS=\"$x,$y,$x2,$y2\" HREF=\"$url\">\n";
- }
- }
- $map .= "</MAP>";
- flock (MAP, LOCK_UN) || die "couldn't unlock $map_file: $!";
- close (MAP) || die "couldn't close $map_file: $!";
-
- if ($DEBUG > 2) { print STDERR "html: closed $map_file\n"; }
-
- $doc =~ s/%%MAP%%/$map/g;
-
- my $img_name = "current";
-
- $doc =~ s@%%IMAGE%%@images/$img_name.jpg@g;
-
-
- my $mod_time = $map_file_date;
- if ($script_date > $mod_time) { $mod_time = $script_date; }
-
- if (do_ifmod($mod_time)) {
- return;
- }
-
- my $exp = compute_expires_time($mod_time);
-
- print "Content-Type: text/html\n";
- print "Content-Length: " . length($doc) . "\n";
- print "Last-Modified: " . format_http_time($mod_time) . "\n";
-
- # This is a suggestion to consider the object invalid after the given
- # date. This is sometimes ignored.
- #
- print "Expires: " . format_http_time($exp) . "\n";
-
- # This may or may not cause a cacheing proxy to pass this stuff along.
- # It's not standardized, but was historically used for... something.
- print "Pragma: no-cache\n";
-
- # This says the same thing as the Expires header, but it is a stronger
- # assertion that we're serious and should be listened to.
- #
- my $age = $exp - time;
- print "Cache-Control: max-age=$age, must-revalidate\n";
-
- print "\n";
- print $doc;
-}
-
-
-# Write the interior JPEG document and associated HTTP headers.
-#
-sub cgi_emit_jpeg_document {
-
- my $image_data = "";
- my $jpg_file_date;
- my $do_ims = 0;
-
- # The map file is the means by which we hold write-locks on the image
- # file. So first obtain the lock on that file.
- #
- local *MAP;
- open (MAP, "+<$map_file") || die "couldn't open $map_file: $!";
-
- if ($DEBUG > 2) { print STDERR "jpeg: opened $map_file\n"; }
- flock (MAP, LOCK_SH) || die "couldn't lock $map_file: $!";
- if ($DEBUG > 2) { print STDERR "jpeg: locked $map_file\n"; }
-
- # Now we have exclusive access to the image file. Read it.
- #
- local *IMG;
- open (IMG, "<$image_jpg") || die "couldn't open $image_jpg: $!";
-
- $jpg_file_date = (stat(IMG))[9];
-
- if (do_ifmod($jpg_file_date)) {
- $do_ims = 1;
- if ($DEBUG > 2) {
- my $ims = $ENV{HTTP_IF_MODIFIED_SINCE};
- $ims =~ s/;.*//;
- print STDERR "not-modified-since " .
- localtime(parse_http_time($ims)) . "\n";
- print STDERR "jpg date: " . localtime($jpg_file_date) . "\n";
- }