#!/usr/bin/perl -wT # # LiveFrame - a web based photo album and slideshow application # # http://www.liveframe.org # # copyright (c)1999, 2000; this is homemade # jim@thisishomemade.com # # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License. # # http://www.gnu.org/copyleft/gpl.html # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. use strict; use CGI (); # CONFIGURTION OPTIONS # filesystem path to liveframe directory: #my $lfdir = "/www/liveframe.org/demo/lfdir"; my $lfdir = "/home/www/html/clandestino/pix/2003"; # URL to liveframe.cgi: #my $lfcgiurl = "http://www.liveframe.org/demo/liveframe.cgi"; my $lfcgiurl = "http://www.clandestino.com/pix/2003.cgi"; # URL to liveframe directory: #my $lfdirurl = "http://www.liveframe.org/demo/lfdir"; my $lfdirurl = "http://www.clandestino.com/pix/2003"; # LiveFrame site name: my $sitename = "LiveFrame"; # enable start screen: my $startscreen = "yes"; # configuration file separator character: my $sepchar ="}"; # use the galleryorder file to do manual gallery ordering: my $orderon = "yes"; # you shouldn't need to modify anything below this line. ######################################################## # VERSION INFO my $version = "0.94e"; # LISTEN TO THE CGI my $query = new CGI; my $galleryrequest = $query->path_info() || "unspecified"; my $mode = $query->param('m') || "nonav"; my $show = $query->param('ss') || "no"; my $showspeed = $query->param('showspeed') || "8"; my $showresumespeed = $query->param('showresumespeed') || "8"; my $setsize = $query->param('sz'); my $setpage = $query->param('pg'); # IF GALLERY IS UNSPECIFIED, DISPLAY INDEX if ($galleryrequest eq "unspecified") { lfindex(); } # SET VARIABLES, DO SOME INTITAL THINKING, RUN THE PARSER my @photos; my @gallerylist; my $title; my $gallerycaption; my $indextitle; my $indexcaption; my $indexpreview; my $indexed; my $gallery; my $page; my $size; $galleryrequest = substr($galleryrequest, 1); ($gallery, $page, $size) = split(/\s*\/\s*/, $galleryrequest, 3); unless (defined $page) { $page = $setpage; } unless (defined $page) { if ($startscreen eq "yes") { $page = "start"; $mode = "frameset"; } else { $page = "1"; $mode = "frameset"; } } elsif ($page eq "") { if ($startscreen eq "yes") { $page = "start"; $mode = "frameset"; } else { $page = "1"; $mode = "frameset"; } } if (defined $setsize) { $size = $setsize; } unless (defined $size) { $size = "no"; } parseconfig(); # DETERMINE PAGE CREATION MODE if ($mode eq "display") { picture("display"); } elsif ($mode eq "nav") { picture("nav"); } elsif ($mode eq "photo") { picture("photo"); } elsif ($mode eq "nonav") { if ($page eq "start") { frameset(); } picture("photo"); } elsif ($mode eq "preview") { preview(); } elsif ($mode eq "shownav") { frameset(); } else { frameset(); } # SUB: PARSE THE CONFIG FILE sub parseconfig { my ($parsemode) = @_; my @parseindex; open(CONFIG, "${lfdir}/galleries/$gallery/config") || error("The gallery specified could not be viewed: $!"); while () { chomp; s/#.*//; s/^\s+//; s/\s+$//; next unless length; unless (defined $parsemode) { push @photos, [ split(/\s*$sepchar\s*/, $_, 2) ]; } else { push @parseindex, [ split(/\s*$sepchar\s*/, $_, 2) ]; } } $title = $photos[0][0]; $gallerycaption = $photos[0][1]; $indextitle = $parseindex[0][0]; $indexcaption = $parseindex[0][1]; $indexpreview = $parseindex[1][0]; } # SUB: CREATE THE MASTER FRAMESET sub frameset { my %content = ( htmllfcgiurl => $lfcgiurl, htmllfdirurl => $lfdirurl, htmltitle => $title, htmlpage => $page, htmlsize => $size, htmlversion => $version, htmlsitename => $sitename, htmlgallery => $gallery, htmlgallerycaption => $gallerycaption, htmlshow => $show, htmlshowspeed => $showspeed, ); header(); print template("${lfdir}/templates/frameset.tmpl", \%content); } # SUB: CREATE THE PREVIEW PANE sub preview { my %content = ( htmllfcgiurl => $lfcgiurl, htmllfdirurl => $lfdirurl, htmltitle => $title, htmlpage => $page, htmlsize => $size, htmlversion => $version, htmlsitename => $sitename, htmlgallery => $gallery, ); header(); print template("${lfdir}/templates/previewtop.tmpl", \%content); my @list; my $x; for $x ( 1 .. $#photos ) { if (defined $photos[$x][0]) { my %content2 = ( htmllfcgiurl => $lfcgiurl, htmllfdirurl => $lfdirurl, htmltitle => $title, htmlpage => $page, htmlsize => $size, htmlversion => $version, htmlsitename => $sitename, htmlgallery => $gallery, htmlpreviewpage => $x, htmlpreviewname => $photos[$x][0], ); print template("${lfdir}/templates/previewmiddle.tmpl", \%content2); } } print template("${lfdir}/templates/previewbottom.tmpl", \%content); } # SUB: CREATE THE DISPLAY FRAMESET, PHOTO AND NAVIGATION FRAMES sub picture { my $showon = " "; my $shownum = "1"; my $newshowspeed = "8"; my $showimage = "slideshow"; my $showbutton = "pause"; my $sizemenu; my $sizeselected; my @sizemenuitems; my $navcount = 1; my $navpercent = "50"; my ($pagemode) = @_; if ($page eq "start") { start(); } else { my $lastnum = $page; --$lastnum; my $currentnum = $page; my $nextnum = $page; ++$nextnum; my $current = $photos[$currentnum][0]; my $next = $photos[$nextnum][0]; my $currentphoto = "$current"; my $caption = $photos[$currentnum][1] || " "; if ($startscreen eq "yes") { if ($lastnum < 1) { $lastnum = "start"; } $nextnum = "start" unless $next; } else { my $verylastnum = $#photos; if ($lastnum < 1) { $lastnum = "$verylastnum"; } $nextnum = "1" unless $next; } if ($show eq "yes") { ++$navcount; if ($showspeed eq "pause") { $showbutton = "resume"; $newshowspeed = "$showresumespeed"; $shownum = "$nextnum"; $showimage = "slideshowpause"; } else { $showon = ""; $showresumespeed = "$showspeed"; $newshowspeed = "pause"; $shownum = "$page"; } } if (-d "${lfdir}/galleries/${gallery}/display") { $size = "display"; } else { ++$navcount; if (-d "${lfdir}/galleries/${gallery}/xsmall") { if ($size eq "no") { $size = "xsmall"; } if ($size eq "xsmall") { $sizeselected = " selected"; } else { $sizeselected = " "; } push @sizemenuitems, "xs"; } if (-d "${lfdir}/galleries/${gallery}/small") { if ($size eq "no") { $size = "small"; } if ($size eq "small") { $sizeselected = " selected"; } else { $sizeselected = " "; } push @sizemenuitems, "sm"; } if (-d "${lfdir}/galleries/${gallery}/medium") { if ($size eq "no") { $size = "medium"; } if ($size eq "medium") { $sizeselected = " selected"; } else { $sizeselected = " "; } push @sizemenuitems, "md"; } if (-d "${lfdir}/galleries/${gallery}/large") { if ($size eq "no") { $size = "large"; } if ($size eq "large") { $sizeselected = " selected"; } else { $sizeselected = " "; } push @sizemenuitems, "lg"; } if (-d "${lfdir}/galleries/${gallery}/xlarge") { if ($size eq "no") { $size = "xlarge"; } if ($size eq "xlarge") { $sizeselected = " selected"; } else { $sizeselected = " "; } push @sizemenuitems, "xl"; } } $sizemenu = join "\n", @sizemenuitems; if ($navcount eq 2) { $navpercent = "33"; } elsif ($navcount eq 3) { $navpercent = "25"; } if ($currentphoto eq "") { error("The image specified could not be found."); } my %content = ( htmlversion => $version, htmlsitename => $sitename, htmltitle => $title, htmllfcgiurl => $lfcgiurl, htmllfdirurl => $lfdirurl, htmlgallery => $gallery, htmllastnum => $lastnum, htmlnextnum => $nextnum, htmlpage => $page, htmlcaption => $caption, htmlcurrentphoto => $currentphoto, htmlshow => $show, htmlshowon => $showon, htmlshowspeed => $showspeed, htmlnewshowspeed => $newshowspeed, htmlshowbutton => $showbutton, htmlshowresumespeed => $showresumespeed, htmlshownum => $shownum, htmlshowimage => $showimage, htmlsize => $size, htmlsizemenu => $sizemenu, htmlnavpercent => $navpercent, ); header(); if ($mode eq "display") { print template("${lfdir}/templates/display.tmpl", \%content); } elsif ($mode eq "photo") { print template("${lfdir}/templates/photo.tmpl", \%content); } elsif ($mode eq "nav") { print template("${lfdir}/templates/navleft.tmpl", \%content); if ($show eq "yes") { print template("${lfdir}/templates/navslide.tmpl", \%content); } unless ($size eq "display") { print template("${lfdir}/templates/navsize.tmpl", \%content); } print template("${lfdir}/templates/navright.tmpl", \%content); } else { print template("${lfdir}/templates/photononav.tmpl", \%content); } } } # SUB: GET A LIST OF GALLERIES sub getgalleries { my @hidelist; my $hidden; my $galleryitem; my $gallerydir = "${lfdir}/galleries"; if ($orderon eq "yes") { if (-f "$gallerydir/order.conf") { open(ORDERFILE, "$gallerydir/order.conf"); while () { chomp; s/#.*//; s/^\s+//; s/\s+$//; next unless length; push @gallerylist, $_; } } else { print "

