Skip to content

Instantly share code, notes, and snippets.

@kwylez
Created February 3, 2011 16:16
Show Gist options
  • Save kwylez/809702 to your computer and use it in GitHub Desktop.
Save kwylez/809702 to your computer and use it in GitHub Desktop.
<?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