From: Martin Mares Date: Sun, 30 Dec 2012 11:18:35 +0000 (+0100) Subject: Gallery2: Front-end attachment reform X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=c1e83fe05106d620b4b74af0d9e33f6266e25503;p=gallery.git Gallery2: Front-end attachment reform Finally, I understood that the original idea of attaching front-ends directly from gallery.cf is fallacious. It makes things unnecessarily complicated, especially if you want to use multiple front-ends. Now, the only place where we care of the web front-end is gallery.cgi itself. Necessarily, we no longer insist that all configuration variables we set are previously defined. Also, requested thumbnail sizes are now explicitly mentioned in gallery.cf, because we cannot infer them from the front-ends (which did not work properly anyway). --- diff --git a/gal/README b/gal/README index 9c0d350..e37fda0 100644 --- a/gal/README +++ b/gal/README @@ -28,16 +28,13 @@ Files and directories o gallery.cf -- all programs expect that the current directory contains a configuration file. In fact, the config file is a perl script, whose sole purpose is to set up paths, construct a gallery object and set its - options. Also, it usually attaches an appropriate web front-end. + options. A simple example looks as follows: use UCW::Gallery; - use UCW::Gallery::Web::Plain; my $gal = UCW::Gallery->new; - UCW::Gallery::Web::Plain->attach($gal); - $gal->set(Title => 'A Gallery', SubTitle => '(an example)'); return $gal; @@ -58,9 +55,10 @@ Files and directories use lib "../path/to/gallery/modules"; use UCW::Gallery; + use UCW::Gallery::Web::Plain; my $gal = UCW::Gallery->load_config(); - $gal->get('WebFe')->dispatch(); + UCW::Gallery::Web::Plain->run($gal); Workflow ~~~~~~~~ diff --git a/gal/UCW/Gallery.pm b/gal/UCW/Gallery.pm index 3912868..63e51b9 100644 --- a/gal/UCW/Gallery.pm +++ b/gal/UCW/Gallery.pm @@ -28,7 +28,8 @@ sub new($) { ScanDefaultTransform => 's', PhotoMaxWidth => 1024, PhotoMaxHeight => 1024, - ThumbFormats => {}, # Set up by themes + ThumbFormats => [ "114x94" ], # Built-in themes use the first size, + # but more can be generated # Titles and navigation Title => 'An Unnamed Gallery', @@ -73,17 +74,14 @@ 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; + $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; + $self->{cfg}->{$key} = shift @_; } } @@ -92,13 +90,6 @@ sub get_config_keys($) { return keys %{$self->{cfg}}; } -sub require_thumbnails($$$) { - my ($self, $w, $h) = @_; - my $fmt = "${w}x${h}"; - $self->{cfg}->{ThumbFormats}->{$fmt} = 1; - return $fmt; -} - sub write_list($$$) { my ($self, $file, $images) = @_; open my $fh, '>:utf8', "$file.new" or die "Cannot create $file.new: $!\n"; @@ -158,4 +149,10 @@ sub cache_meta_name($) { return File::Spec->catfile($self->get('CacheDir'), 'cache.meta'); } +sub thumb_fmt_to_size($$) { + my ($self, $fmt) = @_; + my ($tw, $th) = ($fmt =~ m{^(\d+)x(\d+)$}) or die "Cannot parse thumbnail format $fmt\n"; + return ($tw, $th); +} + 1; diff --git a/gal/UCW/Gallery/Web/HighSlide.pm b/gal/UCW/Gallery/Web/HighSlide.pm index 86ffcac..b3df6e6 100644 --- a/gal/UCW/Gallery/Web/HighSlide.pm +++ b/gal/UCW/Gallery/Web/HighSlide.pm @@ -12,12 +12,6 @@ use UCW::Gallery::Web; our @ISA = qw(UCW::Gallery::Web); my $theme_name = "plain"; -my $navw = 48; -my $navh = 48; -my $box_w = 130; -my $box_h = 110; -my $thumb_w = 114; -my $thumb_h = 94; sub theme_dir($) { my ($self) = @_; @@ -26,10 +20,8 @@ sub theme_dir($) { sub theme_head_extras($) { my ($self) = @_; - my $tdir = $self->theme_dir; my $hsdir = $self->get('ThemeUrlPrefix') . "highslide"; return <