<div id="gallery">

<?php
// Penguin Gallery http://www.penguintutor.com/penguingallery 
// Copyright 2009 Stewart Watkiss
/*  
	This file is a part of Penguin Gallery

	Penguin Gallery 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 3 of the License, or
    (at your option) any later version.

    Penguin Gallery 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 Penguin Gallery.  If not, see <http://www.gnu.org/licenses/>.
*/


// This is a container php script that calls the other components - note that the setup code must be run first
// As it creates variables / arrays that are referenced by the subsequent components

if (defined('__DIR__')) {
	$galleryphpdir = __DIR__;
    }
    else {
        $galleryphpdir = dirname(__FILE__);
    }
$galleryphpdir .= "/";

// what gallery are we viewing - config file must match galleryname with .cfg
$galleryname = trim($_GET[galleryname]);
if ($galleryname == "") {$galleryname = "index";}
if (!preg_match('/^[\w-\/]+$/', $galleryname)) {echo "<p>Gallery name contains invalid characters. $galleryname</p>"; exit(2);} 


// **** temporary - for now if index selected then we embed galleryindex.php into the file
// In future we will generate the preview index page
if ($galleryname == "index")
{
	include ($_SERVER['DOCUMENT_ROOT']."/galleryindex.php");
	exit (0);
}


$galleryconfigfile = $galleryname.".cfg";

// Check no . in the configfile other than .cfg (security check)
if (!preg_match ('/^[\w-\/]+\.cfg$/', $galleryconfigfile))
{
	echo "<p>Invalid configuration filename $galleryconfigfile - view PenguinGallery documentation for more details.</p></div>";
	return;
}

/*// Give galleryconfigfile full path don't change - otherwise add path to url
if (!preg_match ("/^\//", $galleryconfigfile))
{
	//$path = $_SERVER['SCRIPT_NAME'];
	// Add path from url to make this absolute path
	$urlpath = $_SERVER['PHP_SELF'];
	// strip out the filename bit - must end .php (could add alternatives in the match - or even allow more generic anything past last /)
	$urlpath = preg_replace ('/\/[\w-]+\.php$/', '', $urlpath);
	$galleryconfigfile = $urlpath."/".$galleryconfigfile;
}*/

//echo "<p>Config file $galleryconfigfile</p></div>";
//return;

// Setup variables based on files in folder
include ($galleryphpdir."gallerysetup.php");
// Show the main image
include ($galleryphpdir."galleryimg.php");
// Add the navigation bars
include ($galleryphpdir."gallerynav.php");
// Show thumbnails for other images (optional if slideshow only required)
include ($galleryphpdir."gallerythumb.php");
?>

</div>

<div id="galleryabout"><p><a href="http://www.penguintutor.com/penguingallery">Powered by PenguinGallery</a></div>
