#!/usr/bin/perl # Author : bobf # Date : 23 April 2004 # unshift (@INC, "_CGI-BIN"); require "cgi-lib.pl" ; require "addCss.pl" ; &ReadParse(*input); print &PrintHeader; # Script name: imgDisplay.cgi # Usage: imgDisplay.cgi?dir=dir/Path[&p=hou_ald][&pic=indivPicName] # Prints any pics found in user input directory ("dir") as thumbnails that are linked to full size pics. Requires all pics in same # directory with thumbnails named identical to full pics preceeded by "tn_". Settings file required in same directory as pics # containing header text (diplayed on both thumb and pic pages), footerText (diplayed only on individual pic pages, and picture # descriptions. Format is "varName|varValue|0\n". Var names are "headerText", "footerText", and image name (ie: img_1656.jpg). # # Web site specific page start and end are found in "CONTENT/templateStart.dat" and "CONTENT/templateEnd.dat" # # Optional input is "p" which defines additional page content placed on thumbnail page before thumbnails. This file is also placed # in the CONTENT directory, assuming it is info concerning the same subject as the pictures and leads into the pic pages. &printHeader ; # Get page start from CONTENT/templateStart.dat (web site specific header, nav, etc) and display ... # ---- START CONTENT ---- &getPicListing ; # Get pics from user input dir, excluding files that begin with _tn ... &picPageSettings ; # Get variables from $input{dir}/picPageSettings into assoc array $setting{} ... # headerText (like "CDC - Alder Hill Project" -- printed both thumb and indiv pages), # footerText (like "Alder Hill Project" -- only printed if individual pic) # and picture descriptions (not invoked yet) ... &print_pContent ; # if a particular pic input, get it and display it ... &dispThumbsOrOnePic ; # if(! $input{pic}, disp thumbnail page, else display one pic with prev and next links ... if(! $input{pic} ){&printPicPageEnd } # Prints spacer and $setting{footerText} ... # ---- END CONTENT ---- &printFooter ; # Get page end from CONTENT/templateEnd.dat (web site specific footer, nav ends, etc) and display ... sub dispThumbsOrOnePic{ if(! $input{pic} ){ # dir only, display thumbnail page if($input{p}){ undef $head }else{ $head = $setting{headerText} } print qq~ $head
~ ; $y = 0 ; foreach $pic (@pics){ $dispPath = "?dir=" . $input{dir} . "&pic=" . $pic .$p ; $pPath = $input{dir} . "/" . "tn_" . $pic ; print qq~ ~ ; undef $rowEnd ; if(++$y == 3){ $y = 0 ; print" " ; $rowEnd = 1 ; } } if(! $rowEnd){ print" " ; } print"

Click to see big picture)
" ; }else{ $currentPic = $input{pic} ; $currentPath = $input{dir} . "/" . $input{pic} ; $x = 0 ; $notFound = 1 ; $y = @pics ; while(@pics[$x] && $notFound){ if(@pics[$x] eq $input{pic}){ $prevIndex = $x - 1 ; if($x == 0){ undef $prevPath ; $prevLink = "First Picture" ; }else{ $prevPic = @pics[$prevIndex] ; $prevPath = $input{dir} . "/" . @pics[$prevIndex] ; } $nextIndex = $x + 1 ; if($nextIndex == $y){ undef $nextPath ; $nextLink = "No More Pics" ; }else{ $nextPic = @pics[$nextIndex] ; $nextPath = $input{dir} . "/" . @pics[$nextIndex] ; } undef $notFound ; last ; } $x++ ; } $thumbLink = "Thumbnail Page" ; if(-e "$prevPath"){ $prevLink = "<<   Previous" ; } if(-e "$nextPath"){ $nextLink = "Next >>" ; } print qq~ $setting{headerText}
$prevLink                   $thumbLink                   $nextLink
~ ; } } # END of sub dispThumbsOrOnePic sub getPicListing{ @pictures = `ls $input{dir}` ; undef @pics ; undef $pics ; foreach $file (@pictures){ if($file !~ /^tn_/ && ($file =~ /$\.jpg/ || $file =~ /$\.gif/ || $file =~ /$\.png/)){ $file =~ s/[^a-zA-Z0-9_\.\-]//g ; push(@pics,$file) ; } } undef @pictures ; @pics = sort(@pics) ; # if a particular pic was input, create addon to link for it ... if($input{p}){$p = "&p=" . $input{p}} } sub picPageSettings{ undef @settings ; $path = $input{dir} . "/picPageSettings.dat" ; if(-e "$path"){ unless (open (SETTINGS, "<$path")){ $msg="Cannot find, or could not open $path for reading (line# 25)!" ; &errFatalClose($msg) ; } @settings = ; close (SETTINGS); } foreach $line(@settings){ ($name,$var,$reminder) = split(/\|/,$line) ; $setting{$name} = $var ; } } sub printHeader{ unless (open (HEAD, " ; close (HEAD); foreach $l (@header){ print $l ; } } sub print_pContent{ if($input{p} && ! $input{pic}){ # print only if thumbnail page ... $path = "CONTENT/" . $input{p} . ".dat" ; unless (open (CONTENT, "<$path")){ $msg="Cannot find, or could not open $path for reading (line# 41)!" ; &errFatalClose($msg) ; } @pContent = ; close (CONTENT); foreach $l (@pContent){ print $l ; } undef @pContent ; } } sub printPicPageEnd{ print qq~

 

$setting{footerText} ~ ; } sub printFooter{ unless (open (FOOT, " ; close (FOOT); foreach $l (@footer){ print $l ; } } sub errFatalClose{ my $msg = shift ; print qq~

$msg Terminating script. Unable to continue.
~ ; exit ; }