<!DOCTYPE html
     PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<?php
$image_dir = $_REQUEST["dir"];
$dir_desc = dirname_to_desc($image_dir);

$images = new Images($image_dir);
?>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>D. Vrabel&apos;s/Photos/<?php echo $dir_desc ?></title>
  <link href="../global.css" rel="stylesheet" type="text/css"/>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
</head>

<body>
<div class="header">
<a href="..">Contents</a> / <a href=".">Photos</a> / <?php echo $dir_desc ?>
</div>

<h1><?php echo $dir_desc ?></h1>

<p>
<?php
foreach( $images->images as $im ) {
    $im_desc = filename_to_desc($im);

    printf("<a href=\"%s/%s\"><img class=\"thumbs\" src=\"%s/thumbs/%s\" alt=\"%s\" title=\"%s\"/></a>\n",
           $images->directory, rawurlencode($im),
           $images->directory, rawurlencode($im),
           $im_desc, $im_desc);
}
?>
</p>
<div style="padding: 0.15em;">
</div>

<div class="footer">
<a href="..">Contents</a> / <a href=".">Photos</a> / <?php echo $dir_desc ?>
</div>

<address>
Last updated on $Date: 2007-09-15 14:49:02 +0100 (Sat, 15 Sep 2007) $ by David Vrabel
(<a href="mailto:dvrabel@cantab.net">dvrabel@cantab.net</a>)
</address>

</body>

</html>

<?php
class Images {
    var $directory;
    var $images;

    function Images($dir)
    {
        $this->directory = $dir;
        $this->find_images();
    }

    function find_images()
    {
        $jpg_regex = ".jpg$";
        $this->images = array();

        $dir = dir( $this->directory );
        while( $fn = $dir->read() ) {
            /* Skip images that haven't be renamed yet. */
            if( ereg("imgp[[:digit:]]{4}.jpg$", $fn) ) {
                continue;
            }
            if( ereg(".jpg$", $fn) ) {
                $this->images[] = $fn;
            }
        }
        sort($this->images);
    }
}

function dirname_to_desc($fn)
{
    ereg("images/(.+)$", $fn, $regs);
    return ereg_replace("/", " - ", $regs[1]);
}

function filename_to_desc($fn)
{
    return ereg_replace("([^/]).jpg$", "\\1", $fn);
}
?>
