Hi
I modified the script a little bit to suit my needs,
but when i call the script 2 times on the same page
my page crashes,
I use the following call:
[!PhotoGallery? &folder=`inbouwkasten_wilrijk` &image_link_rel=`inbouwkast` &title=`Inbouwkasten - Wilrijk` &thumbnail=`inbouwkast.jpg` !]
What am i doing wrong, and how can i modify tje script that this works fine
<?php
/**
* @name PhotoGallery
* @author Dave Child <[email protected]>
* @license GPLv3
* @version 0.1
*
* This snippet returns a photo gallery with subfolders. Shows
* thumbnails of images and links to full size. Works with most
* common lightbox clones. Designed and tested with prettyPhoto
* (a jQuery lightbox clone: http://tinyurl.com/dkuwya ).
*
* Shows JPG, JPEG, GIF and PNG images in the target folder.
* Image title is taken from the image name.
*
* &folder=`foldername`
* Folder to display. Not optional. Must be within assets/images/
*
* &width=`60` - Optional
* Thumbnail width. Defaults to 60. TinyMCE thumbnails are 96
* by 96 by default. Probably best not to use thumbnails larger
* than that unless you’ve set TinyMCE to use bigger dimensions.
*
* &list_class=`gallery` - Optional
* Class to add to the ul containing the photos. Defaults to
* blank.
*
* &image_link_rel=`prettyPhoto` - Optional
* Most galleries use a rel on the link to control the popup.
* Defaults to blank.
*
* &subfolder_list_title=`Sub-Galleries` - Optional
* Title for the subfolders list. Uses an h2. If left blank,
* returns no title and no h2.
*
* &subfolder_list=`on` - Optional
* Return the subfolders list. "on" or "off".
*
* &image_list_title=`Photos` - Optional
* Title for the images list. Uses an h2. If left blank,
* returns no title and no h2.
*
* &image_list=`on` - Optional
* Return the image list. "on" or "off".
*/
// ---------------------------------------------------
// Check input variables
// ---------------------------------------------------
if (!isset($folder)) {
die(’No folder set’);
}
if (!isset($thumbnail)) {
die(’No thumbnail set’);
}
if (!isset($title)) {
die(’No title set’);
}
if (($_GET[’folder’]) && (preg_match(’#[^A-Za-z0-9/-_]#’, $_GET[’folder’]) == false)) {
$folder .= ’/’ . $_GET[’folder’];
}
$width = (isset($width)) ? $width : 60;
$list_class = (isset($list_class)) ? ’ ’ . $list_class : ’’;
$image_link_rel = (isset($image_link_rel)) ? $image_link_rel : ’’;
$image_list = ($image_list == ’off’) ? ’off’ : ’on’;
$subfolder_list = ($subfolder_list == ’off’) ? ’off’ : ’on’;
$doc_folder = $modx->config[’base_path’] . ’assets/images/’ . $folder . ’/’;
// ---------------------------------------------------
// Check folder exists
// ---------------------------------------------------
if (!is_dir($doc_folder)) {
$modx->logEvent(1, 3, ’Folder was not a folder: ’ . $doc_folder, ’PhotoGallery Snippet’);
return ’Error: Photo gallery folder not found.’;
}
// ---------------------------------------------------
// Define a few variables
// ---------------------------------------------------
$id = $modx->documentIdentifier;
$url = $modx->makeUrl($id);
$folder_list_html = ’’;
$image_list_html = ’’;
$counter = 0;
$thumbnailLink =’’;
// Initialize output
$return = ’’;
// ---------------------------------------------------
// Loop through items in folder
// ---------------------------------------------------
if ($handle = opendir($doc_folder)) {
while (false !== ($file = readdir($handle))) {
if ((substr($file, 0, 7) != ’.thumb_’) && ($file != ’.’) && ($file != ’..’)) {
if (is_dir($doc_folder . $file)) {
if ($subfolder_list == ’on’) {
$folder_list_html .= ’<li><a href="’ . $url . ’?folder=’;
if (($_GET[’folder’]) && (preg_match(’#[^A-Za-z0-9/-_]#’, $_GET[’folder’]) == false)) {
$folder_list_html .= $_GET[’folder’] . ’/’;
}
$folder_list_html .= $file .’"><span>’ . process_name($file) . ’</span></a></li>’;
}
} elseif ($image_list == ’on’) {
$file_pieces = explode(’.’, $file);
$ext_piece_num = count($file_pieces) - 1;
if (
(strtolower($file_pieces[$ext_piece_num]) == ’jpg’)
||(strtolower($file_pieces[$ext_piece_num]) == ’jpeg’)
||(strtolower($file_pieces[$ext_piece_num]) == ’png’)
||(strtolower($file_pieces[$ext_piece_num]) == ’gif’)
) {
if ($counter == 0) {
$thumbnailLink =’<img alt="" src="assets/templates/twodo/images/’. $thumbnail .’" class="imgindent" />’;
$counter++;
}
$image_list_html .= ’<a rel="lytebox[’ . $image_link_rel . ’]" title="’ . $title .’" href="assets/images/’ . $folder . ’/’ . $file .’">’ . $thumbnailLink .’</a>’;
$thumbnailLink =’’;
}
}
}
}
closedir($handle);
}
// ---------------------------------------------------
// Add folders to return if wanted
// ---------------------------------------------------
if (($subfolder_list == ’on’) && ($folder_list_html <> ’’)) {
if ($subfolder_list_title <> ’’) {
$return .= ’<h2>’ . $subfolder_list_title . ’</h2>’;
}
$return .= $folder_list_html;
}
// ---------------------------------------------------
// Add images to return if wanted
// ---------------------------------------------------
if (($image_list == ’on’) && ($image_list_html <> ’’)) {
if ($image_list_title <> ’’) {
$return .= ’<h2>’ . $image_list_title . ’</h2>’;
}
$return .= $image_list_html;
}
return $return;
// ---------------------------------------------------
// Define process_name Function
// ---------------------------------------------------
function process_name($filename) {
$filename = strtolower($filename);
$filename = str_replace(’.jpg’, ’’, $filename);
$filename = str_replace(’.jpeg’, ’’, $filename);
$filename = str_replace(’.png’, ’’, $filename);
$filename = str_replace(’.gif’, ’’, $filename);
$filename = str_replace(’-’, ’ ’, $filename);
$filename = str_replace(’_’, ’ ’, $filename);
$filename = preg_replace(’/ +/’, ’ ’, $filename);
return ucwords($filename);
}
?>