function advagg_js_compress_jsminplus in Advanced CSS/JS Aggregation 7.2
Same name and namespace in other branches
- 6 advagg_js_compress/advagg_js_compress.module \advagg_js_compress_jsminplus()
- 7 advagg_js_compress/advagg_js_compress.module \advagg_js_compress_jsminplus()
Compress a JS string using jsmin+.
Parameters
string $contents: Javascript string.
bool $log_errors: FALSE to disable logging to watchdog on failure.
1 string reference to 'advagg_js_compress_jsminplus'
- advagg_js_compress_configuration in advagg_js_compress/
advagg_js_compress.module - Generate the js compress configuration.
File
- advagg_js_compress/
advagg_js_compress.advagg.inc, line 548
Code
function advagg_js_compress_jsminplus(&$contents, $log_errors = TRUE) {
$no_errors = TRUE;
$contents_before = $contents;
$old_error = error_get_last();
// Set max nesting level.
if (!class_exists('JSMinPlus')) {
$nesting_level = ini_get('xdebug.max_nesting_level');
if (!empty($nesting_level) && $nesting_level < 200) {
ini_set('xdebug.max_nesting_level', 200);
}
}
// Try libraries for jsminplus.
if (is_callable('libraries_load')) {
libraries_load('jsminplus');
}
// Only include jsminplus.inc if the JSMinPlus class doesn't exist.
if (!class_exists('JSMinPlus')) {
include drupal_get_path('module', 'advagg_js_compress') . '/jsminplus.inc';
}
ob_start();
try {
// JSMin+ the contents of the aggregated file.
$contents = @JSMinPlus::minify($contents);
// Capture any output from JSMinPlus.
$error = trim(ob_get_contents());
if (!empty($error)) {
$no_errors = FALSE;
throw new Exception($error);
}
$recent_error = error_get_last();
if (!empty($recent_error) && serialize($recent_error) !== serialize($old_error)) {
$no_errors = FALSE;
$error = print_r($recent_error, TRUE);
throw new Exception($error);
}
} catch (Exception $e) {
$no_errors = FALSE;
// Log the exception thrown by JSMin+ and roll back to uncompressed content.
if ($log_errors) {
watchdog('advagg_js_compress', '@message <pre> @contents </pre>', array(
'@message' => $e
->getMessage(),
'@contents' => $contents_before,
), WATCHDOG_WARNING);
}
$contents = $contents_before;
}
ob_end_clean();
return $no_errors;
}