From 006c56f153962d8280c05ae8dcf4cabc291c34dc Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Sun, 8 Feb 2015 21:49:54 +0100 Subject: [PATCH] Added an example web front-end --- README | 2 ++ example/.htaccess | 8 ++++++ example/README | 7 ++++++ example/default.cf | 59 +++++++++++++++++++++++++++++++++++++++++++++ example/gallery.cgi | 26 ++++++++++++++++++++ 5 files changed, 102 insertions(+) create mode 100644 example/.htaccess create mode 100644 example/README create mode 100644 example/default.cf create mode 100644 example/gallery.cgi diff --git a/README b/README index 0a5d7c7..0aed6db 100644 --- a/README +++ b/README @@ -86,3 +86,5 @@ Workflow of images and it will try to re-use as much information from the previous gallery.list as possible. - When you modify existing images, run "gal scan --update". + + o See example/* for an example web front-end. diff --git a/example/.htaccess b/example/.htaccess new file mode 100644 index 0000000..aa29d40 --- /dev/null +++ b/example/.htaccess @@ -0,0 +1,8 @@ +Options -Indexes + +RewriteEngine On +RewriteBase /photos/ +RewriteRule ^([0-9][0-9][0-9][0-9]/.*)/thumb/(.*) /static/gallery/cache/$1/$2 [L] +RewriteRule ^([0-9][0-9][0-9][0-9]/.*)/photo/(.*) /static/gallery/photo/$1/$2 [L] +RewriteRule ^([0-9][0-9][0-9][0-9]/[^/]+)$ $1/ [R,L] +RewriteRule ^([0-9][0-9][0-9][0-9]/[^/]+)(/.*) gallery.cgi?dir=$1 [L,QSA] diff --git a/example/README b/example/README new file mode 100644 index 0000000..8835637 --- /dev/null +++ b/example/README @@ -0,0 +1,7 @@ +This is an example how to build a web gallery using UCW::Gallery. + +It requires UCW::CGI from LibUCW (see http://www.ucw.cz/libucw/) +and lots of tweaking for your site. + +You can see a gallery very similar to this example in action +at http://mj.ucw.cz/photos/. diff --git a/example/default.cf b/example/default.cf new file mode 100644 index 0000000..a43f20c --- /dev/null +++ b/example/default.cf @@ -0,0 +1,59 @@ +# Generic configuration file for UCW::Gallery + +use strict; +use warnings; +use utf8; + +use UCW::Gallery; +use Cwd; + +our $base_dir; +our $gallery; +our $static_dir; +our $lib_dir; + +BEGIN { + my $current_dir = getcwd; + if (($base_dir, $gallery) = $current_dir =~ m{(.*)/lib/photos/(.*)}) { + # We are called from the generated web tree + $static_dir = "$base_dir/static"; + $lib_dir = "$base_dir/lib"; + } elsif (($base_dir, $gallery) = $current_dir =~ m{(.*/web)/photos/(.*)}) { + # We are called from the source tree + $static_dir = "$base_dir/static"; # Expecting symlink to static + $lib_dir = $base_dir; + } else { + die "photos/default.cf: Please call me from the right directory\n"; + } +} + +use lib "$lib_dir/perl"; + +my $gal = UCW::Gallery->new(); + +$gal->set( + OrigDir => '/home/mj/photos', + PhotoDir => "$static_dir/gallery/photo/$gallery", + CacheDir => "$static_dir/gallery/cache/$gallery", + CacheExif => 1, + + PhotoUrlPrefix => 'photo/', # Rewritten by mod_rewrite later + ThumbUrlPrefix => 'thumb/', + ThemeUrlPrefix => '/gal/', + + ParentURL => '/photos/', + WebHeadExtras => "\n", + WebBotExtras => sub ($) { + my ($self) = @_; + return "" if $self->showing_image; + my $ziplink = "

The whole gallery can be also "; + return <


+
+$ziplink +
+AMEN + }, +); + +return $gal; diff --git a/example/gallery.cgi b/example/gallery.cgi new file mode 100644 index 0000000..b20d8b4 --- /dev/null +++ b/example/gallery.cgi @@ -0,0 +1,26 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use lib $ENV{'DOCUMENT_ROOT'} . "/../lib/gal/lib"; +use lib $ENV{'DOCUMENT_ROOT'} . "/../lib/perl"; +use UCW::CGI; +use UCW::CGI::ErrorHandler; +use UCW::Gallery; +use UCW::Gallery::Web::HighSlide; + +my $dir; +UCW::CGI::parse_args({ + dir => { var => \$dir, check => '^\w+(/([A-Za-z0-9][A-Za-z0-9.-]*))*$' }, +}); + +my $path = $ENV{'DOCUMENT_ROOT'} . "/../lib/photos/$dir"; +if ($dir ne "" && -f "$path/gallery.cf") { + chdir $path or die; + my $gal = UCW::Gallery->load_config(); + UCW::Gallery::Web::HighSlide->run($gal); +} else { + print STDERR "Gallery not found: $path\n"; + UCW::CGI::http_error("404 Gallery Not Found"); +} -- 2.39.2