Created
February 3, 2011 16:16
-
-
Save kwylez/809702 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once 'Zend/Loader/Autoloader.php'; | |
Zend_Loader_Autoloader::getInstance(); | |
$response = array(); | |
$jsonResponse = ''; | |
$gallery = ''; | |
$galleryImages = array(); | |
$galleryDirectories = array(); | |
$galleryRoot = "./gallery"; | |
$pathToSmallImages = ''; | |
$pathToMediumImages = ''; | |
$pathToLargeImages = ''; | |
$pathToThumbnailImage = ''; | |
$queryParamFilterChain = new Zend_Filter(); | |
$queryParamFilterChain->addFilter(new Zend_Filter_HtmlEntities()) | |
->addFilter(new Zend_Filter_StripTags()); | |
$gallery = $queryParamFilterChain->filter($_GET['gallery']); | |
$pathToSmallImages = "{$galleryRoot}/{$gallery}/small"; | |
$pathToMediumImages = "{$galleryRoot}/{$gallery}/medium"; | |
$pathToLargeImages = "{$galleryRoot}/{$gallery}/large"; | |
$pathToThumbnailImage = "{$galleryRoot}/{$gallery}/thumb"; | |
function compareFileName($a, $b) { | |
return strnatcmp($a['name'], $b['name']); | |
} | |
foreach (new DirectoryIterator(realpath($galleryRoot)) as $info) { | |
if ($info->isDot()) { continue; } | |
if ($info->isDir()) { | |
$dirs[] = $info->getFilename(); | |
} | |
} | |
if (in_array($gallery, $dirs)) { | |
$it = new DirectoryIterator(realpath($pathToThumbnailImage)); | |
foreach ($it as $info) { | |
if ($info->isDot()) { continue; } | |
if ($info->isFile()) { | |
$width = 0; | |
$height = 0; | |
$imgSize = getimagesize('/full/system/path/'.$pathToMediumImages.'/'.$info->getFilename()); | |
$width = $imgSize[0]; | |
$height = $imgSize[1]; | |
$galleryImages[] = array('name' => $info->getFilename(), 'width' => $width, 'height' => $height); | |
} | |
} | |
usort($galleryImages, 'compareFileName'); | |
$response = array('total' => count($galleryImages), | |
'thumbnailPath' => $pathToThumbnailImage, | |
'smallPath' => $pathToSmallImages, | |
'mediumPath' => $pathToMediumImages, | |
'largePath' => $pathToLargeImages, | |
'images' => $galleryImages); | |
} else { | |
$response = array('total' => '0'); | |
} | |
header('Content-type: application/json; charset=utf-8'); | |
print Zend_Json::encode($response); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment