Main »

Show



show.cgi version 1



#!/usr/bin/perl -Tw

use strict;
#use CGI qw(:standard);
#use CGI::Carp qw(warningsToBrowser fatalsToBrowser);

my $image_subDir = 'landscapes/sky';
my $pageHeading = "Slide Show";
my $pageSubHeading = "run on test pics";
my $footer = 'website design and photography copyright 2013 by <a href="http://lisalanephoto.com/" target="_blank">Lisa Lane Photography';
my $picExtString = '(\.jpg)|(\.jpeg)|(\.png)|(\.gif)|(\.tif)|(\.tiff)';

#====================================
my $script_name = $ENV{SCRIPT_NAME}; # returns: /testarea/publicDomainPics2/show.cgi
   $script_name =~ m/^.+\/(.+)$/;
   $script_name = $1 if($1);  # sets: show.cgi
my $cgi_url=$ENV{'REQUEST_URI'}; # returns: pov.us/testarea/publicDomainPics2/show.cgi?autoPlay=0&picN=3
   $cgi_url=~ m/(.+?)\?/;
   $cgi_url= $1 if($1);
my $image_dir=$ENV{SCRIPT_FILENAME}; # returns: /var/www/webA1/web/testarea/publicDomainPics2/show.cgi
   $image_dir=~ m/(.+?\/)$script_name$/;
   $image_dir= $1 if($1);
   $image_dir = $image_dir . $image_subDir;

opendir (DATA, "$image_dir");
# this sorts by alphanumeric so order can be set by filename.
#my @filenames = sort { $a cmp $b } grep (!/^\.\.?$/, readdir (DATA)); # this ignored "." dir, but allowed subdir or non pic files.
my @filenames = sort { $a cmp $b } grep (/$picExtString$/i, readdir (DATA));  # we just want to display pic type files and not dirs.
closedir (DATA);

my $numberOfPics = @filenames;

my %query = &parse_query;

$query{'picN'} = 0 unless $query{'picN'};      # first time through picN is not sent.
my $image_name = $filenames[$query{'picN'}];
my $nextpicN = $query{'picN'} + 1;
my $prevpicN = $query{'picN'} - 1;
my $currentPic = $query{'picN'} +1;

$nextpicN = 0              if($nextpicN > @filenames-1); 
$prevpicN = @filenames-1   if($prevpicN < 0);

&html_main;

sub parse_query {

  my @pairs = split(/&/, $ENV{'QUERY_STRING'}); 
  foreach my $pair (@pairs) {
    my ($name, $value) = split(/=/, $pair);
    $query{$name} = $value;
  }
  return(%query);
}

sub html_main{

# cgi variables passed via url ie: 125grandview.com/cgi-bin/show.cgi?autoPlay=0&amp;picN=4

my $delay = 3;
my $date = "/bin/date";
my $refreshURL;
my $play;

my $autoPlay = $query{'autoPlay'};
	#my $autoPlay_orig = $autoPlay;
$autoPlay = 1 unless defined $autoPlay;
if($autoPlay){$refreshURL = "Refresh:  $delay; URL=$cgi_url?autoPlay=1&picN=$nextpicN\n";$play = "stop";$autoPlay=0;} 
else{$refreshURL = "Refresh:  600; URL=$cgi_url?autoPlay=0&amp;picN=$nextpicN\n";$play = "start";$autoPlay=1;}
print "$refreshURL";
print "Content-type: text/html; charset=utf-8\n\n";
	#print "autoPlay = $autoPlay_orig <br> refreshURL = $refreshURL<br>\n";

print qq~
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-type" content="text/html;charset=UTF-8">
<style type="text/css">
p {margin:0em 0 0em 0; color:#AAAAAA}
body {color:#FFFFFF; background-color:#000000;}
img {  max-width: 85%;  max-height: 85%;}
a:link {text-decoration:none; color:#AAAAAA;}
a:visited {text-decoration:none; color:#AAAAAA;}
a:hover {text-decoration:underline; color:#FFFFFF;}
a:active {text-decoration:underline; color:#FFFFFF;}
</style>
<title>Slide Show: $image_name</title>
</head>
<body>

<p align="left">&nbsp;&nbsp;<a href="$cgi_url"><strong><font face="Arial,Helvetica" size="6" color="#FFFFFF">$pageHeading</font></strong></a> &nbsp;<font face="Arial,Helvetica" size="2" color="#AAAAAA">$pageSubHeading</font></p>

<p align="center"><font face="Arial,Helvetica" size="2">
   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
<a href="$cgi_url?autoPlay=0&amp;picN=$prevpicN">&nbsp;&nbsp;&nbsp;&lt;&nbsp;&nbsp;&nbsp;</a>
  &nbsp; <a href="$cgi_url?autoPlay=0&amp;picN=$nextpicN">&nbsp;&nbsp;&nbsp;&gt;&nbsp;&nbsp;&nbsp;</a>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<a href="$cgi_url?autoPlay=$autoPlay&amp;picN=$nextpicN">&nbsp;&nbsp;$play&nbsp;&nbsp;</a>
</font>
<font face="Arial,Helvetica" size="4">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font face="Arial,Helvetica" size="1" color="#666666"><a href="$cgi_url/contact.cgi">contact / info</a>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
 $currentPic / $numberOfPics

</font></p>

<center>
<a href="$image_subDir/$image_name" target="_blank"><img src="$image_subDir/$image_name" border="0" alt="click for hi rez image"></a>
</center>
<br><br><br >
<p align="right"><font face="Arial,Helvetica" size="1">$footer</a>&nbsp;&nbsp;&nbsp;&nbsp;</font></p>

</body></html>

~;

}

top level subjects:

Page last modified on October 29, 2014, at 08:43 PM

^