error repor when header/footer absent
[mkgallery.git] / mkgallery.pl
1 #!/usr/bin/perl
2
3 my $version='$Id$';
4
5 # Recursively create image gallery index and slideshow wrappings.
6 # Makes use of modified "slideshow" javascript by Samuel Birch
7 # http://www.phatfusion.net/slideshow/
8
9 # Copyright (c) 2006-2008 Eugene G. Crosser
10
11 #  This software is provided 'as-is', without any express or implied
12 #  warranty.  In no event will the authors be held liable for any damages
13 #  arising from the use of this software.
14 #
15 #  Permission is granted to anyone to use this software for any purpose,
16 #  including commercial applications, and to alter it and redistribute it
17 #  freely, subject to the following restrictions:
18 #
19 #  1. The origin of this software must not be misrepresented; you must not
20 #     claim that you wrote the original software. If you use this software
21 #     in a product, an acknowledgment in the product documentation would be
22 #     appreciated but is not required.
23 #  2. Altered source versions must be plainly marked as such, and must not be
24 #     misrepresented as being the original software.
25 #  3. This notice may not be removed or altered from any source distribution.
26
27 package FsObj;
28
29 use strict;
30 use Carp;
31 use POSIX qw/getcwd strftime/;
32 use HTTP::Date;
33 use CGI qw/:html *table *Tr *td *center *div *Link/;
34 use Image::Info qw/image_info dim/;
35 use Term::ReadLine;
36 use Getopt::Long;
37 use Encode;
38 use encoding 'utf-8';
39 binmode(STDOUT, ":utf8");
40
41 my $haveimagick = eval { require Image::Magick; };
42 { package Image::Magick; }      # to make perl compiler happy
43
44 my $haverssxml = eval { require XML::RSS; };
45 { package XML::RSS; }           # to make perl compiler happy
46
47 my @sizes = (160, 640, 1600);
48 my $incdir = ".gallery2";
49
50 ######################################################################
51
52 my $incpath;
53 my $rssobj;
54 my $debug = 0;
55 my $asktitle = 0;
56 my $noasktitle = 0;
57 my $rssfile = "";
58
59 charset("utf-8");
60
61 unless (GetOptions(
62                 'help'=>\&help,
63                 'incpath'=>\$incpath,
64                 'asktitle'=>\$asktitle,
65                 'noasktitle'=>\$noasktitle,
66                 'rssfile=s'=>\$rssfile,
67                 'debug'=>\$debug)) {
68         &help;
69 }
70
71 if ($rssfile && ! $haverssxml) {
72         print STDERR "You need to get XML::RSS from CPAN to use --rssfile\n";
73         exit 1;
74 }
75
76 my $term = new Term::ReadLine "Edit Title";
77
78 FsObj->new(getcwd)->iterate;
79 if ($rssobj) { $rssobj->{'rss'}->save($rssobj->{'file'}); }
80
81 sub help {
82
83         print STDERR <<__END__;
84 usage: $0 [options]
85  --help:        print help message and exit
86  --incpath:     do not try to find .gallery2 diretory upstream, use
87                 specified path (absolute or relavive).  Use with causion.
88  --debug:       print a lot of debugging info to stdout as you run
89  --asktitle:    ask to edit album titles even if there are ".title" files
90  --noasktitle:  don't ask to enter album titles even where ".title"
91                 files are absent.  Use partial directory names as titles.
92  --rssfile=...: build RSS feed for newly added "albums", give name of rss file
93 __END__
94
95         exit 1;
96 }
97
98 sub new {
99         my $this = shift;
100         my $class;
101         my $self;
102         if (ref($this)) {
103                 $class = ref($this);
104                 my $parent = $this;
105                 my $name = shift;
106                 $self = {
107                                 -parent=>$parent,
108                                 -root=>$parent->{-root},
109                                 -toppath=>$parent->{-toppath},
110                                 -depth=>$parent->{-depth}+1,
111                                 -base=>$name,
112                                 -fullpath=>$parent->{-fullpath}.'/'.$name,
113                                 -relpath=>$parent->{-relpath}.$name.'/',
114                                 -inc=>'../'.$parent->{-inc},
115                         };
116         } else {
117                 $class = $this;
118                 my $root=shift;
119                 $self = {
120                                 -depth=>0,
121                                 -root=>$root,
122                                 -fullpath=>$root,
123                         };
124                 # fill in -inc, -rss, -relpath
125                 initpaths($self); # we are not blessed yet, so cheat.
126         }
127         bless $self, $class;
128         if ($debug) {
129                 print "new $class:\n";
130                 foreach my $k(keys %$self) {
131                         print "\t$k\t=\t$self->{$k}\n";
132                 }
133         }
134         return $self;
135 }
136
137 sub initpaths {
138         my $self=shift;         # this is not a method but we cheat
139         my $depth=20;           # arbitrary max depth
140         my $fullpath=$self->{-fullpath};
141         my $inc;
142         my $relpath;
143
144         if ($incpath) {
145                 $inc = $incpath;
146                 $inc .= '/' unless ($inc =~ m%/$%);
147         } else {
148                 $inc="";
149                 while ( ! -d $fullpath."/".$inc."/".$incdir ) {
150                         $inc = "../".$inc;
151                         last unless ($depth-- > 0);
152                 }
153         }
154         if ($depth > 0) {
155                 $self->{-inc} = $inc;
156                 my $dp=0;
157                 my $pos;
158                 for ($pos=index($inc,'/');$pos>=0;
159                                         $pos=index($inc,'/',$pos+1)) {
160                         $dp++;
161                 }
162                 for ($pos=length($fullpath);$dp>0 && $pos>0;
163                                         $pos=rindex($fullpath,'/',$pos-1)) {
164                         $dp--;
165                 }
166                 my $relpath = substr($fullpath,$pos);
167                 $relpath =~ s%^/%%;
168                 $relpath .= '/' if ($relpath);
169                 $self->{-relpath} = $relpath;
170                 $self->{-toppath} = substr($fullpath,0,$pos);
171                 #print "rel=$relpath, top=$self->{-toppath}, inc=$inc\n";
172                 initrss($self);
173         } else {
174                 $self->{-inc} = 'NO-.INCLUDE-IN-PATH/'; # won't work anyway
175                 $self->{-rss} = '';
176                 $self->{-relpath} = '';
177         }
178 }
179
180 sub initrss {
181         my $self=shift;         # this is not a method but we cheat
182         my $fullpath=$self->{-fullpath};
183         my $toppath=$self->{-toppath};
184         my $inc=$self->{-inc}.$incdir.'/';
185         my $conffile=$toppath.'/'.$incdir.'/rss.conf';
186         my $CONF;
187
188         if ($rssfile) {
189                 if (open($CONF,">".$conffile)) {
190                         print $CONF "file: ",$rssfile,"\n";
191                         close($CONF);
192                 } else {
193                         print STDERR "could not open $conffile: $!\n";
194                 }
195         } else {
196                 if (open($CONF,$conffile)) {
197                         my $ln=<$CONF>;
198                         close($CONF);
199                         chop $ln;
200                         my ($k,$v)=split(':', $ln);
201                         $k =~ s/^\s*//;
202                         $k =~ s/\s*$//;
203                         $v =~ s/^\s*//;
204                         $v =~ s/\s*$//;
205                         if ($k eq 'file') {
206                                 $rssfile=$v;
207                         }
208                 }
209         }
210
211         return unless ($rssfile);
212
213         $rssobj->{'file'} = $self->{-toppath}.'/'.$rssfile;
214         $rssobj->{'rss'} = new XML::RSS (version=>'2.0');
215         if ( -f $rssobj->{'file'} ) {
216                 $rssobj->{'rss'}->parsefile($rssobj->{'file'});
217                 my $itemstodel = @{$rssobj->{'rss'}->{'items'}} - 15;
218                 while ($itemstodel-- > 0) {
219                         pop(@{$rssobj->{'rss'}->{'items'}})
220                 }
221                 $rssobj->{'rss'}->save($rssobj->{'file'});
222         } else {
223                 my $link;
224                 my $p1;
225                 my $p2;
226                 for ($p1=0,$p2=length($toppath);
227                                 substr($rssfile,$p1,3) eq '../' && $p2>0;
228                                 $p1+=3,$p2=rindex($toppath,'/',$p2-1)) {;}
229                 $link=substr($toppath,$p2);
230                 $link =~ s%^/%%;
231                 $link .= '/' if ($link);
232                 while (($p1=index($rssfile,'/',$p1+1)) >= 0) {
233                         $link = '../'.$link;
234                 }
235                 
236                 $rssobj->{'rss'}->channel(
237                         title=>'Gallery',
238                         link=>$link,
239                         description=>'Gallery Feed',
240                         #language=>$language,
241                         #rating=>$rating,
242                         #copyright=>$copyright,
243                         #pubDate=>$pubDate,
244                         #lastBuildDate=>$lastBuild,
245                         #docs=>$docs,
246                         #managingEditor=>$editor,
247                         #webMaster=>$webMaster
248                 );
249                 $rssobj->{'rss'}->save($rssobj->{'file'});
250         }
251         $self->{-rss} = $rssobj->{'rss'};
252 }
253
254 sub iterate {
255         my $self = shift;
256         my $fullpath .= $self->{-fullpath};
257         print "iterate in dir $fullpath\n" if ($debug);
258
259         my $youngest=0;
260         my @rdirlist;
261         my @rimglist;
262         my $D;
263         unless (opendir($D,$fullpath)) {
264                 warn "cannot opendir $fullpath: $!";
265                 return;
266         }
267         while (my $de = readdir($D)) {
268                 next if ($de =~ /^\./);
269                 my $child = $self->new($de);
270                 my @stat = stat($child->{-fullpath});
271                 $youngest = $stat[9] if ($youngest < $stat[9]);
272                 if ($child->isdir) {
273                         push(@rdirlist,$child);
274                 } elsif ($child->isimg) {
275                         push(@rimglist,$child);
276                 }
277         }
278         closedir($D);
279         my @dirlist = sort {$a->{-base} cmp $b->{-base}} @rdirlist;
280         undef @rdirlist; # inplace sorting would be handy here
281         my @imglist = sort {$a->{-base} cmp $b->{-base}} @rimglist;
282         undef @rimglist; # optimize away unsorted versions
283         $self->{-firstimg} = $imglist[0];
284
285         print "Dir: $self->{-fullpath}\n" if ($debug);
286
287 # 1. first of all, fill title for this directory and create hidden subdirs
288
289         $self->initdir;
290
291 # 2. recurse into subdirectories to get their titles filled
292 #    before we start writing out subalbum list
293
294         foreach my $dir(@dirlist) {
295                 $dir->iterate;
296         }
297
298 # 3. iterate through images to build cross-links,
299
300         my $previmg = undef;
301         foreach my $img(@imglist) {
302                 # list-linking must be done before generating
303                 # aux html because aux pages rely on prev/next refs
304                 if ($previmg) {
305                         $previmg->{-nextimg} = $img;
306                         $img->{-previmg} = $previmg;
307                 }
308                 $previmg=$img;
309         }
310
311 # 4. create scaled versions and aux html pages
312
313         foreach my $img(@imglist) {
314                 # scaled versions must be generated before aux html
315                 # and main image index because they both rely on
316                 # refs to scaled images and they may be just original
317                 # images, this is not known before we try scaling.
318                 $img->makescaled;
319                 # finally, make aux html pages
320                 $img->makeaux;
321         }
322
323 # no need to go beyond this point if the directory timestamp did not
324 # change since we built index.html file last time.
325
326         my @istat = stat($self->{-fullpath}.'/index.html');
327         return unless ($youngest > $istat[9]);
328
329 # 5. start building index.html for the directory
330
331         $self->startindex;
332
333 # 6. iterate through subdirectories to build subalbums list
334
335         if (@dirlist) {
336                 $self->startsublist;
337                 foreach my $dir(@dirlist) {
338                         $dir->sub_entry;
339                 }
340                 $self->endsublist;
341         }
342
343 # 7. iterate through images to build thumb list
344
345         if (@imglist) {
346                 $self->startimglist;
347                 foreach my $img(@imglist) {
348                         print "Img: $img->{-fullpath}\n" if ($debug);
349                         $img->img_entry;
350                 }
351                 $self->endimglist;
352         }
353
354 # 8. comlplete building index.html for the directory
355
356         $self->endindex;
357 }
358
359 sub isdir {
360         my $self = shift;
361         return ( -d $self->{-fullpath} );
362 }
363
364 sub isimg {
365         my $self = shift;
366         my $fullpath = $self->{-fullpath};
367         return 0 unless ( -f $fullpath );
368         my $info = image_info($fullpath);
369         if (my $error = $info->{error}) {
370                 if (($error !~ "Unrecognized file format") &&
371                     ($error !~ "Can't read head")) {
372                         warn "File \"$fullpath\": $error\n";
373                 }
374                 return 0;
375         }
376
377         tryapp12($info) unless ($info->{'ExifVersion'});
378
379         $self->{-isimg} = 1;
380         $self->{-info} = $info;
381         return 1;
382 }
383
384 sub tryapp12 {
385         my $info = shift;       # this is not a method
386         my $app12;
387         # dirty hack to take care of Image::Info parser strangeness
388         foreach my $k(keys %$info) {
389                 $app12=substr($k,6).$info->{$k} if ($k =~ /^App12-/);
390         }
391         return unless ($app12); # bad luck
392         my $seenfirstline=0;
393         foreach my $ln(split /[\r\n]+/,$app12) {
394                 $ln =~ s/[[:^print:]\000]/ /g;
395                 unless ($seenfirstline) {
396                         $seenfirstline=1;
397                         $info->{'Make'}=$ln;
398                         next;
399                 }
400                 my ($k,$v)=split /=/,$ln,2;
401                 if ($k eq 'TimeDate') {
402                         $info->{'DateTime'} =
403                                 strftime("%Y:%m:%d %H:%M:%S", localtime($v))
404                                                         unless ($v < 0);
405                 } elsif ($k eq 'Shutter') {
406                         $info->{'ExposureTime'} = '1/'.int(1000000/$v+.5);
407                 } elsif ($k eq 'Flash') {
408                         $info->{'Flash'} = $v?'Flash fired':'Flash did not fire';
409                 } elsif ($k eq 'Type') {
410                         $info->{'Model'} = $v;
411                 } elsif ($k eq 'Version') {
412                         $info->{'Software'} = $v;
413                 } elsif ($k eq 'Fnumber') {
414                         $info->{'FNumber'} = $v;
415                 }
416         }
417 }
418
419 sub initdir {
420         my $self = shift;
421         my $fullpath = $self->{-fullpath};
422         for my $subdir(@sizes, 'html') {
423                 my $tdir=sprintf "%s/.%s",$self->{-fullpath},$subdir;
424                 mkdir($tdir,0755) unless ( -d $tdir );
425         }
426         $self->edittitle;
427 }
428
429 sub edittitle {
430         my $self = shift;
431         my $fullpath = $self->{-fullpath};
432         my $title;
433         my $T;
434         if (open($T,'<'.$fullpath.'/.title')) {
435                 $title = <$T>;
436                 $title =~ s/[\r\n]*$//;
437                 close($T);
438         }
439         if ($asktitle || (!$title && !$noasktitle)) {
440                 my $prompt = $self->{-relpath};
441                 $prompt = '/' unless ($prompt);
442                 my $OUT = $term->OUT || \*STDOUT;
443                 print $OUT "Enter title for $fullpath\n";
444                 $title = $term->readline($prompt.' >',$title);
445                 $term->addhistory($title) if ($title);
446                 if (open($T,'>'.$fullpath.'/.title')) {
447                         print $T $title,"\n";
448                         close($T);
449                 }
450         }
451         unless ($title) {
452                 $title=$self->{-relpath};
453         }
454         $self->{-title}=$title;
455         print "title in $fullpath is $title\n" if ($debug);
456 }
457
458 sub makescaled {
459         my $self = shift;
460         my $fn = $self->{-fullpath};
461         my $name = $self->{-base};
462         my $dn = $self->{-parent}->{-fullpath};
463         my ($w, $h) = dim($self->{-info});
464         my $max = ($w > $h)?$w:$h;
465
466         foreach my $size(@sizes) {
467                 my $nref = '.'.$size.'/'.$name;
468                 my $nfn = $dn.'/'.$nref;
469                 my $factor=$size/$max;
470                 if ($factor >= 1) {
471                         $self->{$size}->{'url'} = $name; # unscaled version
472                         $self->{$size}->{'dim'} = [$w, $h];
473                 } else {
474                         $self->{$size}->{'url'} = $nref;
475                         $self->{$size}->{'dim'} = [int($w*$factor+.5),
476                                                         int($h*$factor+.5)];
477                         if (isnewer($fn,$nfn)) {
478                                 doscaling($fn,$nfn,$factor,$w,$h);
479                         }
480                 }
481         }
482 }
483
484 sub isnewer {
485         my ($fn1,$fn2) = @_;                    # this is not a method
486         my @stat1=stat($fn1);
487         my @stat2=stat($fn2);
488         return (!@stat2 || ($stat1[9] > $stat2[9]));
489         # true if $fn2 is absent or is older than $fn1
490 }
491
492 sub doscaling {
493         my ($src,$dest,$factor,$w,$h) = @_;     # this is not a method
494
495         my $err=1;
496         if ($haveimagick) {
497                 my $im = new Image::Magick;
498                 print "doscaling $src -> $dest by $factor\n" if ($debug);
499                 if ($err = $im->Read($src)) {
500                         warn "ImageMagick: read \"$src\": $err";
501                 } else {
502                         $im->Scale(width=>$w*$factor,height=>$h*$factor);
503                         $err=$im->Write($dest);
504                         warn "ImageMagick: write \"$dest\": $err" if ($err);
505                 }
506                 undef $im;
507         }
508         if ($err) {     # fallback to command-line tools
509                 system("djpeg \"$src\" | pnmscale \"$factor\" | cjpeg >\"$dest\"");
510         }
511 }
512
513 sub makeaux {
514         my $self = shift;
515         my $name = $self->{-base};
516         my $dn = $self->{-parent}->{-fullpath};
517         my $pref = $self->{-previmg}->{-base};
518         my $nref = $self->{-nextimg}->{-base};
519         my $inc = $self->{-inc}.$incdir.'/';
520         my $title = $self->{-info}->{'Comment'};
521         $title = $name unless ($title);
522
523         print "slide: \"$title\": \"$pref\"->\"$name\"->\"$nref\"\n" if ($debug);
524
525         # slideshow
526         for my $refresh('static', 'slide') {
527                 my $fn = sprintf("%s/.html/%s-%s.html",$dn,$name,$refresh);
528                 if (isnewer($self->{-fullpath},$fn)) {
529                         my $imgsrc = '../'.$self->{$sizes[1]}->{'url'};
530                         my $fwdref;
531                         my $bakref;
532                         if ($nref) {
533                                 $fwdref = sprintf("%s-%s.html",$nref,$refresh);
534                         } else {
535                                 $fwdref = '../index.html';
536                         }
537                         if ($pref) {
538                                 $bakref = sprintf("%s-%s.html",$pref,$refresh);
539                         } else {
540                                 $bakref = '../index.html';
541                         }
542                         my $toggleref;
543                         my $toggletext;
544                         if ($refresh eq 'slide') {
545                                 $toggleref=sprintf("%s-static.html",$name);
546                                 $toggletext = 'Stop!';
547                         } else {
548                                 $toggleref=sprintf("%s-slide.html",$name);
549                                 $toggletext = 'Play-&gt;';
550                         }
551                         my $F;
552                         unless (open($F,'>'.$fn)) {
553                                 warn "cannot open \"$fn\": $!";
554                                 next;
555                         }
556                         binmode($F, ":utf8");
557                         if ($refresh eq 'slide') {
558                                 print $F start_html(
559                                         -encoding=>"utf-8",
560                                         -title=>$title,
561                                         -bgcolor=>"#808080",
562                                         -head=>meta({-http_equiv=>'Refresh',
563                                                 -content=>"3; url=$fwdref"}),
564                                         -style=>{-src=>$inc."gallery.css"},
565                                         ),"\n",
566                                         comment("Created by ".$version),"\n";
567                                                 
568                         } else {
569                                 print $F start_html(-title=>$title,
570                                         -encoding=>"utf-8",
571                                         -bgcolor=>"#808080",
572                                         -style=>{-src=>$inc."gallery.css"},
573                                         ),"\n",
574                                         comment("Created by ".$version),"\n";
575                         }
576                         print $F start_table({-class=>'navi'}),start_Tr,"\n",
577                                 td(a({-href=>"../index.html"},"Index")),"\n",
578                                 td(a({-href=>$bakref},"&lt;&lt;Prev")),"\n",
579                                 td(a({-href=>$toggleref},$toggletext)),"\n",
580                                 td(a({-href=>$fwdref},"Next&gt;&gt;")),"\n",
581                                 td({-class=>'title'},$title),"\n",
582                                 end_Tr,
583                                 end_table,"\n",
584                                 center(table({-class=>'picframe'},
585                                         Tr(td(img({-src=>$imgsrc,
586                                                    -class=>'standalone',
587                                                    -alt=>$title}))))),"\n",
588                                 end_html,"\n";
589                         close($F);
590                 }
591         }
592
593         # info html
594         my $fn = sprintf("%s/.html/%s-info.html",$dn,$name);
595         if (isnewer($self->{-fullpath},$fn)) {
596                 my $F;
597                 unless (open($F,'>'.$fn)) {
598                         warn "cannot open \"$fn\": $!";
599                         return;
600                 }
601                 my $imgsrc = sprintf("../.%s/%s",$sizes[0],$name);
602                 print $F start_html(-title=>$title,
603                                 -encoding=>"utf-8",
604                                 -style=>{-src=>$inc."gallery.css"},
605                                 -script=>[
606                                         {-src=>$inc."mootools.js"},
607                                         {-src=>$inc."urlparser.js"},
608                                         {-src=>$inc."infopage.js"},
609                                 ]),"\n",
610                         comment("Created by ".$version),"\n",
611                         start_center,"\n",
612                         h1($title),"\n",
613                         table({-class=>'ipage'},
614                                 Tr(td(img({-src=>$imgsrc,
615                                            -class=>'thumbnail',
616                                            -alt=>$title})),
617                                         td($self->infotable))),
618                         a({-href=>'../index.html',-class=>'conceal'},
619                                 'Index'),"\n",
620                         end_center,"\n",
621                         end_html,"\n";
622                 close($F);
623         }
624 }
625
626 sub startindex {
627         my $self = shift;
628         my $fn = $self->{-fullpath}.'/index.html';
629         my $block = $self->{-fullpath}.'/.noindex';
630         $fn = '/dev/null' if ( -f $block );
631         my $IND;
632         unless (open($IND,'>'.$fn)) {
633                 warn "cannot open $fn: $!";
634                 return;
635         }
636         binmode($IND, ":utf8");
637         $self->{-IND} = $IND;
638
639         my $inc = $self->{-inc}.$incdir.'/';
640         my $title = $self->{-title};
641         my $rsslink="";
642         if ($rssobj) {
643                 $rsslink=Link({-rel=>'alternate',
644                                 -type=>'application/rss+xml',
645                                 -title=>'RSS',
646                                 -href=>$self->{-inc}.$rssfile});
647         }
648         print $IND start_html(-title => $title,
649                         -encoding=>"utf-8",
650                         -head=>$rsslink,
651                         -style=>[
652                                 {-src=>$inc."gallery.css"},
653                                 {-src=>$inc."custom.css"},
654                         ],
655                         -script=>[
656                                 {-src=>$inc."mootools.js"},
657                                 {-src=>$inc."overlay.js"},
658                                 {-src=>$inc."urlparser.js"},
659                                 {-src=>$inc."multibox.js"},
660                                 {-src=>$inc."showwin.js"},
661                                 {-src=>$inc."controls.js"},
662                                 {-src=>$inc."show.js"},
663                                 {-src=>$inc."gallery.js"},
664                         ]),"\n",
665                 comment("Created by ".$version),"\n",
666                 start_div({-class => 'indexContainer',
667                                 -id => 'indexContainer'}),
668                 "\n";
669         my $EVL;
670         if (open($EVL,$self->{-toppath}.'/'.$incdir.'/header.pl')) {
671                 my $prm;
672                 while (<$EVL>) {
673                         $prm .= $_;
674                 }
675                 close($EVL);
676                 %_ = (
677                         -version        => $version,
678                         -depth          => $self->{-depth},
679                         -title          => $title,
680                         -breadcrumbs    => "breadcrumbs unimplemented",
681                 );
682                 print $IND eval $prm,"\n";
683         } else {
684                 print STDERR "could not open ",
685                         $self->{-toppath}.'/'.$incdir.'/header.pl',
686                         " ($!), reverting to default header";
687                 print $IND a({-href=>"../index.html"},"UP"),"\n",
688                         h1({-class=>'title'},$title),"\n",
689         }
690 }
691
692 sub endindex {
693         my $self = shift;
694         my $IND = $self->{-IND};
695
696         print $IND end_div;
697         my $EVL;
698         if (open($EVL,$self->{-toppath}.'/'.$incdir.'/footer.pl')) {
699                 my $prm;
700                 while (<$EVL>) {
701                         $prm .= $_;
702                 }
703                 close($EVL);
704                 %_ = (
705                         -version        => $version,
706                         -depth          => $self->{-depth},
707                         -title          => $self->{-title},
708                         -breadcrumbs    => "breadcrumbs unimplemented",
709                 );
710                 print $IND eval $prm,"\n";
711         } else {
712                 print STDERR "could not open ",
713                         $self->{-toppath}.'/'.$incdir.'/footer.pl',
714                         " ($!), reverting to default empty footer";
715         }
716         print $IND end_html,"\n";
717
718         close($IND) if ($IND);
719         undef $self->{-IND};
720         if ($rssobj) {
721                 my $rsstitle=sprintf "%s [%d images, %d subalbums]",
722                                 $self->{-title},
723                                 $self->{-numofimgs},
724                                 $self->{-numofsubs};
725                 my $rsslink=$rssobj->{'rss'}->channel('link').
726                         $self->{-relpath}."index.html";
727                 $rssobj->{'rss'}->add_item(
728                         title           => $self->{-title},
729                         link            => $rsslink,
730                         description     => $rsstitle,
731                         pubDate         => time2str(time),
732                 );
733         }
734 }
735
736 sub startsublist {
737         my $self = shift;
738         my $IND = $self->{-IND};
739
740         print $IND h2({-class=>"atitle"},"Albums"),"\n",start_table,"\n";
741 }
742
743 sub sub_entry {
744         my $self = shift;
745         my $IND = $self->{-parent}->{-IND};
746         my $name = $self->{-base};
747         my $title = $self->{-title};
748
749         $self->{-parent}->{-numofsubs}++;
750         print $IND Tr(td(a({-href=>$name.'/index.html'},$name)),
751                         td(a({-href=>$name.'/index.html'},$title))),"\n";
752 }
753
754 sub endsublist {
755         my $self = shift;
756         my $IND = $self->{-IND};
757
758         print $IND end_table,"\n",br({-clear=>'all'}),hr,"\n\n";
759 }
760
761 sub startimglist {
762         my $self = shift;
763         my $IND = $self->{-IND};
764         my $first = $self->{-firstimg}->{-base};
765         my $slideref = sprintf(".html/%s-slide.html",$first);
766
767         print $IND h2({-class=>"ititle"},"Images ",
768                 a({-href=>$slideref,-class=>'showStart',-rel=>'i'.$first},
769                         '&gt; slideshow')),"\n";
770 }
771
772 sub img_entry {
773         my $self = shift;
774         my $IND = $self->{-parent}->{-IND};
775         my $name = $self->{-base};
776         my $title = $self->{-info}->{'Comment'};
777         $title = $name unless ($title);
778         my $thumb = $self->{$sizes[0]}->{'url'};
779         my $info = $self->{-info};
780         my ($w, $h) = dim($info);
781
782         my $i=0+$self->{-parent}->{-numofimgs};
783         $self->{-parent}->{-numofimgs}++;
784
785         print $IND a({-name=>$name}),"\n",
786                 start_table({-class=>'slide'}),start_Tr,start_td,"\n",
787                 div({-class=>'slidetitle'},
788                         "\n ",a({-href=>".html/$name-info.html",
789                                 -title=>'Image Info: '.$name,
790                                 -class=>'infoBox'},
791                                 $title),"\n"),"\n",
792                 div({-class=>'slideimage'},
793                         "\n ",a({-href=>".html/$name-static.html",
794                                 -title=>$title,
795                                 -class=>'showImage',
796                                 -rel=>'i'.$name},
797                                 img({-src=>$thumb,
798                                      -class=>'thumbnail',
799                                      -alt=>$title})),"\n"),"\n",
800                 start_div({-class=>'varimages',-id=>'i'.$name,-title=>$title}),"\n";
801         foreach my $sz(@sizes) {
802                 my $src=$self->{$sz}->{'url'};
803                 my $w=$self->{$sz}->{'dim'}->[0];
804                 my $h=$self->{$sz}->{'dim'}->[1];
805                 print $IND "  ",a({-href=>$src,
806                         -class=>"conceal",
807                         -rel=>$w."x".$h,
808                         -title=>"Reduced to ".$w."x".$h},
809                         $w."x".$h)," \n";
810         }
811         print $IND "  ",a({-href=>$name,
812                                 -rel=>$w."x".$h,
813                                 -title=>'Original'},$w."x".$h),
814                 "\n",end_div,"\n",
815                 end_td,end_Tr,end_table,"\n";
816 }
817
818 sub endimglist {
819         my $self = shift;
820         my $IND = $self->{-IND};
821
822         print $IND br({-clear=>'all'}),hr,"\n\n";
823 }
824
825 sub infotable {
826         my $self = shift;
827         my $info = $self->{-info};
828         my $msg='';
829
830         my @infokeys=(
831                 'DateTime',
832                 'ExposureTime',
833                 'FNumber',
834                 'Flash',
835                 'ISOSpeedRatings',
836                 'MeteringMode',
837                 'ExposureProgram',
838                 'FocalLength',
839                 'FileSource',
840                 'Make',
841                 'Model',
842                 'Software',
843         );
844         $msg.=start_table({-class=>'infotable'})."\n";
845         foreach my $k(@infokeys) {
846                 $msg.=Tr(td($k.":"),td($info->{$k}))."\n" if ($info->{$k});
847         }
848         $msg.=end_table."\n";
849 }
850