X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=gal2%2FUCW%2FGallery.pm;h=8b4c3fac2c3686222852e1dfb2b9c2f8357944df;hb=9616a1f03e8290d15f0d15def6c8fb6d4e9420bf;hp=847de01987b3b1f226424ed13e483743111ff5cf;hpb=b89f977dc5a5d785766118992aa90a7eff7b5d3b;p=gallery.git diff --git a/gal2/UCW/Gallery.pm b/gal2/UCW/Gallery.pm index 847de01..8b4c3fa 100644 --- a/gal2/UCW/Gallery.pm +++ b/gal2/UCW/Gallery.pm @@ -8,48 +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/', -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 ($!) { @@ -58,23 +52,58 @@ 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{"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}, @@ -115,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;