#!/usr/local/bin/perl5.00503 # # LiveFrame - a web based photo album and slideshow application # # http://www.liveframe.org # # copyright (c)1999, 2000; this is homemade # jim@thisishomemade.com # # program modified by Marc Lenburg, copyright (c) 2001, 2002 # marc@marclenburg.net # # 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 = "/usr/local/apache/share/htdocs/davislab/images/"; # URL to liveframe.cgi: my $lfcgiurl = "http://www.ucsf.edu/davislab/images/images.cgi"; # URL to root directory: my $rooturl = "http://www.ucsf.edu/davislab"; # URL to liveframe directory: my $lfdirurl = "http://www.ucsf.edu/davislab/images/"; # LiveFrame site name: my $sitename = "davis lab > images"; # enable start screen: my $startscreen = "no"; # 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.94d"; # LISTEN TO THE CGI my $query = new CGI; my $mode = $query->param('m') || "display"; 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'); my $galleryrequest = $query->path_info() || "unspecified"; if ($galleryrequest eq "unspecified") { $mode = "preview"; $galleryrequest = "/images"; } # 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; my $firstbit; my $lastbit; ######################################### # ADD SOME NEW VARIABLES FOR NEXT GALLERY LINK my $nextgallerytitle; my $nextgalleryname; my $nextgalleryurl; my $nextgalleryleader = "next: "; my $nomoregalleriesleader = "return to "; my $nextgallerytail; my $nomoregalleriestail =" index"; ######################################### $galleryrequest = substr($galleryrequest, 1); if ($galleryrequest =~ /cgi/) { ($firstbit, $lastbit) = split(/cgi\//, $galleryrequest, 2); unless ($lastbit) { lfindex(); exit; } } else {$lastbit = $galleryrequest;} ($gallery, $page, $size) = split(/\s*\/\s*/, $lastbit, 3); #########debug #header(); # print "$galleryrequest\n"; # print "$firstbit\n"; # print "$lastbit\n"; # print "$gallery\n"; # print "$page\n"; # print "$size\n"; # print "$mode\n"; unless (defined $page) { $page = $setpage; } unless (defined $page) { if ($startscreen eq "yes") { $page = "start"; $mode = "display"; } else { $page = "1"; $mode = "preview"; } } elsif ($page eq "") { if ($startscreen eq "yes") { $page = "start"; $mode = "display"; } else { $page = "1"; $mode = "display"; } } ######debug #print "$page\n"; #print "$mode"; if (defined $setsize) { $size = $setsize; } unless (defined $size) { $size = "no"; } parseconfig(); if ($mode eq "preview") { preview(); } else { picture("display"); } exit; # 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*/, $_, 3) ]; } else { push @parseindex, [ split(/\s*$sepchar\s*/, $_, 3) ]; } } $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, htmlrooturl => $rooturl, 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, htmlrooturl => $rooturl, 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, htmlrooturl => $rooturl, htmltitle => $title, htmlpage => $page, htmlsize => $size, htmlversion => $version, htmlsitename => $sitename, htmlgallery => $gallery, htmlpreviewpage => $x, htmlpreviewname => $photos[$x][0], htmlphototitle => $photos[$x][1] || " ", htmlcaption => $photos[$x][2] || " ", ); 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 $totalphotos = $#photos; ######################################### # if at the end, change mode and get name of next gallery # ######################################### if ($page eq $totalphotos) { $mode ="end"; nextgallery(); } ######################################### ######################################### # if at the beginning, change mode# ######################################### if ($page eq 1) { $mode ="beginning"; } ######################################### my $current = $photos[$currentnum][0]; my $next = $photos[$nextnum][0]; my $currentphoto = "$current"; my $phototitle = $photos[$currentnum][1] || " "; my $caption = $photos[$currentnum][2] || " "; if (-d "${lfdir}/galleries/${gallery}/display") { $size = "display"; } if ($currentphoto eq "") { error("The image specified could not be found."); } my %content = ( htmlversion => $version, htmlsitename => $sitename, htmltitle => $title, htmllfcgiurl => $lfcgiurl, htmllfdirurl => $lfdirurl, htmlrooturl => $rooturl, htmlgallery => $gallery, htmllastnum => $lastnum, htmlnextnum => $nextnum, htmlpage => $page, htmltotalphotos => $totalphotos, htmlphototitle => $phototitle, 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, htmlnextgallerytitle => $nextgallerytitle, htmlnextgalleryname => $nextgalleryname, htmlnextgalleryurl => $nextgalleryurl, ); header(); if ($mode eq "display") { print template("${lfdir}/templates/display.tmpl", \%content); } ######################################### # ADD TEMPLATE FOR END OF GALLERY elsif ($mode eq "end") { print template("${lfdir}/templates/end.tmpl", \%content); } ######################################### # ADD TEMPLATE FOR BEGINNING OF GALLERY elsif ($mode eq "beginning") { print template("${lfdir}/templates/beginning.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) { $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, htmlrooturl => $rooturl, 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, htmlrooturl => $rooturl, 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, htmlrooturl => $rooturl, 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, htmlrooturl => $rooturl, 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, htmlrooturl => $rooturl, ); header(); print template("${lfdir}/templates/error.tmpl", \%content); exit; } ######################################### # SUB: GET NEXT GALLERY sub nextgallery { my ($item, $nextgallery, @parseindex); my $currentposition = -1; my $count=0; getgalleries(); my $lastgallery = $#gallerylist; foreach $item (@gallerylist) { if ($gallery eq $item) { $currentposition = $count; } ++$count; } if ($currentposition eq -1) { error("couldn't find current gallery, $gallery"); return; } else { $nextgallery = $currentposition + 1; if ($nextgallery > $lastgallery) { $nextgalleryurl = $lfcgiurl; $nextgallerytitle = $nomoregalleriesleader . $sitename . $nomoregalleriestail; } else { $nextgalleryname = $gallerylist[$nextgallery]; $nextgalleryurl = $lfcgiurl . "/" . $nextgalleryname; open(CONFIG, "${lfdir}/galleries/$nextgalleryname/config") || error("couldn't find next gallery: $!"); while () { chomp; s/#.*//; s/^\s+//; s/\s+$//; next unless length; push @parseindex, [ split(/\s*$sepchar\s*/, $_, 2) ]; } $nextgallerytitle = $nextgalleryleader . $parseindex[0][0] . $nextgallerytail; } } }