Error
order.conf could not be opened: $!

(Turn manual gallery ordering off or create an order.conf file!)

"; } } else { my $hiddenfile = "$gallerydir/hidden.conf"; if (-f "$hiddenfile") { open(HIDEFILE, "$hiddenfile"); while () { chomp; s/#.*//; s/^\s+//; s/\s+$//; next unless length; push @hidelist, $_; } #unless (defined @hidelist) unless (@hidelist) { $hidden = " "; } else { $hidden = join "|", @hidelist; } } else { $hidden = " "; } opendir(GALLERY, $gallerydir) || error("The gallery directory could not be opened: $!"); while( defined ($galleryitem = readdir GALLERY) ) { next if $galleryitem =~ /^(\.\.??|CVS|hidden.conf|order.conf|$hidden)$/; push @gallerylist, "$galleryitem"; } } } # SUB: CREATE START PAGE sub start { my $prevgallerytitle; my $prevgallerycaption; my $prevgallerypreview; my $nextgallerytitle; my $nextgallerycaption; my $nextgallerypreview; my $prevgallery; my $nextgallery; my $prevgallerynum; my $nextgallerynum; my $gallerynum; my $galleryitem; getgalleries(); my $thisgallery = $gallery; my %content = ( htmlversion => $version, htmlsitename => $sitename, htmltitle => $title, htmllfcgiurl => $lfcgiurl, htmllfdirurl => $lfdirurl, htmlgallery => $thisgallery, htmlgallerycaption => $gallerycaption, ); header(); print template("${lfdir}/templates/starttop.tmpl", \%content); $gallerynum = 0; foreach (@gallerylist) { if ($_ eq $gallery) { last; } $gallerynum++; } my $lastgallerynum = $#gallerylist; if ($lastgallerynum > 1) { $prevgallerynum = $gallerynum; --$prevgallerynum; $nextgallerynum = $gallerynum; ++$nextgallerynum; if ($prevgallerynum < 0) { $prevgallerynum = $lastgallerynum; } if ($nextgallerynum > $lastgallerynum) { $nextgallerynum = "0"; } $gallery = "$gallerylist[$prevgallerynum]"; $prevgallery = $gallery; parseconfig("parseindex"); $prevgallerytitle = $indextitle; $prevgallerycaption = $indexcaption; $prevgallerypreview = $indexpreview; $gallery = "$gallerylist[$nextgallerynum]"; $nextgallery = $gallery; parseconfig("parseindex"); $nextgallerytitle = $indextitle; $nextgallerycaption = $indexcaption; $nextgallerypreview = $indexpreview; my %content2 = ( htmllfcgiurl => $lfcgiurl, htmllfdirurl => $lfdirurl, htmlprevgallery => $prevgallery, htmlnextgallery => $nextgallery, htmlprevgallerytitle => $prevgallerytitle, htmlprevgallerycaption => $prevgallerycaption, htmlprevgallerypreview => $prevgallerypreview, htmlnextgallerytitle => $nextgallerytitle, htmlnextgallerycaption => $nextgallerycaption, htmlnextgallerypreview => $nextgallerypreview, ); print template("${lfdir}/templates/startmiddle.tmpl", \%content2); } print template("${lfdir}/templates/startbottom.tmpl", \%content); exit; } # SUB: CREATE INDEX sub lfindex { my %content = ( htmlversion => $version, htmltitle => $title, htmllfcgiurl => $lfcgiurl, htmllfdirurl => $lfdirurl, htmlsitename => $sitename, ); header(); print template("${lfdir}/templates/galleryindextop.tmpl", \%content); getgalleries(); my $x; for $x (@gallerylist) { $gallery = $x; parseconfig("parseindex"); my %listcontent = ( htmllfcgiurl => $lfcgiurl, htmllfdirurl => $lfdirurl, htmlgallery => $gallery, htmlindextitle => $indextitle, htmlindexcaption => $indexcaption, htmlindexpreview => $indexpreview, ); print template("${lfdir}/templates/galleryindexitem.tmpl", \%listcontent); } print template("${lfdir}/templates/galleryindexbottom.tmpl", \%content); exit; } #SUB: HTML HEADER sub header { print "Content-type: text/html\n\n"; } # SUB: TEMPLATE GENERATOR sub template { my ($templatename, $contents) = @_; my $text; local $/; local *TMPL; open(TMPL, "< $templatename\0") || return; $text = ; close(TMPL); $text =~ s{ %% ( .*? ) %% } { exists( $contents->{$1} ) ? $contents->{$1} : "" }gsex; return $text; } # SUB: ERROR HANDLING sub error { my ($message) = @_; my %content = ( htmlversion => $version, htmlsitename => $sitename, htmlmessage => $message, htmllfcgiurl => $lfcgiurl, htmllfdirurl => $lfdirurl, ); header(); print template("${lfdir}/templates/error.tmpl", \%content); exit; }