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