]> mj.ucw.cz Git - gallery.git/blobdiff - gal2/UCW/Gallery.pm
Gallery2: gen-cache
[gallery.git] / gal2 / UCW / Gallery.pm
index ad0f35dac944980b259c4cbc1666a9e491e3fbc0..847de01987b3b1f226424ed13e483743111ff5cf 100644 (file)
@@ -6,6 +6,8 @@ package UCW::Gallery;
 use strict;
 use warnings;
 
+use Storable;
+
 BEGIN {
        # Standard Perl module stuff
        use Exporter();
@@ -21,24 +23,28 @@ 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{'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{'ScanDefaultTransform'} = 's';
        $CF{'OrigDir'} = '.';
        $CF{'PhotoDir'} = 'photo';
-       $CF{"CacheDir"} = "cache",
+       $CF{'CacheDir'} = 'cache',
+       $CF{'PhotoMaxWidth'} = 1024,
+       $CF{'PhotoMaxHeight'} = 1024,
+       # FIXME: ThumbSizes should be set by themes
+       $CF{'ThumbSizes'} = [ [114,94], [256,256] ],
 }
 
 sub LoadConfig() {
@@ -99,4 +105,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;