X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=gal2%2FUCW%2FGallery.pm;h=8b4c3fac2c3686222852e1dfb2b9c2f8357944df;hb=9616a1f03e8290d15f0d15def6c8fb6d4e9420bf;hp=c8bdc68a5fd52f45e46ae682889fc552714084cf;hpb=007f7a52da1cfc87f33de07fc873d0fac46558b4;p=gallery.git diff --git a/gal2/UCW/Gallery.pm b/gal2/UCW/Gallery.pm index c8bdc68..8b4c3fa 100644 --- a/gal2/UCW/Gallery.pm +++ b/gal2/UCW/Gallery.pm @@ -8,51 +8,42 @@ use warnings; 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/', + + # 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; } -our %CF; - -BEGIN { %CF = ( - # Directories - OrigDir => '.', # Original images - PhotoDir => 'photo', # Scaled-down photos for web - CacheDir => 'cache', # Cache with meta-data and thumbnails - ThemeDir => 'gal', # Themes - - # URL prefixes - PhotoUrlPrefix => 'photo/', - ThumbUrlPrefix => 'thumb/', - ThemeUrlPrefix => 'gal/', - - # Processing machinery settings - ScanDefaultTransform => 's', - PhotoMaxWidth => 1024, - PhotoMaxHeight => 1024, - ThumbFormats => {}, # Set up by themes - - # HTML output settings - Title => 'An Unnamed Gallery', - HeadExtras => "", - TopExtras => "", - BotExtras => "", - ParentURL => '../', - BackURL => "", - FwdURL => "", - ImageSubpages => 1, -); } - -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 ($!) { @@ -61,25 +52,55 @@ sub LoadConfig() { 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{'ThemeDir'} . "/$v/theme.pm"; - UCW::Gallery::Theme::Init($CF{'ThemeUrlPrefix'} . $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 RequireThumbnails($$) { - my ($w, $h) = @_; +sub get_config_keys($) { + my ($self) = @_; + return keys %{$self->{cfg}}; +} + +sub require_thumbnails($$$) { + my ($self, $w, $h) = @_; my $fmt = "${w}x${h}"; - $CF{'ThumbFormats'}->{$fmt} = 1; + $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"; @@ -123,6 +144,7 @@ sub WriteMeta($$) { 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;