View source
<?php
define('ADVAGG_CSS_COMPRESS_PRESERVE_CSS', TRUE);
define('ADVAGG_CSS_COMPRESS_AGG_FILES', TRUE);
define('ADVAGG_CSS_COMPRESS_INLINE', TRUE);
define('ADVAGG_CSS_COMPRESS_INLINE_CACHE', TRUE);
define('ADVAGG_CSS_COMPRESSOR', 2);
define('ADVAGG_CSS_COMPRESS_COMPRESSOR_LEVEL', 'sane');
function advagg_css_compress_menu() {
$items = array();
$file_path = drupal_get_path('module', 'advagg_css_compress');
$items['admin/settings/advagg/css-compress'] = array(
'title' => 'CSS Compression',
'description' => 'Adjust CSS Compression settings.',
'page callback' => 'advagg_css_compress_admin_page',
'type' => MENU_LOCAL_TASK,
'access arguments' => array(
'administer site configuration',
),
'file path' => $file_path,
'file' => 'advagg_css_compress.admin.inc',
'weight' => 10,
);
return $items;
}
function advagg_css_compress_advagg_css_alter(&$contents, $files, $bundle_md5) {
if (!variable_get('advagg_css_compress_agg_files', ADVAGG_CSS_COMPRESS_AGG_FILES)) {
return;
}
$compressor = variable_get('advagg_css_compressor', ADVAGG_CSS_COMPRESSOR);
if ($compressor == 0) {
advagg_css_compress_css_tidy($contents);
}
elseif ($compressor == 1) {
advagg_css_compress_css_compressor($contents);
}
elseif ($compressor == 2) {
advagg_css_compress_yui_cssmin($contents);
}
}
function advagg_css_compress_advagg_css_inline_alter(&$contents) {
if (!variable_get('advagg_css_compress_inline', ADVAGG_CSS_COMPRESS_INLINE)) {
return;
}
$compressor = variable_get('advagg_css_compressor', ADVAGG_CSS_COMPRESSOR);
if (variable_get('advagg_css_compress_inline_cache', ADVAGG_CSS_COMPRESS_INLINE_CACHE)) {
$key = md5($contents) . $compressor;
$table = 'cache_advagg_css_compress_inline';
$data = cache_get($key, $table);
if (!empty($data->data)) {
$contents = $data->data;
return;
}
}
if ($compressor == 0) {
advagg_css_compress_css_tidy($contents);
}
if ($compressor == 1) {
advagg_css_compress_css_compressor($contents);
}
if (isset($key)) {
cache_set($key, $contents, $table, CACHE_TEMPORARY);
}
}
function advagg_css_compress_css_tidy(&$contents) {
$filename = drupal_get_path('module', 'advagg_css_compress') . '/csstidy/class.csstidy.inc';
include_once $filename;
$css = new csstidy();
if (function_exists('set_time_limit')) {
@set_time_limit(variable_get('advagg_set_time_limit', ADVAGG_SET_TIME_LIMIT));
}
$css
->set_cfg('preserve_css', variable_get('advagg_css_compress_preserve_css', ADVAGG_CSS_COMPRESS_PRESERVE_CSS));
$css
->set_cfg('remove_last_;', TRUE);
$css
->set_cfg('merge_selectors', TRUE);
$css
->set_cfg('optimise_shorthands', TRUE);
$css
->set_cfg('silent', TRUE);
$css
->set_cfg('compress_colors', TRUE);
$css
->set_cfg('sort_selectors', FALSE);
$css
->set_cfg('sort_properties', FALSE);
$css
->set_cfg('discard_invalid_properties', FALSE);
$css
->set_cfg('timestamp', FALSE);
$css
->load_template("highest_compression");
$css
->parse($contents);
$contents = $css->print
->plain();
}
function advagg_css_compress_css_compressor(&$contents) {
$filename = drupal_get_path('module', 'advagg_css_compress') . '/css-compressor-3.x/src/CSSCompression.inc';
include_once $filename;
$CSSC = new CSSCompression(variable_get('advagg_css_compress_compressor_level', ADVAGG_CSS_COMPRESS_COMPRESSOR_LEVEL));
$contents = $CSSC
->compress($contents);
}
function advagg_css_compress_yui_cssmin(&$contents) {
$filename = drupal_get_path('module', 'advagg_css_compress') . '/yui/CSSMin.inc';
include_once $filename;
$cssmin = new CSSmin();
$contents = $cssmin
->run($contents, 4096);
}
function advagg_css_compress_flush_caches() {
return array(
'cache_advagg_css_compress_inline',
);
}