function magic_assets_regex_steps in Magic 7.2
Groups include/exclude patterns together.
This is required to allow for complex chained includes/excludes. We can't do this in a single, complicated regular expression as regex does not really support this (negative lookbehinds are not sufficient).
Parameters
$items: An array of include/exclude patterns.
Return value
array The include/exclude patterns as groups.
3 calls to magic_assets_regex_steps()
- MagicCSSTestCase::testMagicCSSExcludes in ./
magic.test - Test magic_assets_exclude().
- MagicJSTestCase::testMagicJSExcludes in ./
magic.test - Test magic_assets_exclude().
- magic_css_js_alter in ./
magic.module - Helper function to remove unwanted css or js.
File
- includes/
magic.assets.inc, line 92 - A file to contain functions for the magic module to abuse.
Code
function magic_assets_regex_steps($items) {
$switch = FALSE;
$key = 0;
$groups = array();
// Iterate over all exclude/include paths and form groups. We start a new
// group every time we switch from inclusion to exclusion.
foreach ($items as $item) {
// If an item starts with a "~" it is an inclusion pattern.
if ($exclude = strpos($item, '~') === 0) {
$item = substr($item, 1);
}
// Start a new group if we are switching between exclusion/inclusion.
if ($switch !== $exclude && ($switch = !$switch) === FALSE) {
$key++;
}
// Initialize the group with two empty arrays if it does not exist yet.
if (!isset($groups[$key])) {
$groups[$key] = array_fill(0, 2, array());
}
$groups[$key][!$switch ? 0 : 1][] = $item;
}
// Each group now needs to have its items converted to a regex string.
foreach ($groups as &$group) {
foreach (array(
0,
1,
) as $key) {
$group[$key] = !empty($group[$key]) ? magic_assets_prepare_regex($group[$key]) : FALSE;
}
}
return $groups;
}