function s3fs_copy_system_images_directories in S3 File System 7.2
Same name and namespace in other branches
- 7.3 s3fs.module \s3fs_copy_system_images_directories()
Build array of modules, themes, and libraries that may contain system images.
Return value
array Associative array containing all active sub-directories and root-level directories where system images exist, counts for each directory, and an overall total of files to be copied.
1 call to s3fs_copy_system_images_directories()
File
- ./
s3fs.module, line 1071 - Hook implementations and other primary functionality for S3 File System.
Code
function s3fs_copy_system_images_directories() {
// Add Drupal's default misc and modules directories.
$dirs = array(
'misc',
'modules',
);
// Add directories of current libraries.
foreach (libraries_get_libraries() as $library_name => $library_path) {
$dirs[] = $library_path;
}
// Add directories of enabled modules.
foreach (module_list() as $module_name => $module) {
$dirs[] = drupal_get_path('module', $module_name);
}
// Add directories of available themes.
foreach (list_themes() as $theme_name => $theme) {
$dirs[] = drupal_get_path('theme', $theme_name);
}
// Remove duplicate directories.
$dirs = array_values(array_unique($dirs));
// Remove directories without images, and add counts for those that have images.
$image_dirs = array();
foreach ($dirs as $dir) {
if ($files = file_scan_directory($dir, '/^.*\\.(png|gif|jpe?g|svg|bmp)$/')) {
$image_dirs[$dir] = count($files);
}
}
// Create an array of root-level directories where files reside, and counts for each directory.
$root_image_dirs = array();
foreach ($image_dirs as $image_dir => $image_count) {
$dir_split = explode('/', $image_dir);
if (array_key_exists($dir_split[0], $root_image_dirs)) {
$root_image_dirs[$dir_split[0]] = $root_image_dirs[$dir_split[0]] + $image_count;
}
else {
$root_image_dirs[$dir_split[0]] = $image_count;
}
}
// Sort arrays alphabetically for display.
ksort($image_dirs);
ksort($root_image_dirs);
return array(
'total' => array_sum($image_dirs),
'dirs' => $image_dirs,
'root_dirs' => $root_image_dirs,
);
}