#!c:/perl/bin/perl.exe ################################################## # Photosearch 04/06/99 by Jeff Waldock # Lists pictures ################################################## $rootdir="/usr/photos/main/"; $rooturl="/photos/main/"; $cgiroot="/usr/photos/"; $imageurl="/images"; $cgibin="/photos"; $cgilocation = "$cgibin/newphotosearch.pl"; ################################################### # Get Date and Time from Server @days=("Sun","Mon","Tue","Wed","Thu","Fri","Sat"); @longdays=("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"); @month=("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"); # Get Date and Time from Server $date = localtime(); ($sec,$min,$hour,$mday,$mon,$yr,$wday,$yday,$isdst) = localtime(time); if ($min < 10) {$min="0".$min; } $shorttime="$hour:$min"; $year=$yr+1900; $date1="$days[$wday] $mday $month[$mon] $year at $shorttime"; $date2="$longdays[$wday] $mday $month[$mon] $year at $shorttime"; $thisyear=$year; print "Content-Type: text/html\n\n"; $request_method=$ENV{'REQUEST_METHOD'}; if ($request_method eq "GET") { $form_info=$ENV{'QUERY_STRING'}; } else { $size_of_info=$ENV{'CONTENT_LENGTH'}; read(STDIN, $form_info, $size_of_info); } @key_value_pairs=split(/&/,$form_info); foreach $key_value (@key_value_pairs) { ($key,$value)=split(/=/,$key_value); $value=~ tr/+/ /; $value=~ s/%([\dA-Fa-f][\dA-Fa-f])/pack("C",hex($1))/eg; $INPUT{$key} = $value; #print "",$key," = ",$value,"
\n"; } $sortorder=$INPUT{'sortorder'}; unless ($sortorder) { $sortorder="LatestFirst"; } $yfile=$INPUT{'yfile'}; $thisid=$INPUT{'id'}; $size=$INPUT{'size'}; if ($yfile) { &ShowPicture; } $searchstring=$INPUT{'search'}; $searchstring =~ s/ //g; $searchstring =~ s/_/ /g; $picsperframe=$INPUT{'n'}; unless(($searchstring)||($picsperframe)) { #first call - set up the list of search words $searchform=1; &ShowSearchForm; } else { unless ($picsperframe) { $picsperframe=4; } if ($searchstring) { #generate the search index &SearchSetup; } $pic1=$INPUT{"first"}; unless ($pic1) { $pic1=1; } &Header; &GetPhotoData; } &Footer; print "\n"; exit; sub ShowSearchForm { print < Jeff Waldock's Photographs

Jeff's Photos - keyword search


1. Select a keyword from the list given, or enter a value into the box.
2. Choose the number of images to display per page.
3. Press GO!

Choose a keyword: End_of_Section1 $infile=$rootdir."/keywords.txt"; open (FILE,$infile); @lines=; close(FILE); $nn=$#lines; if ($nn>16) { $nn=16; } print " Select the number of images per page
Enter a keyword: GO

