<?php

  
// miniGallery - to make a quick and dirty gallery.

  // Number of pictures per page
  
$page_size=20;

  
// Pictures to display per row
  
$rows_horizontal=5;

  
// Directory which contains your images
  
$img_dir="images";

  
// Directory which contains your thumbnails
  
$thmb_dir="thumbnails";

  
// Title to display above every page (set to NULL for none)
  
$title="title goes here";

  
// Text between name and extension in thumbnail names (set to NULL for none)
  // example: $thmb_ext="_t";
  
$thmb_ext NULL;

  
// You should not have to configure any settings beyond this point!
  //**********************************************************************\\
  // CHANGELOG:
  //
  // v0.1 alpha:
  //   * inital version
  //
  // v0.1 beta:
  //   * added first and last page links
  //   * added checks for page skipping
  //   * added comments to the code ;)
  //
  // v0.1:
  //   * added support for thumbnails with leading chars
  //
  // v0.2
  //   * fixed a bug that would display an empty page as last
  //     page if the last page was exactly filled.
  //
  // v0.3
  //   * added counter so you can see what page you're at.
  //
  // v0.3.1
  //   * added total to the counter so you can see how much is left
  //   * counter was off by one.

?>

<html>
  <head>
    <style type="text/css">

      body {
        font-family: verdana, arial, sans;
        background-color:#000000;
        color:#ffffff;
      }

      img { border: 1px solid #555555; }

      h1 {
        background-color:#555555;
        color:#ffffff;
        font-size:35px;
      }

      a {
        text-decoration:none;
        color:#ff0000;
      }

      #spacer { margin-left:200px; }

    </style>
  </head>
  <body><center>

<?php

  
// first print the title of the gallery
  
print("<h1>$title</h1>\n");

  
// determine if we're skipping pages, if not set to 0
  
if(isset($_GET['skip'])) {
    
$skip=$_GET['skip'];
    if(
$skip<0$skip=0;
  } else 
$skip=0;

  
// read all files from the $img_dir and remove the . and ..
  // also precaclulate the number of files so we do this only once
  
$files array_slice(scandir($img_dir), 2);
  
$dir_size count($files);

  
// calculate what the highest $skip should be for the last page
  
$last_page $dir_size-(($dir_size-$page_size)%$page_size);
  if(
$last_page == $dir_size$last_page -= $page_size;

  
// and stop clowns from entering high numbers
  
if($skip>$last_page$skip $last_page;

  
// also stop people from entering random numbers and screwing up the page layout
  
if(($skip%$page_size)>0$skip $skip-($skip%$page_size);

  
// start displaying images, skipping the first pages and
  // not trying to display more than we have
  
for($i=$skip$i<$dir_size && ($i-$skip)<$page_size$i++) {
    
$img_name $files[$i];
    if(
thmb_ext != "") {
      
$thmb_name ereg_replace('(.*)\.(.*)''\1'.$thmb_ext.'.\2'$img_name);
    } else 
$thmb_name $img_name;
    print(
'<a href="'.$img_dir.'/'.$img_name.'">');
    print(
'<img src="'.$thmb_dir.'/'.$thmb_name.'"></a>');

    
// should we hit the end of a row then print line feeds
    
if(($i+1)%$rows_horizontal==|| ($i+1)==$dir_size) print('<br/><br/>');
    print(
"\n");
  } 
  print(
'<br/>'.($skip+1).'-'.($i).' / '.($dir_size));
  print(
"<br/>\n");

  
// if we've skipped pages then print the link to get back and
  // one to skip to the beginning
  
if($skip>0){
    print(
'<a href="?skip=0">|&lt;&lt;&nbsp;&nbsp;</a>');
    print(
'<a href="?skip='.($skip-$page_size).'">&lt;back</a>'."\n");

    
// make sure there's some space between the back and next links
    // only needed if there is actually a next page.
    
if($i<$dir_size){
      print(
'<span id="spacer"/>'."\n");
    }
  }

  
// if there are still more pages to come then display a link to get there
  // and also print one to skip to the end
  
if($i<$dir_size){
    print(
'<a href="?skip='.$i.'">next&gt;</a>');
    print(
'&nbsp;&nbsp;<a href="?skip='.$last_page.'">&gt;&gt;|</a>'."\n");
  }

?>

  <br/><br/><a href="index.phps">miniGallery</a> v0.3.1 - Mattijs Vreeling 2007<br/>
  </center></body>
</html>