/**
* render
*
* @since 2.6.0
*
* @param string $directory
* @param array $options
*
* @return string
*/
public static function render($directory = null, $options = null)
{
$output = null;
$outputItem = null;
/* html elements */
$imageElement = new Html\Element();
$imageElement->init('img', array('class' => self::$_config['className']['image']));
$linkElement = new Html\Element();
$linkElement->init('a');
$listElement = new Html\Element();
$listElement->init('ul', array('class' => self::$_config['className']['list']));
/* gallery directory */
$galleryDirectory = new Directory();
$galleryDirectory->init($directory, self::$_config['thumbDirectory']);
$galleryDirectoryArray = $galleryDirectory->getArray();
/* adjust order */
if ($options['order'] === 'desc') {
$galleryDirectoryArray = array_reverse($galleryDirectoryArray);
}
/* gallery data */
$galleryCounter = 0;
$galleryTotal = count($galleryDirectoryArray);
$galleryId = uniqid('gallery-');
/* remove thumbs */
if ($options['command'] === 'remove' || !$galleryTotal) {
$galleryDirectory->remove(self::$_config['thumbDirectory']);
} else {
/* process directory */
foreach ($galleryDirectoryArray as $key => $value) {
$imagePath = $directory . '/' . $value;
$thumbPath = $directory . '/' . self::$_config['thumbDirectory'] . '/' . $value;
/* create thumbs */
if ($options['command'] === 'create' || !is_file($thumbPath)) {
self::_createThumb($value, $directory, $options);
}
/* image data */
$imageData = self::_getImageData($imagePath);
/* collect item output */
$outputItem .= '<li>';
$outputItem .= $linkElement->copy()->attr(array('href' => $imagePath, 'data-counter' => ++$galleryCounter, 'data-total' => $galleryTotal, 'data-id' => $galleryId, 'data-artist' => array_key_exists('artist', $imageData) ? $imageData['artist'] : null, 'data-date' => array_key_exists('date', $imageData) ? $imageData['date'] : null, 'data-description' => array_key_exists('description', $imageData) ? $imageData['description'] : null))->html($imageElement->copy()->attr(array('src' => $thumbPath, 'alt' => array_key_exists('description', $imageData) ? $imageData['description'] : null)));
$outputItem .= '</li>';
}
$output = $listElement->attr('id', $galleryId)->html($outputItem);
}
return $output;
}