1 # Simple Photo Gallery: Web Interface
2 # (c) 2003--2012 Martin Mares <mj@ucw.cz>
4 package UCW::Gallery::Web;
17 'i' => { 'var' => \$show_img, 'check' => '\d+' },
18 'a' => { 'var' => \$want_archive },
22 print "<p style='color:red'>Bad luck, the script is broken. Sorry.\n<p>$_[0]\n";
23 print "</body></html>\n";
27 my ($self, $key) = @_;
28 return $self->{gal}->get($key);
32 my ($self, $key) = @_;
33 my $val = $self->get($key);
34 if (ref $val eq 'CODE') {
41 # For use by extras hooks
47 # For use by extras hooks: return true if we are showing an image page, false for index page
48 sub showing_image($) {
50 return $show_img ne "";
55 my $title = UCW::CGI::html_escape($self->get('Title'));
56 my $hextras = $self->extras('WebHeadExtras');
57 my $textras = $self->extras('WebTopExtras');
58 my $theme_hextras = $self->theme_head_extras;
60 Content-Type: text/html
62 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
64 $hextras$theme_hextras<title>$title</title>
68 $UCW::CGI::ErrorHandler::error_hook = \&error;
73 print $self->extras('WebBotExtras'), "</body></html>\n";
79 if ($show_img < 1 || $show_img > $self->{num_photos}) {
80 UCW::CGI::http_error('404 No such photo');
84 my $meta = $self->{meta};
85 my $id = $meta->{sequence}->[$show_img-1];
86 my $m = $meta->{photo}->{$id} or die;
89 $self->show_links(($show_img > 1 ? ("?i=".($show_img-1)) : ""),
91 ($show_img < $self->{num_photos} ? ("?i=".($show_img+1)) : ""));
93 my $t = UCW::CGI::html_escape($m->{title});
96 print "<h1>$t</h1>\n" if $t ne "";
97 my $img = $self->get('PhotoUrlPrefix') . $self->{gal}->photo_name($m, $id);
98 print "<p class=large><img src='$img' width=$w height=$h alt='$t'>\n";
103 sub show_pre_thumbs($) {
107 sub show_post_thumbs($) {
115 $self->show_links($self->get('BackURL'), $self->get('ParentURL'), $self->get('FwdURL'));
116 print "<h1>", $self->get('Title'), "</h1>\n";
117 my $subtitle = $self->get('SubTitle');
118 print "<h2>$subtitle</h2>\n" if $subtitle ne "";
119 $self->show_pre_thumbs;
121 my $meta = $self->{meta};
122 for my $idx (1..$self->{num_photos}) {
123 my $id = $meta->{sequence}->[$idx-1];
124 my $m = $meta->{photo}->{$id};
126 if ($self->get('WebImageSubpages')) {
127 $click_url = "?i=$idx";
129 $click_url = $self->get('PhotoUrlPrefix') . $self->{gal}->photo_name($m, $id);
131 $self->show_thumb($meta, $id, $click_url);
134 $self->show_post_thumbs;
140 binmode STDOUT, ':utf8';
141 UCW::CGI::parse_args(\%args);
142 $self->{meta} = $self->{gal}->read_meta(File::Spec->catfile($self->get('CacheDir'), 'cache.meta'));
143 $self->{num_photos} = scalar @{$self->{meta}->{sequence}};
146 require UCW::Gallery::Archive;
147 UCW::Gallery::Archive::send_archive($self->{gal}, $self->{meta});
148 } elsif ($show_img ne "") {
156 my ($class, $gal) = @_;
157 my $self = { gal => $gal };
161 # Extras are either strings or functions called with the current gallery object as parameter
166 # Used by the theming logic
167 WebThemeCSS => undef,
169 # 1 if thumbnail link to sub-pages with images, 0 if they link directly to image files
170 WebImageSubpages => 1,
172 # If enabled, calling the CGI with a=zip produces a ZIP archive with all photos.
173 WebAllowArchives => 1,