Subversion Repositories taios

Rev

Rev 377 | Rev 379 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

<?php

require '../_taios.php';

function getImageSizes($sourceImageFilePath,  $maxResizeWidth, $maxResizeHeight) {

    $size = getimagesize($sourceImageFilePath);
    $origWidth = $size[0];
    $origHeight = $size[1];

    $resizedWidth = $origWidth;
    $resizedHeight = $origHeight;
 
    if ($resizedWidth > $maxResizeWidth)
    {
        $aspectRatio = $maxResizeWidth / $resizedWidth;
        $resizedWidth = round($aspectRatio * $resizedWidth);
        $resizedHeight = round($aspectRatio * $resizedHeight);
    }
    if ($resizedHeight > $maxResizeHeight)
    {
        $aspectRatio = $maxResizeHeight / $resizedHeight;
        $resizedWidth = round($aspectRatio * $resizedWidth);
        $resizedHeight = round($aspectRatio * $resizedHeight);
    }
 
    return array($resizedWidth, $resizedHeight);
}

$page = new Taios_Page('Photo Albums', '../');
$page->drawHeader();
$page->drawMiddle();

$dirName = $_GET['dir'];
if (empty($dirName))
{
    $page->redirect('index.php');
}

write('<p class="bold"><a href="index.php">Back to Photos</a></p><br />');

if (file_exists("albums/" . $dirName . "/description.txt"))
{
    write('<p>' . $page->replaceBBCode(file_get_contents("albums/" . $dirName . "/description.txt")) . '</p><br />');
}

write('<table>');
write('<tr>');

$directory = "albums/" . $dirName . "/";
$sortOrder = "newestFirst";

$results = array();
$handler = opendir($directory);
   
while ($file = readdir($handler))
{
    if ($file != '.' && $file != '..' && $file != "robots.txt" && $file != ".htaccess" && getimagesize($directory . $file))
    {
           $currentModified = filectime($directory . $file);
           $file_names[] = $file;
           $file_dates[] = $currentModified;
    }    
}

closedir($handler);

if ($sortOrder == "newestFirst")
{
    arsort($file_dates);
}
else
{
    asort($file_dates);
}
   
$file_names_Array = array_keys($file_dates);
foreach ($file_names_Array as $idx => $name) $name=$file_names[$name];
$file_dates = array_merge($file_dates);
   
$i = 0;

$indexInArray = 0;
$i = 0;

foreach ($file_dates as $$file_dates)
{
    $j = $file_names_Array[$indexInArray];
    $file = $file_names[$j];
   
    if ($i >= 3)
    {
        write('</tr><tr>');
        $i = 0;
    }
   
    $filename = $directory . $file;
    $size = getImageSizes($filename, 300, 300);

    write('<td><a href="' . str_replace(" ", "%20", $filename) . '"><img width="' . $size[0] . '" height="' . $size[1] . '" src="' . str_replace(" ", "%20", $filename) . '" /></a></td>');
       
    $i++;
    $indexInArray++;
}

write('</tr>');
write('<table>');

$page->drawFooter();

?>