End_of_Section2 } sub SearchSetup { $infile=$rootdir."index.txt"; open (FILE,$infile); @lines=; close(FILE); $lastdate=$lines[0]; $lastdate =~ s/"//g; $outfile=$rootdir."searchindex.txt"; open (OFILE,">$outfile"); print OFILE "$searchstring\n"; for ($j=1; $j<=$#lines; $j++) { @info=split(/\|/,$lines[$j]); $kw=$info[8]; if ($kw =~ $searchstring) { print OFILE $lines[$j]; } } close(OFILE); #print "hi!\n"; } sub GetPhotoData { if ($sortorder eq "None") { $resfile=$rootdir."temp.txt"; open (FILE,$resfile); @lines=; close(FILE); $searchstring=$lines[0]; } else { $resfile=$rootdir."searchindex.txt"; open (FILE,$resfile); @oldlines=; close(FILE); $searchstring=$oldlines[0]; &SortByFileDate; } #sub GetPhotoData { # $resfile=$rootdir."searchindex.txt"; # open (FILE,$resfile); # @lines=; # close(FILE); # $searchstring=$lines[0]; $searchstring =~ s/\n//g; print "

Jeff's Photos

"; $numpix=$#lines; if ($numpix>1) { print "Found $numpix images containing "$searchstring"

\n"; } else { if ($numpix==0) { print "Found 0 images containing "$searchstring"

\n"; } else { print "Found 1 image containing "$searchstring"

\n"; } } $p=$picsperframe-1; $pic2=$pic1+$p; if ($pic2>$numpix) {$pic2=$numpix;} $w=(100-$p*5)/$picsperframe; $pnow=$pic2-$pic1+1; $pleft=$p-$pnow; print "\n"; #get the photo information for ($j=0; $j<$pnow; $j++) { @info=split(/\|/,$lines[$pic1+$j]); $id[$j]=$info[0]; if ($id[$j]) { $section[$j]=$info[2]; $section[$j] =~ tr/A-Z/a-z/; $filename[$j]=$info[3]; $filename[$j]=~tr/A-Z/a-z/; $filename[$j]=~s/ //g; $filepath[$j]=$filename[$j]; @ss=split(/\//,$filename[$j]); $nss=$#ss; #print "nss=$nss
\n"; $thumburl[$j]=""; $sectionpath[$j]=''; for ($f=0;$f<$nss;$f++) { #print $ss[$f]."\\"; $thumburl[$j]=$thumburl[$j].$ss[$f].'/'; $sectionpath[$j]=$sectionpath[$j].$ss[$f].'/'; } $thumburl[$j]=$thumburl[$j].'thumb/'; $thumburl[$j]=$thumburl[$j].$ss[$nss]; #$thumburl[$j]=~s/\\/\//g; #$thumburl[$j]=~tr/A-Z/a-z/; $fileurl[$j]=$filename[$j]; $fileurl[$j]=~s/$rootdir/$rooturl/; $thumburl[$j]=~s/$rootdir/$rooturl/; $xpix[$j]=$info[4]; $ypix[$j]=$info[5]; $pixels[$j]=$xpix[$j]." by ".$ypix[$j]." pixels "; ($size[$j])=(stat($filepath[$j]))[7]; $filesize[$j]="(".int($size[$j]/1000)."K)"; $imagedet[$j]=$info[6]; $datetaken[$j]=$info[7]; $keywords[$j]=$info[8]; $description[$j]=$info[9]; } } #do the labels in row 1 print "\n"; for ($j=0; $j<=$p; $j++) { if ($j<$pnow) { print "\n"; } else { print "\n"; } } print "\n"; #do the photo thumbnails in row 2 print "\n"; for ($j=0; $j<=$p; $j++) { if ($j<$pnow) { print "\n"; } else { print "\n"; } } print "\n"; #do the info in row 3 print "\n"; for ($j=0; $j<=$p; $j++) { if ($j<$pnow) { print "\n"; } else { print "\n"; } } print "\n"; #links to other sizes in row 4 print "\n"; for ($j=0; $j<=$p; $j++) { if ($j < $pnow) { print "\n"; } else { print "\n"; } } print "\n"; print "
$id[$j] 
"; print "\"$pixels[$j]$filesize[$j]\"

"; print "

 
"; print "$datetaken[$j]

"; print "$description[$j]"; print "

 
"; $thisfile=$filename[$j]; $thisfile=~tr/\\/\//; $thisfile=~s/$sectionpath[$j]//; $sectionpath[$j]=~tr/\\/\//; $sp=$sectionpath[$j]; @files=<$sp*>; $n=@files-1; for ($jj=0;$jj<=$n;$jj++) { if (-d $files[$jj]) { $xfile=$files[$jj]."/".$thisfile; $yfile=$xfile; $yfile=~s/$rootdir/$rooturl/; $s=$xfile; $s=~s/$sectionpath[$j]//; $s=~s/$thisfile//; $s=~s/\///g; if (-e $xfile) { unless ($xfile=~"thumb") { $ypath=$yfile; $ypath=~s/$rooturl/$rootdir/; ($size)=(stat($ypath))[7]; $filesize="(".int($size/1000)."K)"; #print "$s pixels
\n"; print "$s pixels $filesize
\n"; } } } } print "
 
\n"; print "

\n"; print "

\n"; print "\n"; print "
\n"; #print "$pic1, $pic2, $numpix
\n"; if (($pic1 > 1)&&($pic2 < $numpix)) { $prevpic=$pic1-$picsperframe; $nextpic=$pic1+$picsperframe; $lastpic=$numpix-$picsperframe+1; print "
"; print "\"Back\n"; print "\"Previous\n"; print "\"Next\n"; print "\"Go\n"; print "
"; } elsif (($pic1<2)&&($pic2>=$numpix)) { } elsif ($pic1 < 2) { $nextpic=$pic1+$picsperframe; $lastpic=$numpix-$picsperframe+1; print "
"; print "\n"; print "\n"; print "\"Next\n"; print "\"Go\n"; print "
"; } elsif ($pic2 >= $numpix) { $prevpic=$pic1-$picsperframe; print "
"; print "\"Back\n"; print "\"Previous\n"; print "\n"; print "\n"; print "
"; } else { } print "
\n"; $picbeg=$pic1; $picend=$pic2; if ($pic2>$numpix) { $picend=$numpix; } print "
Showing $picbeg to $picend of $numpix
\n"; print "
\n"; print "
\n"; } sub Header { print "\n"; print "\n"; print "\n"; print "\n"; } sub Footer { $infile=$rootdir."index.txt"; open (FILE,$infile); @lines=; close(FILE); $lastdate=$lines[0]; $lastdate =~ s/"//g; print "\n"; print "\n"; print "\n"; print "\n"; if ($searchstring) { print "\n"; print "\n"; print "\n"; } print "
"; print "\"Back"; unless ($searchform) { print "\"Back"; } print "© Jeff Waldock, $thisyear
\n"; print "This query: $date2
Data file last updated: $lastdate
 
 Page "; print ""; $nframes=int($numpix/$picsperframe)+1; $jpage=1; for ($jpix=1;$jpix<=$nframes;$jpix++) { $start=($jpix-1)*$picsperframe+1; $end=$start+$picsperframe-1; $thispage=0; #check to see if this is the current page if (($pic1>=$start)&&($pic1<=$end)) { $thispage=1; } if ($end>$numpix) { $end=$numpix; if ($thispage==1) { print "$jpage"; } else { print "$jpage"; } } else { if ($thispage==1) { print "$jpage|"; } else { print "$jpage|"; } } $jpage++; } print "
\n"; } sub ShowPicture { print "Content-Type: text/html\n\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "
\n"; $idsel=$thisid; &GetOnePhotoInfo; print "$datetaken  $description

"; print "
\n"; print "

\n"; exit; } sub GetOnePhotoInfo { $resfile=$rootdir."index.txt"; open (FILE,$resfile); @lines=; close(FILE); $lastdate=$lines[0]; $lastdate =~ s/#//g; $numpix=$#lines; #find the details for this pic for ($j=0; $j<=$numpix; $j++) { @info=split(/\|/,$lines[$pic1+$j]); $id=$info[0]; if ($id == $idsel) { $section=$info[2]; $section =~ tr/A-Z/a-z/; $filename=$info[3]; $filepath=$filename; @ss=split(/\\/,$filename); $nss=$#ss; $fileurl=$filename; $fileurl=~s/\\/\//g; $fileurl=~tr/A-Z/a-z/; $fileurl=~s/$rootdir/$rooturl/; $imagedet=$info[6]; $datetaken=$info[7]; $keywords=$info[8]; $description=$info[9]; last; } } } sub SortByFileDate { $zmonth{"January"}="01"; $zmonth{"February"}="02"; $zmonth{"March"}="03"; $zmonth{"April"}="04"; $zmonth{"May"}="05"; $zmonth{"June"}="06"; $zmonth{"July"}="07"; $zmonth{"August"}="08"; $zmonth{"September"}="09"; $zmonth{"October"}="10"; $zmonth{"November"}="11"; $zmonth{"December"}="12"; $zmonth{"Jan"}="01"; $zmonth{"Feb"}="02"; $zmonth{"Mar"}="03"; $zmonth{"Apr"}="04"; $zmonth{"Jun"}="06"; $zmonth{"Jul"}="07"; $zmonth{"Aug"}="08"; $zmonth{"Sep"}="09"; $zmonth{"Oct"}="10"; $zmonth{"Nov"}="11"; $zmonth{"Dec"}="12"; for ($j=1; $j<=$#oldlines; $j++) { @info=split(/\|/,$oldlines[$j]); $lin++; #find the filename (to use as the sort key) @parts=split(/\|/,$oldlines[$j]); $filedate=$parts[7]; $filemonth=$filedate; $fileyear=$filedate; $fileyear =~ s/[^0-9 ]//gi; $filemonth =~ s/[0-9]//gi; $fileyear =~ s/ //g; $filemonth =~ s/ //g; $thisdate=$fileyear.$zmonth{$filemonth}; #@fileparts=split(/\\/,$filepath); #$fn=$fileparts[$#fileparts]; #$fn =~ s/[^0-9]//gi; $newlines{$oldlines[$j]}=$thisdate; #print "$thisdate .. $oldlines[$j]
\n"; } if ($sortorder eq "LatestFirst") { @lines=sort { $newlines{$b} <=> $newlines{$a} } keys %newlines; } else { @lines=sort { $newlines{$a} <=> $newlines{$b} } keys %newlines; } #write data to temp.txt $outfile=$rootdir."temp.txt"; #print "outfile=$outfile
\n"; open (NFILE,">$outfile"); print NFILE $lastdate; for ($j=1; $j<=$#oldlines; $j++) { print NFILE $lines[$j]; } close(NFILE); }