2 # (c) 2003--2012 Martin Mares <mj@ucw.cz>
18 OrigDir => '.', # Original images
19 PhotoDir => 'photo', # Scaled-down photos for web
20 CacheDir => 'cache', # Cache with meta-data and thumbnails
23 PhotoUrlPrefix => 'photo/',
24 ThumbUrlPrefix => 'thumb/',
25 ThemeUrlPrefix => 'gal/',
27 # Processing machinery settings
28 ScanDefaultTransform => 's',
29 PhotoMaxWidth => 1024,
30 PhotoMaxHeight => 1024,
31 ThumbFormats => {}, # Set up by themes
33 # Titles and navigation
34 Title => 'An Unnamed Gallery',
40 return bless $self, $class;
44 my $cfg = "./gallery.cf";
46 unless (defined $self) {
48 die "Error parsing $cfg: $@";
50 die "Cannot load $cfg: $!\n";
52 die "Cannot load $cfg, check that it returns true\n";
58 ### Object methods ###
61 my ($self, $key) = @_;
62 if (exists $self->{cfg}->{$key}) {
63 my $val = $self->{cfg}->{$key};
64 defined $val or warn "Gallery: Config item $key is not set\n";
67 warn "Gallery: Config item $key does not exist\n";
74 while (my $key = shift @_) {
76 !exists $self->{cfg}->{$key} or warn "Gallery: Re-definining config item $key\n";
77 $self->{cfg}->{$key} = $val;
83 while (my $key = shift @_) {
85 exists $self->{cfg}->{$key} or warn "Gallery: Config item $key does not exist\n";
86 $self->{cfg}->{$key} = $val;
90 sub get_config_keys($) {
92 return keys %{$self->{cfg}};
95 sub require_thumbnails($$$) {
96 my ($self, $w, $h) = @_;
97 my $fmt = "${w}x${h}";
98 $self->{cfg}->{ThumbFormats}->{$fmt} = 1;
102 sub write_list($$$) {
103 my ($self, $file, $images) = @_;
104 open my $fh, '>:utf8', "$file.new" or die "Cannot create $file.new: $!\n";
105 for my $i (@$images) {
111 ($i->{title} eq '' ? '-' : $i->{title}),
115 rename "$file.new", $file or die "Cannot rename $file.new to $file: $!\n";
119 my ($self, $file) = @_;
121 open my $fh, '<:utf8', $file or return;
127 ($i->{file}, $i->{id}, $i->{orientation}, $i->{xfrm}, $i->{title}) = split /\t/;
128 if ($i->{title} eq '-') { $i->{title} = ""; }
136 my ($self, $file, $meta) = @_;
137 open my $fh, '>', "$file.new" or die "Cannot create $file.new: $!\n";
138 Storable::nstore_fd($meta, $fh);
140 rename "$file.new", $file or die "Cannot rename $file.new to $file: $!\n";
144 my ($self, $file) = @_;
145 open my $fh, '<', $file or die "Cannot read $file: $!\n";
146 my $meta = Storable::fd_retrieve($fh) or die "Cannot parse $file\n";