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