tobias's point of view |
Main »
Picst 2 #!/usr/bin/perl -wT # name this code picst.cgi # dump into a directory with a bunch of pictures. # when browsed to, will dynamically generate urls for all the pictures in the dir. # pictures open in a new browser window when url is clicked on. # thumbnails can be generated and placed in a thumbs/ dir by using the script # thumbn.pl # find pics/ \( -iname *.jpg -o -iname *.jpeg -o -iname *.png -o -iname *.gif -o -iname *.tif -o -iname *.tiff \) -exec ./thumbn.pl {} \; use URI::Escape; $ENV{ 'PATH' } = '/bin:/usr/bin:/usr/local/bin'; # satisfy the taint switch to use our cmd line below. my $urlVar = "dir="; $urlVar = $ENV{'QUERY_STRING'} if $ENV{'QUERY_STRING'}; my ($key, $dir) = split /=/,$urlVar; # my 'key' should be "dir" . $dir = uri_unescape("$dir"); $dir =~ s/^\/|\/$//g; my @subDir = split /\//,$dir; my $urlRoot = $ENV{SCRIPT_NAME}; $urlRoot =~ s/\?.+$/\//; # remove the get values in the url my $cgiName = $urlRoot; $cgiName =~ s/\/$//; $cgiName =~ s/^.+\///g; # want clean cgi name my $navBar = " <a href=\"$cgiName\">home</a>" if($dir ne ''); # want url for 'home' if not at home. $navBar = "home" if($dir eq ''); # no url if at home. $navBar .= genNavBar(@subDir); # get dir branch and set up nav bar. print "Content-type: text/html\n\n"; print <<EOP; <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <HTML> <HEAD> <META HTTP-EQUIV="Expires" CONTENT="Mon, 23 Sep 1996 01:21:00 GMT"> <META http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <TITLE> My Family Pics</TITLE> <STYLE TYPE="TEXT/CSS"> <!-- p { color: #999999; font-size:8pt; font-family:arial; font-style:normal; font-weight:normal; background-color: black; } body { margin-left:50px; color:#999999; font-size:8pt; font-family:arial; font-style:normal; font-weight:normal; background-color: black; } A:link { color:#dddd00; font-size:small; font-family:arial; font-style:normal; font-weight:normal; text-decoration:none; } A:active { color:#ffff00; font-size:small; font-family:arial; font-style:normal; font-weight:normal; } A:visited { color:#999900; font-size:small; font-family:arial; font-style:normal; font-weight:normal; text-decoration:none; } A:hover { color:#ffff00; font-size:small; font-family:arial; font-style:normal; font-weight:normal; } .thumbnail{ position: relative; z-index: 0; } .thumbnail:hover{ background-color: transparent; z-index: 50; } .thumbnail span{ /*CSS for enlarged image*/ position: absolute; background-color: #ffffbb; padding: 5px; left: -1000px; border: 1px dashed gray; visibility: hidden; color: black; text-decoration: none; } .thumbnail span img{ /*CSS for enlarged image*/ border-width: 0; padding: 2px; } .thumbnail:hover span{ /*CSS for enlarged image on hover*/ visibility: visible; top: 0; left: 60px; /*position where enlarged image should offset horizontally */ } hr { color: #999900; width: 600px; height: 1px; background-color: #999900; margin: 0px 0px 0px 0px; border: 0; } --> </STYLE> </HEAD> <BODY> <br> <h1>My Family Pictures</h1> EOP #print "<br>debug:: urlRoot=$urlRoot; cgiName=$cgiName; urlVar=$urlVar; key=$key; dir=$dir <br>\n"; print "$navBar <br><br>\n"; opendir(DIR,"./$dir") || die "NO SUCH Directory: ./$dir"; foreach my $file ( sort readdir(DIR) ){ # print the dir at top of the listings. if($file =~ /^(\.||\.\.||index.html|RCS|.*\.cgi|.*\.swp|thumbs|.*\.pl)$/i){next;} my $fullDir = "$dir/$file/"; $fullDir =~ s/^\/|\/$//g; # remove leading or trailing slashes my $fullDirEncoded = uri_escape($fullDir); my $fileCnt; unless ($fullDir =~ m/^(.+)$/){die "dir had something not expected:$fullDir \n";} # to satisfy the taint switch on the perl line. $fullDir = $1; $fullDir =~ s/\'/\'\\\'\'/g; # in the find below a quote ' mark needs to be escaped like this '\'' my $cmd = "find '$fullDir' -path \"*thumbs\" -prune -o \\( -type f -print \\) | wc -l"; $fullDir =~ s/\'\\\'\'/\'/g; # now we need to remove the escapped quote mark. if(-d "$fullDir"){$fileCnt = `$cmd`;} if(! $fileCnt | ($fileCnt == 0)){$fileCnt = "no";} if(-d "$fullDir"){print " <a href=\"$cgiName\?dir=$fullDirEncoded\">dir-> $file</a>   $fileCnt files <br>\n";} } closedir(DIR); print "<br><br>\n"; opendir(DIR,"./$dir") || die "NO SUCH Directory: ./$dir"; foreach my $file ( sort readdir(DIR) ){ if($file =~ /^(\.||\.\.||index.html|RCS|.*\.cgi|.*\.swp|thumbs|.*\.pl)$/i){next;} my $fullDir = "$dir/$file/"; my $thumb = $file; my $thumbMid = $file; $thumb =~ s/(.+?)\.(.+)$/$1_thumb\.$2/; # need to looks for filenames the _thumb.xxx $thumbMid =~ s/(.+?)\.(.+)$/$1_thumb_Mid\.$2/; # need to looks for filenames the _thumb_Mid.xxx $fullDir =~ s/^\/|\/$//g; # remove leading or trailing slashes my $fileSize = sprintf("%.2f",(-s $fullDir) / 1000000); # want file size in Mbytes. if(-d $fullDir){next;} # dirs we print at top of file list to screen ie already printed by this time. elsif(-e "$dir/thumbs/$thumb" && -e "$dir/thumbs/$thumbMid"){print " <a href=\"$fullDir\" target=\"_blank\">$file</a> \n<a class=\"thumbnail\" href=\"$fullDir\" target=\"_blank\"> \n<img src=\"$dir/thumbs/$thumb\" border=\"0\" ALT=\"pic\">\n<span><img src=\"$dir/thumbs/$thumbMid\" ALT=\"\"> </span></a>";} # with thumbnail and Mid size thumbnail elsif(-e "$dir/thumbs/$thumb"){print " <a href=\"$fullDir\" target=\"_blank\">$file</a> <a href=\"$fullDir\" target=\"_blank\"> \n<img src=\"$dir/thumbs/$thumb\" border=\"0\"></a>";} # with thumbnail only else{print " <a href=\"$fullDir\" target=\"_blank\">$file</a>";} # no thumbnail. print " ( $fileSize mb ) <br>\n"; # this only prints on files. } closedir(DIR); print <<EOPrint; <br><br><br><br> <hr> <a href="$cgiName">home</a> my family pictures. Click on 'home' to go back to the beginning. <a href="http://validator.w3.org/check?uri=referer"><img src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01 Transitional" height="15" width="44"></a> <a href="http://jigsaw.w3.org/css-validator/check/referer"> <img style="border:0;width:44px;height:15px" src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Valid CSS!" > </a> <br> </body></html> EOPrint sub genNavBar { # generate the nav bar to get back my @dirs = @_; # sent cginame, dir array my ($cnt,$updir,$navString); my $arrayCnt = scalar @dirs; foreach my $dir (@dirs){ $cnt++; $updir .= "$dir/"; if($cnt < $arrayCnt){$navString .= qq' / <a href="?dir=$updir">$dir</a>';} else{$navString .= " / $dir"}; } return($navString); } # end of sub genNavBar. |
top level subjects: |
Page last modified on August 19, 2012, at 11:25 PM |