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