<?
/*
Template Name: Desktops
*/
?>


<?
/*    Please Note:
    This file contains snippets. You must still know where to put them.
    I've split them up where possible, but be smart, ok?

    
    License:
    This code is copyright © 2007 Aaron Linville and Erik J. Barzeski.
    The right to re-use or re-purpose this code for your own use is granted
    so long as reasonable credit is given to the original authors, including
    a link to <http://nslog.com/desktops/resizer>. In other words, use it all
    you want, but be so kind as to give some credit.
*/ 
?>


<head>

<!-- Lightbox Code -->
<script type="text/javascript" src="/lightbox/js/prototype.js"></script>
<script type="text/javascript" src="/lightbox/js/scriptaculous.js?load=effects"></script>
<script type="text/javascript" src="/lightbox/js/lightbox.js"></script>
<link rel="stylesheet" href="/lightbox/css/lightbox.css" type="text/css" media="screen" />


<style type="text/css">
div.desktop
{
    float: left;
    margin: 0 20px 0 0;
    padding: 0;
    width: 152px;
    height: 200px;
    text-align: center;
}

div.desktop img
{
    float: left;
    border: 1px solid #000;
    margin: 0;
    padding: 0;
}

div#size
{
    width: 100%;
    border: 1px solid #9c9;
    background: #efe;
    display: block;
    float: left;
}

div#size form input, div#size form span
{
    font-size: x-large;
    color: #333;
}

div#size form
{
    margin: 10px;
    padding: 0px;
}
</style>

<script language="javascript">
function processDownload(filename)
{
    if(downloadForm.height.value >= 600 && downloadForm.width.value >= 800)
    {
        downloadForm.image.value=filename;
        downloadForm.submit();
    }
    else
    {
        alert('Please fill out an appropriate image height and width.');
        var sizeBox = document.getElementById("size");
        sizeBox.style.border = "1px solid #f00";
        sizeBox.style.background = "#fcc";
    }
    return;
}
</script>



</head>

















<body>



<div id="size">

<!-- "_desktops" is the directory on my server which houses my desktops -->

<form method="GET" action="/_desktops/downloader.php" name="downloadForm">
Width: <input name="width" type="text" size="6" value="1920" />
Height: <input name="height" type="text" size="6" value="1200" />    <input type="hidden" value="" name="image" />
</form>
</div>

<?
    $filter 
'.jpg';

    
// Builds a list of previews based on files in a directory
    
$path "/path/to/previews/desktops/folder";
    
$dir_handle = @opendir($path) or die("Unable to open '$path'");

    
$imageList = array();

    while (
false !== ($file readdir($dir_handle)))
    {
        
// Hide up and current directories as well as files that start with "-"
        
if($file != "." && $file != ".." && $file[0] != "-")
        {
            
$imageList[] = str_replace('.jpg'''$file);
        }
    }
    
    
sort($imageList);
    
    for(
$i=0$i<count($imageList); $i++)
    {
        
$img $imageList[$i];
?>

<div class="desktop">
<p><strong><?=$img;?></strong><br />
<a href="/_desktops/preview/<?=$img;?>.jpg" rel="lightbox" title="<?=$img;?>"><img src="/_desktops/thumb/<?=$img;?>.jpg" height="112" width="150" />
Preview</a> | <a href="#" onClick="processDownload('<?=$img;?>');" title="Download <?=$img;?>">Download</a></p>
</div>

<? ?>