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