# Simple Photo Gallery: Web Archiver
# (c) 2005 Martin Mares <mj@ucw.cz>

package Gallery::Archive;
import Gallery qw(%CF);

use IO::Handle;

sub new($$) {
	my ($cls, $type) = @_;
	my $x = { 'type' => $type, 'files' => [] };
	return bless $x;
}

sub Start($) {
	my ($this) = @_;
	my $type = $this->{'type'};
	my $cts = { "tar" => "application/x-tar", "zip" => "application/zip" };
	defined $cts->{$type} or die "Unknown archive type $type";
	print "Content-Type: ", $cts->{$type}, "\n";
	print "Content-Disposition: inline;filename=gallery.$type\n";
	print "\n";
}

sub Finish($) {
	my ($this) = @_;
	my $type = $this->{'type'};
	STDOUT->flush();
	chdir($CF{"PhotoDir"}) or die;
	if ($type eq "tar") {
		system("tar", "cf", "-", @{$this->{'files'}});
	} elsif ($type eq "zip") {
		system("zip", "-q", "-", @{$this->{'files'}});
	} else { die; }
}

sub RawHTML($$) {
}

sub img($$$) {
	my ($this, $orig, $annot) = @_;
	push @{$this->{'files'}}, $orig;
}

1;
