use Storable;
-BEGIN {
- # Standard Perl module stuff
- use Exporter();
- our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS);
- $VERSION = 1.00;
- @ISA = qw(Exporter);
- @EXPORT = qw(&SetOptions);
- %EXPORT_TAGS = ();
- @EXPORT_OK = qw(%CF);
-}
+### Class methods ###
+
+sub new($) {
+ my ($class) = @_;
+ my $self = { };
+ $self->{cfg} = {
+ # Directories
+ OrigDir => '.', # Original images
+ PhotoDir => 'photo', # Scaled-down photos for web
+ CacheDir => 'cache', # Cache with meta-data and thumbnails
+
+ # URL prefixes
+ PhotoUrlPrefix => 'photo/',
+ ThumbUrlPrefix => 'thumb/',
+ ThemeUrlPrefix => 'gal/',
-our %CF;
-our $th;
-
-BEGIN {
- $CF{'Title'} = 'An Unnamed Gallery',
- $CF{'HeadExtras'} = "",
- $CF{'TopExtras'} = "",
- $CF{'BotExtras'} = "",
- $CF{'ParentURL'} = '../',
- $CF{'BackURL'} = "",
- $CF{'FwdURL'} = "",
- $CF{'ImageSubpages'} = 1,
- $CF{'AllowArchives'} = 1,
- $CF{'PhotoUrlPrefix'} = "",
- $CF{'ThumbUrlPrefix'} = "",
- $CF{'MetaDataDir'} = '.',
- $CF{'PhotoDir'} = '.',
-
- $CF{'ScanDefaultTransform'} = 's';
- $CF{'OrigDir'} = '.';
- $CF{'PhotoDir'} = 'photo';
- $CF{'CacheDir'} = 'cache',
- $CF{'PhotoMaxWidth'} = 1024,
- $CF{'PhotoMaxHeight'} = 1024,
- # FIXME: ThumbSizes should be set by themes
- $CF{'ThumbSizes'} = [ [114,94], [256,256] ],
+ # Processing machinery settings
+ ScanDefaultTransform => 's',
+ PhotoMaxWidth => 1024,
+ PhotoMaxHeight => 1024,
+ ThumbFormats => {}, # Set up by themes
+
+ # Titles and navigation
+ Title => 'An Unnamed Gallery',
+ SubTitle => "",
+ ParentURL => '../',
+ BackURL => "",
+ FwdURL => "",
+ };
+ return bless $self, $class;
}
-sub LoadConfig() {
+sub load_config($) {
my $cfg = "./gallery.cf";
- unless (defined do $cfg) {
+ my $self = do $cfg;
+ unless (defined $self) {
if ($@) {
die "Error parsing $cfg: $@";
} elsif ($!) {
die "Cannot load $cfg, check that it returns true\n";
}
}
+ return $self;
}
-sub SetOptions(@) {
- while (my $o = shift @_) {
- my $v = shift @_;
- $CF{$o} = $v;
- if ($o eq "Theme") {
- require $CF{"GalDir"} . "/$v/theme.pm";
- Gallery::Theme::Init($CF{"GalURL"} . "/$v");
- }
+### Object methods ###
+
+sub get($$) {
+ my ($self, $key) = @_;
+ if (exists $self->{cfg}->{$key}) {
+ my $val = $self->{cfg}->{$key};
+ defined $val or warn "Gallery: Config item $key is not set\n";
+ return $val;
+ } else {
+ warn "Gallery: Config item $key does not exist\n";
+ return;
+ }
+}
+
+sub def($@) {
+ my $self = shift;
+ while (my $key = shift @_) {
+ my $val = shift @_;
+ !exists $self->{cfg}->{$key} or warn "Gallery: Re-definining config item $key\n";
+ $self->{cfg}->{$key} = $val;
}
}
+sub set($@) {
+ my $self = shift;
+ while (my $key = shift @_) {
+ my $val = shift @_;
+ exists $self->{cfg}->{$key} or warn "Gallery: Config item $key does not exist\n";
+ $self->{cfg}->{$key} = $val;
+ }
+}
+
+sub get_config_keys($) {
+ my ($self) = @_;
+ return keys %{$self->{cfg}};
+}
+
+sub require_thumbnails($$$) {
+ my ($self, $w, $h) = @_;
+ my $fmt = "${w}x${h}";
+ $self->{cfg}->{ThumbFormats}->{$fmt} = 1;
+ return $fmt;
+}
+
+### Subroutines (to be converted to methods later) ###
+
sub WriteList($$) {
my ($file, $images) = @_;
open LIST, '>', "$file.new" or die "Cannot create $file.new: $!\n";
- print LIST "# Image\tID\tRotate\tXform\tTitle\n";
for my $i (@$images) {
print LIST join("\t",
$i->{file},
sub ReadMeta($) {
my ($file) = @_;
+ # FIXME: open my META
open META, '<', $file or die "Cannot read $file: $!\n";
my $meta = Storable::fd_retrieve(\*META) or die "Cannot parse $file\n";
close META;