X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=gal2%2FUCW%2FGallery%2FWeb.pm;h=dbf913a63de4858f97fbdb8ef1359cb08cbf4d47;hb=426863234124dfad2c43a3d6967680c7217bc090;hp=d2a718ad372d277a644b8b3cc3fced5fe9aa6ba8;hpb=f9921003cf92c6e31af784bdf0e3f0e42d6fc25d;p=gallery.git diff --git a/gal2/UCW/Gallery/Web.pm b/gal2/UCW/Gallery/Web.pm index d2a718a..dbf913a 100644 --- a/gal2/UCW/Gallery/Web.pm +++ b/gal2/UCW/Gallery/Web.pm @@ -3,134 +3,164 @@ package UCW::Gallery::Web; -use UCW::Gallery qw(%CF); +use strict; +use warnings; + +use UCW::Gallery; use UCW::CGI; use File::Spec; my $show_img; +my $want_archive; my %args = ( 'i' => { 'var' => \$show_img, 'check' => '\d+' }, + 'a' => { 'var' => \$want_archive }, ); -our $meta; -our $num_photos; - sub error($) { print "

Bad luck, the script is broken. Sorry.\n

$_[0]\n"; print "\n"; } -sub show_links($$$) { - my ($prev, $up, $next) = @_; - print "

"; - print ""; - print "Back" if $prev ne ""; - print "\n"; - print ""; - print "Forward" if $next ne ""; - print "\n"; - print "Up\n" if $up ne ""; +sub get($$) { + my ($self, $key) = @_; + return $self->{gal}->get($key); } -sub html_top() { - my $title = UCW::CGI::html_escape($CF{"Title"}); +sub extras($$) { + my ($self, $key) = @_; + my $val = $self->get($key); + if (ref $val eq 'CODE') { + return &$val($self->{gal}); + } else { + return $val; + } +} + +sub html_top($) { + my ($self) = @_; + my $title = UCW::CGI::html_escape($self->get('Title')); + my $hextras = $self->extras('WebHeadExtras'); + my $textras = $self->extras('WebTopExtras'); + my $theme_hextras = $self->theme_head_extras; print < -$CF{"HeadExtras"} - -$title +$hextras$theme_hextras$title -$CF{"TopExtras"} +$textras EOF - $UCW::CGI::error_hook = \&error; + $UCW::CGI::ErrorHandler::error_hook = \&error; } -sub html_bot() { - print "$CF{'BotExtras'}\n\n"; +sub html_bot($) { + my ($self) = @_; + print $self->extras('WebBotExtras'), "\n"; } -sub show_img() { - if ($show_img < 1 || $show_img > $num_photos) { - print "Status: 404\n"; - html_top(); - print "

No such photo

\n"; - html_bot(); +sub show_img($) { + my ($self) = @_; + + if ($show_img < 1 || $show_img > $self->{num_photos}) { + UCW::CGI::http_error('404 No such photo'); return; } + my $meta = $self->{meta}; my $id = $meta->{sequence}->[$show_img-1]; my $m = $meta->{photo}->{$id} or die; - html_top(); + $self->html_top; - show_links(($show_img > 1 ? ("?i=".($show_img-1)) : ""), - "?", - ($show_img < $num_photos ? ("?i=".($show_img+1)) : "")); + $self->show_links(($show_img > 1 ? ("?i=".($show_img-1)) : ""), + ".", + ($show_img < $self->{num_photos} ? ("?i=".($show_img+1)) : "")); my $t = UCW::CGI::html_escape($m->{title}); my $w = $m->{w}; my $h = $m->{h}; print "

$t

\n" if $t ne ""; - my $img = $CF{'PhotoUrlPrefix'} . $id . ".jpg"; + my $img = $self->get('PhotoUrlPrefix') . $id . '.jpg'; print "

$t\n"; - html_bot(); + $self->html_bot; } -sub show_list() { - html_top(); +sub show_pre_thumbs($) { + my ($self) = @_; +} - show_links($CF{'BackURL'}, $CF{'ParentURL'}, $CF{'FwdURL'}); - print "

$CF{'Title'}

\n"; - print "

$CF{'SubTitle'}

\n" if defined $CF{'SubTitle'}; +sub show_post_thumbs($) { + my ($self) = @_; +} - my $thumb_fmt = $CF{'ThumbW'} . "x" . $CF{'ThumbH'}; - my $thumb_meta = $meta->{thumb}->{$thumb_fmt} or die "No thumbnails for format $thumb_fmt found!\n"; +sub show_list($) { + my ($self) = @_; + $self->html_top; - for my $idx (1..$num_photos) { + $self->show_links($self->get('BackURL'), $self->get('ParentURL'), $self->get('FwdURL')); + print "

", $self->get('Title'), "

\n"; + my $subtitle = $self->get('SubTitle'); + print "

$subtitle

\n" if $subtitle ne ""; + $self->show_pre_thumbs; + + my $meta = $self->{meta}; + for my $idx (1..$self->{num_photos}) { my $id = $meta->{sequence}->[$idx-1]; - my $m = $meta->{photo}->{$id} or die; - my $tm = $thumb_meta->{$id} or die; - - my $annot = UCW::CGI::html_escape($m->{title}); - my $tw = $tm->{w}; - my $th = $tm->{h}; - my $thumb = $CF{'ThumbUrlPrefix'} . "$thumb_fmt/$id.jpg"; - my $side_w = $CF{"ThumbW"} + 2*$CF{"InteriorMargin"}; - my $side_h = $CF{"ThumbH"} + 2*$CF{"InteriorMargin"}; - my $box_w = $CF{"LeftW"} + $side_w + $CF{"RightW"}; - my $box_h = $CF{"TopH"} + $side_h + $CF{"BotH"}; - print "
\n"; - print "\n"; - print "\n"; - my $ol = $CF{'LeftW'} + $CF{'InteriorMargin'} + int(($CF{'ThumbW'} - $tw)/2); - my $ot = $CF{'TopH'} + $CF{'InteriorMargin'} + int(($CF{'ThumbH'} - $th)/2); - my $tit = ($annot ne "") ? " title=\"$annot\"" : ""; - my $url = ($CF{"ImageSubpages"} ? "?i=$idx" : $orig); - print "$orig\n"; - print "\n"; - print "\n"; - print "
\n"; - print "
\n\n"; + my $click_url; + if ($self->get('WebImageSubpages')) { + $click_url = "?i=$idx"; + } else { + $click_url = $self->get('PhotoUrlPrefix') . "$id.jpg"; + } + $self->show_thumb($meta, $id, $click_url); } - html_bot(); + $self->show_post_thumbs; + $self->html_bot(); } -sub Dispatch() { +sub dispatch($) { + my ($self) = @_; + binmode STDOUT, ':utf8'; UCW::CGI::parse_args(\%args); - UCW::Gallery::LoadConfig(); - $meta = UCW::Gallery::ReadMeta(File::Spec->catfile($CF{'CacheDir'}, 'cache.meta')); - $num_photos = scalar @{$meta->{sequence}}; - - if ($show_img ne "") { - show_img(); + $self->{meta} = $self->{gal}->read_meta(File::Spec->catfile($self->get('CacheDir'), 'cache.meta')); + $self->{num_photos} = scalar @{$self->{meta}->{sequence}}; + + if ($want_archive) { + require UCW::Gallery::Archive; + UCW::Gallery::Archive::send_archive($self->{gal}, $self->{meta}); + } elsif ($show_img ne "") { + $self->show_img; } else { - show_list(); + $self->show_list; } } +sub attach($$) { + my ($class, $gal) = @_; + my $self = { gal => $gal }; + $gal->def( + WebFE => $self, + + # Extras are either strings or functions called with the current gallery object as parameter + WebHeadExtras => "", + WebTopExtras => "", + WebBotExtras => "", + + # Used by the theming logic + WebThemeCSS => undef, + + # 1 if thumbnail link to sub-pages with images, 0 if they link directly to image files + WebImageSubpages => 1, + + # If enabled, calling the CGI with a=zip produces a ZIP archive with all photos. + WebAllowArchives => 1, + ); + bless $self, $class; + return $self; +} + 42;