]> mj.ucw.cz Git - gallery.git/blobdiff - gal2/UCW/Gallery.pm
Gallery2: Clean up remnants of archiving
[gallery.git] / gal2 / UCW / Gallery.pm
index b2d41a6ed84851f632e996a1323a43c1ea578f11..f97ddd8bc4332e9bb3fafc1848471291c417a1cd 100644 (file)
@@ -6,6 +6,8 @@ package UCW::Gallery;
 use strict;
 use warnings;
 
+use Storable;
+
 BEGIN {
        # Standard Perl module stuff
        use Exporter();
@@ -18,28 +20,35 @@ BEGIN {
 }
 
 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'} = 'n';
-       $CF{'OrigDir'} = '.';
-       $CF{'PhotoDir'} = 'photo';
-       $CF{'CacheDir'} = "cache",
-}
+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() {
        my $cfg = "./gallery.cf";
@@ -59,12 +68,18 @@ sub SetOptions(@) {
                my $v = shift @_;
                $CF{$o} = $v;
                if ($o eq "Theme") {
-                       require $CF{"GalDir"} . "/$v/theme.pm";
-                       Gallery::Theme::Init($CF{"GalURL"} . "/$v");
+                       require $CF{'ThemeDir'} . "/$v/theme.pm";
+                       UCW::Gallery::Theme::Init($CF{'ThemeUrlPrefix'} . $v);
                }
        }
 }
 
+sub RequireThumbnails($$) {
+       my ($w, $h) = @_;
+       my $fmt = "${w}x${h}";
+       $CF{'ThumbFormats'}->{$fmt} = 1;
+}
+
 sub WriteList($$) {
        my ($file, $images) = @_;
        open LIST, '>', "$file.new" or die "Cannot create $file.new: $!\n";
@@ -99,4 +114,20 @@ sub ReadList($) {
        return \@images;
 }
 
+sub WriteMeta($$) {
+       my ($file, $meta) = @_;
+       open META, '>', "$file.new" or die "Cannot create $file.new: $!\n";
+       Storable::nstore_fd($meta, \*META);
+       close META;
+       rename "$file.new", $file or die "Cannot rename $file.new to $file: $!\n";
+}
+
+sub ReadMeta($) {
+       my ($file) = @_;
+       open META, '<', $file or die "Cannot read $file: $!\n";
+       my $meta = Storable::fd_retrieve(\*META) or die "Cannot parse $file\n";
+       close META;
+       return $meta;
+}
+
 1;