]> mj.ucw.cz Git - gallery.git/commitdiff
Added an example web front-end
authorMartin Mares <mj@ucw.cz>
Sun, 8 Feb 2015 20:49:54 +0000 (21:49 +0100)
committerMartin Mares <mj@ucw.cz>
Sun, 8 Feb 2015 20:49:54 +0000 (21:49 +0100)
README
example/.htaccess [new file with mode: 0644]
example/README [new file with mode: 0644]
example/default.cf [new file with mode: 0644]
example/gallery.cgi [new file with mode: 0644]

diff --git a/README b/README
index 0a5d7c7a4c7b6bc281c05170992afab121ee8677..0aed6db7681369f480cdf7f787a11cde2ce82975 100644 (file)
--- 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 (file)
index 0000000..aa29d40
--- /dev/null
@@ -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 (file)
index 0000000..8835637
--- /dev/null
@@ -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 (file)
index 0000000..a43f20c
--- /dev/null
@@ -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 => "<link rel=stylesheet href='/mj.css' type='text/css' media=all>\n",
+       WebBotExtras => sub ($) {
+               my ($self) = @_;
+               return "" if $self->showing_image;
+               my $ziplink = "<p>The whole gallery can be also <button class=gal-zip type=submit name=a value=zip>downloaded as a ZIP archive.</button>";
+               return <<AMEN ;
+<div class=gal-bottom><p class=gal-sep><hr>
+<form action='.' method=POST>
+$ziplink
+</form></div>
+AMEN
+       },
+);
+
+return $gal;
diff --git a/example/gallery.cgi b/example/gallery.cgi
new file mode 100644 (file)
index 0000000..b20d8b4
--- /dev/null
@@ -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");
+}