]> mj.ucw.cz Git - gallery.git/blobdiff - gal2/UCW/Gallery.pm
Gallery2: More renames
[gallery.git] / gal2 / UCW / Gallery.pm
index f97ddd8bc4332e9bb3fafc1848471291c417a1cd..8b4c3fac2c3686222852e1dfb2b9c2f8357944df 100644 (file)
@@ -8,51 +8,42 @@ use warnings;
 
 use Storable;
 
 
 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";
        my $cfg = "./gallery.cf";
-       unless (defined do $cfg) {
+       my $self = do $cfg;
+       unless (defined $self) {
                if ($@) {
                        die "Error parsing $cfg: $@";
                } elsif ($!) {
                if ($@) {
                        die "Error parsing $cfg: $@";
                } elsif ($!) {
@@ -61,29 +52,58 @@ sub LoadConfig() {
                        die "Cannot load $cfg, check that it returns true\n";
                }
        }
                        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}";
        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";
 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},
        for my $i (@$images) {
                print LIST join("\t",
                        $i->{file},
@@ -124,6 +144,7 @@ sub WriteMeta($$) {
 
 sub ReadMeta($) {
        my ($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;
        open META, '<', $file or die "Cannot read $file: $!\n";
        my $meta = Storable::fd_retrieve(\*META) or die "Cannot parse $file\n";
        close META;