#!/usr/bin/perl -wT

#---libsetup---

# having . in @INC can cause tainting issues for use

no lib '.';

use FindBin;
BEGIN {
  ($dir)=($FindBin::Bin=~/^([\w\d\-\/\.]+)$/)
    or die "invalid current directory $FindBin::Bin";
}
use lib $dir;

#---endlibsetup---

use strict;

use PhotoPub::Global qw(&init &finit);
use PhotoPub::CGIBase qw($query &printheader);
use PhotoPub::Config;

use PhotoPub::Album qw(&albumhtml);

use HTML::Entities;

&init();

# Various things mean that we don't actually know the age when we start
# printing HTML
#   - samples of pictures
#   - counts of photos in ranges
#   - ...
# But it means that the user has to wait ages to see anything if we wait
# to output the headers and only output all the HTML at once, so we get it
# wrong. Set the following variable to 1 if you want to delay this.
 
my $delayheaders=0;

if(!$delayheaders) {
  &albumhtml(scalar $query->Vars,\&printheader,sub { print shift; });
} else {
  my $outtext="";
  &albumhtml(scalar $query->Vars,sub { },sub { $outtext.=shift; });
  &printheader();
  print $outtext;
}

&finit();
