<?php @error_reporting (E_ALL ^ E_NOTICE);
/* --------------------------------------------------------------- *
* USER SETTINGS
* --------------------------------------------------------------- */
/*
** PAGE TITLE (text string)
**
** will appear at the top of the page
**
**/
$page_title = "Picture Gallery";
/*
** Upper CONTENT (text string)
**
** Link, description, graphic, etc - will appear in upper
**
**/
$go_back = "<a href= \" \">Back</a>";
//$right_content = "";
$image_dir = "images";
$next_photo = "Next Photo >";
$prev_photo = "< Previous Photo";
$use_gifs = true;
$columns = 5;
//$image = array( "image_1", "image_2", "image_3");
?>
<style type="text/css" media="all">
<!--
.phppgtitleband { /* table, holds $page_title, $left_content, $right_content */
margin:10px auto 0 auto;
padding:0;
background-color: #EEE;
border: 1px solid #CCC;
width: 100%;
font-size: 90%;
}
.phppgtitleband td {
width:33%;
padding: 5px;
}
.phppgmainbox { /* holds next/prev links and main image */
margin:10px auto 0 auto;
padding:0;
min-height:400px;
}
.phppgnextbox { /* holds next and previous links */
margin-bottom:5px;
padding:0;
text-align:center;
}
.phppgimagebox { /* table, holds main image */
margin:0 auto 0 auto;
padding:0;
}
.phppgimageframe { /* frame around main image */
width: auto;
border: 1px solid #CCC;
background-color: #EEE;
padding: 15px 15px 40px 15px;
}
.phppgimagetag { /* main image's img tag style */
border: 1px solid #CCC;
}
.phppggifbox { /* table style that holds gif thumbnail's */
margin:10px auto 0 auto;
padding:0;
border-collapse:collapse;
}
.phppggifbox td {
padding: 5px;
border:1px solid #999;
border-collapse:collapse;
text-align:center;
vertical-align:middle;
}
-->
</style>
<?php
/* --------------------------------------------------------------- *
* DO NOT EDIT BELOW THIS LINE
* --------------------------------------------------------------- */
if (!headers_sent()) {
print("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"\n");
print(" \"http://www.w3.org/TR/html4/loose.dtd\">\n");
print("<html>\n");
print("<head>\n");
print(" <meta http-equiv=\"content-type\" content=\"text/html; charset=iso-8859-1\">\n");
print(" <title>Photo Gallery</title>\n");
print("</head>\n");
print("<body>\n");
$print_footer = TRUE;
} else {
$print_footer = FALSE;
}
/* --------------------------------------------------------------- *
* SETUP, DEFAULTS, and CHECK SETTINGS
* --------------------------------------------------------------- */
$view = (isset($_REQUEST['view'])) ? $_REQUEST['view'] : "";
// Check Setup
if (!isset($image_dir) || !$image_dir) {
die("Setup Error:<br>The variable <b>\$image_dir</b> (in the 'USER SETTING' section) is not set.");
}
if (($image_dir[strlen($image_dir) - 1] == "/") || ($image_dir[strlen($image_dir) - 1] == "\\")) {
die("Setup Error:<br>The variable <b>\$image_dir</b> (in the 'USER SETTING' section) should <b>not</b> end with a slash");
}
if (!is_dir($image_dir)) {
die("Setup Error:<br>The variable <b>\$image_dir</b> (in the 'USER SETTING' section) must be a directory.");
}
// Read all files in $image_dir
if (!isset($image)) {
$image = phppg_recursive_listdir($image_dir);
} else {
array_walk ($image, 'phppg_add_image_dir');
}
if (!is_array($image) || !count($image)) {
die("Setup Error:<br>There are no files in the image directory. You specify this direcory in the 'USER SETTINGS' secion as \$image_dir.");
}
// SECURITY CHECK
// Requested $view must contain the REAL PATH of '$image_dir'
if ($view) {
$image_dir_path = realpath($_SERVER['DOCUMENT_ROOT'] . dirname($_SERVER['PHP_SELF']) . "/" . $image_dir); // REALPATH to user specified image directory
$view_dir_path = dirname(realpath($_SERVER['DOCUMENT_ROOT'] . dirname($_SERVER['PHP_SELF']) . "/" . $view . ".jpg")); // REALPATH to the file we're supposed to be viewing
if (!$image_dir_path || !$view_dir_path || !stristr($view_dir_path, $image_dir_path)) {
die("BAD REQUEST<br>Please <a href=\"" . $_SERVER['PHP_SELF'] . "\">go back</a> and request another image");
}
}
// Remove ".gif" and ".jpg" extensions - only show unique images
array_walk ($image, 'phppg_remove_extension');
$temp_image = array_unique($image);
$image = array();
$i = 0;
foreach ($temp_image as $v) { /* reset array keys */
$image[$i] = $v;
$i++;
}
// Defaults
if (!isset($columns) || !(int) $columns) $columns = 4;
if (!isset($view) || !$view) $view = $image[0];
if (!isset($next_photo) || !$next_photo) $next_photo = "Next Photo";
if (!isset($page_title)) $page_title = "";
if (!isset($left_content)) $left_content = "";
if (!isset($right_content)) $right_content = "";
if (!isset($use_gifs)) $use_gifs = false;
/* --------------------------------------------------------------- *
* TOP NAV AND TITLE
* --------------------------------------------------------------- */
if ($page_title || $left_content || $right_content) {
?>
<title>Picture Gallery</title>
<table width="800" align="center" height="20">
<tr>
<td align="center"><a href="photos/pics.html"><strong><?php echo $go_back; ?></strong></a>
</td>
</tr>
</table>
<table class="phppgtitleband" width="800" align="center">
<tr>
<td style="text-align:center;" width="800"><?php echo $page_title; ?></td>
</tr>
</table>
<?php
}
/* --------------------------------------------------------------- *
* DISPLAY - large JPEG IMAGE
* --------------------------------------------------------------- */
//if ($view && (file_exists($image_path . $view . ".jpg"))) {
if ($view && (file_exists($view . ".jpg"))) {
$currKey = array_keys ($image, $view);
$nextKey = $currKey[0] + 1;
$prevKey = $currKey[0] - 1;
if (!array_key_exists($nextKey, $image)) $nextKey = 0;
if (!array_key_exists($prevKey, $image)) $prevKey = (count($image) - 1);
?>
<div class="phppgmainbox">
<!-- NEXT / PREV LINKS -->
<?php if ($prev_photo || $next_photo) { ?>
<div class="phppgnextbox">
<?php if ($prev_photo) { ?>
<a href="<?php echo $_SERVER['photos/PHP_SELF'] . "?view=" . $image[$prevKey]; ?>"><?php echo $prev_photo; ?></a>
<?php } ?>
<?php if ($next_photo) { ?>
<a href="<?php echo $_SERVER['photos/PHP_SELF'] . "?view=" . $image[$nextKey]; ?>"><?php echo $next_photo; ?></a>
<?php } ?>
</div>
<?php } ?>
<!-- MAIN PHOTO -->
<table class="phppgimagebox"><tr><td>
<div class="phppgimageframe">
<img src="<?php echo $view; ?>.jpg" alt="" class="phppgimagetag">
</div>
</td></tr></table>
</div>
<?php
}
/* --------------------------------------------------------------- *
* DISPLAY - thumnail GIFs
* --------------------------------------------------------------- */
if ($use_gifs) {
?>
<table class="phppggifbox">
<tr>
<?php
$i = 0;
if (!((int) $columns)) {
$columns = 4;
}
foreach($image as $v) {
($i % $columns) ? $row = FALSE : $row = TRUE;
if ($i && $row) {
print("\t</tr>\n");
print("\t<tr>\n");
}
?>
<td><a href="<?php echo $_SERVER['photos/PHP_SELF'] . "?view=" . $v ?>"><img src="<?php echo $v ?>.gif" alt="" border="1"></a></td>
<?php
$i++;
}
?>
</tr>
</table>
<?php
}
/* --------------------------------------------------------------- *
* FUNCTIONS
* --------------------------------------------------------------- */
function phppg_remove_extension(&$value, $key) {
$value = preg_replace(array("/.gif/i", "/.jpg/i"), "", $value);
}
function phppg_add_image_dir(&$value, $key) {
global $image_dir;
$value = $image_dir . "/" . $value;
}
/**
** array phppg_recursive_listdir( (string) base)
**
** Recursively looks through a directory and returns all items as an array
**
** @param base (string) base
**
*/
function phppg_recursive_listdir($base) {
static $filelist = array();
static $dirlist = array();
if(is_dir($base)) {
$dh = opendir($base);
while (false !== ($dir = readdir($dh))) {
if (is_dir($base ."/". $dir) && $dir !== '.' && $dir !== '..') {
$subbase = $base ."/". $dir;
$dirlist[] = $subbase;
$subdirlist = phppg_recursive_listdir($subbase);
} elseif(is_file($base ."/". $dir) && $dir !== '.' && $dir !== '..') {
$filelist[] = $base ."/". $dir;
//$filelist[] = $dir;
}
}
closedir($dh);
}
@sort($dirlist);
@sort($filelist);
$array['dirs'] = $dirlist;
$array['files'] = $filelist;
//return $array;
return $filelist;
}
if ($print_footer) {
print("</body>\n");
print("</html>\n");
}
?>