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 ### Subroutines (to be converted to methods later) ###
105 my ($file, $images) = @_;
106 open LIST, '>', "$file.new" or die "Cannot create $file.new: $!\n";
107 for my $i (@$images) {
108 print LIST join("\t",
113 ($i->{title} eq '' ? '-' : $i->{title}),
117 rename "$file.new", $file or die "Cannot rename $file.new to $file: $!\n";
123 open LIST, '<', $file or return;
129 ($i->{file}, $i->{id}, $i->{orientation}, $i->{xfrm}, $i->{title}) = split /\t/;
130 if ($i->{title} eq '-') { $i->{title} = ""; }
138 my ($file, $meta) = @_;
139 open META, '>', "$file.new" or die "Cannot create $file.new: $!\n";
140 Storable::nstore_fd($meta, \*META);
142 rename "$file.new", $file or die "Cannot rename $file.new to $file: $!\n";
147 # FIXME: open my META
148 open META, '<', $file or die "Cannot read $file: $!\n";
149 my $meta = Storable::fd_retrieve(\*META) or die "Cannot parse $file\n";