]> mj.ucw.cz Git - gallery.git/commitdiff
Gallery2: Front-end attachment reform
authorMartin Mares <mj@ucw.cz>
Sun, 30 Dec 2012 11:18:35 +0000 (12:18 +0100)
committerMartin Mares <mj@ucw.cz>
Sun, 8 Feb 2015 20:14:17 +0000 (21:14 +0100)
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).

gal/README
gal/UCW/Gallery.pm
gal/UCW/Gallery/Web/HighSlide.pm
gal/UCW/Gallery/Web/NrtBlue.pm
gal/UCW/Gallery/Web/Plain.pm
gal/bin/gal-cache

index 9c0d3500a7856d7d0c15d6a7fccf5de24766f677..e37fda09c1a9a65ee91b0e8c5e0c81ef6f01b207 100644 (file)
@@ -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
 ~~~~~~~~
index 3912868a2f61e4e13f51f16957dd1b2436070eb0..63e51b9f1fc76f6c0b01a38058f55e9ea96ab3a1 100644 (file)
@@ -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;
index 86ffcacf4a09548cbc06ed5a0a8c158daa4034b2..b3df6e6eaeae445f41373d26aa5c00f798008150 100644 (file)
@@ -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 <<AMEN ;
-<link rel=stylesheet href='$tdir/style.css' type='text/css' media=all>
 <script type="text/javascript" src="$hsdir/highslide-with-gallery.js"></script>
 <script type="text/javascript" src="$hsdir/custom.js" charset="utf-8"></script>
 <script type="text/javascript">
@@ -47,13 +39,9 @@ sub show_links($$$$) {
        my ($self, $prev, $up, $next) = @_;
        my $theme = $self->theme_dir;
        print "<p class=parent>";
-       print "<span class=back style='width: ${navw}px; height: ${navh}px'>";
-       print "<a href='$prev'><img src='$theme/prev.png' width=${navw} height=${navh} alt='Back'></a>" if $prev ne "";
-       print "</span>\n";
-       printf "<span class=fwd style='width: ${navw}px; height: ${navh}px'>";
-       printf "<a href='$next'><img src='$theme/next.png' width=${navw} height=${navh} alt='Forward'></a>" if $next ne "";
-       print "</span>\n";
-       printf "<a href='$up'><img src='$theme/back.png' width=${navw} height=${navh} alt='Up'></a>" if $up ne "";
+       print "<a href='$prev'><img class=back prev src='$theme/prev.png'></a>" if $prev ne "";
+       printf "<a href='$next'><img class=fwd src='$theme/next.png'></a>" if $next ne "";
+       printf "<a href='$up'><img class=up src='$theme/back.png'></a>" if $up ne "";
 }
 
 sub show_pre_thumbs($) {
@@ -69,10 +57,9 @@ sub show_post_thumbs($) {
 
 sub show_thumb($) {
        my ($self, $meta, $photo_id, $click_url) = @_;
-       my $theme = $self->theme_dir;
        my $m = $meta->{photo}->{$photo_id};
        my $annot = UCW::CGI::html_escape($m->{title});
-       my $tf = $self->{thumb_fmt};
+       my $tf = $self->get('ThumbFormats')->[0];
        my $tm = $meta->{thumb}->{$tf}->{$photo_id} or die "No thumbnails for format $tf found!\n";
        my $tw = $tm->{w};
        my $th = $tm->{h};
@@ -85,10 +72,10 @@ sub show_thumb($) {
        print "<img src='$thumb' width=$tw height=$th alt='Photo'$tit></a>\n";
 }
 
-sub attach($$) {
+sub run($$) {
        my ($class, $gal) = @_;
        my $self = $class->SUPER::attach($gal);
-       $self->{thumb_fmt} = $gal->require_thumbnails($thumb_w, $thumb_h);
+       $self->dispatch();
        return $self;
 }
 
index 0d327f157459c4f36de01ac74f36ccb2cc33f9a7..7fc56378a5ee2446adb5ab1f7c1bcd8dfedaebb5 100644 (file)
@@ -15,8 +15,6 @@ our @ISA = qw(UCW::Gallery::Web);
 my $theme_name = "nrt-blue";
 my $navw = 48;
 my $navh = 48;
-my $thumb_w = 114;
-my $thumb_h = 94;
 my $interior_margin = 4;
 my $left_w = 14;
 my $right_w = 18;
@@ -52,7 +50,8 @@ sub show_thumb($) {
        my $theme = $self->theme_dir;
        my $m = $meta->{photo}->{$photo_id};
        my $annot = UCW::CGI::html_escape($m->{title});
-       my $tf = $self->{thumb_fmt};
+       my $tf = $self->get('ThumbFormats')->[0];
+       my ($thumb_w, $thumb_h) = $self->{gal}->thumb_fmt_to_size($tf);
        my $tm = $meta->{thumb}->{$tf}->{$photo_id} or die "No thumbnails for format $tf found!\n";
        my $tw = $tm->{w};
        my $th = $tm->{h};
@@ -73,10 +72,10 @@ sub show_thumb($) {
        print "</div></div>\n\n";
 }
 
-sub attach($$) {
+sub run($$) {
        my ($class, $gal) = @_;
        my $self = $class->SUPER::attach($gal);
-       $self->{thumb_fmt} = $gal->require_thumbnails($thumb_w, $thumb_h);
+       $self->dispatch();
        return $self;
 }
 
index 885095b541e455689fdb0e592220eb1bd6aa2163..f7d213cb8443696a2a7140c693713476696797d3 100644 (file)
@@ -16,8 +16,6 @@ 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) = @_;
@@ -48,7 +46,8 @@ sub show_thumb($) {
        my $theme = $self->theme_dir;
        my $m = $meta->{photo}->{$photo_id};
        my $annot = UCW::CGI::html_escape($m->{title});
-       my $tf = $self->{thumb_fmt};
+       my $tf = $self->get('ThumbFormats')->[0];
+       my ($thumb_w, $thumb_h) = $self->{gal}->thumb_fmt_to_size($tf);
        my $tm = $meta->{thumb}->{$tf}->{$photo_id} or die "No thumbnails for format $tf found!\n";
        my $tw = $tm->{w};
        my $th = $tm->{h};
@@ -61,10 +60,10 @@ sub show_thumb($) {
        print "</div></div>\n\n";
 }
 
-sub attach($$) {
+sub run($$) {
        my ($class, $gal) = @_;
        my $self = $class->SUPER::attach($gal);
-       $self->{thumb_fmt} = $gal->require_thumbnails($thumb_w, $thumb_h);
+       $self->dispatch();
        return $self;
 }
 
index da9a29132dfbab2ec26aa96ca95737970e3350d8..904b85e3e04c28c4a93463802b6456056151809b 100755 (executable)
@@ -40,9 +40,9 @@ for my $f (@$orig_list) {
        $m->{title} = $f->{title};
 }
 
-for my $thumb_fmt (keys %{$gal->get('ThumbFormats')}) {
-       my ($tw, $th) = ($thumb_fmt =~ m{^(\d+)x(\d+)$}) or die "Cannot parse thumbnail format $thumb_fmt\n";
+for my $thumb_fmt (@{$gal->get('ThumbFormats')}) {
        print "Generating $thumb_fmt thumbnails\n";
+       my ($tw, $th) = $gal->thumb_fmt_to_size($thumb_fmt);
        my $thumb_meta = {};
        $meta->{thumb}->{$thumb_fmt} = $thumb_meta;
        my $thumb_dir = File::Spec->catfile($cache_dir, $thumb_fmt);