+# 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;