<?
define('ROOT','..');
require_once(ROOT.'/.config.php');
///////////////////////////


$css=array(
	INC.'/bootstrap.min.css',
	ROOT.'/style.css',
);


///////////////////////////
$CACHE_ENABLED	= ($CONF->DEV_MODE==0 || ($CONF->DEV_MODE==1 && $CONF->DEV_CACHED==1) ? 1:0);
$CACHE_FILE		= CACHE.'/frontend_CSS.cache';


if($CACHE_ENABLED==false || !file_exists($CACHE_FILE)) {
	foreach($css as $file) $data.=@file_get_contents($file);
	if($CONF->DEV_MODE==0) {
		$data=trim(preg_replace('/\s\s+/','',$data));
		$data=preg_replace_callback('#/\*(?:.(?!/)|[^\*](?=/)|(?<!\*)/)*\*/#s','remove_comments',$data);
	}
	$data=str_replace(array(' , ',', ',' ,'),array(',',',',','),$data);
	$data=str_replace(array(' : ',': ',' :'),array(':',':',':'),$data);
	$data=str_replace(array(' ; ','; ',' :'),array(';',';',';'),$data);
	$data=str_replace(array(' { ','{ ',' {'),array('{','{','{'),$data);
	$data=str_replace(array(' } ','} ',' }'),array('}','}','}'),$data);
	file_put_contents($CACHE_FILE, $data);
} else {
	$data=file_get_contents($CACHE_FILE);
}


ob_start("ob_gzhandler");
header("Content-Type: text/css");
header("Cache-Control: Public");
header("Expires: ".gmdate("D, d M Y H:i:s", strtotime("1 year"))." GMT");
header("ETag: '".md5($data).'"');
echo $data;







function remove_comments($matches) {
  // as usual: $matches[0] is the complete match
  // $matches[1] the match for the first subpattern
  // enclosed in '(...)' and so on
  return '';
}

?>