You are here

function hook_advagg_save_aggregate_alter in Advanced CSS/JS Aggregation 7.2

Allow other modules to alter the contents and add new files to save (.gz).

Parameters

array $files_to_save: Array($uri => $contents).

array $aggregate_settings: Array of settings.

array $other_parameters: Array of containing $files and $type.

See also

advagg_save_aggregate()

advagg_advagg_save_aggregate_alter()

Related topics

3 functions implement hook_advagg_save_aggregate_alter()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

advagg_advagg_save_aggregate_alter in ./advagg.advagg.inc
Implements hook_advagg_save_aggregate_alter().
advagg_js_compress_advagg_save_aggregate_alter in advagg_js_compress/advagg_js_compress.advagg.inc
Implements hook_advagg_save_aggregate_alter().
advagg_sri_advagg_save_aggregate_alter in advagg_sri/advagg_sri.advagg.inc
Implements hook_advagg_save_aggregate_alter().
1 invocation of hook_advagg_save_aggregate_alter()
advagg_save_aggregate in ./advagg.missing.inc
Save an aggregate given a filename, the files included in it, and the type.

File

./advagg.api.php, line 133
Hooks provided by the AdvAgg module.

Code

function hook_advagg_save_aggregate_alter(array &$files_to_save, array $aggregate_settings, array $other_parameters) {

  // Return if gzip is disabled.
  if (empty($aggregate_settings['variables']['advagg_gzip'])) {
    return;
  }

  // See if a .gz file already exists.
  $gzip_exists = FALSE;
  foreach ($files_to_save as $uri => $contents) {

    // See if this uri contains .gz near the end of it.
    $pos = strripos($uri, '.gz', 91 + strlen(ADVAGG_SPACE) * 3);
    if (!empty($pos)) {
      $len = strlen($uri);

      // .gz file exists, exit loop.
      if ($pos == $len - 3) {
        $gzip_exists = TRUE;
        break;
      }
    }
  }

  // If a .gz file does not exist, create one.
  if (!$gzip_exists) {

    // Use the first file in the array.
    $data = reset($files_to_save);
    $uri = key($files_to_save);

    // Compress it and add it to the $files_to_save array.
    $compressed = gzencode($data, 9, FORCE_GZIP);
    $files_to_save[$uri . '.gz'] = $compressed;
  }
}