<?php

// Slideshow v1.1 by Justin Blanton (justin@justinblanton.com)
// Last modified 07.04.2007

/*******************************************************************************
                                    INSTALL
 *******************************************************************************

 1.) Create a directory of pictures numbered sequentially (i.e., 00.jpg, 01.jpg,
     etc., or any other naming scheme that specifies the order in which you want
     the images to appear).
 2.) Create a text file and on the first line put the title of the slideshow for
     this particular directory of pictures.  Name the file "title.txt" and 
     place it in the directory containing the pictures.
 3.) Modify the HTML in slideshow.php.txt; see below.
 4.) Rename slideshow.phps to slideshow.php and place it in the directory
     containing the pictures.
 5.) Point to slideshow.php from a web browser.
     
 *******************************************************************************
                                MODIFY YOUR HTML
 *******************************************************************************
 
 You'll want to use your own markup in the "PRINT HTML" section (see below) so 
 that it corresponds to your site design preferences.  I've left my actual
 template intact so that you can see how easy it is to make the necessary 
 changes.  It should be fairly simple to figure out the variables used in the
 markup and their meanings, but I'm going to list them here just in case
 someone is confused:
 
    $title    = the title of the slideshow (found in title.txt; see above)
    $num_pics = the total number of images in the current directory
    $photos   = array containing the names of the images
    $image    = index into photos array
    $prev     = the previous displayed image
    $next     = the next image to be displayed
                also used to specify the number of the current image displayed
    
 *******************************************************************************
                                  CODE SECTION
 ******************************************************************************/


$image $_GET[image];

// look for picture files in current directory and add them to photos array
$current_dir opendir(".");
while (
$file readdir($current_dir)) {
    if (
eregi("(\.jpg|\.gif|\.png)$"$file)) $photos[] = $file;
}
closedir($current_dir);

// check to see if images were found in directory; if no images were found,
// alert user through $title on webpage
if ($photos == null$title "There are no pictures in this directory!  ";
// images were found; sort them
else sort($photos);

// read title of slideshow from title.txt
if (file_exists('title.txt')) { 
    
$title_file file('title.txt'); 
    
$title $title.$title_file[0];
}
// no title.txt file was found; alert user through $title on webpage
else $title $title."You did not supply a title.txt file!";
   
// get total number of pictures 
$num_pics count($photos);

// if image number is not specified, set it to the first image
if (empty($image)) $image '0';

// if user is on the last image or if the image number specified is greater than
// the number of pics available in the directory, start user at first image
if (($image == $num_pics) || ($image $num_pics)) $image '0';

// setup the link for the next image
$next $image 1;

// setup the link for the previous image
if ($image == '0'$prev $num_pics 1;
else 
$prev $image 1;

/*******************************************************************************
                                   PRINT HTML
 ******************************************************************************/

print <<< PRINT_PAGE
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<link rel="stylesheet" type="text/css" media="screen" href="http://justinblanton.com/screen.css" />
<link rel="alternate" type="application/rss+xml" title="RSS" href="http://justinblanton.com/syndicate/" />
<meta name="description" content="life. technology. politics." />
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<meta http-equiv="Content-Language" content="en-us" />
<title>Justin Blanton | Photos | $title</title>
</head>
<body>
<div id="container">
<div id="photos">
<h3>$title <span class="tiny">($next of $num_pics)</span></h3>
<a href="?image=$next"><img src="$photos
[$image]"></a>
<br />
<p><a href="?image=$prev">&laquo; prev</a> &middot; <a href="?image=0">photos home</a> &middot; <a href="?image=$next">next &raquo;</a></p>
</div>
</div>
</body>
</html>
PRINT_PAGE;
?>