function _context_addassets_scandir in Context Add Assets 7
Same name and namespace in other branches
- 6 context_addassets.module \_context_addassets_scandir()
Scan drupal location for a type of file.
Parameters
string $filetype: extension of the file your looking for. Note: No leading period, for filetype use "js" instead of ".js"
@param string $where the location function will search. Currently Supports: Modules, Themes (Active), and Abitrary File Paths
@return Array An array indexed by file paths containing strings describing each path "Theme Key - File Name"
1 call to _context_addassets_scandir()
- context_reaction_addassets_base::_context_addassets_search in plugins/
context_reaction_addassets_base.inc - * Scan active themes for js files. * *
File
- ./
context_addassets.module, line 304
Code
function _context_addassets_scandir($filetype = NULL, $where = 'themes') {
$file_files = FALSE;
// If $filetype has leading "." - remove it.
if ($filetype[0] == '.') {
$filetype = drupal_substr(1, drupal_strlen($filetype));
}
// Future setting to include all themes
$include_all = FALSE;
$mask = "/.+\\." . $filetype . '/';
switch ($where) {
// If want to find assets in modules.
case 'modules':
// Grab selected modules
$modules = variable_get('context_addassets_index_modules', array());
foreach ($modules as $path) {
if (!$path) {
continue;
}
$files_raw[$path] = file_scan_directory($path, $mask);
}
break;
// If want to find assets in file paths.
case 'paths':
// Initialize path array index at zero.
$path_index = 0;
// Grab every set file path
while ($path = variable_get('context_addassets_index_path' . $path_index, NULL)) {
$files_raw[$path] = file_scan_directory($path, $mask);
$path_index += 1;
}
break;
// If you want to find assets in themes
case 'themes':
default:
// Setup vars to avoid foreach fails.
$selected_themes = array();
$files_raw = array();
// We'll grab active themes
$themes = list_themes();
foreach ($themes as $item) {
// Only lists the theme if the theme is enabled.
// Drupal's list_themes() function returns an array of objects, so we extract an array from each of the objects.
$list = get_object_vars($item);
// Only list the theme if it is enabled.
if ($include_all == FALSE and $list['status'] or $include_all == TRUE) {
$list = get_object_vars($item);
$path = explode('/', $list['filename']);
unset($path[count($path) - 1]);
$path = implode('/', $path);
$selected_themes[] = array(
'name' => $list['info']['name'],
'path' => $path,
);
}
}
// Scan $selected_themes for given filetype.
foreach ($selected_themes as $theme) {
$dir = $theme['path'];
$name = $theme['name'];
$mask = "/.+\\." . $filetype . "/";
$files_raw[$name] = file_scan_directory($dir, $mask);
}
break;
}
// switch $where
// No files found.
if (isset($files_raw)) {
if (is_array($files_raw)) {
// Remove the full path.
foreach ($files_raw as $key => $value) {
foreach ($value as $value_key => $file) {
$file_files[$file->uri] = $key . ' -- ' . $file->uri;
}
}
}
}
return $file_files;
}