diff --git a/omega/includes/assets.inc b/omega/includes/assets.inc index f17c599..31a859a 100644 --- a/omega/includes/assets.inc +++ b/omega/includes/assets.inc @@ -22,6 +22,11 @@ * @see hook_css_alter() */ function omega_assets_prepare_regex(array $paths) { + // Don't do any processing if no paths are given. + if (empty($paths)) { + return FALSE; + } + $profile = drupal_get_profile(); $site = preg_quote(conf_path(), '/'); @@ -37,6 +42,36 @@ function omega_assets_prepare_regex(array $paths) { ':base-theme' => $themes ? '(?:' . implode('|', $themes) . ')' : FALSE, ); + // Add all active modules to the token list. + foreach (module_list() as $module) { + $directory = preg_quote(drupal_get_path('module', $module), '/'); + $tokens[$module] = $directory; + } + // Add all themes and engines to the token list. + foreach (list_themes() as $theme_name => $theme_info) { + $directory = preg_quote(dirname($theme_info->filename), '/'); + $tokens[$theme_name] = $directory; + // Add theme engine if not already set. + if (!isset($tokens[$theme_info->engine])) { + // Theme engines aren't in the database so we use the information from the + // theme itself. Using drupal_get_path() would find the path but generate + // a warning. + $directory = ''; + if (drupal_realpath($theme_info->owner)) { + $directory = preg_quote(dirname($theme_info->owner), '/'); + } + $tokens[$theme_info->engine] = $directory; + } + } + // Get install profiles. + // Same as in install_find_profiles(). + $profiles = file_scan_directory('./profiles', '/\.profile$/', array('key' => 'name'), 0, TRUE); + foreach ($profiles as $profile => $profile->info) { + // Add theme engine. + $directory = preg_quote(drupal_get_path('profile', $profile), '/'); + $tokens[$profile] = $directory; + } + foreach ($paths as &$item) { // The first segment (everything before the first slash) is the namespace. // This rule only applies to local files... So if the namespace can not be @@ -44,32 +79,12 @@ function omega_assets_prepare_regex(array $paths) { // trying to target an external file. list($namespace) = explode('/', $item, 2); - // Process token namespaces. + // If a namespace is know but doesn't have a path + // skip the whole item. if (isset($tokens[$namespace]) && empty($tokens[$namespace])) { unset($item); continue; } - // Skip wildcard namespaces. - elseif ($namespace != '*' && !isset($tokens[$namespace])) { - // Check if it refers to a theme, module, profile or theme engine. - foreach (array('theme', 'module', 'profile', 'theme_engine') as $type) { - // We can't use drupal_get_path() directly because that uses dirname() - // internally which returns '.' if no filename was found. - if ($filename = drupal_get_filename($type, $namespace)) { - $directory = preg_quote(dirname($filename), '/'); - // Now that we know about this namespace we can add it to the tokens - // array for performance reasons. - $tokens[$namespace] = $directory; - break; - } - } - - if (empty($tokens[$namespace]) && function_exists('libraries_get_path')) { - if ($directory = libraries_get_path($namespace)) { - $tokens[$namespace] = preg_quote($directory, '/'); - } - } - } // Escape any regex characters and replace tokens and wildcards. $item = isset($tokens[$namespace]) ? substr($item, strlen($namespace)) : $item;