#!/usr/bin/perl ############################################################################## # # thumbnail - thumbnail organizer/picture viewer # # Copyright 1998 GorskiSoft # # Darrin M. Gorski # # Revisions: # # 08-Jan-1998 dgorski Initial coding. # ############################################################################## # # CONFIGURABLE OPTIONS # # HTML stuff # $html_title = "Thumbnail Picture Organizer"; $html_header = '

Thumbnail Organizer

'; $html_footer = '
Pages produced by Thumbnail
'; $body_attributes = "BGCOLOR=\"FFFFFF\""; $border_width = 6; $columns = 3; # # files, URLs, and dirs # $photo_dir_url = 'http://www.gorski.net/pictures'; $thumbnail_dir_url = 'http://www.gorski.net/pictures/thumbnails'; $thumbnail_dir = '/usr/etc/thumbnails'; $script_url = 'http://www.gorski.net/cgi-bin/thumbnail.pl'; $caption_file = '/usr/thumbnails/captions.txt'; # END CONFIGURABLE OPTIONS # ############################################################################## # subroutines sub error { print &HTML_out(<thumbnail - error An error occurred: $_[0]

EOF exit; } sub get_filelist { my @list, $key, $val; if ($caption_file && open(CAPTIONS,"<$caption_file") ) { while () { ($key,$val) = split(/:/,$_,2); push(@list,$key); $captions{$key} = $val; } close(CAPTIONS); } else { opendir(DIR, $thumbnail_dir) || &error("Unable to read directory $thumbnail_dir: $!"); while ($key = readdir(DIR)) { push(@list,$key) unless $key =~ /^\.\.?$/; } closedir(DIR); } return(@list); } sub HTML_out { # returns entity headers (and entity) return("Content-type: TEXT/HTML\r\nContent-length: " . length($_[0]) . "\r\n\r\n$_[0]"); } sub build_table { # &build_table($columns,@list); my ($columns, @list) = @_; my $loop = 0; my $td_width = int( (1 / $columns) * 100 ); my $table = "\r\n"; while (@list) { # build a row $table .= "\r\n"; for ($loop=0; $loop < $columns; ++$loop) { $_ = shift(@list); if (!/^$/) { $table .= "\r\n"; } else { $table .= "\r\n"; } } $table .= "\r\n"; } $table .= "
" . "\r\n" . "" . "
$captions{$_}

\r\n"; return($table); } sub picture_frame { # &picture_frame($picture); return("$html_title: $_[0]" . "\r\n$html_header

" . "
" . "


$html_footer"); } sub table_frame { # &table_frame($table); return("$html_title" . "\r\n$html_header

" . "

Click on any image to see a full-size version

" . "$_[0]

$html_footer"); } # main() $|=1; if ($ENV{'QUERY_STRING'} ne '') { print &HTML_out(&picture_frame($ENV{'QUERY_STRING'})); } else { print &HTML_out(&table_frame(&build_table($columns,&get_filelist))); } exit;