1 # Simple Photo Gallery: Web Interface
2 # (c) 2003--2012 Martin Mares <mj@ucw.cz>
4 package UCW::Gallery::Web;
6 use UCW::Gallery qw(%CF);
14 'i' => { 'var' => \$show_img, 'check' => '\d+' },
15 'a' => { 'var' => \$send_archive }
22 if ($send_archive && $CF{'AllowArchives'}) {
24 require UCW::Gallery::Archive;
25 return new UCW::Gallery::Archive($send_archive);
32 print "<p style='color:red'>Bad luck, the script is broken. Sorry.\n<p>$_[0]\n";
33 print "</body></html>\n";
37 my ($prev, $up, $next) = @_;
38 print "<p class=parent>";
39 print "<span class=back style='width: $CF{'BackW'}px; height: $CF{'BackH'}px'>";
40 print "<a href='$prev'><img src='$CF{'BackImg'}' width=$CF{'BackW'} height=$CF{'BackH'} alt='Back'></a>" if $prev ne "";
42 print "<span class=fwd style='width: $CF{'FwdW'}px; height: $CF{'FwdH'}px'>";
43 print "<a href='$next'><img src='$CF{'FwdImg'}' width=$CF{'FwdW'} height=$CF{'FwdH'} alt='Forward'></a>" if $next ne "";
45 print "<a href='$up'><img src='$CF{'ParentImg'}' width=$CF{'ParentW'} height=$CF{'ParentH'} alt='Up'></a>\n" if $up ne "";
49 my $title = UCW::CGI::html_escape($CF{"Title"});
51 Content-Type: text/html
53 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
56 <link rel=stylesheet href="$CF{"StyleSheet"}" type="text/css" media=all>
61 $UCW::CGI::error_hook = \&error;
65 print "$CF{'BotExtras'}\n</body></html>\n";
69 if ($show_img < 1 || $show_img > $num_photos) {
70 print "Status: 404\n";
72 print "<h1>No such photo</h1>\n";
77 my $id = $meta->{sequence}->[$show_img-1];
78 my $m = $meta->{photo}->{$id} or die;
81 show_links(($show_img > 1 ? ("?i=".($show_img-1)) : ""),
83 ($show_img < $num_photos ? ("?i=".($show_img+1)) : ""));
85 my $t = UCW::CGI::html_escape($m->{title});
88 print "<h1>$t</h1>\n" if $t ne "";
89 my $img = $CF{'PhotoUrlPrefix'} . $id . ".jpg";
90 print "<p class=large><img src='$img' width=$w height=$h alt='$t'>\n";
98 show_links($CF{'BackURL'}, $CF{'ParentURL'}, $CF{'FwdURL'});
99 print "<h1>$CF{'Title'}</h1>\n";
100 print "<h2>$CF{'SubTitle'}</h2>\n" if defined $CF{'SubTitle'};
102 my $thumb_fmt = $CF{'ThumbW'} . "x" . $CF{'ThumbH'};
103 my $thumb_meta = $meta->{thumb}->{$thumb_fmt} or die "No thumbnails for format $thumb_fmt found!\n";
105 for my $idx (1..$num_photos) {
106 my $id = $meta->{sequence}->[$idx-1];
107 my $m = $meta->{photo}->{$id} or die;
108 my $tm = $thumb_meta->{$id} or die;
110 my $annot = UCW::CGI::html_escape($m->{title});
113 my $thumb = $CF{'ThumbUrlPrefix'} . "/$thumb_fmt/$id.jpg";
114 my $side_w = $CF{"ThumbW"} + 2*$CF{"InteriorMargin"};
115 my $side_h = $CF{"ThumbH"} + 2*$CF{"InteriorMargin"};
116 my $box_w = $CF{"LeftW"} + $side_w + $CF{"RightW"};
117 my $box_h = $CF{"TopH"} + $side_h + $CF{"BotH"};
118 print "<div class=thf><div class=thumb>\n";
119 print "<img src='$CF{'TopImg'}' width=$box_w height=$CF{'TopH'} alt='' class=tt>\n";
120 print "<img src='$CF{'LeftImg'}' width=$CF{'LeftW'} height=$side_h alt='' class=tl>\n";
121 my $ol = $CF{'LeftW'} + $CF{'InteriorMargin'} + int(($CF{'ThumbW'} - $tw)/2);
122 my $ot = $CF{'TopH'} + $CF{'InteriorMargin'} + int(($CF{'ThumbH'} - $th)/2);
123 my $tit = ($annot ne "") ? " title=\"$annot\"" : "";
124 my $url = ($CF{"ImageSubpages"} ? "?i=$id" : $orig);
125 print "<a href='$url'><img src='$thumb' width=$w height=$h alt='$orig'$tit class=ti style='left: ${ol}px; top: ${ot}px'></a>\n";
126 print "<img src='$CF{'RightImg'}' width=$CF{'RightW'} height=$side_h alt='' class=tr>\n";
127 print "<img src='$CF{'BotImg'}' width=$box_w height=$CF{'BotH'} alt='' class=tb>\n";
136 UCW::CGI::parse_args(\%args);
137 UCW::Gallery::LoadConfig();
138 $meta = UCW::Gallery::ReadMeta(File::Spec->catfile($CF{'CacheDir'}, 'cache.meta'));
139 $num_photos = scalar @{$meta->{sequence}};
141 if ($show_img ne "") {