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