#!/usr/bin/perl # frame.cgi - an image display and navigation script # Copyright (C) 2002 Scott Draves # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. use CGI; sub read_whole_file { my ($fname) = @_; open FH, $fname; $result = ""; while () { $result = $result . $_; } return $result; } $frame="frame3.cgi"; $query = CGI::new(); $dir = $query->param('dir'); $file = $query->param('file'); $zoom = $query->param('zoom'); $image = "$dir/$file"; $image_file = $image; # no dots in image name xxx if ($file =~ /(.*)\.(.*)/) { $zoomed = "$dir/gen/$1.small.jpg"; } else { print STDERR "$frame: image name $image_file has no dot extension\n"; } if ($zoom) { $image_file = $zoomed; } $caption_name = $image; if ($caption_name =~ /(.*)\.[!.]*/) { $caption_name = "$1.caption.html"; $caption = read_whole_file($caption_name); } else { print STDERR "$frame: image name $caption_name has no dot extension\n"; $caption = ""; } $fineprint = <Creative Commons License by spot at draves dot org. eos $fineprint_name = $image; if ($fineprint_name =~ /(.*)\.[!.]*/) { $fineprint_name = "$1.fineprint.html"; if (-e $fineprint_name) { $fineprint = read_whole_file($fineprint_name); } } else { print STDERR "$frame: image name $fineprint_name has no dot extension\n"; } $order_name = "$dir/order"; $order = read_whole_file($order_name); if ("" eq $order) { print STDERR "$frame: order nonexistent.\n"; } # print STDERR "$frame: order = $order\n"; $norder = 0; while ($order =~ /(.*)\n/) { $ORDER{$norder} = $1; $norder += 1; $order = substr($order, 1+length($1)); } $prev = "previous"; $next = "next"; $next_url="$dir"; for ($i = 0; $i < $norder; $i++) { #print STDERR "$frame: trying $file $ORDER{$i}\n"; if ($file eq $ORDER{$i}) { if ($i > 0) { $prev_file = $ORDER{$i-1}; $prev = "previous"; } if ($i < $norder-1) { $next_file = $ORDER{$i+1}; $next_url="$frame?dir=$dir&file=$next_file&zoom=$zoom"; $next = "next"; } $i = $norder; } } $first_file = $ORDER{'0'}; $last_file = $ORDER{$norder - 1}; if ($zoom) { $zoom_target = "$frame?dir=$dir&file=$file&zoom=0"; $zoom_link = "zoom"; } else { if (-r $zoomed) { $zoom_target = "$frame?dir=$dir&file=$file&zoom=1"; $zoom_link = "zoom"; } else { $zoom_link = "zoom"; } } $jscript=<= 32) { var keychar = String.fromCharCode(key); document.location.href="$next_url"; } } document.onkeypress=doit; eojs $header = `djpeg '$image_file' 2>/dev/null | head -2`; if ($header =~ /P.\n(.*) (.*)\n/) { $width = $1; $height = $2; $size_tags = "width=$width height=$height"; } else { $size_tags = ""; } print $query->header(); print $query->start_html(-title=>$image, -style=>{'src'=>'frame_style.css'}, -script=>$jscript); print "\n"; print <
home blog galleries about help
$prev
index
$zoom_link
$next
$caption

$fineprint

eos print $query->end_html; print "\n";