You are here

function _advagg_relocate_callback in Advanced CSS/JS Aggregation 7.2

Gets external CSS files and puts the contents of it in the aggregate.

Parameters

array $matches: Array of matched items from preg_replace_callback().

array $files: List of files with the media type.

array $aggregate_settings: Array of settings.

Return value

string Contents of the import statement.

1 call to _advagg_relocate_callback()
advagg_relocate_advagg_get_css_aggregate_contents_alter in advagg_relocate/advagg_relocate.advagg.inc
Implements hook_advagg_get_css_aggregate_contents_alter().
1 string reference to '_advagg_relocate_callback'
advagg_relocate_advagg_get_css_aggregate_contents_alter in advagg_relocate/advagg_relocate.advagg.inc
Implements hook_advagg_get_css_aggregate_contents_alter().

File

advagg_relocate/advagg_relocate.advagg.inc, line 249
Advanced aggregation relocate module.

Code

function _advagg_relocate_callback(array $matches = array(), array $files = array(), array $aggregate_settings = array()) {

  // Store values for preg_replace_callback callback.
  $_args =& drupal_static(__FUNCTION__, array());
  if (!empty($files)) {
    $_args['files'] = $files;
  }
  if (!empty($aggregate_settings)) {
    $_args['aggregate_settings'] = $aggregate_settings;
  }

  // Short circuit if no matches were passed in.
  if (empty($matches)) {
    return '';
  }

  // Bail if not matched.
  if (empty($matches[1])) {
    return $matches[0];
  }

  // Check URL.
  if (!advagg_relocate_check_domain_of_font_url($matches[1], $_args['aggregate_settings'])) {
    return $matches[0];
  }

  // Check per file settings.
  if (!isset($_args['aggregate_settings']['variables']['advagg_relocate_css_file_settings'])) {
    $_args['aggregate_settings']['variables']['advagg_relocate_css_file_settings'] = variable_get('advagg_relocate_css_file_settings', array());
  }
  $key_to_check = str_replace(array(
    '=',
    '&',
    ' ',
  ), array(
    '_',
    '-',
    '-',
  ), $matches[1]);
  foreach ($_args['files'] as $filename => $values) {
    $form_api_filename = str_replace(array(
      '/',
      '.',
      '=',
      '&',
      ' ',
    ), array(
      '__',
      '--',
      '_',
      '-',
      '+',
    ), $filename);

    // All has been checked; good to go.
    if (!empty($_args['aggregate_settings']['variables']['advagg_relocate_css_file_settings']["all:{$form_api_filename}"])) {
      continue;
    }

    // This file is good to be inlined.
    if (!empty($_args['aggregate_settings']['variables']['advagg_relocate_css_file_settings'][$form_api_filename][$key_to_check])) {
      continue;
    }

    // No go, return unaltered.
    return $matches[0];
  }
  $font_faces = advagg_relocate_get_remote_font_data($matches[1], $_args['aggregate_settings']);
  return advagg_relocate_font_face_parser($font_faces);
}