Write CSS parts to disk; used when CSS selectors in one file is > 4096.
Parameters
string $css: CSS data to write to disk.
int $overall_split: Running count of what selector we are from the original file.
array $file_info: File info array from advagg_get_info_on_file().
Return value
array Array with advagg_get_info_on_file data and split data; FALSE on failure.
1 call to advagg_create_subfile()
- advagg_split_css_file in ./
advagg.inc - Given a file info array it will split the file up.
File
-
./
advagg.inc, line 1347
Code
function advagg_create_subfile($css, $overall_split, array $file_info) {
static $parts_uri;
static $parts_path;
if (!isset($parts_uri)) {
list($css_path) = advagg_get_root_files_dir();
$parts_uri = $css_path[0] . '/parts';
$parts_path = $css_path[1] . '/parts';
// Create the public://advagg_css/parts dir.
file_prepare_directory($parts_uri, FILE_CREATE_DIRECTORY);
// Make advagg_save_data() available.
module_load_include('inc', 'advagg', 'advagg.missing');
}
// Get the path from $file_info['data'].
$uri_path = advagg_get_relative_path($file_info['data']);
if (!file_exists($uri_path) || is_dir($uri_path)) {
return FALSE;
}
// Write the current chunk of the CSS into a file.
$new_filename = str_ireplace('.css', '.' . $overall_split . '.css', $uri_path);
// Fix for things that write dynamically to the public file system.
$scheme = file_uri_scheme($new_filename);
if ($scheme) {
$wrapper = file_stream_wrapper_get_instance_by_scheme($scheme);
if ($wrapper && method_exists($wrapper, 'getDirectoryPath')) {
// Use the wrappers directory path.
$new_filename = $wrapper->getDirectoryPath() . '/' . file_uri_target($new_filename);
}
else {
// If the scheme does not have a wrapper; prefix file with the scheme.
$new_filename = $scheme . '/' . file_uri_target($new_filename);
}
}
$part_uri = $parts_uri . '/' . $new_filename;
$dirname = drupal_dirname($part_uri);
file_prepare_directory($dirname, FILE_CREATE_DIRECTORY);
$filename_path = advagg_s3fs_evaluate_no_rewrite_cssjs(FALSE) ? $parts_uri : $parts_path;
// Get info on the file that was just created.
$part = advagg_get_info_on_file($filename_path . '/' . $new_filename, TRUE) + $file_info;
$part['split'] = TRUE;
$part['split_location'] = $overall_split;
$part['split_original'] = $file_info['data'];
// Overwrite/create file if hash doesn't match.
$hash = drupal_hash_base64($css);
if ($part['content_hash'] !== $hash) {
advagg_save_data($part_uri, $css, TRUE);
$part = advagg_get_info_on_file($filename_path . '/' . $new_filename, TRUE) + $file_info;
$part['split'] = TRUE;
$part['split_location'] = $overall_split;
$part['split_original'] = $file_info['data'];
}
return $part;
}