function _ddblock_get_image_array in Dynamic display block 7
Same name and namespace in other branches
- 6 ddblock.module \_ddblock_get_image_array()
Get images from a directory.
Parameters
$imagepath: Path to the directoryory where the images are stored.
$order: The order in which to return the images.
$max_image: The maximum images to show in the slideshow.
$ignore_files: Comma seperated list of strings. When string exist in image file name, the image is ignored.
Return value
An array containing the filenames of the images for the dynamic display block.
1 call to _ddblock_get_image_array()
- ddblock_content in ./
ddblock.module - Get contents of dynamic display block block.
File
- ./
ddblock.module, line 2298 - Enables your site to display dynamic content in a block.
Code
function _ddblock_get_image_array($imagepath, $order, $max_image, $ignore_files, $image_style_slide, $image_style_pager_item) {
// only images jpg, jpeg, gif, png
$mask = '/[a-zA-Z0-9\\_\\-\\.\\]\\[]+\\.(jpe?g|gif|png|JPE?G|GIF|PNG)$/';
// ignore the following files
$ignore = '/(\\.\\.?|CVS)$/';
// Finds all files that match a given mask in a given directory, files which match the ignore variable are excluded.
$file_array = file_scan_directory($imagepath, $mask, array(
'nomask' => $ignore,
'callback' => $callback = 0,
'recurse' => $recurse = FALSE,
'key' => $key = 'filename',
'min_depth' => $min_depth = 0,
));
$file_names = array();
if (sizeof($file_array) > 0) {
// Remove to file to ignore
if (!empty($ignore_files)) {
$ignore_strings = explode(',', $ignore_files);
$temp_file_array = array();
foreach ($file_array as $value) {
$ignore = FALSE;
foreach ($ignore_strings as $ignore_string) {
if (stristr($value->filename, $ignore_string)) {
$ignore = TRUE;
break;
}
}
if (!$ignore) {
$temp_file_array[] = $value;
}
}
$file_array = $temp_file_array;
}
if (sizeof($file_array) > 0) {
foreach ($file_array as $value) {
if ($image_style_slide != 'none') {
$image_info = _ddblock_get_file_sizes($value->uri, $image_style_slide);
$image = array(
'title' => 'image',
'path' => $value->uri,
'alt' => 'image',
'style_name' => $image_style_slide,
'width' => $image_info['width'] . 'px',
'height' => $image_info['height'] . 'px',
);
$file_names['slide_image'][] = theme('image_style', $image);
}
else {
$variables = array(
'path' => $value->uri,
'alt' => 'image',
'title' => 'image',
'width' => '100%',
'height' => '100%',
'attributes' => array(),
);
$file_names['slide_image'][] = '<img src="' . file_create_url($value->uri) . '" alt="image">';
// $file_names['slide_image'][] = theme('image', $variables);
}
if ($image_style_pager_item != 'none') {
$image_info = _ddblock_get_file_sizes($value->uri, $image_style_pager_item);
$image = array(
'title' => 'image',
'path' => $value->uri,
'alt' => 'image',
'style_name' => $image_style_pager_item,
'width' => $image_info['width'] . 'px',
'height' => $image_info['height'] . 'px',
);
$file_names['pager_image'][] = theme('image_style', $image);
}
else {
$variables = array(
'path' => $value->uri,
'alt' => 'image',
'title' => 'image',
'width' => '55px',
'height' => '55px',
'attributes' => array(),
);
$file_names['pager_image'][] = theme('image', $variables);
}
}
switch ($order) {
case 'random':
shuffle($file_names);
break;
case 'asc':
asort($file_names['slide_image']);
asort($file_names['pager_image']);
break;
case 'desc':
rsort($file_names['slide_image']);
rsort($file_names['pager_image']);
break;
case 'none':
break;
}
$file_names['slide_image'] = array_slice($file_names['slide_image'], 0, $max_image);
$file_names['pager_image'] = array_slice($file_names['pager_image'], 0, $max_image);
}
}
return $file_names;
}