You are here

function _advagg_relocate_get_urls in Advanced CSS/JS Aggregation 7.2

Return a filename => url array for external assets.

Parameters

array $data: CSS or JS data array.

string $type: Either css or js.

array $aggregate_settings: Array of settings.

Return value

array Array of external assets to be served locally.

2 calls to _advagg_relocate_get_urls()
advagg_relocate_css_post_alter in advagg_relocate/advagg_relocate.module
Alter the css array.
advagg_relocate_js_post_alter in advagg_relocate/advagg_relocate.module
Alter the js array.

File

advagg_relocate/advagg_relocate.module, line 1248
Advanced aggregation relocate module.

Code

function _advagg_relocate_get_urls(array $data, $type, array $aggregate_settings) {
  $domains_blacklist = $aggregate_settings['variables']["advagg_relocate_{$type}_domains_blacklist"];
  $files_blacklist = $aggregate_settings['variables']["advagg_relocate_{$type}_files_blacklist"];
  $urls = array();
  foreach ($data as $key => $value) {

    // Get all external js files.
    if ($value['type'] !== 'external') {
      continue;
    }

    // If no_relocate=TRUE, do not move it to be local.
    if (!empty($value['no_relocate'])) {
      continue;
    }
    if (empty($value['data'])) {
      $value['data'] = $key;
    }
    $host = parse_url($value['data'], PHP_URL_HOST);
    if (!empty($domains_blacklist)) {
      foreach ($domains_blacklist as $domain) {
        if ($domain === $host) {
          continue 2;
        }
      }
    }
    if (!empty($files_blacklist)) {
      foreach ($files_blacklist as $file) {
        if (strpos($file, $host) !== FALSE) {
          continue 2;
        }
      }
    }

    // Encode the URL into a filename. Force HTTPS.
    $filename = advagg_url_to_filename(advagg_force_https_path($value['data']));

    // Make sure it ends with .css or .js.
    if (stripos(strrev($filename), strrev($type)) !== 0) {
      $filename .= ".{$type}";
    }
    $urls[$filename] = $key;
  }
  return $urls;
}