Implements hook_advagg_js_inline_alter().

Fichier

advagg_js_compress/advagg_js_compress.module, line 144

Code

function advagg_js_compress_advagg_js_inline_alter(&$contents) {
    if (!variable_get('advagg_js_compress_inline', ADVAGG_JS_COMPRESS_INLINE)) {
        return;
    }
    $compressor = variable_get('advagg_js_compressor', ADVAGG_JS_COMPRESSOR);
    // If using a cache, try to get the contents of it.
    if (variable_get('advagg_js_compress_inline_cache', ADVAGG_JS_COMPRESS_INLINE_CACHE)) {
        $key = md5($contents) . $compressor;
        $table = 'cache_advagg_js_compress_inline';
        $data = cache_get($key, $table);
        if (!empty($data->data)) {
            $contents = $data->data;
            return;
        }
    }
    if ($compressor == 0) {
        $original_contents = $contents;
        list($before, $after) = advagg_js_compress_jsminplus($contents);
        $ratio = ($before - $after) / $before;
        // Make sure the returned string is not empty or has a VERY high
        // compression ratio.
        if (empty($contents) || $ratio > variable_get('advagg_js_max_compress_ratio', ADVAGG_JS_MAX_COMPRESS_RATIO)) {
            $contents = $original_contents;
        }
    }
    if ($compressor == 1) {
        $contents = jsmin($contents);
    }
    // If using a cache set it.
    if (isset($key)) {
        cache_set($key, $contents, $table, CACHE_TEMPORARY);
    }
}