Skip to content

Instantly share code, notes, and snippets.

@delonnewman
Created July 29, 2009 10:31
Show Gist options
  • Save delonnewman/157970 to your computer and use it in GitHub Desktop.
Save delonnewman/157970 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl -wT
#-*- Mode: perl; -*-
########################################################################
#
# Description:
# This is a front end for Original v0.3 written by Jimmac & Tigert.
# It can be used with mod_perl or just drop it in your cgi-bin
# directory.
#
# Type "perldoc image_viewer.pl" at your command line for more info.
#
# Author: Delon Newman <delonn@earthlink.net>
#
# Copyright (C) 2001 Delon Newman
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of the
# License, or (at your option) any later version.
#
# This script is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this library; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
########################################################################
use strict;
use CGI qw(:standard);
use CGI::Carp;
$|++;
# "Globals"
my $ROOT_DIR = '/var/www/html';
my $ROOT_HTML = '/';
my $IMG_DIR = "$ROOT_DIR/img";
my $IMG_URL = '/img';
$0 = 'image_viewer.pl';
# Theme Defaults
my $left_button = "$IMG_URL/pics/left.png";
my $right_button = "$IMG_URL/pics/right.png";
my $top_button = "$IMG_URL/pics/top.png";
# HTML
my $body = '<body bgcolor="#ffffff">';
my $SCRIPTS = '<script language="JavaScript">
function showhide() {
var args;
args = showhide.arguments;
if (document.getElementById(args[0]).style.display=="block") {
document.getElementById(args[0]).style.display = "none";
} else {
document.getElementById(args[0]).style.display = "block";
}
}//End function
</script>';
# Parameters
my ( $gallery, $page ) = undef;
$gallery = param('gallery'); # the name of a dirctory in $iMG_DIR
$page = param('page'); # page number or 'index'
print "Content-type: text/html\n\n";
# Print custom gallery top if avalile.
if ( -e "$IMG_DIR/gallery-top.html" ) {
open( TOP, "$IMG_DIR/gallery-top.html" ) or
warn "Cannot open $IMG_DIR/gallery-top.html: $!";
print <TOP>;
}
# Print "Original" default if custom not there.
else {
print "<html><head><title>Image Galleries</title><meta name=\"MSSmartTagsPreventParsing\" content=\"TRUE\"><link rel=\"stylesheet\" href=\"css/gallery.css\">", $SCRIPTS, '</head>', $body;
}
if ( $page eq '' and $gallery eq '' ) { view_gallery_list() }
elsif ( $page eq 'index' or $page eq '' ) { view_gallery_index($gallery) }
else { view_gallery_image($gallery, $page) }
# Print custom gallery bottom if avalile.
if ( -e "$IMG_DIR/gallery-bottom.html" ) {
open( BOTTOM, "$IMG_DIR/gallery-bottom.html" ) or
warn "Cannot open $IMG_DIR/gallery-bottom.html: $!";
print <BOTTOM>;
}
# Print "Original" default if custom not there.
else { print end_html }
# View a list of galleries in img directory
sub view_gallery_list {
chdir($IMG_DIR);
my @galleries = <*>;
my @html;
#print i('image_viewer2');
print h1("Image Galleries"), '<div class="navigation"><ul>';
foreach my $gallery (@galleries) {
if ( -e "$IMG_DIR/$gallery" &&
-e "$IMG_DIR/$gallery/thumbs" &&
-e "$IMG_DIR/$gallery/lq" &&
-e "$IMG_DIR/$gallery/hq" &&
-e "$IMG_DIR/$gallery/comments" ) {
print li(a({ -href => "/$0\?gallery\=$gallery" },
"\u$gallery" ) ,' - Last Modified: ',
int(-M "$IMG_DIR/$gallery"), ' day(s) ago' );
}
else { next }
}
print '</ul></div><p class="copyright">Generated by <em><a href="http://jimmac.musichall.cz/original.php3">Original</a> ver. 0.3</em></p>';
#return \@html;
}
# View index page in gallery mode
sub view_gallery_index {
my $gallery = shift;
my @html = ();
my $thumb_dir = "$IMG_DIR/$gallery/thumbs";
my @images = <$thumb_dir/*>;
#print $body;
#print i('image_viewer2');
print h1("\u$gallery Gallery");
# Print Navigation Bar ( one link to main section )
print p({ -class => 'navigation' }, '[',
a({ href => "/$0" }, 'back to index'), ']'),'<p>';
# Print thumbnail gallery
if ( -e "$IMG_DIR/$gallery" &&
-e "$IMG_DIR/$gallery/thumbs" &&
-e "$IMG_DIR/$gallery/lq" &&
-e "$IMG_DIR/$gallery/hq" &&
-e "$IMG_DIR/$gallery/comments" ) {
for ( my $i = 1; $i <= int(@images); $i++ ) {
print a({ -href => "/$0?gallery=$gallery&page=$i" },
img({ -src => "/img/$gallery/thumbs/img\-$i\.png",
-alt => "image No. $i", -border => '0', -class => "gallery" }));
}
}
elsif ( !(-e "$IMG_DIR/$gallery") ) {
print "<b>Error:</b> No such file or directory: <b>$IMG_DIR/$gallery</b><br>";
}
else {
print "<b>Error:</b> Bad input in directory: <b>$IMG_DIR/$gallery</b><br>";
}
print '</p><p class="copyright">Generated by <em><a href="http://jimmac.musichall.cz/original.php3">Original</a> ver. 0.3</em></p>';
#return \@html;
}
# View n image in gallery mode
sub view_gallery_image {
my $gallery = shift;
my $image_num = shift;
#my @html = ();
my ( $next_image, $prev_image ) = undef;
my @images = <$IMG_DIR/$gallery/thumbs/*>;
if ( $image_num == 1 ){
$prev_image = int(@images);
$next_image = $image_num + 1;
}
elsif ( $image_num == int(@images) ) {
$next_image = 1;
$prev_image = $image_num - 1;
}
elsif ( $image_num > int(@images) ) {
$image_num = 1;
$prev_image = int(@images);
$next_image = $image_num + 1;
} else {
$next_image = $image_num + 1;
$prev_image = $image_num - 1;
}
open ( COMMENT, "$IMG_DIR/$gallery/comments/$image_num\.txt" ) or
warn "Cannot open comment file $image_num\.txt: $!";
my $comment = <COMMENT>;
my $images = int(@images);
# Print Image Page
#print $body;
#print i('image_viewer2');
print h1("\u$gallery Gallery");
# Print Navigation Bar
print p({ -class => 'navigation' },
a({ -href => "/$0?gallery=$gallery&page=$prev_image" },
img({ -src => "$IMG_URL/pics/left.png", -alt => '<', -border => '0'}) ),
a({ -href => "/$0?gallery=$gallery" },
img({ -src => "$IMG_URL/pics/top.png", -alt => '^', -border => '0' }) ),
a({ -href => "/$0?gallery=$gallery&page=$next_image" },
img({ -src => "$IMG_URL/pics/right.png", -alt => '>', -border => '0' }) ));
# Print Image
print table({ -width => '640', -border => '0', -align => 'center' },
Tr(td(img({ -src => "/img/$gallery/lq/img\-$image_num\.jpg",
-alt => $image_num, -class => "gallery" }),
p({ -class => 'comment' }, span($comment)),
p(a({ -href => "/img/$gallery/mq/img\-$image_num\.jpg" }, 'MQ&nbsp;' ),
a({ -href => "/img/$gallery/hq/img\-$image_num\.jpg" }, 'HQ' )))));
# Print Navigation Bar
print p({ -class => 'navigation' },
a({ -href => "/$0?gallery=$gallery&page=$prev_image" },
img({ -src => "$IMG_URL/pics/left.png", -alt => '<', -border => '0' }) ),
a({ -href => "/$0?gallery=$gallery" },
img({ -src => "$IMG_URL/pics/top.png", -alt => '^', -border => '0' }) ),
a({ -href => "/$0?gallery=$gallery&page=$next_image" },
img({ -src => "$IMG_URL/pics/right.png", -alt => '>', -border => '0'}) )),
'<p class="copyright">Generated by <em><a href="http://jimmac.musichall.cz/original.php3">Original</a> ver. 0.3</em></p>';
#return \@html;
}
=head1 NAME
Image Viewer - A front end to Original v0.3
=head1 SYNOPSIS
image_viewer.pl
image_viewer.pl?gallery=New-Photos
image_viewer.pl?gallery=New-Photos&page=3
=head1 DESCRIPTION
This is a front end for Original v0.3 written by Jimmac & Tigert. It can be used with mod_perl or as a regular cgi program. It depends on galleries generated by Original you can find it at Jimmac's site: http://hideout.net/original.php3. In the Original package you will find a shell script as well as a Nautilus script. For instructions on how to use these see the README file. Generate your gallery then place the gallery in the path indicated by the $IMG_DIR variable in the image_viewer.pl script. The default is "/var/www/html/img". Place image_viewer.pl in your root directory or cgi-bin dirctory, now the script is useable, you can execute it by entering:
http://[Your domain here]/image_viewer.pl
or
http://[Your domain here]/cgi-bin/image_viewer.pl
into the location bar of your web browser. This will display a list of the galleries in your directory as links. If you would like to access a given gallery directly, add ?gallery=[given gallery] to your URL.
=head1 COPYRIGHT
Copyright 2001 Delon Newman.
This program is free software; you can redistribute it and/or modify it under the terms of the GPL.
=head1 AUTHOR
Written by Delon Newman <delonn@earthlink.net>
=cut
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment