You are here

function magic_exclude_assets in Magic 7

Helper function for eliminating elements from an array using a simplified regex pattern.

Parameters

$elements: The array of elements that should have some of its items removed.

$regex: A regex as generated by omega_generate_path_regex().

1 call to magic_exclude_assets()
magic_css_js_alter in ./magic.module
Helper function to remove unwanted css or js.

File

includes/magic.inc, line 135
A file to contain functions for the magic module to abuse.

Code

function magic_exclude_assets(&$elements, $exclude, $include) {
  $mapping = magic_generate_asset_mapping($elements);

  // We first check to see if we have an include array. If not, we don't need to
  // check it as well.
  if ($include) {

    // We do a grep on each the exclude list, and include list and return the keys
    // of the exclude list minus those that are specifically included.
    $full_exclude = array_diff_key(preg_grep($exclude, $mapping), preg_grep($include, $mapping));

    // Finally, implode the array of items to exclude into a proper regex and
    // invoke in on the array of files to be excluded.
    $elements = array_diff_key($elements, $full_exclude);
  }
  else {

    // We only have an exclude array, so we only have to do a preg_grep for it.
    $elements = array_diff_key($elements, preg_grep($exclude, $mapping));
  }
}