function advagg_ext_compress_string in Advanced CSS/JS Aggregation 7.2
Compress CSS using via command line.
Parameters
string $contents: The data to compress.
string $type: Should be css or js.
bool $log_errors: TRUE to log errors.
Return value
bool TRUE on success.
2 calls to advagg_ext_compress_string()
- advagg_ext_compress_css_compress in advagg_ext_compress/
advagg_ext_compress.module - Compress CSS using via command line.
- advagg_ext_compress_js_compress in advagg_ext_compress/
advagg_ext_compress.module - Compress Javascript using via command line.
File
- advagg_ext_compress/
advagg_ext_compress.module, line 195 - Advanced CSS/JS aggregation external compression module.
Code
function advagg_ext_compress_string(&$contents, $type, $log_errors) {
list($css_path, $js_path) = advagg_get_root_files_dir();
if ($type === 'css') {
$dir = $css_path[0];
}
else {
$dir = $js_path[0];
}
$new_temp_file = $dir . '/advagg_file_' . drupal_hash_base64(microtime(TRUE) . mt_rand()) . '.' . $type;
$temp_file_full = advagg_get_relative_path($new_temp_file);
file_put_contents($new_temp_file, $contents);
// Set the permissions on the temp file.
drupal_chmod($new_temp_file);
$debug = array();
$output = advagg_ext_compress_execute_cmd($temp_file_full, $type, $debug);
if (empty($output)) {
return FALSE;
}
$new_contents = advagg_file_get_contents($output);
if (strpos($new_contents, 'Error') === 0) {
if ($log_errors) {
watchdog('advagg_ext_compress', "@a \n<br>\n<br> @b", array(
// Only log 4k of data.
'@a' => substr($new_contents, 0, 4096),
'@b' => print_r($debug, TRUE),
));
}
$return = FALSE;
}
else {
$contents = $new_contents;
$return = TRUE;
}
// Cleanup.
if (file_exists($new_temp_file)) {
unlink($new_temp_file);
}
if (file_exists($temp_file_full)) {
unlink($temp_file_full);
}
if (file_exists($output)) {
unlink($output);
}
return $return;
}