function agrcache_build_aggregate_cache in Aggregate cache 7
Replacement for drupal_build_css_cache() and drupal_build_js_cache().
2 calls to agrcache_build_aggregate_cache()
- agrcache_aggregate_css in ./
agrcache.module - Replacement for drupal_aggregate_css().
- agrcache_get_js in ./
agrcache.module - Replacement for drupal_get_js().
File
- ./
agrcache.module, line 274 - Provides imagecache style generation of css/js aggregates.
Code
function agrcache_build_aggregate_cache($files, $type) {
$data = '';
$uri = '';
$map = agrcache_get_file_list($type);
$key = hash('sha256', agrcache_serialize_files($files));
if (isset($map['files'][$key])) {
return array(
'uri' => $map['files'][$key],
);
}
else {
// To ensure a new filenames are created only when the contents of the
// hashed files changes, use a hash of the contents for the filename.
$function = 'agrcache_collect_' . $type . '_group';
$data = $function($files);
if ($data) {
// Prefix filename to prevent blocking by firewalls which reject files
// starting with "ad*". Even though the file map is by the hash of files,
// the filename must hash by both the the contents and the files array. It
// is possible to have identical contents even if files have moved, but
// since URLs are replaced, the resulting file should be different even if
// the contents are the same, i.e. two different file keys pointing to the
// same filename.
$filename = $type . '_' . drupal_hash_base64(agrcache_serialize_files($files) . $data) . ".{$type}";
// Create the aggregate directory within the files folder.
$path = "public://{$type}";
$uri = $path . '/' . $filename;
return array(
'key' => $key,
'uri' => $uri,
'#write_cache' => TRUE,
);
}
else {
return FALSE;
}
}
}