$(eval $(dir-setup))
-$(call lib-copy, UCW/Gallery.pm UCW/Gallery/Web.pm UCW/Gallery/Web/NrtBlue.pm UCW/Gallery/Web/Plain.pm UCW/Gallery/Web/HighSlide.pm)
+$(call lib-copy, UCW/Gallery.pm)
+$(call lib-copy, $(addprefix UCW/Gallery/, Web.pm Archive.pm))
+$(call lib-copy, $(addprefix UCW/Gallery/Web/, Plain.pm NrtBlue.pm HighSlide.pm))
$(call copy, $(addprefix nrt-blue/,back.png bot.png left.png next.png prev.png right.png top.png style.css))
$(call copy, $(addprefix plain/,back.png next.png prev.png style.css))
--- /dev/null
+# Simple Photo Gallery: Archiving
+# (c) 2003--2012 Martin Mares <mj@ucw.cz>
+
+package UCW::Gallery::Archive;
+
+use strict;
+use warnings;
+
+use Archive::Zip;
+use File::Spec;
+use UCW::CGI;
+
+sub send_archive($$) {
+ my ($gal, $meta) = @_;
+
+ if (!$gal->get('WebAllowArchives')) {
+ UCW::CGI::http_error('403 Archiving forbidden by server configuration');
+ return;
+ }
+
+ my $zip = Archive::Zip->new;
+ my $cnt = 0;
+ for my $id (@{$meta->{sequence}}) {
+ $zip->addFile(File::Spec->catfile($gal->get('PhotoDir'), "$id.jpg"), sprintf("%03d.jpg", $cnt)) or die;
+ $cnt++;
+ }
+
+ print "Content-type: application/zip\n\n";
+ $zip->writeToFileHandle(\*STDOUT, 0);
+}
+
+42;
use File::Spec;
my $show_img;
+my $want_archive;
my %args = (
'i' => { 'var' => \$show_img, 'check' => '\d+' },
+ 'a' => { 'var' => \$want_archive },
);
sub error($) {
return $self->{gal}->get($key);
}
+sub extras($$) {
+ my ($self, $key) = @_;
+ my $val = $self->get($key);
+ if (ref $val eq 'CODE') {
+ return &$val($self->{gal});
+ } else {
+ return $val;
+ }
+}
+
sub html_top($) {
my ($self) = @_;
my $title = UCW::CGI::html_escape($self->get('Title'));
- my $hextras = $self->get('WebHeadExtras');
- my $textras = $self->get('WebTopExtras');
+ my $hextras = $self->extras('WebHeadExtras');
+ my $textras = $self->extras('WebTopExtras');
my $theme_hextras = $self->theme_head_extras;
print <<EOF ;
Content-Type: text/html
sub html_bot($) {
my ($self) = @_;
- print $self->get('WebBotExtras'), "</body></html>\n";
+ print $self->extras('WebBotExtras'), "</body></html>\n";
}
sub show_img($) {
$self->{meta} = $self->{gal}->read_meta(File::Spec->catfile($self->get('CacheDir'), 'cache.meta'));
$self->{num_photos} = scalar @{$self->{meta}->{sequence}};
- if ($show_img ne "") {
+ if ($want_archive) {
+ require UCW::Gallery::Archive;
+ UCW::Gallery::Archive::send_archive($self->{gal}, $self->{meta});
+ } elsif ($show_img ne "") {
$self->show_img;
} else {
$self->show_list;
my $self = { gal => $gal };
$gal->def(
WebFE => $self,
+
+ # Extras are either strings or functions called with the current gallery object as parameter
WebHeadExtras => "",
WebTopExtras => "",
WebBotExtras => "",
+
+ # Used by the theming logic
WebThemeCSS => undef,
+
+ # 1 if thumbnail link to sub-pages with images, 0 if they link directly to image files
WebImageSubpages => 1,
+
+ # If enabled, calling the CGI with a=zip produces a ZIP archive with all photos.
+ WebAllowArchives => 1,
);
bless $self, $class;
return $self;