<?php

/**
 * Snippet to minify CSS.
 *
 * THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 *
 * @package clearFusionCMS\snippet\minifyCSS
 * @copyright Copyright (c) 2013 clearFusionCMS. All rights reserved.
 * @link http://clearfusioncms.com
 */

if(isset($css)) {
	// Strip comments and multiple white space
	$css = preg_replace('#\s*/\*.*?\*/\s*#s', '', $css);
	$css = preg_replace('#\s+#', ' ', $css);

	// Strip white space around chars
	$css = preg_replace('#([;:\{,\}])\s+#', '$1', $css);
	$css = preg_replace('#\s+([;:\{,\}])#', '$1', $css);

	// Remove trailing ; and put lines in
	$css = str_replace(';}', '}', $css);
	$css = str_replace('}', "}\n", $css);

	echo $css;
}