From 3458be45556b066cd093f5c0696c1627808d71f6 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Mon, 24 Dec 2012 00:32:02 +0100 Subject: [PATCH] Gallery2: First attempts at web version --- gal2/UCW/Gallery.pm | 14 ++-- gal2/UCW/Gallery/Web.pm | 148 ++++++++++++++++++++++++++++++++++++++++ gal2/gal-cache | 5 +- gal2/gal-gen | 6 +- gal2/nrt/back.png | Bin 0 -> 590 bytes gal2/nrt/bot.png | Bin 0 -> 721 bytes gal2/nrt/left.png | Bin 0 -> 144 bytes gal2/nrt/next.png | Bin 0 -> 1309 bytes gal2/nrt/prev.png | Bin 0 -> 1352 bytes gal2/nrt/right.png | Bin 0 -> 210 bytes gal2/nrt/style.css | 17 +++++ gal2/nrt/theme.conf | 40 +++++++++++ gal2/nrt/theme.pm | 40 +++++++++++ gal2/nrt/top.png | Bin 0 -> 459 bytes 14 files changed, 260 insertions(+), 10 deletions(-) create mode 100644 gal2/UCW/Gallery/Web.pm create mode 100644 gal2/nrt/back.png create mode 100644 gal2/nrt/bot.png create mode 100644 gal2/nrt/left.png create mode 100644 gal2/nrt/next.png create mode 100644 gal2/nrt/prev.png create mode 100644 gal2/nrt/right.png create mode 100644 gal2/nrt/style.css create mode 100644 gal2/nrt/theme.conf create mode 100644 gal2/nrt/theme.pm create mode 100644 gal2/nrt/top.png diff --git a/gal2/UCW/Gallery.pm b/gal2/UCW/Gallery.pm index 847de01..f0a1e97 100644 --- a/gal2/UCW/Gallery.pm +++ b/gal2/UCW/Gallery.pm @@ -20,9 +20,9 @@ BEGIN { } our %CF; -our $th; BEGIN { + # FIXME: Check config $CF{'Title'} = 'An Unnamed Gallery', $CF{'HeadExtras'} = "", $CF{'TopExtras'} = "", @@ -36,6 +36,7 @@ BEGIN { $CF{'ThumbUrlPrefix'} = "", $CF{'MetaDataDir'} = '.', $CF{'PhotoDir'} = '.', + # FIXME: Who sets GalDir? $CF{'ScanDefaultTransform'} = 's'; $CF{'OrigDir'} = '.'; @@ -43,8 +44,7 @@ BEGIN { $CF{'CacheDir'} = 'cache', $CF{'PhotoMaxWidth'} = 1024, $CF{'PhotoMaxHeight'} = 1024, - # FIXME: ThumbSizes should be set by themes - $CF{'ThumbSizes'} = [ [114,94], [256,256] ], + $CF{'ThumbFormats'} = {}, } sub LoadConfig() { @@ -66,11 +66,17 @@ sub SetOptions(@) { $CF{$o} = $v; if ($o eq "Theme") { require $CF{"GalDir"} . "/$v/theme.pm"; - Gallery::Theme::Init($CF{"GalURL"} . "/$v"); + UCW::Gallery::Theme::Init($CF{"GalURL"} . "/$v"); } } } +sub RequireThumbnails($$) { + my ($w, $h) = @_; + my $fmt = "${w}x${h}"; + $CF{'ThumbFormats'}->{$fmt} = 1; +} + sub WriteList($$) { my ($file, $images) = @_; open LIST, '>', "$file.new" or die "Cannot create $file.new: $!\n"; diff --git a/gal2/UCW/Gallery/Web.pm b/gal2/UCW/Gallery/Web.pm new file mode 100644 index 0000000..ac33361 --- /dev/null +++ b/gal2/UCW/Gallery/Web.pm @@ -0,0 +1,148 @@ +# Simple Photo Gallery: Web Interface +# (c) 2003--2012 Martin Mares + +package UCW::Gallery::Web; + +use UCW::Gallery qw(%CF); +use UCW::CGI; +use File::Spec; + +my $show_img; +my $send_archive; + +my %args = ( + 'i' => { 'var' => \$show_img, 'check' => '\d+' }, + 'a' => { 'var' => \$send_archive } +); + +our $meta; +our $num_photos; + +sub new() { + if ($send_archive && $CF{'AllowArchives'}) { + # FIXME? + require UCW::Gallery::Archive; + return new UCW::Gallery::Archive($send_archive); + } else { + return bless {}; + } +} + +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 html_top() { + my $title = UCW::CGI::html_escape($CF{"Title"}); + print < + +$CF{"HeadExtras"} + +$title + +$CF{"TopExtras"} +EOF + $UCW::CGI::error_hook = \&error; +} + +sub html_bot() { + print "$CF{'BotExtras'}\n\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(); + return; + } + + my $id = $meta->{sequence}->[$show_img-1]; + my $m = $meta->{photo}->{$id} or die; + html_top(); + + show_links(($show_img > 1 ? ("?i=".($show_img-1)) : ""), + "?", + ($show_img < $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"; + print "

$t\n"; + + html_bot(); +} + +sub show_list() { + html_top(); + + show_links($CF{'BackURL'}, $CF{'ParentURL'}, $CF{'FwdURL'}); + print "

$CF{'Title'}

\n"; + print "

$CF{'SubTitle'}

\n" if defined $CF{'SubTitle'}; + + 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"; + + for my $idx (1..$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=$id" : $orig); + print "$orig\n"; + print "\n"; + print "\n"; + print "
\n"; + print "
\n\n"; + } + + html_bot(); +} + +sub Dispatch() { + 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(); + } else { + show_list(); + } +} + +42; diff --git a/gal2/gal-cache b/gal2/gal-cache index d6ee353..5accb3f 100755 --- a/gal2/gal-cache +++ b/gal2/gal-cache @@ -31,9 +31,8 @@ if (-d $cache_dir) { print "Creating cache directory: $cache_dir\n"; File::Path::mkpath($cache_dir) or die "Unable to create $cache_dir: $!\n"; -for my $t (@{$CF{'ThumbSizes'}}) { - my ($tw, $th) = @$t; - my $thumb_fmt = $tw . 'x' . $th; +for my $thumb_fmt (keys %{$CF{'ThumbFormats'}}) { + my ($tw, $th) = ($thumb_fmt =~ m{^(\d+)x(\d+)$}) or die "Cannot parse thumbnail format $thumb_fmt\n"; print "Generating $thumb_fmt thumbnails\n"; my $thumb_meta = {}; $meta->{thumb}->{$thumb_fmt} = $thumb_meta; diff --git a/gal2/gal-gen b/gal2/gal-gen index 7d244fe..3c1a6e9 100755 --- a/gal2/gal-gen +++ b/gal2/gal-gen @@ -41,7 +41,6 @@ for my $f (@$orig_list) { my $id = $f->{id}; my $rotate = $f->{orientation}; my $xfrm = $f->{xfrm}; - push @{$meta->{sequence}}, $id; print "$id: "; my $p = new Image::Magick; @@ -69,7 +68,10 @@ for my $f (@$orig_list) { 'xf' => $xfrm, 'w' => $w, 'h' => $h, + 'title' => $f->{title}, }; + $meta->{photo}->{$id} = $m; + push @{$meta->{sequence}}, $id; my $om = $old_meta->{photo}->{$id}; if ($om && @@ -79,7 +81,6 @@ for my $f (@$orig_list) { $om->{h} eq $m->{h}) { # FIXME: Remove old images? print "... uptodate\n"; - $meta->{photo}->{$id} = $om; next; } @@ -121,7 +122,6 @@ for my $f (@$orig_list) { rename $tmp, $photo or die "Cannot rename $tmp to $photo: $!\n"; print "... OK\n"; - $meta->{photo}->{$id} = $m; } print "Writing meta-data\n"; diff --git a/gal2/nrt/back.png b/gal2/nrt/back.png new file mode 100644 index 0000000000000000000000000000000000000000..c0c4ceee6b7060a1816cadaf5d8f3fe3fbb6daca GIT binary patch literal 590 zcmV-U0-2`6a(svgG|apI#=Wp3CV~SD>INsAJa%n?n8oZX_2L zUS}&5-86R&cQ>~RW!ZbLpe9$FIm6+d&cP~IY?mLe$`%RrttTxQrNC{j3`{Qm{zScwZo?J02JdtU-XDVT2c?~hnbv}3ICGNm98902@sIwH zJo)-kiTVwsl(^k)xLhtMiURZb93D>>%jFW&=@hfs4AbcplgR{Wnj(&4gkgvv2tWuy z@ZAgb^czA52qB%<)kM>sg24Od`5cr|(}Ex{6|5-8FpF)+rA zY_>x-Ml`#cQA%+<9$&t2Prumhc8KE`Q4}GHA|srus?|gTU_|4bW53_Oe)XPSuv)Dk zgn$qNgTVltb8ya$XaJr?vn30H0E{tk&Y_gTcDwzC+wlBkR;v|?qClFa7!HR>lElcy z7&9IL54Tuz5K5^LO$dRqEV0>akYyPbi^Xg2$n&FEuh-b^b`U~fJRV~_9wW;#q-hEv zgb|HW`qY;wr4#`Cc|lcGxZm%%UavTvPAG~3d7k6r;{$n~<9IycbUNXBz2bJep{gn< zrA&WK^RuTPG()`3T9i_RVTdS-AcVkhI7F6Z7>!0X+3c)lkH_o*l~N|7g<*&|jv=K4 z0F&E<5ICRDD9h4|_J(wc#yQ7eFhG(dwXIVh(6(hX=9)z3G%bsr+w^u?mL=}@JEW9e zv^SznG}{3!n|=_8U7@@zCQbI~;a+{V*S2EpPc+vVv+uuq0Nm3UbEuAfxYs)m_xxOwwu#y*nx-k7-R$4n`g!_At0+>#>%%a)d00000NkvXXu0mjf DkDgPz literal 0 HcmV?d00001 diff --git a/gal2/nrt/left.png b/gal2/nrt/left.png new file mode 100644 index 0000000000000000000000000000000000000000..3bd3aed4b8d2b0c324184b7e199df9d8dff4e612 GIT binary patch literal 144 zcmeAS@N?(olHy`uVBq!ia0vp^d_bJW!3HFMzhCeSNQHa4IEGZrd3(-~>wp6XYvAPM zivP+{H-7jEa%fJ|nN-H6qa#=KWv=I@Rh!Oi=`bkYzW&_zOLxz|iE{EZw#ei>zW(1n k4i=_H2L%Bn>Oiiz%Snw5Z2vinfL1Vgy85}Sb4q9e0RHbW0ssI2 literal 0 HcmV?d00001 diff --git a/gal2/nrt/next.png b/gal2/nrt/next.png new file mode 100644 index 0000000000000000000000000000000000000000..72a4e391f6b29845ec1e9f61e2a0f3493a568c80 GIT binary patch literal 1309 zcmV+&1>*XNP)7s8!`laXLCWqEe|urfD{XSXo(V8msF%rPFCD6bfV*M#m5>w-7m$d1GS( zv$L}(7K^A>tEkm#*XBCKX0usLPfufKX9pJ-7me-s+iFFZPN$n@u|A$YeM$!h2Tdzc ztJUcC?c0vAnx;`Im7;t;-%%x60+^;r@7}#@2{Af4+7zNztI_W6E)5P2{#A&U0G4G@ zsZ^q+r6tc0j4`^ryriwIEsDire+{A~0Aq}*)hcDPS$gy4jVB1k7@4L?=jZ42>C>mb z2GJ6L=*L#5R4SCoWa#zl*PbB^!=QXVPpMRjG)?>C5N!dxLVWn}fesH3sa!6TWm%pe zUcP)uU%!5(VzKCWJpW&=dLcm&AW0I!;V_;&c>-P69p~=t?V(U8pi-%TF$Mq-MG>J; z2oD}Sz@tZx9Al43aR;CUXRC}M7I4(sddj^7v?8$-EV#^vRu>-)hq!0G8JMn*<(dV1RQcSTWU}W>)HIkzyN~5AijM0;>o(Dd};cys|B)Q6dTY%%^V^8K)RYfQif+&iP zu}2Xj1{;MH&0HJ%DcO#sho@xl|A- T!%_XA00000NkvXXu0mjfJAZ90 literal 0 HcmV?d00001 diff --git a/gal2/nrt/prev.png b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zNm!PJMxz1Obz{AmMcVc{LFDs!0Do8MM~@zXh!6w;{<$sx{eun=SFc_L0H~^pd-v|) z%9Sf^{y5?&hJ!H%$8k`tR$-bZ%H=X@wHg>>NT<^%6biU_@gg)$Ln@VO>oh?S!1Fv< zmW4{Cf`fwt93LO!=g*%IMG=~&p;#=!Fbt&A>BzfstgjNSnE={H*7yCe+hns@Boc|= z3fal?IgW!M2uP>Xa2yAsC?c23ovMw-nt_%WV{ly;wr#_490WlCQ4}G|GGtlq2+&dx z1n_+yj^n_#ZFrssp65gF{{qko5(Gi``pEM<1VI4L^L^`Z>wag9AqawSMtGi&-9}Fh za57AIv6vsH&f*PyX9XCv&i%L1A;6$D1Q@i20E5;LV9+}E0Dl42yAF%TvDU5t0000< KMNUMnLSTY}K!ET7 literal 0 HcmV?d00001 diff --git a/gal2/nrt/right.png b/gal2/nrt/right.png new file mode 100644 index 0000000000000000000000000000000000000000..3e655dccb48e5febb5234624debd22db2de79d80 GIT binary patch literal 210 zcmeAS@N?(olHy`uVBq!ia0vp^LO`6x!3HFc)gEjBQZqeW978JRyuDz_*X$s`dNHe; zp|hi7rzv}yn3B#L2DV38E5B~O?!D!jl=#+l+M23CUOJ}_*_`*ee8i%U=dgo|fMCr! zfri}MCoF@#6rcO76>YdC^;|Y@A+yHPfb75D{wr?3VEFSH^Z5nZ8@R2WzwWKtsJCKy m3r-;CDEM*m`UP?<3G78XLmeCaT9SZ{WbkzLb6Mw<&;$Vb5>puf literal 0 HcmV?d00001 diff --git a/gal2/nrt/style.css b/gal2/nrt/style.css new file mode 100644 index 0000000..b67b092 --- /dev/null +++ b/gal2/nrt/style.css @@ -0,0 +1,17 @@ +.thf { margin: 0 0 0 0; padding: 0 0 0 0; float: left; border: none; } +.thumb { position: relative; width: 154px; height: 134px; background-color: black; } +.tt { position: absolute; top: 0; left: 0; } +.tl { position: absolute; top: 14px; left: 0; } +.ti { position: absolute; } +.tr { position: absolute; top: 14px; right: 0; } +.tb { position: absolute; bottom: 0; right: 0; } +.annot { width: 154px; text-align: center; } +IMG { border: none; } +H1 { text-align: center; } +H2 { text-align: center; } +P { clear: both; } +H2 { clear: both; } +.parent { text-align: center; } +.large { text-align: center; } +.back { float: left; } +.fwd { float: right; } diff --git a/gal2/nrt/theme.conf b/gal2/nrt/theme.conf new file mode 100644 index 0000000..4242eba --- /dev/null +++ b/gal2/nrt/theme.conf @@ -0,0 +1,40 @@ + +PicturesPerRow: 5 +BGColor: #ffffff +TextColor: #000000 +CommentColor: #000000 +FilmBGColor: #322207 +LinkColor: #000000 +ALinkColor: gold +VLinkColor: #000000 +LinkSize: 1 + +# linksize | top +# | v +# ------------------|---------------- --- +# | | | | +# ------------------v---------------- --- +# | | ______________________ | | ^ +# | | | ^ | | | | +# | | | | height | | | +# | | | | | | | +# l | | | | | | | right +# --->|---| |<--|----width------->| |---|<----- +# | | | | | | | +# | | | | | | | +# | | | | | | | +# | | | v | | | +# | | |---------------------| | | | +# | | | | v +# ----------------------------------- --- +# | | | +# ----------------------------------- --- +# ^ +# | bottom +# +# total = left + linksize + width + linksize + right + +# Decorations: top bottom left right +Decorations: 14 18 14 18 +ThumbWidth: 120 +ThumbHeight: 100 diff --git a/gal2/nrt/theme.pm b/gal2/nrt/theme.pm new file mode 100644 index 0000000..f9674ad --- /dev/null +++ b/gal2/nrt/theme.pm @@ -0,0 +1,40 @@ +# NRT Theme for MJ's Photo Gallery +# (c) 2003--2004 Martin Mares ; GPL'ed +# Theme images taken from the cthumb package (c) Carlos Puchol + +package UCW::Gallery::Theme; + +use strict; +use warnings; + +use UCW::Gallery; + +sub Init($) { + my ($u) = @_; + UCW::Gallery::SetOptions( + "StyleSheet" => "$u/style.css", + "ThumbW" => 114, + "ThumbH" => 94, + "TopImg" => "$u/top.png", + "TopH" => 14, + "BotImg" => "$u/bot.png", + "BotH" => 18, + "LeftImg" => "$u/left.png", + "LeftW" => 14, + "RightImg" => "$u/right.png", + "RightW" => 18, + "InteriorMargin" => 4, + "ParentImg" => "$u/back.png", + "ParentH" => 48, + "ParentW" => 48, + "BackImg" => "$u/prev.png", + "BackH" => 48, + "BackW" => 48, + "FwdImg" => "$u/next.png", + "FwdH" => 48, + "FwdW" => 48 + ); + UCW::Gallery::RequireThumbnails(114, 94); +} + +1; diff --git a/gal2/nrt/top.png b/gal2/nrt/top.png new file mode 100644 index 0000000000000000000000000000000000000000..d8d5866441822e70012cd5d6603b0ea2e6aedf81 GIT binary patch literal 459 zcmV;+0W|)JP) z7?LFxOlyrKNm^Gg91)G@=ysj4WL_#}1`%Pu-!HK?VI^FzS1>cuG)0zW*lae)vJ7dO zB1w|3vJHynC1Yk-YjHRnes49xpXYM9V7J?avE6Qia9*~qXcXVX^_V{HiiMp=C<}_5Fx0(TO zqcJ9&wSw@CJkNVgg4Vj%iS}&r4S*E>!W8H88AVZq@Ez#np;0L