function _ddblock_get_image_array in Dynamic display block 6
Same name and namespace in other branches
- 7 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.
Return value
An array containing the filename 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 2069 - Enables your site to display dynamic content in a block.
Code
function _ddblock_get_image_array($imagepath, $order, $max_image, $ignore_files) {
// only images jpg, jpeg, gif, png
$mask = '[a-zA-Z0-9\\_\\-\\.]+\\.(jpe?g|gif|png|JPE?G|GIF|PNG)$';
// ignore the following files
$ignore = array(
'.',
'..',
'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, $ignore, $callback = 0, $recurse = FALSE, $key = 'filename', $min_depth = 0, $depth = 0);
$file_names = array();
if (!empty($ignore_files)) {
$ignore_strings = explode(',', $ignore_files);
foreach ($file_array as $value) {
$ignore = FALSE;
foreach ($ignore_strings as $ignore_string) {
if (stristr($value->filename, $ignore_string)) {
$ignore = TRUE;
break;
}
}
if (!$ignore) {
$file_names[] = $value->filename;
}
}
}
else {
foreach ($file_array as $value) {
$file_names[] = $value->filename;
}
}
switch ($order) {
case 'random':
shuffle($file_names);
break;
case 'asc':
asort($file_names);
break;
case 'desc':
rsort($file_names);
break;
case 'none':
break;
}
$file_names = array_slice($file_names, 0, $max_image);
return $file_names;
}