You are here

function advagg_css_compress_css_tidy in Advanced CSS/JS Aggregation 7

Same name and namespace in other branches
  1. 6 advagg_css_compress/advagg_css_compress.module \advagg_css_compress_css_tidy()

Use the CSS Tidy library to compress the CSS.

TODO have set_cfg be fully configurable from GUI.

2 calls to advagg_css_compress_css_tidy()
advagg_css_compress_advagg_css_alter in advagg_css_compress/advagg_css_compress.module
Implements hook_advagg_css_alter().
advagg_css_compress_advagg_css_inline_alter in advagg_css_compress/advagg_css_compress.module
Implements hook_advagg_css_inline_alter().

File

advagg_css_compress/advagg_css_compress.module, line 116
Advanced aggregation css compression module.

Code

function advagg_css_compress_css_tidy(&$contents) {

  // Initialize CSSTidy.
  $filename = drupal_get_path('module', 'advagg_css_compress') . '/csstidy/class.csstidy.inc';
  include_once DRUPAL_ROOT . '/' . $filename;
  $css = new csstidy();

  // Try to allocate enough time to run CSSTidy.
  if (function_exists('set_time_limit')) {
    @set_time_limit(240);
  }

  // Set configuration.
  $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");

  // Compress CSS.
  $css
    ->parse($contents);
  $contents = $css->print
    ->plain();
}